portals
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
mod grid_errors;
|
||||
mod object_placement;
|
||||
mod player_placement;
|
||||
mod portal_placement;
|
||||
mod round_trip;
|
||||
|
||||
use crate::board::Board;
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
use super::{load_board, map_3x1};
|
||||
|
||||
fn portal_toml(portals: &str) -> String {
|
||||
format!(
|
||||
"{}{}",
|
||||
map_3x1("...", ""),
|
||||
portals
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn portal_duplicate_name_drops_second() {
|
||||
let toml = portal_toml(
|
||||
"[[portals]]\nname = \"a\"\nx = 0\ny = 0\ntarget_map = \"x\"\ntarget_entry = \"b\"\n\
|
||||
[[portals]]\nname = \"a\"\nx = 1\ny = 0\ntarget_map = \"x\"\ntarget_entry = \"c\"\n",
|
||||
);
|
||||
let board = load_board(&toml);
|
||||
assert_eq!(board.portals.len(), 1, "second portal with duplicate name should be dropped");
|
||||
assert_eq!(board.portals[0].x, 0);
|
||||
assert!(!board.is_valid(), "duplicate name should be a load error");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn portal_palette_char_places_portal_at_grid_position() {
|
||||
let toml = format!(
|
||||
"{}{}",
|
||||
map_3x1("1..", ""),
|
||||
"[[portals]]\nname = \"p\"\npalette = \"1\"\ntarget_map = \"x\"\ntarget_entry = \"e\"\n"
|
||||
);
|
||||
let board = load_board(&toml);
|
||||
assert_eq!(board.portals.len(), 1);
|
||||
assert_eq!(board.portals[0].x, 0);
|
||||
assert_eq!(board.portals[0].y, 0);
|
||||
assert_eq!(board.portals[0].name, "p");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn portal_palette_char_colliding_with_object_is_dropped() {
|
||||
let toml = format!(
|
||||
"{}{}{}",
|
||||
map_3x1("1..", ""),
|
||||
"[[objects]]\npalette = \"1\"\ntile = 64\nfg = \"#ffffff\"\nbg = \"#000000\"\n",
|
||||
"[[portals]]\nname = \"p\"\npalette = \"1\"\ntarget_map = \"x\"\ntarget_entry = \"e\"\n"
|
||||
);
|
||||
let board = load_board(&toml);
|
||||
assert_eq!(board.portals.len(), 0, "portal whose palette char is already an object char should be dropped");
|
||||
}
|
||||
Reference in New Issue
Block a user