1use serde_json::Value;
2
3macro_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
12macro_rules! test( ($name:ident, $s:expr, $msg:expr) => (
13 #[test]
14 fn $name() { bad!($s, $msg); }
15) );
16
17test!(
18 datetime_malformed_no_leads,
19 include_str!("invalid/datetime-malformed-no-leads.toml"),
20 "invalid number at line 1 column 12"
21);
22test!(
23 datetime_malformed_no_secs,
24 include_str!("invalid/datetime-malformed-no-secs.toml"),
25 "invalid number at line 1 column 11"
26);
27test!(
28 datetime_malformed_no_t,
29 include_str!("invalid/datetime-malformed-no-t.toml"),
30 "invalid number at line 1 column 8"
31);
32test!(
33 datetime_malformed_with_milli,
34 include_str!("invalid/datetime-malformed-with-milli.toml"),
35 "invalid number at line 1 column 14"
36);
37test!(
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);
42test!(
43 duplicate_keys,
44 include_str!("invalid/duplicate-keys.toml"),
45 "duplicate key: `dupe` at line 2 column 1"
46);
47test!(
48 duplicate_table,
49 include_str!("invalid/duplicate-table.toml"),
50 "redefinition of table `dependencies` for key `dependencies` at line 7 column 1"
51);
52test!(
53 duplicate_tables,
54 include_str!("invalid/duplicate-tables.toml"),
55 "redefinition of table `a` for key `a` at line 2 column 1"
56);
57test!(
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);
62test!(
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);
67test!(
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);
72test!(
73 float_no_suffix,
74 include_str!("invalid/float-no-suffix.toml"),
75 "invalid number at line 1 column 5"
76);
77test!(
78 float_no_trailing_digits,
79 include_str!("invalid/float-no-trailing-digits.toml"),
80 "invalid number at line 1 column 12"
81);
82test!(
83 key_after_array,
84 include_str!("invalid/key-after-array.toml"),
85 "expected newline, found an identifier at line 1 column 14"
86);
87test!(
88 key_after_table,
89 include_str!("invalid/key-after-table.toml"),
90 "expected newline, found an identifier at line 1 column 11"
91);
92test!(
93 key_empty,
94 include_str!("invalid/key-empty.toml"),
95 "expected a table key, found an equals at line 1 column 2"
96);
97test!(
98 key_hash,
99 include_str!("invalid/key-hash.toml"),
100 "expected an equals, found a comment at line 1 column 2"
101);
102test!(
103 key_newline,
104 include_str!("invalid/key-newline.toml"),
105 "expected an equals, found a newline at line 1 column 2"
106);
107test!(
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);
112test!(
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);
117test!(
118 key_space,
119 include_str!("invalid/key-space.toml"),
120 "expected an equals, found an identifier at line 1 column 3"
121);
122test!(
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);
127test!(
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);
132test!(
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);
137test!(
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);
142test!(
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);
147test!(
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);
152test!(
153 string_no_close,
154 include_str!("invalid/string-no-close.toml"),
155 "newline in string found at line 1 column 42"
156);
157test!(
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);
162test!(
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);
167test!(
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);
172test!(
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);
177test!(
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);
182test!(
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);
187test!(
188 table_whitespace,
189 include_str!("invalid/table-whitespace.toml"),
190 "expected a right bracket, found an identifier at line 1 column 10"
191);
192test!(
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);
197test!(
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);
202test!(
203 text_after_integer,
204 include_str!("invalid/text-after-integer.toml"),
205 "expected newline, found an identifier at line 1 column 13"
206);
207test!(
208 text_after_string,
209 include_str!("invalid/text-after-string.toml"),
210 "expected newline, found an identifier at line 1 column 41"
211);
212test!(
213 text_after_table,
214 include_str!("invalid/text-after-table.toml"),
215 "expected newline, found an identifier at line 1 column 9"
216);
217test!(
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);
222test!(
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