v2 / vlib / v / tests / options / option_struct_compare_test.v
88 lines · 73 sloc · 940 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1interface Interface {
2 a ?int
3}
4
5struct Test2 {
6 a ?int
7}
8
9type Alias = int
10type AliasStruct = Test2
11type AliasStruct2 = fn ()
12
13type AliasStruct3 = []int
14
15type SumType = Alias | AliasStruct2 | f64 | int
16
17struct Test {
18mut:
19 a ?int
20 b ?f64
21 c ?string
22 d ?[]int
23 e ?[]string
24 f ?[]f64
25 g ?fn ()
26 h ?Alias
27 i ?Interface = Test2{
28 a: -1
29 }
30 j ?AliasStruct
31 k ?AliasStruct2
32 l ?AliasStruct3
33 m ?SumType
34 n SumType
35}
36
37fn test_simple_compare() {
38 mut a := Test{}
39 mut b := Test{}
40 assert a == b
41}
42
43fn test_anon_compare() {
44 z := fn () {}
45 d := fn () {}
46 mut a := Test{}
47 mut b := Test{}
48
49 assert a == b
50
51 a.g = z
52 b.g = d
53 assert a != b
54}
55
56fn test_alias_compare() {
57 z := 1
58 d := 2
59 mut a := Test{}
60 mut b := Test{}
61
62 assert a == b
63
64 a.h = z
65 b.h = d
66 assert a != b
67}
68
69fn test_iface_compare() {
70 z := Test2{
71 a: -1
72 }
73 d := Test2{
74 a: 0
75 }
76 mut a := Test{
77 a: 0
78 }
79 mut b := Test{
80 a: 0
81 }
82
83 assert a == b
84
85 a.i = z
86 b.i = d
87 assert a != b
88}
89