Skip to content

Commit 03c4299

Browse files
committed
#151 Testcase for atom author in RSS
1 parent 69a2fc6 commit 03c4299

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"items": [
3+
{
4+
"author": {
5+
"name": "Item Author"
6+
},
7+
"authors": [
8+
{
9+
"name": "Item Author"
10+
}
11+
],
12+
"extensions": {
13+
"atom": {
14+
"author": [
15+
{
16+
"name": "author",
17+
"value": "",
18+
"parsed": {
19+
"authors": [
20+
{
21+
"name": "Item Author"
22+
}
23+
]
24+
}
25+
}
26+
]
27+
}
28+
}
29+
}
30+
],
31+
"feedType": "rss",
32+
"feedVersion": "2.0"
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!--
2+
Description: rss item with atom author
3+
-->
4+
<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom">
5+
<channel>
6+
<item>
7+
<a10:author><a10:name>Item Author</a10:name></a10:author>
8+
</item>
9+
</channel>
10+
</rss>

translator_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ func TestDefaultRSSTranslator_Translate(t *testing.T) {
3232
// Parse actual feed
3333
translator := &gofeed.DefaultRSSTranslator{}
3434
fp := &rss.Parser{}
35-
rssFeed, _ := fp.Parse(f)
35+
rssFeed, _ := fp.Parse(f, gofeed.NewParser().BuildRSSExtParsers())
3636
actual, _ := translator.Translate(rssFeed)
3737

38+
// the `Parsed` part of extensions is not correctly unmarshalled from JSON
39+
// workaround: move the actual extensions through a round of json marshalling so that we get the same
40+
for _, i := range actual.Items {
41+
if len(i.Extensions) > 0 {
42+
b, _ := jsonEncoding.Marshal(i.Extensions)
43+
jsonEncoding.Unmarshal(b, &i.Extensions)
44+
}
45+
}
46+
3847
// Get json encoded expected feed result
3948
ef := fmt.Sprintf("testdata/translator/rss/%s.json", name)
4049
e, _ := ioutil.ReadFile(ef)

0 commit comments

Comments
 (0)