Skip to content

Commit a9a8dd6

Browse files
committed
Add tuple-with-map and single-entry map runtime tests
Exercise map inside an anonymous tuple (filter_mode_preserve_top path) and the single-entry boundary case.
1 parent ee6a8b0 commit a9a8dd6

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/runtime/map/runner.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ impl Guest for Component {
2121
test_nested_roundtrip();
2222
test_variant_roundtrip();
2323
test_result_roundtrip();
24+
test_tuple_roundtrip();
25+
test_single_entry_roundtrip();
2426
}
2527
}
2628

@@ -174,3 +176,23 @@ fn test_result_roundtrip() {
174176
Ok(_) => panic!("expected Err"),
175177
}
176178
}
179+
180+
fn test_tuple_roundtrip() {
181+
let mut map = NamesById::new();
182+
map.insert(7, "seven".to_string());
183+
let (result_map, result_num) = tuple_roundtrip((&map, 42));
184+
assert_eq!(result_map.len(), 1);
185+
assert_eq!(result_map.get(&7).map(String::as_str), Some("seven"));
186+
assert_eq!(result_num, 42);
187+
}
188+
189+
fn test_single_entry_roundtrip() {
190+
let mut input = NamesById::new();
191+
input.insert(99, "ninety-nine".to_string());
192+
let result = single_entry_roundtrip(&input);
193+
assert_eq!(result.len(), 1);
194+
assert_eq!(
195+
result.get(&99).map(String::as_str),
196+
Some("ninety-nine"),
197+
);
198+
}

tests/runtime/map/test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,16 @@ impl exports::test::maps::to_test::Guest for Component {
9696
fn result_roundtrip(a: Result<NamesById, String>) -> Result<NamesById, String> {
9797
a
9898
}
99+
100+
fn tuple_roundtrip(a: (NamesById, u64)) -> (NamesById, u64) {
101+
assert_eq!(a.0.len(), 1);
102+
assert_eq!(a.0.get(&7).map(String::as_str), Some("seven"));
103+
assert_eq!(a.1, 42);
104+
a
105+
}
106+
107+
fn single_entry_roundtrip(a: NamesById) -> NamesById {
108+
assert_eq!(a.len(), 1);
109+
a
110+
}
99111
}

tests/runtime/map/test.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface to-test {
2626
nested-roundtrip: func(a: map<string, map<u32, string>>) -> map<string, map<u32, string>>;
2727
variant-roundtrip: func(a: map-or-string) -> map-or-string;
2828
result-roundtrip: func(a: result<names-by-id, string>) -> result<names-by-id, string>;
29+
tuple-roundtrip: func(a: tuple<names-by-id, u64>) -> tuple<names-by-id, u64>;
30+
single-entry-roundtrip: func(a: names-by-id) -> names-by-id;
2931
}
3032

3133
world test {

0 commit comments

Comments
 (0)