package parser
import (
"reflect"
"strings"
"testing"
)
func TestSniff(t *testing.T) {
testcases := [][2]string{
{
``,
"rdf",
},
{
``,
"rss",
},
{
``,
"rss",
},
{
``,
"atom",
},
{
`{}`,
"json",
},
{
`
`,
"",
},
}
for _, testcase := range testcases {
have, _ := sniff(testcase[0])
want := testcase[1]
if want != have {
t.Log(testcase[0])
t.Errorf("Invalid format: want=%#v have=%#v", want, have)
}
}
}
func TestParse(t *testing.T) {
have, _ := Parse(strings.NewReader(`
Title
-
Item 1
content]]>
`))
want := &Feed{
Title: "Title",
Items: []Item{
{
Title: "Item 1",
Content: "content
",
},
},
}
if !reflect.DeepEqual(want, have) {
t.Logf("want: %#v", want)
t.Logf("have: %#v", have)
t.Fatal("invalid content")
}
}