From a4926886ee8cc35e122a502903cb834a025773f4 Mon Sep 17 00:00:00 2001 From: "simon.hengel" Date: Sun, 18 Apr 2010 18:16:54 +0000 Subject: Add unit tests for parser --- tests/parsetests.hs | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/runparsetests.sh | 14 +++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/parsetests.hs create mode 100644 tests/runparsetests.sh diff --git a/tests/parsetests.hs b/tests/parsetests.hs new file mode 100644 index 00000000..f66355e2 --- /dev/null +++ b/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) diff --git a/tests/runparsetests.sh b/tests/runparsetests.sh new file mode 100644 index 00000000..f02d3f1c --- /dev/null +++ b/tests/runparsetests.sh @@ -0,0 +1,14 @@ +#!/bin/sh +cd `dirname $0` + +runhaskell -hide-all-packages -cpp \ + -packagecontainers \ + -packagearray \ + -packagebase \ + -packageghc \ + -packagexhtml \ + -packageghc-paths \ + -packageHUnit \ + -i../dist/build/ \ + -i../src/ \ + parsetests.hs -- cgit v1.2.3