summaryrefslogtreecommitdiffstats
path: root/third_party/rust/serde_json/tests/debug.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/serde_json/tests/debug.rs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/serde_json/tests/debug.rs')
-rw-r--r--third_party/rust/serde_json/tests/debug.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/third_party/rust/serde_json/tests/debug.rs b/third_party/rust/serde_json/tests/debug.rs
new file mode 100644
index 0000000000..8ddcf5a381
--- /dev/null
+++ b/third_party/rust/serde_json/tests/debug.rs
@@ -0,0 +1,81 @@
+use indoc::indoc;
+use serde_json::{json, Number, Value};
+
+#[test]
+fn number() {
+ assert_eq!(format!("{:?}", Number::from(1)), "Number(1)");
+ assert_eq!(format!("{:?}", Number::from(-1)), "Number(-1)");
+ assert_eq!(
+ format!("{:?}", Number::from_f64(1.0).unwrap()),
+ "Number(1.0)"
+ );
+}
+
+#[test]
+fn value_null() {
+ assert_eq!(format!("{:?}", json!(null)), "Null");
+}
+
+#[test]
+fn value_bool() {
+ assert_eq!(format!("{:?}", json!(true)), "Bool(true)");
+ assert_eq!(format!("{:?}", json!(false)), "Bool(false)");
+}
+
+#[test]
+fn value_number() {
+ assert_eq!(format!("{:?}", json!(1)), "Number(1)");
+ assert_eq!(format!("{:?}", json!(-1)), "Number(-1)");
+ assert_eq!(format!("{:?}", json!(1.0)), "Number(1.0)");
+ assert_eq!(Number::from_f64(1.0).unwrap().to_string(), "1.0"); // not just "1"
+ assert_eq!(Number::from_f64(12e40).unwrap().to_string(), "1.2e41");
+}
+
+#[test]
+fn value_string() {
+ assert_eq!(format!("{:?}", json!("s")), "String(\"s\")");
+}
+
+#[test]
+fn value_array() {
+ assert_eq!(format!("{:?}", json!([])), "Array []");
+}
+
+#[test]
+fn value_object() {
+ assert_eq!(format!("{:?}", json!({})), "Object {}");
+}
+
+#[test]
+fn error() {
+ let err = serde_json::from_str::<Value>("{0}").unwrap_err();
+ let expected = "Error(\"key must be a string\", line: 1, column: 2)";
+ assert_eq!(format!("{:?}", err), expected);
+}
+
+#[test]
+fn indented() {
+ let j = json!({
+ "Array": [true],
+ "Bool": true,
+ "EmptyArray": [],
+ "EmptyObject": {},
+ "Null": null,
+ "Number": 1,
+ "String": "...",
+ });
+ let expected = indoc! {r#"
+ Object {
+ "Array": Array [
+ Bool(true),
+ ],
+ "Bool": Bool(true),
+ "EmptyArray": Array [],
+ "EmptyObject": Object {},
+ "Null": Null,
+ "Number": Number(1),
+ "String": String("..."),
+ }"#
+ };
+ assert_eq!(format!("{:#?}", j), expected);
+}