aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/src/conv.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 173580dee..ee503633d 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -547,3 +547,46 @@ where
547 self.map(|it| it.try_conv_with(ctx)).collect() 547 self.map(|it| it.try_conv_with(ctx)).collect()
548 } 548 }
549} 549}
550
551#[cfg(test)]
552mod tests {
553 use super::*;
554 use test_utils::extract_ranges;
555
556 #[test]
557 fn conv_fold_line_folding_only_fixup() {
558 let text = r#"<fold>mod a;
559mod b;
560mod c;</fold>
561
562fn main() <fold>{
563 if cond <fold>{
564 a::do_a();
565 }</fold> else <fold>{
566 b::do_b();
567 }</fold>
568}</fold>"#;
569
570 let (ranges, text) = extract_ranges(text, "fold");
571 assert_eq!(ranges.len(), 4);
572 let folds = vec![
573 Fold { range: ranges[0], kind: FoldKind::Mods },
574 Fold { range: ranges[1], kind: FoldKind::Block },
575 Fold { range: ranges[2], kind: FoldKind::Block },
576 Fold { range: ranges[3], kind: FoldKind::Block },
577 ];
578
579 let line_index = LineIndex::new(&text);
580 let ctx = FoldConvCtx { text: &text, line_index: &line_index, line_folding_only: true };
581 let converted: Vec<_> = folds.into_iter().map_conv_with(&ctx).collect();
582
583 let expected_lines = [(0, 2), (4, 10), (5, 6), (7, 9)];
584 assert_eq!(converted.len(), expected_lines.len());
585 for (folding_range, (start_line, end_line)) in converted.iter().zip(expected_lines.iter()) {
586 assert_eq!(folding_range.start_line, *start_line);
587 assert_eq!(folding_range.start_character, None);
588 assert_eq!(folding_range.end_line, *end_line);
589 assert_eq!(folding_range.end_character, None);
590 }
591 }
592}