xbc: support append to bare key, add array tests
parent
2c0dcb6e9e
commit
e6205a4242
|
@ -215,12 +215,16 @@ def parse_block(key, seq):
|
|||
if op == '+=':
|
||||
if isinstance(ret[k], str):
|
||||
assign = [ret[k]]
|
||||
elif ret[k] is True:
|
||||
assign = []
|
||||
else:
|
||||
assign = ret[k]
|
||||
if isinstance(value, str):
|
||||
assign.append(value)
|
||||
else:
|
||||
assign.extend(value)
|
||||
if isinstance(assign, list) and len(assign) == 1:
|
||||
assign = assign[0]
|
||||
else:
|
||||
assign = value
|
||||
|
||||
|
|
|
@ -65,3 +65,23 @@ def test_ovewrite_nonexistent():
|
|||
'Keys can only be updated if they exist.'
|
||||
with pytest.raises(ParseError):
|
||||
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']}
|
||||
|
|
Loading…
Reference in New Issue