1local tasty = require 'tasty'
3local test = tasty.test_case
4local group = tasty.test_group
5local assert = tasty.assert
7function os_is_windows ()
8 return package.config:sub(1,1) == '\\'
14 test('returns null-Attr if no arguments are given', function ()
15 local attr = pandoc.Attr()
16 assert.are_equal(attr.identifier, '')
17 assert.are_same(attr.classes, {})
18 assert.are_same(attr.attributes, {})
21 'accepts string-indexed table or list of pairs as attributes',
23 local attributes_list = pandoc.List:new {{'one', '1'}, {'two', '2'}}
24 local attr_from_list = pandoc.Attr('', {}, attributes_list:clone())
27 pandoc.List:new(attr_from_list.attributes),
31 local attributes_table = {one = '1', two = '2'}
32 local attr_from_table = pandoc.Attr('', {}, attributes_table)
34 local assoc_list_from_table =
35 pandoc.List:new(attr_from_table.attributes)
36 -- won't work in general, but does in this special case
37 table.sort(assoc_list_from_table, function(x, y) return x[1]<y[1] end)
39 assoc_list_from_table,
45 group 'AttributeList' {
46 test('allows access via fields', function ()
47 local attributes = pandoc.Attr('', {}, {{'a', '1'}, {'b', '2'}}).attributes
48 assert.are_equal(attributes.a, '1')
49 assert.are_equal(attributes.b, '2')
51 test('allows access to pairs via numerical indexing', function ()
52 local attributes = pandoc.Attr('', {}, {{'a', '1'}, {'b', '2'}}).attributes
53 assert.are_same(attributes[1], {'a', '1'})
54 assert.are_same(attributes[2], {'b', '2'})
56 test('adds entries by field name', function ()
57 local attributes = pandoc.Attr('',{}, {{'c', '1'}, {'d', '2'}}).attributes
60 -- checking the full AttributeList would "duplicate" entries
61 setmetatable(attributes, nil),
62 {{'c', '1'}, {'d', '2'}, {'e', '3'}}
65 test('deletes entries by field name', function ()
66 local attributes = pandoc.Attr('',{}, {a = '1', b = '2'}).attributes
68 assert.is_nil(attributes.a)
69 local assoc_list = setmetatable(attributes, nil)
70 assert.are_same(assoc_list, {{'b', '2'}})
72 test('remains unchanged if deleted key did not exist', function ()
73 local assoc_list = pandoc.List:new {{'alpha', 'x'}, {'beta', 'y'}}
74 local attributes = pandoc.Attr('', {}, assoc_list:clone()).attributes
76 assert.are_same(pandoc.List:new(attributes), assoc_list)
78 test('gives key-value pairs when iterated-over', function ()
79 local attributes = {width = '11', height = '22', name = 'test'}
80 local attr = pandoc.Attr('', {}, attributes)
82 for k, v in pairs(attr.attributes) do
83 assert.are_equal(attributes[k], v)
86 assert.are_equal(count, 3)
92 test('clones Attr', function ()
93 local attr = pandoc.Attr('test', {'my-class'}, {foo = 'bar'})
94 local cloned = attr:clone()
98 assert.are_same(cloned.identifier, 'test')
99 assert.are_same(cloned.classes, {'my-class'})
100 assert.are_same(cloned.attributes.foo, 'bar')
102 test('clones ListAttributes', function ()
103 local la = pandoc.ListAttributes(2, pandoc.DefaultStyle, pandoc.Period)
104 local cloned = la:clone()
106 assert.are_same(cloned.start, 2)
108 test('clones Para', function ()
109 local para = pandoc.Para {pandoc.Str 'Hello'}
110 local cloned = para:clone()
111 para.content[1].text = 'bye'
112 assert.are_same(cloned, pandoc.Para {pandoc.Str 'Hello'})
114 test('clones Str', function ()
115 local str = pandoc.Str 'Hello'
116 local cloned = str:clone()
118 assert.are_same(cloned.text, 'Hello')
120 test('clones Citation', function ()
121 local cite = pandoc.Citation('leibniz', pandoc.AuthorInText)
122 local cloned = cite:clone()
124 assert.are_same(cloned.id, 'leibniz')
129 test('external string processing', function ()
130 if os_is_windows() then
131 local pipe_result = pandoc.pipe('find', {'hi'}, 'hi')
132 assert.are_equal('hi', pipe_result:match '%a+')
134 local pipe_result = pandoc.pipe('tr', {'a', 'b'}, 'abc')
135 assert.are_equal('bbc', pipe_result:match '%a+')
138 test('failing pipe', function ()
139 if os_is_windows() then
140 local success, err = pcall(pandoc.pipe, 'find', {'/a'}, 'hi')
141 assert.is_falsy(success)
142 assert.are_equal('find', err.command)
143 assert.is_truthy(err.error_code ~= 0)
145 local success, err = pcall(pandoc.pipe, 'false', {}, 'abc')
146 assert.is_falsy(success)
147 assert.are_equal('false', err.command)
148 assert.are_equal(1, err.error_code)
149 assert.are_equal('', err.output)
155 test('Markdown', function ()
156 local valid_markdown = '*Hello*, World!\n'
157 local expected = pandoc.Pandoc({
159 pandoc.Emph { pandoc.Str 'Hello' },
165 assert.are_same(expected, pandoc.read(valid_markdown))
167 test('failing read', function ()
168 assert.error_matches(
169 function () pandoc.read('foo', 'nosuchreader') end,
170 'Unknown reader: nosuchreader'
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