add test for postfix completion relevance

Follow up to #11857, add a test and cov-marks
This commit is contained in:
Aleksey Kladov 2022-04-03 12:09:55 +01:00
parent 40cba42e47
commit a8f460209d
2 changed files with 33 additions and 1 deletions

View file

@ -243,8 +243,10 @@ fn build_postfix_snippet_builder<'ctx>(
CompletionItem::new(CompletionItemKind::Snippet, ctx.source_range(), label);
item.detail(detail).snippet_edit(cap, edit);
let postfix_match = if ctx.original_token.text() == label {
cov_mark::hit!(postfix_exact_match_is_high_priority);
Some(CompletionRelevancePostfixMatch::Exact)
} else {
cov_mark::hit!(postfix_inexact_match_is_low_priority);
Some(CompletionRelevancePostfixMatch::NonExact)
};
let relevance = CompletionRelevance { postfix_match, ..Default::default() };

View file

@ -1550,7 +1550,8 @@ fn foo() {
}
#[test]
fn postfix_completion_relevance() {
fn postfix_exact_match_is_high_priority() {
cov_mark::check!(postfix_exact_match_is_high_priority);
check_relevance_for_kinds(
r#"
mod ops {
@ -1585,4 +1586,33 @@ fn main() {
"#]],
);
}
#[test]
fn postfix_inexact_match_is_low_priority() {
cov_mark::check!(postfix_inexact_match_is_low_priority);
check_relevance_for_kinds(
r#"
struct S;
impl S {
fn f(&self) {}
}
fn main() {
S.$0
}
"#,
&[CompletionItemKind::Snippet, CompletionItemKind::Method],
expect![[r#"
me f() []
sn ref []
sn refm []
sn match []
sn box []
sn dbg []
sn dbgr []
sn call []
sn let []
sn letm []
"#]],
);
}
}