#!/usr/bin/env node // Test WASM build of SX kernel const path = require('path'); const build_dir = path.join(__dirname, '../_build/default/browser'); async function main() { // Load WASM module — require.main.filename must point to build dir // so the WASM loader finds .wasm assets via path.dirname(require.main.filename) require.main.filename = path.join(build_dir, 'test_wasm.js'); require(path.join(build_dir, 'sx_browser.bc.wasm.js')); // Wait for WASM init await new Promise(r => setTimeout(r, 2000)); const sx = globalThis.SxKernel; if (!sx) { console.error('FAIL: SxKernel not available'); process.exit(1); } console.log('Engine:', sx.engine()); // Basic tests const tests = [ ['(+ 1 2)', 3], ['(- 10 3)', 7], ['(* 6 7)', 42], ['(/ 10 2)', 5], ['(= 5 5)', true], ['(< 3 5)', true], ['(> 5 3)', true], ['(not false)', true], ['(inc 5)', 6], ['(dec 5)', 4], ['(len (list 1 2 3))', 3], ['(len "hello")', 5], ['(first (list 10 20))', 10], ['(nth "hello" 0)', 'h'], ['(nth "hello" 4)', 'o'], ['(str "a" "b")', 'ab'], ['(join ", " (list "a" "b" "c"))', 'a, b, c'], ['(let ((x 10) (y 20)) (+ x y))', 30], ['(if true "yes" "no")', 'yes'], ['(cond (= 1 2) "one" :else "other")', 'other'], ['(case 2 1 "one" 2 "two" :else "other")', 'two'], ['(render-to-html (list (quote div) "hello"))', '