Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/test_toml_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,3 +1314,25 @@ def test_appending_to_super_table():
"""

assert doc.as_string() == expected


def test_missing_newline_after_inline_table_issue_440():
"""Regression test for https://github.com/python-poetry/tomlkit/issues/440"""
content = """[x]\na.b = {}"""
doc = parse(content)
doc["x"]["c"] = 3
expected = "[x]\na.b = {}\nc = 3\n"
assert doc.as_string() == expected

# With trailing newline should also work
content2 = """[x]\na.b = {}\n"""
doc2 = parse(content2)
doc2["x"]["c"] = 3
assert doc2.as_string() == expected

# Non-dotted key variant
content3 = """[x]\na = {}"""
doc3 = parse(content3)
doc3["x"]["c"] = 3
expected3 = "[x]\na = {}\nc = 3\n"
assert doc3.as_string() == expected3
2 changes: 2 additions & 0 deletions tomlkit/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,8 @@ def _render_table(self, key: Key, table: Table, prefix: str | None = None) -> st
cur += "\n"
cur += self._render_aot(k, v, prefix=_key)
else:
if k is not None and cur and not cur.endswith("\n"):
cur += "\n"
cur += self._render_simple_item(
k, v, prefix=_key if key.is_dotted() else None
)
Expand Down
Loading