nomo/tests/file_tests.rs
Marcel Müller d3e6410ec0 Setup a testing bench
Signed-off-by: Marcel Müller <neikos@neikos.email>
2026-03-06 13:56:39 +01:00

46 lines
1.3 KiB
Rust

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);
});
}