From 6d105ccd93b8793592a6e89872766fcaf6c822e4 Mon Sep 17 00:00:00 2001 From: Alex Zatelepin Date: Mon, 21 Oct 2019 22:34:44 +0300 Subject: add test #2033 --- crates/ra_lsp_server/src/conv.rs | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'crates/ra_lsp_server/src/conv.rs') 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 self.map(|it| it.try_conv_with(ctx)).collect() } } + +#[cfg(test)] +mod tests { + use super::*; + use test_utils::extract_ranges; + + #[test] + fn conv_fold_line_folding_only_fixup() { + let text = r#"mod a; +mod b; +mod c; + +fn main() { + if cond { + a::do_a(); + } else { + b::do_b(); + } +}"#; + + let (ranges, text) = extract_ranges(text, "fold"); + assert_eq!(ranges.len(), 4); + let folds = vec![ + Fold { range: ranges[0], kind: FoldKind::Mods }, + Fold { range: ranges[1], kind: FoldKind::Block }, + Fold { range: ranges[2], kind: FoldKind::Block }, + Fold { range: ranges[3], kind: FoldKind::Block }, + ]; + + let line_index = LineIndex::new(&text); + let ctx = FoldConvCtx { text: &text, line_index: &line_index, line_folding_only: true }; + let converted: Vec<_> = folds.into_iter().map_conv_with(&ctx).collect(); + + let expected_lines = [(0, 2), (4, 10), (5, 6), (7, 9)]; + assert_eq!(converted.len(), expected_lines.len()); + for (folding_range, (start_line, end_line)) in converted.iter().zip(expected_lines.iter()) { + assert_eq!(folding_range.start_line, *start_line); + assert_eq!(folding_range.start_character, None); + assert_eq!(folding_range.end_line, *end_line); + assert_eq!(folding_range.end_character, None); + } + } +} -- cgit v1.2.3