From 21d3a2fb76ff68d42b43534ed0110d9eec8784e8 Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David Date: Sun, 4 Dec 2022 01:08:36 -0500 Subject: [PATCH] add simple test --- helix-core/src/comment.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index e05a23f1acf8a..fc617cd3df7d1 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -327,4 +327,30 @@ mod test { // TODO: account for uncommenting with uneven comment indentation } + + #[test] + fn test_find_block_comments() { + // three lines 5 characters. + let mut doc = Rope::from("1\n2\n3"); + // select whole document + let selection = Selection::single(0, doc.len_chars()); + + let text = doc.slice(..); + + let res = find_block_comments("/*", "*/", text, &selection); + + assert_eq!(res, (false, vec![(Range::new(0, 5), 0, 4, 0, 0)])); + + // comment + let transaction = toggle_block_comments(&doc, &selection, None); + transaction.apply(&mut doc); + + assert_eq!(doc, "/* 1\n2\n3 */"); + + // uncomment + let selection = Selection::single(0, doc.len_chars()); + let transaction = toggle_block_comments(&doc, &selection, None); + transaction.apply(&mut doc); + assert_eq!(doc, "1\n2\n3"); + } }