1
//! Unit tests for entity-accessor eval handlers.
2

            
3
use crate::ast::{Expr, WasmType};
4
use crate::runtime::SymbolTable;
5

            
6
use super::meta::{
7
    context_type, entity_count, entity_type, primary_entity_idx, primary_entity_type,
8
};
9
use super::split::split_account_name;
10
use super::transaction::transaction_is_multi_currency;
11

            
12
#[test]
13
1
fn transaction_is_multi_currency_is_a_bool_truth_value() {
14
    // A predicate is a truth value, not an index: an index is never nil, so an
15
    // I32-typed flag would make `(if (transaction-is-multi-currency 0) …)`
16
    // always true.
17
1
    let mut symbols = SymbolTable::new();
18
1
    let idx = Expr::Number(crate::ast::Fraction::from_integer(0));
19
1
    let result = transaction_is_multi_currency(&mut symbols, &[idx]).unwrap();
20
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::Bool));
21
1
}
22

            
23
#[test]
24
1
fn split_account_name_returns_wasm_runtime_string() {
25
1
    let mut symbols = SymbolTable::new();
26
1
    let idx = Expr::Number(crate::ast::Fraction::from_integer(1));
27
1
    let result = split_account_name(&mut symbols, &[idx]).unwrap();
28
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::StringRef));
29
1
}
30

            
31
#[test]
32
1
fn split_account_name_arity_error() {
33
1
    let mut symbols = SymbolTable::new();
34
1
    assert!(split_account_name(&mut symbols, &[]).is_err());
35
1
}
36

            
37
#[test]
38
1
fn test_entity_count_returns_wasm_runtime_i32() {
39
1
    let mut symbols = SymbolTable::new();
40
1
    let result = entity_count(&mut symbols, &[]).unwrap();
41
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::I32));
42
1
}
43

            
44
#[test]
45
1
fn test_context_type_returns_wasm_runtime_i32() {
46
1
    let mut symbols = SymbolTable::new();
47
1
    let result = context_type(&mut symbols, &[]).unwrap();
48
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::I32));
49
1
}
50

            
51
#[test]
52
1
fn test_primary_entity_type_returns_wasm_runtime_i32() {
53
1
    let mut symbols = SymbolTable::new();
54
1
    let result = primary_entity_type(&mut symbols, &[]).unwrap();
55
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::I32));
56
1
}
57

            
58
#[test]
59
1
fn test_primary_entity_idx_returns_wasm_runtime_i32() {
60
1
    let mut symbols = SymbolTable::new();
61
1
    let result = primary_entity_idx(&mut symbols, &[]).unwrap();
62
1
    assert_eq!(result, Expr::WasmRuntime(WasmType::I32));
63
1
}
64

            
65
#[test]
66
1
fn test_entity_count_arity_error() {
67
1
    let mut symbols = SymbolTable::new();
68
1
    assert!(entity_count(&mut symbols, &[Expr::Nil]).is_err());
69
1
}
70

            
71
#[test]
72
1
fn test_entity_type_arity_error() {
73
1
    let mut symbols = SymbolTable::new();
74
1
    assert!(entity_type(&mut symbols, &[]).is_err());
75
1
}