fix: avoid unicode-width breaking change in tests (#1171)

unicode-width 0.1.13 changed the width of \u{1} from 0 to 1.
Our tests assumed that \u{1} had a width of 0, so this change replaces
the \u{1} character with \u{200B} (zero width space) in the tests.

Upstream issue (closed as won't fix):
https://github.com/unicode-rs/unicode-width/issues/55
This commit is contained in:
Josh McKinney 2024-06-06 23:06:14 -07:00 committed by GitHub
parent 4f307e69db
commit e6871b9e21
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 9 additions and 7 deletions

View file

@ -42,7 +42,7 @@ termwiz = { version = "0.22.0", optional = true }
time = { version = "0.3.11", optional = true, features = ["local-offset"] } time = { version = "0.3.11", optional = true, features = ["local-offset"] }
unicode-segmentation = "1.10" unicode-segmentation = "1.10"
unicode-truncate = "1" unicode-truncate = "1"
unicode-width = "=0.1.12" # incompatible changes in 0.1.13 https://github.com/unicode-rs/unicode-width/issues/55 unicode-width = "0.1.13"
[dev-dependencies] [dev-dependencies]
anyhow = "1.0.71" anyhow = "1.0.71"

View file

@ -609,16 +609,18 @@ mod tests {
#[test] #[test]
fn set_string_zero_width() { fn set_string_zero_width() {
assert_eq!("\u{200B}".width(), 0);
let area = Rect::new(0, 0, 1, 1); let area = Rect::new(0, 0, 1, 1);
let mut buffer = Buffer::empty(area); let mut buffer = Buffer::empty(area);
// Leading grapheme with zero width // Leading grapheme with zero width
let s = "\u{1}a"; let s = "\u{200B}a";
buffer.set_stringn(0, 0, s, 1, Style::default()); buffer.set_stringn(0, 0, s, 1, Style::default());
assert_eq!(buffer, Buffer::with_lines(["a"])); assert_eq!(buffer, Buffer::with_lines(["a"]));
// Trailing grapheme with zero with // Trailing grapheme with zero with
let s = "a\u{1}"; let s = "a\u{200B}";
buffer.set_stringn(0, 0, s, 1, Style::default()); buffer.set_stringn(0, 0, s, 1, Style::default());
assert_eq!(buffer, Buffer::with_lines(["a"])); assert_eq!(buffer, Buffer::with_lines(["a"]));
} }

View file

@ -433,7 +433,7 @@ mod test {
#[test] #[test]
fn zero_width_char_at_end_of_line() { fn zero_width_char_at_end_of_line() {
let line = "foo\0"; let line = "foo\u{200B}";
for paragraph in [ for paragraph in [
Paragraph::new(line), Paragraph::new(line),
Paragraph::new(line).wrap(Wrap { trim: false }), Paragraph::new(line).wrap(Wrap { trim: false }),

View file

@ -673,11 +673,11 @@ mod test {
#[test] #[test]
fn line_composer_zero_width_at_end() { fn line_composer_zero_width_at_end() {
let width = 3; let width = 3;
let line = "foo\0"; let line = "foo\u{200B}";
let (word_wrapper, _, _) = run_composer(Composer::WordWrapper { trim: true }, line, width); let (word_wrapper, _, _) = run_composer(Composer::WordWrapper { trim: true }, line, width);
let (line_truncator, _, _) = run_composer(Composer::LineTruncator, line, width); let (line_truncator, _, _) = run_composer(Composer::LineTruncator, line, width);
assert_eq!(word_wrapper, vec!["foo\0"]); assert_eq!(word_wrapper, vec!["foo"]);
assert_eq!(line_truncator, vec!["foo\0"]); assert_eq!(line_truncator, vec!["foo\u{200B}"]);
} }
#[test] #[test]