v2 / vlib / v / tests / structs / struct_pointer_nil_comparison_test.v
23 lines · 21 sloc · 368 bytes · 3ced22e21bbe424ecf49ff21af643e789d665106
Raw
1struct PtrNilFoo {
2 x int
3}
4
5fn test_struct_pointer_comparison_with_nil_is_nil_safe() {
6 p := &PtrNilFoo{
7 x: 42
8 }
9 same_value := &PtrNilFoo{
10 x: 42
11 }
12 other := &PtrNilFoo{
13 x: 7
14 }
15 nil_p := unsafe { &PtrNilFoo(nil) }
16 nil_q := unsafe { &PtrNilFoo(nil) }
17
18 assert p == same_value
19 assert p != other
20 assert p != nil_p
21 assert nil_p != p
22 assert nil_p == nil_q
23}
24