3 import Control.Monad (Monad(..), sequence)
4 import Data.Either (Either(..))
5 import Data.Function (($), (.))
6 import Data.Functor ((<$>))
7 import Data.Semigroup (Semigroup(..))
8 import Data.String (String)
9 import System.IO (IO, FilePath)
10 import Text.Show (Show(..))
11 import qualified Data.ByteString.Lazy as BSL
12 import qualified Data.List as List
13 import qualified Data.Text.Lazy as TL
14 import qualified Data.Text.Lazy.Encoding as TL
17 import Test.Tasty.Golden
19 import qualified Symantic.XML.RelaxNG as RelaxNG
20 import qualified Symantic.Atom as Atom
22 goldensIO :: IO TestTree
24 testGroup "Golden" <$>
29 goldensAtom :: IO TestTree
31 inputFiles <- List.sort <$> findByExtension [".xml"] "test/Golden"
32 return $ testGroup "RelaxNG"
33 [ testGroup "Validate"
34 [ testGolden inputFile ".read" $
35 ((TL.encodeUtf8 . TL.pack . show) <$>) <$>
36 RelaxNG.readWithRelaxNG Atom.format inputFile
37 | inputFile <- inputFiles
41 [ testGolden "test/Golden/atom" ".rnc" $
42 return $ Right $ TL.encodeUtf8 $
43 RelaxNG.writeRNC Atom.format
48 -- * Golden testing utilities
49 testGolden :: TestName -> TestName -> IO (Either String BSL.ByteString) -> TestTree
50 testGolden testName expectedExt =
51 goldenVsStringDiff testName diffGolden (testName <> expectedExt)
54 diffGolden :: FilePath -> FilePath -> [String]
55 diffGolden ref new = ["diff", "-u", ref, new]
57 unLeft :: Either String BSL.ByteString -> IO BSL.ByteString
59 Left err -> return $ TL.encodeUtf8 $ TL.pack err