Add function to test completion edit

This commit is contained in:
Aleksey Kladov
2020-07-03 13:21:14 +02:00
parent 57576ac420
commit 503de8e229
2 changed files with 22 additions and 1 deletions

View File

@@ -1,8 +1,10 @@
//! Runs completion for testing purposes.
use hir::Semantics;
use itertools::Itertools;
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
use stdx::format_to;
use test_utils::assert_eq_text;
use crate::{
completion::{completion_item::CompletionKind, CompletionConfig},
@@ -54,6 +56,17 @@ pub(crate) fn completion_list_with_options(
.collect()
}
pub(crate) fn check_edit(what: &str, ra_fixture_before: &str, ra_fixture_after: &str) {
let (analysis, position) = analysis_and_position(ra_fixture_before);
let completions: Vec<CompletionItem> =
analysis.completions(&CompletionConfig::default(), position).unwrap().unwrap().into();
let (completion,) =
completions.into_iter().filter(|it| it.label() == what).collect_tuple().unwrap();
let mut actual = analysis.file_text(position.file_id).unwrap().to_string();
completion.text_edit().apply(&mut actual);
assert_eq_text!(ra_fixture_after, &actual)
}
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
let (analysis, pos) = analysis_and_position(code);
analysis