use std::collections::HashMap; use nomo::Context; #[derive(serde::Serialize)] struct Info { input: String, context: HashMap, } #[test] fn check_cases() { insta::glob!("cases/*.nomo", |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 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::>(context).unwrap() } else { HashMap::new() }; settings.set_info(&Info { input: input.to_string(), context: map.clone(), }); let mut context = Context::new(); for (k, v) in map { context.try_insert(k, v).unwrap(); } let parsed = nomo::parser::parse(input.into()).unwrap(); let _guard = settings.bind_to_scope(); insta::assert_debug_snapshot!("1-parsed", parsed); let ast = match nomo::ast::parse(parsed.tokens()) { Ok(ast) => ast, Err(err) => { eprintln!("{}", err.to_report(input)); panic!("Could not evaluate ast"); } }; insta::assert_debug_snapshot!("2-ast", ast); let emit = nomo::emit::emit_machine(ast); insta::assert_debug_snapshot!("3-instructions", emit); let output = nomo::eval::execute(&emit, &context).unwrap(); insta::assert_debug_snapshot!("4-output", output); }); }