diff --git a/src/protocol/tests/eval_binding.rs b/src/protocol/tests/eval_binding.rs index f4241920636e5f82b23b095b5208ad0e6399017d..1d61b48dcda8a059da5b67fdf085926bd67aa84d 100644 --- a/src/protocol/tests/eval_binding.rs +++ b/src/protocol/tests/eval_binding.rs @@ -129,6 +129,40 @@ fn test_binding_from_union() { }); } +#[test] +fn test_binding_from_tuple() { + Tester::new_single_source_expect_ok("tuple binding", " + func foo() -> u32 { + u64 value = 2000; + auto tuple = (\"hello\", value, 21); + + bool success1 = false; + if (let (\"hello\", value, 21) = tuple && let (a, b, c) = tuple) { + success1 = a == \"hello\" && b == value && c == 21; + } + + bool success2 = true; + if (let (\"nope\", a, b) = tuple) success2 = false; + if (let (\"hello\", 2001, 21) = tuple) success2 = false; + if (let (a, 2001, b) = tuple) success2 = false; + if (let (a, b, 22) = tuple) success2 = false; + + bool success3 = false; + if (let (\"hello\", v2a, v3a) = tuple && let (v1a, 2000, v3b) = tuple && let (v1b, v2b, 21) = tuple) { + success3 = v1a == v1b && v2a == v2b && v3a == v3b; + } + + if (success1 && success2 && success3 && let (\"hello\", a, b) = tuple) { + return cast(a) + b; + } + + return 0; + } + ").for_function("foo", |f| { f + .call_ok(Some(Value::UInt32(2021))); + }); +} + #[test] fn test_binding_fizz_buzz() { Tester::new_single_source_expect_ok("am I employable?", "