add reverse, snippet for prepend implementation
This commit is contained in:
parent
6961fcc9fa
commit
928c9b91ed
6 changed files with 288 additions and 25 deletions
|
|
@ -187,4 +187,159 @@ mod append_lib_tests {
|
|||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop() {
|
||||
let document = "(def test '' (pop (1 2 3)))";
|
||||
let check1 = "(car test)";
|
||||
let result1 = "1";
|
||||
let check2 = "(cdr test)";
|
||||
let result2 = "(2 3)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let ch1 = lex(&check1.to_string()).unwrap();
|
||||
let ch2 = lex(&check2.to_string()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch1, &mut syms).unwrap().to_string(),
|
||||
result1.to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch2, &mut syms).unwrap().to_string(),
|
||||
result2.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_pop_mono() {
|
||||
let document = "(def test '' (pop (1)))";
|
||||
let check1 = "(car test)";
|
||||
let result1 = "1";
|
||||
let check2 = "(cdr test)";
|
||||
let result2 = "(<nil>)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let ch1 = lex(&check1.to_string()).unwrap();
|
||||
let ch2 = lex(&check2.to_string()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch1, &mut syms).unwrap().to_string(),
|
||||
result1.to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch2, &mut syms).unwrap().to_string(),
|
||||
result2.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dq() {
|
||||
let document = "(def test '' (dq (1 2 3)))";
|
||||
let check1 = "(car test)";
|
||||
let result1 = "3";
|
||||
let check2 = "(cdr test)";
|
||||
let result2 = "(1 2)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let ch1 = lex(&check1.to_string()).unwrap();
|
||||
let ch2 = lex(&check2.to_string()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch1, &mut syms).unwrap().to_string(),
|
||||
result1.to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch2, &mut syms).unwrap().to_string(),
|
||||
result2.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_dq_mono() {
|
||||
let document = "(def test '' (dq (1)))";
|
||||
let check1 = "(car test)";
|
||||
let result1 = "1";
|
||||
let check2 = "(cdr test)";
|
||||
let result2 = "(<nil>)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
||||
let ch1 = lex(&check1.to_string()).unwrap();
|
||||
let ch2 = lex(&check2.to_string()).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch1, &mut syms).unwrap().to_string(),
|
||||
result1.to_string(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
*eval(&ch2, &mut syms).unwrap().to_string(),
|
||||
result2.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_reverse() {
|
||||
let document = "(reverse ('test' 1 2 3))";
|
||||
let result = "(3 2 1 'test')";
|
||||
|
||||
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_reverse_mono() {
|
||||
let document = "(reverse ('test'))";
|
||||
let result = "('test')";
|
||||
|
||||
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_reverse_nil() {
|
||||
let document = "(reverse ())";
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue