aboutsummaryrefslogtreecommitdiff
path: root/test/Tests
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert+github@zeitkraut.de>2017-03-20 15:17:03 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-03-20 15:17:03 +0100
commitf2f6851713674545e2f303b95589cbaff8e6a6b9 (patch)
treea3b65213bb63aece6b0ae3726394abb153b1c7fd /test/Tests
parentb010a8c5e7ba4969100fe078f0f9a1a6cdaf7c5c (diff)
downloadpandoc-f2f6851713674545e2f303b95589cbaff8e6a6b9.tar.gz
Lua filters (#3514)
* Add `--lua-filter` option. This works like `--filter` but takes pathnames of special lua filters and uses the lua interpreter baked into pandoc, so that no external interpreter is needed. Note that lua filters are all applied after regular filters, regardless of their position on the command line. * Add Text.Pandoc.Lua, exporting `runLuaFilter`. Add `pandoc.lua` to data files. * Add private module Text.Pandoc.Lua.PandocModule to supply the default lua module. * Add Tests.Lua to tests. * Add data/pandoc.lua, the lua module pandoc imports when processing its lua filters. * Document in MANUAL.txt.
Diffstat (limited to 'test/Tests')
-rw-r--r--test/Tests/Lua.hs34
1 files changed, 34 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