summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs34
-rw-r--r--test/lua/hello-world-doc.lua10
-rw-r--r--test/lua/plain-to-para.lua6
-rw-r--r--test/lua/strmacro.lua10
-rw-r--r--test/test-pandoc.hs2
5 files changed, 62 insertions, 0 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
new file mode 100644
index 000000000..4f8bd46d8
--- /dev/null
+++ b/test/Tests/Lua.hs
@@ -0,0 +1,34 @@
+{-# Language OverloadedStrings #-}
+module Tests.Lua ( tests ) where
+
+import System.FilePath ((</>))
+import Test.Tasty (TestTree)
+import Test.Tasty.HUnit (Assertion, assertEqual, testCase)
+import Text.Pandoc.Builder
+import Text.Pandoc.Lua
+
+tests :: [TestTree]
+tests =
+ [ testCase "macro expansion via filter" $
+ assertFilterConversion "a '{{helloworld}}' string is expanded"
+ "strmacro.lua"
+ (doc . para $ str "{{helloworld}}")
+ (doc . para . emph $ str "Hello, World")
+
+ , testCase "convert all plains to paras" $
+ assertFilterConversion "plains become para"
+ "plain-to-para.lua"
+ (doc $ bulletList [plain (str "alfa"), plain (str "bravo")])
+ (doc $ bulletList [para (str "alfa"), para (str "bravo")])
+
+ , testCase "make hello world document" $
+ assertFilterConversion "Document contains 'Hello, World!'"
+ "hello-world-doc.lua"
+ (doc . para $ str "Hey!" <> linebreak <> str "What's up?")
+ (doc . para $ str "Hello," <> space <> str "World!")
+ ]
+
+assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
+assertFilterConversion msg filterPath docIn docExpected = do
+ docRes <- runLuaFilter ("lua" </> filterPath) [] docIn
+ assertEqual msg docExpected docRes
diff --git a/test/lua/hello-world-doc.lua b/test/lua/hello-world-doc.lua
new file mode 100644
index 000000000..221321a60
--- /dev/null
+++ b/test/lua/hello-world-doc.lua
@@ -0,0 +1,10 @@
+return {
+ {
+ Doc = function(doc)
+ local meta = {}
+ local hello = { pandoc.Str "Hello,", pandoc.Space(), pandoc.Str "World!" }
+ local blocks = { pandoc.Para(hello) }
+ return pandoc.Doc(blocks, meta)
+ end
+ }
+}
diff --git a/test/lua/plain-to-para.lua b/test/lua/plain-to-para.lua
new file mode 100644
index 000000000..747257411
--- /dev/null
+++ b/test/lua/plain-to-para.lua
@@ -0,0 +1,6 @@
+return {
+ { Plain = function (blk)
+ return pandoc.Para(blk.c)
+ end,
+ }
+}
diff --git a/test/lua/strmacro.lua b/test/lua/strmacro.lua
new file mode 100644
index 000000000..1b28801be
--- /dev/null
+++ b/test/lua/strmacro.lua
@@ -0,0 +1,10 @@
+return {
+ { Str = function (inline)
+ if inline.c == "{{helloworld}}" then
+ return pandoc.Emph {pandoc.Str "Hello, World"}
+ else
+ return inline
+ end
+ end,
+ }
+}
diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs
index 396c0f478..97ad3183f 100644
--- a/test/test-pandoc.hs
+++ b/test/test-pandoc.hs
@@ -5,6 +5,7 @@ module Main where
import GHC.IO.Encoding
import Test.Tasty
import qualified Tests.Command
+import qualified Tests.Lua
import qualified Tests.Old
import qualified Tests.Readers.Docx
import qualified Tests.Readers.EPUB
@@ -61,6 +62,7 @@ tests = testGroup "pandoc tests" [ Tests.Command.tests
, testGroup "Txt2Tags" Tests.Readers.Txt2Tags.tests
, testGroup "EPUB" Tests.Readers.EPUB.tests
]
+ , testGroup "Lua filters" Tests.Lua.tests
]
main :: IO ()