git.iko.soy/typeable/pandoc
on fa6ffca help sign in
typeable/pandoc/test/lua/module/pandoc-utils.lua
93 lines 2.6 kB history raw
1local tasty = require 'tasty'
2local utils = require 'pandoc.utils'
4local assert = tasty.assert
5local test = tasty.test_case
6local group = tasty.test_group
8return {
9 group 'blocks_to_inlines' {
10 test('default separator', function ()
11 local blocks = {
12 pandoc.Para { pandoc.Str 'Paragraph1' },
13 pandoc.Para { pandoc.Emph { pandoc.Str 'Paragraph2' } }
14 }
15 local expected = {
16 pandoc.Str 'Paragraph1',
17 pandoc.Space(), pandoc.Str '¶', pandoc.Space(),
18 pandoc.Emph { pandoc.Str 'Paragraph2' }
19 }
20 assert.are_same(
21 expected,
22 utils.blocks_to_inlines(blocks)
23 )
24 end),
25 test('custom separator', function ()
26 local blocks = {
27 pandoc.Para{ pandoc.Str 'Paragraph1' },
28 pandoc.Para{ pandoc.Emph 'Paragraph2' }
29 }
30 local expected = {
31 pandoc.Str 'Paragraph1',
32 pandoc.LineBreak(),
33 pandoc.Emph { pandoc.Str 'Paragraph2' }
34 }
35 assert.are_same(
36 expected,
37 utils.blocks_to_inlines(blocks, { pandoc.LineBreak() })
38 )
39 end)
40 },
42 group 'make_sections' {
43 test('sanity check', function ()
44 local blks = {
45 pandoc.Header(1, {pandoc.Str 'First'}),
46 pandoc.Header(2, {pandoc.Str 'Second'}),
47 pandoc.Header(2, {pandoc.Str 'Third'}),
48 }
49 local hblks = utils.make_sections(true, 1, blks)
50 assert.are_equal('Div', hblks[1].t)
51 assert.are_equal('Header', hblks[1].content[1].t)
52 assert.are_equal('1', hblks[1].content[1].attributes['number'])
53 end)
54 },
56 group 'normalize_date' {
57 test('09 Nov 1989', function ()
58 assert.are_equal('1989-11-09', utils.normalize_date '09 Nov 1989')
59 end),
60 test('12/31/2017', function ()
61 assert.are_equal('2017-12-31', utils.normalize_date '12/31/2017')
62 end),
63 },
65 group 'sha1' {
66 test('hashing', function ()
67 local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
68 assert.are_equal(ref_hash, utils.sha1 'Hello, World!')
69 end)
70 },
72 group 'stringify' {
73 test('inlines', function ()
74 local inline = pandoc.Emph{
75 pandoc.Str 'Cogito',
76 pandoc.Space(),
77 pandoc.Str 'ergo',
78 pandoc.Space(),
79 pandoc.Str 'sum.',
80 }
81 assert.are_equal('Cogito ergo sum.', utils.stringify(inline))
82 end)
83 },
85 group 'to_roman_numeral' {
86 test('convertes number', function ()
87 assert.are_equal('MDCCCLXXXVIII', utils.to_roman_numeral(1888))
88 end),
89 test('fails on non-convertible argument', function ()
90 assert.is_falsy(pcall(utils.to_roman_numeral, 'not a number'))
91 end)
92 },