From c298f6041c1dabff3d049b9fe7610b71fb3ff396 Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Tue, 9 Jul 2013 14:06:32 +0100 Subject: 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. --- src/Haddock/Doc.hs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/Haddock/Doc.hs') 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 -- cgit v1.2.3