vxx / vlib / v / gen / wasm / tests / browser_int_builtins_test.v
34 lines · 31 sloc · 1.3 KB · 31b6787f871ae4bbdb9fd09e589d7cc565db0821
Raw
1import os
2
3// On the `-os browser` target, integer-to-string (`int.str()`), `println(int)`,
4// string interpolation/concat of integers, and the `min_int`/`max_int` builtin
5// constants used to fail — their implementations live in
6// `vlib/builtin/wasm/int_notd_no_imports.v` / `string_notd_no_imports.v`, which
7// were only compiled for `-os wasi`. They are now in the shared
8// `vlib/builtin/wasm/` dir, so browser builds pick them up too.
9fn test_wasm_browser_target_can_format_integers() {
10 vexe := os.quoted_path(@VEXE)
11 wrkdir := os.join_path(os.vtmp_dir(), 'wasm_browser_int_tests')
12 os.mkdir_all(wrkdir)!
13 defer {
14 os.rmdir_all(wrkdir) or {}
15 }
16
17 source_path := os.join_path(wrkdir, 'ints.v')
18 output_path := os.join_path(wrkdir, 'ints.wasm')
19 source := [
20 'pub fn main() {',
21 '\tprintln(42)', // println(int) needs int.str()
22 '\tn := 7',
23 "\tprintln('value=' + n.str())", // explicit int.str() + string concat
24 '\t_ = max_int', // min_int/max_int builtin consts
25 '\t_ = min_int',
26 '}',
27 ].join_lines()
28 os.write_file(source_path, source)!
29
30 res :=
31 os.execute('${vexe} -b wasm -os browser -o ${os.quoted_path(output_path)} ${os.quoted_path(source_path)}')
32 assert res.exit_code == 0, 'browser integer formatting failed to compile: ${res.output}'
33 assert os.exists(output_path), 'missing browser wasm output'
34}
35