Fix excess missed markers in non-Latin text

This commit is contained in:
Damien Elmes 2023-02-10 14:40:45 +10:00
parent 0f86c9fd11
commit 0be31b1b17

View File

@ -72,7 +72,7 @@ impl DiffContext {
}
"insert" => {
let expected_str = self.slice_expected(&opcode);
provided.push(DiffToken::missing("-".repeat(expected_str.len())));
provided.push(DiffToken::missing("-".repeat(expected_str.chars().count())));
expected.push(DiffToken::missing(expected_str));
}
"replace" => {
@ -248,6 +248,15 @@ mod test {
assert_eq!(ctx.to_tokens().provided, &[good("1"), missing("-"),]);
}
#[test]
fn missed_chars_counted_correctly() {
let ctx = DiffContext::new("нос", "нс");
assert_eq!(
ctx.to_tokens().provided,
&[good("н"), missing("-"), good("с")]
);
}
#[test]
fn handles_certain_unicode_as_expected() {
// this was not parsed as expected with dissimilar 1.0.4