Skip to content

Commit 559dada

Browse files
fix: honor CLI indent option when decoding (#48)
* test: add comprehensive decoder edge case tests Add 58 new edge case tests for the decoder module, improving coverage. * fix: honor CLI indent option when decoding * chore: remove oversized decoder edge-case test file per review feedback
1 parent 728120d commit 559dada

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/toon_format/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def decode_toon_to_json(
210210
options = DecodeOptions(indent=indent, strict=strict)
211211
data = decode(toon_text, options)
212212

213-
return json.dumps(data, indent=2, ensure_ascii=False)
213+
return json.dumps(data, indent=indent, ensure_ascii=False)
214214

215215

216216
if __name__ == "__main__":

tests/test_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ def test_no_strict_option(self, tmp_path):
272272
result = main()
273273
assert result == 0
274274

275+
def test_decode_indent_option_affects_output(self, tmp_path):
276+
"""Ensure --indent controls the JSON formatting."""
277+
input_file = tmp_path / "input.toon"
278+
input_file.write_text("outer:\n inner: 1")
279+
280+
with patch("sys.stdout", new_callable=StringIO) as mock_stdout:
281+
with patch("sys.argv", ["toon", str(input_file), "--decode", "--indent", "4"]):
282+
result = main()
283+
assert result == 0
284+
output = mock_stdout.getvalue()
285+
assert ' "inner": 1' in output
286+
275287
def test_error_file_not_found(self):
276288
"""Test error when input file doesn't exist."""
277289
with patch("sys.stderr", new_callable=StringIO) as mock_stderr:

0 commit comments

Comments
 (0)