Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/serde_json/tests/debug.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / serde_json / tests / debug.rs` 83 lines ยท 2038 bytes Raw Blame History 1 #![allow(clippy::uninlined_format_args)] 2 3 use indoc::indoc; 4 use serde_json::{json, Number, Value}; 5 6 #[test] 7 fn number() { 8 assert_eq!(format!("{:?}", Number::from(1)), "Number(1)"); 9 assert_eq!(format!("{:?}", Number::from(-1)), "Number(-1)"); 10 assert_eq!( 11 format!("{:?}", Number::from_f64(1.0).unwrap()), 12 "Number(1.0)" 13 ); 14 } 15 16 #[test] 17 fn value_null() { 18 assert_eq!(format!("{:?}", json!(null)), "Null"); 19 } 20 21 #[test] 22 fn value_bool() { 23 assert_eq!(format!("{:?}", json!(true)), "Bool(true)"); 24 assert_eq!(format!("{:?}", json!(false)), "Bool(false)"); 25 } 26 27 #[test] 28 fn value_number() { 29 assert_eq!(format!("{:?}", json!(1)), "Number(1)"); 30 assert_eq!(format!("{:?}", json!(-1)), "Number(-1)"); 31 assert_eq!(format!("{:?}", json!(1.0)), "Number(1.0)"); 32 assert_eq!(Number::from_f64(1.0).unwrap().to_string(), "1.0"); // not just "1" 33 assert_eq!(Number::from_f64(12e40).unwrap().to_string(), "1.2e+41"); 34 } 35 36 #[test] 37 fn value_string() { 38 assert_eq!(format!("{:?}", json!("s")), "String(\"s\")"); 39 } 40 41 #[test] 42 fn value_array() { 43 assert_eq!(format!("{:?}", json!([])), "Array []"); 44 } 45 46 #[test] 47 fn value_object() { 48 assert_eq!(format!("{:?}", json!({})), "Object {}"); 49 } 50 51 #[test] 52 fn error() { 53 let err = serde_json::from_str::("{0}").unwrap_err(); 54 let expected = "Error(\"key must be a string\", line: 1, column: 2)"; 55 assert_eq!(format!("{:?}", err), expected); 56 } 57 58 #[test] 59 fn indented() { 60 let j = json!({ 61 "Array": [true], 62 "Bool": true, 63 "EmptyArray": [], 64 "EmptyObject": {}, 65 "Null": null, 66 "Number": 1, 67 "String": "...", 68 }); 69 let expected = indoc! {r#" 70 Object { 71 "Array": Array [ 72 Bool(true), 73 ], 74 "Bool": Bool(true), 75 "EmptyArray": Array [], 76 "EmptyObject": Object {}, 77 "Null": Null, 78 "Number": Number(1), 79 "String": String("..."), 80 }"# 81 }; 82 assert_eq!(format!("{:#?}", j), expected); 83 }