1
use nomiscript::{
2
    Reader, eval_program,
3
    runtime::{SymbolTable, Value},
4
};
5

            
6
2
fn eval_expr(code: &str) -> (SymbolTable, Result<Value, nomiscript::Error>) {
7
2
    let mut symbols = SymbolTable::with_builtins();
8
2
    let result = Reader::parse(code).and_then(|program| eval_program(&mut symbols, &program));
9
2
    (symbols, result)
10
2
}
11

            
12
#[test]
13
1
fn test_defstruct_creates_functions() {
14
1
    let (symbols, result) = eval_expr("(defstruct person name age) T");
15
1
    assert!(result.is_ok(), "DEFSTRUCT should succeed and return T");
16
1
    for name in [
17
1
        "MAKE-PERSON",
18
1
        "PERSON-P",
19
1
        "COPY-PERSON",
20
1
        "PERSON-NAME",
21
1
        "PERSON-AGE",
22
1
        "(SETF PERSON-NAME)",
23
1
        "(SETF PERSON-AGE)",
24
1
    ] {
25
7
        assert!(symbols.contains(name), "{name} should be defined");
26
    }
27
1
}
28

            
29
#[test]
30
1
fn test_defstruct_constructor_exists() {
31
1
    let (symbols, result) = eval_expr("(defstruct person name age) (quote (make-person))");
32
1
    assert!(result.is_ok(), "Constructor function should exist");
33
1
    assert!(symbols.contains("MAKE-PERSON"));
34
1
}