import { test } from 'node:test'; import assert from 'node:assert/strict'; import { reconstructAddress, pageText, selfTest } from './reconstruct.mjs'; test('frozen full-volume location, canonical address and first/middle/last page hashes',async()=>{assert.equal((await selfTest()).selfTest,'passed');}); test('rejects malformed, noncanonical, unsupported and oversized addresses',()=>{ for(const address of ['', 'epb1/0/w0/s0/v0/p1','epb2/00/w0/s0/v0/p1','epb2/t/w0/s0/v0/p1','epb2/0/w4/s0/v0/p1','epb2/0/w0/s5/v0/p1','epb2/0/w0/s0/v32/p1','epb2/0/w0/s0/v00/p1','epb2/0/w0/s0/v0/p0','epb2/0/w0/s0/v0/p411','epb2/0/w0/s0/v0/p01','epb2/0/w0/s0/v0/p1\n','x'.repeat(1400001)])assert.throws(()=>reconstructAddress(address)); }); test('rejects arithmetic overflow and inverse volumes outside the one-space Library',()=>{ assert.throws(()=>reconstructAddress(`epb2/${'s'.repeat(1312000)}/w3/s4/v31/p1`),/outside/); assert.throws(()=>reconstructAddress('epb2/0/w0/s0/v0/p1'),/valid reading Library/); }); test('page output preserves exact forty by eighty layout and rejects invalid page selectors',()=>{ const content=new Uint8Array(1312000),text=pageText(content,410);assert.equal(text.split('\n').length,40);assert.ok(text.split('\n').every(line=>line.length===80));assert.equal(text.length,3239); for(const page of [0,411,-1,1.2,NaN,'1'])assert.throws(()=>pageText(content,page)); });