use crate::tui::render::{dropdown_dimensions, truncate_to_chars};
#[test]
fn never_overflows_when_anchored_at_x_plus_one() {
let lengths = vec![200, 50, 30];
let (width, _inner, _budget) = dropdown_dimensions(15, &lengths, 154, 1);
assert!(
width < 154,
"width must not push past frame right edge: width={width}"
);
}
#[test]
fn respects_terminal_width_for_narrow_terminals() {
let lengths = vec![1000];
let (width, _, _) = dropdown_dimensions(10, &lengths, 30, 1);
assert!(
width <= 29,
"narrow terminal must clamp to width - 1: width={width}"
);
}
#[test]
fn handles_zero_input_area_width_without_panic() {
let lengths = vec![80];
let (width, _, _) = dropdown_dimensions(10, &lengths, 0, 1);
assert!(width >= 1);
}
#[test]
fn responsive_grows_to_fit_short_content_without_capping_at_80() {
let lengths = vec![100];
let (width, _, budget) = dropdown_dimensions(15, &lengths, 200, 1);
assert!(
width > 80,
"responsive sizing must allow growth past 80 on a wide terminal: width={width}"
);
assert!(
budget >= 100,
"desc budget must accommodate full 100-char description: budget={budget}"
);
}
#[test]
fn truncates_when_content_exceeds_terminal() {
let lengths = vec![500];
let (width, _, budget) = dropdown_dimensions(15, &lengths, 100, 1);
assert!(width <= 99, "must clamp at terminal-1: width={width}");
assert!(
budget < 500,
"desc budget must shrink below full description length when terminal is too narrow: budget={budget}"
);
}
#[test]
fn floor_at_40_when_terminal_allows() {
let lengths: Vec<usize> = vec![];
let (width, _, _) = dropdown_dimensions(10, &lengths, 200, 1);
assert!(width >= 40, "floor at 40 expected: width={width}");
}
#[test]
fn name_col_chars_drives_layout_alignment() {
let lengths = vec![20];
let (width_short, _, budget_short) = dropdown_dimensions(8, &lengths, 200, 1);
let (width_long, _, budget_long) = dropdown_dimensions(20, &lengths, 200, 1);
assert!(
width_long >= width_short,
"longer name column should produce >= dropdown width"
);
assert!(budget_short >= 20);
assert!(budget_long >= 20);
}
#[test]
fn truncate_passes_through_short_strings() {
let s = truncate_to_chars("short", 100);
assert_eq!(s, "short");
}
#[test]
fn truncate_appends_ellipsis_when_clipped() {
let s = truncate_to_chars("0123456789abcdef", 10);
assert_eq!(s.chars().count(), 10);
assert!(s.ends_with('…'));
}
#[test]
fn truncate_zero_budget_returns_empty() {
let s = truncate_to_chars("anything", 0);
assert_eq!(s, "");
}
#[test]
fn truncate_one_char_budget_is_just_the_ellipsis() {
let s = truncate_to_chars("hello world", 1);
assert_eq!(s.chars().count(), 1);
assert_eq!(s, "…");
}
#[test]
fn truncate_handles_multi_byte_unicode() {
let s = truncate_to_chars("日本語のテキスト", 4);
assert_eq!(s.chars().count(), 4);
assert!(s.ends_with('…'));
}