3 -- import qualified System.FilePath as Path
4 -- import qualified Text.Blaze.Utils as Blaze
5 import Control.Monad (Monad(..))
6 import Data.Either (Either(..))
7 import Data.Function (($), (.))
8 import Data.Functor ((<$>))
9 import Data.Semigroup (Semigroup(..))
10 import Data.String (String)
12 import Text.Show (Show(..))
13 import qualified Data.ByteString.Lazy as BS
14 import qualified Data.List as List
15 import qualified Data.Text.Lazy as TL
16 import qualified Data.Text.Lazy.Encoding as TL
17 import qualified Data.TreeSeq.Strict as TreeSeq
18 import qualified Text.Blaze.Html.Renderer.Utf8 as Blaze
21 import Test.Tasty.Golden
23 import qualified Language.TCT as TCT
24 import qualified Language.TCT.Debug as TCT
25 import qualified Language.TCT.Write.HTML5 as TCT.Write.HTML5
26 import qualified Language.TCT.Write.Plain as TCT.Write.Plain
27 import qualified Language.TCT.Write.XML as TCT.Write.XML
29 diff :: String -> String -> [String]
30 diff ref new = ["diff", "-u", ref, new]
32 readAST :: String -> IO (Either TCT.ErrorRead TCT.Roots)
33 readAST inputFile = do
34 inp <- BS.readFile inputFile
35 return $ TCT.readTrees inputFile $ TL.decodeUtf8 inp
37 unLeft :: Show err => Either err BS.ByteString -> IO BS.ByteString
39 Left err -> return $ TL.encodeUtf8 $ TL.pack $ show err
42 goldensIO :: IO TestTree
44 inputFiles <- List.sort <$> findByExtension [".tct"] "test/Golden"
48 [ goldenVsStringDiff inputFile diff (inputFile <> ".ast") $
50 readAST inputFile >>= \ast ->
56 | inputFile <- inputFiles
59 [ goldenVsStringDiff inputFile diff inputFile $
61 readAST inputFile >>= \ast ->
64 . (<> TL.singleton '\n')
65 . TCT.Write.Plain.document
67 | inputFile <- inputFiles
70 [ goldenVsStringDiff inputFile diff (inputFile <> ".html5") $
72 readAST inputFile >>= \ast ->
75 . TCT.Write.HTML5.document
77 | inputFile <- inputFiles
80 [ goldenVsStringDiff inputFile diff (inputFile <> ".xml") $
82 readAST inputFile >>= \ast ->
88 . TCT.Write.XML.document
90 | inputFile <- inputFiles