@@ -9,6 +9,71 @@ function os_is_windows ()
13+ group 'Constructor' {
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_table = {one = '1', two = '2'}
24+ local attributes_list = pandoc.List:new {{'one', '1'}, {'two', '2'}}
25+ local attr_from_table = pandoc.Attr('', {}, attributes_table)
26+ local attr_from_list = pandoc.Attr('', {}, attributes_list:clone())
28+ pandoc.List:new(attr_from_table.attributes),
32+ pandoc.List:new(attr_from_list.attributes),
38+ group 'AttributeList' {
39+ test('allows access via fields', function ()
40+ local attributes = pandoc.Attr('', {}, {{'a', '1'}, {'b', '2'}}).attributes
41+ assert.are_equal(attributes.a, '1')
42+ assert.are_equal(attributes.b, '2')
44+ test('allows access to pairs via numerical indexing', function ()
45+ local attributes = pandoc.Attr('', {}, {{'a', '1'}, {'b', '2'}}).attributes
46+ assert.are_same(attributes[1], {'a', '1'})
47+ assert.are_same(attributes[2], {'b', '2'})
49+ test('adds entries by field name', function ()
50+ local attributes = pandoc.Attr('',{}, {{'c', '1'}, {'d', '2'}}).attributes
53+ -- checking the full AttributeList would "duplicate" entries
54+ setmetatable(attributes, nil),
55+ {{'c', '1'}, {'d', '2'}, {'e', '3'}}
58+ test('deletes entries by field name', function ()
59+ local attributes = pandoc.Attr('',{}, {a = '1', b = '2'}).attributes
61+ assert.is_nil(attributes.a)
62+ local assoc_list = setmetatable(attributes, nil)
63+ assert.are_same(assoc_list, {{'b', '2'}})
65+ test('gives key-value pairs when iterated-over', function ()
66+ local attributes = {width = '11', height = '22', name = 'test'}
67+ local attr = pandoc.Attr('', {}, attributes)
69+ for k, v in pairs(attr.attributes) do
70+ assert.are_equal(attributes[k], v)
73+ assert.are_equal(count, 3)
12 group 'pipe' {
77 group 'pipe' {
13 test('external string processing', function ()
78 test('external string processing', function ()
14 if os_is_windows() then
79 if os_is_windows() then