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 | macro_rules! test( ($name:ident, $s:expr, $msg:expr) => ( |
13 | #[test] |
14 | fn $name() { bad!($s, $msg); } |
15 | ) ); |
16 | |
17 | test!( |
18 | datetime_malformed_no_leads, |
19 | include_str!("invalid/datetime-malformed-no-leads.toml" ), |
20 | "invalid number at line 1 column 12" |
21 | ); |
22 | test!( |
23 | datetime_malformed_no_secs, |
24 | include_str!("invalid/datetime-malformed-no-secs.toml" ), |
25 | "invalid number at line 1 column 11" |
26 | ); |
27 | test!( |
28 | datetime_malformed_no_t, |
29 | include_str!("invalid/datetime-malformed-no-t.toml" ), |
30 | "invalid number at line 1 column 8" |
31 | ); |
32 | test!( |
33 | datetime_malformed_with_milli, |
34 | include_str!("invalid/datetime-malformed-with-milli.toml" ), |
35 | "invalid number at line 1 column 14" |
36 | ); |
37 | test!( |
38 | duplicate_key_table, |
39 | include_str!("invalid/duplicate-key-table.toml" ), |
40 | "duplicate key: `type` for key `fruit` at line 4 column 8" |
41 | ); |
42 | test!( |
43 | duplicate_keys, |
44 | include_str!("invalid/duplicate-keys.toml" ), |
45 | "duplicate key: `dupe` at line 2 column 1" |
46 | ); |
47 | test!( |
48 | duplicate_table, |
49 | include_str!("invalid/duplicate-table.toml" ), |
50 | "redefinition of table `dependencies` for key `dependencies` at line 7 column 1" |
51 | ); |
52 | test!( |
53 | duplicate_tables, |
54 | include_str!("invalid/duplicate-tables.toml" ), |
55 | "redefinition of table `a` for key `a` at line 2 column 1" |
56 | ); |
57 | test!( |
58 | empty_implicit_table, |
59 | include_str!("invalid/empty-implicit-table.toml" ), |
60 | "expected a table key, found a period at line 1 column 10" |
61 | ); |
62 | test!( |
63 | empty_table, |
64 | include_str!("invalid/empty-table.toml" ), |
65 | "expected a table key, found a right bracket at line 1 column 2" |
66 | ); |
67 | test!( |
68 | float_no_leading_zero, |
69 | include_str!("invalid/float-no-leading-zero.toml" ), |
70 | "expected a value, found a period at line 1 column 10" |
71 | ); |
72 | test!( |
73 | float_no_suffix, |
74 | include_str!("invalid/float-no-suffix.toml" ), |
75 | "invalid number at line 1 column 5" |
76 | ); |
77 | test!( |
78 | float_no_trailing_digits, |
79 | include_str!("invalid/float-no-trailing-digits.toml" ), |
80 | "invalid number at line 1 column 12" |
81 | ); |
82 | test!( |
83 | key_after_array, |
84 | include_str!("invalid/key-after-array.toml" ), |
85 | "expected newline, found an identifier at line 1 column 14" |
86 | ); |
87 | test!( |
88 | key_after_table, |
89 | include_str!("invalid/key-after-table.toml" ), |
90 | "expected newline, found an identifier at line 1 column 11" |
91 | ); |
92 | test!( |
93 | key_empty, |
94 | include_str!("invalid/key-empty.toml" ), |
95 | "expected a table key, found an equals at line 1 column 2" |
96 | ); |
97 | test!( |
98 | key_hash, |
99 | include_str!("invalid/key-hash.toml" ), |
100 | "expected an equals, found a comment at line 1 column 2" |
101 | ); |
102 | test!( |
103 | key_newline, |
104 | include_str!("invalid/key-newline.toml" ), |
105 | "expected an equals, found a newline at line 1 column 2" |
106 | ); |
107 | test!( |
108 | key_open_bracket, |
109 | include_str!("invalid/key-open-bracket.toml" ), |
110 | "expected a right bracket, found an equals at line 1 column 6" |
111 | ); |
112 | test!( |
113 | key_single_open_bracket, |
114 | include_str!("invalid/key-single-open-bracket.toml" ), |
115 | "expected a table key, found eof at line 1 column 2" |
116 | ); |
117 | test!( |
118 | key_space, |
119 | include_str!("invalid/key-space.toml" ), |
120 | "expected an equals, found an identifier at line 1 column 3" |
121 | ); |
122 | test!( |
123 | key_start_bracket, |
124 | include_str!("invalid/key-start-bracket.toml" ), |
125 | "expected a right bracket, found an equals at line 2 column 6" |
126 | ); |
127 | test!( |
128 | key_two_equals, |
129 | include_str!("invalid/key-two-equals.toml" ), |
130 | "expected a value, found an equals at line 1 column 6" |
131 | ); |
132 | test!( |
133 | string_bad_byte_escape, |
134 | include_str!("invalid/string-bad-byte-escape.toml" ), |
135 | "invalid escape character in string: `x` at line 1 column 13" |
136 | ); |
137 | test!( |
138 | string_bad_escape, |
139 | include_str!("invalid/string-bad-escape.toml" ), |
140 | "invalid escape character in string: `a` at line 1 column 42" |
141 | ); |
142 | test!( |
143 | string_bad_line_ending_escape, |
144 | include_str!("invalid/string-bad-line-ending-escape.toml" ), |
145 | "invalid escape character in string: ` ` at line 2 column 79" |
146 | ); |
147 | test!( |
148 | string_byte_escapes, |
149 | include_str!("invalid/string-byte-escapes.toml" ), |
150 | "invalid escape character in string: `x` at line 1 column 12" |
151 | ); |
152 | test!( |
153 | string_no_close, |
154 | include_str!("invalid/string-no-close.toml" ), |
155 | "newline in string found at line 1 column 42" |
156 | ); |
157 | test!( |
158 | table_array_implicit, |
159 | include_str!("invalid/table-array-implicit.toml" ), |
160 | "table redefined as array for key `albums` at line 13 column 1" |
161 | ); |
162 | test!( |
163 | table_array_malformed_bracket, |
164 | include_str!("invalid/table-array-malformed-bracket.toml" ), |
165 | "expected a right bracket, found a newline at line 1 column 10" |
166 | ); |
167 | test!( |
168 | table_array_malformed_empty, |
169 | include_str!("invalid/table-array-malformed-empty.toml" ), |
170 | "expected a table key, found a right bracket at line 1 column 3" |
171 | ); |
172 | test!( |
173 | table_empty, |
174 | include_str!("invalid/table-empty.toml" ), |
175 | "expected a table key, found a right bracket at line 1 column 2" |
176 | ); |
177 | test!( |
178 | table_nested_brackets_close, |
179 | include_str!("invalid/table-nested-brackets-close.toml" ), |
180 | "expected newline, found an identifier at line 1 column 4" |
181 | ); |
182 | test!( |
183 | table_nested_brackets_open, |
184 | include_str!("invalid/table-nested-brackets-open.toml" ), |
185 | "expected a right bracket, found a left bracket at line 1 column 3" |
186 | ); |
187 | test!( |
188 | table_whitespace, |
189 | include_str!("invalid/table-whitespace.toml" ), |
190 | "expected a right bracket, found an identifier at line 1 column 10" |
191 | ); |
192 | test!( |
193 | table_with_pound, |
194 | include_str!("invalid/table-with-pound.toml" ), |
195 | "expected a right bracket, found a comment at line 1 column 5" |
196 | ); |
197 | test!( |
198 | text_after_array_entries, |
199 | include_str!("invalid/text-after-array-entries.toml" ), |
200 | "invalid TOML value, did you mean to use a quoted string? at line 2 column 46" |
201 | ); |
202 | test!( |
203 | text_after_integer, |
204 | include_str!("invalid/text-after-integer.toml" ), |
205 | "expected newline, found an identifier at line 1 column 13" |
206 | ); |
207 | test!( |
208 | text_after_string, |
209 | include_str!("invalid/text-after-string.toml" ), |
210 | "expected newline, found an identifier at line 1 column 41" |
211 | ); |
212 | test!( |
213 | text_after_table, |
214 | include_str!("invalid/text-after-table.toml" ), |
215 | "expected newline, found an identifier at line 1 column 9" |
216 | ); |
217 | test!( |
218 | text_before_array_separator, |
219 | include_str!("invalid/text-before-array-separator.toml" ), |
220 | "expected a right bracket, found an identifier at line 2 column 46" |
221 | ); |
222 | test!( |
223 | text_in_array, |
224 | include_str!("invalid/text-in-array.toml" ), |
225 | "invalid TOML value, did you mean to use a quoted string? at line 3 column 3" |
226 | ); |
227 | |