Skip to content

Commit

Permalink
Add test cases from go-yaml#184
Browse files Browse the repository at this point in the history
Signed-off-by: Vinzenz Feenstra <evilissmo@redhat.com>
  • Loading branch information
Vinzenz Feenstra committed Sep 20, 2017
1 parent 764aa8c commit 91409cd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,50 @@ func (s *S) TestMergeStruct(c *C) {
}
}

func (s *S) TestMapMerging(c *C) {
data := `---
world: &world
greeting: Hello
earth:
<< : *world`

config := map[string]interface{}{}
err := yaml.Unmarshal([]byte(data), &config)
if err != nil {
c.Errorf("Failed to parse\n%v\n\ninto a %T: %v", data, config, err)
}

earth := config["earth"]
expected := map[interface{}]interface{}{
"greeting": "Hello",
}

if !reflect.DeepEqual(earth, expected) {
c.Errorf("Merging does not work. Expected %v (%T), got %v (%T)", expected, expected, earth, earth)
}
}

func (s *S) TestMapSliceMerging(c *C) {
data := `---
world: &world
greeting: Hello
earth:
<< : *world`

config := make(yaml.MapSlice, 0)
err := yaml.Unmarshal([]byte(data), &config)
if err != nil {
c.Errorf("Failed to parse\n%v\n\ninto a %T: %v", data, config, err)
}

earth := config[1].Value
expected := yaml.MapSlice{{Key: "greeting", Value: "Hello"}}

if !reflect.DeepEqual(earth, expected) {
c.Errorf("Merging does not work. Expected %v (%T), got %v (%T)", expected, expected, earth, earth)
}
}

var unmarshalNullTests = []func() interface{}{
func() interface{} { var v interface{}; v = "v"; return &v },
func() interface{} { var s = "s"; return &s },
Expand Down

0 comments on commit 91409cd

Please sign in to comment.