aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2021-12-21 09:40:23 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2021-12-21 09:24:21 -0800
commitd7cab5198269fbbdbc40f54a2ad7aeb83fee619f (patch)
tree2888f841a1c5ac6fe2dec545eff8f1c3e1cf49c4 /test
parentc90802d7d85ba2ae98492701b30cc37bde757b83 (diff)
downloadpandoc-d7cab5198269fbbdbc40f54a2ad7aeb83fee619f.tar.gz
Lua: add new library function `pandoc.utils.type`.
The function behaves like the default `type` function from Lua's standard library, but is aware of pandoc userdata types. A typical use-case would be to determine the type of a metadata value.
Diffstat (limited to 'test')
-rw-r--r--test/lua/module/pandoc-utils.lua40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/lua/module/pandoc-utils.lua b/test/lua/module/pandoc-utils.lua
index 7a43e9286..104adfe4c 100644
--- a/test/lua/module/pandoc-utils.lua
+++ b/test/lua/module/pandoc-utils.lua
@@ -116,6 +116,46 @@ return {
end)
},
+ group 'type' {
+ test('nil', function ()
+ assert.are_equal(utils.type(nil), 'nil')
+ end),
+ test('boolean', function ()
+ assert.are_equal(utils.type(true), 'boolean')
+ assert.are_equal(utils.type(false), 'boolean')
+ end),
+ test('number', function ()
+ assert.are_equal(utils.type(5), 'number')
+ assert.are_equal(utils.type(-3.02), 'number')
+ end),
+ test('string', function ()
+ assert.are_equal(utils.type(''), 'string')
+ assert.are_equal(utils.type('asdf'), 'string')
+ end),
+ test('plain table', function ()
+ assert.are_equal(utils.type({}), 'table')
+ end),
+ test('List', function ()
+ assert.are_equal(utils.type(pandoc.List{}), 'List')
+ end),
+ test('Inline', function ()
+ assert.are_equal(utils.type(pandoc.Str 'a'), 'Inline')
+ assert.are_equal(utils.type(pandoc.Emph 'emphasized'), 'Inline')
+ end),
+ test('Inlines', function ()
+ assert.are_equal(utils.type(pandoc.Inlines{pandoc.Str 'a'}), 'Inlines')
+ assert.are_equal(utils.type(pandoc.Inlines{pandoc.Emph 'b'}), 'Inlines')
+ end),
+ test('Blocks', function ()
+ assert.are_equal(utils.type(pandoc.Para 'a'), 'Block')
+ assert.are_equal(utils.type(pandoc.CodeBlock 'true'), 'Block')
+ end),
+ test('Inlines', function ()
+ assert.are_equal(utils.type(pandoc.Blocks{'a'}), 'Blocks')
+ assert.are_equal(utils.type(pandoc.Blocks{pandoc.CodeBlock 'b'}), 'Blocks')
+ end),
+ },
+
group 'to_simple_table' {
test('convertes Table', function ()
function simple_cell (blocks)