diff options
Diffstat (limited to 'test/lua/module/pandoc-utils.lua')
-rw-r--r-- | test/lua/module/pandoc-utils.lua | 184 |
1 files changed, 179 insertions, 5 deletions
diff --git a/test/lua/module/pandoc-utils.lua b/test/lua/module/pandoc-utils.lua index 9bd903f2d..4cf2c84a7 100644 --- a/test/lua/module/pandoc-utils.lua +++ b/test/lua/module/pandoc-utils.lua @@ -39,6 +39,46 @@ return { end) }, + group 'equals' { + test('compares Pandoc elements', function () + assert.is_truthy( + utils.equals(pandoc.Pandoc{'foo'}, pandoc.Pandoc{'foo'}) + ) + end), + test('compares Block elements', function () + assert.is_truthy( + utils.equals(pandoc.Plain{'foo'}, pandoc.Plain{'foo'}) + ) + assert.is_falsy( + utils.equals(pandoc.Para{'foo'}, pandoc.Plain{'foo'}) + ) + end), + test('compares Inline elements', function () + assert.is_truthy( + utils.equals(pandoc.Emph{'foo'}, pandoc.Emph{'foo'}) + ) + assert.is_falsy( + utils.equals(pandoc.Emph{'foo'}, pandoc.Strong{'foo'}) + ) + end), + test('compares Inline with Block elements', function () + assert.is_falsy( + utils.equals(pandoc.Emph{'foo'}, pandoc.Plain{'foo'}) + ) + assert.is_falsy( + utils.equals(pandoc.Para{'foo'}, pandoc.Strong{'foo'}) + ) + end), + test('compares Pandoc with Block elements', function () + assert.is_falsy( + utils.equals(pandoc.Pandoc{'foo'}, pandoc.Plain{'foo'}) + ) + assert.is_falsy( + utils.equals(pandoc.Para{'foo'}, pandoc.Pandoc{'foo'}) + ) + end), + }, + group 'make_sections' { test('sanity check', function () local blks = { @@ -62,6 +102,31 @@ return { end), }, + group 'references' { + test('gets references from doc', function () + local ref = { + ['author'] = { + {given = 'Max', family = 'Mustermann'} + }, + ['container-title'] = pandoc.Inlines('JOSS'), + ['id'] = 'test', + ['issued'] = {['date-parts'] = {{2021}}}, + ['title'] = pandoc.Inlines{ + pandoc.Quoted('DoubleQuote', 'Interesting'), + pandoc.Space(), + 'work' + }, + ['type'] = 'article-journal', + } + local nocite = pandoc.Cite( + '@test', + {pandoc.Citation('test', 'NormalCitation')} + ) + local doc = pandoc.Pandoc({}, {nocite = nocite, references = {ref}}) + assert.are_same({ref}, pandoc.utils.references(doc)) + end) + }, + group 'sha1' { test('hashing', function () local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01' @@ -70,7 +135,7 @@ return { }, group 'stringify' { - test('inlines', function () + test('Inline', function () local inline = pandoc.Emph{ pandoc.Str 'Cogito', pandoc.Space(), @@ -79,7 +144,49 @@ return { pandoc.Str 'sum.', } assert.are_equal('Cogito ergo sum.', utils.stringify(inline)) - end) + end), + test('Block', function () + local block = pandoc.Para{ + pandoc.Str 'Make', + pandoc.Space(), + pandoc.Str 'it', + pandoc.Space(), + pandoc.Str 'so.', + } + assert.are_equal('Make it so.', utils.stringify(block)) + end), + test('boolean', function () + assert.are_equal('true', utils.stringify(true)) + assert.are_equal('false', utils.stringify(false)) + end), + test('number', function () + assert.are_equal('5', utils.stringify(5)) + assert.are_equal('23.23', utils.stringify(23.23)) + end), + test('Attr', function () + local attr = pandoc.Attr('foo', {'bar'}, {a = 'b'}) + assert.are_equal('', utils.stringify(attr)) + end), + test('List', function () + local list = pandoc.List{pandoc.Str 'a', pandoc.Blocks('b')} + assert.are_equal('ab', utils.stringify(list)) + end), + test('Blocks', function () + local blocks = pandoc.Blocks{pandoc.Para 'a', pandoc.Header(1, 'b')} + assert.are_equal('ab', utils.stringify(blocks)) + end), + test('Inlines', function () + local inlines = pandoc.Inlines{pandoc.Str 'a', pandoc.Subscript('b')} + assert.are_equal('ab', utils.stringify(inlines)) + end), + test('Meta', function () + local meta = pandoc.Meta{ + a = pandoc.Inlines 'funny and ', + b = 'good movie', + c = pandoc.List{pandoc.Inlines{pandoc.Str '!'}} + } + assert.are_equal('funny and good movie!', utils.stringify(meta)) + end), }, group 'to_roman_numeral' { @@ -91,6 +198,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) @@ -106,14 +253,14 @@ return { {long = {pandoc.Plain { pandoc.Str "the", pandoc.Space(), pandoc.Str "caption"}}}, {{pandoc.AlignDefault, nil}}, - {pandoc.Attr(), {{pandoc.Attr(), {simple_cell{pandoc.Plain "head1"}}}}}, + pandoc.TableHead{pandoc.Row{simple_cell{pandoc.Plain "head1"}}}, {{ attr = pandoc.Attr(), - body = {{pandoc.Attr(), {simple_cell{pandoc.Plain "cell1"}}}}, + body = {pandoc.Row{simple_cell{pandoc.Plain "cell1"}}}, head = {}, row_head_columns = 0 }}, - {pandoc.Attr(), {}}, + pandoc.TableFoot(), pandoc.Attr() ) local stbl = utils.to_simple_table(tbl) @@ -155,5 +302,32 @@ return { -- reversible assert.are_same(simple_table, utils.to_simple_table(tbl)) end), + test('empty caption', function () + local simple_table = pandoc.SimpleTable( + {}, + {pandoc.AlignDefault}, + {0}, + {{pandoc.Plain 'a'}}, + {{{pandoc.Plain 'b'}}} + ) + local tbl = utils.from_simple_table(simple_table) + assert.are_equal( + pandoc.Blocks{}, + tbl.caption.long + ) + assert.is_nil(tbl.caption.short) + end), + test('empty body', function () + local simple_table = pandoc.SimpleTable( + pandoc.Inlines('a nice caption'), + {pandoc.AlignDefault}, + {0}, + {{pandoc.Plain 'a'}}, + {} + ) + local tbl = utils.from_simple_table(simple_table) + tbl.bodies:map(print) + assert.are_same(pandoc.List(), tbl.bodies) + end), } } |