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

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

            
12
2
fn compile(code: &str) -> Result<Vec<u8>, nomiscript::Error> {
13
2
    let program = Reader::parse(code)?;
14
2
    let mut symbols = SymbolTable::with_builtins_for_wasm();
15
2
    Compiler::new().compile(&program, &mut symbols)
16
2
}
17

            
18
#[test]
19
1
fn test_basic_defstruct() {
20
1
    let code = r"
21
1
    (defstruct person name age)
22
1
    (quote person)
23
1
    ";
24
1
    let result = eval_expr(code);
25
1
    assert!(result.is_ok(), "Basic DEFSTRUCT should work");
26
1
}
27

            
28
#[test]
29
1
fn test_defstruct_constructor() {
30
1
    let code = r#"
31
1
    (defstruct person name age)
32
1
    (make-person :name "John" :age 30)
33
1
    "#;
34
1
    let wasm = compile(code);
35
1
    assert!(
36
1
        wasm.is_ok(),
37
        "DEFSTRUCT constructor should compile: {wasm:?}"
38
    );
39
1
}
40

            
41
#[test]
42
1
fn test_setf_with_defstruct() {
43
1
    let code = r#"
44
1
    (defstruct person name age)
45
1
    (let ((p (make-person :name "John" :age 30)))
46
1
      (setf (person-name p) "Jane")
47
1
      (person-name p))
48
1
    "#;
49
1
    let wasm = compile(code);
50
1
    assert!(wasm.is_ok(), "SETF with defstruct should compile: {wasm:?}");
51
1
}
52

            
53
#[test]
54
1
fn test_get_input_entities_is_wasm_only() {
55
1
    let code = r"
56
1
    ;; GET-INPUT-ENTITIES returns a runtime cons list, which is WASM-only
57
1
    (get-input-entities)
58
1
    ";
59
1
    let result = eval_expr(code);
60
1
    assert!(
61
1
        result.is_err(),
62
        "GET-INPUT-ENTITIES should fail in interpreter (WASM-only)"
63
    );
64
1
}