1
use ron::{
2
    de::{from_bytes, from_str},
3
    error::Position,
4
    Error, Value,
5
};
6

            
7
#[test]
8
4
fn test_char() {
9
4
    let de: char = from_str("'Փ'").unwrap();
10
4
    assert_eq!(de, 'Փ');
11
4
}
12

            
13
#[test]
14
4
fn test_string() {
15
4
    let de: String = from_str("\"My string: ऄ\"").unwrap();
16
4
    assert_eq!(de, "My string: ऄ");
17
4
}
18

            
19
#[test]
20
4
fn test_char_not_a_comment() {
21
4
    let _ = from_str::<ron::Value>("A('/')").unwrap();
22
4
}
23

            
24
#[test]
25
4
fn ident_starts_with_non_ascii_byte() {
26
4
    let _ = from_str::<Value>("שּׁȬSSSSSSSSSSR").unwrap();
27
4
}
28

            
29
#[test]
30
4
fn test_file_invalid_unicode() {
31
4
    let error = from_bytes::<Value>(&[b'\n', b'a', 0b11000000, 0]).unwrap_err();
32
4
    assert!(matches!(error.code, Error::Utf8Error(_)));
33
4
    assert_eq!(error.position, Position { line: 2, col: 2 });
34
4
    let error = from_bytes::<Value>(&[b'\n', b'\n', 0b11000000]).unwrap_err();
35
4
    assert!(matches!(error.code, Error::Utf8Error(_)));
36
4
    assert_eq!(error.position, Position { line: 3, col: 1 });
37
4
}
38

            
39
#[test]
40
4
fn serialize_invalid_whitespace() {
41
4
    assert_eq!(
42
4
        ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().new_line("a"))
43
4
            .unwrap_err(),
44
4
        Error::Message(String::from(
45
4
            "Invalid non-whitespace `PrettyConfig::new_line`"
46
4
        ))
47
4
    );
48
4
    assert_eq!(
49
4
        ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().indentor("a"))
50
4
            .unwrap_err(),
51
4
        Error::Message(String::from(
52
4
            "Invalid non-whitespace `PrettyConfig::indentor`"
53
4
        ))
54
4
    );
55
4
    assert_eq!(
56
4
        ron::ser::to_string_pretty(&42, ron::ser::PrettyConfig::default().separator("a"))
57
4
            .unwrap_err(),
58
4
        Error::Message(String::from(
59
4
            "Invalid non-whitespace `PrettyConfig::separator`"
60
4
        ))
61
4
    );
62
4
}