1131: Use inline snapshots in complete_dot r=matklad a=vipentti

Relates to #1127 

Co-authored-by: Ville Penttinen <villem.penttinen@gmail.com>
This commit is contained in:
bors[bot] 2019-04-10 11:05:31 +00:00
commit 6d9acb8753
10 changed files with 136 additions and 180 deletions

View file

@ -55,29 +55,41 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty
#[cfg(test)]
mod tests {
use crate::completion::{check_completion, CompletionKind};
use crate::completion::{do_completion, CompletionKind, CompletionItem};
use insta::assert_debug_snapshot_matches;
fn check_ref_completion(name: &str, code: &str) {
check_completion(name, code, CompletionKind::Reference);
fn do_ref_completion(code: &str) -> Vec<CompletionItem> {
do_completion(code, CompletionKind::Reference)
}
#[test]
fn test_struct_field_completion() {
check_ref_completion(
"struct_field_completion",
r"
struct A { the_field: u32 }
fn foo(a: A) {
a.<|>
}
",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A { the_field: u32 }
fn foo(a: A) {
a.<|>
}
",
),
@r###"[
CompletionItem {
label: "the_field",
source_range: [94; 94),
delete: [94; 94),
insert: "the_field",
kind: Field,
detail: "u32"
}
]"###
);
}
#[test]
fn test_struct_field_completion_self() {
check_ref_completion(
"struct_field_completion_self",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A {
/// This is the_field
@ -89,13 +101,35 @@ mod tests {
}
}
",
),
@r###"[
CompletionItem {
label: "foo",
source_range: [187; 187),
delete: [187; 187),
insert: "foo()$0",
kind: Method,
detail: "fn foo(self)"
},
CompletionItem {
label: "the_field",
source_range: [187; 187),
delete: [187; 187),
insert: "the_field",
kind: Field,
detail: "(u32,)",
documentation: Documentation(
"This is the_field"
)
}
]"###
);
}
#[test]
fn test_struct_field_completion_autoderef() {
check_ref_completion(
"struct_field_completion_autoderef",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A { the_field: (u32, i32) }
impl A {
@ -104,26 +138,47 @@ mod tests {
}
}
",
),
@r###"[
CompletionItem {
label: "foo",
source_range: [126; 126),
delete: [126; 126),
insert: "foo()$0",
kind: Method,
detail: "fn foo(&self)"
},
CompletionItem {
label: "the_field",
source_range: [126; 126),
delete: [126; 126),
insert: "the_field",
kind: Field,
detail: "(u32, i32)"
}
]"###
);
}
#[test]
fn test_no_struct_field_completion_for_method_call() {
check_ref_completion(
"no_struct_field_completion_for_method_call",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A { the_field: u32 }
fn foo(a: A) {
a.<|>()
}
",
),
@"[]"
);
}
#[test]
fn test_method_completion() {
check_ref_completion(
"method_completion",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A {}
impl A {
@ -133,13 +188,24 @@ mod tests {
a.<|>
}
",
),
@r###"[
CompletionItem {
label: "the_method",
source_range: [144; 144),
delete: [144; 144),
insert: "the_method()$0",
kind: Method,
detail: "fn the_method(&self)"
}
]"###
);
}
#[test]
fn test_no_non_self_method() {
check_ref_completion(
"no_non_self_method",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A {}
impl A {
@ -149,13 +215,15 @@ mod tests {
a.<|>
}
",
),
@"[]"
);
}
#[test]
fn test_method_attr_filtering() {
check_ref_completion(
"method_attr_filtering",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
struct A {}
impl A {
@ -169,26 +237,56 @@ mod tests {
a.<|>
}
",
),
@r###"[
CompletionItem {
label: "the_method",
source_range: [249; 249),
delete: [249; 249),
insert: "the_method()$0",
kind: Method,
detail: "fn the_method(&self)"
}
]"###
);
}
#[test]
fn test_tuple_field_completion() {
check_ref_completion(
"tuple_field_completion",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
fn foo() {
let b = (0, 3.14);
b.<|>
}
",
),
@r###"[
CompletionItem {
label: "0",
source_range: [75; 75),
delete: [75; 75),
insert: "0",
kind: Field,
detail: "i32"
},
CompletionItem {
label: "1",
source_range: [75; 75),
delete: [75; 75),
insert: "1",
kind: Field,
detail: "f64"
}
]"###
);
}
#[test]
fn test_tuple_field_inference() {
check_ref_completion(
"tuple_field_inference",
assert_debug_snapshot_matches!(
do_ref_completion(
r"
pub struct S;
impl S {
@ -204,6 +302,17 @@ mod tests {
}
}
",
),
@r###"[
CompletionItem {
label: "blah",
source_range: [299; 300),
delete: [299; 300),
insert: "blah()$0",
kind: Method,
detail: "pub fn blah(&self)"
}
]"###
);
}
}

View file

@ -1,16 +0,0 @@
---
created: "2019-02-18T09:22:23.941335305Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "the_method",
source_range: [249; 249),
delete: [249; 249),
insert: "the_method()$0",
kind: Method,
detail: "fn the_method(&self)"
}
]

View file

@ -1,16 +0,0 @@
---
created: "2019-02-18T09:22:23.939676100Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "the_method",
source_range: [144; 144),
delete: [144; 144),
insert: "the_method()$0",
kind: Method,
detail: "fn the_method(&self)"
}
]

View file

@ -1,7 +0,0 @@
---
created: "2019-01-22T14:45:00.552379600+00:00"
creator: insta@0.4.0
expression: kind_completions
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
---
[]

View file

@ -1,7 +0,0 @@
---
created: "2019-01-22T14:45:00.552379600+00:00"
creator: insta@0.4.0
expression: kind_completions
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
---
[]

View file

@ -1,16 +0,0 @@
---
created: "2019-02-18T09:22:23.939645902Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "the_field",
source_range: [85; 85),
delete: [85; 85),
insert: "the_field",
kind: Field,
detail: "u32"
}
]

View file

@ -1,24 +0,0 @@
---
created: "2019-02-18T09:22:23.940872916Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "foo",
source_range: [126; 126),
delete: [126; 126),
insert: "foo()$0",
kind: Method,
detail: "fn foo(&self)"
},
CompletionItem {
label: "the_field",
source_range: [126; 126),
delete: [126; 126),
insert: "the_field",
kind: Field,
detail: "(u32, i32)"
}
]

View file

@ -1,27 +0,0 @@
---
created: "2019-02-18T09:22:23.940872918Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "foo",
source_range: [187; 187),
delete: [187; 187),
insert: "foo()$0",
kind: Method,
detail: "fn foo(self)"
},
CompletionItem {
label: "the_field",
source_range: [187; 187),
delete: [187; 187),
insert: "the_field",
kind: Field,
detail: "(u32,)",
documentation: Documentation(
"This is the_field"
)
}
]

View file

@ -1,24 +0,0 @@
---
created: "2019-02-18T09:22:23.939710971Z"
creator: insta@0.6.2
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "0",
source_range: [75; 75),
delete: [75; 75),
insert: "0",
kind: Field,
detail: "i32"
},
CompletionItem {
label: "1",
source_range: [75; 75),
delete: [75; 75),
insert: "1",
kind: Field,
detail: "f64"
}
]

View file

@ -1,16 +0,0 @@
---
created: "2019-04-05T23:00:18.283812700Z"
creator: insta@0.7.4
source: crates/ra_ide_api/src/completion/completion_item.rs
expression: kind_completions
---
[
CompletionItem {
label: "blah",
source_range: [299; 300),
delete: [299; 300),
insert: "blah()$0",
kind: Method,
detail: "pub fn blah(&self)"
}
]