tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

runtime-backends.test.mjs (2138B)


      1 import {readFile} from 'node:fs/promises';
      2 import test from 'node:test';
      3 import assert from 'node:assert/strict';
      4 import {backend,backends,runtimeStats} from '../dist/runtime-backends.js';
      5 import {createRuntimeSession} from '../dist/runtime-session.js';
      6 
      7 test('runtime selection is explicit, fixed and fails without fallback',async()=>{
      8  assert.deepEqual(Object.keys(backends),['zig-wasm','haskell-wasm']);
      9  assert.equal(backend('haskell-wasm'),'haskell-wasm');
     10  assert.deepEqual(Object.values(backends).map(x=>x.label),['Zig','Haskell']);
     11  for(const name of ['js','toString','constructor','unknown'])assert.throws(()=>backend(name),/Unknown/);
     12  for(const name of [null,'js','unknown'])await assert.rejects(createRuntimeSession(name,false),/Unsupported/);
     13 });
     14 test('runtime diagnostics do not invent graph counters for WASM',()=>{
     15  const value=runtimeStats({backend:'haskell-wasm',linearMemoryBytes:12*1048576});
     16  assert.equal(value,'12.0 MiB WASM linear memory');
     17  assert.doesNotMatch(value,/work|heap nodes|allocated/);
     18 });
     19 
     20 test('the real page explicitly defaults to Haskell and retains alternative runtimes',async()=>{
     21  const html=await readFile(new URL('../index.html',import.meta.url),'utf8');
     22  const selector=html.match(/<select id="runtime-backend">([\s\S]*?)<\/select>/)[1];
     23  assert.match(selector,/^<option value="haskell-wasm" selected>Haskell<\/option>/);
     24  assert.match(selector,/>Zig<\/option>/);
     25  assert.doesNotMatch(selector,/JavaScript|value="js"/);
     26  assert.doesNotMatch(selector.replace(/<[^>]*>/g,''),/WASM|reference/i);
     27  assert.equal((selector.match(/\bselected\b/g)||[]).length,1);
     28  for(const name of ['zig-wasm'])assert.match(selector,new RegExp('value="'+name+'"'));
     29 });
     30 
     31 test('production editor has no checkpoint restore or JS Worker branch',async()=>{
     32  const app=await readFile(new URL('../src/app.ts',import.meta.url),'utf8');
     33  assert.doesNotMatch(app,/CompiledDraft|compiledDraft|persistentDefinitions|type: 'restore'|compiler-worker\.js/);
     34  const protocol=await readFile(new URL('../src/compiler-protocol.ts',import.meta.url),'utf8');
     35  assert.doesNotMatch(protocol,/GraphCheckpoint|CompiledDraft|restore/);
     36 });