@@ -5,10 +5,12 @@ import Data.List (intersperse)
55import Data.Text (Text)
66import qualified Data.Text as T
77import Test.Tasty
8+import Test.Tasty.QuickCheck
89import Tests.Helpers
910import Text.Pandoc
1011import Text.Pandoc.Arbitrary ()
1112import Text.Pandoc.Builder
13+import Text.Pandoc.Walk (walk)
1214
1315amuse :: Text -> Pandoc
1416amuse = purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse]}
@@ -24,6 +26,30 @@ infix 4 =:
2426spcSep :: [Inlines] -> Inlines
2527spcSep = mconcat . intersperse space
2628
29+-- Tables and code blocks don't round-trip yet
30+
31+removeTables :: Block -> Block
32+removeTables (Table{}) = Para [Str "table was here"]
33+removeTables x = x
34+
35+removeCodeBlocks :: Block -> Block
36+removeCodeBlocks (CodeBlock{}) = Para [Str "table was here"]
37+removeCodeBlocks x = x
38+
39+-- Demand that any AST produced by Muse reader and written by Muse writer can be read back exactly the same way.
40+-- Currently we remove code blocks and tables and compare third rewrite to the second.
41+-- First and second rewrites are not equal yet.
42+roundTrip :: Block -> Bool
43+roundTrip b = d'' == d'''
44+ where d = walk (removeCodeBlocks . removeTables) $ Pandoc nullMeta [b]
45+ d' = rewrite d
46+ d'' = rewrite d'
47+ d''' = rewrite d''
48+ rewrite = amuse . T.pack . (++ "\n") . T.unpack .
49+ (purely $ writeMuse def { writerExtensions = extensionsFromList [Ext_amuse]
50+ , writerWrapText = WrapPreserve
51+ })
52+
2753tests :: [TestTree]
2854tests =
2955 [ testGroup "Inlines"
@@ -165,7 +191,8 @@ tests =
165191 ]
166192
167193 , testGroup "Blocks"
168− [ "Block elements end paragraphs" =:
194+ [ testProperty "Round trip" roundTrip
195+ , "Block elements end paragraphs" =:
169196 T.unlines [ "First paragraph"
170197 , "----"
171198 , "Second paragraph"