1
- use serde:: { de, Deserialize } ;
2
1
use std:: fmt;
3
2
3
+ use serde:: { de, Deserialize } ;
4
+ use snapbox:: assert_data_eq;
5
+ use snapbox:: prelude:: * ;
6
+ use snapbox:: str;
7
+
4
8
macro_rules! bad {
5
9
( $toml: expr, $ty: ty, $msg: expr) => {
6
10
match toml:: from_str:: <$ty>( $toml) {
7
11
Ok ( s) => panic!( "parsed to: {:#?}" , s) ,
8
- Err ( e) => snapbox :: assert_eq ( $msg , e. to_string( ) ) ,
12
+ Err ( e) => assert_data_eq! ( e. to_string( ) , $msg . raw ( ) ) ,
9
13
}
10
14
} ;
11
15
}
@@ -83,13 +87,14 @@ fn custom_errors() {
83
87
# ^
84
88
" ,
85
89
Parent <CasedString >,
86
- " \
90
+ str ! [ [ r#"
87
91
TOML parse error at line 2, column 19
88
92
|
89
93
2 | p_a = ''
90
94
| ^^
91
95
invalid length 0, expected a non-empty string
92
- "
96
+
97
+ "# ] ]
93
98
) ;
94
99
95
100
// Missing field in table.
@@ -99,13 +104,14 @@ invalid length 0, expected a non-empty string
99
104
# ^
100
105
" ,
101
106
Parent <CasedString >,
102
- " \
107
+ str ! [ [ r#"
103
108
TOML parse error at line 1, column 1
104
109
|
105
110
1 |
106
111
| ^
107
112
missing field `p_b`
108
- "
113
+
114
+ "# ] ]
109
115
) ;
110
116
111
117
// Invalid type in p_b.
@@ -116,13 +122,14 @@ missing field `p_b`
116
122
# ^
117
123
" ,
118
124
Parent <CasedString >,
119
- " \
125
+ str ! [ [ r#"
120
126
TOML parse error at line 3, column 19
121
127
|
122
128
3 | p_b = 1
123
129
| ^
124
130
invalid type: integer `1`, expected a sequence
125
- "
131
+
132
+ "# ] ]
126
133
) ;
127
134
128
135
// Sub-table in Vec is missing a field.
@@ -135,13 +142,14 @@ invalid type: integer `1`, expected a sequence
135
142
]
136
143
" ,
137
144
Parent <CasedString >,
138
- " \
145
+ str ! [ [ r#"
139
146
TOML parse error at line 4, column 17
140
147
|
141
148
4 | {c_a = 'a'}
142
149
| ^^^^^^^^^^^
143
150
missing field `c_b`
144
- "
151
+
152
+ "# ] ]
145
153
) ;
146
154
147
155
// Sub-table in Vec has a field with a bad value.
@@ -154,13 +162,14 @@ missing field `c_b`
154
162
]
155
163
" ,
156
164
Parent <CasedString >,
157
- " \
165
+ str ! [ [ r#"
158
166
TOML parse error at line 4, column 35
159
167
|
160
168
4 | {c_a = 'a', c_b = '*'}
161
169
| ^^^
162
- invalid value: string \" *\" , expected all lowercase or all uppercase
163
- "
170
+ invalid value: string "*", expected all lowercase or all uppercase
171
+
172
+ "# ] ]
164
173
) ;
165
174
166
175
// Sub-table in Vec is missing a field.
@@ -174,13 +183,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase
174
183
]
175
184
" ,
176
185
Parent <CasedString >,
177
- " \
186
+ str ! [ [ r#"
178
187
TOML parse error at line 5, column 17
179
188
|
180
189
5 | {c_a = 'aa'}
181
190
| ^^^^^^^^^^^^
182
191
missing field `c_b`
183
- "
192
+
193
+ "# ] ]
184
194
) ;
185
195
186
196
// Sub-table in the middle of a Vec is missing a field.
@@ -195,13 +205,14 @@ missing field `c_b`
195
205
]
196
206
" ,
197
207
Parent <CasedString >,
198
- " \
208
+ str ! [ [ r#"
199
209
TOML parse error at line 5, column 17
200
210
|
201
211
5 | {c_a = 'aa'},
202
212
| ^^^^^^^^^^^^
203
213
missing field `c_b`
204
- "
214
+
215
+ "# ] ]
205
216
) ;
206
217
207
218
// Sub-table in the middle of a Vec has a field with a bad value.
@@ -216,13 +227,14 @@ missing field `c_b`
216
227
]
217
228
" ,
218
229
Parent <CasedString >,
219
- " \
230
+ str ! [ [ r#"
220
231
TOML parse error at line 5, column 36
221
232
|
222
233
5 | {c_a = 'aa', c_b = 1},
223
234
| ^
224
235
invalid type: integer `1`, expected a string
225
- "
236
+
237
+ "# ] ]
226
238
) ;
227
239
228
240
// Sub-table in the middle of a Vec has an extra field.
@@ -238,13 +250,14 @@ invalid type: integer `1`, expected a string
238
250
]
239
251
" ,
240
252
Parent <CasedString >,
241
- " \
253
+ str ! [ [ r#"
242
254
TOML parse error at line 5, column 42
243
255
|
244
256
5 | {c_a = 'aa', c_b = 'bb', c_d = 'd'},
245
257
| ^^^
246
258
unknown field `c_d`, expected `c_a` or `c_b`
247
- "
259
+
260
+ "# ] ]
248
261
) ;
249
262
250
263
// Sub-table in the middle of a Vec is missing a field.
@@ -267,13 +280,14 @@ unknown field `c_d`, expected `c_a` or `c_b`
267
280
c_b = 'bbbb'
268
281
" ,
269
282
Parent <CasedString >,
270
- " \
283
+ str ! [ [ r#"
271
284
TOML parse error at line 6, column 13
272
285
|
273
286
6 | [[p_b]]
274
287
| ^^^^^^^
275
288
missing field `c_b`
276
- "
289
+
290
+ "# ] ]
277
291
) ;
278
292
279
293
// Sub-table in the middle of a Vec has a field with a bad value.
@@ -292,13 +306,14 @@ missing field `c_b`
292
306
c_b = 'bbb'
293
307
" ,
294
308
Parent <CasedString >,
295
- " \
309
+ str ! [ [ r#"
296
310
TOML parse error at line 8, column 19
297
311
|
298
312
8 | c_b = '*'
299
313
| ^^^
300
- invalid value: string \" *\" , expected all lowercase or all uppercase
301
- "
314
+ invalid value: string "*", expected all lowercase or all uppercase
315
+
316
+ "# ] ]
302
317
) ;
303
318
304
319
// Sub-table in the middle of a Vec has an extra field.
@@ -320,13 +335,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase
320
335
c_b = 'bbbb'
321
336
" ,
322
337
Parent <CasedString >,
323
- " \
338
+ str ! [ [ r#"
324
339
TOML parse error at line 8, column 13
325
340
|
326
341
8 | c_d = 'dd' # unknown field
327
342
| ^^^
328
343
unknown field `c_d`, expected `c_a` or `c_b`
329
- "
344
+
345
+ "# ] ]
330
346
) ;
331
347
}
332
348
@@ -338,13 +354,14 @@ fn serde_derive_deserialize_errors() {
338
354
# ^
339
355
" ,
340
356
Parent <String >,
341
- " \
357
+ str ! [ [ r#"
342
358
TOML parse error at line 1, column 1
343
359
|
344
360
1 |
345
361
| ^
346
362
missing field `p_b`
347
- "
363
+
364
+ "# ] ]
348
365
) ;
349
366
350
367
bad ! (
@@ -356,13 +373,14 @@ missing field `p_b`
356
373
]
357
374
" ,
358
375
Parent <String >,
359
- " \
376
+ str ! [ [ r#"
360
377
TOML parse error at line 4, column 17
361
378
|
362
379
4 | {c_a = ''}
363
380
| ^^^^^^^^^^
364
381
missing field `c_b`
365
- "
382
+
383
+ "# ] ]
366
384
) ;
367
385
368
386
bad ! (
@@ -374,13 +392,14 @@ missing field `c_b`
374
392
]
375
393
" ,
376
394
Parent <String >,
377
- " \
395
+ str ! [ [ r#"
378
396
TOML parse error at line 4, column 34
379
397
|
380
398
4 | {c_a = '', c_b = 1}
381
399
| ^
382
400
invalid type: integer `1`, expected a string
383
- "
401
+
402
+ "# ] ]
384
403
) ;
385
404
386
405
// FIXME: This location could be better.
@@ -393,13 +412,14 @@ invalid type: integer `1`, expected a string
393
412
]
394
413
" ,
395
414
Parent <String >,
396
- " \
415
+ str ! [ [ r#"
397
416
TOML parse error at line 4, column 38
398
417
|
399
418
4 | {c_a = '', c_b = '', c_d = ''},
400
419
| ^^^
401
420
unknown field `c_d`, expected `c_a` or `c_b`
402
- "
421
+
422
+ "# ] ]
403
423
) ;
404
424
405
425
bad ! (
@@ -411,13 +431,14 @@ unknown field `c_d`, expected `c_a` or `c_b`
411
431
]
412
432
" ,
413
433
Parent <String >,
414
- " \
434
+ str ! [ [ r#"
415
435
TOML parse error at line 4, column 34
416
436
|
417
437
4 | {c_a = '', c_b = 1, c_d = ''},
418
438
| ^
419
439
invalid type: integer `1`, expected a string
420
- "
440
+
441
+ "# ] ]
421
442
) ;
422
443
}
423
444
@@ -431,13 +452,14 @@ fn error_handles_crlf() {
431
452
a = 2\r \n \
432
453
",
433
454
toml:: Value ,
434
- " \
455
+ str ! [ [ r#"
435
456
TOML parse error at line 5, column 1
436
457
|
437
458
5 | a = 2
438
459
| ^
439
460
duplicate key `a` in table `t2`
440
- "
461
+
462
+ "# ] ]
441
463
) ;
442
464
443
465
// Should be the same as above.
@@ -449,12 +471,13 @@ duplicate key `a` in table `t2`
449
471
a = 2\n \
450
472
",
451
473
toml:: Value ,
452
- " \
474
+ str ! [ [ r#"
453
475
TOML parse error at line 5, column 1
454
476
|
455
477
5 | a = 2
456
478
| ^
457
479
duplicate key `a` in table `t2`
458
- "
480
+
481
+ "# ] ]
459
482
) ;
460
483
}
0 commit comments