Skip to content

Commit e357886

Browse files
committed
temp
[ci skip]
1 parent 05ddba1 commit e357886

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

tests/lsp/test_reference_cte.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#!/usr/bin/env python3
2-
"""Test script for CTE go-to-definition functionality."""
3-
41
import re
52
from sqlmesh.core.context import Context
63
from sqlmesh.lsp.context import LSPContext, ModelTarget
74
from sqlmesh.lsp.reference import get_references
85
from sqlmesh.lsp.uri import URI
96
from lsprotocol.types import Range, Position
7+
import typing as t
8+
109

1110
def test_cte_parsing():
1211
context = Context(paths=["examples/sushi"])
@@ -22,29 +21,41 @@ def test_cte_parsing():
2221
with open(sushi_customers_path, "r", encoding="utf-8") as file:
2322
read_file = file.readlines()
2423

25-
references = get_references(lsp_context, URI.from_path(sushi_customers_path), Position(line=0, character=0))
24+
# Find position of the cte reference
25+
ranges = find_ranges_from_regex(
26+
read_file,
27+
r"current_marketing"
28+
)
29+
assert len(ranges) == 2
30+
# Middle of the second range
31+
position = Position(line=ranges[1].start.line, character=ranges[1].start.character + 4)
32+
33+
references = get_references(
34+
lsp_context, URI.from_path(sushi_customers_path), position
35+
)
2636

2737
assert len(references) == 1
2838
assert references[0].uri == URI.from_path(sushi_customers_path)
39+
assert references[0].description is None
2940

30-
ranges = find_ranges_from_regex(read_file, r"WITH\s+current_marketing\s+AS\s+\(SELECT\s+customer_id,\s+status\s+FROM\s+sushi\.marketing\s+WHERE\s+valid_to\s+is\s+null\)")
41+
ranges = find_ranges_from_regex(
42+
read_file,
43+
r"WITH\s+current_marketing\s+AS\s+\(SELECT\s+customer_id,\s+status\s+FROM\s+sushi\.marketing\s+WHERE\s+valid_to\s+is\s+null\)",
44+
)
3145
assert len(ranges) == 1
3246
assert ranges[0].start == Position(line=1, character=0)
3347
assert ranges[0].end == Position(line=1, character=1)
3448

35-
36-
49+
assert references[0].range == ranges[0]
3750

3851

3952
def find_ranges_from_regex(read_file: t.List[str], regex: str) -> t.List[Range]:
4053
"""Find all ranges in the read file that match the regex."""
4154
return [
4255
Range(
4356
start=Position(line=line_number, character=match.start()),
44-
end=Position(line=line_number, character=match.end())
57+
end=Position(line=line_number, character=match.end()),
4558
)
4659
for line_number, line in enumerate(read_file)
4760
for match in [m for m in [re.search(regex, line)] if m]
4861
]
49-
50-

0 commit comments

Comments
 (0)