]> git.lizzy.rs Git - rust.git/blob - crates/ide-completion/src/tests/item.rs
More precise completion filtering
[rust.git] / crates / ide-completion / src / tests / item.rs
1 //! Completion tests for item specifics overall.
2 //!
3 //! Except for use items which are tested in [super::use_tree] and mod declarations with are tested
4 //! in [crate::completions::mod_].
5 use expect_test::{expect, Expect};
6
7 use crate::tests::{completion_list, BASE_ITEMS_FIXTURE};
8
9 fn check(ra_fixture: &str, expect: Expect) {
10     let actual = completion_list(&format!("{}{}", BASE_ITEMS_FIXTURE, ra_fixture));
11     expect.assert_eq(&actual)
12 }
13
14 #[test]
15 fn target_type_or_trait_in_impl_block() {
16     check(
17         r#"
18 impl Tra$0
19 "#,
20         expect![[r#"
21             en Enum
22             ma makro!(…) macro_rules! makro
23             md module
24             st Record
25             st Tuple
26             st Unit
27             tt Trait
28             un Union
29             bt u32
30             kw crate::
31             kw self::
32             kw super::
33         "#]],
34     )
35 }
36
37 #[test]
38 fn target_type_in_trait_impl_block() {
39     check(
40         r#"
41 impl Trait for Str$0
42 "#,
43         expect![[r#"
44             en Enum
45             ma makro!(…) macro_rules! makro
46             md module
47             st Record
48             st Tuple
49             st Unit
50             tt Trait
51             un Union
52             bt u32
53             kw crate::
54             kw self::
55             kw super::
56         "#]],
57     )
58 }
59
60 #[test]
61 fn after_trait_name_in_trait_def() {
62     check(
63         r"trait A $0",
64         expect![[r#"
65             kw where
66         "#]],
67     );
68 }
69
70 #[test]
71 fn after_target_name_in_impl() {
72     check(
73         r"impl Trait $0",
74         expect![[r#"
75             kw for
76             kw where
77         "#]],
78     );
79     // FIXME: This should not emit `kw for`
80     check(
81         r"impl Trait for Type $0",
82         expect![[r#"
83             kw for
84             kw where
85         "#]],
86     );
87 }
88
89 #[test]
90 fn after_struct_name() {
91     // FIXME: This should emit `kw where` only
92     check(
93         r"struct Struct $0",
94         expect![[r#"
95             kw const
96             kw enum
97             kw extern
98             kw fn
99             kw impl
100             kw mod
101             kw pub
102             kw pub(crate)
103             kw pub(super)
104             kw static
105             kw struct
106             kw trait
107             kw type
108             kw union
109             kw unsafe
110             kw use
111         "#]],
112     );
113 }
114
115 #[test]
116 fn after_fn_name() {
117     // FIXME: This should emit `kw where` only
118     check(
119         r"fn func() $0",
120         expect![[r#"
121             kw const
122             kw enum
123             kw extern
124             kw fn
125             kw impl
126             kw mod
127             kw pub
128             kw pub(crate)
129             kw pub(super)
130             kw static
131             kw struct
132             kw trait
133             kw type
134             kw union
135             kw unsafe
136             kw use
137         "#]],
138     );
139 }
140
141 #[test]
142 fn before_record_field() {
143     check(
144         r#"
145 struct Foo {
146     $0
147     pub f: i32,
148 }
149 "#,
150         expect![[r#"
151             kw pub
152             kw pub(crate)
153             kw pub(super)
154         "#]],
155     )
156 }