Skip to content

Commit

Permalink
fix: multiline array format broken when deleting the last item (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Aug 7, 2022
1 parent a639224 commit ad7dfe0
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 118 deletions.
21 changes: 17 additions & 4 deletions tests/test_items.py
Expand Up @@ -368,7 +368,7 @@ def test_array_multiline_modify():
def test_append_to_empty_array():
doc = parse("x = [ ]")
doc["x"].append("a")
assert doc.as_string() == 'x = [ "a" ]'
assert doc.as_string() == 'x = ["a" ]'
doc = parse("x = [\n]")
doc["x"].append("a")
assert doc.as_string() == 'x = [\n "a"\n]'
Expand Down Expand Up @@ -410,6 +410,8 @@ def test_modify_array_with_comment():
2
]"""
)
doc["x"].pop(0)
assert doc.as_string() == "x = [\n 2\n]"


def test_append_to_multiline_array_with_comment():
Expand All @@ -432,14 +434,25 @@ def test_append_to_multiline_array_with_comment():
2,
3,
]
"""
)
assert doc["x"].pop() == 3
assert (
doc.as_string()
== """\
x = [
# Here is a comment
1,
2,
]
"""
)


def test_append_dict_to_array():
doc = parse("x = [ ]")
doc = parse("x = []")
doc["x"].append({"name": "John Doe", "email": "john@doe.com"})
expected = 'x = [ {name = "John Doe",email = "john@doe.com"} ]'
expected = 'x = [{name = "John Doe",email = "john@doe.com"}]'
assert doc.as_string() == expected
# Make sure the produced string is valid
assert parse(doc.as_string()) == doc
Expand Down Expand Up @@ -469,7 +482,7 @@ def test_array_add_line():
== """[
1, 2, 3, # Line 1
4, 5, 6, # Line 2
7, 8
7, 8,
]"""
)

Expand Down

0 comments on commit ad7dfe0

Please sign in to comment.