finished while form

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-02 15:29:50 -08:00
parent 6ef467db94
commit c235f9727f
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
5 changed files with 185 additions and 5 deletions

View file

@ -131,4 +131,86 @@ mod control_lib_tests {
assert!(false);
}
}
#[test]
fn test_while_basic() {
let switch_dec = "(def switch true)";
// if prev is true, switch looped once and only once
// else prev will have a problematic type
let while_loop = "
(while switch
(def prev switch)
(toggle switch)
(if switch
(def prev)
()))";
let test_check = "prev";
let switch_tree = lex(&switch_dec.to_string()).unwrap();
let while_tree = lex(&while_loop.to_string()).unwrap();
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&switch_tree, &mut syms).unwrap();
eval(&while_tree, &mut syms).unwrap();
eval(&check_tree, &mut syms).unwrap();
}
#[test]
fn test_while_eval_cond() {
let switch_dec = "(def switch true)";
// if prev is true, switch looped once and only once
// else prev will have a problematic type
let while_loop = "
(while (or switch switch)
(def prev switch)
(toggle switch)
(if switch
(def prev)
()))";
let test_check = "prev";
let switch_tree = lex(&switch_dec.to_string()).unwrap();
let while_tree = lex(&while_loop.to_string()).unwrap();
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&switch_tree, &mut syms).unwrap();
eval(&while_tree, &mut syms).unwrap();
eval(&check_tree, &mut syms).unwrap();
}
#[test]
fn test_while_2_iter() {
let additional = "(def sw1 true)";
let switch_dec = "(def sw2 true)";
// while should loop twice and define result
let while_loop = "
(while sw1
(toggle sw2)
(if (and sw1 sw2)
(def sw1 false)
(def result 'yay')))";
let test_check = "result";
let another_tree = lex(&additional.to_string()).unwrap();
let switch_tree = lex(&switch_dec.to_string()).unwrap();
let while_tree = lex(&while_loop.to_string()).unwrap();
let check_tree = lex(&test_check.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&another_tree, &mut syms).unwrap();
eval(&switch_tree, &mut syms).unwrap();
eval(&while_tree, &mut syms).unwrap();
eval(&check_tree, &mut syms).unwrap();
}
}