@@ -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
139168def test_rename_cte_outer ():
140169 context = Context (paths = ["examples/sushi" ])
0 commit comments