git.iko.soy/typeable/pandoc
on master help sign in
Muse reader: Add partial round trip test
a8ac673Alexander Krotov
test/Tests/Readers/Muse.hs+28−1
@@ -5,10 +5,12 @@ import Data.List (intersperse)
5import Data.Text (Text)
5import Data.Text (Text)
6import qualified Data.Text as T
6import qualified Data.Text as T
7import Test.Tasty
7import Test.Tasty
8+import Test.Tasty.QuickCheck
8import Tests.Helpers
9import Tests.Helpers
9import Text.Pandoc
10import Text.Pandoc
10import Text.Pandoc.Arbitrary ()
11import Text.Pandoc.Arbitrary ()
11import Text.Pandoc.Builder
12import Text.Pandoc.Builder
13+import Text.Pandoc.Walk (walk)
12
14
13amuse :: Text -> Pandoc
15amuse :: Text -> Pandoc
14amuse = purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse]}
16amuse = purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse]}
@@ -24,6 +26,30 @@ infix 4 =:
24spcSep :: [Inlines] -> Inlines
26spcSep :: [Inlines] -> Inlines
25spcSep = mconcat . intersperse space
27spcSep = mconcat . intersperse space
26
28
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+
27tests :: [TestTree]
53tests :: [TestTree]
28tests =
54tests =
29 [ testGroup "Inlines"
55 [ testGroup "Inlines"
@@ -165,7 +191,8 @@ tests =
165 ]
191 ]
166
192
167 , testGroup "Blocks"
193 , testGroup "Blocks"
194+ [ testProperty "Round trip" roundTrip
168− [ "Block elements end paragraphs" =:
195+ , "Block elements end paragraphs" =:
169 T.unlines [ "First paragraph"
196 T.unlines [ "First paragraph"
170 , "----"
197 , "----"
171 , "Second paragraph"
198 , "Second paragraph"