mod append_lib_tests { use relish::ast::{Ctr, eval, lex, SymTable}; use relish::stdlib::{static_stdlib, dynamic_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(false, &mut syms).unwrap(); if let Ok(tree) = lex(&document.to_string()) { if let Ctr::Seg(ref s) = *eval(&tree, &mut syms).unwrap() { assert_eq!(s.to_string(), result); } } else { assert!(false) } } #[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(false, &mut syms).unwrap(); if let Ok(tree) = lex(&document.to_string()) { if let Ctr::Seg(ref s) = *eval(&tree, &mut syms).unwrap() { assert_eq!(s.to_string(), result); } } else { assert!(false); } } #[test] fn test_mono_append() { let document = "(append)"; let result = "()"; let mut syms = SymTable::new(); static_stdlib(&mut syms).unwrap(); dynamic_stdlib(false, &mut syms).unwrap(); if let Ok(tree) = lex(&document.to_string()) { if let Ctr::Seg(ref s) = *eval(&tree, &mut syms).unwrap() { assert_eq!(s.to_string(), result); } } else { assert!(false); } } #[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(false, &mut syms).unwrap(); if let Ok(tree) = lex(&document.to_string()) { if let Ctr::Seg(ref s) = *eval(&tree, &mut syms).unwrap() { assert_eq!(s.to_string(), result); } } else { assert!(false); } } }