-
Notifications
You must be signed in to change notification settings - Fork 56
feat: Add JSON indentation option to decode() method #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
e35585f
fd4c793
44ffada
9f906f9
41a8da5
aa992fd
25ca310
16bfa8f
7f854b5
239e9d2
28dc1ea
089fa56
f4e54ed
c7bdbcf
b53ca61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,12 +52,26 @@ class DecodeOptions: | |||||||||||||||
|
|
||||||||||||||||
| Attributes: | ||||||||||||||||
| indent: Number of spaces per indentation level (default: 2) | ||||||||||||||||
| Used for parsing TOON format. | ||||||||||||||||
| strict: Enable strict validation (default: True) | ||||||||||||||||
| Enforces spec conformance checks. | ||||||||||||||||
|
Comment on lines
54
to
+57
|
||||||||||||||||
| indent: Number of spaces per indentation level (default: 2) | |
| Used for parsing TOON format. | |
| strict: Enable strict validation (default: True) | |
| Enforces spec conformance checks. | |
| indent: Number of spaces per indentation level (default: 2). | |
| strict: Enable strict validation (default: True). | |
| Enforces TOON specification conformance checks. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,10 +10,14 @@ | |||||||||||||||||||||||||
| Python type normalization is tested in test_normalization.py. | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||
| from typing import Any, Dict, List | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| from toon_format import ToonDecodeError, decode, encode | ||||||||||||||||||||||||||
| from toon_format.types import DecodeOptions, EncodeOptions | ||||||||||||||||||||||||||
| from tests.test_spec_fixtures import get_all_decode_fixtures | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| class TestEncodeAPI: | ||||||||||||||||||||||||||
|
|
@@ -286,3 +290,111 @@ def test_roundtrip_with_length_marker(self): | |||||||||||||||||||||||||
| toon = encode(original, {"lengthMarker": "#"}) | ||||||||||||||||||||||||||
| decoded = decode(toon) | ||||||||||||||||||||||||||
| assert decoded == original | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| class TestDecodeJSONIndentation: | ||||||||||||||||||||||||||
| """Test decode() JSON indentation feature (Issue #10). | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Comprehensive tests for the json_indent feature are in TestDecodeJSONIndentationWithSpecFixtures, | ||||||||||||||||||||||||||
| which validates against official TOON specification fixtures. | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
jreakin marked this conversation as resolved.
|
||||||||||||||||||||||||||
| pass | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+298
to
+311
|
||||||||||||||||||||||||||
| @pytest.mark.skip( | |
| reason="Placeholder for targeted decode() JSON indentation tests. See TODO above." | |
| ) | |
| class TestDecodeJSONIndentation: | |
| """Test decode() JSON indentation feature (Issue #10). | |
| Comprehensive tests for the json_indent feature are in | |
| TestDecodeJSONIndentationWithSpecFixtures, which validates against official | |
| TOON specification fixtures. | |
| """ | |
| pass |
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type hint for _get_sample_decode_fixtures() is List[tuple] which is imprecise. Based on how the return value is used (lines 337-338 and 365-366), it should be List[Tuple[str, Dict[str, Any]]] to match the structure of the tuples being appended at line 325.
Consider updating the import and return type:
from typing import Any, Dict, List, Tuple # Add Tuple to imports
def _get_sample_decode_fixtures() -> List[Tuple[str, Dict[str, Any]]]:
Copilot
AI
Nov 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unpacking in this loop is incorrect. get_all_decode_fixtures() returns tuples of (test_id, test_data, fixture_name) (3 elements), but the code unpacks only 2 elements into (test_id, test_data). This will cause a ValueError: too many values to unpack at runtime.
Fix the unpacking to include all three elements:
for test_id, test_data, fixture_name in all_fixtures:
if f"{fixture_name}.json" in selected_files and len(test_cases) < 9:
test_cases.append((test_id, test_data))
Uh oh!
There was an error while loading. Please reload this page.