From 6fbcd9ddeb37f54c86c70f081a353a97a6395dc9 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Thu, 1 Aug 2024 11:12:25 +0200 Subject: [PATCH] Select at least one character --- src/jsonyx/_decoder.py | 4 +++- src/jsonyx/test/test_syntax_error.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/jsonyx/_decoder.py b/src/jsonyx/_decoder.py index b48a8cd..68a3066 100644 --- a/src/jsonyx/_decoder.py +++ b/src/jsonyx/_decoder.py @@ -51,7 +51,9 @@ def _get_err_context(doc: str, start: int, end: int) -> tuple[int, str, int]: else: line_end = start - end = min(max(start + 1, line_end), end) + if (end := min(max(start + 1, line_end), end)) == start: + end += 1 + max_chars: int = get_terminal_size().columns - 4 # leading spaces if end == line_end + 1: # newline max_chars -= 1 diff --git a/src/jsonyx/test/test_syntax_error.py b/src/jsonyx/test/test_syntax_error.py index 6fff4a6..c77df61 100644 --- a/src/jsonyx/test/test_syntax_error.py +++ b/src/jsonyx/test/test_syntax_error.py @@ -83,8 +83,8 @@ def test_start_and_end_position( # noqa: PLR0913, PLR0917 # ^^^^^^^ ^^^^^^^ # No newline - (17, "start-middle-end", 0, 5, 1, "start-middle-end", 6), - # ^^^^^ ^^^^^ + (9, "start-end", 0, 5, 1, "start-end", 6), + # ^^^^^ ^^^^^ (8, "current\nnext", 0, 12, 1, "current", 8), # ^^^^^^^^^^^^^ ^^^^^^^ (8, "current\rnext", 0, 12, 1, "current", 8), @@ -102,6 +102,10 @@ def test_start_and_end_position( # noqa: PLR0913, PLR0917 (8, "current\r\nnext", 7, 13, 8, "current", 9), # ^^^^^^^^ ^ + # At least one character + (9, "start-end", 5, 5, 6, "start-end", 7), + # ^ ^ + # Expand tabs (8, "\tcurrent", 1, 8, 2, " current", 9), # ^^^^^^^ ^^^^^^^