diff options
| author | Albert Krewinkel <albert@zeitkraut.de> | 2019-05-20 18:52:28 +0200 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2019-05-20 12:52:28 -0400 |
| commit | 6208d4e7fcf1792203b3069d0002ad5cb1ec05dd (patch) | |
| tree | 4aa85637c54ffaf67b950c1ed3c9ff7ce9a940de /test/lua/module/pandoc.lua | |
| parent | 90141e7b4fc48477106ee5481e3d9b1b4a54338e (diff) | |
Improve output of Lua tests (#5499)
This makes use of tasty-lua, a package to write tests in Lua
and integrate the results into Tasty output. Test output becomes
more informative: individual tests and test groups become visible
in test output. Failures are reported with helpful error messages.
Diffstat (limited to 'test/lua/module/pandoc.lua')
| -rw-r--r-- | test/lua/module/pandoc.lua | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/lua/module/pandoc.lua b/test/lua/module/pandoc.lua new file mode 100644 index 000000000..b9509cdb6 --- /dev/null +++ b/test/lua/module/pandoc.lua @@ -0,0 +1,58 @@ +local tasty = require 'tasty' + +local test = tasty.test_case +local group = tasty.test_group +local assert = tasty.assert + +function os_is_windows () + return package.config:sub(1,1) == '\\' +end + +return { + group 'pipe' { + test('external string processing', function () + if os_is_windows() then + local pipe_result = pandoc.pipe('find', {'hi'}, 'hi') + assert.are_equal('hi', pipe_result:match '%a+') + else + local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc') + assert.are_equal('bbc', pipe_result:match '%a+') + end + end), + test('failing pipe', function () + if os_is_windows() then + local success, err = pcall(pandoc.pipe, 'find', {'/a'}, 'hi') + assert.is_falsy(success) + assert.are_equal('find', err.command) + assert.is_truthy(err.error_code ~= 0) + else + local success, err = pcall(pandoc.pipe, 'false', {}, 'abc') + assert.is_falsy(success) + assert.are_equal('false', err.command) + assert.are_equal(1, err.error_code) + assert.are_equal('', err.output) + end + end) + }, + + group 'read' { + test('Markdown', function () + local valid_markdown = '*Hello*, World!\n' + local expected = pandoc.Pandoc({ + pandoc.Para { + pandoc.Emph { pandoc.Str 'Hello' }, + pandoc.Str ',', + pandoc.Space(), + pandoc.Str 'World!' + } + }) + assert.are_same(expected, pandoc.read(valid_markdown)) + end), + test('failing read', function () + assert.error_matches( + function () pandoc.read('foo', 'nosuchreader') end, + 'Unknown reader: nosuchreader' + ) + end) + }, +} |
