Skip to content

Commit a36c9d8

Browse files
bors[bot]Veykril
andauthored
Merge #9669
9669: minor: Move out fn_param tests r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents b7e80d1 + 03efb50 commit a36c9d8

File tree

4 files changed

+152
-122
lines changed

4 files changed

+152
-122
lines changed

crates/ide_completion/src/completions/fn_param.rs

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -75,124 +75,3 @@ fn add_new_item_to_acc(
7575
item.kind(CompletionItemKind::Binding).lookup_by(lookup);
7676
item.add_to(acc)
7777
}
78-
79-
#[cfg(test)]
80-
mod tests {
81-
use expect_test::{expect, Expect};
82-
83-
use crate::{tests::filtered_completion_list, CompletionKind};
84-
85-
fn check(ra_fixture: &str, expect: Expect) {
86-
let actual = filtered_completion_list(ra_fixture, CompletionKind::Magic);
87-
expect.assert_eq(&actual);
88-
}
89-
90-
#[test]
91-
fn test_param_completion_last_param() {
92-
check(
93-
r#"
94-
fn foo(file_id: FileId) {}
95-
fn bar(file_id: FileId) {}
96-
fn baz(file$0) {}
97-
"#,
98-
expect![[r#"
99-
bn file_id: FileId
100-
"#]],
101-
);
102-
}
103-
104-
#[test]
105-
fn test_param_completion_first_param() {
106-
check(
107-
r#"
108-
fn foo(file_id: FileId) {}
109-
fn bar(file_id: FileId) {}
110-
fn baz(file$0 id: u32) {}
111-
"#,
112-
expect![[r#"
113-
bn file_id: FileId
114-
"#]],
115-
);
116-
}
117-
118-
#[test]
119-
fn test_param_completion_nth_param() {
120-
check(
121-
r#"
122-
fn foo(file_id: FileId) {}
123-
fn baz(file$0, x: i32) {}
124-
"#,
125-
expect![[r#"
126-
bn file_id: FileId
127-
"#]],
128-
);
129-
}
130-
131-
#[test]
132-
fn test_param_completion_trait_param() {
133-
check(
134-
r#"
135-
pub(crate) trait SourceRoot {
136-
pub fn contains(&self, file_id: FileId) -> bool;
137-
pub fn module_map(&self) -> &ModuleMap;
138-
pub fn lines(&self, file_id: FileId) -> &LineIndex;
139-
pub fn syntax(&self, file$0)
140-
}
141-
"#,
142-
expect![[r#"
143-
bn file_id: FileId
144-
"#]],
145-
);
146-
}
147-
148-
#[test]
149-
fn completes_param_in_inner_function() {
150-
check(
151-
r#"
152-
fn outer(text: String) {
153-
fn inner($0)
154-
}
155-
"#,
156-
expect![[r#"
157-
bn text: String
158-
"#]],
159-
)
160-
}
161-
162-
#[test]
163-
fn completes_non_ident_pat_param() {
164-
check(
165-
r#"
166-
struct Bar { bar: u32 }
167-
168-
fn foo(Bar { bar }: Bar) {}
169-
fn foo2($0) {}
170-
"#,
171-
expect![[r#"
172-
bn Bar { bar }: Bar
173-
"#]],
174-
)
175-
}
176-
177-
#[test]
178-
fn test_param_completion_self_param() {
179-
check(
180-
r#"
181-
struct A {}
182-
183-
impl A {
184-
fn foo(file_id: FileId) {}
185-
fn new($0) {
186-
}
187-
}
188-
"#,
189-
expect![[r#"
190-
bn self
191-
bn &self
192-
bn mut self
193-
bn &mut self
194-
bn file_id: FileId
195-
"#]],
196-
)
197-
}
198-
}

crates/ide_completion/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! Notable examples for completions that are being tested in this module's submodule are paths.
66
77
mod attribute;
8+
mod fn_param;
89
mod item_list;
910
mod item;
1011
mod pattern;
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
use expect_test::{expect, Expect};
2+
3+
use crate::tests::completion_list;
4+
5+
fn check(ra_fixture: &str, expect: Expect) {
6+
let actual = completion_list(ra_fixture);
7+
expect.assert_eq(&actual);
8+
}
9+
10+
#[test]
11+
fn only_param() {
12+
check(
13+
r#"
14+
fn foo(file_id: usize) {}
15+
fn bar(file_id: usize) {}
16+
fn baz(file$0) {}
17+
"#,
18+
expect![[r#"
19+
bn file_id: usize
20+
kw mut
21+
"#]],
22+
);
23+
}
24+
25+
#[test]
26+
fn last_param() {
27+
check(
28+
r#"
29+
fn foo(file_id: usize) {}
30+
fn bar(file_id: usize) {}
31+
fn baz(foo: (), file$0) {}
32+
"#,
33+
expect![[r#"
34+
bn file_id: usize
35+
kw mut
36+
"#]],
37+
);
38+
}
39+
40+
#[test]
41+
fn first_param() {
42+
check(
43+
r#"
44+
fn foo(file_id: usize) {}
45+
fn bar(file_id: usize) {}
46+
fn baz(file$0 id: u32) {}
47+
"#,
48+
expect![[r#"
49+
bn file_id: usize
50+
kw mut
51+
"#]],
52+
);
53+
}
54+
55+
#[test]
56+
fn trait_param() {
57+
check(
58+
r#"
59+
pub(crate) trait SourceRoot {
60+
pub fn contains(file_id: usize) -> bool;
61+
pub fn syntax(file$0)
62+
}
63+
"#,
64+
expect![[r#"
65+
bn file_id: usize
66+
kw mut
67+
"#]],
68+
);
69+
}
70+
71+
#[test]
72+
fn in_inner_function() {
73+
check(
74+
r#"
75+
fn outer(text: &str) {
76+
fn inner($0)
77+
}
78+
"#,
79+
expect![[r#"
80+
bn text: &str
81+
kw mut
82+
"#]],
83+
)
84+
}
85+
86+
#[test]
87+
fn shows_non_ident_pat_param() {
88+
check(
89+
r#"
90+
struct Bar { bar: u32 }
91+
fn foo(Bar { bar }: Bar) {}
92+
fn foo2($0) {}
93+
"#,
94+
expect![[r#"
95+
bn Bar { bar }: Bar
96+
kw mut
97+
bn Bar Bar { bar$1 }: Bar$0
98+
st Bar
99+
"#]],
100+
)
101+
}
102+
103+
#[test]
104+
fn in_impl_only_param() {
105+
check(
106+
r#"
107+
struct A {}
108+
109+
impl A {
110+
fn foo(file_id: usize) {}
111+
fn new($0) {}
112+
}
113+
"#,
114+
expect![[r#"
115+
bn self
116+
bn &self
117+
bn mut self
118+
bn &mut self
119+
bn file_id: usize
120+
kw mut
121+
sp Self
122+
st A
123+
"#]],
124+
)
125+
}
126+
127+
#[test]
128+
fn in_impl_after_self() {
129+
// FIXME: self completions should not be here
130+
check(
131+
r#"
132+
struct A {}
133+
134+
impl A {
135+
fn foo(file_id: usize) {}
136+
fn new(self, $0) {}
137+
}
138+
"#,
139+
expect![[r#"
140+
bn self
141+
bn &self
142+
bn mut self
143+
bn &mut self
144+
bn file_id: usize
145+
kw mut
146+
sp Self
147+
st A
148+
"#]],
149+
)
150+
}

crates/ide_db/src/call_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl ActiveParameter {
166166

167167
let idx = active_parameter?;
168168
let mut params = signature.params(sema.db);
169-
if params.len() <= idx {
169+
if !(idx < params.len()) {
170170
cov_mark::hit!(too_many_arguments);
171171
return None;
172172
}

0 commit comments

Comments
 (0)