v2 / vlib / v / tests / interfaces / interface_embedding_with_interface_para_test.v
38 lines · 32 sloc · 515 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface Eq {
2 eq(other Eq) bool
3}
4
5interface Ord {
6 Eq
7 lt(other Ord) bool
8}
9
10// implement Ord for Int
11struct Int {
12 value int
13}
14
15fn (i Int) eq(other Ord) bool {
16 if other is Int {
17 return i.value == other.value
18 }
19 return false
20}
21
22fn (i Int) lt(other Ord) bool {
23 if other is Int {
24 return i.value < other.value
25 }
26 return false
27}
28
29fn compare(x Ord, y Ord) {
30 println(x.eq(y))
31 assert !x.eq(y)
32 println(x.lt(y))
33 assert x.lt(y)
34}
35
36fn test_interface_embedding_with_interface_para() {
37 compare(Int{1}, Int{2})
38}
39