use lipgloss::{
join,
position::Position,
position::{BOTTOM, CENTER, LEFT, RIGHT, TOP},
};
#[test]
fn join_horizontal_top_bottom_center_heights() {
let a = "A\nA\nA\nA\nA"; let b = "b1\nb2";
let out_top = join::join_horizontal(TOP, &[a, b]);
let expected_top =
"A".to_string() + "b1\n" + "A" + "b2\n" + "A" + " \n" + "A" + " \n" + "A" + " ";
assert_eq!(out_top, expected_top);
let out_bottom = join::join_horizontal(BOTTOM, &[a, b]);
let expected_bottom =
"A".to_string() + " \n" + "A" + " \n" + "A" + " \n" + "A" + "b1\n" + "A" + "b2";
assert_eq!(out_bottom, expected_bottom);
let out_center = join::join_horizontal(CENTER, &[a, b]);
let expected_center =
"A".to_string() + " \n" + "A" + " \n" + "A" + "b1\n" + "A" + "b2\n" + "A" + " ";
assert_eq!(out_center, expected_center);
}
#[test]
fn join_vertical_fractional_positions() {
let a = "x\ny\nz"; let b = "ww";
let out_left = join::join_vertical(Position(0.2), &[a, b]);
let expected_left = "x \ny \nz \nww";
assert_eq!(out_left, expected_left);
let out_rightish = join::join_vertical(Position(0.8), &[a, b]);
let expected_rightish = " x\n y\n z\nww";
assert_eq!(out_rightish, expected_rightish);
}
#[test]
fn join_horizontal_multi_blocks_cjk_emoji_and_ansi() {
let cjk = "漢字\n仮名"; let emoji = "😀\n🎉"; let ansi = "\x1b[34mblue\x1b[0m\n\x1b[32mgrn\x1b[0m";
let out = join::join_horizontal(CENTER, &[cjk, emoji, ansi]);
let lines: Vec<&str> = out.split('\n').collect();
assert_eq!(lines.len(), 2);
fn w(s: &str) -> usize {
lipgloss::utils::width_visible(s)
}
let cjk_lines: Vec<&str> = cjk.split('\n').collect();
let emoji_lines: Vec<&str> = emoji.split('\n').collect();
let ansi_lines: Vec<&str> = ansi.split('\n').collect();
let cjk_max = cjk_lines.iter().map(|l| w(l)).max().unwrap();
let emoji_max = emoji_lines.iter().map(|l| w(l)).max().unwrap();
let ansi_max = ansi_lines.iter().map(|l| w(l)).max().unwrap();
let total = cjk_max + emoji_max + ansi_max;
for ln in lines {
assert_eq!(w(ln), total);
}
}
#[test]
fn join_horizontal_fractional_position() {
let a = "A\nA\nA\nA\nA"; let b = "b1\nb2"; let pos = Position(0.2);
let out = join::join_horizontal(pos, &[a, b]);
let expected =
"A".to_string() + " \n" + "A" + "b1\n" + "A" + "b2\n" + "A" + " \n" + "A" + " ";
assert_eq!(out, expected);
}
#[test]
fn join_vertical_left_right_and_center_with_ansi() {
let a = "X\nY"; let b = "\x1b[31mab\x1b[0m";
let out_left = join::join_vertical(LEFT, &[a, b]);
let expected_left = format!("X \nY \n{}", b);
assert_eq!(out_left, expected_left);
let out_right = join::join_vertical(RIGHT, &[a, b]);
let expected_right = format!(" X\n Y\n{}", b);
assert_eq!(out_right, expected_right);
let pos = Position(0.3);
let out_center = join::join_vertical(pos, &[a, b]);
let expected_center = format!("X \nY \n{}", b);
assert_eq!(out_center, expected_center);
}