Skip to content

Commit dbf1cc1

Browse files
authored
Merge pull request #736 from epage/snapbox
chore: Update to snapbox 0.6
2 parents 1d980a4 + ec9bfd7 commit dbf1cc1

File tree

16 files changed

+923
-590
lines changed

16 files changed

+923
-590
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/toml/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ serde = { version = "1.0.199", features = ["derive"] }
5151
serde_json = "1.0.116"
5252
toml-test-harness = "0.4.8"
5353
toml-test-data = "1.11.0"
54-
snapbox = "0.5.10"
54+
snapbox = "0.6.0"
5555

5656
[[test]]
5757
name = "decoder_compliance"

crates/toml/tests/testsuite/de_errors.rs

Lines changed: 65 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
use serde::{de, Deserialize};
21
use std::fmt;
32

3+
use serde::{de, Deserialize};
4+
use snapbox::assert_data_eq;
5+
use snapbox::prelude::*;
6+
use snapbox::str;
7+
48
macro_rules! bad {
59
($toml:expr, $ty:ty, $msg:expr) => {
610
match toml::from_str::<$ty>($toml) {
711
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()),
913
}
1014
};
1115
}
@@ -83,13 +87,14 @@ fn custom_errors() {
8387
# ^
8488
",
8589
Parent<CasedString>,
86-
"\
90+
str![[r#"
8791
TOML parse error at line 2, column 19
8892
|
8993
2 | p_a = ''
9094
| ^^
9195
invalid length 0, expected a non-empty string
92-
"
96+
97+
"#]]
9398
);
9499

95100
// Missing field in table.
@@ -99,13 +104,14 @@ invalid length 0, expected a non-empty string
99104
# ^
100105
",
101106
Parent<CasedString>,
102-
"\
107+
str![[r#"
103108
TOML parse error at line 1, column 1
104109
|
105110
1 |
106111
| ^
107112
missing field `p_b`
108-
"
113+
114+
"#]]
109115
);
110116

111117
// Invalid type in p_b.
@@ -116,13 +122,14 @@ missing field `p_b`
116122
# ^
117123
",
118124
Parent<CasedString>,
119-
"\
125+
str![[r#"
120126
TOML parse error at line 3, column 19
121127
|
122128
3 | p_b = 1
123129
| ^
124130
invalid type: integer `1`, expected a sequence
125-
"
131+
132+
"#]]
126133
);
127134

128135
// Sub-table in Vec is missing a field.
@@ -135,13 +142,14 @@ invalid type: integer `1`, expected a sequence
135142
]
136143
",
137144
Parent<CasedString>,
138-
"\
145+
str![[r#"
139146
TOML parse error at line 4, column 17
140147
|
141148
4 | {c_a = 'a'}
142149
| ^^^^^^^^^^^
143150
missing field `c_b`
144-
"
151+
152+
"#]]
145153
);
146154

147155
// Sub-table in Vec has a field with a bad value.
@@ -154,13 +162,14 @@ missing field `c_b`
154162
]
155163
",
156164
Parent<CasedString>,
157-
"\
165+
str![[r#"
158166
TOML parse error at line 4, column 35
159167
|
160168
4 | {c_a = 'a', c_b = '*'}
161169
| ^^^
162-
invalid value: string \"*\", expected all lowercase or all uppercase
163-
"
170+
invalid value: string "*", expected all lowercase or all uppercase
171+
172+
"#]]
164173
);
165174

166175
// Sub-table in Vec is missing a field.
@@ -174,13 +183,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase
174183
]
175184
",
176185
Parent<CasedString>,
177-
"\
186+
str![[r#"
178187
TOML parse error at line 5, column 17
179188
|
180189
5 | {c_a = 'aa'}
181190
| ^^^^^^^^^^^^
182191
missing field `c_b`
183-
"
192+
193+
"#]]
184194
);
185195

186196
// Sub-table in the middle of a Vec is missing a field.
@@ -195,13 +205,14 @@ missing field `c_b`
195205
]
196206
",
197207
Parent<CasedString>,
198-
"\
208+
str![[r#"
199209
TOML parse error at line 5, column 17
200210
|
201211
5 | {c_a = 'aa'},
202212
| ^^^^^^^^^^^^
203213
missing field `c_b`
204-
"
214+
215+
"#]]
205216
);
206217

207218
// Sub-table in the middle of a Vec has a field with a bad value.
@@ -216,13 +227,14 @@ missing field `c_b`
216227
]
217228
",
218229
Parent<CasedString>,
219-
"\
230+
str![[r#"
220231
TOML parse error at line 5, column 36
221232
|
222233
5 | {c_a = 'aa', c_b = 1},
223234
| ^
224235
invalid type: integer `1`, expected a string
225-
"
236+
237+
"#]]
226238
);
227239

228240
// Sub-table in the middle of a Vec has an extra field.
@@ -238,13 +250,14 @@ invalid type: integer `1`, expected a string
238250
]
239251
",
240252
Parent<CasedString>,
241-
"\
253+
str![[r#"
242254
TOML parse error at line 5, column 42
243255
|
244256
5 | {c_a = 'aa', c_b = 'bb', c_d = 'd'},
245257
| ^^^
246258
unknown field `c_d`, expected `c_a` or `c_b`
247-
"
259+
260+
"#]]
248261
);
249262

250263
// 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`
267280
c_b = 'bbbb'
268281
",
269282
Parent<CasedString>,
270-
"\
283+
str![[r#"
271284
TOML parse error at line 6, column 13
272285
|
273286
6 | [[p_b]]
274287
| ^^^^^^^
275288
missing field `c_b`
276-
"
289+
290+
"#]]
277291
);
278292

279293
// Sub-table in the middle of a Vec has a field with a bad value.
@@ -292,13 +306,14 @@ missing field `c_b`
292306
c_b = 'bbb'
293307
",
294308
Parent<CasedString>,
295-
"\
309+
str![[r#"
296310
TOML parse error at line 8, column 19
297311
|
298312
8 | c_b = '*'
299313
| ^^^
300-
invalid value: string \"*\", expected all lowercase or all uppercase
301-
"
314+
invalid value: string "*", expected all lowercase or all uppercase
315+
316+
"#]]
302317
);
303318

304319
// 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
320335
c_b = 'bbbb'
321336
",
322337
Parent<CasedString>,
323-
"\
338+
str![[r#"
324339
TOML parse error at line 8, column 13
325340
|
326341
8 | c_d = 'dd' # unknown field
327342
| ^^^
328343
unknown field `c_d`, expected `c_a` or `c_b`
329-
"
344+
345+
"#]]
330346
);
331347
}
332348

@@ -338,13 +354,14 @@ fn serde_derive_deserialize_errors() {
338354
# ^
339355
",
340356
Parent<String>,
341-
"\
357+
str![[r#"
342358
TOML parse error at line 1, column 1
343359
|
344360
1 |
345361
| ^
346362
missing field `p_b`
347-
"
363+
364+
"#]]
348365
);
349366

350367
bad!(
@@ -356,13 +373,14 @@ missing field `p_b`
356373
]
357374
",
358375
Parent<String>,
359-
"\
376+
str![[r#"
360377
TOML parse error at line 4, column 17
361378
|
362379
4 | {c_a = ''}
363380
| ^^^^^^^^^^
364381
missing field `c_b`
365-
"
382+
383+
"#]]
366384
);
367385

368386
bad!(
@@ -374,13 +392,14 @@ missing field `c_b`
374392
]
375393
",
376394
Parent<String>,
377-
"\
395+
str![[r#"
378396
TOML parse error at line 4, column 34
379397
|
380398
4 | {c_a = '', c_b = 1}
381399
| ^
382400
invalid type: integer `1`, expected a string
383-
"
401+
402+
"#]]
384403
);
385404

386405
// FIXME: This location could be better.
@@ -393,13 +412,14 @@ invalid type: integer `1`, expected a string
393412
]
394413
",
395414
Parent<String>,
396-
"\
415+
str![[r#"
397416
TOML parse error at line 4, column 38
398417
|
399418
4 | {c_a = '', c_b = '', c_d = ''},
400419
| ^^^
401420
unknown field `c_d`, expected `c_a` or `c_b`
402-
"
421+
422+
"#]]
403423
);
404424

405425
bad!(
@@ -411,13 +431,14 @@ unknown field `c_d`, expected `c_a` or `c_b`
411431
]
412432
",
413433
Parent<String>,
414-
"\
434+
str![[r#"
415435
TOML parse error at line 4, column 34
416436
|
417437
4 | {c_a = '', c_b = 1, c_d = ''},
418438
| ^
419439
invalid type: integer `1`, expected a string
420-
"
440+
441+
"#]]
421442
);
422443
}
423444

@@ -431,13 +452,14 @@ fn error_handles_crlf() {
431452
a = 2\r\n\
432453
",
433454
toml::Value,
434-
"\
455+
str![[r#"
435456
TOML parse error at line 5, column 1
436457
|
437458
5 | a = 2
438459
| ^
439460
duplicate key `a` in table `t2`
440-
"
461+
462+
"#]]
441463
);
442464

443465
// Should be the same as above.
@@ -449,12 +471,13 @@ duplicate key `a` in table `t2`
449471
a = 2\n\
450472
",
451473
toml::Value,
452-
"\
474+
str![[r#"
453475
TOML parse error at line 5, column 1
454476
|
455477
5 | a = 2
456478
| ^
457479
duplicate key `a` in table `t2`
458-
"
480+
481+
"#]]
459482
);
460483
}

0 commit comments

Comments
 (0)