Skip to content

Commit

Permalink
fix: trailing_commas: fix tests & only when indent set
Browse files Browse the repository at this point in the history
Make the `trailing_commas` flag do what it says: Only apply when pretty
printing (`indent is not None`).

Fix all remaining `test_simpleion.py` failures.
  • Loading branch information
Stephen Jacob committed Oct 10, 2024
1 parent d753ba1 commit b124edc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion amazon/ion/writer_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def _raw_writer_coroutine(depth=0, container_event=None, whence=None, indent=Non
ion_event, self = (yield transition)
delegate = self

if has_written_values and (trailing_commas or not ion_event.event_type.ends_container):
if has_written_values and ((indent and trailing_commas) or not ion_event.event_type.ends_container):
# TODO This will always emit a delimiter for containers--should make it not do that.
# Write the delimiter for the next value.
if depth == 0:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_simpleion.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ class PrettyPrintParams(NamedTuple):
indent=None, trailing_commas=True, # not pretty print
exact_text="$ion_1_0 [a,b,chair::2008-08-08T]"),
PrettyPrintParams(ion_text='[apple, {roof: false}]', indent='\t', trailing_commas=True,
exact_text="$ion_1_0\n[\n\tapple,\n\t{\n\t\troof: false,\n\t}\n]"),
exact_text="$ion_1_0\n[\n\tapple,\n\t{\n\t\troof: false,\n\t},\n]"),
PrettyPrintParams(ion_text='[apple, "banana", {roof: false}]', indent='\t', trailing_commas=True,
exact_text="$ion_1_0\n[\n\tapple,\n\t\"banana\",\n\t{\n\t\troof: false,\n\t}\n]"),
exact_text="$ion_1_0\n[\n\tapple,\n\t\"banana\",\n\t{\n\t\troof: false,\n\t},\n]"),
PrettyPrintParams(ion_text='[apple, {roof: false, walls:4, door: wood::large::true}]', indent='\t',
trailing_commas=True,
regexes=["\\A\\$ion_1_0\n\\[\n\tapple,\n\t\\{", "\n\t\tdoor: wood::large::true,\n",
"\n\t\troof: false,\n", "\n\t\twalls: 4,\n", "\n\t\\}\n\\]\\Z"])
"\n\t\troof: false,\n", "\n\t\twalls: 4,\n", "\n\t\\},\n\\]\\Z"])
)
def test_pretty_print(p):
if c_ext:
Expand Down

0 comments on commit b124edc

Please sign in to comment.