From 96ea12ec9104ae406a7bfdebcb771c9f63ba48bf Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Wed, 15 Apr 2026 10:39:15 -0300 Subject: [PATCH] test(tui): cover emoji sequence table widths Add a markdown table regression test with emoji presentation, keycap, and ZWJ sequences. This documents that the Rust renderer produces boxed table rows with consistent `unicode-width` display widths before xterm-specific behavior is handled separately. --- codex-rs/tui/src/markdown_render_tests.rs | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/codex-rs/tui/src/markdown_render_tests.rs b/codex-rs/tui/src/markdown_render_tests.rs index d038525197..24e6e41935 100644 --- a/codex-rs/tui/src/markdown_render_tests.rs +++ b/codex-rs/tui/src/markdown_render_tests.rs @@ -4,6 +4,7 @@ use ratatui::text::Line; use ratatui::text::Span; use ratatui::text::Text; use std::path::Path; +use unicode_width::UnicodeWidthStr; use crate::markdown_render::COLON_LOCATION_SUFFIX_RE; use crate::markdown_render::HASH_LOCATION_SUFFIX_RE; @@ -1449,6 +1450,52 @@ fn table_with_emoji_cells_renders_boxed_table() { ); } +#[test] +fn table_with_emoji_sequence_cells_has_consistent_display_width() { + let md = "| Left aligned | Center aligned | Right aligned |\n\ + |:-------------|:--------------:|--------------:|\n\ + | alpha | 🅰️ | 10 |\n\ + | **beta** | 🅱️ | 200 |\n\ + | _gamma_ | 🔤 | 3,000 |\n\ + | `delta()` | 🔢 | 40,000 |\n\ + | epsilon ([link](https://example.com/epsilon)) | 🔗 | 500,000 |\n\ + | zeta | ↔️ | 6,000,000 |\n\ + | eta | 1️⃣ | 70,000,000 |\n\ + | theta | 👩‍💻 | 800,000,000 |\n"; + let text = crate::markdown_render::render_markdown_text_with_width(md, Some(120)); + let lines: Vec = text + .lines + .iter() + .map(|line| line.spans.iter().map(|span| span.content.clone()).collect()) + .collect(); + let table_lines: Vec<&str> = lines + .iter() + .filter(|line| { + line.contains(|ch| { + matches!( + ch, + '┌' | '┬' | '┐' | '├' | '┼' | '┤' | '└' | '┴' | '┘' | '│' + ) + }) + }) + .map(String::as_str) + .collect(); + let expected_width = table_lines + .first() + .expect("expected unicode table to render as a box") + .width(); + + assert!( + table_lines.iter().all(|line| line.width() == expected_width), + "expected every rendered table row to have width {expected_width}: {table_lines:?}" + ); + assert!( + table_lines.iter().any(|line| line.contains("🅰️")) + && table_lines.iter().any(|line| line.contains("👩‍💻")), + "expected emoji sequence stress cells inside table: {table_lines:?}" + ); +} + #[test] fn table_falls_back_to_pipe_rendering_if_it_cannot_fit() { let md = "| c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8 | c9 | c10 |\n|---|---|---|---|---|---|---|---|---|---|\n| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |