// Runs whole + chunked over the corpus (or a directory), catching throws, and reports the failing inputs. import fs from "node:fs"; import path from "node:path"; process.env.TYPESTRIP_ERASE_WASM ??= "build/erase.wasm"; const root = new URL("../..", import.meta.url).pathname.replace(/\/$/, ""); const { transformSync } = await import(root + "/src/index.js"); const { cases } = await import(root + "/test/corpus.mjs"); function* parts(src) { let seed = src.length; for (let i = 0; i < src.length; ) { seed = (seed * 1103515245 + 12345) & 0x7fffffff; const n = 1 + (seed % 4096); yield src.slice(i, i + n); i += n; } } function chunked(src) { let out = ""; for (const piece of transformSync(parts(src))) out += piece; return out; } let n = 0, bad = 0; const limit = Number(process.env.LIMIT ?? 10); for (const { name, src } of cases({ only: process.argv[2] })) { n++; let got; try { got = transformSync(src); } catch (e) { console.log(`THREW whole: ${name}`); bad++; if (bad >= limit) break; continue; } try { const c = chunked(src); if (c !== got) { let j = 0; while (got[j] === c[j]) j++; console.log(`DIFF chunked: ${name} at ${j}: ${JSON.stringify(c.slice(Math.max(0, j - 30), j + 30))} vs ${JSON.stringify(got.slice(Math.max(0, j - 30), j + 30))}`); bad++; } } catch (e) { console.log(`THREW chunked: ${name}`); bad++; } if (bad >= limit) break; } console.log(`${n} inputs, ${bad} bad`);