Skip to content

Commit 4c92f2d

Browse files
committed
Add more pattern tests
1 parent 396167e commit 4c92f2d

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

crates/ra_ide/src/completion/patterns.rs

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ use ra_syntax::{
66
SyntaxNode, SyntaxToken,
77
};
88

9-
pub(crate) fn inside_impl(element: SyntaxElement) -> bool {
10-
element.ancestors().find(|it| it.kind() == IMPL_DEF).is_some()
11-
}
12-
139
pub(crate) fn inside_trait(element: SyntaxElement) -> bool {
1410
element.ancestors().find(|it| it.kind() == TRAIT_DEF).is_some()
1511
}
@@ -42,10 +38,6 @@ pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool {
4238
not_same_range_ancestor(element).filter(|it| it.kind() == BLOCK_EXPR).is_some()
4339
}
4440

45-
pub(crate) fn has_item_list_parent(element: SyntaxElement) -> bool {
46-
not_same_range_ancestor(element).filter(|it| it.kind() == ITEM_LIST).is_some()
47-
}
48-
4941
pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
5042
previous_sibling_or_ancestor_sibling(element).filter(|it| it.kind() == TRAIT_DEF).is_some()
5143
}
@@ -122,8 +114,8 @@ fn previous_sibling_or_ancestor_sibling(element: SyntaxElement) -> Option<Syntax
122114
#[cfg(test)]
123115
mod tests {
124116
use super::{
125-
has_block_expr_parent, has_impl_as_prev_sibling, has_trait_as_prev_sibling, if_is_prev,
126-
inside_trait, unsafe_is_prev,
117+
has_bind_pat_parent, has_block_expr_parent, has_impl_as_prev_sibling, has_ref_pat_parent,
118+
has_trait_as_prev_sibling, if_is_prev, inside_trait, unsafe_is_prev,
127119
};
128120
use crate::completion::test_utils::check_pattern_is_applicable;
129121

@@ -193,4 +185,51 @@ mod tests {
193185
has_block_expr_parent,
194186
);
195187
}
188+
189+
#[test]
190+
fn test_has_ref_pat_parent_in_func_parameters() {
191+
check_pattern_is_applicable(
192+
r"
193+
fn my_fn(&<|>) {
194+
let a = 2;
195+
}
196+
",
197+
has_ref_pat_parent,
198+
);
199+
}
200+
201+
#[test]
202+
fn test_has_ref_pat_parent_in_let_statement() {
203+
check_pattern_is_applicable(
204+
r"
205+
fn my_fn() {
206+
let &<|>
207+
}
208+
",
209+
has_ref_pat_parent,
210+
);
211+
}
212+
213+
#[test]
214+
fn test_has_bind_pat_parent_in_func_parameters() {
215+
check_pattern_is_applicable(
216+
r"
217+
fn my_fn(m<|>) {
218+
}
219+
",
220+
has_bind_pat_parent,
221+
);
222+
}
223+
224+
#[test]
225+
fn test_has_bind_pat_parent_in_let_statement() {
226+
check_pattern_is_applicable(
227+
r"
228+
fn my_fn() {
229+
let m<|>
230+
}
231+
",
232+
has_bind_pat_parent,
233+
);
234+
}
196235
}

crates/ra_ide/src/completion/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
CompletionItem, FilePosition,
77
};
88
use hir::Semantics;
9-
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement, SyntaxToken};
9+
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement};
1010

1111
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
1212
do_completion_with_options(code, kind, &CompletionConfig::default())

0 commit comments

Comments
 (0)