@@ -15,13 +15,40 @@ module Tests.Readers.FB2 (tests) where
15import Prelude
15import Prelude
16import Test.Tasty
16import Test.Tasty
17import Tests.Helpers
17import Tests.Helpers
18−import Test.Tasty.Golden (goldenVsString)
18+-- import Test.Tasty.Golden (goldenVsString)
19+import Test.Tasty.Golden.Advanced (goldenTest)
21+import qualified Data.ByteString.Lazy as LBS
19import qualified Data.ByteString as BS
23import qualified Data.ByteString as BS
20import Text.Pandoc
24import Text.Pandoc
21import Text.Pandoc.UTF8 (toText, fromStringLazy)
25import Text.Pandoc.UTF8 (toText, fromStringLazy)
22import Data.Text (Text, unpack)
26import Data.Text (Text, unpack)
23import System.FilePath (replaceExtension)
27import System.FilePath (replaceExtension)
29+simpleCmp :: Eq a => String -> a -> a -> IO (Maybe String)
31+ return $ if x == y then Nothing else Just e
35+ :: TestName -- ^ test name
36+ -> FilePath -- ^ path to the «golden» file (the file that contains correct output)
37+ -> IO LBS.ByteString -- ^ action that returns a string
38+ -> TestTree -- ^ the test verifies that the returned string is the same as the golden file contents
39+goldenVsString name ref act =
43+ (LBS.toStrict <$> act)
47+ cmp x y = simpleCmp msg x y
49+ msg = printf "Test output from %s was different from %s. It was: %s" ref (show x) (show y)
50+ upd = BS.writeFile ref
25fb2ToNative :: Text -> Text
52fb2ToNative :: Text -> Text
26fb2ToNative = purely (writeNative def{ writerTemplate = Just mempty }) . purely (readFB2 def)
53fb2ToNative = purely (writeNative def{ writerTemplate = Just mempty }) . purely (readFB2 def)