1utils = require 'pandoc.utils'
4------------------------------------------------------------------------
5function test_hierarchicalize ()
7 pandoc.Header(1, {pandoc.Str 'First'}),
8 pandoc.Header(2, {pandoc.Str 'Second'}),
9 pandoc.Header(2, {pandoc.Str 'Third'}),
11 local hblks = utils.hierarchicalize(blks)
12 return hblks[1].t == "Sec"
13 and hblks[1].contents[1].t == "Sec"
14 and hblks[1].contents[2].numbering[1] == 1
15 and hblks[1].contents[2].numbering[2] == 2
19------------------------------------------------------------------------
21 local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
22 local hash = utils.sha1 'Hello, World!'
23 return hash == ref_hash
27------------------------------------------------------------------------
28function file_exists (filename)
29 local fh = io.open(filename, 'r')
30 return fh ~= nil and (fh:close() or true)
33function warn (...) io.stderr:write(...) end
36 if not file_exists('/bin/sed') then
37 warn 'Did not find /bin/sed, skipping test'
40 local pipe_result = pandoc.pipe('/bin/sed', {'-e', 's/a/b/'}, 'abc')
41 return pipe_result == 'bbc'
44function test_failing_pipe ()
45 if not file_exists('/bin/false') then
46 warn 'Did not find /bin/false, skipping test'
49 local res, err = pcall(pandoc.pipe, '/bin/false', {}, 'abc')
51 err.command == '/bin/false' and
52 err.error_code == 1 and
57------------------------------------------------------------------------
59 local valid_markdown = '*Hello*, World!\n'
60 local res = pandoc.read(valid_markdown).blocks[1].content
61 return res[1].t == 'Emph' and res[3].t == 'Space' and res[4].t == 'Str'
64function test_failing_read ()
65 local res, err = pcall(pandoc.read, 'foo', 'nosuchreader')
66 return not res and err:match 'Unknown reader: nosuchreader'
70------------------------------------------------------------------------
71function test_stringify ()
72 local inline = pandoc.Emph{
79 return utils.stringify(inline) == 'Cogito ergo sum.'
83------------------------------------------------------------------------
84function test_to_roman_numeral ()
85 return utils.to_roman_numeral(1888) == 'MDCCCLXXXVIII'
86 -- calling with a string fails
87 and not pcall(utils.to_roman_numeral, 'not a number')
91------------------------------------------------------------------------
92function test_normalize_date ()
93 return utils.normalize_date("12/31/2017") == '2017-12-31'
94 and utils.normalize_date("pandoc") == nil
98------------------------------------------------------------------------
100 return fn() and "OK" or "FAIL"
105 pandoc.Plain{pandoc.Str("hierarchicalize: " .. run(test_hierarchicalize))},
106 pandoc.Plain{pandoc.Str("normalize_date: " .. run(test_normalize_date))},
107 pandoc.Plain{pandoc.Str("pipe: " .. run(test_pipe))},
108 pandoc.Plain{pandoc.Str("failing pipe: " .. run(test_failing_pipe))},
109 pandoc.Plain{pandoc.Str("read: " .. run(test_read))},
110 pandoc.Plain{pandoc.Str("failing read: " .. run(test_failing_read))},
111 pandoc.Plain{pandoc.Str("sha1: " .. run(test_sha1))},
112 pandoc.Plain{pandoc.Str("stringify: " .. run(test_stringify))},
113 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