mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +00:00
[ty] Add some "inside string" tests for object.<CURSOR>
completions
Ref https://github.com/astral-sh/ruff/pull/18629#pullrequestreview-2919922754
This commit is contained in:
parent
324e5cbc19
commit
8123dab05a
1 changed files with 50 additions and 0 deletions
|
@ -1786,6 +1786,56 @@ def _():
|
||||||
assert_snapshot!(test.completions(), @"<No completions found>");
|
assert_snapshot!(test.completions(), @"<No completions found>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_dot_attr1() {
|
||||||
|
let test = cursor_test(
|
||||||
|
r#"
|
||||||
|
foo = 1
|
||||||
|
bar = 2
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
def method(self): ...
|
||||||
|
|
||||||
|
f = Foo()
|
||||||
|
|
||||||
|
# String, this is not an attribute access
|
||||||
|
"f.<CURSOR>
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
// TODO: This should not have any completions suggested for it.
|
||||||
|
// We do correctly avoid giving `object.attr` completions here,
|
||||||
|
// but we instead fall back to scope based completions. Since
|
||||||
|
// we're inside a string, we should avoid giving completions at
|
||||||
|
// all.
|
||||||
|
assert_snapshot!(test.completions(), @r"
|
||||||
|
Foo
|
||||||
|
bar
|
||||||
|
f
|
||||||
|
foo
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn string_dot_attr2() {
|
||||||
|
let test = cursor_test(
|
||||||
|
r#"
|
||||||
|
foo = 1
|
||||||
|
bar = 2
|
||||||
|
|
||||||
|
class Foo:
|
||||||
|
def method(self): ...
|
||||||
|
|
||||||
|
f = Foo()
|
||||||
|
|
||||||
|
# F-string, this is an attribute access
|
||||||
|
f"{f.<CURSOR>
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
test.assert_completions_include("method");
|
||||||
|
}
|
||||||
|
|
||||||
impl CursorTest {
|
impl CursorTest {
|
||||||
fn completions(&self) -> String {
|
fn completions(&self) -> String {
|
||||||
self.completions_if(|_| true)
|
self.completions_if(|_| true)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue