interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

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
3use indoc::indoc;
4use serde_json::{json, Number, Value};
5
6#[test]
7fn 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]
17fn value_null() {
18 assert_eq!(format!("{:?}", json!(null)), "Null");
19}
20
21#[test]
22fn value_bool() {
23 assert_eq!(format!("{:?}", json!(true)), "Bool(true)");
24 assert_eq!(format!("{:?}", json!(false)), "Bool(false)");
25}
26
27#[test]
28fn 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]
37fn value_string() {
38 assert_eq!(format!("{:?}", json!("s")), "String(\"s\")");
39}
40
41#[test]
42fn value_array() {
43 assert_eq!(format!("{:?}", json!([])), "Array []");
44}
45
46#[test]
47fn value_object() {
48 assert_eq!(format!("{:?}", json!({})), "Object {}");
49}
50
51#[test]
52fn error() {
53 let err = serde_json::from_str::<Value>("{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]
59fn 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}