package rss
import (
"testing"
"github.com/mmcdole/gofeed"
)
func Test_RSSItem(t *testing.T) {
cases := []struct {
input gofeed.Item
filter string
output Item
}{
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: `
`,
},
filter: `<[a-z]+.+?/([a-z]+)?>`,
output: Item{
Name: "a",
Link: "b",
Content: `a

`,
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: `a b c
d e f`,
},
filter: `<[a-z]+.+?/([a-z]+)?>`,
output: Item{
Name: "a",
Link: "b",
Content: `a
`,
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: "",
},
filter: "",
output: Item{
Name: "a",
Link: "b",
Content: `a
`,
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: `
`,
},
filter: "",
output: Item{
Name: "a",
Link: "b",
Content: `a
`,
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: "x y",
},
filter: "[a-z]*",
output: Item{
Name: "a",
Link: "b",
Content: `a
x
y`,
},
},
}
for _, c := range cases {
output := FromGofeedItem(&c.input, c.filter)
if *output != c.output {
t.Errorf("failed to convert gofeed: wanted %v, got %v", c.output, *output)
}
}
}