mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-27 22:34:14 +00:00
Merge #9669
9669: minor: Move out fn_param tests r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
a36c9d8b5c
@ -75,124 +75,3 @@ fn add_new_item_to_acc(
|
|||||||
item.kind(CompletionItemKind::Binding).lookup_by(lookup);
|
item.kind(CompletionItemKind::Binding).lookup_by(lookup);
|
||||||
item.add_to(acc)
|
item.add_to(acc)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use expect_test::{expect, Expect};
|
|
||||||
|
|
||||||
use crate::{tests::filtered_completion_list, CompletionKind};
|
|
||||||
|
|
||||||
fn check(ra_fixture: &str, expect: Expect) {
|
|
||||||
let actual = filtered_completion_list(ra_fixture, CompletionKind::Magic);
|
|
||||||
expect.assert_eq(&actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_param_completion_last_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn foo(file_id: FileId) {}
|
|
||||||
fn bar(file_id: FileId) {}
|
|
||||||
fn baz(file$0) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn file_id: FileId
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_param_completion_first_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn foo(file_id: FileId) {}
|
|
||||||
fn bar(file_id: FileId) {}
|
|
||||||
fn baz(file$0 id: u32) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn file_id: FileId
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_param_completion_nth_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn foo(file_id: FileId) {}
|
|
||||||
fn baz(file$0, x: i32) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn file_id: FileId
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_param_completion_trait_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
pub(crate) trait SourceRoot {
|
|
||||||
pub fn contains(&self, file_id: FileId) -> bool;
|
|
||||||
pub fn module_map(&self) -> &ModuleMap;
|
|
||||||
pub fn lines(&self, file_id: FileId) -> &LineIndex;
|
|
||||||
pub fn syntax(&self, file$0)
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn file_id: FileId
|
|
||||||
"#]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_param_in_inner_function() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
fn outer(text: String) {
|
|
||||||
fn inner($0)
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn text: String
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn completes_non_ident_pat_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
struct Bar { bar: u32 }
|
|
||||||
|
|
||||||
fn foo(Bar { bar }: Bar) {}
|
|
||||||
fn foo2($0) {}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn Bar { bar }: Bar
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_param_completion_self_param() {
|
|
||||||
check(
|
|
||||||
r#"
|
|
||||||
struct A {}
|
|
||||||
|
|
||||||
impl A {
|
|
||||||
fn foo(file_id: FileId) {}
|
|
||||||
fn new($0) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"#,
|
|
||||||
expect![[r#"
|
|
||||||
bn self
|
|
||||||
bn &self
|
|
||||||
bn mut self
|
|
||||||
bn &mut self
|
|
||||||
bn file_id: FileId
|
|
||||||
"#]],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
//! Notable examples for completions that are being tested in this module's submodule are paths.
|
//! Notable examples for completions that are being tested in this module's submodule are paths.
|
||||||
|
|
||||||
mod attribute;
|
mod attribute;
|
||||||
|
mod fn_param;
|
||||||
mod item_list;
|
mod item_list;
|
||||||
mod item;
|
mod item;
|
||||||
mod pattern;
|
mod pattern;
|
||||||
|
150
crates/ide_completion/src/tests/fn_param.rs
Normal file
150
crates/ide_completion/src/tests/fn_param.rs
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
|
use crate::tests::completion_list;
|
||||||
|
|
||||||
|
fn check(ra_fixture: &str, expect: Expect) {
|
||||||
|
let actual = completion_list(ra_fixture);
|
||||||
|
expect.assert_eq(&actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn only_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo(file_id: usize) {}
|
||||||
|
fn bar(file_id: usize) {}
|
||||||
|
fn baz(file$0) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn last_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo(file_id: usize) {}
|
||||||
|
fn bar(file_id: usize) {}
|
||||||
|
fn baz(foo: (), file$0) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn first_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn foo(file_id: usize) {}
|
||||||
|
fn bar(file_id: usize) {}
|
||||||
|
fn baz(file$0 id: u32) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn trait_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
pub(crate) trait SourceRoot {
|
||||||
|
pub fn contains(file_id: usize) -> bool;
|
||||||
|
pub fn syntax(file$0)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_inner_function() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
fn outer(text: &str) {
|
||||||
|
fn inner($0)
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn text: &str
|
||||||
|
kw mut
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shows_non_ident_pat_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct Bar { bar: u32 }
|
||||||
|
fn foo(Bar { bar }: Bar) {}
|
||||||
|
fn foo2($0) {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn Bar { bar }: Bar
|
||||||
|
kw mut
|
||||||
|
bn Bar Bar { bar$1 }: Bar$0
|
||||||
|
st Bar
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_impl_only_param() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
impl A {
|
||||||
|
fn foo(file_id: usize) {}
|
||||||
|
fn new($0) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn self
|
||||||
|
bn &self
|
||||||
|
bn mut self
|
||||||
|
bn &mut self
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
sp Self
|
||||||
|
st A
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_impl_after_self() {
|
||||||
|
// FIXME: self completions should not be here
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
struct A {}
|
||||||
|
|
||||||
|
impl A {
|
||||||
|
fn foo(file_id: usize) {}
|
||||||
|
fn new(self, $0) {}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
bn self
|
||||||
|
bn &self
|
||||||
|
bn mut self
|
||||||
|
bn &mut self
|
||||||
|
bn file_id: usize
|
||||||
|
kw mut
|
||||||
|
sp Self
|
||||||
|
st A
|
||||||
|
"#]],
|
||||||
|
)
|
||||||
|
}
|
@ -166,7 +166,7 @@ impl ActiveParameter {
|
|||||||
|
|
||||||
let idx = active_parameter?;
|
let idx = active_parameter?;
|
||||||
let mut params = signature.params(sema.db);
|
let mut params = signature.params(sema.db);
|
||||||
if params.len() <= idx {
|
if !(idx < params.len()) {
|
||||||
cov_mark::hit!(too_many_arguments);
|
cov_mark::hit!(too_many_arguments);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user