aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorHirokazu Hata <[email protected]>2019-01-03 03:01:52 +0000
committerHirokazu Hata <[email protected]>2019-01-03 03:07:20 +0000
commitf5992964edb0e6dba7970c344b46bfd75f57e9a0 (patch)
tree4e97d6c21771a2b470580277796f5c87150cdf61 /crates/ra_analysis/src
parenta4c30d750411f09a999b201631000a08e88907fd (diff)
Add Analysis#teype_of test
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/mock_analysis.rs28
1 files changed, 27 insertions, 1 deletions
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 {
55 (res, position) 55 (res, position)
56 } 56 }
57 57
58 /// Same as `with_files`, but requires that a single file contains two `<|>` marker,
59 /// whose range is also returned.
60 pub fn with_files_and_range(fixture: &str) -> (MockAnalysis, FileRange) {
61 let mut range = None;
62 let mut res = MockAnalysis::new();
63 for entry in parse_fixture(fixture) {
64 if entry.text.contains(CURSOR_MARKER) {
65 assert!(
66 range.is_none(),
67 "only two marker (<|>) per fixture is allowed"
68 );
69 range = Some(res.add_file_with_range(&entry.meta, &entry.text));
70 } else {
71 res.add_file(&entry.meta, &entry.text);
72 }
73 }
74 let range = range.expect("expected two marker (<|>)");
75 (res, range)
76 }
77
58 pub fn add_file(&mut self, path: &str, text: &str) -> FileId { 78 pub fn add_file(&mut self, path: &str, text: &str) -> FileId {
59 let file_id = FileId((self.files.len() + 1) as u32); 79 let file_id = FileId((self.files.len() + 1) as u32);
60 self.files.push((path.to_string(), text.to_string())); 80 self.files.push((path.to_string(), text.to_string()));
@@ -102,12 +122,18 @@ impl MockAnalysis {
102 } 122 }
103} 123}
104 124
105/// Creates analysis from a multi-file fixture, returns positions marked with <|>. 125/// Creates analysis from a multi-file fixture, returns positions marked with a <|>.
106pub fn analysis_and_position(fixture: &str) -> (Analysis, FilePosition) { 126pub fn analysis_and_position(fixture: &str) -> (Analysis, FilePosition) {
107 let (mock, position) = MockAnalysis::with_files_and_position(fixture); 127 let (mock, position) = MockAnalysis::with_files_and_position(fixture);
108 (mock.analysis(), position) 128 (mock.analysis(), position)
109} 129}
110 130
131/// Creates analysis from a multi-file fixture, returns ranges marked with two <|>.
132pub fn analysis_and_range(fixture: &str) -> (Analysis, FileRange) {
133 let (mock, range) = MockAnalysis::with_files_and_range(fixture);
134 (mock.analysis(), range)
135}
136
111/// Creates analysis for a single file. 137/// Creates analysis for a single file.
112pub fn single_file(code: &str) -> (Analysis, FileId) { 138pub fn single_file(code: &str) -> (Analysis, FileId) {
113 let mut mock = MockAnalysis::new(); 139 let mut mock = MockAnalysis::new();