Skip to content

Commit a1b67d6

Browse files
adapt test
1 parent 08043e9 commit a1b67d6

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

tests/lsp/test_document_highlight.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,6 @@ def test_get_document_highlights_multiple_ctes():
106106
)
107107
highlights = get_document_highlights(lsp_context, test_uri, position)
108108

109+
# This should return the column usages as well
109110
assert highlights is not None
110-
assert len(highlights) == len(inner_ranges) # Should match all occurrences of inner CTE only
111+
assert len(highlights) == 4

tests/lsp/test_rename_cte.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def test_rename_cte():
119119
assert uri in workspace_edit.changes
120120

121121
edits = workspace_edit.changes[uri]
122-
assert len(edits) == 2 # Should have 2 edits: definition + usage
122+
123+
# Should have edited four occurences including column usages
124+
assert len(edits) == 4
123125

124126
# Verify that both ranges are being edited
125127
edit_ranges = [edit.range for edit in edits]
@@ -135,6 +137,33 @@ def test_rename_cte():
135137
# Verify that all edits have the new name
136138
assert all(edit.new_text == "new_marketing" for edit in edits)
137139

140+
# Apply the edits to verify the result
141+
with open(sushi_customers_path, "r", encoding="utf-8") as file:
142+
lines = file.readlines()
143+
144+
# Apply edits in reverse order to avoid offset issues
145+
sorted_edits = sorted(
146+
edits, key=lambda e: (e.range.start.line, e.range.start.character), reverse=True
147+
)
148+
for edit in sorted_edits:
149+
line_idx = edit.range.start.line
150+
start_char = edit.range.start.character
151+
end_char = edit.range.end.character
152+
153+
line = lines[line_idx]
154+
new_line = line[:start_char] + edit.new_text + line[end_char:]
155+
lines[line_idx] = new_line
156+
157+
# Verify the edited content
158+
edited_content = "".join(lines)
159+
assert "new_marketing" in edited_content
160+
assert "current_marketing" not in edited_content.replace("current_marketing_outer", "")
161+
assert edited_content.count("new_marketing") == 4
162+
assert (
163+
" SELECT new_marketing.* FROM new_marketing WHERE new_marketing.customer_id != 100\n"
164+
in lines
165+
)
166+
138167

139168
def test_rename_cte_outer():
140169
context = Context(paths=["examples/sushi"])

0 commit comments

Comments
 (0)