v2 / vlib / v / tests / options / option_cast_test.v
69 lines · 60 sloc · 767 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1struct Test {
2 a int
3}
4
5type MySum = f64 | int
6
7type MyAlias = Test
8
9fn test_int() {
10 a := ?int(1)
11 if a != none {
12 assert dump(a) == 1
13 assert true
14 } else {
15 assert false
16 }
17}
18
19fn test_struct() {
20 b := ?Test{
21 a: 1
22 }
23 if b != none {
24 assert dump(b) == Test{
25 a: 1
26 }
27 assert true
28 } else {
29 assert false
30 }
31}
32
33fn test_string() {
34 c := ?string('foo')
35 if c != none {
36 assert dump(c) == 'foo'
37 assert true
38 } else {
39 assert false
40 }
41}
42
43fn test_sum_type() {
44 d := ?MySum(1.2)
45 assert d != none
46
47 if d != none {
48 assert dump(d) == MySum(1.2)
49 assert true
50 } else {
51 assert false
52 }
53}
54
55fn test_alias() {
56 d := ?MyAlias(Test{
57 a: 1
58 })
59 assert d != none
60
61 if d != none {
62 assert dump(d) == Test{
63 a: 1
64 }
65 assert true
66 } else {
67 assert false
68 }
69}
70