From d1fcb945dd0c441ba8d88e0ee56affde24ebcdad Mon Sep 17 00:00:00 2001 From: Moosems <95927277+Moosems@users.noreply.github.com> Date: Thu, 25 Jul 2024 20:06:44 -0600 Subject: [PATCH] Fix bug and tests --- salve/server.py | 6 +- .../links_and_hidden_chars.py | 2 +- tests/test_ipc.py | 59 ++++--------------- 3 files changed, 17 insertions(+), 50 deletions(-) diff --git a/salve/server.py b/salve/server.py index d9fd3b7..5a83b2c 100644 --- a/salve/server.py +++ b/salve/server.py @@ -3,7 +3,7 @@ from time import sleep from pyeditorconfig import get_config -from token_tools import Token +from token_tools import Token, normal_text_range from .misc import ( COMMANDS, @@ -159,7 +159,9 @@ def handle_request(self, request: Request) -> None: self.logger.info("Searching for Links and chars") result = get_special_tokens( self.files[file], - request["text_range"], # type: ignore + normal_text_range(self.files[file], request["text_range"])[ # type: ignore + 1 + ], ) case _: self.logger.warning(f"Command {command} not recognized") diff --git a/salve/server_functions/links_and_hidden_chars.py b/salve/server_functions/links_and_hidden_chars.py index 3da8222..e1f609a 100644 --- a/salve/server_functions/links_and_hidden_chars.py +++ b/salve/server_functions/links_and_hidden_chars.py @@ -10,7 +10,7 @@ def get_urls(whole_text: str, text_range: tuple[int, int]) -> list[Token]: start_pos: tuple[int, int] = (text_range[0], 0) url_toks: list[Token] = [] while True: - if start_pos[0] >= text_range[1]: + if start_pos[0] > text_range[1]: break line: str = lines[start_pos[0] - text_range[0]][start_pos[1] :] match_start: Match[str] | None = url_regex.search(line) diff --git a/tests/test_ipc.py b/tests/test_ipc.py index 253ee56..b2ee0d1 100644 --- a/tests/test_ipc.py +++ b/tests/test_ipc.py @@ -82,7 +82,7 @@ def test_IPC(): raise AssertionError("Highlight output is None") highlight_output["id"] = 0 - expected_output: Response = { + assert highlight_output == { "id": 0, "type": "response", "cancelled": False, @@ -122,63 +122,28 @@ def test_IPC(): ], } - # Deal with Windows weirdness - if platform == "win32": - expected_output = { - "id": 0, - "type": "response", - "cancelled": False, - "command": HIGHLIGHT, - "result": [ - ((1, 0), 4, "Keyword"), - ((1, 5), 4, "Name"), - ((1, 10), 6, "Keyword"), - ((1, 17), 1, "Name"), - ((1, 20), 12, "Comment"), - ((3, 0), 3, "Name"), - ((3, 4), 1, "Operator"), - ((3, 6), 3, "Name"), - ((3, 11), 7, "Comment"), - ((5, 0), 5, "Name"), - ((5, 5), 1, "Punctuation"), - ((5, 6), 5, "String"), - ((5, 11), 1, "Punctuation"), - ((5, 14), 16, "Comment"), - ((8, 0), 5, "Keyword"), - ((8, 6), 3, "Name"), - ((8, 9), 1, "Punctuation"), - ((8, 10), 3, "Name"), - ((8, 13), 2, "Punctuation"), - ((9, 4), 3, "String"), - ((10, 4), 4, "String"), - ((11, 4), 3, "String"), - ((13, 4), 3, "Keyword"), - ((13, 8), 8, "Name"), - ((13, 16), 1, "Punctuation"), - ((13, 17), 4, "Name"), - ((13, 21), 2, "Punctuation"), - ((14, 8), 4, "Keyword"), - ((17, 0), 3, "Name"), - ((17, 3), 2, "Punctuation"), - ((18, 0), 24, "Comment"), - ], - } - - assert highlight_output == expected_output - links_and_hidden_chars_result: Response | None = context.get_response( LINKS_AND_CHARS ) if links_and_hidden_chars_result is None: raise AssertionError("links_and_hidden_chars_result output is None") links_and_hidden_chars_result["id"] = 0 - assert links_and_hidden_chars_result == { + expected_output = { "id": 0, "type": "response", "cancelled": False, "command": LINKS_AND_CHARS, - "result": [((5, 7), 1, "Hidden_Char")], + "result": [((18, 2), 22, "Link"), ((5, 7), 1, "Hidden_Char")], } + if platform == "win32": + expected_output = { + "id": 0, + "type": "response", + "cancelled": False, + "command": LINKS_AND_CHARS, + "result": [((18, 2), 22, "Link")], + } + assert links_and_hidden_chars_result == expected_output context.update_file( "foo", open(Path("tests/testing_file2.py"), "r+").read()