aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2017-08-13 12:37:10 +0200
committerAlbert Krewinkel <albert@zeitkraut.de>2017-08-13 14:23:54 +0200
commit2dc3dbd68b557cbd8974b9daf84df3d26ab5f843 (patch)
treeacd1e83277f97cddd2e2717da6cb8243c3e4f57e /test
parent418bda81282c82325c5a296a3c486fdc5ab1dfe0 (diff)
downloadpandoc-2dc3dbd68b557cbd8974b9daf84df3d26ab5f843.tar.gz
Use hslua >= 0.7, update Lua code
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Lua.hs31
1 files changed, 14 insertions, 17 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index ebd39366b..8cbda996a 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -13,7 +13,7 @@ import Text.Pandoc.Builder ( (<>), bulletList, doc, doubleQuoted, emph
, space, str, strong)
import Text.Pandoc.Lua
-import qualified Scripting.Lua as Lua
+import Foreign.Lua
tests :: [TestTree]
tests = map (localOption (QuickCheckTests 20))
@@ -71,23 +71,20 @@ assertFilterConversion msg filterPath docIn docExpected = do
docRes <- runLuaFilter Nothing ("lua" </> filterPath) [] docIn
assertEqual msg docExpected docRes
-roundtripEqual :: (Eq a, Lua.StackValue a) => a -> IO Bool
+roundtripEqual :: (Eq a, FromLuaStack a, ToLuaStack a) => a -> IO Bool
roundtripEqual x = (x ==) <$> roundtripped
where
- roundtripped :: (Lua.StackValue a) => IO a
- roundtripped = do
- lua <- Lua.newstate
- Lua.openlibs lua
- pushPandocModule Nothing lua
- Lua.setglobal lua "pandoc"
- oldSize <- Lua.gettop lua
- Lua.push lua x
- size <- Lua.gettop lua
+ roundtripped :: (FromLuaStack a, ToLuaStack a) => IO a
+ roundtripped = runLua $ do
+ openlibs
+ pushPandocModule Nothing
+ setglobal "pandoc"
+ oldSize <- gettop
+ push x
+ size <- gettop
when ((size - oldSize) /= 1) $
error ("not exactly one additional element on the stack: " ++ show size)
- res <- Lua.peek lua (-1)
- retval <- case res of
- Nothing -> error "could not read from stack"
- Just y -> return y
- Lua.close lua
- return retval
+ res <- peekEither (-1)
+ case res of
+ Left _ -> error "could not read from stack"
+ Right y -> return y