From f5992964edb0e6dba7970c344b46bfd75f57e9a0 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Thu, 3 Jan 2019 12:01:52 +0900 Subject: Add Analysis#teype_of test --- crates/ra_analysis/src/mock_analysis.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'crates/ra_analysis/src') diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs index 960529404..b37371499 100644 --- a/crates/ra_analysis/src/mock_analysis.rs +++ b/crates/ra_analysis/src/mock_analysis.rs @@ -55,6 +55,26 @@ impl MockAnalysis { (res, position) } + /// Same as `with_files`, but requires that a single file contains two `<|>` marker, + /// whose range is also returned. + pub fn with_files_and_range(fixture: &str) -> (MockAnalysis, FileRange) { + let mut range = None; + let mut res = MockAnalysis::new(); + for entry in parse_fixture(fixture) { + if entry.text.contains(CURSOR_MARKER) { + assert!( + range.is_none(), + "only two marker (<|>) per fixture is allowed" + ); + range = Some(res.add_file_with_range(&entry.meta, &entry.text)); + } else { + res.add_file(&entry.meta, &entry.text); + } + } + let range = range.expect("expected two marker (<|>)"); + (res, range) + } + pub fn add_file(&mut self, path: &str, text: &str) -> FileId { let file_id = FileId((self.files.len() + 1) as u32); self.files.push((path.to_string(), text.to_string())); @@ -102,12 +122,18 @@ impl MockAnalysis { } } -/// Creates analysis from a multi-file fixture, returns positions marked with <|>. +/// Creates analysis from a multi-file fixture, returns positions marked with a <|>. pub fn analysis_and_position(fixture: &str) -> (Analysis, FilePosition) { let (mock, position) = MockAnalysis::with_files_and_position(fixture); (mock.analysis(), position) } +/// Creates analysis from a multi-file fixture, returns ranges marked with two <|>. +pub fn analysis_and_range(fixture: &str) -> (Analysis, FileRange) { + let (mock, range) = MockAnalysis::with_files_and_range(fixture); + (mock.analysis(), range) +} + /// Creates analysis for a single file. pub fn single_file(code: &str) -> (Analysis, FileId) { let mut mock = MockAnalysis::new(); -- cgit v1.2.3