From c848e8a7cadbb2a7156e6df891315a4dfe8c380a Mon Sep 17 00:00:00 2001 From: Michael Panchenko Date: Tue, 20 May 2025 01:41:15 +0200 Subject: [PATCH] Extended tests --- test/multilspy/php/test_php_basic.py | 21 +++----------------- test/resources/repos/php/test_repo/index.php | 4 ++++ test/serena/test_serena_agent.py | 19 +++++++++++++----- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/test/multilspy/php/test_php_basic.py b/test/multilspy/php/test_php_basic.py index 08cf73a..942281f 100644 --- a/test/multilspy/php/test_php_basic.py +++ b/test/multilspy/php/test_php_basic.py @@ -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)}" diff --git a/test/resources/repos/php/test_repo/index.php b/test/resources/repos/php/test_repo/index.php index 70d0d34..f8c4cda 100644 --- a/test/resources/repos/php/test_repo/index.php +++ b/test/resources/repos/php/test_repo/index.php @@ -13,4 +13,8 @@ echo $greeting; helperFunction(); +function useHelperFunction() { + helperFunction(); +} + ?> \ No newline at end of file diff --git a/test/serena/test_serena_agent.py b/test/serena/test_serena_agent.py index 03d660d..143bdfe 100644 --- a/test/serena/test_serena_agent.py +++ b/test/serena/test_serena_agent.py @@ -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"], )