mirror of https://github.com/astral-sh/ruff
[ty] Ensure `rename` `CursorTest` calls `can_rename` before renaming (#21790)
This commit is contained in:
parent
b8ecc83a54
commit
3aefe85b32
|
|
@ -110,6 +110,10 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn rename(&self, new_name: &str) -> String {
|
fn rename(&self, new_name: &str) -> String {
|
||||||
|
let Some(_) = can_rename(&self.db, self.cursor.file, self.cursor.offset) else {
|
||||||
|
return "Cannot rename".to_string();
|
||||||
|
};
|
||||||
|
|
||||||
let Some(rename_results) =
|
let Some(rename_results) =
|
||||||
rename(&self.db, self.cursor.file, self.cursor.offset, new_name)
|
rename(&self.db, self.cursor.file, self.cursor.offset, new_name)
|
||||||
else {
|
else {
|
||||||
|
|
@ -1182,6 +1186,7 @@ result = func(10, y=20)
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Should rename the alias
|
||||||
#[test]
|
#[test]
|
||||||
fn import_alias() {
|
fn import_alias() {
|
||||||
let test = CursorTest::builder()
|
let test = CursorTest::builder()
|
||||||
|
|
@ -1197,21 +1202,10 @@ result = func(10, y=20)
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assert_snapshot!(test.rename("z"), @r"
|
assert_snapshot!(test.rename("z"), @"Cannot rename");
|
||||||
info[rename]: Rename symbol (found 2 locations)
|
|
||||||
--> main.py:3:20
|
|
||||||
|
|
|
||||||
2 | import warnings
|
|
||||||
3 | import warnings as abc
|
|
||||||
| ^^^
|
|
||||||
4 |
|
|
||||||
5 | x = abc
|
|
||||||
| ---
|
|
||||||
6 | y = warnings
|
|
||||||
|
|
|
||||||
");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Should rename the alias
|
||||||
#[test]
|
#[test]
|
||||||
fn import_alias_use() {
|
fn import_alias_use() {
|
||||||
let test = CursorTest::builder()
|
let test = CursorTest::builder()
|
||||||
|
|
@ -1227,18 +1221,6 @@ result = func(10, y=20)
|
||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
assert_snapshot!(test.rename("z"), @r"
|
assert_snapshot!(test.rename("z"), @"Cannot rename");
|
||||||
info[rename]: Rename symbol (found 2 locations)
|
|
||||||
--> main.py:3:20
|
|
||||||
|
|
|
||||||
2 | import warnings
|
|
||||||
3 | import warnings as abc
|
|
||||||
| ^^^
|
|
||||||
4 |
|
|
||||||
5 | x = abc
|
|
||||||
| ---
|
|
||||||
6 | y = warnings
|
|
||||||
|
|
|
||||||
");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue