use pixelsrc::terminal::{render_ansi_grid, render_coordinate_grid, ANSI_RESET};
use std::collections::HashMap;
#[test]
fn test_show_basic_sprite() {
let grid = vec![
"{_}{r}{_}".to_string(),
"{r}{r}{r}".to_string(),
"{_}{r}{_}".to_string(),
];
let palette = HashMap::from([
("{_}".to_string(), "#00000000".to_string()),
("{r}".to_string(), "#FF0000".to_string()),
]);
let aliases = HashMap::new();
let (colored, legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(
colored.contains("\x1b["),
"Output should contain ANSI escape sequences"
);
assert!(
colored.contains(ANSI_RESET),
"Output should contain ANSI reset sequence"
);
assert!(
legend.contains("{r}") || legend.contains("r"),
"Legend should list token names"
);
}
#[test]
fn test_show_palette_colors() {
let grid = vec![
"{red}{green}{blue}".to_string(),
];
let palette = HashMap::from([
("{red}".to_string(), "#FF0000".to_string()),
("{green}".to_string(), "#00FF00".to_string()),
("{blue}".to_string(), "#0000FF".to_string()),
]);
let aliases = HashMap::new();
let (colored, _legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(
colored.contains("255;0;0") || colored.contains("48;2;255;0;0"),
"Should have red background color"
);
assert!(
colored.contains("0;255;0") || colored.contains("48;2;0;255;0"),
"Should have green background color"
);
assert!(
colored.contains("0;0;255") || colored.contains("48;2;0;0;255"),
"Should have blue background color"
);
}
#[test]
fn test_show_transparency() {
let grid = vec![
"{_}{x}{_}".to_string(),
];
let palette = HashMap::from([
("{_}".to_string(), "#00000000".to_string()),
("{x}".to_string(), "#FF0000".to_string()),
]);
let aliases = HashMap::new();
let (colored, _legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(
colored.contains("48;5;236"),
"Transparent should use distinct background (gray)"
);
}
#[test]
fn test_show_with_coordinates() {
let grid = vec![
"{a}{b}".to_string(),
"{c}{d}".to_string(),
];
let coord_output = render_coordinate_grid(&grid, false);
assert!(
!coord_output.is_empty(),
"Coordinate display should produce output"
);
}
#[test]
fn test_show_with_aliases() {
let grid = vec![
"{skin}{hair}".to_string(),
"{skin}{hair}".to_string(),
];
let palette = HashMap::from([
("{skin}".to_string(), "#FFD5B4".to_string()),
("{hair}".to_string(), "#8B4513".to_string()),
]);
let aliases = HashMap::from([
('s', "{skin}".to_string()),
('h', "{hair}".to_string()),
]);
let (colored, legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(
colored.contains('s') || colored.contains('h'),
"Should display alias characters"
);
assert!(
legend.contains("Legend:"),
"Legend should have header"
);
assert!(
colored.contains("\x1b["),
"Should contain ANSI escape sequences"
);
}
#[test]
fn test_show_empty_grid() {
let grid: Vec<String> = vec![];
let palette = HashMap::new();
let aliases = HashMap::new();
let (colored, legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(colored.is_empty() || colored.trim().is_empty(), "Empty grid produces empty output");
assert!(legend.is_empty() || !legend.contains("{"), "Empty grid has no legend entries");
}
#[test]
fn test_show_single_pixel() {
let grid = vec!["{x}".to_string()];
let palette = HashMap::from([
("{x}".to_string(), "#FF00FF".to_string()),
]);
let aliases = HashMap::new();
let (colored, _legend) = render_ansi_grid(&grid, &palette, &aliases);
assert!(!colored.is_empty(), "Single pixel should produce output");
assert!(
colored.contains("\x1b["),
"Should have ANSI formatting"
);
}
#[test]
fn test_show_large_sprite() {
let mut grid = Vec::new();
for row in 0..32 {
let mut row_str = String::new();
for col in 0..32 {
if (row + col) % 2 == 0 {
row_str.push_str("{a}");
} else {
row_str.push_str("{b}");
}
}
grid.push(row_str);
}
let palette = HashMap::from([
("{a}".to_string(), "#FFFFFF".to_string()),
("{b}".to_string(), "#000000".to_string()),
]);
let aliases = HashMap::new();
let (colored, _) = render_ansi_grid(&grid, &palette, &aliases);
assert!(!colored.is_empty(), "Large sprite should render");
let line_count = colored.lines().count();
assert!(line_count >= 32, "Should have at least 32 lines for 32 rows");
}