From 4484908a867fc742104d6ffe63b865a411203276 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:03:08 +0200 Subject: Rewrite goto definition tests --- crates/ra_ide/src/mock_analysis.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src/mock_analysis.rs') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 889b84c59..120d29aa0 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -3,11 +3,15 @@ use std::sync::Arc; use ra_cfg::CfgOptions; use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; -use test_utils::{extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER}; +use test_utils::{ + extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, +}; use crate::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, }; +use ra_syntax::TextRange; +use rustc_hash::FxHashMap; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -77,6 +81,28 @@ impl MockAnalysis { .expect("no file in this mock"); FileId(idx as u32 + 1) } + pub fn annotations(&self) -> FxHashMap> { + self.files + .iter() + .enumerate() + .filter_map(|(idx, fixture)| { + let file_id = FileId(idx as u32 + 1); + let annotations = extract_annotations(&fixture.text); + if annotations.is_empty() { + return None; + } + Some((file_id, annotations)) + }) + .collect() + } + pub fn annotation(&self) -> (FileRange, String) { + let all = self.annotations(); + assert_eq!(all.len(), 1); + let (file_id, mut for_file) = all.into_iter().next().unwrap(); + assert_eq!(for_file.len(), 1); + let (range, data) = for_file.pop().unwrap(); + (FileRange { file_id, range}, data) + } pub fn analysis_host(self) -> AnalysisHost { let mut host = AnalysisHost::default(); let mut change = AnalysisChange::new(); -- cgit v1.2.3 From 34072d53b683805f449bf106d16788f171ca3522 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 30 Jun 2020 13:20:16 +0200 Subject: Rewrite goto implementation tests --- crates/ra_ide/src/mock_analysis.rs | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'crates/ra_ide/src/mock_analysis.rs') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index 120d29aa0..db6d50694 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -10,8 +10,6 @@ use test_utils::{ use crate::{ Analysis, AnalysisChange, AnalysisHost, CrateGraph, Edition, FileId, FilePosition, FileRange, }; -use ra_syntax::TextRange; -use rustc_hash::FxHashMap; /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis /// from a set of in-memory files. @@ -81,27 +79,23 @@ impl MockAnalysis { .expect("no file in this mock"); FileId(idx as u32 + 1) } - pub fn annotations(&self) -> FxHashMap> { + pub fn annotations(&self) -> Vec<(FileRange, String)> { self.files .iter() .enumerate() - .filter_map(|(idx, fixture)| { + .flat_map(|(idx, fixture)| { let file_id = FileId(idx as u32 + 1); let annotations = extract_annotations(&fixture.text); - if annotations.is_empty() { - return None; - } - Some((file_id, annotations)) + annotations + .into_iter() + .map(move |(range, data)| (FileRange { file_id, range }, data)) }) .collect() } pub fn annotation(&self) -> (FileRange, String) { - let all = self.annotations(); + let mut all = self.annotations(); assert_eq!(all.len(), 1); - let (file_id, mut for_file) = all.into_iter().next().unwrap(); - assert_eq!(for_file.len(), 1); - let (range, data) = for_file.pop().unwrap(); - (FileRange { file_id, range}, data) + all.pop().unwrap() } pub fn analysis_host(self) -> AnalysisHost { let mut host = AnalysisHost::default(); -- cgit v1.2.3 From 80386ca5be78d8ea65483df3edeec1a89b09a5a3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Jul 2020 10:03:07 +0200 Subject: Use Strings for display names --- crates/ra_ide/src/mock_analysis.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_ide/src/mock_analysis.rs') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index db6d50694..a393d3dba 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -130,7 +130,7 @@ impl MockAnalysis { let other_crate = crate_graph.add_crate_root( file_id, edition, - Some(CrateName::new(crate_name).unwrap()), + Some(crate_name.to_string()), cfg, env, Default::default(), -- cgit v1.2.3 From fb0bc941a504e2ef5cf8766e0faa58bfeaecc712 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Jul 2020 14:33:03 +0200 Subject: Cleanup diagnostics tests --- crates/ra_ide/src/mock_analysis.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'crates/ra_ide/src/mock_analysis.rs') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index a393d3dba..b28054688 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -71,20 +71,13 @@ impl MockAnalysis { } pub fn id_of(&self, path: &str) -> FileId { - let (idx, _) = self - .files - .iter() - .enumerate() - .find(|(_, data)| path == data.path) - .expect("no file in this mock"); - FileId(idx as u32 + 1) + let (file_id, _) = + self.files().find(|(_, data)| path == data.path).expect("no file in this mock"); + file_id } pub fn annotations(&self) -> Vec<(FileRange, String)> { - self.files - .iter() - .enumerate() - .flat_map(|(idx, fixture)| { - let file_id = FileId(idx as u32 + 1); + self.files() + .flat_map(|(file_id, fixture)| { let annotations = extract_annotations(&fixture.text); annotations .into_iter() @@ -92,6 +85,9 @@ impl MockAnalysis { }) .collect() } + pub fn files(&self) -> impl Iterator + '_ { + self.files.iter().enumerate().map(|(idx, fixture)| (FileId(idx as u32 + 1), fixture)) + } pub fn annotation(&self) -> (FileRange, String) { let mut all = self.annotations(); assert_eq!(all.len(), 1); -- cgit v1.2.3 From b68ef1231daf6eb1abeb06a30dc89af1254b833d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 21 Jul 2020 17:17:21 +0200 Subject: More Rustic API for Env --- crates/ra_ide/src/mock_analysis.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_ide/src/mock_analysis.rs') diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index b28054688..c7e0f4b58 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use ra_cfg::CfgOptions; -use ra_db::{CrateName, Env, FileSet, SourceRoot, VfsPath}; +use ra_db::{CrateName, FileSet, SourceRoot, VfsPath}; use test_utils::{ extract_annotations, extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, }; @@ -110,7 +110,7 @@ impl MockAnalysis { data.edition.and_then(|it| it.parse().ok()).unwrap_or(Edition::Edition2018); let file_id = FileId(i as u32 + 1); - let env = Env::from(data.env.iter()); + let env = data.env.into_iter().collect(); if path == "/lib.rs" || path == "/main.rs" { root_crate = Some(crate_graph.add_crate_root( file_id, -- cgit v1.2.3