Skip to content

Commit ad7dfe0

Browse files
authored
fix: multiline array format broken when deleting the last item (#218)
1 parent a639224 commit ad7dfe0

File tree

2 files changed

+221
-118
lines changed

2 files changed

+221
-118
lines changed

tests/test_items.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ def test_array_multiline_modify():
368368
def test_append_to_empty_array():
369369
doc = parse("x = [ ]")
370370
doc["x"].append("a")
371-
assert doc.as_string() == 'x = [ "a" ]'
371+
assert doc.as_string() == 'x = ["a" ]'
372372
doc = parse("x = [\n]")
373373
doc["x"].append("a")
374374
assert doc.as_string() == 'x = [\n "a"\n]'
@@ -410,6 +410,8 @@ def test_modify_array_with_comment():
410410
2
411411
]"""
412412
)
413+
doc["x"].pop(0)
414+
assert doc.as_string() == "x = [\n 2\n]"
413415

414416

415417
def test_append_to_multiline_array_with_comment():
@@ -432,14 +434,25 @@ def test_append_to_multiline_array_with_comment():
432434
2,
433435
3,
434436
]
437+
"""
438+
)
439+
assert doc["x"].pop() == 3
440+
assert (
441+
doc.as_string()
442+
== """\
443+
x = [
444+
# Here is a comment
445+
1,
446+
2,
447+
]
435448
"""
436449
)
437450

438451

439452
def test_append_dict_to_array():
440-
doc = parse("x = [ ]")
453+
doc = parse("x = []")
441454
doc["x"].append({"name": "John Doe", "email": "[email protected]"})
442-
expected = 'x = [ {name = "John Doe",email = "[email protected]"} ]'
455+
expected = 'x = [{name = "John Doe",email = "[email protected]"}]'
443456
assert doc.as_string() == expected
444457
# Make sure the produced string is valid
445458
assert parse(doc.as_string()) == doc
@@ -469,7 +482,7 @@ def test_array_add_line():
469482
== """[
470483
1, 2, 3, # Line 1
471484
4, 5, 6, # Line 2
472-
7, 8
485+
7, 8,
473486
]"""
474487
)
475488

0 commit comments

Comments
 (0)