parent
03b9f3d5f3
commit
7f9b32e36a
2 changed files with 10 additions and 1 deletions
|
@ -846,7 +846,10 @@ local AttributeList = {
|
||||||
|
|
||||||
__newindex = function (t, k, v)
|
__newindex = function (t, k, v)
|
||||||
local cur, idx = List.find_if(t, assoc_key_equals(k))
|
local cur, idx = List.find_if(t, assoc_key_equals(k))
|
||||||
if v == nil then
|
if v == nil and not cur then
|
||||||
|
-- deleted key does not exists in list
|
||||||
|
return
|
||||||
|
elseif v == nil then
|
||||||
table.remove(t, idx)
|
table.remove(t, idx)
|
||||||
elseif cur then
|
elseif cur then
|
||||||
cur[2] = v
|
cur[2] = v
|
||||||
|
|
|
@ -62,6 +62,12 @@ return {
|
||||||
local assoc_list = setmetatable(attributes, nil)
|
local assoc_list = setmetatable(attributes, nil)
|
||||||
assert.are_same(assoc_list, {{'b', '2'}})
|
assert.are_same(assoc_list, {{'b', '2'}})
|
||||||
end),
|
end),
|
||||||
|
test('remains unchanged if deleted key did not exist', function ()
|
||||||
|
local assoc_list = pandoc.List:new {{'alpha', 'x'}, {'beta', 'y'}}
|
||||||
|
local attributes = pandoc.Attr('', {}, assoc_list:clone()).attributes
|
||||||
|
attributes.a = nil
|
||||||
|
assert.are_same(pandoc.List:new(attributes), assoc_list)
|
||||||
|
end),
|
||||||
test('gives key-value pairs when iterated-over', function ()
|
test('gives key-value pairs when iterated-over', function ()
|
||||||
local attributes = {width = '11', height = '22', name = 'test'}
|
local attributes = {width = '11', height = '22', name = 'test'}
|
||||||
local attr = pandoc.Attr('', {}, attributes)
|
local attr = pandoc.Attr('', {}, attributes)
|
||||||
|
|
Loading…
Add table
Reference in a new issue