Extract variable
This commit is contained in:
parent
c956fff004
commit
e58db20e21
|
@ -73,20 +73,25 @@ impl TokenTreeFactory {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
macro_rules! TEST_DIR {
|
||||||
|
() => {
|
||||||
|
"token_tree_factory_tests"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! run_test {
|
macro_rules! run_test {
|
||||||
($test_file:expr) => {
|
($test_file:expr) => {
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
// given
|
// given
|
||||||
let input = include_str!(concat!("token_tree_factory_tests/", $test_file, ".md"));
|
let input = include_str!(concat!(TEST_DIR!(), "/", $test_file, ".md"));
|
||||||
|
|
||||||
// when
|
// when
|
||||||
let tree = TokenTreeFactory::create(input);
|
let tree = TokenTreeFactory::create(input);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
let tree_as_str = format!("{tree:#?}");
|
let tree_as_str = format!("{tree:#?}");
|
||||||
let should_be =
|
let should_be = include_str!(concat!(TEST_DIR!(), "/", $test_file, ".check"));
|
||||||
include_str!(concat!("token_tree_factory_tests/", $test_file, ".check"));
|
|
||||||
assert_eq!(tree_as_str, should_be);
|
assert_eq!(tree_as_str, should_be);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -98,12 +103,12 @@ mod tests {
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
let input = include_str!(concat!("token_tree_factory_tests/", $test_file, ".md"));
|
let input = include_str!(concat!(TEST_DIR!(), "/", $test_file, ".md"));
|
||||||
let tree = TokenTreeFactory::create(input);
|
let tree = TokenTreeFactory::create(input);
|
||||||
let tree_as_str = format!("{tree:#?}");
|
let tree_as_str = format!("{tree:#?}");
|
||||||
let file = concat!("src/md_parser/token_tree_factory_tests/", $test_file, ".check");
|
let file = concat!("src/md_parser/", TEST_DIR!(), "/", $test_file, ".check");
|
||||||
|
|
||||||
// prevent user from accidentially leaving the current macro in a test
|
// prevent user from accidentally leaving the current macro in a test
|
||||||
if Path::new(file).exists() {
|
if Path::new(file).exists() {
|
||||||
panic!("Test case already exists: {file}");
|
panic!("Test case already exists: {file}");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user