2018-04-06 23:29:15 +00:00
|
|
|
package rss
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseAtomTitle(t *testing.T) {
|
|
|
|
tests := map[string]string{
|
|
|
|
"atom_1.0": "Titel des Weblogs",
|
|
|
|
"atom_1.0_enclosure": "Titel des Weblogs",
|
|
|
|
"atom_1.0-1": "Golem.de",
|
|
|
|
}
|
|
|
|
|
|
|
|
for test, want := range tests {
|
|
|
|
name := filepath.Join("testdata", test)
|
|
|
|
data, err := ioutil.ReadFile(name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Reading %s: %v", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
feed, err := Parse(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Parsing %s: %v", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed.Title != want {
|
|
|
|
t.Errorf("%s: got %q, want %q", name, feed.Title, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseAtomContent(t *testing.T) {
|
|
|
|
tests := map[string]string{
|
|
|
|
"atom_1.0": "Volltext des Weblog-Eintrags",
|
|
|
|
"atom_1.0_enclosure": "Volltext des Weblog-Eintrags",
|
|
|
|
"atom_1.0-1": "",
|
2020-07-27 20:09:02 +00:00
|
|
|
// "atom_1.0_html": "<body>html</body>",
|
2018-04-06 23:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for test, want := range tests {
|
|
|
|
name := filepath.Join("testdata", test)
|
|
|
|
data, err := ioutil.ReadFile(name)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Reading %s: %v", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
feed, err := Parse(data)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Parsing %s: %v", name, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if feed.Items[0].Content != want {
|
|
|
|
t.Errorf("%s: got %q, want %q", name, feed.Items[0].Content, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|