190 lines
4.8 KiB
Rust
190 lines
4.8 KiB
Rust
mod append_lib_tests {
|
|
use relish::ast::{eval, lex, SymTable};
|
|
use relish::stdlib::{dynamic_stdlib, static_stdlib};
|
|
|
|
#[test]
|
|
fn test_append_to_empty_list() {
|
|
let document = "(append () 1)";
|
|
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_multi_append_to_empty_list() {
|
|
let document = "(append () 1 'two' 3.4)";
|
|
let result = "(1 'two' 3.4)";
|
|
|
|
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_append_to_full_list() {
|
|
let document = "(append (1 2) 3)";
|
|
let result = "(1 2 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_mono_append() {
|
|
let document = "(append)";
|
|
let result = "(<nil>)";
|
|
|
|
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_append_no_list() {
|
|
let document = "(append 'test' 1 2 3)";
|
|
let result = "('test' 1 2 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_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(),
|
|
);
|
|
}
|
|
}
|