v2 / vlib / v / tests / generics / generics_array_builtin_method_call_test.v
32 lines · 28 sloc · 477 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Container[T] {
2mut:
3 items []T
4}
5
6fn (mut c Container[T]) pop() ?T {
7 return c.items.pop()
8}
9
10struct Item {
11 data string
12 priority int
13}
14
15fn test_generic_array_pop_call() {
16 mut a1 := Container[int]{
17 items: [11, 22]
18 }
19 println(a1)
20 ret1 := a1.pop() or { 0 }
21 println(ret1)
22 assert ret1 == 22
23
24 item1 := Item{'a', 1}
25 item2 := Item{'b', 2}
26 mut a2 := Container[Item]{
27 items: [item1, item2]
28 }
29 println(a2)
30 ret2 := a2.pop() or { Item{} }
31 assert ret2 == item2
32}
33