From 17abd35a74737bae582bd882402a490047a2e310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Sat, 22 Aug 2020 20:41:11 +0200 Subject: [PATCH] #151 Testcase for atom author in RSS --- ...author_-_rss_channel_item_author_atom.json | 28 +++++++++++++++++++ ..._author_-_rss_channel_item_author_atom.xml | 10 +++++++ translator_test.go | 11 +++++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.json create mode 100644 testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.xml diff --git a/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.json b/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.json new file mode 100644 index 00000000..270d78c2 --- /dev/null +++ b/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.json @@ -0,0 +1,28 @@ +{ + "items": [ + { + "author": { + "name": "Item Author" + }, + "extensions": { + "atom": { + "author": [ + { + "name": "author", + "value": "", + "parsed": { + "authors": [ + { + "name": "Item Author" + } + ] + } + } + ] + } + } + } + ], + "feedType": "rss", + "feedVersion": "2.0" +} diff --git a/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.xml b/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.xml new file mode 100644 index 00000000..f444b0cc --- /dev/null +++ b/testdata/translator/rss/feed_item_author_-_rss_channel_item_author_atom.xml @@ -0,0 +1,10 @@ + + + + + Item Author + + + diff --git a/translator_test.go b/translator_test.go index fca4f232..6b1ad60b 100644 --- a/translator_test.go +++ b/translator_test.go @@ -35,9 +35,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, _ := json.Marshal(i.Extensions) + json.Unmarshal(b, &i.Extensions) + } + } + // Get json encoded expected feed result ef := fmt.Sprintf("testdata/translator/rss/%s.json", name) e, _ := ioutil.ReadFile(ef)