From b5bd8a9461dc317ff61abec68feba4a86d39e9f2 Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Sat, 24 Feb 2018 21:59:50 +0100 Subject: Lua: register script name in global variable The name of the Lua script which is executed is made available in the global Lua variable `PANDOC_SCRIPT_FILE`, both for Lua filters and custom writers. Closes: #4393 --- test/lua/script-name.lua | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 test/lua/script-name.lua (limited to 'test/lua') diff --git a/test/lua/script-name.lua b/test/lua/script-name.lua new file mode 100644 index 000000000..4b5a223f0 --- /dev/null +++ b/test/lua/script-name.lua @@ -0,0 +1,3 @@ +function Para (_) + return pandoc.Para{pandoc.Str(PANDOC_SCRIPT_FILE)} +end -- cgit v1.2.3 From 4139e3e92b9ee88bd3e689e06113c96726988dae Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Sun, 29 Apr 2018 16:20:38 +0300 Subject: Test Lua filter converting display math to inline math --- test/Tests/Lua.hs | 9 ++++++++- test/lua/math.lua | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/lua/math.lua (limited to 'test/lua') diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs index b401e4e65..28a691715 100644 --- a/test/Tests/Lua.hs +++ b/test/Tests/Lua.hs @@ -12,7 +12,8 @@ import Test.Tasty.QuickCheck (QuickCheckTests (..), ioProperty, testProperty) import Text.Pandoc.Arbitrary () import Text.Pandoc.Builder (bulletList, divWith, doc, doubleQuoted, emph, header, linebreak, para, plain, rawBlock, - singleQuoted, space, str, strong) + singleQuoted, space, str, strong, + math, displayMath) import Text.Pandoc.Class (runIOorExplode, setUserDataDir) import Text.Pandoc.Definition (Block (BlockQuote, Div, Para), Inline (Emph, Str), Attr, Meta, Pandoc, pandocTypesVersion) @@ -48,6 +49,12 @@ tests = map (localOption (QuickCheckTests 20)) (doc $ bulletList [plain (str "alfa"), plain (str "bravo")]) (doc $ bulletList [para (str "alfa"), para (str "bravo")]) + , testCase "convert display math to inline math" $ + assertFilterConversion "display math becomes inline math" + "math.lua" + (doc $ para (displayMath "5+5")) + (doc $ para (math "5+5")) + , testCase "make hello world document" $ assertFilterConversion "Document contains 'Hello, World!'" "hello-world-doc.lua" diff --git a/test/lua/math.lua b/test/lua/math.lua new file mode 100644 index 000000000..34307dd9e --- /dev/null +++ b/test/lua/math.lua @@ -0,0 +1,10 @@ +return { + { + Math = function (elem) + if elem.mathtype == "DisplayMath" then + elem.mathtype = "InlineMath" + end + return elem + end, + } +} -- cgit v1.2.3 From e6d85927ea69325e79fa4fd5cee0882e9ad3303f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 11:07:57 -0700 Subject: test-pandoc-utils.lua: remove problems with missing `/bin/false`. Previously it was assumed that the system would have `/bin/false` and `/bin/sed`, and these tests were skipped otherwise. On MacOS, these utilities are located in `/usr/bin`. Fixed by just using `sed` and `false` -- these should always be in the path. Removed the "skipping" behavior, replaced with a check for Windows. On Windowns, we use `echo` and `cd`, which should always exist. Not yet checked on Windows. --- test/lua/test-pandoc-utils.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index c732d2f85..000be1f7a 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -32,25 +32,34 @@ end function warn (...) io.stderr:write(...) end +function os_is_windows () + return package.config:sub(1,1) == '\\' +end + function test_pipe () - if not file_exists('/bin/sed') then - warn 'Did not find /bin/sed, skipping test' - return true + if os_is_windows() then + local pipe_result = pandoc.pipe('echo', {}, 'hi') + return pipe_result == 'hi\n' + else + local pipe_result = pandoc.pipe('sed', {'-e', 's/a/b/'}, 'abc') + return pipe_result == 'bbc\n' end - local pipe_result = pandoc.pipe('/bin/sed', {'-e', 's/a/b/'}, 'abc') - return pipe_result == 'bbc' end function test_failing_pipe () - if not file_exists('/bin/false') then - warn 'Did not find /bin/false, skipping test' - return true + if os_is_windows() then + local res, err = pcall(pandoc.pipe, 'cd', {}, 'NoNExistEnt') + return not res and + err.command == 'cd' and + err.error_code == 1 and + err.output == '' + else + local res, err = pcall(pandoc.pipe, 'false', {}, 'abc') + return not res and + err.command == 'false' and + err.error_code == 1 and + err.output == '' end - local res, err = pcall(pandoc.pipe, '/bin/false', {}, 'abc') - return not res and - err.command == '/bin/false' and - err.error_code == 1 and - err.output == '' end -- Read -- cgit v1.2.3 From 83fb9d549542b12c14e48cda3a8ce4809466386c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 11:22:10 -0700 Subject: test-pandoc-utils.lua: workaround some local differences in 'echo'. --- test/lua/test-pandoc-utils.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index 000be1f7a..4d02f6980 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -39,10 +39,10 @@ end function test_pipe () if os_is_windows() then local pipe_result = pandoc.pipe('echo', {}, 'hi') - return pipe_result == 'hi\n' + return pipe_result == 'hi\n' or pipe_result == 'hi' else local pipe_result = pandoc.pipe('sed', {'-e', 's/a/b/'}, 'abc') - return pipe_result == 'bbc\n' + return pipe_result == 'bbc\n' or pipe_result == 'bbc' end end -- cgit v1.2.3 From fa4f3c5c17ac0a832aea8933e5e723b9f40239c6 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 11:51:50 -0700 Subject: test-pandoc-utils.lua - use tr instead of sed. It should be installed on all *nix systems. --- test/lua/test-pandoc-utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index 4d02f6980..f0040062e 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -41,7 +41,7 @@ function test_pipe () local pipe_result = pandoc.pipe('echo', {}, 'hi') return pipe_result == 'hi\n' or pipe_result == 'hi' else - local pipe_result = pandoc.pipe('sed', {'-e', 's/a/b/'}, 'abc') + local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc') return pipe_result == 'bbc\n' or pipe_result == 'bbc' end end -- cgit v1.2.3 From 9f2af30c066d4d821237532b1dea3c8f3e7fac7b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 12:28:12 -0700 Subject: More adjustments to test-pandoc-utils.lua. We need to find something that will work on windows. --- test/lua/test-pandoc-utils.lua | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index f0040062e..4d736d2d5 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -38,7 +38,7 @@ end function test_pipe () if os_is_windows() then - local pipe_result = pandoc.pipe('echo', {}, 'hi') + local pipe_result = pandoc.pipe('find', {'hi'}, 'hi') return pipe_result == 'hi\n' or pipe_result == 'hi' else local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc') @@ -48,11 +48,10 @@ end function test_failing_pipe () if os_is_windows() then - local res, err = pcall(pandoc.pipe, 'cd', {}, 'NoNExistEnt') + local res, err = pcall(pandoc.pipe, 'find', {'/a'}, 'hi') return not res and - err.command == 'cd' and - err.error_code == 1 and - err.output == '' + err.command == 'find' and + err.error_code ~= 0 else local res, err = pcall(pandoc.pipe, 'false', {}, 'abc') return not res and -- cgit v1.2.3 From 691f38f3d6e1ee4cd1f5d5c8c60c628543f11f55 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 22:08:23 -0700 Subject: test-pandoc-utils.lua - add diagnostic for windows test. --- test/lua/test-pandoc-utils.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index 4d736d2d5..89d273cef 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -39,6 +39,7 @@ end function test_pipe () if os_is_windows() then local pipe_result = pandoc.pipe('find', {'hi'}, 'hi') + print(pipe_result) return pipe_result == 'hi\n' or pipe_result == 'hi' else local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc') -- cgit v1.2.3 From 5f33d2e0cd9f19566904c93be04f586de811dd75 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 22:32:44 -0700 Subject: Another try at test-pandoc-utils.lua on windows. --- test/lua/test-pandoc-utils.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/lua') diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index 89d273cef..21f937edb 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -39,11 +39,10 @@ end function test_pipe () if os_is_windows() then local pipe_result = pandoc.pipe('find', {'hi'}, 'hi') - print(pipe_result) - return pipe_result == 'hi\n' or pipe_result == 'hi' + return pipe_result:match("%a+") == 'hi' else local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc') - return pipe_result == 'bbc\n' or pipe_result == 'bbc' + return pipe_result:match("%a+") == 'bbc' end end -- cgit v1.2.3