tricu

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

ownership.test.js (887B)


      1 import { strictEqual, throws } from 'node:assert';
      2 import { it } from 'node:test';
      3 import { init, free, leaf, stem, retain, release, collect, toBool } from '../src/lib.js';
      4 
      5 it('owned bigint handles survive collection and reject released/cross-context use', () => {
      6   const ctx = init(), other = init();
      7   try {
      8     const t = leaf(ctx), alias = retain(ctx, t);
      9     strictEqual(typeof t, 'bigint');
     10     const truth = stem(ctx, t);
     11     release(ctx, t);
     12     collect(ctx);
     13     strictEqual(toBool(ctx, alias), false);
     14     strictEqual(toBool(ctx, truth), true);
     15     throws(() => release(ctx, t), /status 1/);
     16     throws(() => retain(other, alias), /status 1/);
     17     release(ctx, alias);
     18     release(ctx, truth);
     19     collect(ctx);
     20     const replacement = leaf(ctx);
     21     throws(() => toBool(ctx, t), /failed/);
     22     release(ctx, replacement);
     23   } finally {
     24     free(other);
     25     free(ctx);
     26   }
     27 });