Add extra JSON highlighting tests

This commit is contained in:
Darren Burns 2022-03-08 15:43:35 +00:00
parent 7ce9bcabcd
commit 93e584c47c
No known key found for this signature in database
GPG Key ID: B0939B45037DC345
2 changed files with 17 additions and 0 deletions

View File

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Collapsed definitions for single-character spinners, to save memory and reduce import time.
- Fix print_json indent type in __init__.py
- Fix error when inspecting object defined in REPL https://github.com/Textualize/rich/pull/2037
- Fix incorrect highlighting of non-indented JSON https://github.com/Textualize/rich/pull/2038
### Changed

View File

@ -113,6 +113,22 @@ def test_highlight_json_with_indent():
]
def test_highlight_json_string_only():
json_string = '"abc"'
text = Text(json_string)
highlighter = JSONHighlighter()
highlighter.highlight(text)
assert text.spans == [Span(0, 5, "json.str")]
def test_highlight_json_empty_string_only():
json_string = '""'
text = Text(json_string)
highlighter = JSONHighlighter()
highlighter.highlight(text)
assert text.spans == [Span(0, 2, "json.str")]
def test_highlight_json_no_indent():
json_string = json.dumps({"name": "apple", "count": 1}, indent=None)
text = Text(json_string)