mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-30 02:33:55 +00:00
rename mock_analysis -> fixture
This commit is contained in:
parent
09348b2474
commit
b06259673f
@ -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);
|
||||
|
@ -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) => {
|
||||
|
@ -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 {
|
||||
|
@ -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<CompletionItem> {
|
||||
@ -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<CompletionItem> =
|
||||
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<CompletionItem> {
|
||||
let (analysis, position) = analysis_and_position(code);
|
||||
let (analysis, position) = fixture::position(code);
|
||||
analysis.completions(&config, position).unwrap().unwrap().into()
|
||||
}
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 };
|
||||
|
@ -1,12 +1,27 @@
|
||||
//! FIXME: write short doc here
|
||||
|
||||
//! 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<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)
|
||||
}
|
||||
|
||||
/// Creates analysis from a multi-file fixture, returns positions marked with <|>.
|
||||
pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition) {
|
||||
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);
|
||||
@ -18,24 +33,8 @@ pub(crate) fn analysis_and_position(ra_fixture: &str) -> (Analysis, FilePosition
|
||||
(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<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)
|
||||
}
|
||||
|
||||
/// Creates analysis for a single file, returns range marked with a pair of <|>.
|
||||
pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) {
|
||||
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);
|
||||
@ -48,9 +47,7 @@ pub(crate) fn analysis_and_range(ra_fixture: &str) -> (Analysis, FileRange) {
|
||||
}
|
||||
|
||||
/// 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)>) {
|
||||
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);
|
@ -25,15 +25,14 @@ fn method_range(item: SyntaxNode, file_id: FileId) -> Option<FileRange> {
|
||||
|
||||
#[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]
|
||||
|
@ -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() {
|
||||
"" => (),
|
||||
|
@ -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;
|
||||
|
||||
|
@ -56,10 +56,10 @@ fn pick_best(tokens: TokenAtOffset<SyntaxToken>) -> Option<SyntaxToken> {
|
||||
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());
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ macro_rules! eprintln {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod mock_analysis;
|
||||
mod fixture;
|
||||
|
||||
mod markup;
|
||||
mod prime_caches;
|
||||
|
@ -65,11 +65,11 @@ pub(crate) fn crate_for(db: &RootDatabase, file_id: FileId) -> Vec<CrateId> {
|
||||
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;
|
||||
|
@ -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<SearchScope>, 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();
|
||||
|
@ -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<FileId> = 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());
|
||||
|
@ -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!(
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -104,12 +104,12 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St
|
||||
mod tests {
|
||||
use test_utils::assert_eq_text;
|
||||
|
||||
use crate::mock_analysis::{analysis_and_range, single_file};
|
||||
use crate::fixture;
|
||||
|
||||
#[test]
|
||||
fn test_syntax_tree_without_range() {
|
||||
// Basic syntax
|
||||
let (analysis, file_id) = single_file(r#"fn foo() {}"#);
|
||||
let (analysis, file_id) = fixture::file(r#"fn foo() {}"#);
|
||||
let syn = analysis.syntax_tree(file_id, None).unwrap();
|
||||
|
||||
assert_eq_text!(
|
||||
@ -132,7 +132,7 @@ SOURCE_FILE@0..11
|
||||
.trim()
|
||||
);
|
||||
|
||||
let (analysis, file_id) = single_file(
|
||||
let (analysis, file_id) = fixture::file(
|
||||
r#"
|
||||
fn test() {
|
||||
assert!("
|
||||
@ -184,7 +184,7 @@ SOURCE_FILE@0..60
|
||||
|
||||
#[test]
|
||||
fn test_syntax_tree_with_range() {
|
||||
let (analysis, range) = analysis_and_range(r#"<|>fn 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() {
|
||||
|
@ -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<String> {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user