use crate::tui::render::utils::char_boundary_at_width;
use crate::tui::render::utils::wrap_line_with_padding;
use ratatui::text::Line;
#[test]
fn test_char_boundary_ascii() {
assert_eq!(char_boundary_at_width("hello", 3), 3);
assert_eq!(char_boundary_at_width("hello", 5), 5);
assert_eq!(char_boundary_at_width("hello", 10), 5); }
#[test]
fn test_char_boundary_multibyte() {
let s = "ab█cd";
assert_eq!(char_boundary_at_width(s, 2), 2); assert_eq!(char_boundary_at_width(s, 3), 5); assert_eq!(char_boundary_at_width(s, 4), 6); }
#[test]
fn test_char_boundary_wide_chars() {
let s = "a中b";
assert_eq!(char_boundary_at_width(s, 1), 1); assert_eq!(char_boundary_at_width(s, 2), 1); assert_eq!(char_boundary_at_width(s, 3), 4); }
#[test]
fn test_char_boundary_empty() {
assert_eq!(char_boundary_at_width("", 5), 0);
assert_eq!(char_boundary_at_width("hello", 0), 0);
}
#[test]
fn test_wrap_ascii_fits() {
let line = Line::from("short line");
let result = wrap_line_with_padding(line, 80, " ");
assert_eq!(result.len(), 1);
}
#[test]
fn test_wrap_ascii_wraps() {
let line = Line::from("this is a longer line that should wrap");
let result = wrap_line_with_padding(line, 20, " ");
assert!(
result.len() > 1,
"expected wrapping, got {} lines",
result.len()
);
}
#[test]
fn test_wrap_multibyte_no_panic() {
let text = format!("some text with a block char █ at the end{}", "█");
let line = Line::from(text);
let result = wrap_line_with_padding(line, 30, " ");
assert!(!result.is_empty());
}
#[test]
fn test_wrap_emoji_no_panic() {
let line = Line::from("🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀🦀");
let result = wrap_line_with_padding(line, 10, " ");
assert!(!result.is_empty());
}
#[test]
fn test_wrap_cjk_no_panic() {
let line = Line::from("中文测试字符串需要正确换行处理");
let result = wrap_line_with_padding(line, 10, " ");
assert!(result.len() > 1);
}
#[test]
fn test_wrap_mixed_multibyte_and_spaces() {
let line = Line::from("hello █ world █ test █ more █ text █ end");
let result = wrap_line_with_padding(line, 15, " ");
assert!(result.len() > 1);
for l in &result {
let joined: String = l.spans.iter().map(|s| s.content.as_ref()).collect();
assert!(!joined.is_empty());
}
}
#[test]
fn test_wrap_zero_width() {
let line = Line::from("test");
let result = wrap_line_with_padding(line, 0, " ");
assert_eq!(result.len(), 1); }
#[test]
fn test_wrap_cursor_char() {
let mut input =
"next I just noticed something weird like if I keep on this window it is always super fast"
.to_string();
input.push('\u{2588}'); let line = Line::from(format!(" {}", input));
let result = wrap_line_with_padding(line, 170, " ");
assert!(!result.is_empty());
}