1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use beads_rust::format::truncate_title;
#[test]
fn test_truncate_title_with_wide_characters() {
// "🚀🚀🚀" is 3 chars, but 6 visual columns.
// If max_len is 4, it should probably truncate to "🚀..." or similar?
// Actually, truncate_title truncates by *characters*, not visual width.
// So truncate_title("🚀🚀🚀", 4) with current logic:
// title_len = 3 chars. <= 4. Returns "🚀🚀🚀".
// Visual width is 6. If terminal is 4 columns wide, this overflows.
let title = "🚀🚀🚀";
let _truncated = truncate_title(title, 4);
// With current buggy logic:
// chars().count() is 3. 3 <= 4. Returns "🚀🚀🚀".
// Visual width is 6.
// We expect it to truncate to fit visual width 4.
// "🚀..." is 2 + 3 = 5 width. Too wide.
// "..." is 3 width. Fits.
// So "🚀🚀🚀" should probably become "..." if max width is 4.
// Let's assert what we *want* (correct behavior), which will fail.
// Or simpler: "あaaaaa" (1 wide char + 5 ascii).
// Width: 2 + 5 = 7.
// Chars: 6.
// If max_len = 6.
// Current logic: chars count is 6. Returns "あaaaaa".
// Actual width: 7. Overflow!
let title_mixed = "あaaaaa";
let truncated_mixed = truncate_title(title_mixed, 6);
// We expect valid truncation to fit in 6 columns.
// "あ..." -> 2 + 3 = 5 cols. Fits.
// "あa..." -> 2 + 1 + 3 = 6 cols. Fits perfectly.
// "あaa..." -> 2 + 2 + 3 = 7 cols. Overflow.
// So result should be "あa..." or shorter.
// With new logic, it should be "あa..." (width 6).
assert_eq!(
truncated_mixed, "あa...",
"Logic should correctly truncate to visual width 6"
);
// Verify emoji case too
let title_emoji = "🚀🚀🚀";
let truncated_emoji = truncate_title(title_emoji, 4);
// Max 4. ellipsis is 3. 1 column left. 🚀 is 2 cols.
// So "🚀..." is 5 cols. Doesn't fit.
// Should return "..." (3 cols).
assert_eq!(
truncated_emoji, "...",
"Logic should handle wide emoji correctly"
);
}