Skip to content

Commit 597e106

Browse files
committed
Add tests for int and float JSON values and fix lexer regex
- Add 42 and 3.14 to TEST_JSON_VALUES to test numeric JSON parsing - Fix EnhancedJsonLexer regex to handle prefixes before numeric JSON values - Resolves FIXME comment about missing int & float test coverage
1 parent 5b604c3 commit 597e106

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

httpie/output/lexers/json.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class EnhancedJsonLexer(RegexLexer):
2020
tokens = {
2121
'root': [
2222
# Eventual non-JSON data prefix followed by actual JSON body.
23-
# FIX: data prefix + number (integer or float) is not correctly handled.
2423
(
25-
fr'({PREFIX_REGEX})' + r'((?:[{\["]|true|false|null).+)',
24+
fr'({PREFIX_REGEX})' + r'((?:[{\["]|true|false|null|-?\d).+)',
2625
bygroups(PREFIX_TOKEN, using(JsonLexer))
2726
),
2827
# JSON body.

tests/test_json.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
'}',
2929
]
3030
TEST_JSON_VALUES = [
31-
# FIXME: missing int & float
3231
{},
3332
{'a': 0, 'b': 0},
3433
[],
3534
['a', 'b'],
3635
'foo',
36+
42,
37+
3.14,
3738
True,
3839
False,
3940
None,

0 commit comments

Comments
 (0)