Skip to content

Commit

Permalink
Pick the max when there are many indices for a key. (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored and sdispater committed Nov 28, 2018
1 parent b10d0cc commit cad4e0a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,18 @@ def test_add_remove():
doc.remove("foo")

assert doc.as_string() == ""


def test_append_table_after_multiple_indices():
content = """
[packages]
foo = "*"
[settings]
enable = false
[packages.bar]
version = "*"
"""
doc = parse(content)
doc.append("foobar", {"name": "John"})
3 changes: 3 additions & 0 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def _insert_after(
item = _item(item)

idx = self._map[key]
# Insert after the max index if there are many.
if isinstance(idx, tuple):
idx = max(idx)
current_item = self._body[idx][1]
if "\n" not in current_item.trivia.trail:
current_item.trivia.trail += "\n"
Expand Down

0 comments on commit cad4e0a

Please sign in to comment.