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(edit): Ensure std tables under dotted tables are printed #528

Merged
merged 2 commits into from Mar 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions crates/toml_edit/src/encode.rs
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
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