Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions vlib/v/gen/wasm/tests/browser_int_builtins_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os

// On the `-os browser` target, integer-to-string (`int.str()`), `println(int)`,
// string interpolation/concat of integers, and the `min_int`/`max_int` builtin
// constants used to fail — their implementations live in
// `vlib/builtin/wasm/int_notd_no_imports.v` / `string_notd_no_imports.v`, which
// were only compiled for `-os wasi`. They are now in the shared
// `vlib/builtin/wasm/` dir, so browser builds pick them up too.
fn test_wasm_browser_target_can_format_integers() {
vexe := os.quoted_path(@VEXE)
wrkdir := os.join_path(os.vtmp_dir(), 'wasm_browser_int_tests')
os.mkdir_all(wrkdir)!
defer {
os.rmdir_all(wrkdir) or {}
}

source_path := os.join_path(wrkdir, 'ints.v')
output_path := os.join_path(wrkdir, 'ints.wasm')
source := [
'pub fn main() {',
'\tprintln(42)', // println(int) needs int.str()
'\tn := 7',
"\tprintln('value=' + n.str())", // explicit int.str() + string concat
'\t_ = max_int', // min_int/max_int builtin consts
'\t_ = min_int',
'}',
].join_lines()
os.write_file(source_path, source)!

res :=
os.execute('${vexe} -b wasm -os browser -o ${os.quoted_path(output_path)} ${os.quoted_path(source_path)}')
assert res.exit_code == 0, 'browser integer formatting failed to compile: ${res.output}'
assert os.exists(output_path), 'missing browser wasm output'
}
Loading