88 lines
1.5 KiB
Go
88 lines
1.5 KiB
Go
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: `<img src="A" and=things/> <img src="asdf" and="some-toher-stuff"></img>`,
|
|
},
|
|
filter: `<[a-z]+.+?/([a-z]+)?>`,
|
|
output: Item{
|
|
Name: "a",
|
|
Link: "b",
|
|
Content: `<img src="A"/><br><img src="asdf"/>`,
|
|
},
|
|
},
|
|
{
|
|
input: gofeed.Item{
|
|
Title: "a",
|
|
Link: "b",
|
|
Content: `a b c <img src="asdf" and="some-toher-stuff"></img> d e f`,
|
|
},
|
|
filter: `<[a-z]+.+?/([a-z]+)?>`,
|
|
output: Item{
|
|
Name: "a",
|
|
Link: "b",
|
|
Content: `<img src="asdf"/>`,
|
|
},
|
|
},
|
|
{
|
|
input: gofeed.Item{
|
|
Title: "a",
|
|
Link: "b",
|
|
Content: "",
|
|
},
|
|
filter: "",
|
|
output: Item{
|
|
Name: "a",
|
|
Link: "b",
|
|
Content: "",
|
|
},
|
|
},
|
|
{
|
|
input: gofeed.Item{
|
|
Title: "a",
|
|
Link: "b",
|
|
Content: `<img src="asdf"></img>`,
|
|
},
|
|
filter: "",
|
|
output: Item{
|
|
Name: "a",
|
|
Link: "b",
|
|
Content: `<img src="asdf"/>`,
|
|
},
|
|
},
|
|
{
|
|
input: gofeed.Item{
|
|
Title: "a",
|
|
Link: "b",
|
|
Content: "x y",
|
|
},
|
|
filter: "[a-z]*",
|
|
output: Item{
|
|
Name: "a",
|
|
Link: "b",
|
|
Content: "x<br>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)
|
|
}
|
|
}
|
|
}
|