aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFélix Sipma <felix.sipma@no-log.org>2017-01-13 16:30:59 +0100
committerFélix Sipma <felix.sipma@no-log.org>2017-01-13 16:30:59 +0100
commita8d72e995f565f1b8d243516ee9224e06ff294c5 (patch)
treed3b77be7b1980d411aea98c447bf16a409fa6dd7
parentc787030c4f80f015a09f6e1930e8d6869ea74f4f (diff)
add atom feed test
-rw-r--r--perfeed.cabal5
-rw-r--r--src/Types.hs10
-rw-r--r--test/Spec.hs86
-rw-r--r--test/files/atom.xml1
4 files changed, 93 insertions, 9 deletions
diff --git a/perfeed.cabal b/perfeed.cabal
index 3dd06c9..b8e932d 100644
--- a/perfeed.cabal
+++ b/perfeed.cabal
@@ -86,10 +86,13 @@ test-suite perfeed-test
main-is: Spec.hs
build-depends: base
, hspec
- , QuickCheck
+ , hspec-expectations-pretty-diff
+ , monad-logger
, perfeed
+ , protolude
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010
+ default-extensions: NoImplicitPrelude
source-repository head
type: git
diff --git a/src/Types.hs b/src/Types.hs
index 709ae79..bc256e9 100644
--- a/src/Types.hs
+++ b/src/Types.hs
@@ -38,7 +38,7 @@ data Feed
, feedLinks :: ![Link]
, feedEntries :: ![Entry]
}
- deriving (Show)
+ deriving (Eq, Show)
data Entry
= Entry
@@ -49,14 +49,14 @@ data Entry
, entryContent :: !(Maybe Content)
, entryLinks :: ![Link]
}
- deriving (Show)
+ deriving (Eq, Show)
data Link
= Link
{ linkHref :: !Url
, linkRel :: !(Maybe Text)
}
- deriving (Show)
+ deriving (Eq, Show)
data Person
= Person
@@ -64,12 +64,12 @@ data Person
, personURI :: !(Maybe Url)
, personEmail :: !(Maybe Email)
}
- deriving (Show)
+ deriving (Eq, Show)
data Content
= TextContent LText
| HtmlContent LText
- deriving (Show)
+ deriving (Eq, Show)
-- TODO: use data
type Url = Text
diff --git a/test/Spec.hs b/test/Spec.hs
index 2cd11a0..f742a4f 100644
--- a/test/Spec.hs
+++ b/test/Spec.hs
@@ -1,6 +1,86 @@
-import Test.Hspec
-import Test.QuickCheck
+{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE TemplateHaskell #-}
+
+import Protolude
+import Prelude (read)
+import Test.Hspec hiding (shouldBe)
+import Test.Hspec.Expectations.Pretty (shouldBe)
+import Parse (cursorFromFile)
+import Atom (parseAtomFeed)
+import Control.Monad.Logger (runStderrLoggingT)
+import Types
main :: IO ()
-main = putStrLn "Test suite not yet implemented"
+main = hspec spec
+
+spec :: SpecWith ()
+spec = describe "Feed parsing" $
+ it "can parse an atom feed" $ do
+ c <- liftIO $ cursorFromFile "test/files/atom.xml"
+ mf <- runStderrLoggingT (parseAtomFeed "http://example.com" c)
+ mf `shouldBe` Just atomFeed
+
+atomFeed = Feed {
+ feedId = "http://example.com",
+ feedTitle = "Example Blog",
+ feedUpdated = read "2015-07-23 04:05:00 UTC",
+ feedAuthors = [
+ Person {
+ personName = "Example Team",
+ personURI = Nothing,
+ personEmail = Nothing
+ }
+ ],
+ feedLinks = [
+ Link {
+ linkHref = "http://www.example.com/feed",
+ linkRel = Just "self"
+ },
+ Link {
+ linkHref = "http://www.example.com/",
+ linkRel = Nothing
+ }
+ ],
+ feedEntries = [
+ Entry {
+ entryId = "http://www.example.com/blog/2015/07/example1",
+ entryTitle = "Example 1",
+ entryUpdated = read "2015-07-23 04:05:00 UTC",
+ entryAuthors = [],
+ entryContent = Just (HtmlContent "<p>Blablabla</p>"),
+ entryLinks = [
+ Link {
+ linkHref = "http://www.example.com/blog/2015/07/example1",
+ linkRel = Nothing
+ }
+ ]
+ },
+ Entry {
+ entryId = "http://www.example.com/blog/2015/07/example2",
+ entryTitle = "Example 2",
+ entryUpdated = read "2015-07-22 12:00:00 UTC",
+ entryAuthors = [],
+ entryContent = Just (HtmlContent "<h1>Blo</h1>"),
+ entryLinks = [
+ Link {
+ linkHref = "http://www.example.com/blog/2015/07/example2",
+ linkRel = Nothing
+ }
+ ]
+ },
+ Entry {
+ entryId = "http://www.example.com/blog/2015/07/example3",
+ entryTitle = "Example 3",
+ entryUpdated = read "2015-07-06 00:00:00 UTC",
+ entryAuthors = [],
+ entryContent = Just (HtmlContent "<h1>Bli</h1>"),
+ entryLinks = [
+ Link {
+ linkHref = "http://www.example.com/blog/2015/07/example3",
+ linkRel = Nothing
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/files/atom.xml b/test/files/atom.xml
new file mode 100644
index 0000000..2492d2f
--- /dev/null
+++ b/test/files/atom.xml
@@ -0,0 +1 @@
+<?xml version="1.0" encoding="UTF-8"?><feed xmlns="http://www.w3.org/2005/Atom"><title>Example Blog</title><link href="http://www.example.com/feed" rel="self"/><link href="http://www.example.com/"/><updated>2015-07-23T04:05:00-00:00</updated><id>http://www.example.com/</id><author><name>Example Team</name></author><entry><id>http://www.example.com/blog/2015/07/example1</id><link href="http://www.example.com/blog/2015/07/example1"/><updated>2015-07-23T04:05:00-00:00</updated><title>Example 1</title><content type="html">&lt;p&gt;Blablabla&lt;/p&gt;</content></entry><entry><id>http://www.example.com/blog/2015/07/example2</id><link href="http://www.example.com/blog/2015/07/example2"/><updated>2015-07-22T12:00:00-00:00</updated><title>Example 2</title><content type="html">&lt;h1&gt;Blo&lt;/h1&gt;</content></entry><entry><id>http://www.example.com/blog/2015/07/example3</id><link href="http://www.example.com/blog/2015/07/example3"/><updated>2015-07-06T00:00:00-00:00</updated><title>Example 3</title><content type="html">&lt;h1&gt;Bli&lt;/h1&gt;</content></entry></feed>