more test cleanup

This commit is contained in:
2026-07-25 23:20:52 -05:00
parent c3be2329c0
commit ba8c72d5a5
12 changed files with 117 additions and 164 deletions
+53 -21
View File
@@ -181,29 +181,46 @@ mod tests {
use super::{BoardWidget, DARKNESS_BG};
use crate::utils::rgba8_to_color;
use kiln_core::Board;
use kiln_core::board_spec::BoardSpec;
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::style::Color;
use ratatui::widgets::Widget;
use kiln_core::board_spec::BoardSpec;
use std::collections::HashSet;
/// Deserializes one `[boards.NAME]` table into a [`Board`].
///
/// The script pool passed to `into_board` is empty, so boards built here must be
/// script-free — it validates every object's `script` against that pool.
fn board_from(toml: &str) -> Board {
let spec: BoardSpec = toml::from_str(toml).expect("board spec parses");
spec.into_board(&HashSet::new()).expect("board spec converts")
}
/// An `{ r, g, b, a }` color table. `Glyph` derives serde straight onto
/// `color::Rgba8`, so map TOML spells colors out structurally rather than as
/// `"#rrggbb"` strings.
fn rgb(r: u8, g: u8, b: u8) -> String {
format!("{{ r = {r}, g = {g}, b = {b}, a = 255 }}")
}
/// Builds a tiny dark board: a 5×1 corridor with the player at the left end
/// and a wall at x=2 occluding the two cells behind it.
fn dark_corridor() -> Board {
let toml = r##"
[map]
board_from(
r##"
name = "corridor"
width = 5
height = 1
dark = true
[grid]
content = "@ # "
[grid.palette]
"@" = { kind = "player" }
"#" = { kind = "wall", tile = "#", fg = "#808080", bg = "#404040" }
"##;
let mf: BoardSpec = toml::from_str(toml).unwrap();
Board::try_from(mf).unwrap()
grid = "@ # "
[palette."@"]
type = "player"
[palette."#"]
type = "builtin"
kind = "wall"
"##,
)
}
#[test]
@@ -243,21 +260,36 @@ mod tests {
#[test]
fn colored_object_light_tints_nearby_and_darkens_far() {
// A dark 6×1 corridor, no player torch: a single red light object at x=2
// A dark 6×1 corridor, no player torch: a single red light source at x=2
// (radius 2) tints its own cell red; a cell beyond its reach is darkness.
let toml = r##"
[map]
//
// The light is a Sensor, not a grid object: every grid object is solid now,
// and a lamp you can walk through belongs off-grid. The player sits at x=0
// (Board::lighting reads player_pos for the sightline) but carries no torch,
// so the sensor is the only light.
let board = board_from(&format!(
r##"
name = "lit"
width = 6
height = 1
dark = true
[grid]
sparse = [ { x = 2, y = 0, ch = "L" } ]
[grid.palette]
"L" = { kind = "object", tile = 1, fg = "#ff0000", bg = "#000000", solid = false, light = 2 }
"##;
let board = Board::try_from(toml::from_str::<BoardSpec>(toml).unwrap()).unwrap();
let fov = board.lighting(0); // no player torch — only the object lights
grid = "@ "
[palette."@"]
type = "player"
[[sensors]]
x = 2
y = 0
draw_layer = "Above"
opaque = false
glow = 2
glyph = {{ tile = 1, fg = {fg}, bg = {bg} }}
"##,
fg = rgb(255, 0, 0),
bg = rgb(0, 0, 0),
));
let fov = board.lighting(0); // no player torch — only the sensor lights
let area = Rect::new(0, 0, 6, 1);
let mut buf = Buffer::empty(area);