Don't return empty spans when splitting comments on word boundaries

ida_star
Wilfred Hughes 2021-09-04 22:59:47 +07:00
parent 6664eaa243
commit b8be456309
1 changed files with 6 additions and 37 deletions

@ -3,8 +3,6 @@
#![allow(clippy::mutable_key_type)] // Hash for Syntax doesn't use mutable fields.
use itertools::{EitherOrBoth, Itertools};
use lazy_static::lazy_static;
use regex::Regex;
use std::cell::Cell;
use std::cmp::{max, min};
use std::collections::hash_map::DefaultHasher;
@ -565,11 +563,12 @@ fn split_comment_words(
// TODO: merge adjacent single-line comments unless there are
// blank lines between them.
lazy_static! {
static ref WORD_BOUNDARY_RE: Regex = Regex::new(r"\b").unwrap();
}
let content_parts: Vec<_> = WORD_BOUNDARY_RE.split(content).collect();
let other_parts: Vec<_> = WORD_BOUNDARY_RE.split(opposite_content).collect();
let content_parts: Vec<_> = content
.split_inclusive(&[' ', '\n', '\t'] as &[char])
.collect();
let other_parts: Vec<_> = opposite_content
.split_inclusive(&[' ', '\n', '\t'] as &[char])
.collect();
let content_newlines = NewlinePositions::from(content);
let opposite_content_newlines = NewlinePositions::from(opposite_content);
@ -1187,21 +1186,6 @@ mod tests {
assert_eq!(
res,
vec![
MatchedPos {
kind: MatchKind::UnchangedCommentPart {
opposite_pos: vec![SingleLineSpan {
line: 0.into(),
start_col: 0,
end_col: 0
}]
},
pos: vec![SingleLineSpan {
line: 0.into(),
start_col: 0,
end_col: 0
}],
prev_opposite_pos: vec![]
},
MatchedPos {
kind: MatchKind::ChangedCommentPart,
pos: vec![SingleLineSpan {
@ -1211,21 +1195,6 @@ mod tests {
}],
prev_opposite_pos: vec![]
},
MatchedPos {
kind: MatchKind::UnchangedCommentPart {
opposite_pos: vec![SingleLineSpan {
line: 0.into(),
start_col: 3,
end_col: 3
}]
},
pos: vec![SingleLineSpan {
line: 0.into(),
start_col: 3,
end_col: 3
}],
prev_opposite_pos: vec![]
},
]
);
}