Skip to content

Commit 2939fef

Browse files
committed
[ty] Ensure rename CursorTest calls can_rename before renaming
1 parent b8ecc83 commit 2939fef

File tree

1 file changed

+8
-26
lines changed

1 file changed

+8
-26
lines changed

crates/ty_ide/src/rename.rs

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ mod tests {
110110
}
111111

112112
fn rename(&self, new_name: &str) -> String {
113+
let Some(_) = can_rename(&self.db, self.cursor.file, self.cursor.offset) else {
114+
return "Cannot rename".to_string();
115+
};
116+
113117
let Some(rename_results) =
114118
rename(&self.db, self.cursor.file, self.cursor.offset, new_name)
115119
else {
@@ -1182,6 +1186,7 @@ result = func(10, y=20)
11821186
");
11831187
}
11841188

1189+
// TODO Should rename the alias
11851190
#[test]
11861191
fn import_alias() {
11871192
let test = CursorTest::builder()
@@ -1197,21 +1202,10 @@ result = func(10, y=20)
11971202
)
11981203
.build();
11991204

1200-
assert_snapshot!(test.rename("z"), @r"
1201-
info[rename]: Rename symbol (found 2 locations)
1202-
--> main.py:3:20
1203-
|
1204-
2 | import warnings
1205-
3 | import warnings as abc
1206-
| ^^^
1207-
4 |
1208-
5 | x = abc
1209-
| ---
1210-
6 | y = warnings
1211-
|
1212-
");
1205+
assert_snapshot!(test.rename("z"), @"Cannot rename");
12131206
}
12141207

1208+
// TODO Should rename the alias
12151209
#[test]
12161210
fn import_alias_use() {
12171211
let test = CursorTest::builder()
@@ -1227,18 +1221,6 @@ result = func(10, y=20)
12271221
)
12281222
.build();
12291223

1230-
assert_snapshot!(test.rename("z"), @r"
1231-
info[rename]: Rename symbol (found 2 locations)
1232-
--> main.py:3:20
1233-
|
1234-
2 | import warnings
1235-
3 | import warnings as abc
1236-
| ^^^
1237-
4 |
1238-
5 | x = abc
1239-
| ---
1240-
6 | y = warnings
1241-
|
1242-
");
1224+
assert_snapshot!(test.rename("z"), @"Cannot rename");
12431225
}
12441226
}

0 commit comments

Comments
 (0)