mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Inline snapshots for all tests in complete_snippet, remove now-unused check_completion
This commit is contained in:
parent
460423e66c
commit
69244a6e18
7 changed files with 58 additions and 81 deletions
|
@ -16,7 +16,7 @@ mod complete_postfix;
|
||||||
use ra_db::SourceDatabase;
|
use ra_db::SourceDatabase;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use crate::completion::completion_item::{check_completion, do_completion};
|
use crate::completion::completion_item::do_completion;
|
||||||
use crate::{
|
use crate::{
|
||||||
completion::{
|
completion::{
|
||||||
completion_context::CompletionContext,
|
completion_context::CompletionContext,
|
||||||
|
|
|
@ -39,39 +39,78 @@ fn ${1:feature}() {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::completion::{check_completion, CompletionKind};
|
use crate::completion::{do_completion, CompletionItem, CompletionKind};
|
||||||
|
use insta::assert_debug_snapshot_matches;
|
||||||
|
|
||||||
fn check_snippet_completion(name: &str, code: &str) {
|
fn do_snippet_completion(code: &str) -> Vec<CompletionItem> {
|
||||||
check_completion(name, code, CompletionKind::Snippet);
|
do_completion(code, CompletionKind::Snippet)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_snippets_in_expressions() {
|
fn completes_snippets_in_expressions() {
|
||||||
check_snippet_completion("snippets_in_expressions", r"fn foo(x: i32) { <|> }");
|
assert_debug_snapshot_matches!(
|
||||||
|
do_snippet_completion(r"fn foo(x: i32) { <|> }"),
|
||||||
|
@r#"[
|
||||||
|
CompletionItem {
|
||||||
|
label: "pd",
|
||||||
|
source_range: [17; 17),
|
||||||
|
delete: [17; 17),
|
||||||
|
insert: "eprintln!(\"$0 = {:?}\", $0);",
|
||||||
|
kind: Snippet,
|
||||||
|
},
|
||||||
|
CompletionItem {
|
||||||
|
label: "ppd",
|
||||||
|
source_range: [17; 17),
|
||||||
|
delete: [17; 17),
|
||||||
|
insert: "eprintln!(\"$0 = {:#?}\", $0);",
|
||||||
|
kind: Snippet,
|
||||||
|
},
|
||||||
|
]"#
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_not_complete_snippets_in_path() {
|
fn should_not_complete_snippets_in_path() {
|
||||||
check_snippet_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"should_not_complete_snippets_in_path",
|
do_snippet_completion(r"fn foo(x: i32) { ::foo<|> }"),
|
||||||
r"fn foo(x: i32) { ::foo<|> }",
|
@r#"[]"#
|
||||||
);
|
);
|
||||||
check_snippet_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"should_not_complete_snippets_in_path2",
|
do_snippet_completion(r"fn foo(x: i32) { ::<|> }"),
|
||||||
r"fn foo(x: i32) { ::<|> }",
|
@r#"[]"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_snippets_in_items() {
|
fn completes_snippets_in_items() {
|
||||||
check_snippet_completion(
|
assert_debug_snapshot_matches!(
|
||||||
"snippets_in_items",
|
do_snippet_completion(
|
||||||
r"
|
r"
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
<|>
|
<|>
|
||||||
}
|
}
|
||||||
",
|
"
|
||||||
|
),
|
||||||
|
@r###"
|
||||||
|
⋮[
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "Test function",
|
||||||
|
⋮ source_range: [78; 78),
|
||||||
|
⋮ delete: [78; 78),
|
||||||
|
⋮ insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
|
||||||
|
⋮ kind: Snippet,
|
||||||
|
⋮ lookup: "tfn",
|
||||||
|
⋮ },
|
||||||
|
⋮ CompletionItem {
|
||||||
|
⋮ label: "pub(crate)",
|
||||||
|
⋮ source_range: [78; 78),
|
||||||
|
⋮ delete: [78; 78),
|
||||||
|
⋮ insert: "pub(crate) $0",
|
||||||
|
⋮ kind: Snippet,
|
||||||
|
⋮ },
|
||||||
|
⋮]
|
||||||
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -299,10 +299,3 @@ pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionI
|
||||||
kind_completions.sort_by_key(|c| c.label.clone());
|
kind_completions.sort_by_key(|c| c.label.clone());
|
||||||
kind_completions
|
kind_completions
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) {
|
|
||||||
use insta::assert_debug_snapshot_matches;
|
|
||||||
let kind_completions = do_completion(code, kind);
|
|
||||||
assert_debug_snapshot_matches!(test_name, kind_completions);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
Created: 2019-01-23T05:19:36.475253+00:00
|
|
||||||
Creator: insta@0.1.4
|
|
||||||
Source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
|
|
||||||
[]
|
|
|
@ -1,5 +0,0 @@
|
||||||
Created: 2019-01-23T05:19:36.476869+00:00
|
|
||||||
Creator: insta@0.1.4
|
|
||||||
Source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
|
|
||||||
[]
|
|
|
@ -1,22 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:23:35.141901047Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "pd",
|
|
||||||
source_range: [17; 17),
|
|
||||||
delete: [17; 17),
|
|
||||||
insert: "eprintln!(\"$0 = {:?}\", $0);",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "ppd",
|
|
||||||
source_range: [17; 17),
|
|
||||||
delete: [17; 17),
|
|
||||||
insert: "eprintln!(\"$0 = {:#?}\", $0);",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
]
|
|
|
@ -1,23 +0,0 @@
|
||||||
---
|
|
||||||
created: "2019-05-23T22:23:35.149234118Z"
|
|
||||||
creator: insta@0.8.1
|
|
||||||
source: crates/ra_ide_api/src/completion/completion_item.rs
|
|
||||||
expression: kind_completions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
CompletionItem {
|
|
||||||
label: "Test function",
|
|
||||||
source_range: [66; 66),
|
|
||||||
delete: [66; 66),
|
|
||||||
insert: "#[test]\nfn ${1:feature}() {\n $0\n}",
|
|
||||||
kind: Snippet,
|
|
||||||
lookup: "tfn",
|
|
||||||
},
|
|
||||||
CompletionItem {
|
|
||||||
label: "pub(crate)",
|
|
||||||
source_range: [66; 66),
|
|
||||||
delete: [66; 66),
|
|
||||||
insert: "pub(crate) $0",
|
|
||||||
kind: Snippet,
|
|
||||||
},
|
|
||||||
]
|
|
Loading…
Add table
Add a link
Reference in a new issue