mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
test: add match sumtype var shadow and as
test
This commit is contained in:
parent
45239cbd62
commit
3533335804
31
vlib/v/tests/match_sumtype_var_shadow_and_as.v
Normal file
31
vlib/v/tests/match_sumtype_var_shadow_and_as.v
Normal file
@ -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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user