From 3533335804f8f54e377224f073bb5cbdf917b8cf Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Fri, 19 Jun 2020 01:06:40 +1000 Subject: [PATCH] test: add match sumtype var shadow and `as` test --- .../v/tests/match_sumtype_var_shadow_and_as.v | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 vlib/v/tests/match_sumtype_var_shadow_and_as.v diff --git a/vlib/v/tests/match_sumtype_var_shadow_and_as.v b/vlib/v/tests/match_sumtype_var_shadow_and_as.v new file mode 100644 index 0000000000..6ecd2e8b99 --- /dev/null +++ b/vlib/v/tests/match_sumtype_var_shadow_and_as.v @@ -0,0 +1,31 @@ +struct Cat{name string} +struct Dog{name string} + +type Animal = Cat | Dog + +fn main() { + cat := Cat{name: 'cat'} + dog := Cat{name: 'dog'} + mut animal := Animal{} + + // test shaddow + animal = cat + match animal { + Cat { + assert animal.name == cat.name + } + else{ + assert false + } + } + // test as + animal = dog + match animal as animal_kind { + Dog { + assert animal_kind.name == dog.name + } + else{ + assert false + } + } +}