[commit: haddock] 2.17.3.1-spanfix, alexbiehl-patch-1, ghc-8.0, ghc-8.0-facebook, ghc-head, ghc-head1, haddock-quick, headdock-library-1.4.5, ie_avails, issue-303, issue-475, master, pr-filter-maps, pr/cabal-desc, travis, v2.17, v2.17.3, v2.18, wip-located-module-as, wip/D2418, wip/T11080-open-data-kinds, wip/T11430, wip/T12105, wip/T12105-2, wip/T12942, wip/T13163, wip/T14529, wip/T3384, wip/embelleshed-rdr, wip/new-tree-one-param, wip/rae, wip/remove-frames, wip/remove-frames1, wip/revert-ttg-2017-11-20, wip/ttg-2017-10-13, wip/ttg-2017-10-31, wip/ttg-2017-11-06, wip/ttg2-2017-11-10, wip/ttg3-2017-11-12, wip/ttg4-constraints-2017-11-13, wip/ttg6-unrevert-2017-11-22: Refactor and simplify XHTML helper module of test package. (5934c41)

git at git.haskell.org git at git.haskell.org
Tue Nov 28 11:37:51 UTC 2017


Repository : ssh://git@git.haskell.org/haddock

On branches: 2.17.3.1-spanfix,alexbiehl-patch-1,ghc-8.0,ghc-8.0-facebook,ghc-head,ghc-head1,haddock-quick,headdock-library-1.4.5,ie_avails,issue-303,issue-475,master,pr-filter-maps,pr/cabal-desc,travis,v2.17,v2.17.3,v2.18,wip-located-module-as,wip/D2418,wip/T11080-open-data-kinds,wip/T11430,wip/T12105,wip/T12105-2,wip/T12942,wip/T13163,wip/T14529,wip/T3384,wip/embelleshed-rdr,wip/new-tree-one-param,wip/rae,wip/remove-frames,wip/remove-frames1,wip/revert-ttg-2017-11-20,wip/ttg-2017-10-13,wip/ttg-2017-10-31,wip/ttg-2017-11-06,wip/ttg2-2017-11-10,wip/ttg3-2017-11-12,wip/ttg4-constraints-2017-11-13,wip/ttg6-unrevert-2017-11-22
Link       : http://git.haskell.org/haddock.git/commitdiff/5934c411a8ebe0ba1a317f7c95babfbd63106254

>---------------------------------------------------------------

commit 5934c411a8ebe0ba1a317f7c95babfbd63106254
Author: Ɓukasz Hanuszczak <lukasz.hanuszczak at gmail.com>
Date:   Fri Aug 14 00:34:10 2015 +0200

    Refactor and simplify XHTML helper module of test package.


>---------------------------------------------------------------

5934c411a8ebe0ba1a317f7c95babfbd63106254
 haddock-test/src/Test/Haddock/Xhtml.hs | 40 ++++++++++++++++++++--------------
 html-test/run.hs                       | 17 +++++++++------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/haddock-test/src/Test/Haddock/Xhtml.hs b/haddock-test/src/Test/Haddock/Xhtml.hs
index 35f5910..b694149 100644
--- a/haddock-test/src/Test/Haddock/Xhtml.hs
+++ b/haddock-test/src/Test/Haddock/Xhtml.hs
@@ -2,47 +2,55 @@
 {-# LANGUAGE StandaloneDeriving #-}
 
 
-module Test.Haddock.Xhtml where
+module Test.Haddock.Xhtml
+    ( Xhtml(..)
+    , parseXhtml, dumpXhtml
+    , stripLinks, stripFooter
+    ) where
 
 
-import Control.Monad
-
 import Data.Generics.Aliases
 import Data.Generics.Schemes
 
 import Text.XML.Light
 
 
-deriving instance Eq Content
+newtype Xhtml = Xhtml
+    { xhtmlElement :: Element
+    } deriving Eq
+
+
+-- TODO: Find a way to avoid warning about orphan instances.
 deriving instance Eq Element
+deriving instance Eq Content
 deriving instance Eq CData
 
 
-readXml :: FilePath -> IO (Maybe Element)
-readXml = liftM parseXMLDoc . readFile
+parseXhtml :: String -> Maybe Xhtml
+parseXhtml = fmap Xhtml . parseXMLDoc
 
 
-strip :: Element -> Element
-strip = stripFooter . stripLinks
+dumpXhtml :: Xhtml -> String
+dumpXhtml = ppElement . xhtmlElement
 
 
-stripLinks :: Element -> Element
+stripLinks :: Xhtml -> Xhtml
 stripLinks =
-    everywhere (mkT unlink)
+    Xhtml . everywhere (mkT unlink) . xhtmlElement
   where
     unlink attr@(Attr { attrKey = key })
         | qName key == "href" = attr { attrVal = "#" }
         | otherwise = attr
 
 
-stripFooter :: Element -> Element
+stripFooter :: Xhtml -> Xhtml
 stripFooter =
-    everywhere (mkT defoot)
+    Xhtml . everywhere (mkT defoot) . xhtmlElement
   where
-    defoot elem
-        | isFooter elem = elem { elContent = [] }
-        | otherwise = elem
-    isFooter elem = any isFooterAttr $ elAttribs elem
+    defoot el
+        | isFooter el = el { elContent = [] }
+        | otherwise = el
+    isFooter el = any isFooterAttr $ elAttribs el
     isFooterAttr (Attr { .. }) = and
         [ qName attrKey == "id"
         , attrVal == "footer"
diff --git a/html-test/run.hs b/html-test/run.hs
index 2758bf5..ab007f5 100755
--- a/html-test/run.hs
+++ b/html-test/run.hs
@@ -7,13 +7,11 @@ import System.FilePath
 import Test.Haddock
 import Test.Haddock.Xhtml
 
-import qualified Text.XML.Light as Xml
 
-
-checkConfig :: CheckConfig Xml.Element
+checkConfig :: CheckConfig Xhtml
 checkConfig = CheckConfig
-    { ccfgRead = \_ input -> strip <$> Xml.parseXMLDoc input
-    , ccfgDump = Xml.ppElement
+    { ccfgRead = \mdl input -> stripIfRequired mdl <$> parseXhtml input
+    , ccfgDump = dumpXhtml
     , ccfgEqual = (==)
     }
 
@@ -26,8 +24,13 @@ main :: IO ()
 main = runAndCheck =<< parseArgs checkConfig dirConfig =<< getArgs
 
 
--- *** OLD TEST RUNNER UTILITY FUNCTIONS ***
--- These are considered bad and should be replaced as soon as possible.
+stripIfRequired :: String -> Xhtml -> Xhtml
+stripIfRequired mdl =
+    stripLinks' . stripFooter
+  where
+    stripLinks'
+        | mdl `elem` preserveLinksModules = id
+        | otherwise = stripFooter
 
 
 -- | List of modules in which we don't 'stripLinks'



More information about the ghc-commits mailing list