1
#![allow(dead_code)]
2

            
3
use ron::error::{Error, Position, SpannedError};
4

            
5
8
#[derive(Debug, serde::Deserialize)]
6
struct Test {
7
    a: i32,
8
    b: i32,
9
}
10

            
11
#[test]
12
4
fn test_missing_comma_error() {
13
4
    let tuple_string = r#"(
14
4
        1 // <-- forgotten comma here
15
4
        2
16
4
    )"#;
17
4

            
18
4
    assert_eq!(
19
4
        ron::from_str::<(i32, i32)>(tuple_string).unwrap_err(),
20
4
        SpannedError {
21
4
            code: Error::ExpectedComma,
22
4
            position: Position { line: 3, col: 9 }
23
4
        }
24
4
    );
25

            
26
4
    let list_string = r#"[
27
4
        0,
28
4
        1 // <-- forgotten comma here
29
4
        2
30
4
    ]"#;
31
4

            
32
4
    assert_eq!(
33
4
        ron::from_str::<Vec<i32>>(list_string).unwrap_err(),
34
4
        SpannedError {
35
4
            code: Error::ExpectedComma,
36
4
            position: Position { line: 4, col: 9 }
37
4
        }
38
4
    );
39

            
40
4
    let struct_string = r#"Test(
41
4
        a: 1 // <-- forgotten comma here
42
4
        b: 2
43
4
    )"#;
44
4

            
45
4
    assert_eq!(
46
4
        ron::from_str::<Test>(struct_string).unwrap_err(),
47
4
        SpannedError {
48
4
            code: Error::ExpectedComma,
49
4
            position: Position { line: 3, col: 9 }
50
4
        }
51
4
    );
52

            
53
4
    let map_string = r#"{
54
4
        "a": 1 // <-- forgotten comma here
55
4
        "b": 2
56
4
    }"#;
57
4

            
58
4
    assert_eq!(
59
4
        ron::from_str::<std::collections::HashMap<String, i32>>(map_string).unwrap_err(),
60
4
        SpannedError {
61
4
            code: Error::ExpectedComma,
62
4
            position: Position { line: 3, col: 9 }
63
4
        }
64
4
    );
65

            
66
4
    let extensions_string = r#"#![enable(
67
4
        implicit_some // <-- forgotten comma here
68
4
        unwrap_newtypes
69
4
    ]) 42"#;
70
4

            
71
4
    assert_eq!(
72
4
        ron::from_str::<u8>(extensions_string).unwrap_err(),
73
4
        SpannedError {
74
4
            code: Error::ExpectedComma,
75
4
            position: Position { line: 3, col: 9 }
76
4
        }
77
4
    );
78
4
}
79

            
80
#[test]
81
4
fn test_comma_end() {
82
4
    assert_eq!(ron::from_str::<(i32, i32)>("(0, 1)").unwrap(), (0, 1));
83
4
    assert_eq!(ron::from_str::<(i32, i32)>("(0, 1,)").unwrap(), (0, 1));
84
4
    assert_eq!(ron::from_str::<()>("()"), Ok(()));
85
4
}