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

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

            
12
#[test]
13
1
fn test_transaction_struct_definition() {
14
1
    let code = r"
15
1
    (defstruct transaction
16
1
        post-date
17
1
        enter-date
18
1
        split-count
19
1
        tag-count
20
1
        is-multi-currency)
21
1
    T
22
1
    ";
23
1
    let result = eval_expr(code);
24
1
    assert!(
25
1
        result.is_ok(),
26
        "Transaction struct should be defined successfully"
27
    );
28
1
}
29

            
30
#[test]
31
1
fn test_split_struct_definition() {
32
1
    let code = r"
33
1
    (defstruct split
34
1
        account-id
35
1
        commodity-id
36
1
        value-num
37
1
        value-denom
38
1
        reconcile-state
39
1
        reconcile-date)
40
1
    T
41
1
    ";
42
1
    let result = eval_expr(code);
43
1
    assert!(
44
1
        result.is_ok(),
45
        "Split struct should be defined successfully"
46
    );
47
1
}
48

            
49
#[test]
50
1
fn test_account_struct_definition() {
51
1
    let code = r"
52
1
    (defstruct account
53
1
        parent-account-id
54
1
        name
55
1
        path
56
1
        tag-count)
57
1
    T
58
1
    ";
59
1
    let result = eval_expr(code);
60
1
    assert!(
61
1
        result.is_ok(),
62
        "Account struct should be defined successfully"
63
    );
64
1
}
65

            
66
#[test]
67
1
fn test_commodity_struct_definition() {
68
1
    let code = r"
69
1
    (defstruct commodity
70
1
        symbol
71
1
        name
72
1
        tag-count)
73
1
    T
74
1
    ";
75
1
    let result = eval_expr(code);
76
1
    assert!(
77
1
        result.is_ok(),
78
        "Commodity struct should be defined successfully"
79
    );
80
1
}
81

            
82
#[test]
83
1
fn test_tag_struct_definition() {
84
1
    let code = r"
85
1
    (defstruct tag
86
1
        name
87
1
        value)
88
1
    T
89
1
    ";
90
1
    let result = eval_expr(code);
91
1
    assert!(result.is_ok(), "Tag struct should be defined successfully");
92
1
}
93

            
94
#[test]
95
1
fn test_all_financial_structs() {
96
1
    let code = r"
97
1
    (defstruct transaction
98
1
        post-date
99
1
        enter-date
100
1
        split-count
101
1
        tag-count
102
1
        is-multi-currency)
103
1

            
104
1
    (defstruct split
105
1
        account-id
106
1
        commodity-id
107
1
        value-num
108
1
        value-denom
109
1
        reconcile-state
110
1
        reconcile-date)
111
1

            
112
1
    (defstruct account
113
1
        parent-account-id
114
1
        name
115
1
        path
116
1
        tag-count)
117
1

            
118
1
    (defstruct commodity
119
1
        symbol
120
1
        name
121
1
        tag-count)
122
1

            
123
1
    (defstruct tag
124
1
        name
125
1
        value)
126
1

            
127
1
    T
128
1
    ";
129
1
    let result = eval_expr(code);
130
1
    assert!(
131
1
        result.is_ok(),
132
        "All financial structs should be defined successfully"
133
    );
134
1
}