Remove duplication

This commit is contained in:
Aleksey Kladov 2020-06-24 11:31:30 +02:00
parent c6795fb83a
commit c749fe223b
8 changed files with 34 additions and 41 deletions

View file

@ -215,7 +215,7 @@ impl CallInfo {
mod tests {
use test_utils::mark;
use crate::mock_analysis::single_file_with_position;
use crate::mock_analysis::analysis_and_position;
use super::*;
@ -231,7 +231,7 @@ mod tests {
}
fn call_info_helper(text: &str) -> Option<CallInfo> {
let (analysis, position) = single_file_with_position(text);
let (analysis, position) = analysis_and_position(text);
analysis.call_info(position).unwrap()
}
@ -530,7 +530,7 @@ By default this method stops actor's `Context`."#
#[test]
fn call_info_bad_offset() {
mark::check!(call_info_bad_offset);
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
r#"fn foo(x: u32, y: u32) -> u32 {x + y}
fn bar() { foo <|> (3, ); }"#,
);

View file

@ -2,7 +2,7 @@
use crate::{
completion::{completion_item::CompletionKind, CompletionConfig},
mock_analysis::{analysis_and_position, single_file_with_position},
mock_analysis::analysis_and_position,
CompletionItem,
};
use hir::Semantics;
@ -33,7 +33,7 @@ fn get_all_completion_items(code: &str, options: &CompletionConfig) -> Vec<Compl
let (analysis, position) = if code.contains("//-") {
analysis_and_position(code)
} else {
single_file_with_position(code)
analysis_and_position(code)
};
analysis.completions(options, position).unwrap().unwrap().into()
}
@ -55,7 +55,7 @@ pub(crate) fn completion_list_with_options(
}
pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) {
let (analysis, pos) = single_file_with_position(code);
let (analysis, pos) = analysis_and_position(code);
analysis
.with_db(|db| {
let sema = Semantics::new(db);

View file

@ -315,12 +315,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment {
#[cfg(test)]
mod tests {
use crate::mock_analysis::single_file_with_position;
use crate::mock_analysis::analysis_and_position;
use super::*;
fn do_check(before: &str, afters: &[&str]) {
let (analysis, position) = single_file_with_position(&before);
let (analysis, position) = analysis_and_position(&before);
let before = analysis.file_text(position.file_id).unwrap();
let range = TextRange::empty(position.offset);
let mut frange = FileRange { file_id: position.file_id, range };

View file

@ -399,7 +399,7 @@ mod tests {
use ra_db::FileLoader;
use ra_syntax::TextRange;
use crate::mock_analysis::{analysis_and_position, single_file_with_position};
use crate::mock_analysis::analysis_and_position;
fn trim_markup(s: &str) -> &str {
s.trim_start_matches("```rust\n").trim_end_matches("\n```")
@ -442,7 +442,7 @@ mod tests {
#[test]
fn hover_shows_type_of_an_expression() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
r#"
pub fn foo() -> u32 { 1 }
@ -641,7 +641,7 @@ fn main() {
#[test]
fn hover_some() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
enum Option<T> { Some(T) }
use Option::Some;
@ -654,7 +654,7 @@ fn main() {
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("Option\n```\n\n```rust\nSome"));
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
enum Option<T> { Some(T) }
use Option::Some;
@ -720,21 +720,21 @@ The Some variant
#[test]
fn hover_for_local_variable() {
let (analysis, position) = single_file_with_position("fn func(foo: i32) { fo<|>o; }");
let (analysis, position) = analysis_and_position("fn func(foo: i32) { fo<|>o; }");
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
}
#[test]
fn hover_for_local_variable_pat() {
let (analysis, position) = single_file_with_position("fn func(fo<|>o: i32) {}");
let (analysis, position) = analysis_and_position("fn func(fo<|>o: i32) {}");
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
}
#[test]
fn hover_local_var_edge() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
fn func(foo: i32) { if true { <|>foo; }; }
",
@ -745,14 +745,14 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn hover_for_param_edge() {
let (analysis, position) = single_file_with_position("fn func(<|>foo: i32) {}");
let (analysis, position) = analysis_and_position("fn func(<|>foo: i32) {}");
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("i32"));
}
#[test]
fn test_hover_infer_associated_method_result() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
struct Thing { x: u32 }
@ -773,7 +773,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_infer_associated_method_exact() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
mod wrapper {
struct Thing { x: u32 }
@ -799,7 +799,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_infer_associated_const_in_pattern() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
struct X;
impl X {
@ -821,7 +821,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_self() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
struct Thing { x: u32 }
impl Thing {
@ -835,7 +835,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
/* FIXME: revive these tests
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
struct Thing { x: u32 }
impl Thing {
@ -849,7 +849,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("Thing"));
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
enum Thing { A }
impl Thing {
@ -862,7 +862,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
let hover = analysis.hover(position).unwrap().unwrap();
assert_eq!(trim_markup_opt(hover.info.first()), Some("enum Thing"));
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
enum Thing { A }
impl Thing {
@ -878,7 +878,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_shadowing_pat() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
fn x() {}
@ -894,7 +894,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_macro_invocation() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
macro_rules! foo {
() => {}
@ -911,7 +911,7 @@ fn func(foo: i32) { if true { <|>foo; }; }
#[test]
fn test_hover_tuple_field() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
struct TS(String, i32<|>);
",

View file

@ -221,11 +221,6 @@ pub fn single_file(ra_fixture: &str) -> (Analysis, FileId) {
(mock.analysis(), file_id)
}
/// Creates analysis for a single file, returns position marked with <|>.
pub fn single_file_with_position(ra_fixture: &str) -> (Analysis, FilePosition) {
analysis_and_position(ra_fixture)
}
/// Creates analysis for a single file, returns range marked with a pair of <|>.
pub fn single_file_with_range(ra_fixture: &str) -> (Analysis, FileRange) {
let mut mock = MockAnalysis::new();

View file

@ -191,7 +191,7 @@ fn get_struct_def_name_for_struct_literal_search(
#[cfg(test)]
mod tests {
use crate::{
mock_analysis::{analysis_and_position, single_file_with_position, MockAnalysis},
mock_analysis::{analysis_and_position, MockAnalysis},
Declaration, Reference, ReferenceSearchResult, SearchScope,
};
@ -653,7 +653,7 @@ fn main() {
}
fn get_all_refs(ra_fixture: &str) -> ReferenceSearchResult {
let (analysis, position) = single_file_with_position(ra_fixture);
let (analysis, position) = analysis_and_position(ra_fixture);
analysis.find_all_refs(position, None).unwrap().unwrap()
}

View file

@ -271,12 +271,10 @@ fn rename_reference(
mod tests {
use insta::assert_debug_snapshot;
use ra_text_edit::TextEditBuilder;
use stdx::trim_indent;
use test_utils::{assert_eq_text, mark};
use crate::{
mock_analysis::analysis_and_position, mock_analysis::single_file_with_position, FileId,
};
use stdx::trim_indent;
use crate::{mock_analysis::analysis_and_position, FileId};
#[test]
fn test_rename_to_underscore() {
@ -310,7 +308,7 @@ mod tests {
#[test]
fn test_rename_to_invalid_identifier() {
let (analysis, position) = single_file_with_position(
let (analysis, position) = analysis_and_position(
"
fn main() {
let i<|> = 1;
@ -1056,7 +1054,7 @@ pub mod foo<|>;
fn test_rename(ra_fixture_before: &str, new_name: &str, ra_fixture_after: &str) {
let ra_fixture_after = &trim_indent(ra_fixture_after);
let (analysis, position) = single_file_with_position(ra_fixture_before);
let (analysis, position) = analysis_and_position(ra_fixture_before);
let source_change = analysis.rename(position, new_name).unwrap();
let mut text_edit_builder = TextEditBuilder::default();
let mut file_id: Option<FileId> = None;

View file

@ -77,11 +77,11 @@ fn node_indent(file: &SourceFile, token: &SyntaxToken) -> Option<SmolStr> {
mod tests {
use test_utils::assert_eq_text;
use crate::mock_analysis::single_file_with_position;
use crate::mock_analysis::analysis_and_position;
use stdx::trim_indent;
fn apply_on_enter(before: &str) -> Option<String> {
let (analysis, position) = single_file_with_position(&before);
let (analysis, position) = analysis_and_position(&before);
let result = analysis.on_enter(position).unwrap()?;
let mut actual = analysis.file_text(position.file_id).unwrap().to_string();