Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/tests/expression.rs')
| -rw-r--r-- | crates/ide-completion/src/tests/expression.rs | 252 |
1 files changed, 203 insertions, 49 deletions
diff --git a/crates/ide-completion/src/tests/expression.rs b/crates/ide-completion/src/tests/expression.rs index be5b7f8a34..b4f936b35a 100644 --- a/crates/ide-completion/src/tests/expression.rs +++ b/crates/ide-completion/src/tests/expression.rs @@ -26,22 +26,22 @@ fn baz() { "#, // This should not contain `FooDesc {…}`. expect![[r#" - ct CONST - en Enum + ct CONST Unit + en Enum Enum fn baz() fn() fn create_foo(…) fn(&FooDesc) fn function() fn() ma makro!(…) macro_rules! makro md _69latrick md module - sc STATIC - st FooDesc - st Record - st Tuple - st Unit - un Union + sc STATIC Unit + st FooDesc FooDesc + st Record Record + st Tuple Tuple + st Unit Unit + un Union Union ev TupleV(…) TupleV(u32) - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -83,7 +83,7 @@ fn func(param0 @ (param1, param2): (i32, i32)) { lc param0 (i32, i32) lc param1 i32 lc param2 i32 - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -117,24 +117,24 @@ impl Unit { "#, // `self` is in here twice, once as the module, once as the local expect![[r#" - ct CONST + ct CONST Unit cp CONST_PARAM - en Enum + en Enum Enum fn function() fn() fn local_func() fn() lc self Unit ma makro!(…) macro_rules! makro md module md qualified - sp Self - sc STATIC - st Record - st Tuple - st Unit + sp Self Unit + sc STATIC Unit + st Record Record + st Tuple Tuple + st Unit Unit tp TypeParam - un Union + un Union Union ev TupleV(…) TupleV(u32) - bt u32 + bt u32 u32 kw const kw crate:: kw enum @@ -181,18 +181,18 @@ impl Unit { } "#, expect![[r#" - ct CONST - en Enum + ct CONST Unit + en Enum Enum fn function() fn() ma makro!(…) macro_rules! makro md module md qualified - sc STATIC - st Record - st Tuple - st Unit + sc STATIC Unit + st Record Record + st Tuple Tuple + st Unit Unit tt Trait - un Union + un Union Union ev TupleV(…) TupleV(u32) ?? Unresolved "#]], @@ -211,7 +211,7 @@ fn complete_in_block() { "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw enum @@ -256,7 +256,7 @@ fn complete_after_if_expr() { "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -304,7 +304,7 @@ fn complete_in_match_arm() { "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -328,7 +328,7 @@ fn completes_in_loop_ctx() { r"fn my() { loop { $0 } }", expect![[r#" fn my() fn() - bt u32 + bt u32 u32 kw break kw const kw continue @@ -370,7 +370,7 @@ fn completes_in_let_initializer() { r#"fn main() { let _ = $0 }"#, expect![[r#" fn main() fn() - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -403,8 +403,8 @@ fn foo() { "#, expect![[r#" fn foo() fn() - st Foo - bt u32 + st Foo Foo + bt u32 u32 kw crate:: kw false kw for @@ -439,7 +439,7 @@ fn foo() { expect![[r#" fn foo() fn() lc bar i32 - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -470,7 +470,7 @@ fn quux(x: i32) { fn quux(…) fn(i32) lc x i32 ma m!(…) macro_rules! m - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -497,7 +497,7 @@ fn quux(x: i32) { fn quux(…) fn(i32) lc x i32 ma m!(…) macro_rules! m - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -683,11 +683,11 @@ fn brr() { } "#, expect![[r#" - en HH + en HH HH fn brr() fn() - st YoloVariant + st YoloVariant YoloVariant st YoloVariant {…} YoloVariant { f: usize } - bt u32 + bt u32 u32 kw crate:: kw false kw for @@ -749,7 +749,7 @@ fn foo() { if foo {} $0 } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -789,7 +789,7 @@ fn foo() { if foo {} el$0 } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -829,7 +829,7 @@ fn foo() { bar(if foo {} $0) } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw crate:: kw else kw else if @@ -853,7 +853,7 @@ fn foo() { bar(if foo {} el$0) } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw crate:: kw else kw else if @@ -877,7 +877,7 @@ fn foo() { if foo {} $0 let x = 92; } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -917,7 +917,7 @@ fn foo() { if foo {} el$0 let x = 92; } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -957,7 +957,7 @@ fn foo() { if foo {} el$0 { let x = 92; } } "#, expect![[r#" fn foo() fn() - bt u32 + bt u32 u32 kw const kw crate:: kw else @@ -1009,7 +1009,7 @@ pub struct UnstableThisShouldNotBeListed; expect![[r#" fn main() fn() md std - bt u32 + bt u32 u32 kw const kw crate:: kw enum @@ -1060,8 +1060,8 @@ pub struct UnstableButWeAreOnNightlyAnyway; expect![[r#" fn main() fn() md std - st UnstableButWeAreOnNightlyAnyway - bt u32 + st UnstableButWeAreOnNightlyAnyway UnstableButWeAreOnNightlyAnyway + bt u32 u32 kw const kw crate:: kw enum @@ -1094,3 +1094,157 @@ pub struct UnstableButWeAreOnNightlyAnyway; "#]], ); } + +#[test] +fn inside_format_args_completions_work() { + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("{}", Foo.$0); +} +"#, + expect![[r#" + me foo() fn(&self) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("{}", Foo.f$0); +} +"#, + expect![[r#" + me foo() fn(&self) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); +} + +#[test] +fn inside_faulty_format_args_completions_work() { + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("", Foo.$0); +} +"#, + expect![[r#" + me foo() fn(&self) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("", Foo.f$0); +} +"#, + expect![[r#" + me foo() fn(&self) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("{} {named} {captured} {named} {}", a, named = c, Foo.f$0); +} +"#, + expect![[r#" + me foo() fn(&self) + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn match match expr {} + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + "#]], + ); + check_empty( + r#" +//- minicore: fmt +struct Foo; +impl Foo { + fn foo(&self) {} +} + +fn main() { + format_args!("{", Foo.f$0); +} +"#, + expect![[r#" + sn box Box::new(expr) + sn call function(expr) + sn dbg dbg!(expr) + sn dbgr dbg!(&expr) + sn if if expr {} + sn match match expr {} + sn not !expr + sn ref &expr + sn refm &mut expr + sn unsafe unsafe {} + sn while while expr {} + "#]], + ); +} |