• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Completion tests for expressions.
2 use expect_test::{expect, Expect};
3 
4 use crate::tests::completion_list;
5 
check(ra_fixture: &str, expect: Expect)6 fn check(ra_fixture: &str, expect: Expect) {
7     let actual = completion_list(ra_fixture);
8     expect.assert_eq(&actual)
9 }
10 
11 #[test]
complete_dot_in_attr()12 fn complete_dot_in_attr() {
13     check(
14         r#"
15 //- proc_macros: identity
16 pub struct Foo;
17 impl Foo {
18     fn foo(&self) {}
19 }
20 
21 #[proc_macros::identity]
22 fn main() {
23     Foo.$0
24 }
25 "#,
26         expect![[r#"
27             me foo()  fn(&self)
28             sn box    Box::new(expr)
29             sn call   function(expr)
30             sn dbg    dbg!(expr)
31             sn dbgr   dbg!(&expr)
32             sn let    let
33             sn letm   let mut
34             sn match  match expr {}
35             sn ref    &expr
36             sn refm   &mut expr
37             sn unsafe unsafe {}
38         "#]],
39     )
40 }
41 
42 #[test]
complete_dot_in_attr2()43 fn complete_dot_in_attr2() {
44     check(
45         r#"
46 //- proc_macros: identity
47 pub struct Foo;
48 impl Foo {
49     fn foo(&self) {}
50 }
51 
52 #[proc_macros::identity]
53 fn main() {
54     Foo.f$0
55 }
56 "#,
57         expect![[r#"
58             me foo()  fn(&self)
59             sn box    Box::new(expr)
60             sn call   function(expr)
61             sn dbg    dbg!(expr)
62             sn dbgr   dbg!(&expr)
63             sn let    let
64             sn letm   let mut
65             sn match  match expr {}
66             sn ref    &expr
67             sn refm   &mut expr
68             sn unsafe unsafe {}
69         "#]],
70     )
71 }
72 
73 #[test]
complete_dot_in_attr_input()74 fn complete_dot_in_attr_input() {
75     check(
76         r#"
77 //- proc_macros: input_replace
78 pub struct Foo;
79 impl Foo {
80     fn foo(&self) {}
81 }
82 
83 #[proc_macros::input_replace(
84     fn surprise() {
85         Foo.$0
86     }
87 )]
88 fn main() {}
89 "#,
90         expect![[r#"
91             me foo()  fn(&self)
92             sn box    Box::new(expr)
93             sn call   function(expr)
94             sn dbg    dbg!(expr)
95             sn dbgr   dbg!(&expr)
96             sn let    let
97             sn letm   let mut
98             sn match  match expr {}
99             sn ref    &expr
100             sn refm   &mut expr
101             sn unsafe unsafe {}
102         "#]],
103     )
104 }
105 
106 #[test]
complete_dot_in_attr_input2()107 fn complete_dot_in_attr_input2() {
108     check(
109         r#"
110 //- proc_macros: input_replace
111 pub struct Foo;
112 impl Foo {
113     fn foo(&self) {}
114 }
115 
116 #[proc_macros::input_replace(
117     fn surprise() {
118         Foo.f$0
119     }
120 )]
121 fn main() {}
122 "#,
123         expect![[r#"
124             me foo()  fn(&self)
125             sn box    Box::new(expr)
126             sn call   function(expr)
127             sn dbg    dbg!(expr)
128             sn dbgr   dbg!(&expr)
129             sn let    let
130             sn letm   let mut
131             sn match  match expr {}
132             sn ref    &expr
133             sn refm   &mut expr
134             sn unsafe unsafe {}
135         "#]],
136     )
137 }
138 
139 #[test]
issue_13836_str()140 fn issue_13836_str() {
141     check(
142         r#"
143 //- proc_macros: shorten
144 fn main() {
145     let s = proc_macros::shorten!("text.$0");
146 }
147 "#,
148         expect![[r#""#]],
149     )
150 }
151 
152 #[test]
issue_13836_ident()153 fn issue_13836_ident() {
154     check(
155         r#"
156 //- proc_macros: shorten
157 struct S;
158 impl S {
159     fn foo(&self) {}
160 }
161 fn main() {
162     let s = proc_macros::shorten!(S.fo$0);
163 }
164 "#,
165         expect![[r#""#]],
166     )
167 }
168