• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //! Completion tests for predicates and bounds.
2 use expect_test::{expect, Expect};
3 
4 use crate::tests::{check_empty, completion_list, BASE_ITEMS_FIXTURE};
5 
check(ra_fixture: &str, expect: Expect)6 fn check(ra_fixture: &str, expect: Expect) {
7     let actual = completion_list(&format!("{BASE_ITEMS_FIXTURE}\n{ra_fixture}"));
8     expect.assert_eq(&actual)
9 }
10 
11 #[test]
predicate_start()12 fn predicate_start() {
13     // FIXME: `for` kw
14     check(
15         r#"
16 struct Foo<'lt, T, const C: usize> where $0 {}
17 "#,
18         expect![[r#"
19             en Enum
20             ma makro!(…) macro_rules! makro
21             md module
22             st Foo<…>
23             st Record
24             st Tuple
25             st Unit
26             tt Trait
27             un Union
28             bt u32
29             kw crate::
30             kw self::
31         "#]],
32     );
33 }
34 
35 #[test]
bound_for_type_pred()36 fn bound_for_type_pred() {
37     check(
38         r#"
39 struct Foo<'lt, T, const C: usize> where T: $0 {}
40 "#,
41         expect![[r#"
42             ma makro!(…) macro_rules! makro
43             md module
44             tt Trait
45             kw crate::
46             kw self::
47         "#]],
48     );
49 }
50 
51 #[test]
bound_for_lifetime_pred()52 fn bound_for_lifetime_pred() {
53     // FIXME: should only show lifetimes here, that is we shouldn't get any completions here when not typing
54     // a `'`
55     check(
56         r#"
57 struct Foo<'lt, T, const C: usize> where 'lt: $0 {}
58 "#,
59         expect![[r#"
60             ma makro!(…) macro_rules! makro
61             md module
62             tt Trait
63             kw crate::
64             kw self::
65         "#]],
66     );
67 }
68 
69 #[test]
bound_for_for_pred()70 fn bound_for_for_pred() {
71     check(
72         r#"
73 struct Foo<'lt, T, const C: usize> where for<'a> T: $0 {}
74 "#,
75         expect![[r#"
76             ma makro!(…) macro_rules! makro
77             md module
78             tt Trait
79             kw crate::
80             kw self::
81         "#]],
82     );
83 }
84 
85 #[test]
param_list_for_for_pred()86 fn param_list_for_for_pred() {
87     check(
88         r#"
89 struct Foo<'lt, T, const C: usize> where for<'a> $0 {}
90 "#,
91         expect![[r#"
92             en Enum
93             ma makro!(…) macro_rules! makro
94             md module
95             st Foo<…>
96             st Record
97             st Tuple
98             st Unit
99             tt Trait
100             un Union
101             bt u32
102             kw crate::
103             kw self::
104         "#]],
105     );
106 }
107 
108 #[test]
pred_on_fn_in_impl()109 fn pred_on_fn_in_impl() {
110     check(
111         r#"
112 impl Record {
113     fn method(self) where $0 {}
114 }
115 "#,
116         expect![[r#"
117             en Enum
118             ma makro!(…) macro_rules! makro
119             md module
120             sp Self
121             st Record
122             st Tuple
123             st Unit
124             tt Trait
125             un Union
126             bt u32
127             kw crate::
128             kw self::
129         "#]],
130     );
131 }
132 
133 #[test]
pred_no_unstable_item_on_stable()134 fn pred_no_unstable_item_on_stable() {
135     check_empty(
136         r#"
137 //- /main.rs crate:main deps:std
138 use std::*;
139 struct Foo<T> where T: $0 {}
140 //- /std.rs crate:std
141 #[unstable]
142 pub trait Trait {}
143 "#,
144         expect![[r#"
145             md std
146             kw crate::
147             kw self::
148         "#]],
149     );
150 }
151 
152 #[test]
pred_unstable_item_on_nightly()153 fn pred_unstable_item_on_nightly() {
154     check_empty(
155         r#"
156 //- toolchain:nightly
157 //- /main.rs crate:main deps:std
158 use std::*;
159 struct Foo<T> where T: $0 {}
160 //- /std.rs crate:std
161 #[unstable]
162 pub trait Trait {}
163 "#,
164         expect![[r#"
165             md std
166             tt Trait
167             kw crate::
168             kw self::
169         "#]],
170     );
171 }
172