Compare commits

...

2 Commits

3 changed files with 25 additions and 1 deletions

View File

@ -215,12 +215,16 @@ def parse_block(key, seq):
if op == '+=': if op == '+=':
if isinstance(ret[k], str): if isinstance(ret[k], str):
assign = [ret[k]] assign = [ret[k]]
elif ret[k] is True:
assign = []
else: else:
assign = ret[k] assign = ret[k]
if isinstance(value, str): if isinstance(value, str):
assign.append(value) assign.append(value)
else: else:
assign.extend(value) assign.extend(value)
if isinstance(assign, list) and len(assign) == 1:
assign = assign[0]
else: else:
assign = value assign = value

View File

@ -1,2 +1,2 @@
# pylint: disable=missing-module-docstring,invalid-name # pylint: disable=missing-module-docstring,invalid-name
version = '0.1.1' version = '0.1.2'

View File

@ -65,3 +65,23 @@ def test_ovewrite_nonexistent():
'Keys can only be updated if they exist.' 'Keys can only be updated if they exist.'
with pytest.raises(ParseError): with pytest.raises(ParseError):
loads_xbc('a := 1') loads_xbc('a := 1')
def test_append_key():
'Append an item to a key.'
assert loads_xbc('a; a += 1') == {'a': '1'}
def test_append_single():
'Append an item to a single-item value.'
assert loads_xbc('a = 1; a += 2') == {'a': ['1', '2']}
def test_append_single2():
'Append multiple items to a single-item value.'
assert loads_xbc('a = 1; a += 2, 3') == {'a': ['1', '2', '3']}
def test_append_multi():
'Append an item to an array value'
assert loads_xbc('a = 1, 2; a += 3') == {'a': ['1', '2', '3']}
def test_append_multi2():
'Append multiple items to an array value.'
assert loads_xbc('a = 1, 2; a += 3, 4') == {'a': ['1', '2', '3', '4']}