Extended tests

This commit is contained in:
Michael Panchenko
2025-05-20 01:41:15 +02:00
parent ba51084fd9
commit c848e8a7ca
3 changed files with 21 additions and 23 deletions
+3 -18
View File
@@ -109,11 +109,11 @@ class TestPhpLanguageServer:
@pytest.mark.parametrize("language_server", [Language.PHP], indirect=True)
@pytest.mark.parametrize("repo_path", [Language.PHP], indirect=True)
def test_find_references_across_files(self, language_server: SyncLanguageServer, repo_path: Path) -> None:
index_php_path = str(repo_path / "index.php")
helper_php_path = str(repo_path / "helper.php")
# In index.php (0-indexed lines):
# Line 13: helperFunction(); // Usage of helperFunction
# Find references for helperFunction from its usage (line 13, char 0 for 'h')
references = language_server.request_references(index_php_path, 13, 0)
# Find references for helperFunction from its definition
references = language_server.request_references(helper_php_path, 2, len("function "))
assert references, f"Expected non-empty references for helperFunction but got {references=}"
# Intelephense might return 1 (usage) or 2 (usage + definition) references.
@@ -132,19 +132,4 @@ class TestPhpLanguageServer:
)
usage_in_index_php = {"uri_suffix": "index.php", "line": 13, "character": 0}
definition_in_helper_php = {"uri_suffix": "helper.php", "line": 2, "character": 0}
assert usage_in_index_php in actual_locations_comparable, "Usage of helperFunction in index.php not found"
# Depending on Intelephense's behavior, it might also include the definition.
# For now, we are flexible: it must find the usage. If it finds more, that's also okay.
# If we want to be strict about finding both or only one, this part would need adjustment.
if len(references) == 2:
assert (
definition_in_helper_php in actual_locations_comparable
), "Definition of helperFunction in helper.php expected but not found when 2 references returned"
elif len(references) == 1:
# If only one reference, ensure it's the usage we definitely expect
assert actual_locations_comparable[0] == usage_in_index_php
else:
assert False, f"Expected 1 or 2 references, but got {len(references)}"
@@ -13,4 +13,8 @@ echo $greeting;
helperFunction();
function useHelperFunction() {
helperFunction();
}
?>
+14 -5
View File
@@ -31,6 +31,7 @@ class TestSerenaAgent:
pytest.param(Language.JAVA, "Model", "Class", "Model.java", marks=pytest.mark.java),
pytest.param(Language.RUST, "add", "Function", "lib.rs", marks=pytest.mark.rust),
pytest.param(Language.TYPESCRIPT, "DemoClass", "Class", "index.ts", marks=pytest.mark.typescript),
pytest.param(Language.PHP, "helperFunction", "Function", "helper.php", marks=pytest.mark.php),
],
indirect=["serena_agent"],
)
@@ -47,16 +48,24 @@ class TestSerenaAgent:
@pytest.mark.parametrize(
"serena_agent,symbol_name,def_file,ref_file",
[
(Language.PYTHON, "User", os.path.join("test_repo", "models.py"), os.path.join("test_repo", "services.py")),
(Language.GO, "Helper", "main.go", "main.go"),
(
pytest.param(
Language.PYTHON,
"User",
os.path.join("test_repo", "models.py"),
os.path.join("test_repo", "services.py"),
marks=pytest.mark.python,
),
pytest.param(Language.GO, "Helper", "main.go", "main.go", marks=pytest.mark.go),
pytest.param(
Language.JAVA,
"Model",
os.path.join("src", "main", "java", "test_repo", "Model.java"),
os.path.join("src", "main", "java", "test_repo", "Main.java"),
marks=pytest.mark.java,
),
(Language.RUST, "add", os.path.join("src", "lib.rs"), os.path.join("src", "main.rs")),
(Language.TYPESCRIPT, "helperFunction", "index.ts", "use_helper.ts"),
pytest.param(Language.RUST, "add", os.path.join("src", "lib.rs"), os.path.join("src", "main.rs"), marks=pytest.mark.rust),
pytest.param(Language.TYPESCRIPT, "helperFunction", "index.ts", "use_helper.ts", marks=pytest.mark.typescript),
pytest.param(Language.PHP, "helperFunction", "helper.php", "index.php", marks=pytest.mark.php),
],
indirect=["serena_agent"],
)