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

fix(encode): Correct encoding for key with mixed quotes #757

Merged
merged 12 commits into from
Jul 17, 2024
193 changes: 190 additions & 3 deletions Cargo.lock

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

66 changes: 0 additions & 66 deletions crates/toml/tests/testsuite/display.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use serde::Deserialize;
use snapbox::assert_data_eq;
use snapbox::prelude::*;
use snapbox::str;
use toml::map::Map;
use toml::Value;
use toml::Value::{Array, Boolean, Float, Integer, String, Table};

macro_rules! map( ($($k:expr => $v:expr),*) => ({
Expand Down Expand Up @@ -119,64 +114,3 @@ fn table() {
test2 = 2\n"
);
}

#[test]
fn string_roundtrip() {
assert_string_round_trip(r#""""#, str![[r#""""#]]);
assert_string_round_trip(r#""a""#, str![[r#""a""#]]);

assert_string_round_trip(r#""tab \t tab""#, str![[r#""tab /t tab""#]]);
assert_string_round_trip(
r#""lf \n lf""#,
str![[r#"
"""
lf
lf"""
"#]],
);
assert_string_round_trip(
r#""crlf \r\n crlf""#,
str![[r#"
"""
crlf /r
crlf"""
"#]],
);
assert_string_round_trip(r#""bell \b bell""#, str![[r#""bell /b bell""#]]);
assert_string_round_trip(r#""feed \f feed""#, str![[r#""feed /f feed""#]]);
assert_string_round_trip(
r#""backslash \\ backslash""#,
str!["'backslash / backslash'"],
);

assert_string_round_trip(r#""squote ' squote""#, str![[r#""squote ' squote""#]]);
assert_string_round_trip(
r#""triple squote ''' triple squote""#,
str![[r#""triple squote ''' triple squote""#]],
);
assert_string_round_trip(r#""end squote '""#, str![[r#""end squote '""#]]);

assert_string_round_trip(r#""quote \" quote""#, str![[r#"'quote " quote'"#]]);
assert_string_round_trip(
r#""triple quote \"\"\" triple quote""#,
str![[r#"'triple quote """ triple quote'"#]],
);
assert_string_round_trip(r#""end quote \"""#, str![[r#"'end quote "'"#]]);
}

#[track_caller]
fn assert_string_round_trip(input: &str, expected: impl IntoData) {
let value = Value::deserialize(toml::de::ValueDeserializer::new(input)).unwrap();
let actual = value.to_string();
let _ = Value::deserialize(toml::de::ValueDeserializer::new(input)).unwrap_or_else(|_err| {
panic!(
"invalid value:
```
{actual}
```
"
)
});
let expected = expected.into_data();
assert_data_eq!(actual, expected);
}
1 change: 1 addition & 0 deletions crates/toml_edit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ toml-test-harness = "0.4.8"
toml-test-data = "1.11.0"
libtest-mimic = "0.7.2"
snapbox = "0.6.0"
proptest = "1.5.0"

[[test]]
name = "testsuite"
Expand Down
Loading
Loading