rss/atom_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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": "", "atom_1.0_html": "<body>html</body>", } 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) } if !feed.Items[0].DateValid { t.Errorf("%s: Invalid date: %q", name, feed.Items[0].Date) } } }