Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update to snapbox 0.6 #736

Merged
merged 4 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ serde = { version = "1.0.199", features = ["derive"] }
serde_json = "1.0.116"
toml-test-harness = "0.4.8"
toml-test-data = "1.11.0"
snapbox = "0.5.10"
snapbox = "0.6.0"

[[test]]
name = "decoder_compliance"
Expand Down
107 changes: 65 additions & 42 deletions crates/toml/tests/testsuite/de_errors.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use serde::{de, Deserialize};
use std::fmt;

use serde::{de, Deserialize};
use snapbox::assert_data_eq;
use snapbox::prelude::*;
use snapbox::str;

macro_rules! bad {
($toml:expr, $ty:ty, $msg:expr) => {
match toml::from_str::<$ty>($toml) {
Ok(s) => panic!("parsed to: {:#?}", s),
Err(e) => snapbox::assert_eq($msg, e.to_string()),
Err(e) => assert_data_eq!(e.to_string(), $msg.raw()),
}
};
}
Expand Down Expand Up @@ -83,13 +87,14 @@ fn custom_errors() {
# ^
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 2, column 19
|
2 | p_a = ''
| ^^
invalid length 0, expected a non-empty string
"

"#]]
);

// Missing field in table.
Expand All @@ -99,13 +104,14 @@ invalid length 0, expected a non-empty string
# ^
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 1, column 1
|
1 |
| ^
missing field `p_b`
"

"#]]
);

// Invalid type in p_b.
Expand All @@ -116,13 +122,14 @@ missing field `p_b`
# ^
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 3, column 19
|
3 | p_b = 1
| ^
invalid type: integer `1`, expected a sequence
"

"#]]
);

// Sub-table in Vec is missing a field.
Expand All @@ -135,13 +142,14 @@ invalid type: integer `1`, expected a sequence
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 4, column 17
|
4 | {c_a = 'a'}
| ^^^^^^^^^^^
missing field `c_b`
"

"#]]
);

// Sub-table in Vec has a field with a bad value.
Expand All @@ -154,13 +162,14 @@ missing field `c_b`
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 4, column 35
|
4 | {c_a = 'a', c_b = '*'}
| ^^^
invalid value: string \"*\", expected all lowercase or all uppercase
"
invalid value: string "*", expected all lowercase or all uppercase

"#]]
);

// Sub-table in Vec is missing a field.
Expand All @@ -174,13 +183,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 5, column 17
|
5 | {c_a = 'aa'}
| ^^^^^^^^^^^^
missing field `c_b`
"

"#]]
);

// Sub-table in the middle of a Vec is missing a field.
Expand All @@ -195,13 +205,14 @@ missing field `c_b`
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 5, column 17
|
5 | {c_a = 'aa'},
| ^^^^^^^^^^^^
missing field `c_b`
"

"#]]
);

// Sub-table in the middle of a Vec has a field with a bad value.
Expand All @@ -216,13 +227,14 @@ missing field `c_b`
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 5, column 36
|
5 | {c_a = 'aa', c_b = 1},
| ^
invalid type: integer `1`, expected a string
"

"#]]
);

// Sub-table in the middle of a Vec has an extra field.
Expand All @@ -238,13 +250,14 @@ invalid type: integer `1`, expected a string
]
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 5, column 42
|
5 | {c_a = 'aa', c_b = 'bb', c_d = 'd'},
| ^^^
unknown field `c_d`, expected `c_a` or `c_b`
"

"#]]
);

// Sub-table in the middle of a Vec is missing a field.
Expand All @@ -267,13 +280,14 @@ unknown field `c_d`, expected `c_a` or `c_b`
c_b = 'bbbb'
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 6, column 13
|
6 | [[p_b]]
| ^^^^^^^
missing field `c_b`
"

"#]]
);

// Sub-table in the middle of a Vec has a field with a bad value.
Expand All @@ -292,13 +306,14 @@ missing field `c_b`
c_b = 'bbb'
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 8, column 19
|
8 | c_b = '*'
| ^^^
invalid value: string \"*\", expected all lowercase or all uppercase
"
invalid value: string "*", expected all lowercase or all uppercase

"#]]
);

// Sub-table in the middle of a Vec has an extra field.
Expand All @@ -320,13 +335,14 @@ invalid value: string \"*\", expected all lowercase or all uppercase
c_b = 'bbbb'
",
Parent<CasedString>,
"\
str![[r#"
TOML parse error at line 8, column 13
|
8 | c_d = 'dd' # unknown field
| ^^^
unknown field `c_d`, expected `c_a` or `c_b`
"

"#]]
);
}

Expand All @@ -338,13 +354,14 @@ fn serde_derive_deserialize_errors() {
# ^
",
Parent<String>,
"\
str![[r#"
TOML parse error at line 1, column 1
|
1 |
| ^
missing field `p_b`
"

"#]]
);

bad!(
Expand All @@ -356,13 +373,14 @@ missing field `p_b`
]
",
Parent<String>,
"\
str![[r#"
TOML parse error at line 4, column 17
|
4 | {c_a = ''}
| ^^^^^^^^^^
missing field `c_b`
"

"#]]
);

bad!(
Expand All @@ -374,13 +392,14 @@ missing field `c_b`
]
",
Parent<String>,
"\
str![[r#"
TOML parse error at line 4, column 34
|
4 | {c_a = '', c_b = 1}
| ^
invalid type: integer `1`, expected a string
"

"#]]
);

// FIXME: This location could be better.
Expand All @@ -393,13 +412,14 @@ invalid type: integer `1`, expected a string
]
",
Parent<String>,
"\
str![[r#"
TOML parse error at line 4, column 38
|
4 | {c_a = '', c_b = '', c_d = ''},
| ^^^
unknown field `c_d`, expected `c_a` or `c_b`
"

"#]]
);

bad!(
Expand All @@ -411,13 +431,14 @@ unknown field `c_d`, expected `c_a` or `c_b`
]
",
Parent<String>,
"\
str![[r#"
TOML parse error at line 4, column 34
|
4 | {c_a = '', c_b = 1, c_d = ''},
| ^
invalid type: integer `1`, expected a string
"

"#]]
);
}

Expand All @@ -431,13 +452,14 @@ fn error_handles_crlf() {
a = 2\r\n\
",
toml::Value,
"\
str![[r#"
TOML parse error at line 5, column 1
|
5 | a = 2
| ^
duplicate key `a` in table `t2`
"

"#]]
);

// Should be the same as above.
Expand All @@ -449,12 +471,13 @@ duplicate key `a` in table `t2`
a = 2\n\
",
toml::Value,
"\
str![[r#"
TOML parse error at line 5, column 1
|
5 | a = 2
| ^
duplicate key `a` in table `t2`
"

"#]]
);
}
Loading
Loading