Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 4fdfafd

Browse files
authored
Merge pull request #575 from Jaseci-Labs/test_py_type
Test: Python Type Definition and References for Symbols
2 parents 707e268 + 34341b3 commit 4fdfafd

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

jaclang/langserve/tests/test_server.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,77 @@ def test_go_to_reference(self) -> None:
350350
references = str(lsp.get_references(circle_file, lspt.Position(line, char)))
351351
for expected in expected_refs:
352352
self.assertIn(expected, references)
353+
354+
def test_py_type__definition(self) -> None:
355+
"""Test that the go to definition is correct for pythoon imports."""
356+
lsp = JacLangServer()
357+
workspace_path = self.fixture_abs_path("")
358+
workspace = Workspace(workspace_path, lsp)
359+
lsp.lsp._workspace = workspace
360+
import_file = uris.from_fs_path(
361+
self.fixture_abs_path(
362+
"../../../../jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac"
363+
)
364+
)
365+
lsp.deep_check(import_file)
366+
positions = [
367+
(13, 29, "pygame_mock/color.py:0:0-2:4"),
368+
(3, 17, "/pygame_mock/__init__.py:0:0-0:0"),
369+
(14, 45, "pygame_mock/color.py:0:0-2:4"),
370+
(13, 77, "mock/constants.py:4:3-4:15"),
371+
(17, 28, "mock/display.py:0:0-1:7"),
372+
(15, 22, "/argparse.pyi:124:0-249:13"),
373+
(13, 74, "pygame_mock/constants.py:4:3-4:15"),
374+
(18, 17, "/stdlib/os/__init__.pyi:50:0-50:3"),
375+
]
376+
377+
for line, char, expected in positions:
378+
with self.subTest(line=line, char=char):
379+
self.assertIn(
380+
expected,
381+
str(lsp.get_definition(import_file, lspt.Position(line, char))),
382+
)
383+
384+
def test_py_type__references(self) -> None:
385+
"""Test that the go to definition is correct for pythoon imports."""
386+
lsp = JacLangServer()
387+
workspace_path = self.fixture_abs_path("")
388+
workspace = Workspace(workspace_path, lsp)
389+
lsp.lsp._workspace = workspace
390+
391+
circle_file = uris.from_fs_path(
392+
self.fixture_abs_path(
393+
"../../../../jaclang/compiler/passes/main/tests/fixtures/py_imp_test.jac"
394+
)
395+
)
396+
lsp.deep_check(circle_file)
397+
test_cases = [
398+
(
399+
12,
400+
15,
401+
[
402+
":12:13-12:18",
403+
"12:27-12:32",
404+
"13:26-13:31",
405+
"13:40-13:45",
406+
"14:26-14:31",
407+
"14:40-14:45",
408+
],
409+
),
410+
(13, 63, ["6:33-6:42", "7:23-7:32", "12:45-12:54", "13:58-13:67"]),
411+
(
412+
15,
413+
53,
414+
[
415+
"15:42-15:56",
416+
"15:16-15:30",
417+
"argparse.pyi:334:21-334:35",
418+
"argparse.pyi:163:29-163:43",
419+
"argparse.pyi:32:52-32:66",
420+
],
421+
),
422+
]
423+
for line, char, expected_refs in test_cases:
424+
references = str(lsp.get_references(circle_file, lspt.Position(line, char)))
425+
for expected in expected_refs:
426+
self.assertIn(expected, references)

0 commit comments

Comments
 (0)