1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use toasty_core::stmt::{ConstInput, Expr, Value};
// ---------------------------------------------------------------------------
// Empty record
// ---------------------------------------------------------------------------
#[test]
fn eval_record_empty() {
assert_eq!(
Expr::record(std::iter::empty::<Expr>())
.eval_const()
.unwrap(),
Value::record_from_vec(vec![])
);
}
// ---------------------------------------------------------------------------
// Single-field record
// ---------------------------------------------------------------------------
#[test]
fn eval_record_one_i64() {
assert_eq!(
Expr::record([1i64]).eval_const().unwrap(),
Value::record_from_vec(vec![Value::I64(1)])
);
}
#[test]
fn eval_record_one_string() {
assert_eq!(
Expr::record(["hello"]).eval_const().unwrap(),
Value::record_from_vec(vec![Value::from("hello")])
);
}
// ---------------------------------------------------------------------------
// Multi-field records
// ---------------------------------------------------------------------------
#[test]
fn eval_record_two_fields() {
assert_eq!(
Expr::record([Expr::from(true), Expr::from(42i64)])
.eval_const()
.unwrap(),
Value::record_from_vec(vec![Value::Bool(true), Value::I64(42)])
);
}
#[test]
fn eval_record_three_fields() {
assert_eq!(
Expr::record([Expr::from(1i64), Expr::from("hi"), Expr::from(Value::Null)])
.eval_const()
.unwrap(),
Value::record_from_vec(vec![Value::I64(1), Value::from("hi"), Value::Null])
);
}
// ---------------------------------------------------------------------------
// Fields are expressions — they are evaluated, not stored raw
// ---------------------------------------------------------------------------
#[test]
fn eval_record_fields_are_evaluated() {
// A field that is itself an expression (is_null)
let expr = Expr::record([Expr::is_null(Value::Null), Expr::from(1i64)]);
assert_eq!(
expr.eval_const().unwrap(),
Value::record_from_vec(vec![Value::Bool(true), Value::I64(1)])
);
}
// ---------------------------------------------------------------------------
// eval() with ConstInput agrees with eval_const()
// ---------------------------------------------------------------------------
#[test]
fn eval_with_input_agrees() {
let expr = Expr::record([Expr::from(1i64), Expr::from("a")]);
assert_eq!(
expr.eval(ConstInput::new()).unwrap(),
expr.eval_const().unwrap()
);
}