From 06517a6a4c5c6c7a89ea4ad57d85ffc458393a07 Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Sun, 16 Nov 2014 08:58:40 +0800 Subject: (wip) Add support for @since (closes #26) --- .../test/Documentation/Haddock/ParserSpec.hs | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'haddock-library/test/Documentation/Haddock/ParserSpec.hs') diff --git a/haddock-library/test/Documentation/Haddock/ParserSpec.hs b/haddock-library/test/Documentation/Haddock/ParserSpec.hs index 5550e836..7b0ef78d 100644 --- a/haddock-library/test/Documentation/Haddock/ParserSpec.hs +++ b/haddock-library/test/Documentation/Haddock/ParserSpec.hs @@ -22,8 +22,8 @@ instance IsString (Doc String) where instance IsString a => IsString (Maybe a) where fromString = Just . fromString -parseParas :: String -> Doc String -parseParas = Parse.toRegular . Parse.parseParas +parseParas :: String -> (Maybe Version, Doc String) +parseParas = fmap Parse.toRegular . Parse.parseParas parseString :: String -> Doc String parseString = Parse.toRegular . Parse.parseString @@ -358,12 +358,30 @@ spec = do describe "parseParas" $ do let infix 1 `shouldParseTo` shouldParseTo :: String -> Doc String -> Expectation - shouldParseTo input ast = parseParas input `shouldBe` ast + shouldParseTo input ast = snd (parseParas input) `shouldBe` ast it "is total" $ do property $ \xs -> (length . show . parseParas) xs `shouldSatisfy` (> 0) + context "when parsing @since" $ do + it "adds specified version to the result" $ do + parseParas "@since 0.5.0" `shouldBe` (Just [0,5,0], DocEmpty) + + it "ignores trailing whitespace" $ do + parseParas "@since 0.5.0 \t " `shouldBe` (Just [0,5,0], DocEmpty) + + it "does not allow trailing input" $ do + parseParas "@since 0.5.0 foo" `shouldBe` (Nothing, DocParagraph "@since 0.5.0 foo") + + context "when given multiple times" $ do + it "gives last occurrence precedence" $ do + (parseParas . unlines) [ + "@since 0.5.0" + , "@since 0.6.0" + , "@since 0.7.0" + ] `shouldBe` (Just [0,7,0], DocEmpty) + context "when parsing text paragraphs" $ do let filterSpecial = filter (`notElem` (".(=#-[*`\v\f\n\t\r\\\"'_/@<> " :: String)) -- cgit v1.2.3