test: uncomment previosly skipped tests

pull/12759/head
Nikita Revenco 2025-02-01 21:00:58 +00:00 committed by Nik Revenco
parent 371dec3774
commit de7884c7dd
2 changed files with 35 additions and 32 deletions

View File

@ -80,7 +80,7 @@ fn find_line_comment(
} }
// for a given range and syntax, determine if there are additional tokens to consider // for a given range and syntax, determine if there are additional tokens to consider
pub type GetCommentTokens<'a> = pub type GetInjectedTokens<'a> =
Box<dyn FnMut(usize, usize) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) + 'a>; Box<dyn FnMut(usize, usize) -> (Option<Vec<String>>, Option<Vec<BlockCommentToken>>) + 'a>;
#[must_use] #[must_use]
@ -306,15 +306,14 @@ pub fn toggle_block_comments(
ranges: &Vec<Range>, ranges: &Vec<Range>,
tokens: &[BlockCommentToken], tokens: &[BlockCommentToken],
) -> Vec<Change> { ) -> Vec<Change> {
todo!() let text = doc.slice(..);
// let text = doc.slice(..); let (commented, comment_changes) = find_block_comments(tokens, text, ranges);
// let (commented, comment_changes) = find_block_comments(tokens, text, selection); let (changes, _ranges) =
// let (mut transaction, ranges) = create_block_comment_transaction(doc, ranges, commented, comment_changes);
// create_block_comment_transaction(doc, selection, commented, comment_changes);
// if !commented { // if !commented {
// transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index())); // changes = changes.with_selection(Selection::new(ranges, selection.primary_index()));
// } // }
// transaction changes
} }
pub fn split_lines_of_range(text: RopeSlice, range: &Range) -> Vec<Range> { pub fn split_lines_of_range(text: RopeSlice, range: &Range) -> Vec<Range> {
@ -445,26 +444,30 @@ mod test {
) )
); );
// // comment // comment
// let transaction = toggle_block_comments(&doc, &range, &[BlockCommentToken::default()]); let changes =
// transaction.apply(&mut doc); toggle_block_comments(&doc, &vec![range], &[BlockCommentToken::default()]);
let transaction = Transaction::change(&doc, changes.into_iter());
transaction.apply(&mut doc);
// assert_eq!(doc, "/* 1\n2\n3 */"); assert_eq!(doc, "/* 1\n2\n3 */");
// // uncomment // uncomment
// let selection = Selection::single(0, doc.len_chars()); let range = Range::new(0, doc.len_chars());
// let transaction = let changes =
// toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]); toggle_block_comments(&doc, &vec![range], &[BlockCommentToken::default()]);
// transaction.apply(&mut doc); let transaction = Transaction::change(&doc, changes.into_iter());
// assert_eq!(doc, "1\n2\n3"); transaction.apply(&mut doc);
assert_eq!(doc, "1\n2\n3");
// // don't panic when there is just a space in comment // don't panic when there is just a space in comment
// doc = Rope::from("/* */"); doc = Rope::from("/* */");
// let selection = Selection::single(0, doc.len_chars()); let range = Range::new(0, doc.len_chars());
// let transaction = let changes =
// toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]); toggle_block_comments(&doc, &vec![range], &[BlockCommentToken::default()]);
// transaction.apply(&mut doc); let transaction = Transaction::change(&doc, changes.into_iter());
// assert_eq!(doc, ""); transaction.apply(&mut doc);
assert_eq!(doc, "");
} }
/// Test, if `get_comment_tokens` works, even if the content of the file includes chars, whose /// Test, if `get_comment_tokens` works, even if the content of the file includes chars, whose

View File

@ -5101,7 +5101,7 @@ pub type CommentTransactionFn<'a> = Box<
Option<&[BlockCommentToken]>, Option<&[BlockCommentToken]>,
&Rope, &Rope,
&Selection, &Selection,
comment::GetCommentTokens<'a>, comment::GetInjectedTokens<'a>,
) -> Transaction ) -> Transaction
+ 'a, + 'a,
>; >;
@ -5115,7 +5115,7 @@ fn toggle_comments_impl<'a>(
let rope = doc.text(); let rope = doc.text();
let selection = doc.selection(view.id); let selection = doc.selection(view.id);
// The default comment tokens to fallback to if no comment tokens are found for the injection layer. // The comment tokens to fallback to if no comment tokens are found for the injection layer.
let doc_line_token: Option<&str> = doc let doc_line_token: Option<&str> = doc
.language_config() .language_config()
.and_then(|lc| lc.comment_tokens.as_ref()) .and_then(|lc| lc.comment_tokens.as_ref())
@ -5194,8 +5194,8 @@ fn toggle_comments(cx: &mut Context) {
let line_token = injected_line_tokens let line_token = injected_line_tokens
.as_ref() .as_ref()
.and_then(|lt| lt.first()) .and_then(|token| token.first())
.map(|lt| lt.as_str()) .map(|token| token.as_str())
.or(doc_line_token); .or(doc_line_token);
let block_tokens = injected_block_tokens.as_deref().or(doc_block_tokens); let block_tokens = injected_block_tokens.as_deref().or(doc_block_tokens);
@ -5271,7 +5271,7 @@ fn toggle_line_comments(cx: &mut Context) {
let line_token = injected_line_tokens let line_token = injected_line_tokens
.as_ref() .as_ref()
.and_then(|token| token.first()) .and_then(|tokens| tokens.first())
.map(|token| token.as_str()) .map(|token| token.as_str())
.or(doc_line_token); .or(doc_line_token);
@ -5299,12 +5299,12 @@ fn toggle_block_comments(cx: &mut Context) {
toggle_comments_impl( toggle_comments_impl(
cx, cx,
Box::new( Box::new(
|doc_line_token, doc_block_tokens, rope, selection, mut get_comment_tokens| { |doc_line_token, doc_block_tokens, rope, selection, mut get_injected_tokens| {
Transaction::change( Transaction::change(
rope, rope,
selection.iter().flat_map(|range| { selection.iter().flat_map(|range| {
let (injected_line_tokens, injected_block_tokens) = let (injected_line_tokens, injected_block_tokens) =
get_comment_tokens(range.from(), range.to()); get_injected_tokens(range.from(), range.to());
let line_token = injected_line_tokens let line_token = injected_line_tokens
.as_ref() .as_ref()