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
use toasty_core::stmt::{ConstInput, Expr, Value};
// ---------------------------------------------------------------------------
// Identity map — arg(0) returns each item unchanged
// ---------------------------------------------------------------------------
#[test]
fn map_identity_i64() {
let expr = Expr::map(Expr::list([1i64, 2i64, 3i64]), Expr::arg(0usize));
assert_eq!(
expr.eval_const().unwrap(),
Value::List(vec![Value::I64(1), Value::I64(2), Value::I64(3)])
);
}
#[test]
fn map_identity_strings() {
let expr = Expr::map(Expr::list(["a", "b"]), Expr::arg(0usize));
assert_eq!(
expr.eval_const().unwrap(),
Value::List(vec![Value::from("a"), Value::from("b")])
);
}
// ---------------------------------------------------------------------------
// Empty list maps to empty list
// ---------------------------------------------------------------------------
#[test]
fn map_empty_list() {
let expr = Expr::map(Expr::list(std::iter::empty::<Expr>()), Expr::arg(0usize));
assert_eq!(expr.eval_const().unwrap(), Value::List(vec![]));
}
// ---------------------------------------------------------------------------
// Transform map — apply a function to each item
// ---------------------------------------------------------------------------
#[test]
fn map_is_null_over_list() {
// [Null, I64(1)] → [true, false]
let expr = Expr::map(
Expr::list([Expr::from(Value::Null), Expr::from(1i64)]),
Expr::is_null(Expr::arg(0usize)),
);
assert_eq!(
expr.eval_const().unwrap(),
Value::List(vec![Value::Bool(true), Value::Bool(false)])
);
}
#[test]
fn map_not_over_bools() {
// [true, false] → [false, true]
let expr = Expr::map(Expr::list([true, false]), Expr::not(Expr::arg(0usize)));
assert_eq!(
expr.eval_const().unwrap(),
Value::List(vec![Value::Bool(false), Value::Bool(true)])
);
}
// ---------------------------------------------------------------------------
// eval() with ConstInput agrees with eval_const()
// ---------------------------------------------------------------------------
#[test]
fn eval_with_input_agrees() {
let expr = Expr::map(Expr::list([1i64]), Expr::arg(0usize));
assert_eq!(
expr.eval(ConstInput::new()).unwrap(),
expr.eval_const().unwrap()
);
}
// ---------------------------------------------------------------------------
// Non-list base — returns Err
// ---------------------------------------------------------------------------
#[test]
fn map_non_list_base_is_error() {
let expr = Expr::map(42i64, Expr::arg(0usize));
assert!(expr.eval_const().is_err());
}