|
|
|
#[macro_export]
|
|
|
|
macro_rules! load_test {
|
|
|
|
( $path:expr ) => {{
|
|
|
|
let path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), $path);
|
|
|
|
let raw = std::fs::read_to_string(&path).unwrap_or_else(|err| {
|
|
|
|
panic!("Couldn't load {}: {}", &path, err);
|
|
|
|
});
|
|
|
|
let world: stackline::prelude::World =
|
|
|
|
serde_json::from_str(&raw).expect("Couldn't parse World");
|
|
|
|
world
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! run {
|
|
|
|
( $world:expr ) => {
|
|
|
|
$world.step();
|
|
|
|
};
|
|
|
|
|
|
|
|
( $world:expr, $steps:expr ) => {
|
|
|
|
for _step in 0..$steps {
|
|
|
|
$world.step();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_signal {
|
|
|
|
( $world:expr, $x:expr, $y:expr ) => {{
|
|
|
|
let guard = $world
|
|
|
|
.get(($x, $y))
|
|
|
|
.unwrap_or_else(|| panic!("Couldn't get tile at {}:{}", $x, $y));
|
|
|
|
let signal = guard.signal();
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
signal.is_some(),
|
|
|
|
"Expected signal at {}:{}!\n{}",
|
|
|
|
$x,
|
|
|
|
$y,
|
|
|
|
$world
|
|
|
|
);
|
|
|
|
|
|
|
|
signal.unwrap()
|
|
|
|
}};
|
|
|
|
|
|
|
|
( $world:expr, $x:expr, $y:expr, $signal:expr ) => {{
|
|
|
|
let signal = assert_signal!($world, $x, $y);
|
|
|
|
assert_eq!(signal, $signal);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_no_signal {
|
|
|
|
( $world:expr, $x:expr, $y:expr ) => {{
|
|
|
|
let guard = $world
|
|
|
|
.get(($x, $y))
|
|
|
|
.unwrap_or_else(|| panic!("Couldn't get tile at {}:{}", $x, $y));
|
|
|
|
let signal = guard.signal();
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
signal.is_none(),
|
|
|
|
"Expected no signal at {}:{}!\n{}",
|
|
|
|
$x,
|
|
|
|
$y,
|
|
|
|
$world
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_stored {
|
|
|
|
( $world:expr, $x:expr, $y:expr ) => {{
|
|
|
|
let guard = $world
|
|
|
|
.get_as::<stackline::tile::Store>(($x, $y))
|
|
|
|
.unwrap_or_else(|| panic!("Couldn't get store tile at {}:{}", $x, $y));
|
|
|
|
let signal = guard.signal().cloned();
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
signal.is_some(),
|
|
|
|
"Expected stored signal at {}:{}!\n{}",
|
|
|
|
$x,
|
|
|
|
$y,
|
|
|
|
$world
|
|
|
|
);
|
|
|
|
|
|
|
|
signal.unwrap()
|
|
|
|
}};
|
|
|
|
|
|
|
|
( $world:expr, $x:expr, $y:expr, $signal:expr ) => {{
|
|
|
|
let signal = assert_stored!($world, $x, $y);
|
|
|
|
assert_eq!(
|
|
|
|
signal,
|
|
|
|
$signal,
|
|
|
|
concat!("Expected stored signal at {}:{} to be equal to ", stringify!($signal), "!\n{}"),
|
|
|
|
$x,
|
|
|
|
$y,
|
|
|
|
$world
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_no_stored {
|
|
|
|
( $world:expr, $x:expr, $y:expr ) => {{
|
|
|
|
let guard = $world
|
|
|
|
.get_as::<stackline::tile::Store>(($x, $y))
|
|
|
|
.unwrap_or_else(|| panic!("Couldn't get store tile at {}:{}", $x, $y));
|
|
|
|
let signal = guard.signal();
|
|
|
|
|
|
|
|
assert!(
|
|
|
|
signal.is_none(),
|
|
|
|
"Expected no stored signal at {}:{}!\n{}",
|
|
|
|
$x,
|
|
|
|
$y,
|
|
|
|
$world
|
|
|
|
);
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! assert_display_eq {
|
|
|
|
( $world:expr, $path:expr ) => {{
|
|
|
|
use std::fmt::Write;
|
|
|
|
|
|
|
|
let actual = format!("{:#}", $world);
|
|
|
|
let path = $path;
|
|
|
|
let expected = std::fs::read_to_string(&path).unwrap_or_else(|err| {
|
|
|
|
panic!("Couldn't read {}: {}", path, err);
|
|
|
|
});
|
|
|
|
|
|
|
|
let mut actual_trimmed = String::new();
|
|
|
|
for line in actual.lines() {
|
|
|
|
write!(&mut actual_trimmed, "{}\n", line.trim_end()).unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(actual_trimmed.trim_end(), expected.trim_end());
|
|
|
|
}};
|
|
|
|
}
|