mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-23 06:10:02 +08:00
test: verify committed string oracle
- Regenerate the string case oracle with the active Node executable.\n- Compare the checked-in fixture byte-for-byte before native runtime checks.\n- Keep the Linux parseInt ULP allowance scoped to native output.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { mkdir, readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { beforeAll, expect, test } from "vitest";
|
||||
@@ -33,8 +33,10 @@ beforeAll(async () => {
|
||||
]);
|
||||
});
|
||||
|
||||
// Runs against the committed case file (generated once from Node via
|
||||
// gen-string-cases.mjs — see that file to regenerate). Covers UTF-16
|
||||
// Runs against the committed case file generated from Node via
|
||||
// gen-string-cases.mjs. The test below also verifies the checked-in oracle
|
||||
// against the generator, so an accidental stale result cannot be masked by
|
||||
// the platform-specific native-runtime allowlist. Covers UTF-16
|
||||
// length/charCodeAt/indexOf/includes/startsWith/endsWith/slice/repeat/
|
||||
// trim/trimStart/trimEnd/split/padStart/padEnd/charAt plus parseInt over
|
||||
// ASCII, Latin-1, CJK, astral, and combining-mark strings, including the
|
||||
@@ -63,6 +65,17 @@ const LINUX_PARSEINT_ULP: ReadonlyMap<string, string> = new Map([
|
||||
],
|
||||
]);
|
||||
|
||||
test("committed string oracle matches Node", async () => {
|
||||
const caseFile = join(testDir, "string-cases.txt");
|
||||
const [{ stdout }, committed] = await Promise.all([
|
||||
execFileAsync(process.execPath, [join(testDir, "gen-string-cases.mjs")], {
|
||||
maxBuffer: 2 * 1024 * 1024,
|
||||
}),
|
||||
readFile(caseFile, "utf8"),
|
||||
]);
|
||||
expect(committed).toBe(stdout);
|
||||
});
|
||||
|
||||
test("string methods match Node on committed oracle cases", async () => {
|
||||
const r = await execFileAsync(bin, [join(testDir, "string-cases.txt")]).then(
|
||||
(v) => ({ stderr: v.stderr }),
|
||||
|
||||
Reference in New Issue
Block a user