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.
This commit is contained in:
Felipe Coury
2026-04-15 10:39:15 -03:00
parent 8495fd57ed
commit 96ea12ec91

View File

@@ -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<String> = 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 |