aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-01-13 16:51:15 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2019-01-13 17:14:10 +0100
commit42a7b80c0479c83ed5300103a04545d5139f7a7e (patch)
tree4f3e314356eb68f62001da52d482b8183f541d45 /test
parent9ac5b9d710b52395b43b04fb27ca80102268b547 (diff)
downloadpandoc-42a7b80c0479c83ed5300103a04545d5139f7a7e.tar.gz
data/pandoc.lua: auto-fix nested constructor arguments
Incorrect types to pandoc element constructors are automatically converted to the correct types when possible. This was already done for most constructors, but conversions are now also done for nested types (like lists of lists).
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs19
-rw-r--r--test/lua/smart-constructors.lua10
2 files changed, 25 insertions, 4 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 4bc949ddb..7ad48116a 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -10,10 +10,10 @@ import Test.Tasty (TestTree, localOption)
import Test.Tasty.HUnit (Assertion, assertEqual, testCase)
import Test.Tasty.QuickCheck (QuickCheckTests (..), ioProperty, testProperty)
import Text.Pandoc.Arbitrary ()
-import Text.Pandoc.Builder (bulletList, divWith, doc, doubleQuoted, emph,
- header, linebreak, para, plain, rawBlock,
- singleQuoted, space, str, strong,
- math, displayMath)
+import Text.Pandoc.Builder (bulletList, definitionList, displayMath, divWith,
+ doc, doubleQuoted, emph, header, lineBlock,
+ linebreak, math, orderedList, para, plain, rawBlock,
+ singleQuoted, space, str, strong)
import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str),
Attr, Meta, Pandoc, pandocTypesVersion)
@@ -92,6 +92,17 @@ tests = map (localOption (QuickCheckTests 20))
(doc $ para "one" <> para "two")
(doc $ para "2")
+ , testCase "Smart constructors" $
+ assertFilterConversion "smart constructors returned a wrong result"
+ "smart-constructors.lua"
+ (doc $ para "")
+ (doc $ mconcat
+ [ bulletList [para "Hello", para "World"]
+ , definitionList [("foo", [para "placeholder"])]
+ , lineBlock ["Moin", "Welt"]
+ , orderedList [plain "one", plain "two"]
+ ])
+
, testCase "Convert header upper case" $
assertFilterConversion "converting header to upper case failed"
"uppercase-header.lua"
diff --git a/test/lua/smart-constructors.lua b/test/lua/smart-constructors.lua
new file mode 100644
index 000000000..6e579a12f
--- /dev/null
+++ b/test/lua/smart-constructors.lua
@@ -0,0 +1,10 @@
+-- Test that constructors are "smart" in that they autoconvert
+-- types where sensible.
+function Para (_)
+ return {
+ pandoc.BulletList{pandoc.Para "Hello", pandoc.Para "World"},
+ pandoc.DefinitionList{{"foo", pandoc.Para "placeholder"}},
+ pandoc.LineBlock{"Moin", "Welt"},
+ pandoc.OrderedList{pandoc.Plain{pandoc.Str "one"}, pandoc.Plain "two"}
+ }
+end