flesh/tests/test_lib_append.rs

89 lines
2.3 KiB
Rust
Raw Normal View History

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!(
2023-03-05 22:21:18 -08:00
*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!(
2023-03-05 22:21:18 -08:00
*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!(
2023-03-05 22:21:18 -08:00
*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!(
2023-03-05 22:21:18 -08:00
*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!(
2023-03-05 22:21:18 -08:00
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
}