Skip to content

Commit

Permalink
mmcdole#151 Testcase for atom author in RSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Jan 3, 2024
1 parent 78062da commit 8fa89b5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"items": [
{
"author": {
"name": "Item Author"
},
"authors": [
{
"name": "Item Author"
}
],
"extensions": {
"atom": {
"author": [
{
"name": "author",
"value": "",
"parsed": {
"authors": [
{
"name": "Item Author"
}
]
}
}
]
}
}
}
],
"feedType": "rss",
"feedVersion": "2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
Description: rss item with atom author
-->
<rss version="2.0" xmlns:a10="http://www.w3.org/2005/Atom">
<channel>
<item>
<a10:author><a10:name>Item Author</a10:name></a10:author>
</item>
</channel>
</rss>
11 changes: 10 additions & 1 deletion translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ func TestDefaultRSSTranslator_Translate(t *testing.T) {
// Parse actual feed
translator := &gofeed.DefaultRSSTranslator{}
fp := &rss.Parser{}
rssFeed, _ := fp.Parse(f)
rssFeed, _ := fp.Parse(f, gofeed.NewParser().BuildRSSExtParsers())
actual, _ := translator.Translate(rssFeed)

// the `Parsed` part of extensions is not correctly unmarshalled from JSON
// workaround: move the actual extensions through a round of json marshalling so that we get the same
for _, i := range actual.Items {
if len(i.Extensions) > 0 {
b, _ := jsonEncoding.Marshal(i.Extensions)
jsonEncoding.Unmarshal(b, &i.Extensions)
}
}

// Get json encoded expected feed result
ef := fmt.Sprintf("testdata/translator/rss/%s.json", name)
e, _ := os.ReadFile(ef)
Expand Down

0 comments on commit 8fa89b5

Please sign in to comment.