mirror of
https://github.com/goccy/go-yaml.git
synced 2025-11-09 09:41:11 +00:00
Fix misaligned indentation in comments (#734)
This commit is contained in:
parent
6a6c998c2f
commit
f1c23f747b
2 changed files with 58 additions and 4 deletions
|
|
@ -1452,8 +1452,9 @@ foo:
|
|||
|
||||
func TestComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
yaml string
|
||||
name string
|
||||
yaml string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "map with comment",
|
||||
|
|
@ -1541,6 +1542,52 @@ foo: > # comment
|
|||
# This comment is in its own document
|
||||
---
|
||||
a: b
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "map with misaligned indentation in comments",
|
||||
yaml: `
|
||||
# commentA
|
||||
a: #commentB
|
||||
# commentC
|
||||
b: c # commentD
|
||||
# commentE
|
||||
d: e # commentF
|
||||
# commentG
|
||||
`,
|
||||
expected: `
|
||||
# commentA
|
||||
a: #commentB
|
||||
# commentC
|
||||
b: c # commentD
|
||||
# commentE
|
||||
d: e # commentF
|
||||
# commentG
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "sequence with misaligned indentation in comments",
|
||||
yaml: `
|
||||
# commentA
|
||||
- a # commentB
|
||||
# commentC
|
||||
- b: # commentD
|
||||
# commentE
|
||||
- d # commentF
|
||||
# commentG
|
||||
- e # commentG
|
||||
# commentH
|
||||
`,
|
||||
expected: `
|
||||
# commentA
|
||||
- a # commentB
|
||||
# commentC
|
||||
- b: # commentD
|
||||
# commentE
|
||||
- d # commentF
|
||||
# commentG
|
||||
- e # commentG
|
||||
# commentH
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
@ -1551,8 +1598,12 @@ a: b
|
|||
t.Fatalf("%+v", err)
|
||||
}
|
||||
got := "\n" + f.String()
|
||||
if test.yaml != got {
|
||||
t.Fatalf("expected:%s\ngot:%s", test.yaml, got)
|
||||
expected := test.yaml
|
||||
if test.expected != "" {
|
||||
expected = test.expected
|
||||
}
|
||||
if expected != got {
|
||||
t.Fatalf("expected:%s\ngot:%s", expected, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue