diff --git a/src/protocol/tests/eval_binding.rs b/src/protocol/tests/eval_binding.rs index 4a44447ff65c2fef8dacaaa212a9bb63aaf71d88..acdeb70a9569f6b744905e408e4f673f3c565902 100644 --- a/src/protocol/tests/eval_binding.rs +++ b/src/protocol/tests/eval_binding.rs @@ -82,6 +82,53 @@ fn test_binding_from_array() { }); } +#[test] +fn test_binding_from_union() { + Tester::new_single_source_expect_ok("option type", " + union Option { Some(T), None } + + func is_some(Option opt) -> bool { + if (let Option::Some(throwaway) = opt) return true; + else return false; + } + func is_none(Option opt) -> bool { + if (let Option::Some(throwaway) = opt) return false; + else return true; + } + + func foo() -> u32 { + // Hey look, we're so modern, we have algebraic discriminated sum datauniontypes + auto something = Option::Some(5); + auto nonething = Option::None; + + bool success1 = false; + if (let Option::Some(value) = something && let Option::None = nonething) { + success1 = value == 5; + } + + bool success2 = false; + if (is_some(something) && is_none(nonething)) { + success2 = true; + } + + bool success3 = true; + if (let Option::None = something) success3 = false; + if (let Option::Some(value) = nonething) success3 = false; + + bool success4 = true; + if (is_none(something) || is_some(nonething)) success4 = false; + + if (success1 && success2 && success3 && success4) { + if (let Option::Some(value) = something) return value; + } + + return 0; + } + ").for_function("foo", |f| { f + .call_ok(Some(Value::UInt32(5))); + }); +} + #[test] fn test_binding_fizz_buzz() { Tester::new_single_source_expect_ok("am I employable?", "