diff options
author | Mateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk> | 2013-07-09 14:06:32 +0100 |
---|---|---|
committer | Simon Hengel <sol@typeful.net> | 2013-08-25 09:24:13 +0200 |
commit | c298f6041c1dabff3d049b9fe7610b71fb3ff396 (patch) | |
tree | 67b603ac34a13e5e96ff4e86c539c1b065ec8116 /src/Haddock | |
parent | 90ad0ea538d2fafed2047de8414c55627b94e879 (diff) |
Add spec tests.
This adds tests for all elements we can create during regular
parsing. This also adds tests for text with unicode in it.
Diffstat (limited to 'src/Haddock')
-rw-r--r-- | src/Haddock/Doc.hs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/Haddock/Doc.hs b/src/Haddock/Doc.hs index ca3b6658..18555cfb 100644 --- a/src/Haddock/Doc.hs +++ b/src/Haddock/Doc.hs @@ -1,12 +1,13 @@ module Haddock.Doc ( docAppend, - docParagraph + docParagraph, + combineStringNodes ) where import Haddock.Types import Data.Char (isSpace) - +import Control.Arrow ((***)) -- used to make parsing easier; we group the list items later docAppend :: Doc id -> Doc id -> Doc id @@ -63,3 +64,25 @@ docCodeBlock (DocString s) docCodeBlock (DocAppend l r) = DocAppend l (docCodeBlock r) docCodeBlock d = d + +-- | This is a hack that joins neighbouring 'DocString's into a single one. +-- This is done to ease up the testing and doesn't change the final result +-- as this would be done later anyway. +combineStringNodes :: Doc id -> Doc id +combineStringNodes (DocAppend (DocString x) (DocString y)) = DocString (x ++ y) +combineStringNodes (DocAppend (DocString x) (DocAppend (DocString y) z)) = + tryjoin (DocAppend (DocString (x ++ y)) (combineStringNodes z)) +combineStringNodes (DocAppend x y) = tryjoin (DocAppend (combineStringNodes x) (combineStringNodes y)) +combineStringNodes (DocParagraph x) = DocParagraph (combineStringNodes x) +combineStringNodes (DocWarning x) = DocWarning (combineStringNodes x) +combineStringNodes (DocEmphasis x) = DocEmphasis (combineStringNodes x) +combineStringNodes (DocMonospaced x) = DocMonospaced (combineStringNodes x) +combineStringNodes (DocUnorderedList xs) = DocUnorderedList (map combineStringNodes xs) +combineStringNodes (DocOrderedList x) = DocOrderedList (map combineStringNodes x) +combineStringNodes (DocDefList xs) = DocDefList (map (combineStringNodes *** combineStringNodes) xs) +combineStringNodes (DocCodeBlock x) = DocCodeBlock (combineStringNodes x) +combineStringNodes x = x + +tryjoin :: Doc id -> Doc id +tryjoin (DocAppend (DocString x) (DocString y)) = DocString (x ++ y) +tryjoin x = x |