Skip to content

Commit

Permalink
Merge pull request #757 from epage/key
Browse files Browse the repository at this point in the history
fix(encode): Correct encoding for key with mixed quotes
  • Loading branch information
epage authored Jul 17, 2024
2 parents cd9321f + 3d8852b commit b463f3d
Show file tree
Hide file tree
Showing 6 changed files with 518 additions and 99 deletions.
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

0 comments on commit b463f3d

Please sign in to comment.