|
|
@@ -88,6 +88,39 @@ func TestParseOpmlWithCategories(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestParseOpmlTrimsWhitespace(t *testing.T) {
|
|
|
+ data := `<?xml version="1.0" encoding="utf-8"?>
|
|
|
+ <opml version="2.0">
|
|
|
+ <body>
|
|
|
+ <outline text=" My Category ">
|
|
|
+ <outline title=" Feed 1 " xmlUrl=" http://example.org/feed1/ " htmlUrl=" http://example.org/1 "/>
|
|
|
+ <outline title=" " xmlUrl=" http://example.org/feed2/	"/>
|
|
|
+ </outline>
|
|
|
+ </body>
|
|
|
+ </opml>
|
|
|
+ `
|
|
|
+
|
|
|
+ expected := []subcription{
|
|
|
+ {Title: "Feed 1", FeedURL: "http://example.org/feed1/", SiteURL: "http://example.org/1", CategoryName: "My Category"},
|
|
|
+ {Title: "http://example.org/feed2/", FeedURL: "http://example.org/feed2/", SiteURL: "http://example.org/feed2/", CategoryName: "My Category"},
|
|
|
+ }
|
|
|
+
|
|
|
+ subscriptions, err := parse(bytes.NewBufferString(data))
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(subscriptions) != len(expected) {
|
|
|
+ t.Fatalf("Wrong number of subscriptions: %d instead of %d", len(subscriptions), len(expected))
|
|
|
+ }
|
|
|
+
|
|
|
+ for i := range len(subscriptions) {
|
|
|
+ if subscriptions[i] != expected[i] {
|
|
|
+ t.Errorf(`Subscription is different: "%v" vs "%v"`, subscriptions[i], expected[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestParseOpmlWithEmptyTitleAndEmptySiteURL(t *testing.T) {
|
|
|
data := `<?xml version="1.0" encoding="ISO-8859-1"?>
|
|
|
<opml version="2.0">
|