aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Conway <john.a.conway@gmail.com>2019-05-09 13:32:57 +0100
committerJohn Conway <john.a.conway@gmail.com>2019-05-09 13:32:57 +0100
commit48db15dd7b81a9f404aa04e434eb396a078f484c (patch)
tree76e28a62074cffd95e496d675aa682aaaab7f17e
parentbbf6a46a116342a0ee37e3b96f15b1b5bfee5df6 (diff)
downloadfeed-nim-48db15dd7b81a9f404aa04e434eb396a078f484c.tar.gz
feed-nim-48db15dd7b81a9f404aa04e434eb396a078f484c.zip
[Atom] Test written, bugs fixed
-rw-r--r--src/feednim/atom.nim47
-rwxr-xr-xtests/test_atombin409560 -> 482768 bytes
-rw-r--r--tests/test_atom.nim87
-rw-r--r--tests/test_atom.xml6
4 files changed, 112 insertions, 28 deletions
diff --git a/src/feednim/atom.nim b/src/feednim/atom.nim
index b771bc8..5c8b4a6 100644
--- a/src/feednim/atom.nim
+++ b/src/feednim/atom.nim
@@ -11,13 +11,14 @@ import xmltree
import streams
import sugar
+
type
Atom* = object
- author: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
- id*: string # Required Atom field
- title*: string # Required Atom field
- updated*: string # Required Atom field
- authors*: seq[AtomAuthor] # Pleuralised because the Atom spec allows more than one
+ author*: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
+ id*: string # Required Atom field
+ title*: string # Required Atom field
+ updated*: string # Required Atom field
+ authors*: seq[AtomAuthor] # Pleuralised because the Atom spec allows more than one
categories*: seq[AtomCategory]
contributors*: seq[AtomAuthor]
generator*: string
@@ -29,7 +30,7 @@ type
entries*: seq[AtomEntry]
AtomAuthor* = object
- name*: string # Required Atom field
+ name*: string # Required Atom field
uri*: string
email*: string
@@ -47,11 +48,11 @@ type
length*: string
AtomEntry* = object
- id*: string # Required Atom field
- title*: string # Required Atom field
- updated*: string # Required Atom field
- author: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
- authors*: seq[AtomAuthor] # Pleuralised because the Atom spec allows more than one
+ id*: string # Required Atom field
+ title*: string # Required Atom field
+ updated*: string # Required Atom field
+ author*: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
+ authors*: seq[AtomAuthor] # Pleuralised because the Atom spec allows more than one
categories*: seq[AtomCategory]
content*: string
contentSrc*: string
@@ -64,8 +65,8 @@ type
summary*: string
AtomSource* = object
- author: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
- authors: seq[AtomAuthor]
+ author*: AtomAuthor # Sugar, not in Atom spec. Returns the first author.
+ authors*: seq[AtomAuthor]
categories*: seq[AtomCategory]
contributors*: seq[AtomAuthor]
generator*: string
@@ -107,7 +108,7 @@ proc parseCategories ( node: XmlNode ) : seq[AtomCategory] =
proc parseLink ( node: XmlNode ): AtomLink =
var link: AtomLink = AtomLink()
if node.attrs != nil:
- if node.attr("href") != "": link.href = node.attr("rel")
+ if node.attr("href") != "": link.href = node.attr("href")
if node.attr("rel") != "": link.rel = node.attr("rel")
if node.attr("type") != "": link.linktype = node.attr("type")
if node.attr("hreflang") != "": link.hreflang = node.attr("hreflang")
@@ -129,10 +130,20 @@ proc parseEntry( node: XmlNode) : AtomEntry =
if node.child("category") != nil: entry.categories = node.parseCategories()
if node.child("content") != nil:
- entry.content = node.child("content").innerText
- if node.attrs != nil:
- if node.attr("type") != "": entry.contentType = node.attr("type")
- if node.attr("src") != "": entry.contentSrc = node.attr("src")
+ let content_node = node.child("content")
+ entry.content = content_node.innerText
+
+ if content_node.attrs != nil:
+ if content_node.attr("type") == "xhtml" or content_node.attr("type") == "html":
+ var content = ""
+ entry.contentType = node.attr("type")
+ for item in content_node.items:
+ content = content & $item
+ entry.content = content
+ else:
+ entry.content = content_node.innerText
+
+ entry.contentSrc = content_node.attr("src")
if node.child("contributor") != nil:
entry.contributors = node.parseAuthors(mode="contributor")
diff --git a/tests/test_atom b/tests/test_atom
index 991e0e6..bb04749 100755
--- a/tests/test_atom
+++ b/tests/test_atom
Binary files differ
diff --git a/tests/test_atom.nim b/tests/test_atom.nim
index c4c65f9..d2eac21 100644
--- a/tests/test_atom.nim
+++ b/tests/test_atom.nim
@@ -14,10 +14,85 @@ import feednim
test "Read Valid Atom Feed":
let feed = "./tests/test_atom.xml".loadAtom()
- echo $$feed
+ check feed.id == "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6"
+ check feed.title == "Bloggs's Planes Trains and Automobiles"
+ check feed.updated == "2003-12-13T18:30:02Z"
- check feed.title != ""
- check feed.generator != ""
- check feed.authors[0].name == "Joe Bloggs"
- check feed.authors[0].uri == "http://joe.bloggs"
- check feed.authors[0].email == "mail@joe.bloggs" \ No newline at end of file
+ check feed.author.name == "Joe Bloggs"
+ check feed.author.uri == "http://joe.bloggs"
+ check feed.author.email == "mail@joe.bloggs"
+
+ check feed.contributors[0].name == "Jane Bloggs"
+
+ check feed.categories[0].term == "planes"
+ check feed.categories[0].label == "Planes"
+ check feed.categories[0].scheme == "http://awesomecategories.org"
+ check feed.categories[1].term == "trains"
+ check feed.categories[1].label == "Trains"
+ check feed.categories[2].term == "automobiles"
+ check feed.categories[2].label == "Automobiles"
+
+ #check feed.generator.uri == "https://github.com/dom96/jester"
+ check feed.generator == "Jester"
+
+ check feed.icon == "http://joe.bloggs/mug,jpg"
+
+ check feed.link.href == "http://joe.bloggs/atom"
+ check feed.link.rel == "self"
+ check feed.link.linktype == "application/xml+atom"
+ check feed.link.hreflang == "en-GB"
+ check feed.link.title == "Bloggs's Planes Trains and Automobiles"
+ check feed.link.length == "1000000"
+
+ check feed.logo == "http://joe.bloggs/logo.jpeg"
+ check feed.rights == "Copyright Joe and Jane Bloggs"
+ check feed.subtitle == "About Trains, Planes, and Automobiles."
+
+
+ check feed.entries[0].id == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
+ check feed.entries[0].title == "Aeroplanes not Airplanes"
+ check feed.entries[0].updated == "2003-12-13T18:30:02Z"
+ check feed.entries[0].author.name == "Joe Bloggs"
+ check feed.entries[0].author.uri == "http://joe.bloggs"
+ check feed.entries[0].author.email == "mail@joe.bloggs"
+
+ check feed.entries[0].categories[0].term == "words"
+ check feed.entries[0].categories[0].label == "Words"
+ check feed.entries[0].categories[0].scheme == "http://awesomecategories.org"
+
+ #check feed.entries[0].content.contenttype == "xhtml"
+ check feed.entries[0].content == """<div xmlns="http://www.w3.org/1999/xhtml"><p><i>Aero</i>- not air-, fools!</p></div>"""
+
+ check feed.entries[0].published == "2003-12-13T18:30:02Z"
+ check feed.entries[0].rights == "Copyright Joe Bloggs"
+
+ check feed.entries[0].source.id == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6d"
+ check feed.entries[0].source.title == "Aeroplane"
+ check feed.entries[0].source.subtitle == "Aeroplanes"
+ check feed.entries[0].source.updated == "1755-04-15T18:30:00Z"
+ check feed.entries[0].source.author.name == "Samuel Johnson"
+ check feed.entries[0].source.author.uri == "http://dictionary.com"
+ check feed.entries[0].source.author.email == "sjohnson@dictionary.com"
+ check feed.entries[0].source.categories[0].term == "planes"
+ check feed.entries[0].source.categories[0].label == "Planes"
+ check feed.entries[0].source.categories[0].scheme == "http://awesomecategories.org"
+ check feed.entries[0].source.rights == "Copyright Samual Johnson"
+
+
+ check feed.entries[1].id == "urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a"
+ check feed.entries[1].title == "Trains Are Good"
+ check feed.entries[1].updated == "2003-12-13T18:30:02Z"
+ check feed.entries[1].author.name == "Jane Bloggs"
+
+ check feed.entries[1].categories[0].term == "trains"
+ check feed.entries[1].categories[0].label == "Trains"
+ check feed.entries[1].contentSrc == "http://trains.com"
+ check feed.entries[1].link.href == "http://joe.bloggs/trains-full"
+ check feed.entries[1].link.rel == "alternate"
+ check feed.entries[1].link.linktype == "text/html"
+ check feed.entries[1].link.hreflang == "en-GB"
+ check feed.entries[1].link.title == "Trains!"
+ check feed.entries[1].link.length == "1000000"
+ check feed.entries[1].published == "2003-12-13T18:20:02Z"
+ check feed.entries[1].rights == "Copyright Jane Bloggs"
+ check feed.entries[1].summary == "Trains!" \ No newline at end of file
diff --git a/tests/test_atom.xml b/tests/test_atom.xml
index 5ea44a2..f2a73a1 100644
--- a/tests/test_atom.xml
+++ b/tests/test_atom.xml
@@ -33,7 +33,7 @@
<logo>http://joe.bloggs/logo.jpeg</logo>
<rights>Copyright Joe and Jane Bloggs</rights>
- <subtitle>About Trains, Planes, and Autonmobiles.</subtitle>
+ <subtitle>About Trains, Planes, and Automobiles.</subtitle>
<entry>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
@@ -86,8 +86,6 @@
/>
<published>2003-12-13T18:20:02Z</published>
<rights>Copyright Jane Bloggs</rights>
- <summary>
- Trains!
- </summary>
+ <summary>Trains!</summary>
</entry>
</feed> \ No newline at end of file