aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src/tests')
-rw-r--r--crates/ide_completion/src/tests/items.rs32
-rw-r--r--crates/ide_completion/src/tests/type_pos.rs185
2 files changed, 185 insertions, 32 deletions
diff --git a/crates/ide_completion/src/tests/items.rs b/crates/ide_completion/src/tests/items.rs
index 8dfb8221b..b98baffd6 100644
--- a/crates/ide_completion/src/tests/items.rs
+++ b/crates/ide_completion/src/tests/items.rs
@@ -35,22 +35,6 @@ impl Tra$0
35 ma foo!(…) #[macro_export] macro_rules! foo 35 ma foo!(…) #[macro_export] macro_rules! foo
36 ma foo!(…) #[macro_export] macro_rules! foo 36 ma foo!(…) #[macro_export] macro_rules! foo
37 bt u32 37 bt u32
38 bt bool
39 bt u8
40 bt isize
41 bt u16
42 bt u64
43 bt u128
44 bt f32
45 bt i128
46 bt i16
47 bt str
48 bt i64
49 bt char
50 bt f64
51 bt i32
52 bt i8
53 bt usize
54 "##]], 38 "##]],
55 ) 39 )
56} 40}
@@ -69,22 +53,6 @@ impl Trait for Str$0
69 ma foo!(…) #[macro_export] macro_rules! foo 53 ma foo!(…) #[macro_export] macro_rules! foo
70 ma foo!(…) #[macro_export] macro_rules! foo 54 ma foo!(…) #[macro_export] macro_rules! foo
71 bt u32 55 bt u32
72 bt bool
73 bt u8
74 bt isize
75 bt u16
76 bt u64
77 bt u128
78 bt f32
79 bt i128
80 bt i16
81 bt str
82 bt i64
83 bt char
84 bt f64
85 bt i32
86 bt i8
87 bt usize
88 "##]], 56 "##]],
89 ) 57 )
90} 58}
diff --git a/crates/ide_completion/src/tests/type_pos.rs b/crates/ide_completion/src/tests/type_pos.rs
new file mode 100644
index 000000000..2bfecdd08
--- /dev/null
+++ b/crates/ide_completion/src/tests/type_pos.rs
@@ -0,0 +1,185 @@
1//! Completions tests for type position.
2use expect_test::{expect, Expect};
3
4use crate::tests::completion_list;
5
6fn check_with(ra_fixture: &str, expect: Expect) {
7 let base = r#"
8enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
9use self::Enum::TupleV;
10mod module {}
11
12trait Trait {}
13static STATIC: Unit = Unit;
14const CONST: Unit = Unit;
15struct Record { field: u32 }
16struct Tuple(u32);
17struct Unit
18macro_rules! makro {}
19"#;
20 let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
21 expect.assert_eq(&actual)
22}
23
24#[test]
25fn record_field_ty() {
26 // FIXME: pub shouldnt show up here
27 check_with(
28 r#"
29struct Foo<'lt, T, const C: usize> {
30 f: $0
31}
32"#,
33 expect![[r#"
34 kw pub(crate)
35 kw pub
36 sp Self
37 tp T
38 tt Trait
39 en Enum
40 st Record
41 st Tuple
42 md module
43 st Foo<…>
44 st Unit
45 ma makro!(…) macro_rules! makro
46 bt u32
47 "#]],
48 )
49}
50
51#[test]
52fn tuple_struct_field() {
53 // FIXME: pub should show up here
54 check_with(
55 r#"
56struct Foo<'lt, T, const C: usize>(f$0);
57"#,
58 expect![[r#"
59 sp Self
60 tp T
61 tt Trait
62 en Enum
63 st Record
64 st Tuple
65 md module
66 st Foo<…>
67 st Unit
68 ma makro!(…) macro_rules! makro
69 bt u32
70 "#]],
71 )
72}
73
74#[test]
75fn fn_return_type() {
76 // FIXME: return shouldnt show up here
77 check_with(
78 r#"
79fn x<'lt, T, const C: usize>() -> $0
80"#,
81 expect![[r#"
82 kw return
83 tp T
84 tt Trait
85 en Enum
86 st Record
87 st Tuple
88 md module
89 st Unit
90 ma makro!(…) macro_rules! makro
91 bt u32
92 "#]],
93 );
94}
95
96#[test]
97fn body_type_pos() {
98 // FIXME: return shouldnt show up here
99 check_with(
100 r#"
101fn foo<'lt, T, const C: usize>() {
102 let local = ();
103 let _: $0;
104}
105"#,
106 expect![[r#"
107 kw return
108 tp T
109 tt Trait
110 en Enum
111 st Record
112 st Tuple
113 md module
114 st Unit
115 ma makro!(…) macro_rules! makro
116 bt u32
117 "#]],
118 );
119 check_with(
120 r#"
121fn foo<'lt, T, const C: usize>() {
122 let local = ();
123 let _: self::$0;
124}
125"#,
126 expect![[r#"
127 tt Trait
128 en Enum
129 st Record
130 st Tuple
131 md module
132 st Unit
133 "#]],
134 );
135}
136
137#[test]
138fn completes_types_and_const_in_arg_list() {
139 // FIXME: return shouldnt show up here
140 // FIXME: we should complete the lifetime here for now
141 check_with(
142 r#"
143trait Trait2 {
144 type Foo;
145}
146
147fn foo<'lt, T: Trait2<$0>, const CONST_PARAM: usize>(_: T) {}
148"#,
149 expect![[r#"
150 kw return
151 ta Foo = type Foo;
152 tp T
153 cp CONST_PARAM
154 tt Trait
155 en Enum
156 st Record
157 st Tuple
158 tt Trait2
159 md module
160 st Unit
161 ct CONST
162 ma makro!(…) macro_rules! makro
163 bt u32
164 "#]],
165 );
166 check_with(
167 r#"
168trait Trait2 {
169 type Foo;
170}
171
172fn foo<'lt, T: Trait2<self::$0>, const CONST_PARAM: usize>(_: T) {}
173 "#,
174 expect![[r#"
175 tt Trait
176 en Enum
177 st Record
178 st Tuple
179 tt Trait2
180 md module
181 st Unit
182 ct CONST
183 "#]],
184 );
185}