@@ -0,0 +1,69 @@
1+utils = require 'pandoc'
2+
3+-- SHA1
4+------------------------------------------------------------------------
5+function test_sha1 ()
6+ local ref_hash = '0a0a9f2a6772942557ab5355d76af442f8f65e01'
7+ local hash = utils.sha1 'Hello, World!'
8+ return hash == ref_hash
9+end
10+
11+-- Pipe
12+------------------------------------------------------------------------
13+function file_exists (filename)
14+ local fh = io.open(filename, 'r')
15+ return fh ~= nil and (fh:close() or true)
16+end
17+
18+function warn (...) io.stderr:write(...) end
19+
20+function test_pipe ()
21+ if not file_exists('/bin/sed') then
22+ warn 'Did not find /bin/sed, skipping test'
23+ return true
24+ end
25+ local pipe_result = utils.pipe('/bin/sed', {'-e', 's/a/b/'}, 'abc')
26+ return pipe_result == 'bbc'
27+end
28+
29+function test_failing_pipe ()
30+ if not file_exists('/bin/false') then
31+ warn 'Did not find /bin/false, skipping test'
32+ return true
33+ end
34+ local res, err = pcall(utils.pipe, '/bin/false', {}, 'abc')
35+ return not res and
36+ err.command == '/bin/false' and
37+ err.error_code == 1 and
38+ err.output == ''
39+end
40+
41+-- Read
42+------------------------------------------------------------------------
43+function test_read ()
44+ local valid_markdown = '*Hello*, World!\n'
45+ local res = pandoc.read(valid_markdown).blocks[1].content
46+ return res[1].t == 'Emph' and res[3].t == 'Space' and res[4].t == 'Str'
47+end
48+
49+function test_failing_read ()
50+ local res, err = pcall(pandoc.read, 'foo', 'nosuchreader')
51+ return not res and err:match 'Unknown reader: nosuchreader'
52+end
53+
54+
55+-- Return result
56+------------------------------------------------------------------------
57+function run(fn)
58+ return fn() and "OK" or "FAIL"
59+end
60+
61+function Para (el)
62+ return {
63+ pandoc.Plain{pandoc.Str("sha1: " .. run(test_sha1))},
64+ pandoc.Plain{pandoc.Str("pipe: " .. run(test_pipe))},
65+ pandoc.Plain{pandoc.Str("failing pipe: " .. run(test_failing_pipe))},
66+ pandoc.Plain{pandoc.Str("read: " .. run(test_read))},
67+ pandoc.Plain{pandoc.Str("failing read: " .. run(test_failing_read))},
68+ }
69+end