Add few smoke tests for patterns and refactoring
This commit is contained in:
@@ -5,6 +5,8 @@ use crate::{
|
||||
mock_analysis::{analysis_and_position, single_file_with_position},
|
||||
CompletionItem,
|
||||
};
|
||||
use hir::Semantics;
|
||||
use ra_syntax::{AstNode, NodeOrToken, SyntaxElement, SyntaxToken};
|
||||
|
||||
pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec<CompletionItem> {
|
||||
do_completion_with_options(code, kind, &CompletionConfig::default())
|
||||
@@ -27,3 +29,15 @@ pub(crate) fn do_completion_with_options(
|
||||
kind_completions.sort_by_key(|c| c.label().to_owned());
|
||||
kind_completions
|
||||
}
|
||||
|
||||
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
|
||||
let (analysis, pos) = single_file_with_position(code);
|
||||
analysis
|
||||
.with_db(|db| {
|
||||
let sema = Semantics::new(db);
|
||||
let original_file = sema.parse(pos.file_id);
|
||||
let token = original_file.syntax().token_at_offset(pos.offset).left_biased().unwrap();
|
||||
assert!(check(NodeOrToken::Token(token)));
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user