summaryrefslogtreecommitdiff
path: root/test/Tests
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-12-02 23:07:29 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2017-12-02 23:07:29 +0100
commitd5b1c7b767a24bda592ea35902b8e1dc971d6d80 (patch)
tree3c39efd50b1390ad4dd447cd5a4c1ee14ae1184a /test/Tests
parenta7953a60b984474b6937e153c62f51b560e6f994 (diff)
Lua filters: refactor lua module handling
The integration with Lua's package/module system is improved: A pandoc-specific package searcher is prepended to the searchers in `package.searchers`. The modules `pandoc` and `pandoc.mediabag` can now be loaded via `require`.
Diffstat (limited to 'test/Tests')
-rw-r--r--test/Tests/Lua.hs24
1 files changed, 11 insertions, 13 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 8caab694c..eaa7eb405 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -12,9 +12,9 @@ import Text.Pandoc.Builder (bulletList, divWith, doc, doubleQuoted, emph,
singleQuoted, space, str, strong, (<>))
import Text.Pandoc.Class (runIOorExplode)
import Text.Pandoc.Definition (Block, Inline, Meta, Pandoc)
-import Text.Pandoc.Lua
+import Text.Pandoc.Lua (initLuaState, runLuaFilter, luaPackageParams)
-import Foreign.Lua
+import qualified Foreign.Lua as Lua
tests :: [TestTree]
tests = map (localOption (QuickCheckTests 20))
@@ -101,20 +101,18 @@ assertFilterConversion msg filterPath docIn docExpected = do
Left _ -> fail "lua filter failed"
Right docRes -> assertEqual msg docExpected docRes
-roundtripEqual :: (Eq a, FromLuaStack a, ToLuaStack a) => a -> IO Bool
+roundtripEqual :: (Eq a, Lua.FromLuaStack a, Lua.ToLuaStack a) => a -> IO Bool
roundtripEqual x = (x ==) <$> roundtripped
where
- roundtripped :: (FromLuaStack a, ToLuaStack a) => IO a
- roundtripped = runLua $ do
- openlibs
- pushPandocModule (Just "../data")
- setglobal "pandoc"
- oldSize <- gettop
- push x
- size <- gettop
- when ((size - oldSize) /= 1) $
+ roundtripped :: (Lua.FromLuaStack a, Lua.ToLuaStack a) => IO a
+ roundtripped = Lua.runLua $ do
+ initLuaState =<< Lua.liftIO (runIOorExplode (luaPackageParams (Just "../data")))
+ oldSize <- Lua.gettop
+ Lua.push x
+ size <- Lua.gettop
+ when (size - oldSize /= 1) $
error ("not exactly one additional element on the stack: " ++ show size)
- res <- peekEither (-1)
+ res <- Lua.peekEither (-1)
case res of
Left _ -> error "could not read from stack"
Right y -> return y