Skip to content

Commit

Permalink
Select at least one character
Browse files Browse the repository at this point in the history
  • Loading branch information
nineteendo committed Aug 1, 2024
1 parent 020bbc6 commit 6fbcd9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/jsonyx/_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/jsonyx/test/test_syntax_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
# ^^^^^^^ ^^^^^^^
Expand Down

0 comments on commit 6fbcd9d

Please sign in to comment.