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
// Reference witness: recursively-nested OcelAttributeValue structures — List and
// Map nesting to arbitrary depth (COVERAGE.md §2 — OCEL attribute recursion).
//
// OcelAttributeValue::{List, Map} are recursive: a List of Maps of Lists, etc.
// This witnesses constructing and traversing a nested structure, proving the
// recursion composes (not just the flat variants).
use wasm4pm_compat::ocel::OcelAttributeValue as V;
#[test]
fn nested_list_and_map_values_compose() {
// A map with a nested list value: {"items": [1, 2], "meta": {"flag": true}}
let nested = V::Map(vec![
(
"items".to_string(),
V::List(vec![V::Integer(1), V::Integer(2)]),
),
(
"meta".to_string(),
V::Map(vec![("flag".to_string(), V::Boolean(true))]),
),
]);
match &nested {
V::Map(entries) => {
assert_eq!(entries.len(), 2, "two top-level keys");
// Traverse into the nested list.
match &entries[0].1 {
V::List(items) => {
assert_eq!(items.len(), 2);
assert!(matches!(items[1], V::Integer(2)));
}
other => panic!("items should be a List; got {other:?}"),
}
// Traverse into the nested map.
match &entries[1].1 {
V::Map(inner) => assert!(matches!(inner[0].1, V::Boolean(true))),
other => panic!("meta should be a Map; got {other:?}"),
}
}
other => panic!("expected a Map; got {other:?}"),
}
}
#[test]
fn deeply_nested_lists() {
// [[[42]]] — three levels of list nesting.
let deep = V::List(vec![V::List(vec![V::List(vec![V::Integer(42)])])]);
let mut cur = &deep;
for _ in 0..3 {
cur = match cur {
V::List(items) => &items[0],
other => panic!("expected nested List; got {other:?}"),
};
}
assert!(
matches!(cur, V::Integer(42)),
"innermost value reached through 3 list levels"
);
}