Skip to content

Commit

Permalink
implemented support for RSS <content:encoded>
Browse files Browse the repository at this point in the history
  • Loading branch information
Lutz Horn authored and SlyMarbo committed Jun 6, 2017
1 parent 023392a commit 70c0278
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
54 changes: 54 additions & 0 deletions atom_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package rss

import (
"io/ioutil"
"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 {
data, err := ioutil.ReadFile("testdata/" + test)
if err != nil {
t.Fatalf("Reading %s: %v", test, err)
}

feed, err := Parse(data)
if err != nil {
t.Fatalf("Parsing %s: %v", test, err)
}

if feed.Title != want {
t.Fatalf("%s: expected %s, got %s", test, want, feed.Title)
}
}
}

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": "",
}

for test, want := range tests {
data, err := ioutil.ReadFile("testdata/" + test)
if err != nil {
t.Fatalf("Reading %s: %v", test, err)
}

feed, err := Parse(data)
if err != nil {
t.Fatalf("Parsing %s: %v", test, err)
}

if feed.Items[0].Content != want {
t.Fatalf("%s: expected %s, got %s", test, want, feed.Items[0].Content)
}
}
}
28 changes: 28 additions & 0 deletions rss_1.0_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rss

import (
"io/ioutil"
"testing"
)

func TestParseRSS(t *testing.T) {
tests := map[string]string{
"rss_1.0": "Golem.de",
}

for test, want := range tests {
data, err := ioutil.ReadFile("testdata/" + test)
if err != nil {
t.Fatalf("Reading %s: %v", test, err)
}

feed, err := Parse(data)
if err != nil {
t.Fatalf("Parsing %s: %v", test, err)
}

if feed.Title != want {
t.Fatalf("%s: expected %s, got %s", test, want, feed.Title)
}
}
}
2 changes: 1 addition & 1 deletion rss_2.0.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ type rss2_0Item struct {
XMLName xml.Name `xml:"item"`
Title string `xml:"title"`
Description string `xml:"description"`
Content string `xml:"encoded"`
Content string `xml:"http://purl.org/rss/1.0/modules/content/ encoded"`
Category string `xml:"category"`
Link string `xml:"link"`
PubDate string `xml:"pubDate"`
Expand Down
28 changes: 28 additions & 0 deletions rss_2.0_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rss

import (
"io/ioutil"
"testing"
)

func TestParseContent(t *testing.T) {
tests := map[string]string{
"rss_2.0_content_encoded": "<p><a href=\"https://example.com/\">Example.com</a> is an example site.</p>",
}

for test, want := range tests {
data, err := ioutil.ReadFile("testdata/" + test)
if err != nil {
t.Fatalf("Reading %s: %v", test, err)
}

feed, err := Parse(data)
if err != nil {
t.Fatalf("Parsing %s: %v", test, err)
}

if feed.Items[0].Content != want {
t.Fatalf("%s: expected %s, got %s", test, want, feed.Items[0].Content)
}
}
}
24 changes: 24 additions & 0 deletions testdata/rss_2.0_content_encoded
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
>
<channel>
<title>RSS Title</title>
<description>This is an example of an RSS feed</description>
<link>http://www.someexamplerssdomain.com/main.html</link>
<lastBuildDate>Mon, 06 Sep 2010 00:01:00 +0000</lastBuildDate>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000</pubDate>
<ttl>1800</ttl>

<item>
<title>Example entry</title>
<description>Here is some text containing an interesting
description.</description>
<link>http://www.wikipedia.org/</link>
<guid>unique string per item</guid>
<pubDate>Mon, 06 Sep 2009 16:45:00 +0000</pubDate>
<content:encoded><![CDATA[<p><a href="https://example.com/">Example.com</a> is an example site.</p>]]></content:encoded>
</item>

</channel>
</rss>

0 comments on commit 70c0278

Please sign in to comment.