Skip to content

Commit b2e9f5e

Browse files
authored
Merge pull request #873 from epage/test
test: Sync between toml/toml_edit
2 parents 56fedcc + c1edb4f commit b2e9f5e

File tree

686 files changed

+7776
-677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

686 files changed

+7776
-677
lines changed

Cargo.lock

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

_typos.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[files]
22
extend-exclude = [
3-
"crates/toml_edit/tests/snapshots/**",
3+
"crates/*/tests/snapshots/**",
44
"crates/benchmarks/src/Cargo.*.toml",
55
]
66

crates/toml/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ serde_json = "1.0.116"
5959
toml-test-harness = { version = "1.3.0", features = ["snapshot"] }
6060
toml-test-data = "2.3.0"
6161
snapbox = "0.6.0"
62+
walkdir = "2.5.0"
6263

6364
[[test]]
6465
name = "decoder_compliance"

crates/toml/src/edit.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ pub(crate) mod de {
77
pub(crate) mod de {
88
/// Errors that can occur when deserializing a type.
99
#[derive(Debug, Clone, PartialEq, Eq)]
10-
pub struct Error {
10+
pub(crate) struct Error {
1111
inner: String,
1212
}
1313

1414
impl Error {
1515
/// Add key while unwinding
16-
pub fn add_key(&mut self, _key: String) {}
16+
pub(crate) fn add_key(&mut self, _key: String) {}
1717

1818
/// What went wrong
19-
pub fn message(&self) -> &str {
19+
pub(crate) fn message(&self) -> &str {
2020
self.inner.as_str()
2121
}
2222
}

crates/toml/src/table.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::fmt;
2-
31
use serde::de;
42
use serde::ser;
53

@@ -42,8 +40,8 @@ impl Table {
4240
}
4341

4442
#[cfg(feature = "display")]
45-
impl fmt::Display for Table {
46-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43+
impl std::fmt::Display for Table {
44+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
4745
crate::ser::to_string(self)
4846
.expect("Unable to represent value as string")
4947
.fmt(f)
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
use snapbox::assert_data_eq;
2+
use snapbox::prelude::*;
3+
use snapbox::str;
4+
5+
#[track_caller]
6+
fn t(toml: &str, expected: impl IntoData) {
7+
dbg!(toml);
8+
match toml.parse::<crate::RustDocument>() {
9+
Ok(s) => panic!("parsed to: {s:#?}"),
10+
Err(e) => assert_data_eq!(e.to_string(), expected.raw()),
11+
}
12+
}
13+
14+
#[test]
15+
fn basic_string_escape() {
16+
t(
17+
"a = \"\u{7f}\"",
18+
str![[r#"
19+
TOML parse error at line 1, column 6
20+
|
21+
1 | a = ""
22+
| ^
23+
invalid basic string
24+
25+
"#]],
26+
);
27+
}
28+
29+
#[test]
30+
fn literal_escape() {
31+
t(
32+
"a = '\u{7f}'",
33+
str![[r#"
34+
TOML parse error at line 1, column 6
35+
|
36+
1 | a = ''
37+
| ^
38+
invalid literal string
39+
40+
"#]],
41+
);
42+
}
43+
44+
#[test]
45+
fn stray_cr() {
46+
t(
47+
"\r",
48+
str![[r#"
49+
TOML parse error at line 1, column 1
50+
|
51+
1 |
52+
| ^
53+
54+
55+
"#]],
56+
);
57+
t(
58+
"a = [ \r ]",
59+
str![[r#"
60+
TOML parse error at line 1, column 8
61+
|
62+
1 | a = [
63+
]
64+
| ^
65+
66+
67+
"#]],
68+
);
69+
t(
70+
"a = \"\"\"\r\"\"\"",
71+
str![[r#"
72+
TOML parse error at line 1, column 8
73+
|
74+
1 | a = """
75+
"""
76+
| ^
77+
invalid multiline basic string
78+
79+
"#]],
80+
);
81+
t(
82+
"a = \"\"\"\\ \r \"\"\"",
83+
str![[r#"
84+
TOML parse error at line 1, column 10
85+
|
86+
1 | a = """\
87+
"""
88+
| ^
89+
invalid escape sequence
90+
expected `b`, `f`, `n`, `r`, `t`, `u`, `U`, `\`, `"`
91+
92+
"#]],
93+
);
94+
t(
95+
"a = '''\r'''",
96+
str![[r#"
97+
TOML parse error at line 1, column 8
98+
|
99+
1 | a = '''
100+
'''
101+
| ^
102+
invalid multiline literal string
103+
104+
"#]],
105+
);
106+
t(
107+
"a = '\r'",
108+
str![[r#"
109+
TOML parse error at line 1, column 6
110+
|
111+
1 | a = '
112+
'
113+
| ^
114+
invalid literal string
115+
116+
"#]],
117+
);
118+
t(
119+
"a = \"\r\"",
120+
str![[r#"
121+
TOML parse error at line 1, column 6
122+
|
123+
1 | a = "
124+
"
125+
| ^
126+
invalid basic string
127+
128+
"#]],
129+
);
130+
}
131+
132+
#[test]
133+
fn duplicate_key_with_crlf() {
134+
t(
135+
"\r\n\
136+
[t1]\r\n\
137+
[t2]\r\n\
138+
a = 1\r\n\
139+
a = 2\r\n\
140+
",
141+
str![[r#"
142+
TOML parse error at line 5, column 1
143+
|
144+
5 | a = 2
145+
| ^
146+
duplicate key `a` in table `t2`
147+
148+
"#]],
149+
);
150+
}
151+
152+
#[test]
153+
fn emoji_error_span() {
154+
let input = "😀";
155+
let err = input.parse::<crate::RustDocument>().unwrap_err();
156+
dbg!(err.span());
157+
let actual = &input[err.span().unwrap()];
158+
assert_eq!(actual, input);
159+
}
160+
161+
#[test]
162+
fn text_error_span() {
163+
let input = "asdf";
164+
let err = input.parse::<crate::RustDocument>().unwrap_err();
165+
dbg!(err.span());
166+
let actual = &input[err.span().unwrap()];
167+
assert_eq!(actual, "");
168+
}
169+
170+
#[test]
171+
fn fuzzed_68144_error_span() {
172+
let input = "\"\\ᾂr\"";
173+
let err = input.parse::<crate::RustDocument>().unwrap_err();
174+
dbg!(err.span());
175+
let actual = &input[err.span().unwrap()];
176+
assert_eq!(actual, "ᾂ");
177+
}

crates/toml/tests/compliance/main.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![recursion_limit = "256"]
2+
#![allow(clippy::dbg_macro)]
3+
#![cfg(all(feature = "parse", feature = "display"))]
4+
5+
macro_rules! parse_value {
6+
($s:expr) => {{
7+
use serde::Deserialize;
8+
let v = toml::Value::deserialize(toml::de::ValueDeserializer::new($s));
9+
assert!(
10+
v.is_ok(),
11+
"Failed with `{}` when parsing:
12+
```
13+
{}
14+
```
15+
",
16+
v.unwrap_err(),
17+
$s
18+
);
19+
v.unwrap()
20+
}};
21+
}
22+
23+
mod invalid;
24+
mod parse;
25+
26+
use toml::Table as RustDocument;
27+
use toml::Value as RustValue;

0 commit comments

Comments
 (0)