aboutsummaryrefslogtreecommitdiff
path: root/tests/unit-tests/parsetests.hs
diff options
context:
space:
mode:
authorDavid Waern <david.waern@gmail.com>2010-05-11 19:14:31 +0000
committerDavid Waern <david.waern@gmail.com>2010-05-11 19:14:31 +0000
commita7cfb1d83c7e0f97a806e1f2c202416e625b2ce2 (patch)
treea4154de09f38ddee5e17bc16bfac323a41d9b7b5 /tests/unit-tests/parsetests.hs
parentc7d9f7678de931e580a3fe1bec2fb0e2dead84d3 (diff)
Re-organise the testsuite structure
Diffstat (limited to 'tests/unit-tests/parsetests.hs')
-rw-r--r--tests/unit-tests/parsetests.hs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/unit-tests/parsetests.hs b/tests/unit-tests/parsetests.hs
new file mode 100644
index 00000000..f66355e2
--- /dev/null
+++ b/tests/unit-tests/parsetests.hs
@@ -0,0 +1,56 @@
+module Main (main) where
+
+import Test.HUnit
+import RdrName (RdrName)
+import DynFlags (defaultDynFlags)
+import Haddock.Lex (tokenise)
+import Haddock.Parse (parseParas)
+import Haddock.Types
+
+instance Show RdrName where
+ show x = "RdrName"
+
+data ParseTest = ParseTest {
+ input :: String
+ , result :: (Maybe (Doc RdrName))
+ }
+
+tests :: [ParseTest]
+tests = [
+ ParseTest {
+ input = "foobar"
+ , result = Just $ DocParagraph $ DocString "foobar\n"
+ }
+
+ , ParseTest {
+ input = "foobar\n\nghci> fib 10\n55"
+ , result = Just $ DocAppend (DocParagraph $ DocString "foobar\n") (DocExamples $ [Example "fib 10" ["55"]])
+ }
+
+ , ParseTest {
+ input = "foobar\nghci> fib 10\n55"
+ , result = Nothing -- parse error
+ }
+
+ , ParseTest {
+ input = "foobar\n\n> some code"
+ , result = Just (DocAppend (DocParagraph (DocString "foobar\n")) (DocCodeBlock (DocString " some code\n")))
+ }
+
+ , ParseTest {
+ input = "foobar\n> some code"
+ , result = Nothing -- parse error
+ }
+ ]
+
+
+main = do
+ _ <- runTestTT $ TestList $ map testFromParseTest tests
+ return ();
+ where
+
+ testFromParseTest :: ParseTest -> Test
+ testFromParseTest (ParseTest input result) = TestCase $ assertEqual input (parse input) result
+
+ parse :: String -> Maybe (Doc RdrName)
+ parse input = parseParas $ tokenise defaultDynFlags input (0,0)