You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
#[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))
|
|
.expect(&format!("Couldn't get tile at {}:{}", $x, $y));
|
|
let signal = guard.signal();
|
|
assert!(
|
|
signal.is_some(),
|
|
"Expected signal at {}:{}!\n{}",
|
|
$x,
|
|
$y,
|
|
$world
|
|
);
|
|
signal
|
|
}};
|
|
|
|
( $world:expr, $x:expr, $y:expr, [ $( $data:expr ),* ] ) => {{
|
|
let signal = assert_signal!($pane, $x, $y);
|
|
// TODO: check that signal.data == data
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! assert_no_signal {
|
|
( $world:expr, $x:expr, $y:expr ) => {{
|
|
let guard = $world
|
|
.get(($x, $y))
|
|
.expect(&format!("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_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());
|
|
}};
|
|
}
|