Lines
100 %
Functions
Branches
use nomiscript::{
Reader, eval_program,
runtime::{SymbolTable, Value},
};
fn eval_expr(code: &str) -> (SymbolTable, Result<Value, nomiscript::Error>) {
let mut symbols = SymbolTable::with_builtins();
let result = Reader::parse(code).and_then(|program| eval_program(&mut symbols, &program));
(symbols, result)
}
#[test]
fn test_defstruct_creates_functions() {
let (symbols, result) = eval_expr("(defstruct person name age) T");
assert!(result.is_ok(), "DEFSTRUCT should succeed and return T");
for name in [
"MAKE-PERSON",
"PERSON-P",
"COPY-PERSON",
"PERSON-NAME",
"PERSON-AGE",
"(SETF PERSON-NAME)",
"(SETF PERSON-AGE)",
] {
assert!(symbols.contains(name), "{name} should be defined");
fn test_defstruct_constructor_exists() {
let (symbols, result) = eval_expr("(defstruct person name age) (quote (make-person))");
assert!(result.is_ok(), "Constructor function should exist");
assert!(symbols.contains("MAKE-PERSON"));