From 4c92f2d19089c28c59aec27ff7e1b620eeef6f8e Mon Sep 17 00:00:00 2001 From: Mikhail Rakhmanov Date: Fri, 12 Jun 2020 10:12:15 +0200 Subject: Add more pattern tests --- crates/ra_ide/src/completion/patterns.rs | 59 +++++++++++++++++++++++++----- crates/ra_ide/src/completion/test_utils.rs | 2 +- 2 files changed, 50 insertions(+), 11 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide/src/completion/patterns.rs b/crates/ra_ide/src/completion/patterns.rs index df2594152..25be0c307 100644 --- a/crates/ra_ide/src/completion/patterns.rs +++ b/crates/ra_ide/src/completion/patterns.rs @@ -6,10 +6,6 @@ use ra_syntax::{ SyntaxNode, SyntaxToken, }; -pub(crate) fn inside_impl(element: SyntaxElement) -> bool { - element.ancestors().find(|it| it.kind() == IMPL_DEF).is_some() -} - pub(crate) fn inside_trait(element: SyntaxElement) -> bool { element.ancestors().find(|it| it.kind() == TRAIT_DEF).is_some() } @@ -42,10 +38,6 @@ pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool { not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some() } -pub(crate) fn has_item_list_parent(element: SyntaxElement) -> bool { - not_same_range_ancestor(element).filter(|it| it.kind() == ITEM_LIST).is_some() -} - pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool { previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some() } @@ -122,8 +114,8 @@ fn previous_sibling_or_ancestor_sibling(element: SyntaxElement) -> Option) { + let a = 2; + } + ", + has_ref_pat_parent, + ); + } + + #[test] + fn test_has_ref_pat_parent_in_let_statement() { + check_pattern_is_applicable( + r" + fn my_fn() { + let &<|> + } + ", + has_ref_pat_parent, + ); + } + + #[test] + fn test_has_bind_pat_parent_in_func_parameters() { + check_pattern_is_applicable( + r" + fn my_fn(m<|>) { + } + ", + has_bind_pat_parent, + ); + } + + #[test] + fn test_has_bind_pat_parent_in_let_statement() { + check_pattern_is_applicable( + r" + fn my_fn() { + let m<|> + } + ", + has_bind_pat_parent, + ); + } } diff --git a/crates/ra_ide/src/completion/test_utils.rs b/crates/ra_ide/src/completion/test_utils.rs index 277d2904d..f439f974d 100644 --- a/crates/ra_ide/src/completion/test_utils.rs +++ b/crates/ra_ide/src/completion/test_utils.rs @@ -6,7 +6,7 @@ use crate::{ CompletionItem, FilePosition, }; use hir::Semantics; -use ra_syntax::{AstNode, NodeOrToken, SyntaxElement, SyntaxToken}; +use ra_syntax::{AstNode, NodeOrToken, SyntaxElement}; pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { do_completion_with_options(code, kind, &CompletionConfig::default()) -- cgit v1.2.3