1
use ron::de::{from_str, Error, Position, SpannedError as RonErr};
2

            
3
#[test]
4
4
fn test_simple() {
5
4
    assert_eq!(
6
4
        from_str(
7
4
            "/*
8
4
 * We got a hexadecimal number here!
9
4
 *
10
4
 */0x507"
11
4
        ),
12
4
        Ok(0x507)
13
4
    );
14
4
}
15

            
16
#[test]
17
4
fn test_nested() {
18
4
    assert_eq!(
19
4
        from_str(
20
4
            "/*
21
4
        /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
22
4
    */
23
4
    // The actual value comes.. /*
24
4
    // very soon, these are just checks that */
25
4
    // multi-line comments don't trigger in line comments /*
26
4
\"THE VALUE\" /* This is the value /* :) */ */
27
4
    "
28
4
        ),
29
4
        Ok("THE VALUE".to_owned())
30
4
    );
31
4
}
32

            
33
#[test]
34
4
fn test_unclosed() {
35
4
    assert_eq!(
36
4
        from_str::<String>("\"hi\" /*"),
37
4
        Err(RonErr {
38
4
            code: Error::UnclosedBlockComment,
39
4
            position: Position { line: 1, col: 8 }
40
4
        })
41
4
    );
42
4
    assert_eq!(
43
4
        from_str::<String>(
44
4
            "/*
45
4
        /* quite * some * nesting * going * on * /* here /* (yeah, maybe a bit too much) */ */ */
46
4
    */
47
4
    // The actual value comes.. /*
48
4
    // very soon, these are just checks that */
49
4
    // multi-line comments don't trigger in line comments /*
50
4
/* Unfortunately, this comment won't get closed :(
51
4
\"THE VALUE (which is invalid)\"
52
4
"
53
4
        ),
54
4
        Err(RonErr {
55
4
            code: Error::UnclosedBlockComment,
56
4
            position: Position { line: 9, col: 1 }
57
4
        })
58
4
    );
59
4
}
60

            
61
#[test]
62
4
fn test_unexpected_byte() {
63
4
    assert_eq!(
64
4
        from_str::<u8>("42 /q"),
65
4
        Err(RonErr {
66
4
            code: Error::UnexpectedChar('q'),
67
4
            position: Position { line: 1, col: 6 },
68
4
        })
69
4
    );
70
4
}