aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs25
-rw-r--r--test/lua/blocks-filter.lua8
-rw-r--r--test/lua/inlines-filter.lua19
-rw-r--r--test/lua/meta.lua6
4 files changed, 57 insertions, 1 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 7683df09f..5e01266c0 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -23,7 +23,8 @@ import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder (bulletList, definitionList, displayMath, divWith,
doc, doubleQuoted, emph, header, lineBlock,
linebreak, math, orderedList, para, plain, rawBlock,
- singleQuoted, space, str, strong)
+ singleQuoted, space, str, strong,
+ HasMeta (setMeta))
import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str),
Attr, Meta, Pandoc, pandocTypesVersion)
@@ -129,6 +130,28 @@ tests = map (localOption (QuickCheckTests 20))
(doc $ divWith ("", [], kv_before) (para "nil"))
(doc $ divWith ("", [], kv_after) (para "nil"))
+ , testCase "Filter list of inlines" $
+ assertFilterConversion "List of inlines"
+ "inlines-filter.lua"
+ (doc $ para ("Hello," <> linebreak <> "World! Wassup?"))
+ (doc $ para "Hello, World! Wassup?")
+
+ , testCase "Filter list of blocks" $
+ assertFilterConversion "List of blocks"
+ "blocks-filter.lua"
+ (doc $ para "one." <> para "two." <> para "three.")
+ (doc $ plain "3")
+
+ , testCase "Filter Meta" $
+ let setMetaBefore = setMeta "old" ("old" :: T.Text)
+ . setMeta "bool" False
+ setMetaAfter = setMeta "new" ("new" :: T.Text)
+ . setMeta "bool" True
+ in assertFilterConversion "Meta filtering"
+ "meta.lua"
+ (setMetaBefore . doc $ mempty)
+ (setMetaAfter . doc $ mempty)
+
, testCase "Script filename is set" $
assertFilterConversion "unexpected script name"
"script-name.lua"
diff --git a/test/lua/blocks-filter.lua b/test/lua/blocks-filter.lua
new file mode 100644
index 000000000..4e944e922
--- /dev/null
+++ b/test/lua/blocks-filter.lua
@@ -0,0 +1,8 @@
+function Blocks (blks)
+ -- verify that this looks like a `pandoc.List`
+ if not blks.find or not blks.map or not blks.filter then
+ error("table doesn't seem to be an instance of pandoc.List")
+ end
+ -- return plain block containing the number of elements in the list
+ return {pandoc.Plain {pandoc.Str(tostring(#blks))}}
+end
diff --git a/test/lua/inlines-filter.lua b/test/lua/inlines-filter.lua
new file mode 100644
index 000000000..69608bd77
--- /dev/null
+++ b/test/lua/inlines-filter.lua
@@ -0,0 +1,19 @@
+function isWorldAfterSpace (fst, snd)
+ return fst and fst.t == 'LineBreak'
+ and snd and snd.t == 'Str' and snd.text == 'World!'
+end
+
+function Inlines (inlns)
+ -- verify that this looks like a `pandoc.List`
+ if not inlns.find or not inlns.map or not inlns.filter then
+ error("table doesn't seem to be an instance of pandoc.List")
+ end
+
+ -- Remove spaces before string "World"
+ for i = #inlns-1,1,-1 do
+ if isWorldAfterSpace(inlns[i], inlns[i+1]) then
+ inlns[i] = pandoc.Space()
+ end
+ end
+ return inlns
+end
diff --git a/test/lua/meta.lua b/test/lua/meta.lua
new file mode 100644
index 000000000..5e2946203
--- /dev/null
+++ b/test/lua/meta.lua
@@ -0,0 +1,6 @@
+function Meta (meta)
+ meta.old = nil
+ meta.new = "new"
+ meta.bool = (meta.bool == false)
+ return meta
+end