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

            
6
#[test]
7
4
fn test_hex() {
8
4
    assert_eq!(from_str("0x507"), Ok(0x507));
9
4
    assert_eq!(from_str("0x1A5"), Ok(0x1A5));
10
4
    assert_eq!(from_str("0x53C537"), Ok(0x53C537));
11

            
12
4
    assert_eq!(
13
4
        from_str::<u8>("0x"),
14
4
        Err(SpannedError {
15
4
            code: Error::ExpectedInteger,
16
4
            position: Position { line: 1, col: 3 },
17
4
        })
18
4
    );
19
4
    assert_eq!(
20
4
        from_str::<u8>("0x_1"),
21
4
        Err(SpannedError {
22
4
            code: Error::UnderscoreAtBeginning,
23
4
            position: Position { line: 1, col: 3 },
24
4
        })
25
4
    );
26
4
    assert_eq!(
27
4
        from_str::<u8>("0xFFF"),
28
4
        Err(SpannedError {
29
4
            code: Error::IntegerOutOfBounds,
30
4
            position: Position { line: 1, col: 6 },
31
4
        })
32
4
    );
33
4
}
34

            
35
#[test]
36
4
fn test_bin() {
37
4
    assert_eq!(from_str("0b101"), Ok(0b101));
38
4
    assert_eq!(from_str("0b001"), Ok(0b001));
39
4
    assert_eq!(from_str("0b100100"), Ok(0b100100));
40

            
41
4
    assert_eq!(
42
4
        from_str::<u8>("0b"),
43
4
        Err(SpannedError {
44
4
            code: Error::ExpectedInteger,
45
4
            position: Position { line: 1, col: 3 },
46
4
        })
47
4
    );
48
4
    assert_eq!(
49
4
        from_str::<u8>("0b_1"),
50
4
        Err(SpannedError {
51
4
            code: Error::UnderscoreAtBeginning,
52
4
            position: Position { line: 1, col: 3 },
53
4
        })
54
4
    );
55
4
    assert_eq!(
56
4
        from_str::<u8>("0b111111111"),
57
4
        Err(SpannedError {
58
4
            code: Error::IntegerOutOfBounds,
59
4
            position: Position { line: 1, col: 12 },
60
4
        })
61
4
    );
62
4
}
63

            
64
#[test]
65
4
fn test_oct() {
66
4
    assert_eq!(from_str("0o1461"), Ok(0o1461));
67
4
    assert_eq!(from_str("0o051"), Ok(0o051));
68
4
    assert_eq!(from_str("0o150700"), Ok(0o150700));
69

            
70
4
    assert_eq!(
71
4
        from_str::<u8>("0o"),
72
4
        Err(SpannedError {
73
4
            code: Error::ExpectedInteger,
74
4
            position: Position { line: 1, col: 3 },
75
4
        })
76
4
    );
77
4
    assert_eq!(
78
4
        from_str::<u8>("0o_1"),
79
4
        Err(SpannedError {
80
4
            code: Error::UnderscoreAtBeginning,
81
4
            position: Position { line: 1, col: 3 },
82
4
        })
83
4
    );
84
4
    assert_eq!(
85
4
        from_str::<u8>("0o77777"),
86
4
        Err(SpannedError {
87
4
            code: Error::IntegerOutOfBounds,
88
4
            position: Position { line: 1, col: 8 },
89
4
        })
90
4
    );
91
4
}
92

            
93
#[test]
94
4
fn test_dec() {
95
4
    assert_eq!(from_str("1461"), Ok(1461));
96
4
    assert_eq!(from_str("51"), Ok(51));
97
4
    assert_eq!(from_str("150700"), Ok(150700));
98

            
99
4
    assert_eq!(
100
4
        from_str::<i8>("-_1"),
101
4
        Err(SpannedError {
102
4
            code: Error::UnderscoreAtBeginning,
103
4
            position: Position { line: 1, col: 2 },
104
4
        })
105
4
    );
106
4
    assert_eq!(
107
4
        from_str::<u8>("256"),
108
4
        Err(SpannedError {
109
4
            code: Error::IntegerOutOfBounds,
110
4
            position: Position { line: 1, col: 4 },
111
4
        })
112
4
    );
113
4
}