Skip to content

Commit

Permalink
add xml support: add unit test for xml parser
Browse files Browse the repository at this point in the history
  • Loading branch information
boranx committed Nov 29, 2019
1 parent 980086a commit 38695a4
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions parser/xml/xml_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package xml

import (
"testing"
)

func TestIniParser(t *testing.T) {
parser := &Parser{}
sample := `<note>
<to>foo</to>
<from>bar</from>
<heading>Reminder</heading>
<body>baz</body>
</note>`

var input interface{}
if err := parser.Unmarshal([]byte(sample), &input); err != nil {
t.Fatalf("parser should not have thrown an error: %v", err)
}

if input == nil {
t.Error("there should be information parsed but its nil")
}

inputMap := input.(map[string]interface{})
item := inputMap["note"]
if len(item.(map[string]interface{})) <= 0 {
t.Error("there should be at least one item defined in the parsed file, but none found")
}
}

0 comments on commit 38695a4

Please sign in to comment.