diff options
Diffstat (limited to 'tests/unit-tests/parsetests.hs')
-rw-r--r-- | tests/unit-tests/parsetests.hs | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/tests/unit-tests/parsetests.hs b/tests/unit-tests/parsetests.hs index e0645401..0192ebfc 100644 --- a/tests/unit-tests/parsetests.hs +++ b/tests/unit-tests/parsetests.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE StandaloneDeriving, FlexibleInstances, UndecidableInstances, IncoherentInstances #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} module Main (main) where import Test.HUnit @@ -6,9 +8,14 @@ import DynFlags (defaultDynFlags) import Haddock.Lex (tokenise) import Haddock.Parse (parseParas) import Haddock.Types +import Outputable +import Data.Monoid -instance Show RdrName where - show x = "RdrName" +instance Outputable a => Show a where + show = showSDoc . ppr + +deriving instance Show a => Show (Doc a) +deriving instance Eq a =>Eq (Doc a) data ParseTest = ParseTest { input :: String @@ -47,16 +54,30 @@ tests = [ input = ">>> putFooBar\nfoo\n<BLANKLINE>\nbar" , result = Just $ DocExamples $ [Example "putFooBar" ["foo","","bar"]] } + + -- tests for links + , ParseTest { + input = "<http://example.com/>" + , result = Just . DocParagraph $ hyperlink "http://example.com/" Nothing `mappend` DocString "\n" + } + + , ParseTest { + input = "<http://example.com/ some link>" + , result = Just . DocParagraph $ hyperlink "http://example.com/" (Just "some link") `mappend` DocString "\n" + } ] +hyperlink :: String -> Maybe String -> Doc RdrName +hyperlink url = DocHyperlink . Hyperlink url +main :: IO () main = do _ <- runTestTT $ TestList $ map toTestCase tests return (); where toTestCase :: ParseTest -> Test - toTestCase (ParseTest input result) = TestCase $ assertEqual input result (parse input) + toTestCase (ParseTest s r) = TestCase $ assertEqual s r (parse s) parse :: String -> Maybe (Doc RdrName) - parse input = parseParas $ tokenise defaultDynFlags input (0,0) + parse s = parseParas $ tokenise (defaultDynFlags undefined) s (0,0) |