tricu

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

expression.test.mjs (1073B)


      1 import test from 'node:test';
      2 import assert from 'node:assert/strict';
      3 import {expressionUnit,expressionDiagnostic} from '../dist/expression.js';
      4 test('expression wrapper preserves layout and avoids supplied/user names',()=>{
      5  const u=expressionUnit('let\n  browserExpression1 = 42\n  in browserExpression1',['browserExpression0']);
      6  assert.equal(u.name,'browserExpression2');
      7  assert.equal(u.source,'browserExpression2 = (\n  let\n    browserExpression1 = 42\n    in browserExpression1\n)');
      8 });
      9 test('expression transport rejects empty, malformed Unicode and oversized wrapped source',()=>{
     10  for(const input of ['',null,'\ud800','x'.repeat(16384)])assert.throws(()=>expressionUnit(input,[]));
     11 });
     12 test('expression diagnostics map the compiler wrapper back to user coordinates',()=>{
     13  const e=expressionDiagnostic(Error('Compiler diagnostic 20 at 2:3: unresolved name "nope"'));
     14  assert.equal(e.message,'Compiler diagnostic 20 at expression 1:1: unresolved name "nope"');
     15  const trap=new WebAssembly.RuntimeError('trap');assert.equal(expressionDiagnostic(trap),trap);
     16 });