Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use inline snapshots in complete_fn_param #1130

Merged
merged 1 commit into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 58 additions & 27 deletions crates/ra_ide_api/src/completion/complete_fn_param.rs
Expand Up @@ -54,48 +54,79 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)

#[cfg(test)]
mod tests {
use crate::completion::{check_completion, CompletionKind};
use crate::completion::{do_completion, CompletionItem, CompletionKind};
use insta::assert_debug_snapshot_matches;

fn check_magic_completion(name: &str, code: &str) {
check_completion(name, code, CompletionKind::Magic);
fn do_magic_completion(code: &str) -> Vec<CompletionItem> {
do_completion(code, CompletionKind::Magic)
}

#[test]
fn test_param_completion_last_param() {
check_magic_completion(
"param_completion_last_param",
r"
fn foo(file_id: FileId) {}
fn bar(file_id: FileId) {}
fn baz(file<|>) {}
",
assert_debug_snapshot_matches!(
do_magic_completion(
r"
fn foo(file_id: FileId) {}
fn bar(file_id: FileId) {}
fn baz(file<|>) {}
",
),
@r###"[
CompletionItem {
label: "file_id: FileId",
source_range: [110; 114),
delete: [110; 114),
insert: "file_id: FileId",
lookup: "file_id"
}
]"###
);
}

#[test]
fn test_param_completion_nth_param() {
check_magic_completion(
"param_completion_nth_param",
r"
fn foo(file_id: FileId) {}
fn bar(file_id: FileId) {}
fn baz(file<|>, x: i32) {}
",
assert_debug_snapshot_matches!(
do_magic_completion(
r"
fn foo(file_id: FileId) {}
fn bar(file_id: FileId) {}
fn baz(file<|>, x: i32) {}
",
),
@r###"[
CompletionItem {
label: "file_id: FileId",
source_range: [110; 114),
delete: [110; 114),
insert: "file_id: FileId",
lookup: "file_id"
}
]"###
);
}

#[test]
fn test_param_completion_trait_param() {
check_magic_completion(
"param_completion_trait_param",
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<|>)
}
",
assert_debug_snapshot_matches!(
do_magic_completion(
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<|>)
}
",
),
@r###"[
CompletionItem {
label: "file_id: FileId",
source_range: [289; 293),
delete: [289; 293),
insert: "file_id: FileId",
lookup: "file_id"
}
]"###
);
}
}

This file was deleted.

This file was deleted.

This file was deleted.