diff options
Diffstat (limited to 'crates/ra_editor/src')
-rw-r--r-- | crates/ra_editor/src/folding_ranges.rs | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/crates/ra_editor/src/folding_ranges.rs b/crates/ra_editor/src/folding_ranges.rs index 8aabb5e0b..a1699d449 100644 --- a/crates/ra_editor/src/folding_ranges.rs +++ b/crates/ra_editor/src/folding_ranges.rs | |||
@@ -120,54 +120,65 @@ fn contiguous_range_for_comment<'a>( | |||
120 | #[cfg(test)] | 120 | #[cfg(test)] |
121 | mod tests { | 121 | mod tests { |
122 | use super::*; | 122 | use super::*; |
123 | use test_utils::extract_ranges; | ||
124 | |||
125 | fn do_check(text: &str, fold_kinds: &[FoldKind]) { | ||
126 | let (ranges, text) = extract_ranges(text); | ||
127 | let file = File::parse(&text); | ||
128 | let folds = folding_ranges(&file); | ||
129 | |||
130 | assert_eq!(folds.len(), ranges.len()); | ||
131 | for ((fold, range), fold_kind) in folds.into_iter().zip(ranges.into_iter()).zip(fold_kinds.into_iter()) { | ||
132 | assert_eq!(fold.range.start(), range.start()); | ||
133 | assert_eq!(fold.range.end(), range.end()); | ||
134 | assert_eq!(&fold.kind, fold_kind); | ||
135 | } | ||
136 | } | ||
123 | 137 | ||
124 | #[test] | 138 | #[test] |
125 | fn test_fold_comments() { | 139 | fn test_fold_comments() { |
126 | let text = r#" | 140 | let text = r#" |
127 | // Hello | 141 | <|>// Hello |
128 | // this is a multiline | 142 | // this is a multiline |
129 | // comment | 143 | // comment |
130 | // | 144 | //<|> |
131 | 145 | ||
132 | // But this is not | 146 | // But this is not |
133 | 147 | ||
134 | fn main() { | 148 | fn main() { |
135 | // We should | 149 | <|>// We should |
136 | // also | 150 | // also |
137 | // fold | 151 | // fold |
138 | // this one. | 152 | // this one.<|> |
153 | <|>//! But this one is different | ||
154 | //! because it has another flavor<|> | ||
155 | <|>/* As does this | ||
156 | multiline comment */<|> | ||
139 | }"#; | 157 | }"#; |
140 | 158 | ||
141 | let file = File::parse(&text); | 159 | let fold_kinds = &[ |
142 | let folds = folding_ranges(&file); | 160 | FoldKind::Comment, |
143 | assert_eq!(folds.len(), 2); | 161 | FoldKind::Comment, |
144 | assert_eq!(folds[0].range.start(), 1.into()); | 162 | FoldKind::Comment, |
145 | assert_eq!(folds[0].range.end(), 46.into()); | 163 | FoldKind::Comment, |
146 | assert_eq!(folds[0].kind, FoldKind::Comment); | 164 | ]; |
147 | 165 | do_check(text, fold_kinds); | |
148 | assert_eq!(folds[1].range.start(), 84.into()); | ||
149 | assert_eq!(folds[1].range.end(), 137.into()); | ||
150 | assert_eq!(folds[1].kind, FoldKind::Comment); | ||
151 | } | 166 | } |
152 | 167 | ||
153 | #[test] | 168 | #[test] |
154 | fn test_fold_imports() { | 169 | fn test_fold_imports() { |
155 | let text = r#" | 170 | let text = r#" |
156 | use std::{ | 171 | <|>use std::{ |
157 | str, | 172 | str, |
158 | vec, | 173 | vec, |
159 | io as iop | 174 | io as iop |
160 | }; | 175 | };<|> |
161 | 176 | ||
162 | fn main() { | 177 | fn main() { |
163 | }"#; | 178 | }"#; |
164 | 179 | ||
165 | let file = File::parse(&text); | 180 | let folds = &[FoldKind::Imports]; |
166 | let folds = folding_ranges(&file); | 181 | do_check(text, folds); |
167 | assert_eq!(folds.len(), 1); | ||
168 | assert_eq!(folds[0].range.start(), 1.into()); | ||
169 | assert_eq!(folds[0].range.end(), 46.into()); | ||
170 | assert_eq!(folds[0].kind, FoldKind::Imports); | ||
171 | } | 182 | } |
172 | 183 | ||
173 | 184 | ||