import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; import { shared, int32, int64, bool } from 'moroutine'; describe('shared() tuple', () => { it('creates a tuple from array schema', () => { const t = shared([int32, int64]); assert.deepEqual(t.load(), [0, 0n]); }); it('store writes all elements', () => { const t = shared([int32, int64, bool]); t.store([42, 99n, true]); assert.deepEqual(t.load(), [42, 99n, true]); }); it('elements provides direct access to each Loadable', () => { const t = shared([int32, int32]); t.elements[0].store(10); t.elements[1].store(20); assert.deepEqual(t.load(), [10, 20]); }); it('length returns fixed element count', () => { const t = shared([int32, int32, bool]); assert.equal(t.length, 3); }); it('tuple elements share one buffer', () => { const t = shared([int32, int32]); const SHARED = Symbol.for('moroutine.shared'); const s0 = (t.elements[0] as any)[SHARED](); const s1 = (t.elements[1] as any)[SHARED](); assert.equal(s0.buffer, s1.buffer); }); it('tuple with struct elements', () => { const t = shared([ { x: int32, y: int32 }, { x: int32, y: int32 }, ]); t.store([ { x: 1, y: 2 }, { x: 3, y: 4 }, ]); assert.deepEqual(t.load(), [ { x: 1, y: 2 }, { x: 3, y: 4 }, ]); }); it('struct containing tuple field', () => { const s = shared({ points: [int32, int32, int32], count: int32, }); s.store({ points: [1, 2, 3], count: 3 }); assert.deepEqual(s.load(), { points: [1, 2, 3], count: 3 }); }); });