Skip to content

Commit

Permalink
Fix bug and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moosems committed Jul 26, 2024
1 parent 9ba4dec commit d1fcb94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 50 deletions.
6 changes: 4 additions & 2 deletions salve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion salve/server_functions/links_and_hidden_chars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
59 changes: 12 additions & 47 deletions tests/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d1fcb94

Please sign in to comment.