|
|
@ -110,3 +110,34 @@ func TestToYaml(t *testing.T) {
|
|
|
|
t.Errorf("Expected %q, got %q", expect, got)
|
|
|
|
t.Errorf("Expected %q, got %q", expect, got)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestFromYaml(t *testing.T) {
|
|
|
|
|
|
|
|
doc := `hello: world
|
|
|
|
|
|
|
|
one:
|
|
|
|
|
|
|
|
two: three
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
dict := FromYaml(doc)
|
|
|
|
|
|
|
|
if err, ok := dict["Error"]; ok {
|
|
|
|
|
|
|
|
t.Fatalf("Parse error: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(dict) != 2 {
|
|
|
|
|
|
|
|
t.Fatal("expected two elements.")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
world := dict["hello"]
|
|
|
|
|
|
|
|
if world.(string) != "world" {
|
|
|
|
|
|
|
|
t.Fatal("Expected the world. Is that too much to ask?")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This should fail because we don't currently support lists:
|
|
|
|
|
|
|
|
doc2 := `
|
|
|
|
|
|
|
|
- one
|
|
|
|
|
|
|
|
- two
|
|
|
|
|
|
|
|
- three
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
dict = FromYaml(doc2)
|
|
|
|
|
|
|
|
if _, ok := dict["Error"]; !ok {
|
|
|
|
|
|
|
|
t.Fatal("Expected parser error")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|