v2 / vlib / v / gen / wasm / tests / builtin.vv
150 lines · 128 sloc · 2.14 KB · 40e86a7973f0443945103f8530d80112e50f0fdf
Raw
1fn test() {
2 print('hello!')
3 println('hello!')
4}
5
6fn str_concat() {
7 a := 'Hello '
8 b := 'V!'
9 d := a + b
10 println(d)
11}
12
13fn str_loop_concat() {
14 mut a := 'Y'
15 for _ in 0 .. 20 {
16 a += 'o'
17 }
18 a += '!'
19 println(a)
20}
21
22fn str_cmp() {
23 a := 'Test???'
24 b := 'TestingMcTestface'
25 c := 'TestingMcTestface'
26
27 println(a != b)
28 println(a == b)
29 println(a == c)
30 println(c != b)
31 println(b == a)
32
33 // Duh
34 println(b == b)
35 println(a == a)
36 println(c == c)
37
38 // Dynamically Generated
39 mut d := ''
40 e := 'aaaaaaaa'
41 for _ in 0 .. 8 {
42 d += 'a'
43 }
44 println(d == e)
45 println(d != e)
46
47 // Complex expressions
48 println(d == e && d == e)
49 println(d == e && d == a)
50
51 println(b < a)
52 println(b > a)
53 println(b <= a)
54 println(b >= a)
55
56 // If eval
57 if b == c {
58 println('B is C')
59 }
60 if a != c {
61 println('A is not C')
62 if a == c {
63 panic('A is C')
64 } else {
65 println('A is not C')
66 }
67 }
68}
69
70fn str_literal() {
71 a := 'Big test'
72 b := 'Such wow'
73 c := 'Helllo!'
74 d := '${a} and ${b}'
75 e := a + '${b}' + '${b}'
76 f := 42
77 array := ['${a}', '${b}', '${c}', '${f}']!
78
79 println('${a}')
80 println('${b}')
81 println('${c}')
82 println('${d}')
83 println('${e}')
84 println('meaning of life is ${f}')
85 println('${a}${c}')
86 println('${b}${a}')
87 println('${c}${a}${e}')
88 println('${a}${c}${c}${a}${b}${a}')
89 println('${b}${a}${b}')
90 println('${c}${a}${b}${a}${b}${a}')
91
92 // No for in array for now
93 println('---')
94 for i in 0 .. 4 {
95 println(array[i])
96 }
97
98 // Concat
99 mut concat := ''
100 for i in 0 .. 10 {
101 concat += '${i} - '
102 }
103 println('${concat}10!')
104
105 // Modifiers or dumps are not supported yet...
106}
107
108fn str_methods() {
109 print(128.str())
110 println(i64(-192322).str())
111 println(false.str())
112}
113
114fn str_implicit() {
115 println(false)
116 println(true)
117 a := 100
118 println(a + 10)
119}
120
121fn str_plus_assign_with_call_expr() {
122 mut str := 'a'
123 str += 1.str()
124 println(str)
125}
126
127fn assertions() {
128 assert true, 'hello'
129 assert true
130
131 // assert false, 'no can do'
132}
133
134fn main() {
135 test()
136 str_methods()
137 str_implicit()
138 str_concat()
139 str_cmp()
140 str_loop_concat()
141 str_literal()
142 str_plus_assign_with_call_expr()
143 assertions()
144
145 // panic('nooo!')
146
147 println('wasm builtins')
148 println(vwasm_memory_size())
149 println(vwasm_memory_grow(0))
150}
151