1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/compiler/tests/interface_test.v
2020-03-14 14:19:56 +01:00

74 lines
916 B
V

struct Dog {
breed string
}
struct Cat {
breed string
}
fn (d Cat) name() string { return 'Cat' }
fn (d Cat) speak() { println('meow') }
fn (d Dog) speak() { println('woof') }
fn (d Dog) name() string { return 'Dog'}
interface Speaker {
name() string
speak()
}
interface Speak2er {
name() string
speak()
}
struct Foo {
speaker Speaker
speakers []Speaker
}
fn perform_speak(s Speaker) {
s.speak()
assert true
name := s.name()
assert name == 'Dog' || name == 'Cat'
println(s.name())
}
fn perform_speakers(speakers []Speaker) {
}
fn test_perform_speak() {
dog := Dog{}
perform_speak(dog)
cat := Cat{}
perform_speak(cat)
//perform_speakers([dog, cat])
/*
f := Foo {
speaker: dog
}
*/
}
interface Register {
register()
}
struct RegTest {a int}
fn (f RegTest) register() {
}
fn handle_reg(r Register) {
}
fn test_register() {
f := RegTest{}
f.register()
handle_reg(f)
}