1 | use serde_json::Value; |
2 | |
3 | macro_rules! bad { |
4 | ($toml:expr, $msg:expr) => { |
5 | match basic_toml::from_str::<Value>($toml) { |
6 | Ok(s) => panic!("parsed to: {:#?}" , s), |
7 | Err(e) => assert_eq!(e.to_string(), $msg), |
8 | } |
9 | }; |
10 | } |
11 | |
12 | #[test] |
13 | fn bad() { |
14 | bad!("a = 01" , "invalid number at line 1 column 6" ); |
15 | bad!("a = 1__1" , "invalid number at line 1 column 5" ); |
16 | bad!("a = 1_" , "invalid number at line 1 column 5" ); |
17 | bad!("''" , "expected an equals, found eof at line 1 column 3" ); |
18 | bad!("a = 9e99999" , "invalid number at line 1 column 5" ); |
19 | |
20 | bad!( |
21 | "a = \"\u{7f}\"" , |
22 | "invalid character in string: ` \\u{7f}` at line 1 column 6" |
23 | ); |
24 | bad!( |
25 | "a = ' \u{7f}'" , |
26 | "invalid character in string: ` \\u{7f}` at line 1 column 6" |
27 | ); |
28 | |
29 | bad!("a = -0x1" , "invalid number at line 1 column 5" ); |
30 | bad!("a = 0x-1" , "invalid number at line 1 column 7" ); |
31 | |
32 | // Dotted keys. |
33 | bad!( |
34 | "a.b.c = 1 |
35 | a.b = 2 |
36 | " , |
37 | "duplicate key: `b` for key `a` at line 2 column 12" |
38 | ); |
39 | bad!( |
40 | "a = 1 |
41 | a.b = 2" , |
42 | "dotted key attempted to extend non-table type at line 1 column 5" |
43 | ); |
44 | bad!( |
45 | "a = {k1 = 1, k1.name = \"joe \"}" , |
46 | "dotted key attempted to extend non-table type at line 1 column 11" |
47 | ); |
48 | } |
49 | |