mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
tests: add union_implementing_interface_test.v (#24857)
This commit is contained in:
parent
4db6408e0b
commit
2c4845a16f
1 changed files with 20 additions and 0 deletions
20
vlib/v/tests/unions/union_implementing_interface_test.v
Normal file
20
vlib/v/tests/unions/union_implementing_interface_test.v
Normal file
|
@ -0,0 +1,20 @@
|
|||
interface Speaker {
|
||||
speak() string
|
||||
}
|
||||
|
||||
union MyUnion implements Speaker {
|
||||
vint int
|
||||
vu32 u32
|
||||
vstring string
|
||||
}
|
||||
|
||||
fn (u MyUnion) speak() string {
|
||||
return 'hi, u.vint: ${unsafe { u.vint }}'
|
||||
}
|
||||
|
||||
fn test_union_implementing_interface() {
|
||||
s := Speaker(MyUnion{
|
||||
vint: 123
|
||||
})
|
||||
assert s.speak() == 'hi, u.vint: 123'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue