summaryrefslogtreecommitdiffstats
path: root/vendor/write-json/tests/tests.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /vendor/write-json/tests/tests.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/write-json/tests/tests.rs')
-rw-r--r--vendor/write-json/tests/tests.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/vendor/write-json/tests/tests.rs b/vendor/write-json/tests/tests.rs
new file mode 100644
index 000000000..116c06a26
--- /dev/null
+++ b/vendor/write-json/tests/tests.rs
@@ -0,0 +1,47 @@
+#[test]
+fn smoke() {
+ let mut buf = String::new();
+
+ {
+ let mut obj = write_json::object(&mut buf);
+ obj.string("name", "Peter").number("favorite number", 92.0);
+ obj.array("films")
+ .string("Drowning By Numbers")
+ .string("A Zed & Two Noughts");
+ obj.null("suitcase");
+ }
+
+ assert_eq!(
+ buf,
+ r#"{"name":"Peter","favorite number":92,"films":["Drowning By Numbers","A Zed & Two Noughts"],"suitcase":null}"#
+ )
+}
+
+#[test]
+fn string_escaping() {
+ let mut buf = String::new();
+ {
+ write_json::array(&mut buf)
+ .string("")
+ .string("'")
+ .string("\"")
+ .string("\\")
+ .string("hello world")
+ .string(" \r\n\t\\ \\r\\n\\t")
+ .string("❤😂")
+ .string("\x00\x07\x1F\x20\x7E\x7F\u{80}\u{9f}!");
+ }
+ let strings = buf.replace(|c: char| "[],".contains(c), "\n");
+ let expected = r#"
+""
+"'"
+"\""
+"\\"
+"hello world"
+" \r\n\t\\ \\r\\n\\t"
+"❤\u0020"
+"\u0000\u0070\u00F1 ~\u00F7\u0008\u00F9!"
+"#;
+
+ assert_eq!(strings, expected);
+}