1utils = require 'pandoc.utils'
3-- Squash blocks to inlines
4------------------------------------------------------------------------
5function test_blocks_to_inlines ()
7 pandoc.Para{ pandoc.Str 'Paragraph1' },
8 pandoc.Para{ pandoc.Emph 'Paragraph2' }
10 local inlines = utils.blocks_to_inlines(blocks, {pandoc.LineBreak()})
12 and inlines[1].text == "Paragraph1"
13 and inlines[2].t == 'LineBreak'
14 and inlines[3].content[1].text == "Paragraph2"
18------------------------------------------------------------------------
19function test_hierarchicalize ()
21 pandoc.Header(1, {pandoc.Str 'First'}),
22 pandoc.Header(2, {pandoc.Str 'Second'}),
23 pandoc.Header(2, {pandoc.Str 'Third'}),
25 local hblks = utils.hierarchicalize(blks)
26 return hblks[1].t == "Sec"
27 and hblks[1].contents[1].t == "Sec"
28 and hblks[1].contents[2].numbering[1] == 1
29 and hblks[1].contents[2].numbering[2] == 2
33------------------------------------------------------------------------
35 local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
36 local hash = utils.sha1 'Hello, World!'
37 return hash == ref_hash
41------------------------------------------------------------------------
42function file_exists (filename)
43 local fh = io.open(filename, 'r')
44 return fh ~= nil and (fh:close() or true)
47function warn (...) io.stderr:write(...) end
49function os_is_windows ()
50 return package.config:sub(1,1) == '\\'
54 if os_is_windows() then
55 local pipe_result = pandoc.pipe('find', {'hi'}, 'hi')
56 return pipe_result:match("%a+") == 'hi'
58 local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc')
59 return pipe_result:match("%a+") == 'bbc'
63function test_failing_pipe ()
64 if os_is_windows() then
65 local res, err = pcall(pandoc.pipe, 'find', {'/a'}, 'hi')
67 err.command == 'find' and
70 local res, err = pcall(pandoc.pipe, 'false', {}, 'abc')
72 err.command == 'false' and
73 err.error_code == 1 and
79------------------------------------------------------------------------
81 local valid_markdown = '*Hello*, World!\n'
82 local res = pandoc.read(valid_markdown).blocks[1].content
83 return res[1].t == 'Emph' and res[3].t == 'Space' and res[4].t == 'Str'
86function test_failing_read ()
87 local res, err = pcall(pandoc.read, 'foo', 'nosuchreader')
88 return not res and err:match 'Unknown reader: nosuchreader'
92------------------------------------------------------------------------
93function test_stringify ()
94 local inline = pandoc.Emph{
101 return utils.stringify(inline) == 'Cogito ergo sum.'
105------------------------------------------------------------------------
106function test_to_roman_numeral ()
107 return utils.to_roman_numeral(1888) == 'MDCCCLXXXVIII'
108 -- calling with a string fails
109 and not pcall(utils.to_roman_numeral, 'not a number')
113------------------------------------------------------------------------
114function test_normalize_date ()
115 return utils.normalize_date("12/31/2017") == '2017-12-31'
116 and utils.normalize_date("pandoc") == nil
120------------------------------------------------------------------------
122 return fn() and "OK" or "FAIL"
127 pandoc.Plain{pandoc.Str("blocks_to_inlines: " .. run(test_blocks_to_inlines))},
128 pandoc.Plain{pandoc.Str("hierarchicalize: " .. run(test_hierarchicalize))},
129 pandoc.Plain{pandoc.Str("normalize_date: " .. run(test_normalize_date))},
130 pandoc.Plain{pandoc.Str("pipe: " .. run(test_pipe))},
131 pandoc.Plain{pandoc.Str("failing pipe: " .. run(test_failing_pipe))},
132 pandoc.Plain{pandoc.Str("read: " .. run(test_read))},
133 pandoc.Plain{pandoc.Str("failing read: " .. run(test_failing_read))},
134 pandoc.Plain{pandoc.Str("sha1: " .. run(test_sha1))},
135 pandoc.Plain{pandoc.Str("stringify: " .. run(test_stringify))},
136 pandoc.Plain{pandoc.Str("to_roman_numeral: " .. run(test_to_roman_numeral))},
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list