@@ -13,6 +13,7 @@ import Text.Pandoc.Builder (bulletList, divWith, doc, doubleQuoted, emph,
1313import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
1414import Text.Pandoc.Definition (Block, Inline, Meta, Pandoc)
1515import Text.Pandoc.Lua (runLuaFilter, runPandocLua)
16+import Text.Pandoc.Shared (pandocVersion)
1617
1718import qualified Foreign.Lua as Lua
1819
@@ -106,6 +107,14 @@ tests = map (localOption (QuickCheckTests 20))
106107 , plain (str "stringify: OK")
107108 , plain (str "to_roman_numeral: OK")
108109 ])
110+
111+ , testCase "Pandoc version is set" . runPandocLua' $ do
112+ Lua.getglobal' "table.concat"
113+ Lua.getglobal "PANDOC_VERSION"
114+ Lua.push ("." :: String) -- seperator
115+ Lua.call 2 1
116+ Lua.liftIO . assertEqual "pandoc version is wrong" pandocVersion
117+ =<< Lua.peek Lua.stackTop
109118 ]
110119
111120assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
@@ -121,18 +130,21 @@ roundtripEqual :: (Eq a, Lua.FromLuaStack a, Lua.ToLuaStack a) => a -> IO Bool
121130roundtripEqual x = (x ==) <$> roundtripped
122131 where
123132 roundtripped :: (Lua.FromLuaStack a, Lua.ToLuaStack a) => IO a
124− roundtripped = runIOorExplode $ do
125− setUserDataDir (Just "../data")
126− res <- runPandocLua $ do
127− oldSize <- Lua.gettop
128− Lua.push x
129− size <- Lua.gettop
130− when (size - oldSize /= 1) $
131− error ("not exactly one additional element on the stack: " ++ show size)
132− res <- Lua.peekEither (-1)
133− case res of
134− Left _ -> error "could not read from stack"
135− Right y -> return y
133+ roundtripped = runPandocLua' $ do
134+ oldSize <- Lua.gettop
135+ Lua.push x
136+ size <- Lua.gettop
137+ when (size - oldSize /= 1) $
138+ error ("not exactly one additional element on the stack: " ++ show size)
139+ res <- Lua.peekEither (-1)
136140 case res of
137− Left e -> error (show e)
141+ Left _ -> error "could not read from stack"
138142 Right y -> return y
143+
144+runPandocLua' :: Lua.Lua a -> IO a
145+runPandocLua' op = runIOorExplode $ do
146+ setUserDataDir (Just "../data")
147+ res <- runPandocLua op
148+ case res of
149+ Left e -> error (show e)
150+ Right x -> return x