wip 6 fixed tests

This commit is contained in:
2026-08-11 23:01:12 -05:00
parent 456b3448eb
commit 0f045c39a3
9 changed files with 77 additions and 227 deletions
+3 -74
View File
@@ -501,12 +501,11 @@ impl Board {
#[cfg(test)]
pub(crate) mod tests {
use std::assert_matches;
use super::Board;
use crate::builtin::Builtin;
use crate::floor::Floor;
use crate::glyph::Glyph;
use crate::utils::{Direction, ObjectId, Point};
use crate::utils::ObjectId;
use color::Rgba8;
use std::collections::HashMap;
use crate::object_def::ObjectDef;
@@ -703,76 +702,6 @@ pub(crate) mod tests {
assert!(!board.in_bounds((0, 2)));
}
#[test]
fn can_shift_only_checks_the_cell_ahead() {
// Source must be pushable.
let mut board = open_board(4, 1, (3, 0));
assert!(!board.can_shift(0, 0, Direction::East)); // empty source
// Crate with open space ahead: shiftable.
crate_at(&mut board, 0, 0);
assert!(board.can_shift(0, 0, Direction::East));
assert_matches!(board.get((0, 0)), Some(Tile::Object(_)));
// Crate with another pushable crate ahead: still shiftable (unlike can_push,
// which would follow the chain to the wall and fail).
let mut board = open_board(4, 1, (3, 0));
crate_at(&mut board, 0, 0);
crate_at(&mut board, 1, 0);
wall_at(&mut board, 2, 0);
assert!(board.can_shift(0, 0, Direction::East));
assert!(!board.can_push(0, 0, Direction::East));
// Crate with a non-pushable wall ahead: not shiftable.
let mut board = open_board(3, 1, (2, 0));
crate_at(&mut board, 0, 0);
wall_at(&mut board, 1, 0);
assert!(!board.can_shift(0, 0, Direction::East));
// Crate at the board edge facing off-board: not shiftable.
let mut board = open_board(2, 1, (0, 0));
crate_at(&mut board, 1, 0);
assert!(!board.can_shift(1, 0, Direction::East));
}
#[test]
fn can_shift_treats_the_player_as_a_blocker() {
// The player is always a blocker for a shift — even a grab gem may not shift
// onto it (grab now fires only on player movement, not on being shifted in).
let mut board = open_board(2, 1, (1, 0));
gem_at(&mut board, 0, 0);
assert!(!board.can_shift(0, 0, Direction::East));
// A plain crate likewise may not shift onto the player.
let mut board = open_board(2, 1, (1, 0));
crate_at(&mut board, 0, 0);
assert!(!board.can_shift(0, 0, Direction::East));
}
#[test]
fn push_into_player_pushes_player() {
// Crate shoved east into the player slides the player along into open space.
let mut board = open_board(4, 1, (2, 0));
crate_at(&mut board, 1, 0);
assert!(board.can_push(1, 0, Direction::East));
board.push(1, 0, Direction::East);
assert!(board.get((1, 0)).is_none());
assert!(is_builtin(&board, 2, 0,"crate"));
assert_eq!(board.player_pos(), Point { x: 3, y: 0 });
}
#[test]
fn push_into_player_blocked_by_wall() {
// Player backed against a wall: push has nowhere to go, nothing moves.
let mut board = open_board(4, 1, (2, 0));
crate_at(&mut board, 1, 0);
wall_at(&mut board, 3, 0);
assert!(!board.can_push(1, 0, Direction::East));
board.push(1, 0, Direction::East); // no-op
assert!(is_builtin(&board, 1, 0, "crate"));
assert_eq!(board.player_pos(), Point { x: 2, y: 0 });
}
#[test]
fn glyph_at_uses_floor_for_empty_and_grid_for_solid() {
// Player parked at (2,0) so it doesn't overlap either asserted cell.
@@ -812,7 +741,7 @@ pub(crate) mod tests {
#[test]
fn apply_shift_wall_stops_cascade_but_empty_limits_it() {
// A non-pushable Wall is immobile. Backward cascade from the wall traces
// A wall is immobile (`mobile = false`). Backward cascade from the wall traces
// through preceding solids until it hits empty, marking those as blocked.
// Solids on the *other* side of the empty (outside the blocked region) still move.
let mut board = open_board(6, 1, (5, 0));
@@ -823,7 +752,7 @@ pub(crate) mod tests {
crate_at(&mut board, 4, 0);
// Cycle: idx 0 → idx 1 → idx 2 → idx 3 → idx 4 → idx 0 (wrap)
// immobile = {2} (Wall, Pushable::No)
// immobile = {2} (the wall: Tile::shiftable() is false)
// Backward trace from idx 2: solids[2]=Some → blocked.insert(2), prev=1
// solids[1]=None (empty) → break
// blocked = {2}; Crate at (0,0) is NOT blocked