fix format with comment (#645)

This commit is contained in:
Masaaki Goshima 2025-02-09 15:09:26 +09:00 committed by GitHub
parent 0653c80843
commit e6c495e058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View file

@ -2757,8 +2757,9 @@ type unmarshalList struct {
func (u *unmarshalList) UnmarshalYAML(b []byte) error {
expected := `
- b: c
d: |
- b: c # comment
# comment
d: | # comment
hello
hello
@ -2807,8 +2808,9 @@ config:
func TestDecoder_UnmarshalBytesWithSeparatedList(t *testing.T) {
yml := `
a:
- b: c
d: |
- b: c # comment
# comment
d: | # comment
hello
hello
@ -2818,7 +2820,8 @@ a:
var v struct {
A unmarshalList
}
if err := yaml.Unmarshal([]byte(yml), &v); err != nil {
cm := yaml.CommentMap{}
if err := yaml.UnmarshalWithOptions([]byte(yml), &v, yaml.CommentToMap(cm)); err != nil {
t.Fatal(err)
}
if len(v.A.v) != 2 {