11886: add test for postfix completion relevance r=matklad a=matklad

Follow up to #11857, add a test and cov-marks

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2022-04-03 11:13:46 +00:00 committed by GitHub
commit f6bf7a3e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 []
"#]],
);
}
}