[fine] The VM lives! We can test it a little!
This commit is contained in:
parent
866830b485
commit
1eb7da77fc
8 changed files with 117 additions and 15 deletions
|
|
@ -2,7 +2,7 @@ use fine::compiler::{compile, Function, Module};
|
|||
use fine::parser::SyntaxTree;
|
||||
use fine::semantics::{check, Error, Semantics, Type};
|
||||
use fine::tokens::Lines;
|
||||
use fine::vm::{eval, Context};
|
||||
use fine::vm::{eval_export_fn, Context};
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::fmt::Write as _;
|
||||
|
||||
|
|
@ -264,13 +264,19 @@ fn assert_eval_ok(tree: &SyntaxTree, lines: &Lines, expected: &str) {
|
|||
let semantics = Semantics::new(tree, lines);
|
||||
|
||||
let module = compile(&semantics);
|
||||
let main_function = module.functions[module.init].clone();
|
||||
let mut context = Context::new(module);
|
||||
context.init().expect("Unable to initialize module");
|
||||
|
||||
let mut context = Context::new(module.clone());
|
||||
match eval(&mut context, main_function, vec![]) {
|
||||
match eval_export_fn(&mut context, "test", &[]) {
|
||||
Ok(v) => {
|
||||
let actual = format!("{:?}", v);
|
||||
semantic_assert_eq!(&semantics, None, expected, &actual, "module evaluated");
|
||||
semantic_assert_eq!(
|
||||
&semantics,
|
||||
None,
|
||||
expected,
|
||||
&actual,
|
||||
"wrong return from test function"
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
semantic_panic!(&semantics, None, "error occurred while running: {:?}", e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue