]> gitweb @ CieloNegro.org - Rakka.git/blobdiff - tests/WikiParserTest.hs
Implemented more features
[Rakka.git] / tests / WikiParserTest.hs
similarity index 83%
rename from test/WikiParserTest.hs
rename to tests/WikiParserTest.hs
index 384cc5fde51f549d9310000a98ba9ef1469bb35a..d8772a192ebc2917f8fdfe100562b6eb2dfc65ca 100644 (file)
@@ -9,8 +9,17 @@ import           Test.HUnit
 import           Text.ParserCombinators.Parsec
 
 
+cmdTypeOf :: String -> Maybe CommandType
+cmdTypeOf "br"   = Just InlineCommandType
+cmdTypeOf "i"    = Just InlineCommandType
+cmdTypeOf "b"    = Just InlineCommandType
+cmdTypeOf "span" = Just InlineCommandType
+cmdTypeOf "div"  = Just BlockCommandType
+cmdTypeOf _      = Nothing
+
+
 parseWiki :: String -> Either String WikiPage
-parseWiki src = case parse wikiPage "" src of
+parseWiki src = case parse (wikiPage cmdTypeOf) "" src of
                   Left  err  -> Left (show err)
                   Right page -> Right page
 
@@ -216,6 +225,17 @@ testData = [ (parseWiki ""
                      , List (ListElement Numbered [ [Right (Text "b")] ])
                      ]))
 
+           , (parseWiki "*a<!-- comment -->"
+              ~?=
+              (Right [ List (ListElement Bullet [ [Right (Text "a")] ]) ]))
+
+           , (parseWiki "*a<!-- comment -->\n*b"
+              ~?=
+              (Right [ List (ListElement Bullet [ [Right (Text "a")]
+                                                , [Right (Text "b")]
+                                                ])
+                     ]))
+
            , (parseWiki "foo:bar"
               ~?=
               (Right [ Paragraph [ Text "foo"
@@ -277,4 +297,27 @@ testData = [ (parseWiki ""
            , (parseWiki "'''''foo'''''"
               ~?=
               (Right [ Paragraph [ Italic [Bold [Text "foo"]] ] ]))
+
+           , (parseWiki "<br />"
+              ~?=
+              (Right [ Paragraph [ InlineCmd (InlineCommand "br" [] []) ] ]))
+
+           , (parseWiki "<br style=\"clear: both\"/>"
+              ~?=
+              (Right [ Paragraph [ InlineCmd (InlineCommand "br" [("style", "clear: both")] []) ] ]))
+
+           , (parseWiki "<i><b>foo</b></i>"
+              ~?=
+              (Right [ Paragraph [ InlineCmd (InlineCommand "i" []
+                                              [ InlineCmd (InlineCommand "b" [] [ Text "foo" ]) ]) ] ]))
+
+           , (parseWiki "<i>\nfoo\n<!-- comment -->\nbar</i>"
+              ~?=
+              (Right [ Paragraph [ InlineCmd (InlineCommand "i" []
+                                              [ Text "\n"
+                                              , Text "foo"
+                                              , Text "\n"
+                                              , Text "\n"
+                                              , Text "bar"
+                                              ]) ] ]))
            ]