1{-# Language OverloadedStrings #-}
2module Tests.Lua ( tests ) where
4import Control.Monad (when)
5import System.FilePath ((</>))
6import Test.Tasty (TestTree)
7import Test.Tasty.HUnit (Assertion, assertEqual, testCase)
8import Test.Tasty.QuickCheck (ioProperty, testProperty)
9import Text.Pandoc.Arbitrary ()
10import Text.Pandoc.Definition (Block, Inline, Meta, Pandoc)
11import Text.Pandoc.Builder ( (<>), bulletList, doc, emph, linebreak, rawBlock
12 , para, plain, space, str, strong)
15import qualified Scripting.Lua as Lua
19 [ testCase "macro expansion via filter" $
20 assertFilterConversion "a '{{helloworld}}' string is expanded"
22 (doc . para $ str "{{helloworld}}")
23 (doc . para . emph $ str "Hello, World")
25 , testCase "convert all plains to paras" $
26 assertFilterConversion "plains become para"
28 (doc $ bulletList [plain (str "alfa"), plain (str "bravo")])
29 (doc $ bulletList [para (str "alfa"), para (str "bravo")])
31 , testCase "make hello world document" $
32 assertFilterConversion "Document contains 'Hello, World!'"
34 (doc . para $ str "Hey!" <> linebreak <> str "What's up?")
35 (doc . para $ str "Hello," <> space <> str "World!")
37 , testCase "parse raw markdown blocks" $
38 assertFilterConversion "raw markdown block is converted"
40 (doc $ rawBlock "markdown" "*charly* **delta**")
41 (doc . para $ emph "charly" <> space <> strong "delta")
43 , testProperty "inline elements can be round-tripped through the lua stack" $
44 \x -> ioProperty (roundtripEqual (x::Inline))
46 , testProperty "block elements can be round-tripped through the lua stack" $
47 \x -> ioProperty (roundtripEqual (x::Block))
49 , testProperty "meta blocks can be round-tripped through the lua stack" $
50 \x -> ioProperty (roundtripEqual (x::Meta))
52 , testProperty "documents can be round-tripped through the lua stack" $
53 \x -> ioProperty (roundtripEqual (x::Pandoc))
56assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
57assertFilterConversion msg filterPath docIn docExpected = do
58 docRes <- runLuaFilter ("lua" </> filterPath) [] docIn
59 assertEqual msg docExpected docRes
61roundtripEqual :: (Eq a, Lua.StackValue a) => a -> IO Bool
62roundtripEqual x = (x ==) <$> roundtripped
64 roundtripped :: (Lua.StackValue a) => IO a
68 size <- Lua.gettop lua
70 error ("not exactly one element on the stack: " ++ show size)
71 res <- Lua.peek lua (-1)
73 Nothing -> error "could not read from stack"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list