mirror of
https://github.com/vlang/v.git
synced 2025-09-11 16:36:20 -04:00
tests: add union_implementing_interface_test.v (#24857)
This commit is contained in:
parent
4db6408e0b
commit
2c4845a16f
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…
x
Reference in New Issue
Block a user