finished while form
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
6ef467db94
commit
c235f9727f
5 changed files with 185 additions and 5 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue