logo

news_parse_ex

commit: e84b5e9b5596175e9f2c0a09e1cc1ab8f323a87e
parent 8580e00f537e3a01d65f7f9a81d11bc3461849e7
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 27 Dec 2022 12:37:03 +0100

tests: Add RFC4287 examples

Diffstat:

Atest/fixtures/rfc4287/brief_single_entry.atom20++++++++++++++++++++
Atest/fixtures/rfc4287/extensive_single_entry.atom45+++++++++++++++++++++++++++++++++++++++++++++
Mtest/news_parse_ex_test.exs20++++++++++++++++++++
3 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/test/fixtures/rfc4287/brief_single_entry.atom b/test/fixtures/rfc4287/brief_single_entry.atom @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + + <title>Example Feed</title> + <link href="http://example.org/"/> + <updated>2003-12-13T18:30:02Z</updated> + <author> + <name>John Doe</name> + </author> + <id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id> + + <entry> + <title>Atom-Powered Robots Run Amok</title> + <link href="http://example.org/2003/12/13/atom03"/> + <id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id> + <updated>2003-12-13T18:30:02Z</updated> + <summary>Some text.</summary> + </entry> + +</feed> diff --git a/test/fixtures/rfc4287/extensive_single_entry.atom b/test/fixtures/rfc4287/extensive_single_entry.atom @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<feed xmlns="http://www.w3.org/2005/Atom"> + <title type="text">dive into mark</title> + <subtitle type="html"> + A &lt;em&gt;lot&lt;/em&gt; of effort + went into making this effortless + </subtitle> + <updated>2005-07-31T12:29:29Z</updated> + <id>tag:example.org,2003:3</id> + <link rel="alternate" type="text/html" + hreflang="en" href="http://example.org/"/> + <link rel="self" type="application/atom+xml" + href="http://example.org/feed.atom"/> + <rights>Copyright (c) 2003, Mark Pilgrim</rights> + <generator uri="http://www.example.com/" version="1.0"> + Example Toolkit + </generator> + <entry> + <title>Atom draft-07 snapshot</title> + <link rel="alternate" type="text/html" + href="http://example.org/2005/04/02/atom"/> + <link rel="enclosure" type="audio/mpeg" length="1337" + href="http://example.org/audio/ph34r_my_podcast.mp3"/> + <id>tag:example.org,2003:3.2397</id> + <updated>2005-07-31T12:29:29Z</updated> + <published>2003-12-13T08:29:29-04:00</published> + <author> + <name>Mark Pilgrim</name> + <uri>http://example.org/</uri> + <email>f8dy@example.com</email> + </author> + <contributor> + <name>Sam Ruby</name> + </contributor> + <contributor> + <name>Joe Gregorio</name> + </contributor> + <content type="xhtml" xml:lang="en" + xml:base="http://diveintomark.org/"> + <div xmlns="http://www.w3.org/1999/xhtml"> + <p><i>[Update: The Atom draft is finished.]</i></p> + </div> + </content> + </entry> +</feed> diff --git a/test/news_parse_ex_test.exs b/test/news_parse_ex_test.exs @@ -27,6 +27,26 @@ defmodule NewsParseExTest do assert(parsed.last_update == ~U[2021-11-01T16:09:55Z]) end + test "parses RFC4287 brief, single-entry Atom Feed Document" do + feed = File.read!("test/fixtures/rfc4287/brief_single_entry.atom") + + {:ok, parsed} = NewsParseEx.parse(feed) + assert(parsed.title == "Example Feed") + assert(parsed.description == nil) + assert(parsed.id == "urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6") + assert(parsed.last_update == ~U[2003-12-13T18:30:02Z]) + end + + test "parses RFC4287 more extensive, single-entry Atom Feed Document" do + feed = File.read!("test/fixtures/rfc4287/extensive_single_entry.atom") + + {:ok, parsed} = NewsParseEx.parse(feed) + assert(parsed.title == "dive into mark") + assert(parsed.description == nil) + assert(parsed.id == "tag:example.org,2003:3") + assert(parsed.last_update == ~U[2005-07-31T12:29:29Z]) + end + test "parses git.sr.ht RSS feed" do feed = File.read!("test/fixtures/git.sr.ht/pkgconf-2022-12-27.rss")