implement iseq, tests

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-02 12:48:26 -08:00
parent 5ce0a8e8b2
commit cb83fa5655
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
6 changed files with 134 additions and 25 deletions

View file

@ -238,4 +238,116 @@ mod bool_lib_tests {
panic!()
}
}
#[test]
fn test_iseq_basic_t() {
let document = "(eq? true true)";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(b)
} else {
panic!()
}
}
#[test]
fn test_iseq_basic_f() {
let document = "(eq? true false)";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(!b)
} else {
panic!()
}
}
#[test]
fn test_iseq_basic_f_mixed_data() {
let document = "(eq? true 1)";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(!b)
} else {
panic!()
}
}
#[test]
fn test_iseq_long_f() {
let document = "(eq? true true true true true false)";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(!b)
} else {
panic!()
}
}
#[test]
fn test_iseq_long_t_str() {
let document = "(eq? '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1' '1')";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(b)
} else {
panic!()
}
}
#[test]
fn test_iseq_t_mixed_numerals() {
let document = "(eq? 1 1.0)";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(b)
} else {
panic!()
}
}
#[test]
fn test_iseq_f_wrong_type() {
let document = "(eq? 1 '1')";
let test = lex(&document.to_string()).unwrap();
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&test, &mut syms).unwrap() {
assert!(!b)
} else {
panic!()
}
}
}