Skip to content

Commit b9536f0

Browse files
committed
add tests for finding references
1 parent 77bc3a9 commit b9536f0

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

tests/robotcode/language_server/robotframework/parts/data/document_highlight.robot

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ Test Setup Log To Console hi from test setup
1717

1818
*** Variables ***
1919
${a var} hello
20+
#^^^^^^^ simple variable
2021
${LIB_ARG} from lib
22+
#^^^^^^^ another simple var
2123

2224

2325
*** Test Cases ***
@@ -33,6 +35,8 @@ first
3335
BuiltIn.Log To Console hi ${a var}
3436
# ^^^^^^^^^^^^^^ multiple references with namespace
3537
# ^^^^^ multiple variables
38+
Log ${A_VAR_FROM_RESOURE}
39+
# ^^^^^^^^^^^^^^^^^^^^^ a var from resource
3640

3741
second
3842
[Template] Log To Console
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
*** Settings ***
2+
Library Collections
3+
# ^^^^^^^^^^^ a built library
4+
Library ${CURDIR}/lib/myvariables.py
5+
# ^^^^^^^^^ Variable in library import path
6+
# ^^^^^^^^^^^^^^ a custom library with path
7+
Variables ${CURDIR}/lib/myvariables.py
8+
# ^^^^^^^^^ Variable in variables import path
9+
# ^^^^^^^^^^^^^^ a variable import
10+
Resource ${CURDIR}/resources/firstresource.resource
11+
# ^^^^^^^^^ Variable in resource import path
12+
Library alibrary a_param=from hello WITH NAME lib_hello
13+
# ^^^^^^^^ a custom library
14+
Library alibrary a_param=${LIB_ARG} WITH NAME lib_var
15+
# ^^^^^^^^^^ Variable in library params
16+
# ^^^^^^^^ a same custom library
17+
Suite Setup BuiltIn.Log To Console hi from suite setup
18+
# ^^^^^^^^^^^^^^ suite fixture keyword call with namespace
19+
Test Setup Log To Console hi from test setup
20+
# ^^^^^^^^^^^^^^ test fixture keyword call with namespace
21+
22+
*** Variables ***
23+
${a var} hello
24+
#^^^^^^^ simple variable
25+
${LIB_ARG} from lib
26+
#^^^^^^^ another simple var
27+
28+
29+
*** Test Cases ***
30+
first
31+
[Setup] Log To Console hi ${a var}
32+
# ^^^^^^^^^^^^^^ fixture keyword call
33+
[Teardown] BuiltIn.Log To Console hi ${a var}
34+
# ^^^^^^^^^^^^^^ fixture keyword call with namespace
35+
Log Hi ${a var}
36+
# ^^^ simple keyword call
37+
Log To Console hi ${a var}
38+
# ^^^^^^^^^^^^^^ multiple references
39+
BuiltIn.Log To Console hi ${a var}
40+
# ^^^^^^^^^^^^^^ multiple references with namespace
41+
# ^^^^^ multiple variables
42+
Log ${A_VAR_FROM_RESOURE}
43+
# ^^^^^^^^^^^^^^^^^^^^^ a var from resource
44+
45+
second
46+
[Template] Log To Console
47+
# ^^^^^^^^^^^^^^ template keyword
48+
Hi
49+
There
50+
51+
third
52+
[Template] BuiltIn.Log To Console
53+
# ^^^^^^^^^^^^^^ template keyword with namespace
54+
Hi
55+
There
56+
57+
forth
58+
${result} lib_hello.A Library Keyword
59+
# ^^^^^^^^^ Keyword assignement
60+
Should Be Equal ${result} from hello
61+
${result}= lib_var.A Library Keyword
62+
# ^^^^^^^^^ Keyword assignment with equals sign
63+
Should Be Equal ${result} ${LIB_ARG}

tests/robotcode/language_server/robotframework/parts/data/resources/firstresource.resource

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
*** Variables ***
2+
${A_VAR_FROM_RESOURE} hello from resource
3+
14
*** Keywords ***
25

36
do something in a resource
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from pathlib import Path
2+
from typing import Optional
3+
4+
import pytest
5+
from pytest_regressions.data_regression import DataRegressionFixture
6+
7+
from robotcode.language_server.common.lsp_types import (
8+
Location,
9+
Position,
10+
ReferenceContext,
11+
)
12+
from robotcode.language_server.common.text_document import TextDocument
13+
from robotcode.language_server.robotframework.protocol import (
14+
RobotLanguageServerProtocol,
15+
)
16+
17+
from ..tools import (
18+
GeneratedTestData,
19+
generate_test_id,
20+
generate_tests_from_source_document,
21+
)
22+
23+
24+
@pytest.mark.parametrize(
25+
("test_document", "data"),
26+
generate_tests_from_source_document(Path(Path(__file__).parent, "data/references.robot")),
27+
indirect=["test_document"],
28+
ids=generate_test_id,
29+
)
30+
@pytest.mark.usefixtures("protocol")
31+
@pytest.mark.asyncio
32+
async def test(
33+
data_regression: DataRegressionFixture,
34+
protocol: RobotLanguageServerProtocol,
35+
test_document: TextDocument,
36+
data: GeneratedTestData,
37+
) -> None:
38+
def split(location: Optional[Location]) -> Optional[Location]:
39+
if location is None:
40+
return None
41+
42+
return Location(location.uri, location.range)
43+
44+
result = await protocol.robot_references.collect(
45+
protocol.robot_document_highlight,
46+
test_document,
47+
Position(line=data.line, character=data.character),
48+
ReferenceContext(include_declaration=True),
49+
)
50+
data_regression.check({"data": data, "result": [split(v) for v in result] if result else result})

0 commit comments

Comments
 (0)