finished circuit form

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-03 14:29:53 -08:00
parent c235f9727f
commit 4b587f11ab
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
7 changed files with 144 additions and 53 deletions

View file

@ -160,7 +160,7 @@ mod bool_lib_tests {
eval(&change_tree, &mut syms).unwrap();
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
if let Ctr::Bool(ref b) = *s.car{
if let Ctr::Bool(ref b) = *s.car {
assert_eq!(false, *b)
} else {
panic!()
@ -171,7 +171,7 @@ mod bool_lib_tests {
eval(&change_tree, &mut syms).unwrap();
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
if let Ctr::Bool(ref b) = *s.car{
if let Ctr::Bool(ref b) = *s.car {
assert_eq!(true, *b)
} else {
panic!()
@ -197,7 +197,10 @@ mod bool_lib_tests {
eval(&doc_tree, &mut syms).unwrap();
if let Err(s) = eval(&change_tree, &mut syms) {
assert_eq!(s, "error in call to toggle: can only toggle a boolean".to_string());
assert_eq!(
s,
"error in call to toggle: can only toggle a boolean".to_string()
);
let intermediate = *eval(&check_tree, &mut syms).unwrap();
if let Ctr::Seg(ref s) = intermediate {
assert_eq!(s.to_string(), "('oops')".to_string());
@ -227,7 +230,10 @@ mod bool_lib_tests {
eval(&doc_tree, &mut syms).unwrap();
if let Err(s) = eval(&change_tree, &mut syms) {
assert_eq!(s, "error in call to toggle: cannot toggle a function".to_string());
assert_eq!(
s,
"error in call to toggle: cannot toggle a function".to_string()
);
if let Ctr::String(ref s) = *eval(&check_tree, &mut syms).unwrap() {
assert_eq!(*s, "1".to_string());
} else {

View file

@ -213,4 +213,45 @@ mod control_lib_tests {
eval(&while_tree, &mut syms).unwrap();
eval(&check_tree, &mut syms).unwrap();
}
#[test]
fn test_circuit_basic() {
let document = "(if (circuit true (and true true) true) (def result 'passed') ())";
let test = "result";
let doc_tree = lex(&document.to_string()).unwrap();
let test_tree = lex(&test.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&doc_tree, &mut syms).unwrap();
let res = eval(&test_tree, &mut syms);
println!("{:#?}", res);
res.unwrap();
}
#[test]
fn test_circuit_fail() {
let document = "(if (circuit true (and false true) true) (def result 'passed') ())";
let test = "result";
let doc_tree = lex(&document.to_string()).unwrap();
let test_tree = lex(&test.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&doc_tree, &mut syms).unwrap();
if let Err(s) = eval(&test_tree, &mut syms) {
assert_eq!(
s,
"error in call to result: undefined symbol: result".to_string()
);
} else {
panic!();
}
}
}