diff --git a/src/toon_format/cli.py b/src/toon_format/cli.py index 07efd06..f861f33 100644 --- a/src/toon_format/cli.py +++ b/src/toon_format/cli.py @@ -210,7 +210,7 @@ def decode_toon_to_json( options = DecodeOptions(indent=indent, strict=strict) data = decode(toon_text, options) - return json.dumps(data, indent=2, ensure_ascii=False) + return json.dumps(data, indent=indent, ensure_ascii=False) if __name__ == "__main__": diff --git a/tests/test_cli.py b/tests/test_cli.py index 3499bf7..95b3aea 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -272,6 +272,18 @@ def test_no_strict_option(self, tmp_path): result = main() assert result == 0 + def test_decode_indent_option_affects_output(self, tmp_path): + """Ensure --indent controls the JSON formatting.""" + input_file = tmp_path / "input.toon" + input_file.write_text("outer:\n inner: 1") + + with patch("sys.stdout", new_callable=StringIO) as mock_stdout: + with patch("sys.argv", ["toon", str(input_file), "--decode", "--indent", "4"]): + result = main() + assert result == 0 + output = mock_stdout.getvalue() + assert ' "inner": 1' in output + def test_error_file_not_found(self): """Test error when input file doesn't exist.""" with patch("sys.stderr", new_callable=StringIO) as mock_stderr: