v2 / vlib / v / tests / structs / struct_generic_sizeof_test.v
27 lines · 25 sloc · 644 bytes · dddbacb1960b838b75532443d7ed24328d85daa7
Raw
1const cache_line_size = 32
2
3struct PaddedSlot[T] {
4mut:
5 data T
6 pad [cache_line_size - sizeof(T)]u8
7}
8
9fn test_main() {
10 x := PaddedSlot[int]{}
11 $if new_int ? && x64 {
12 assert '${x}' == 'PaddedSlot[int]{
13 data: 0
14 pad: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
15}'
16 } $else {
17 assert '${x}' == 'PaddedSlot[int]{
18 data: 0
19 pad: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
20}'
21 }
22 x2 := PaddedSlot[u8]{}
23 assert '${x2}' == 'PaddedSlot[u8]{
24 data: 0
25 pad: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
26}'
27}
28