+module WikiParserTest
+ ( testData
+ )
+ where
+
+import Rakka.Wiki
+import Rakka.Wiki.Parser
+import Test.HUnit
+import Text.ParserCombinators.Parsec
+
+
+parseWiki :: String -> Either String WikiPage
+parseWiki src = case parse wikiPage "" src of
+ Left err -> Left (show err)
+ Right page -> Right page
+
+
+testData :: [Test]
+testData = [ (parseWiki ""
+ ~?=
+ (Right []))
+
+ , (parseWiki "=heading="
+ ~?=
+ (Right [Block (Heading 1 "heading")]))
+
+ , (parseWiki "== heading == \n"
+ ~?=
+ (Right [Block (Heading 2 "heading")]))
+
+ , (parseWiki "===== hello world =====\n"
+ ~?=
+ (Right [Block (Heading 5 "hello world")]))
+
+ , (parseWiki "a =not a heading="
+ ~?=
+ (Right [Inline (Text "a =not a heading=")]))
+
+ , (parseWiki "=h=\n\n=h="
+ ~?=
+ (Right [ Block (Heading 1 "h")
+ , Block (Heading 1 "h")
+ ]))
+
+ , (parseWiki "foo\nbar\n\nbaz\n"
+ ~?=
+ (Right [ Inline (Text "foo")
+ , Inline (Text "\n")
+ , Inline (Text "bar")
+ , Block EmptyLine
+ , Inline (Text "baz")
+ , Inline (Text "\n")
+ ]))
+
+ , (parseWiki "foo\n\n\nbar"
+ ~?=
+ (Right [ Inline (Text "foo")
+ , Block EmptyLine
+ , Inline (Text "bar")
+ ]))
+
+ , (parseWiki "foo\n=h="
+ ~?=
+ (Right [ Inline (Text "foo")
+ , Inline (Text "\n")
+ , Block (Heading 1 "h")
+ ]))
+
+ , (parseWiki "<!-- comment -->"
+ ~?=
+ (Right []))
+
+ , (parseWiki "<!-- comment -->foo"
+ ~?=
+ (Right [Inline (Text "foo")]))
+
+ , (parseWiki "foo<!-- comment -->"
+ ~?=
+ (Right [Inline (Text "foo")]))
+
+ , (parseWiki "foo<!-- comment -->bar"
+ ~?=
+ (Right [ Inline (Text "foo")
+ , Inline (Text "bar")
+ ]))
+
+ , (parseWiki "<!-- comment -->=h="
+ ~?=
+ (Right [Block (Heading 1 "h")]))
+
+ , (parseWiki "=h= <!---->"
+ ~?=
+ (Right [Block (Heading 1 "h")]))
+
+ , (parseWiki "<!-- <!-- nested --> comment -->"
+ ~?=
+ (Right []))
+
+ , (parseWiki "[[Page]]"
+ ~?=
+ (Right [Inline (PageLink (Just "Page") Nothing Nothing)]))
+
+ , (parseWiki "[[Page|Link to \"Page\"]]"
+ ~?=
+ (Right [Inline (PageLink (Just "Page") Nothing (Just "Link to \"Page\""))]))
+
+ , (parseWiki "[[Page#foo]]"
+ ~?=
+ (Right [Inline (PageLink (Just "Page") (Just "foo") Nothing)]))
+
+ , (parseWiki "[[#foo]]"
+ ~?=
+ (Right [Inline (PageLink Nothing (Just "foo") Nothing)]))
+
+ , (parseWiki "[[Page#foo|Link to \"Page#foo\"]]"
+ ~?=
+ (Right [Inline (PageLink (Just "Page") (Just "foo") (Just "Link to \"Page#foo\""))]))
+
+ , (parseWiki "foo [[Bar]] baz"
+ ~?=
+ (Right [ Inline (Text "foo ")
+ , Inline (PageLink (Just "Bar") Nothing Nothing)
+ , Inline (Text " baz")
+ ]))
+
+ , (parseWiki "[[Foo]]\n[[Bar]]"
+ ~?=
+ (Right [ Inline (PageLink (Just "Foo") Nothing Nothing)
+ , Inline (Text "\n")
+ , Inline (PageLink (Just "Bar") Nothing Nothing)
+ ]))
+ ]