v2 / vlib / v / tests / consts / const_representation_test.v
39 lines · 27 sloc · 742 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1const zzz_byte_a = u8(`A`)
2
3const zzz_u16_a = u16(999) + 5
4
5const zzza = u64(123)
6
7const zzzb = 5 + zzzc
8
9const zzzc = 6 + zzza
10
11const zzzx = zzza - 124
12
13const zzz_zz = i64(-1)
14
15struct Abc {
16 x int
17}
18
19const zzz_struct = Abc{123}
20
21const zzzs = 'xyz' + 'abc'
22
23fn test_number_consts() {
24 assert zzz_byte_a.hex_full() == '41'
25 assert zzz_u16_a.hex_full() == '03ec'
26 assert zzza.hex_full() == '000000000000007b'
27 assert zzzb.hex_full() == '0000000000000086'
28 assert zzzc.hex_full() == '0000000000000081'
29 // assert zzzx.hex_full() == '00000000ffffffff' // TODO: see why
30 assert zzz_zz.hex_full() == 'ffffffffffffffff'
31}
32
33fn test_struct_consts() {
34 assert zzz_struct.str().contains('x: 123')
35}
36
37fn test_string_consts() {
38 assert zzzs == 'xyzabc'
39}
40