1 use snapbox::assert_data_eq;
2 use snapbox::prelude::*;
3 use snapbox::str;
4
5 #[test]
incomplete_inline_table_issue_296()6 fn incomplete_inline_table_issue_296() {
7 let err = "native = {".parse::<toml_edit::DocumentMut>().unwrap_err();
8 assert_data_eq!(
9 err.to_string(),
10 str![[r#"
11 TOML parse error at line 1, column 11
12 |
13 1 | native = {
14 | ^
15 invalid inline table
16 expected `}`
17
18 "#]]
19 .raw()
20 );
21 }
22
23 #[test]
bare_value_disallowed_issue_293()24 fn bare_value_disallowed_issue_293() {
25 let err = "value=zzz".parse::<toml_edit::DocumentMut>().unwrap_err();
26 assert_data_eq!(
27 err.to_string(),
28 str![[r#"
29 TOML parse error at line 1, column 7
30 |
31 1 | value=zzz
32 | ^
33 invalid string
34 expected `"`, `'`
35
36 "#]]
37 .raw()
38 );
39 }
40
41 #[test]
bare_value_in_array_disallowed_issue_293()42 fn bare_value_in_array_disallowed_issue_293() {
43 let err = "value=[zzz]".parse::<toml_edit::DocumentMut>().unwrap_err();
44 assert_data_eq!(
45 err.to_string(),
46 str![[r#"
47 TOML parse error at line 1, column 8
48 |
49 1 | value=[zzz]
50 | ^
51 invalid array
52 expected `]`
53
54 "#]]
55 .raw()
56 );
57 }
58
59 #[test]
duplicate_table_after_dotted_key_issue_509()60 fn duplicate_table_after_dotted_key_issue_509() {
61 let err = "
62 [dependencies.foo]
63 version = \"0.16\"
64
65 [dependencies]
66 libc = \"0.2\"
67
68 [dependencies]
69 rand = \"0.3.14\"
70 "
71 .parse::<toml_edit::DocumentMut>()
72 .unwrap_err();
73 assert_data_eq!(
74 err.to_string(),
75 str![[r#"
76 TOML parse error at line 8, column 1
77 |
78 8 | [dependencies]
79 | ^
80 invalid table header
81 duplicate key `dependencies` in document root
82
83 "#]]
84 .raw()
85 );
86 }
87
88 #[test]
bad()89 fn bad() {
90 let toml_input = "a = 01";
91 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
92 assert_data_eq!(
93 err.to_string(),
94 str![[r#"
95 TOML parse error at line 1, column 6
96 |
97 1 | a = 01
98 | ^
99 expected newline, `#`
100
101 "#]]
102 .raw()
103 );
104
105 let toml_input = "a = 1__1";
106 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
107 assert_data_eq!(
108 err.to_string(),
109 str![[r#"
110 TOML parse error at line 1, column 7
111 |
112 1 | a = 1__1
113 | ^
114 invalid integer
115 expected digit
116
117 "#]]
118 .raw()
119 );
120
121 let toml_input = "a = 1_";
122 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
123 assert_data_eq!(
124 err.to_string(),
125 str![[r#"
126 TOML parse error at line 1, column 7
127 |
128 1 | a = 1_
129 | ^
130 invalid integer
131 expected digit
132
133 "#]]
134 .raw()
135 );
136
137 let toml_input = "''";
138 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
139 assert_data_eq!(
140 err.to_string(),
141 str![[r#"
142 TOML parse error at line 1, column 3
143 |
144 1 | ''
145 | ^
146 expected `.`, `=`
147
148 "#]]
149 .raw()
150 );
151
152 let toml_input = "a = 9e99999";
153 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
154 assert_data_eq!(
155 err.to_string(),
156 str![[r#"
157 TOML parse error at line 1, column 5
158 |
159 1 | a = 9e99999
160 | ^
161 invalid floating-point number
162
163 "#]]
164 .raw()
165 );
166
167 let toml_input = "a = \"\u{7f}\"";
168 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
169 assert_data_eq!(
170 err.to_string(),
171 str![[r#"
172 TOML parse error at line 1, column 6
173 |
174 1 | a = ""
175 | ^
176 invalid basic string
177
178 "#]]
179 .raw()
180 );
181
182 let toml_input = "a = '\u{7f}'";
183 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
184 assert_data_eq!(
185 err.to_string(),
186 str![[r#"
187 TOML parse error at line 1, column 6
188 |
189 1 | a = ''
190 | ^
191 invalid literal string
192
193 "#]]
194 .raw()
195 );
196
197 let toml_input = "a = -0x1";
198 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
199 assert_data_eq!(
200 err.to_string(),
201 str![[r#"
202 TOML parse error at line 1, column 7
203 |
204 1 | a = -0x1
205 | ^
206 expected newline, `#`
207
208 "#]]
209 .raw()
210 );
211
212 let toml_input = "a = 0x-1";
213 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
214 assert_data_eq!(
215 err.to_string(),
216 str![[r#"
217 TOML parse error at line 1, column 7
218 |
219 1 | a = 0x-1
220 | ^
221 invalid hexadecimal integer
222
223 "#]]
224 .raw()
225 );
226
227 // Dotted keys.
228 let toml_input = "a.b.c = 1
229 a.b = 2
230 ";
231 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
232 assert_data_eq!(
233 err.to_string(),
234 str![[r#"
235 TOML parse error at line 2, column 10
236 |
237 2 | a.b = 2
238 | ^
239 duplicate key `b` in document root
240
241 "#]]
242 .raw()
243 );
244
245 let toml_input = "a = 1
246 a.b = 2";
247 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
248 assert_data_eq!(
249 err.to_string(),
250 str![[r#"
251 TOML parse error at line 2, column 10
252 |
253 2 | a.b = 2
254 | ^
255 dotted key `a` attempted to extend non-table type (integer)
256
257 "#]]
258 .raw()
259 );
260
261 let toml_input = "a = {k1 = 1, k1.name = \"joe\"}";
262 let err = toml_input.parse::<toml_edit::DocumentMut>().unwrap_err();
263 assert_data_eq!(
264 err.to_string(),
265 str![[r#"
266 TOML parse error at line 1, column 6
267 |
268 1 | a = {k1 = 1, k1.name = "joe"}
269 | ^
270 dotted key `k1` attempted to extend non-table type (integer)
271
272 "#]]
273 .raw()
274 );
275 }
276
277 #[test]
emoji_error_span()278 fn emoji_error_span() {
279 let input = "";
280 let err = input.parse::<toml_edit::DocumentMut>().unwrap_err();
281 dbg!(err.span());
282 let actual = &input[err.span().unwrap()];
283 assert_eq!(actual, input);
284 }
285
286 #[test]
text_error_span()287 fn text_error_span() {
288 let input = "asdf";
289 let err = input.parse::<toml_edit::DocumentMut>().unwrap_err();
290 dbg!(err.span());
291 let actual = &input[err.span().unwrap()];
292 assert_eq!(actual, "");
293 }
294
295 #[test]
fuzzed_68144_error_span()296 fn fuzzed_68144_error_span() {
297 let input = "\"\\ᾂr\"";
298 let err = input.parse::<toml_edit::DocumentMut>().unwrap_err();
299 dbg!(err.span());
300 let actual = &input[err.span().unwrap()];
301 assert_eq!(actual, "ᾂ");
302 }
303