Skip to content

Commit

Permalink
Merge pull request #528 from epage/mix
Browse files Browse the repository at this point in the history
fix(edit): Ensure std tables under dotted tables are printed
  • Loading branch information
epage authored Mar 13, 2023
2 parents e4b5ed4 + 1c0df12 commit b6e11da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/toml_edit/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,13 @@ fn visit_nested_tables<'t, F>(
where
F: FnMut(&'t Table, &Vec<&'t Key>, bool) -> Result,
{
callback(table, path, is_array_of_tables)?;
if !table.is_dotted() {
callback(table, path, is_array_of_tables)?;
}

for kv in table.items.values() {
match kv.value {
Item::Table(ref t) if !t.is_dotted() => {
Item::Table(ref t) => {
path.push(&kv.key);
visit_nested_tables(t, path, false, callback)?;
path.pop();
Expand Down
13 changes: 13 additions & 0 deletions crates/toml_edit/tests/testsuite/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,19 @@ fn empty_table() {
table["foo"].as_table().unwrap();
}

#[test]
fn mixed_table_issue_527() {
let input = r#"
[package]
metadata.msrv = "1.65.0"
[package.metadata.release.pre-release-replacements]
"#;
let document = input.parse::<Document>().unwrap();
let actual = document.to_string();
assert_eq(input, actual);
}

#[test]
fn fruit() {
let table = r#"
Expand Down

0 comments on commit b6e11da

Please sign in to comment.