v2 / vlib / v / tests / comptime / comptime_if_is_pointer_test.v
37 lines · 35 sloc · 810 bytes · 711d7c49496a39333fdceaa30264c6e255a02708
Raw
1fn g[T](x T, is_pointer bool, is_voidptr bool) {
2 println('type: ${typeof[T]().name}, isreftype(T): ${isreftype(T)}')
3 $if T is $pointer {
4 println('T is \$pointer')
5 assert is_pointer
6 } $else {
7 println('T is NOT a \$pointer')
8 assert !is_pointer
9 }
10 $if T is $voidptr {
11 println('T is \$voidptr')
12 assert is_voidptr
13 } $else {
14 println('T is NOT a \$voidptr')
15 assert !is_voidptr
16 }
17 println('--------------------------')
18}
19
20struct Abc {}
21
22fn test_is_pointer_and_is_voidptr() {
23 unsafe {
24 g(voidptr(123), true, true)
25 g(&char(456), true, false)
26 //
27 g(int(1000), false, false)
28 g(&int(1001), true, false)
29 g(&&int(1002), true, false)
30 g(&&&int(1003), true, false)
31 //
32 g(Abc{}, false, false)
33 g(&Abc(10001), true, false)
34 g(&&Abc(10002), true, false)
35 g(&&&Abc(10003), true, false)
36 }
37}
38