inline snapshots

This commit is contained in:
funkill2 2019-07-02 00:51:18 +03:00
parent f06e3efbb1
commit 532aaba234
No known key found for this signature in database
GPG key ID: 9202B2432F86E487

View file

@ -74,10 +74,11 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
mod tests { mod tests {
use test_utils::covers; use test_utils::covers;
use crate::completion::{CompletionKind, check_completion, do_completion}; use crate::completion::{CompletionKind, do_completion, CompletionItem};
use insta::assert_debug_snapshot_matches;
fn check_reference_completion(code: &str, expected_completions: &str) { fn do_reference_completion(code: &str) -> Vec<CompletionItem> {
check_completion(code, expected_completions, CompletionKind::Reference); do_completion(code, CompletionKind::Reference)
} }
#[test] #[test]
@ -115,8 +116,8 @@ mod tests {
#[test] #[test]
fn completes_mod_with_docs() { fn completes_mod_with_docs() {
check_reference_completion( assert_debug_snapshot_matches!(
"mod_with_docs", do_reference_completion(
r" r"
use self::my<|>; use self::my<|>;
@ -125,56 +126,113 @@ mod tests {
mod my { mod my {
struct Bar; struct Bar;
} }
", "
),
@r###"[
CompletionItem {
label: "my",
source_range: [27; 29),
delete: [27; 29),
insert: "my",
kind: Module,
documentation: Documentation(
"Some simple\ndocs describing `mod my`.",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_use_item_starting_with_self() { fn completes_use_item_starting_with_self() {
check_reference_completion( assert_debug_snapshot_matches!(
"use_item_starting_with_self", do_reference_completion(
r" r"
use self::m::<|>; use self::m::<|>;
mod m { mod m {
struct Bar; struct Bar;
} }
", "
),
@r###"[
CompletionItem {
label: "Bar",
source_range: [30; 30),
delete: [30; 30),
insert: "Bar",
kind: Struct,
},
]"###
); );
} }
#[test] #[test]
fn completes_use_item_starting_with_crate() { fn completes_use_item_starting_with_crate() {
check_reference_completion( assert_debug_snapshot_matches!(
"use_item_starting_with_crate", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
mod foo; mod foo;
struct Spam; struct Spam;
//- /foo.rs //- /foo.rs
use crate::Sp<|> use crate::Sp<|>
", "
),
@r###"[
CompletionItem {
label: "Spam",
source_range: [11; 13),
delete: [11; 13),
insert: "Spam",
kind: Struct,
},
CompletionItem {
label: "foo",
source_range: [11; 13),
delete: [11; 13),
insert: "foo",
kind: Module,
},
]"###
); );
} }
#[test] #[test]
fn completes_nested_use_tree() { fn completes_nested_use_tree() {
check_reference_completion( assert_debug_snapshot_matches!(
"nested_use_tree", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
mod foo; mod foo;
struct Spam; struct Spam;
//- /foo.rs //- /foo.rs
use crate::{Sp<|>}; use crate::{Sp<|>};
", "
),
@r###"[
CompletionItem {
label: "Spam",
source_range: [12; 14),
delete: [12; 14),
insert: "Spam",
kind: Struct,
},
CompletionItem {
label: "foo",
source_range: [12; 14),
delete: [12; 14),
insert: "foo",
kind: Module,
},
]"###
); );
} }
#[test] #[test]
fn completes_deeply_nested_use_tree() { fn completes_deeply_nested_use_tree() {
check_reference_completion( assert_debug_snapshot_matches!(
"deeply_nested_use_tree", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
mod foo; mod foo;
@ -185,14 +243,24 @@ mod tests {
} }
//- /foo.rs //- /foo.rs
use crate::{bar::{baz::Sp<|>}}; use crate::{bar::{baz::Sp<|>}};
", "
),
@r###"[
CompletionItem {
label: "Spam",
source_range: [23; 25),
delete: [23; 25),
insert: "Spam",
kind: Struct,
},
]"###
); );
} }
#[test] #[test]
fn completes_enum_variant() { fn completes_enum_variant() {
check_reference_completion( assert_debug_snapshot_matches!(
"enum_variant", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// An enum /// An enum
@ -203,14 +271,39 @@ mod tests {
Bar(i32) Bar(i32)
} }
fn foo() { let _ = E::<|> } fn foo() { let _ = E::<|> }
", "
),
@r###"[
CompletionItem {
label: "Bar",
source_range: [116; 116),
delete: [116; 116),
insert: "Bar",
kind: EnumVariant,
detail: "(i32)",
documentation: Documentation(
"Bar Variant with i32",
),
},
CompletionItem {
label: "Foo",
source_range: [116; 116),
delete: [116; 116),
insert: "Foo",
kind: EnumVariant,
detail: "()",
documentation: Documentation(
"Foo Variant",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_enum_variant_with_details() { fn completes_enum_variant_with_details() {
check_reference_completion( assert_debug_snapshot_matches!(
"enum_variant_with_details", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
struct S { field: u32 } struct S { field: u32 }
@ -224,14 +317,50 @@ mod tests {
S(S), S(S),
} }
fn foo() { let _ = E::<|> } fn foo() { let _ = E::<|> }
", "
),
@r###"[
CompletionItem {
label: "Bar",
source_range: [180; 180),
delete: [180; 180),
insert: "Bar",
kind: EnumVariant,
detail: "(i32, u32)",
documentation: Documentation(
"Bar Variant with i32 and u32",
),
},
CompletionItem {
label: "Foo",
source_range: [180; 180),
delete: [180; 180),
insert: "Foo",
kind: EnumVariant,
detail: "()",
documentation: Documentation(
"Foo Variant (empty)",
),
},
CompletionItem {
label: "S",
source_range: [180; 180),
delete: [180; 180),
insert: "S",
kind: EnumVariant,
detail: "(S)",
documentation: Documentation(
"",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_struct_associated_method() { fn completes_struct_associated_method() {
check_reference_completion( assert_debug_snapshot_matches!(
"struct_associated_method", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// A Struct /// A Struct
@ -243,14 +372,28 @@ mod tests {
} }
fn foo() { let _ = S::<|> } fn foo() { let _ = S::<|> }
", "
),
@r###"[
CompletionItem {
label: "m",
source_range: [100; 100),
delete: [100; 100),
insert: "m()$0",
kind: Function,
detail: "fn m()",
documentation: Documentation(
"An associated method",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_struct_associated_const() { fn completes_struct_associated_const() {
check_reference_completion( assert_debug_snapshot_matches!(
"struct_associated_const", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// A Struct /// A Struct
@ -262,14 +405,28 @@ mod tests {
} }
fn foo() { let _ = S::<|> } fn foo() { let _ = S::<|> }
", "
),
@r###"[
CompletionItem {
label: "C",
source_range: [107; 107),
delete: [107; 107),
insert: "C",
kind: Const,
detail: "const C: i32 = 42;",
documentation: Documentation(
"An associated const",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_struct_associated_type() { fn completes_struct_associated_type() {
check_reference_completion( assert_debug_snapshot_matches!(
"struct_associated_type", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// A Struct /// A Struct
@ -281,14 +438,28 @@ mod tests {
} }
fn foo() { let _ = S::<|> } fn foo() { let _ = S::<|> }
", "
),
@r###"[
CompletionItem {
label: "T",
source_range: [101; 101),
delete: [101; 101),
insert: "T",
kind: TypeAlias,
detail: "type T = i32;",
documentation: Documentation(
"An associated type",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_enum_associated_method() { fn completes_enum_associated_method() {
check_reference_completion( assert_debug_snapshot_matches!(
"enum_associated_method", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// An enum /// An enum
@ -300,14 +471,28 @@ mod tests {
} }
fn foo() { let _ = S::<|> } fn foo() { let _ = S::<|> }
", "
),
@r###"[
CompletionItem {
label: "m",
source_range: [100; 100),
delete: [100; 100),
insert: "m()$0",
kind: Function,
detail: "fn m()",
documentation: Documentation(
"An associated method",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_union_associated_method() { fn completes_union_associated_method() {
check_reference_completion( assert_debug_snapshot_matches!(
"union_associated_method", do_reference_completion(
" "
//- /lib.rs //- /lib.rs
/// A union /// A union
@ -319,14 +504,28 @@ mod tests {
} }
fn foo() { let _ = U::<|> } fn foo() { let _ = U::<|> }
", "
),
@r###"[
CompletionItem {
label: "m",
source_range: [101; 101),
delete: [101; 101),
insert: "m()$0",
kind: Function,
detail: "fn m()",
documentation: Documentation(
"An associated method",
),
},
]"###
); );
} }
#[test] #[test]
fn completes_use_paths_across_crates() { fn completes_use_paths_across_crates() {
check_reference_completion( assert_debug_snapshot_matches!(
"completes_use_paths_across_crates", do_reference_completion(
" "
//- /main.rs //- /main.rs
use foo::<|>; use foo::<|>;
@ -335,7 +534,17 @@ mod tests {
pub mod bar { pub mod bar {
pub struct S; pub struct S;
} }
", "
),
@r###"[
CompletionItem {
label: "bar",
source_range: [9; 9),
delete: [9; 9),
insert: "bar",
kind: Module,
},
]"###
); );
} }
} }