summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ron/tests/escape.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/ron/tests/escape.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/ron/tests/escape.rs')
-rw-r--r--third_party/rust/ron/tests/escape.rs77
1 files changed, 77 insertions, 0 deletions
diff --git a/third_party/rust/ron/tests/escape.rs b/third_party/rust/ron/tests/escape.rs
new file mode 100644
index 0000000000..48f5fdaa1d
--- /dev/null
+++ b/third_party/rust/ron/tests/escape.rs
@@ -0,0 +1,77 @@
+use ron::{de::from_str, ser::to_string};
+use serde::{Deserialize, Serialize};
+use std::{char::from_u32, fmt::Debug};
+
+#[test]
+fn test_escape_basic() {
+ assert_eq!(to_string(&"\x07").unwrap(), "\"\\u{7}\"");
+
+ assert_eq!(from_str::<String>("\"\\x07\"").unwrap(), "\x07");
+ assert_eq!(from_str::<String>("\"\\u{7}\"").unwrap(), "\x07");
+
+ assert_eq!(from_str::<char>("\'\\x07\'").unwrap(), '\x07');
+ assert_eq!(from_str::<char>("\'\\u{7}\'").unwrap(), '\x07');
+}
+
+fn check_same<T>(t: T)
+where
+ T: Debug + for<'a> Deserialize<'a> + PartialEq + Serialize,
+{
+ let s: String = to_string(&t).unwrap();
+
+ println!("Serialized: \n\n{}\n\n", s);
+
+ assert_eq!(from_str(&s), Ok(t));
+}
+
+#[test]
+fn test_ascii_10() {
+ check_same("\u{10}".to_owned());
+}
+
+#[test]
+fn test_ascii_chars() {
+ (1..128).into_iter().flat_map(from_u32).for_each(check_same)
+}
+
+#[test]
+fn test_ascii_string() {
+ let s: String = (1..128).into_iter().flat_map(from_u32).collect();
+
+ check_same(s);
+}
+
+#[test]
+fn test_non_ascii() {
+ assert_eq!(to_string(&"♠").unwrap(), "\"♠\"");
+ assert_eq!(to_string(&"ß").unwrap(), "\"ß\"");
+ assert_eq!(to_string(&"ä").unwrap(), "\"ä\"");
+ assert_eq!(to_string(&"ö").unwrap(), "\"ö\"");
+ assert_eq!(to_string(&"ü").unwrap(), "\"ü\"");
+}
+
+#[test]
+fn test_chars() {
+ assert_eq!(to_string(&'♠').unwrap(), "'♠'");
+ assert_eq!(to_string(&'ß').unwrap(), "'ß'");
+ assert_eq!(to_string(&'ä').unwrap(), "'ä'");
+ assert_eq!(to_string(&'ö').unwrap(), "'ö'");
+ assert_eq!(to_string(&'ü').unwrap(), "'ü'");
+ assert_eq!(to_string(&'\u{715}').unwrap(), "'\u{715}'");
+ assert_eq!(
+ from_str::<char>("'\u{715}'").unwrap(),
+ from_str("'\\u{715}'").unwrap()
+ );
+}
+
+#[test]
+fn test_nul_in_string() {
+ assert_eq!(
+ from_str("\"Hello\0World!\""),
+ Ok(String::from("Hello\0World!"))
+ );
+
+ check_same("Hello\0World!".to_owned());
+ check_same("Hello\x00World!".to_owned());
+ check_same("Hello\u{0}World!".to_owned());
+}