added list len, front, and back

This commit is contained in:
Ava Hahn 2023-03-07 14:29:31 -08:00
parent 06d30ac263
commit 7fd47c1812
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
5 changed files with 215 additions and 12 deletions

View file

@ -85,4 +85,106 @@ mod append_lib_tests {
result.to_string(),
);
}
#[test]
fn test_len_empty() {
let document = "(len ())";
let result = "0";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
#[test]
fn test_len_normal() {
let document = "(len (1 2 3))";
let result = "3";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
#[test]
fn test_car_empty() {
let document = "(car ())";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.err()
.unwrap()
.to_string(),
"error in call to car: argument is empty".to_string(),
);
}
#[test]
fn test_car_normal() {
let document = "(car (1 2 3))";
let result = "1";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
#[test]
fn test_cdr_empty() {
let document = "(cdr ())";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.err()
.unwrap()
.to_string(),
"error in call to cdr: argument is empty".to_string(),
);
}
#[test]
fn test_cdr_normal() {
let document = "(cdr (1 2 3))";
let result = "3";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
}