v2 / vlib / v / tests / c_structs / cstruct_str_test.c.v
50 lines · 38 sloc · 727 bytes · dbc6b50cda7524c70160db55fb3201ce0f776d83
Raw
1#include "@VMODROOT/cstruct.h"
2
3@[typedef]
4struct C.Test2 {}
5
6@[typedef]
7struct C.Test1 {
8 a C.Test2
9}
10
11fn (s C.Test2) str() string {
12 return 'test2'
13}
14
15fn (s C.Test1) get() C.Test1 {
16 return s
17}
18
19fn (s C.Test1) s() string {
20 return '.${s.get()}.'
21}
22
23type TestAlias = C.Test2
24
25fn (s TestAlias) str() string {
26 return 'test_alias'
27}
28
29fn (s TestAlias) get() TestAlias {
30 return s
31}
32
33fn test_main() {
34 x := unsafe { &C.Test1(malloc(1024)) }
35 println(x)
36 assert dump('${x}') == '&C.Test1{
37 a: test2
38}'
39 println('.${x.get()}.${x.s()}')
40
41 y := unsafe { &TestAlias(malloc(1024)) }
42 println(y)
43 assert dump('${y}') == '&test_alias'
44 println('.${y.get()}.')
45
46 w := TestAlias(*y)
47 assert dump(w.str()) == 'test_alias'
48
49 assert true
50}
51