From d7cab5198269fbbdbc40f54a2ad7aeb83fee619f Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 21 Dec 2021 09:40:23 +0100 Subject: 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. --- test/lua/module/pandoc-utils.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'test') 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) -- cgit v1.2.3