From 0be31b1b17df58da9cb044c7a0ed33a2939a922f Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 10 Feb 2023 14:40:45 +1000 Subject: [PATCH] Fix excess missed markers in non-Latin text --- rslib/src/typeanswer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/rslib/src/typeanswer.rs b/rslib/src/typeanswer.rs index a0cb08ded..1a95258b6 100644 --- a/rslib/src/typeanswer.rs +++ b/rslib/src/typeanswer.rs @@ -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