Debian Codegraph @

tests/escape.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{charrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/::from_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/from_u32()., fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#};
2
3 use ronrust-analyzer cargo ron 0.12.0 crate/::{derust-analyzer cargo ron 0.12.0 de/::from_strrust-analyzer cargo ron 0.12.0 de/from_str()., serrust-analyzer cargo ron 0.12.0 ser/::to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().};
4 use serderust-analyzer cargo serde 1.0.228 crate/::{Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#, Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#};
5
6 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
7 fn test_escape_basicrust-analyzer cargo ron 0.12.0 test_escape_basic().() {
8 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"\x07").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"\\u{7}\"");
9
10 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>("\"\\x07\"").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\x07");
11 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>("\"\\u{7}\"").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\x07");
12
13 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<char>("\'\\x07\'").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), '\x07');
14 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<char>("\'\\u{7}\'").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), '\x07');
15
16 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
17 from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<char>("\'\\u{}\'").unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(),
18 ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::SpannedErrorrust-analyzer cargo ron 0.12.0 error/SpannedError# {
19 coderust-analyzer cargo ron 0.12.0 error/SpannedError#code.: ronrust-analyzer cargo ron 0.12.0 crate/::Errorrust-analyzer cargo ron 0.12.0 error/Error#::InvalidEscaperust-analyzer cargo ron 0.12.0 error/Error#InvalidEscape#("Expected 1-6 digits, got 0 digits in Unicode escape"),
20 spanrust-analyzer cargo ron 0.12.0 error/SpannedError#span.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Spanrust-analyzer cargo ron 0.12.0 error/Span# {
21 startrust-analyzer cargo ron 0.12.0 error/Span#start.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 4 },
22 endrust-analyzer cargo ron 0.12.0 error/Span#end.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 5 },
23 }
24 }
25 );
26
27 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
28 from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<char>("\'\\q\'").unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(),
29 ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::SpannedErrorrust-analyzer cargo ron 0.12.0 error/SpannedError# {
30 coderust-analyzer cargo ron 0.12.0 error/SpannedError#code.: ronrust-analyzer cargo ron 0.12.0 crate/::Errorrust-analyzer cargo ron 0.12.0 error/Error#::InvalidEscaperust-analyzer cargo ron 0.12.0 error/Error#InvalidEscape#("Unknown escape character"),
31 spanrust-analyzer cargo ron 0.12.0 error/SpannedError#span.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Spanrust-analyzer cargo ron 0.12.0 error/Span# {
32 startrust-analyzer cargo ron 0.12.0 error/Span#start.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 1 },
33 endrust-analyzer cargo ron 0.12.0 error/Span#end.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 4 },
34 }
35 }
36 )
37 }
38
39 fn check_samerust-analyzer cargo ron 0.12.0 check_same().<T>(t: T)
40 where
41 T: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# + for<'a> Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#<'a> + PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# + Serializerust-analyzer cargo serde_core 1.0.228 ser/Serialize#,
42 {
43 let s: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&t).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
44
45 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("Serialized: \n\n{}\n\n", s);
46
47 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_strrust-analyzer cargo ron 0.12.0 de/from_str().(&s), Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(t));
48 }
49
50 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
51 fn test_ascii_10rust-analyzer cargo ron 0.12.0 test_ascii_10().() {
52 check_samerust-analyzer cargo ron 0.12.0 check_same().("\u{10}".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
53 }
54
55 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
56 fn test_ascii_charsrust-analyzer cargo ron 0.12.0 test_ascii_chars().() {
57 (1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#128).flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(from_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/from_u32().).for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(check_samerust-analyzer cargo ron 0.12.0 check_same().)
58 }
59
60 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
61 fn test_ascii_stringrust-analyzer cargo ron 0.12.0 test_ascii_string().() {
62 let s: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = (1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#128).flat_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flat_map().(from_u32rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/from_u32().).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
63
64 check_samerust-analyzer cargo ron 0.12.0 check_same().(s);
65 }
66
67 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
68 fn test_non_asciirust-analyzer cargo ron 0.12.0 test_non_ascii().() {
69 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"♠").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"♠\"");
70 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"ß").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"ß\"");
71 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"ä").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"ä\"");
72 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"ö").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"ö\"");
73 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&"ü").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "\"ü\"");
74 }
75
76 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
77 fn test_charsrust-analyzer cargo ron 0.12.0 test_chars().() {
78 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'♠').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'♠'");
79 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'ß').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'ß'");
80 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'ä').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'ä'");
81 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'ö').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'ö'");
82 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'ü').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'ü'");
83 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(to_stringrust-analyzer cargo ron 0.12.0 ser/to_string().(&'\u{715}').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), "'\u{715}'");
84 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
85 from_strrust-analyzer cargo ron 0.12.0 de/from_str().::<char>("'\u{715}'").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(),
86 from_strrust-analyzer cargo ron 0.12.0 de/from_str().("'\\u{715}'").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
87 );
88 }
89
90 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
91 fn test_nul_in_stringrust-analyzer cargo ron 0.12.0 test_nul_in_string().() {
92 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
93 from_strrust-analyzer cargo ron 0.12.0 de/from_str().("\"Hello\0World!\""),
94 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("Hello\0World!"))
95 );
96
97 check_samerust-analyzer cargo ron 0.12.0 check_same().("Hello\0World!".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
98 check_samerust-analyzer cargo ron 0.12.0 check_same().("Hello\x00World!".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
99 check_samerust-analyzer cargo ron 0.12.0 check_same().("Hello\u{0}World!".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().());
100 }