aboutsummaryrefslogtreecommitdiff
path: root/haddock-library/test/Documentation
diff options
context:
space:
mode:
authorSimon Hengel <sol@typeful.net>2014-11-16 08:58:40 +0800
committerSimon Hengel <sol@typeful.net>2014-11-16 10:20:19 +0800
commit06517a6a4c5c6c7a89ea4ad57d85ffc458393a07 (patch)
treeaa06a22a299eb9d8f7e5efa5528a7c31534bd6d3 /haddock-library/test/Documentation
parentc2b84c0c55bce1120db9826391de0466c33b3062 (diff)
(wip) Add support for @since (closes #26)
Diffstat (limited to 'haddock-library/test/Documentation')
-rw-r--r--haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs7
-rw-r--r--haddock-library/test/Documentation/Haddock/ParserSpec.hs24
2 files changed, 25 insertions, 6 deletions
diff --git a/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs b/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
index 32dd11d4..10c701c7 100644
--- a/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
+++ b/haddock-library/test/Documentation/Haddock/Parser/UtilSpec.hs
@@ -5,6 +5,7 @@ import Documentation.Haddock.Parser.Monad
import Documentation.Haddock.Parser.Util
import Data.Either.Compat (isLeft)
import Test.Hspec
+import Control.Applicative
main :: IO ()
main = hspec spec
@@ -13,10 +14,10 @@ spec :: Spec
spec = do
describe "takeUntil" $ do
it "takes everything until a specified byte sequence" $ do
- parseOnly (takeUntil "end") "someend" `shouldBe` Right "some"
+ snd <$> parseOnly (takeUntil "end") "someend" `shouldBe` Right "some"
it "requires the end sequence" $ do
- parseOnly (takeUntil "end") "someen" `shouldSatisfy` isLeft
+ snd <$> parseOnly (takeUntil "end") "someen" `shouldSatisfy` isLeft
it "takes escaped bytes unconditionally" $ do
- parseOnly (takeUntil "end") "some\\endend" `shouldBe` Right "some\\end"
+ snd <$> parseOnly (takeUntil "end") "some\\endend" `shouldBe` Right "some\\end"
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))