From b06259673f9b535a63c0cabf4eeb935ff73d86d0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 2 Oct 2020 17:34:31 +0200 Subject: rename mock_analysis -> fixture --- crates/ide/src/call_hierarchy.rs | 4 +- crates/ide/src/call_info.rs | 4 +- crates/ide/src/completion.rs | 4 +- crates/ide/src/completion/test_utils.rs | 9 ++-- crates/ide/src/diagnostics.rs | 15 +++--- crates/ide/src/display/navigation_target.rs | 6 +-- crates/ide/src/expand_macro.rs | 4 +- crates/ide/src/extend_selection.rs | 4 +- crates/ide/src/fixture.rs | 70 +++++++++++++++++++++++++++ crates/ide/src/fn_references.rs | 10 ++-- crates/ide/src/goto_definition.rs | 4 +- crates/ide/src/goto_implementation.rs | 4 +- crates/ide/src/goto_type_definition.rs | 4 +- crates/ide/src/hover.rs | 16 +++---- crates/ide/src/inlay_hints.rs | 6 +-- crates/ide/src/lib.rs | 2 +- crates/ide/src/mock_analysis.rs | 73 ----------------------------- crates/ide/src/parent_module.rs | 10 ++-- crates/ide/src/references.rs | 4 +- crates/ide/src/references/rename.rs | 8 ++-- crates/ide/src/runnables.rs | 4 +- crates/ide/src/syntax_highlighting/tests.rs | 10 ++-- crates/ide/src/syntax_tree.rs | 16 +++---- crates/ide/src/typing/on_enter.rs | 4 +- 24 files changed, 143 insertions(+), 152 deletions(-) create mode 100644 crates/ide/src/fixture.rs delete mode 100644 crates/ide/src/mock_analysis.rs (limited to 'crates/ide/src') diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 0fb49de71..d2cf2cc7d 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -139,7 +139,7 @@ impl CallLocations { mod tests { use base_db::FilePosition; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; fn check_hierarchy( ra_fixture: &str, @@ -147,7 +147,7 @@ mod tests { expected_incoming: &[&str], expected_outgoing: &[&str], ) { - let (analysis, pos) = analysis_and_position(ra_fixture); + let (analysis, pos) = fixture::position(ra_fixture); let mut navs = analysis.call_hierarchy(pos).unwrap().unwrap().info; assert_eq!(navs.len(), 1); diff --git a/crates/ide/src/call_info.rs b/crates/ide/src/call_info.rs index 7e99c6b72..d7b2b926e 100644 --- a/crates/ide/src/call_info.rs +++ b/crates/ide/src/call_info.rs @@ -232,10 +232,10 @@ mod tests { use expect_test::{expect, Expect}; use test_utils::mark; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; fn check(ra_fixture: &str, expect: Expect) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let call_info = analysis.call_info(position).unwrap(); let actual = match call_info { Some(call_info) => { diff --git a/crates/ide/src/completion.rs b/crates/ide/src/completion.rs index daea2aa95..697f691b0 100644 --- a/crates/ide/src/completion.rs +++ b/crates/ide/src/completion.rs @@ -133,7 +133,7 @@ pub(crate) fn completions( #[cfg(test)] mod tests { use crate::completion::completion_config::CompletionConfig; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; struct DetailAndDocumentation<'a> { detail: &'a str, @@ -141,7 +141,7 @@ mod tests { } fn check_detail_and_documentation(ra_fixture: &str, expected: DetailAndDocumentation) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let config = CompletionConfig::default(); let completions = analysis.completions(&config, position).unwrap().unwrap(); for item in completions { diff --git a/crates/ide/src/completion/test_utils.rs b/crates/ide/src/completion/test_utils.rs index 1452d7e9e..feb8cd2a6 100644 --- a/crates/ide/src/completion/test_utils.rs +++ b/crates/ide/src/completion/test_utils.rs @@ -8,8 +8,7 @@ use test_utils::assert_eq_text; use crate::{ completion::{completion_item::CompletionKind, CompletionConfig}, - mock_analysis::analysis_and_position, - CompletionItem, + fixture, CompletionItem, }; pub(crate) fn do_completion(code: &str, kind: CompletionKind) -> Vec { @@ -80,7 +79,7 @@ pub(crate) fn check_edit_with_config( ra_fixture_after: &str, ) { let ra_fixture_after = trim_indent(ra_fixture_after); - let (analysis, position) = analysis_and_position(ra_fixture_before); + let (analysis, position) = fixture::position(ra_fixture_before); let completions: Vec = analysis.completions(&config, position).unwrap().unwrap().into(); let (completion,) = completions @@ -94,7 +93,7 @@ pub(crate) fn check_edit_with_config( } pub(crate) fn check_pattern_is_applicable(code: &str, check: fn(SyntaxElement) -> bool) { - let (analysis, pos) = analysis_and_position(code); + let (analysis, pos) = fixture::position(code); analysis .with_db(|db| { let sema = Semantics::new(db); @@ -109,6 +108,6 @@ pub(crate) fn get_all_completion_items( config: CompletionConfig, code: &str, ) -> Vec { - let (analysis, position) = analysis_and_position(code); + let (analysis, position) = fixture::position(code); analysis.completions(&config, position).unwrap().unwrap().into() } diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 906f72a42..f5d627b6e 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -218,10 +218,7 @@ mod tests { use stdx::trim_indent; use test_utils::assert_eq_text; - use crate::{ - mock_analysis::{analysis_and_position, many_files, single_file}, - DiagnosticsConfig, - }; + use crate::{fixture, DiagnosticsConfig}; /// Takes a multi-file input fixture with annotated cursor positions, /// and checks that: @@ -231,7 +228,7 @@ mod tests { fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) { let after = trim_indent(ra_fixture_after); - let (analysis, file_position) = analysis_and_position(ra_fixture_before); + let (analysis, file_position) = fixture::position(ra_fixture_before); let diagnostic = analysis .diagnostics(&DiagnosticsConfig::default(), file_position.file_id) .unwrap() @@ -260,7 +257,7 @@ mod tests { /// which has a fix that can apply to other files. fn check_apply_diagnostic_fix_in_other_file(ra_fixture_before: &str, ra_fixture_after: &str) { let ra_fixture_after = &trim_indent(ra_fixture_after); - let (analysis, file_pos) = analysis_and_position(ra_fixture_before); + let (analysis, file_pos) = fixture::position(ra_fixture_before); let current_file_id = file_pos.file_id; let diagnostic = analysis .diagnostics(&DiagnosticsConfig::default(), current_file_id) @@ -282,7 +279,7 @@ mod tests { /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics /// apply to the file containing the cursor. fn check_no_diagnostics(ra_fixture: &str) { - let (analysis, files) = many_files(ra_fixture); + let (analysis, files) = fixture::files(ra_fixture); let diagnostics = files .into_iter() .flat_map(|file_id| { @@ -293,7 +290,7 @@ mod tests { } fn check_expect(ra_fixture: &str, expect: Expect) { - let (analysis, file_id) = single_file(ra_fixture); + let (analysis, file_id) = fixture::file(ra_fixture); let diagnostics = analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap(); expect.assert_debug_eq(&diagnostics) } @@ -785,7 +782,7 @@ struct Foo { let mut config = DiagnosticsConfig::default(); config.disabled.insert("unresolved-module".into()); - let (analysis, file_id) = single_file(r#"mod foo;"#); + let (analysis, file_id) = fixture::file(r#"mod foo;"#); let diagnostics = analysis.diagnostics(&config, file_id).unwrap(); assert!(diagnostics.is_empty()); diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index bace2f3a3..cf9d617dc 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -423,11 +423,11 @@ pub(crate) fn description_from_symbol(db: &RootDatabase, symbol: &FileSymbol) -> mod tests { use expect_test::expect; - use crate::{mock_analysis::single_file, Query}; + use crate::{fixture, Query}; #[test] fn test_nav_for_symbol() { - let (analysis, _) = single_file( + let (analysis, _) = fixture::file( r#" enum FooInner { } fn foo() { enum FooInner { } } @@ -478,7 +478,7 @@ fn foo() { enum FooInner { } } #[test] fn test_world_symbols_are_case_sensitive() { - let (analysis, _) = single_file( + let (analysis, _) = fixture::file( r#" fn foo() {} struct Foo; diff --git a/crates/ide/src/expand_macro.rs b/crates/ide/src/expand_macro.rs index 8a285bcf7..8d75e0f05 100644 --- a/crates/ide/src/expand_macro.rs +++ b/crates/ide/src/expand_macro.rs @@ -122,10 +122,10 @@ fn insert_whitespaces(syn: SyntaxNode) -> String { mod tests { use expect_test::{expect, Expect}; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; fn check(ra_fixture: &str, expect: Expect) { - let (analysis, pos) = analysis_and_position(ra_fixture); + let (analysis, pos) = fixture::position(ra_fixture); let expansion = analysis.expand_macro(pos).unwrap().unwrap(); let actual = format!("{}\n{}", expansion.name, expansion.expansion); expect.assert_eq(&actual); diff --git a/crates/ide/src/extend_selection.rs b/crates/ide/src/extend_selection.rs index 34563a026..3ee0af8ad 100644 --- a/crates/ide/src/extend_selection.rs +++ b/crates/ide/src/extend_selection.rs @@ -315,12 +315,12 @@ fn adj_comments(comment: &ast::Comment, dir: Direction) -> ast::Comment { #[cfg(test)] mod tests { - use crate::mock_analysis::analysis_and_position; + use crate::fixture; use super::*; fn do_check(before: &str, afters: &[&str]) { - let (analysis, position) = analysis_and_position(&before); + let (analysis, position) = fixture::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 }; diff --git a/crates/ide/src/fixture.rs b/crates/ide/src/fixture.rs new file mode 100644 index 000000000..ed06689f0 --- /dev/null +++ b/crates/ide/src/fixture.rs @@ -0,0 +1,70 @@ +//! Utilities for creating `Analysis` instances for tests. +use base_db::fixture::ChangeFixture; +use test_utils::{extract_annotations, RangeOrOffset}; + +use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; + +/// Creates analysis for a single file. +pub(crate) fn file(ra_fixture: &str) -> (Analysis, FileId) { + let mut host = AnalysisHost::default(); + let change_fixture = ChangeFixture::parse(ra_fixture); + host.db.apply_change(change_fixture.change); + (host.analysis(), change_fixture.files[0]) +} + +/// Creates analysis for many files. +pub(crate) fn files(ra_fixture: &str) -> (Analysis, Vec) { + let mut host = AnalysisHost::default(); + let change_fixture = ChangeFixture::parse(ra_fixture); + host.db.apply_change(change_fixture.change); + (host.analysis(), change_fixture.files) +} + +/// Creates analysis from a multi-file fixture, returns positions marked with <|>. +pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) { + let mut host = AnalysisHost::default(); + let change_fixture = ChangeFixture::parse(ra_fixture); + host.db.apply_change(change_fixture.change); + let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); + let offset = match range_or_offset { + RangeOrOffset::Range(_) => panic!(), + RangeOrOffset::Offset(it) => it, + }; + (host.analysis(), FilePosition { file_id, offset }) +} + +/// Creates analysis for a single file, returns range marked with a pair of <|>. +pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) { + let mut host = AnalysisHost::default(); + let change_fixture = ChangeFixture::parse(ra_fixture); + host.db.apply_change(change_fixture.change); + let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); + let range = match range_or_offset { + RangeOrOffset::Range(it) => it, + RangeOrOffset::Offset(_) => panic!(), + }; + (host.analysis(), FileRange { file_id, range }) +} + +/// Creates analysis from a multi-file fixture, returns positions marked with <|>. +pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(FileRange, String)>) { + let mut host = AnalysisHost::default(); + let change_fixture = ChangeFixture::parse(ra_fixture); + host.db.apply_change(change_fixture.change); + let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); + let offset = match range_or_offset { + RangeOrOffset::Range(_) => panic!(), + RangeOrOffset::Offset(it) => it, + }; + + let annotations = change_fixture + .files + .iter() + .flat_map(|&file_id| { + let file_text = host.analysis().file_text(file_id).unwrap(); + let annotations = extract_annotations(&file_text); + annotations.into_iter().map(move |(range, data)| (FileRange { file_id, range }, data)) + }) + .collect(); + (host.analysis(), FilePosition { file_id, offset }, annotations) +} diff --git a/crates/ide/src/fn_references.rs b/crates/ide/src/fn_references.rs index 1989a562b..459f201ed 100644 --- a/crates/ide/src/fn_references.rs +++ b/crates/ide/src/fn_references.rs @@ -25,15 +25,14 @@ fn method_range(item: SyntaxNode, file_id: FileId) -> Option { #[cfg(test)] mod tests { - use crate::mock_analysis::analysis_and_position; + use crate::fixture; use crate::{FileRange, TextSize}; use std::ops::RangeInclusive; #[test] fn test_find_all_methods() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( r#" - //- /lib.rs fn private_fn() {<|>} pub fn pub_fn() {} @@ -48,9 +47,8 @@ mod tests { #[test] fn test_find_trait_methods() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( r#" - //- /lib.rs trait Foo { fn bar() {<|>} fn baz() {} @@ -64,7 +62,7 @@ mod tests { #[test] fn test_skip_tests() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( r#" //- /lib.rs #[test] diff --git a/crates/ide/src/goto_definition.rs b/crates/ide/src/goto_definition.rs index 5fd2d1e9a..582bf4837 100644 --- a/crates/ide/src/goto_definition.rs +++ b/crates/ide/src/goto_definition.rs @@ -103,10 +103,10 @@ mod tests { use base_db::FileRange; use syntax::{TextRange, TextSize}; - use crate::mock_analysis::analysis_and_annotations; + use crate::fixture; fn check(ra_fixture: &str) { - let (analysis, position, mut annotations) = analysis_and_annotations(ra_fixture); + let (analysis, position, mut annotations) = fixture::annotations(ra_fixture); let (mut expected, data) = annotations.pop().unwrap(); match data.as_str() { "" => (), diff --git a/crates/ide/src/goto_implementation.rs b/crates/ide/src/goto_implementation.rs index a88854d05..6c586bbd1 100644 --- a/crates/ide/src/goto_implementation.rs +++ b/crates/ide/src/goto_implementation.rs @@ -76,10 +76,10 @@ fn impls_for_trait( mod tests { use base_db::FileRange; - use crate::mock_analysis::analysis_and_annotations; + use crate::fixture; fn check(ra_fixture: &str) { - let (analysis, position, annotations) = analysis_and_annotations(ra_fixture); + let (analysis, position, annotations) = fixture::annotations(ra_fixture); let navs = analysis.goto_implementation(position).unwrap().unwrap().info; diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index b55a2dbb1..6d0df04dd 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs @@ -56,10 +56,10 @@ fn pick_best(tokens: TokenAtOffset) -> Option { mod tests { use base_db::FileRange; - use crate::mock_analysis::analysis_and_annotations; + use crate::fixture; fn check(ra_fixture: &str) { - let (analysis, position, mut annotations) = analysis_and_annotations(ra_fixture); + let (analysis, position, mut annotations) = fixture::annotations(ra_fixture); let (expected, data) = annotations.pop().unwrap(); assert!(data.is_empty()); diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 008061a39..9cf02f0a3 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -377,17 +377,17 @@ mod tests { use base_db::FileLoader; use expect_test::{expect, Expect}; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; use super::*; fn check_hover_no_result(ra_fixture: &str) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); assert!(analysis.hover(position, true).unwrap().is_none()); } fn check(ra_fixture: &str, expect: Expect) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let hover = analysis.hover(position, true).unwrap().unwrap(); let content = analysis.db.file_text(position.file_id); @@ -398,7 +398,7 @@ mod tests { } fn check_hover_no_links(ra_fixture: &str, expect: Expect) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let hover = analysis.hover(position, false).unwrap().unwrap(); let content = analysis.db.file_text(position.file_id); @@ -409,7 +409,7 @@ mod tests { } fn check_actions(ra_fixture: &str, expect: Expect) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let hover = analysis.hover(position, true).unwrap().unwrap(); expect.assert_debug_eq(&hover.info.actions) } @@ -963,7 +963,7 @@ impl Thing { "#]], ) } /* FIXME: revive these tests - let (analysis, position) = analysis_and_position( + let (analysis, position) = fixture::position( " struct Thing { x: u32 } impl Thing { @@ -977,7 +977,7 @@ impl Thing { let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup(&hover.info.markup.as_str()), ("Thing")); - let (analysis, position) = analysis_and_position( + let (analysis, position) = fixture::position( " enum Thing { A } impl Thing { @@ -990,7 +990,7 @@ impl Thing { let hover = analysis.hover(position).unwrap().unwrap(); assert_eq!(trim_markup(&hover.info.markup.as_str()), ("enum Thing")); - let (analysis, position) = analysis_and_position( + let (analysis, position) = fixture::position( " enum Thing { A } impl Thing { diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 583f39d85..0afe5f8fd 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -339,14 +339,14 @@ mod tests { use expect_test::{expect, Expect}; use test_utils::extract_annotations; - use crate::{inlay_hints::InlayHintsConfig, mock_analysis::single_file}; + use crate::{fixture, inlay_hints::InlayHintsConfig}; fn check(ra_fixture: &str) { check_with_config(InlayHintsConfig::default(), ra_fixture); } fn check_with_config(config: InlayHintsConfig, ra_fixture: &str) { - let (analysis, file_id) = single_file(ra_fixture); + let (analysis, file_id) = fixture::file(ra_fixture); let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); let actual = @@ -355,7 +355,7 @@ mod tests { } fn check_expect(config: InlayHintsConfig, ra_fixture: &str, expect: Expect) { - let (analysis, file_id) = single_file(ra_fixture); + let (analysis, file_id) = fixture::file(ra_fixture); let inlay_hints = analysis.inlay_hints(file_id, &config).unwrap(); expect.assert_debug_eq(&inlay_hints) } diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index 073b766a5..1aa673cf8 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs @@ -16,7 +16,7 @@ macro_rules! eprintln { } #[cfg(test)] -mod mock_analysis; +mod fixture; mod markup; mod prime_caches; diff --git a/crates/ide/src/mock_analysis.rs b/crates/ide/src/mock_analysis.rs deleted file mode 100644 index 838547599..000000000 --- a/crates/ide/src/mock_analysis.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! FIXME: write short doc here - -use base_db::fixture::ChangeFixture; -use test_utils::{extract_annotations, RangeOrOffset}; - -use crate::{Analysis, AnalysisHost, FileId, FilePosition, FileRange}; - -/// Creates analysis from a multi-file fixture, returns positions marked with <|>. -pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) { - let mut host = AnalysisHost::default(); - let change_fixture = ChangeFixture::parse(ra_fixture); - host.db.apply_change(change_fixture.change); - let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); - let offset = match range_or_offset { - RangeOrOffset::Range(_) => panic!(), - RangeOrOffset::Offset(it) => it, - }; - (host.analysis(), FilePosition { file_id, offset }) -} - -/// Creates analysis for a single file. -pub(crate) fn single_file(ra_fixture: &str) -> (Analysis, FileId) { - let mut host = AnalysisHost::default(); - let change_fixture = ChangeFixture::parse(ra_fixture); - host.db.apply_change(change_fixture.change); - (host.analysis(), change_fixture.files[0]) -} - -/// Creates analysis for a single file. -pub(crate) fn many_files(ra_fixture: &str) -> (Analysis, Vec) { - let mut host = AnalysisHost::default(); - let change_fixture = ChangeFixture::parse(ra_fixture); - host.db.apply_change(change_fixture.change); - (host.analysis(), change_fixture.files) -} - -/// Creates analysis for a single file, returns range marked with a pair of <|>. -pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) { - let mut host = AnalysisHost::default(); - let change_fixture = ChangeFixture::parse(ra_fixture); - host.db.apply_change(change_fixture.change); - let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); - let range = match range_or_offset { - RangeOrOffset::Range(it) => it, - RangeOrOffset::Offset(_) => panic!(), - }; - (host.analysis(), FileRange { file_id, range }) -} - -/// Creates analysis from a multi-file fixture, returns positions marked with <|>. -pub(crate) fn analysis_and_annotations( - ra_fixture: &str, -) -> (Analysis, FilePosition, Vec<(FileRange, String)>) { - let mut host = AnalysisHost::default(); - let change_fixture = ChangeFixture::parse(ra_fixture); - host.db.apply_change(change_fixture.change); - let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)"); - let offset = match range_or_offset { - RangeOrOffset::Range(_) => panic!(), - RangeOrOffset::Offset(it) => it, - }; - - let annotations = change_fixture - .files - .iter() - .flat_map(|&file_id| { - let file_text = host.analysis().file_text(file_id).unwrap(); - let annotations = extract_annotations(&file_text); - annotations.into_iter().map(move |(range, data)| (FileRange { file_id, range }, data)) - }) - .collect(); - (host.analysis(), FilePosition { file_id, offset }, annotations) -} diff --git a/crates/ide/src/parent_module.rs b/crates/ide/src/parent_module.rs index 253454476..ef94acfec 100644 --- a/crates/ide/src/parent_module.rs +++ b/crates/ide/src/parent_module.rs @@ -65,11 +65,11 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec { mod tests { use test_utils::mark; - use crate::mock_analysis::{analysis_and_position, single_file}; + use crate::fixture::{self}; #[test] fn test_resolve_parent_module() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo; @@ -84,7 +84,7 @@ mod tests { #[test] fn test_resolve_parent_module_on_module_decl() { mark::check!(test_resolve_parent_module_on_module_decl); - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo; @@ -102,7 +102,7 @@ mod tests { #[test] fn test_resolve_parent_module_for_inline() { - let (analysis, pos) = analysis_and_position( + let (analysis, pos) = fixture::position( " //- /lib.rs mod foo { @@ -118,7 +118,7 @@ mod tests { #[test] fn test_resolve_crate_root() { - let (analysis, file_id) = single_file( + let (analysis, file_id) = fixture::file( r#" //- /main.rs mod foo; diff --git a/crates/ide/src/references.rs b/crates/ide/src/references.rs index 157e0dc94..e0830eb4f 100644 --- a/crates/ide/src/references.rs +++ b/crates/ide/src/references.rs @@ -194,7 +194,7 @@ mod tests { use expect_test::{expect, Expect}; use stdx::format_to; - use crate::{mock_analysis::analysis_and_position, SearchScope}; + use crate::{fixture, SearchScope}; #[test] fn test_struct_literal_after_space() { @@ -674,7 +674,7 @@ fn g() { f(); } } fn check_with_scope(ra_fixture: &str, search_scope: Option, expect: Expect) { - let (analysis, pos) = analysis_and_position(ra_fixture); + let (analysis, pos) = fixture::position(ra_fixture); let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap(); let mut actual = String::new(); diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 366527070..8cbe1ae5a 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs @@ -275,11 +275,11 @@ mod tests { use test_utils::{assert_eq_text, mark}; use text_edit::TextEdit; - use crate::{mock_analysis::analysis_and_position, FileId}; + use crate::{fixture, FileId}; fn check(new_name: &str, ra_fixture_before: &str, ra_fixture_after: &str) { let ra_fixture_after = &trim_indent(ra_fixture_after); - let (analysis, position) = analysis_and_position(ra_fixture_before); + let (analysis, position) = fixture::position(ra_fixture_before); let source_change = analysis.rename(position, new_name).unwrap(); let mut text_edit_builder = TextEdit::builder(); let mut file_id: Option = None; @@ -297,7 +297,7 @@ mod tests { } fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let source_change = analysis.rename(position, new_name).unwrap().unwrap(); expect.assert_debug_eq(&source_change) } @@ -314,7 +314,7 @@ mod tests { #[test] fn test_rename_to_invalid_identifier() { - let (analysis, position) = analysis_and_position(r#"fn main() { let i<|> = 1; }"#); + let (analysis, position) = fixture::position(r#"fn main() { let i<|> = 1; }"#); let new_name = "invalid!"; let source_change = analysis.rename(position, new_name).unwrap(); assert!(source_change.is_none()); diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index 961066277..752ef2f21 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -292,7 +292,7 @@ fn has_test_function_or_multiple_test_submodules(module: &ast::Module) -> bool { mod tests { use expect_test::{expect, Expect}; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; use super::{RunnableAction, BENCH, BIN, DOCTEST, TEST}; @@ -302,7 +302,7 @@ mod tests { actions: &[&RunnableAction], expect: Expect, ) { - let (analysis, position) = analysis_and_position(ra_fixture); + let (analysis, position) = fixture::position(ra_fixture); let runnables = analysis.runnables(position.file_id).unwrap(); expect.assert_debug_eq(&runnables); assert_eq!( diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index eaa4e163e..694c4b7fa 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -3,7 +3,7 @@ use std::fs; use expect_test::{expect_file, ExpectFile}; use test_utils::project_dir; -use crate::{mock_analysis::single_file, FileRange, TextRange}; +use crate::{fixture, FileRange, TextRange}; #[test] fn test_highlighting() { @@ -178,7 +178,7 @@ fn accidentally_quadratic() { let file = project_dir().join("crates/syntax/test_data/accidentally_quadratic"); let src = fs::read_to_string(file).unwrap(); - let (analysis, file_id) = single_file(&src); + let (analysis, file_id) = fixture::file(&src); // let t = std::time::Instant::now(); let _ = analysis.highlight(file_id).unwrap(); @@ -187,7 +187,7 @@ fn accidentally_quadratic() { #[test] fn test_ranges() { - let (analysis, file_id) = single_file( + let (analysis, file_id) = fixture::file( r#" #[derive(Clone, Debug)] struct Foo { @@ -228,7 +228,7 @@ fn main() { #[test] fn ranges_sorted() { - let (analysis, file_id) = single_file( + let (analysis, file_id) = fixture::file( r#" #[foo(bar = "bar")] macro_rules! test {} @@ -479,7 +479,7 @@ fn test_extern_crate() { /// result as HTML, and compares it with the HTML file given as `snapshot`. /// Note that the `snapshot` file is overwritten by the rendered HTML. fn check_highlighting(ra_fixture: &str, expect: ExpectFile, rainbow: bool) { - let (analysis, file_id) = single_file(ra_fixture); + let (analysis, file_id) = fixture::file(ra_fixture); let actual_html = &analysis.highlight_as_html(file_id, rainbow).unwrap(); expect.assert_eq(actual_html) } diff --git a/crates/ide/src/syntax_tree.rs b/crates/ide/src/syntax_tree.rs index f80044959..0eed2dbd7 100644 --- a/crates/ide/src/syntax_tree.rs +++ b/crates/ide/src/syntax_tree.rs @@ -104,12 +104,12 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Optionfn foo() {}<|>"#.trim()); + let (analysis, range) = fixture::range(r#"<|>fn foo() {}<|>"#.trim()); let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap(); assert_eq_text!( @@ -206,7 +206,7 @@ FN@0..11 .trim() ); - let (analysis, range) = analysis_and_range( + let (analysis, range) = fixture::range( r#"fn test() { <|>assert!(" fn foo() { @@ -242,7 +242,7 @@ EXPR_STMT@16..58 #[test] fn test_syntax_tree_inside_string() { - let (analysis, range) = analysis_and_range( + let (analysis, range) = fixture::range( r#"fn test() { assert!(" <|>fn foo() { @@ -276,7 +276,7 @@ SOURCE_FILE@0..12 ); // With a raw string - let (analysis, range) = analysis_and_range( + let (analysis, range) = fixture::range( r###"fn test() { assert!(r#" <|>fn foo() { @@ -310,7 +310,7 @@ SOURCE_FILE@0..12 ); // With a raw string - let (analysis, range) = analysis_and_range( + let (analysis, range) = fixture::range( r###"fn test() { assert!(r<|>#" fn foo() { diff --git a/crates/ide/src/typing/on_enter.rs b/crates/ide/src/typing/on_enter.rs index f7d46146c..a0dc4b9df 100644 --- a/crates/ide/src/typing/on_enter.rs +++ b/crates/ide/src/typing/on_enter.rs @@ -109,10 +109,10 @@ mod tests { use stdx::trim_indent; use test_utils::{assert_eq_text, mark}; - use crate::mock_analysis::analysis_and_position; + use crate::fixture; fn apply_on_enter(before: &str) -> Option { - let (analysis, position) = analysis_and_position(&before); + let (analysis, position) = fixture::position(&before); let result = analysis.on_enter(position).unwrap()?; let mut actual = analysis.file_text(position.file_id).unwrap().to_string(); -- cgit v1.2.3