Skip to content

Commit 44909f9

Browse files
committed
Implementa Definição de Testes no Interpretador
1 parent e0ad684 commit 44909f9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

src/interpreter/statement_execute.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ pub fn execute(stmt: Statement, env: &Environment<Expression>) -> Result<Computa
320320
Ok(Computation::Continue(new_env))
321321
}
322322

323+
Statement::TestDef(teste) => {
324+
new_env.map_test(teste.clone());
325+
Ok(Computation::Continue(new_env))
326+
}
327+
323328
Statement::Return(exp) => {
324329
let exp_value = match eval(*exp, &new_env)? {
325330
ExpressionResult::Value(expr) => expr,
@@ -1098,4 +1103,28 @@ mod tests {
10981103
assert_eq!(computation, "assertfalse fail".to_string());
10991104
}
11001105
}
1106+
mod testdef_statement_tests {
1107+
use super::*;
1108+
1109+
#[test]
1110+
fn test_execute_testdef() {
1111+
let env = create_test_env();
1112+
let test_def = Statement::TestDef(Function {
1113+
name: "test_example".to_string(),
1114+
kind: Type::TVoid,
1115+
params: Vec::new(),
1116+
body: Some(Box::new(Statement::Block(vec![Statement::Assert(
1117+
Box::new(Expression::CTrue),
1118+
Box::new(Expression::CString("Test passed".to_string())),
1119+
)]))),
1120+
});
1121+
let programa = Statement::Block(vec![test_def.clone()]);
1122+
match execute(programa, &env) {
1123+
Ok(Computation::Continue(new_env)) => {
1124+
assert!(new_env.lookup_test(&"test_example".to_string()).is_some());
1125+
}
1126+
_ => panic!("Test definition execution failed"),
1127+
}
1128+
}
1129+
}
11011130
}

0 commit comments

Comments
 (0)