Setup a testing bench
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
4470af3926
commit
d3e6410ec0
16 changed files with 336 additions and 4 deletions
46
tests/file_tests.rs
Normal file
46
tests/file_tests.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use temple::Context;
|
||||
|
||||
#[test]
|
||||
fn check_cases() {
|
||||
insta::glob!("cases/*.temple", |path| {
|
||||
let mut settings = insta::Settings::clone_current();
|
||||
settings.set_snapshot_path("cases");
|
||||
settings.set_snapshot_suffix(path.file_stem().unwrap().display().to_string());
|
||||
settings.set_prepend_module_to_snapshot(false);
|
||||
let _guard = settings.bind_to_scope();
|
||||
|
||||
let input = std::fs::read_to_string(path).unwrap();
|
||||
|
||||
let (context, input) = input.split_once("\n---\n").unwrap_or_else(|| ("", &input));
|
||||
|
||||
let map = if !context.is_empty() {
|
||||
serde_json::from_str::<HashMap<String, serde_json::Value>>(context).unwrap()
|
||||
} else {
|
||||
HashMap::new()
|
||||
};
|
||||
|
||||
let mut context = Context::new();
|
||||
|
||||
for (k, v) in map {
|
||||
context.insert(k, v);
|
||||
}
|
||||
|
||||
let parsed = temple::parser::parse(input.into()).unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!("parsed", parsed);
|
||||
|
||||
let ast = temple::ast::parse(parsed.tokens()).unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!("ast", ast);
|
||||
|
||||
let emit = temple::emit::emit_machine(ast);
|
||||
|
||||
insta::assert_debug_snapshot!("instructions", emit);
|
||||
|
||||
let output = temple::eval::execute(&emit, &context).unwrap();
|
||||
|
||||
insta::assert_debug_snapshot!("output", output);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue