Debian Codegraph @

third_party/rust/ron/tests/unicode.rs

raw
1 use ron::{
2 de::{from_bytes, from_str},
3 error::Position,
4 Error, Value,
5 };
6
7 #[test]
8 fn test_char() {
9 let de: char = from_str("'Փ'").unwrap();
10 assert_eq!(de, 'Փ');
11 }
12
13 #[test]
14 fn test_string() {
15 let de: String = from_str("\"My string: ऄ\"").unwrap();
16 assert_eq!(de, "My string: ऄ");
17 }
18
19 #[test]
20 fn test_char_not_a_comment() {
21 let _ = from_str::<ron::Value>("A('/')").unwrap();
22 }
23
24 #[test]
25 fn ident_starts_with_non_ascii_byte() {
26 let _ = from_str::<Value>("שּׁȬSSSSSSSSSSR").unwrap();
27 }
28
29 #[test]
30 fn test_file_invalid_unicode() {
31 let error = from_bytes::<Value>(&[b'\n', b'a', 0b11000000, 0]).unwrap_err();
32 assert!(matches!(error.code, Error::Utf8Error(_)));
33 assert_eq!(error.position, Position { line: 2, col: 2 });
34 let error = from_bytes::<Value>(&[b'\n', b'\n', 0b11000000]).unwrap_err();
35 assert!(matches!(error.code, Error::Utf8Error(_)));
36 assert_eq!(error.position, Position { line: 3, col: 1 });
37 }
38
39 #[test]
40 fn serialize_invalid_whitespace() {
41 assert_eq!(
42 ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().new_line("a"))
43 .unwrap_err(),
44 Error::Message(String::from(
45 "Invalid non-whitespace `PrettyConfig::new_line`"
46 ))
47 );
48 assert_eq!(
49 ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().indentor("a"))
50 .unwrap_err(),
51 Error::Message(String::from(
52 "Invalid non-whitespace `PrettyConfig::indentor`"
53 ))
54 );
55 assert_eq!(
56 ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().separator("a"))
57 .unwrap_err(),
58 Error::Message(String::from(
59 "Invalid non-whitespace `PrettyConfig::separator`"
60 ))
61 );
62 }