1// SPDX-License-Identifier: MIT
2//
3// Writes testdata/ordinal_cases.txt: for pairs of strings chosen around the
4// differences between .NET's OrdinalIgnoreCase and JavaScript's case mapping,
5// what the runner's `--cmp` mode answers (equality, ordering, IndexOf,
6// StartsWith, EndsWith). ordinal_test.go replays it.
7//
8// dotnet build -c Release expr/gen/runner -p:RunnerSrc=<runner>/src/Sdk
9// node expr/gen/runner/ordinal_cases.mjs > expr/testdata/ordinal_cases.txt
10
11import { writeFileSync, mkdtempSync, rmSync } from "node:fs";
12import { tmpdir } from "node:os";
13import { join } from "node:path";
14import { runDriver, here, checkEnvironment } from "./env.mjs";
15
16const words = [
17 "", "a", "A", "ab", "AB", "abc", "ABC", "Hello", "hELLO", "hello world", "true", "TRUE", "null",
18 "ß", "SS", "ss", "ẞ", "ʼn", "ʼN", "ffi", "FFI", "ffi", "ı", "I", "i", "İ", "ſ", "s", "S",
19 "\u212a", "k", "K", "\u212b", "å", "Å", "σ", "ς", "Σ", "ΑΣ", "ας", "ασ", "DŽ", "Dž", "dž", "Lj", "lj",
20 "é", "É", "e\u0301", "ÿ", "Ÿ", "µ", "μ", "Μ", "ǰ", "J\u030c", "ΐ", "ῼ", "ᾳ", "ᾼ",
21 "\u00e9", "\u00c9", "Dža", "DŽa", "Ж", "ж", "ა", "Ა", "ꭰ", "Ꭰ", "ᏸ", "Ᏸ", "ⓐ", "Ⓐ", "a", "A",
22 "\ue000", "\uffff", "\ud83d\ude00", "\ud801\udc00", "\ud801\udc28", "\u{10428}", "\ud800\udc00", "ab\ud83d\ude00", "AB\ud83d\ude00",
23 "x\u2028y", "x y", "x\u00a0y", "0", "00", "1e3", "-", "_", "a-b", "a_b", "[]", "'",
24];
25const hex = s => s.length ? [...s].flatMap(c => { const n = c.codePointAt(0); return n > 0xffff ? [0xd800 + ((n - 0x10000) >> 10), 0xdc00 + ((n - 0x10000) & 0x3ff)] : [n]; }).map(u => u.toString(16).toUpperCase()).join(".") : "-";
26const lines = [];
27for (const a of words) for (const b of words) lines.push(`${hex(a)} ${hex(b)}`);
28const tmp = mkdtempSync(join(tmpdir(), "ordinal-"));
29writeFileSync(join(tmp, "in.txt"), lines.join("\n") + "\n");
30const out = runDriver(["--cmp", join(tmp, "in.txt")]).split("\n").filter(Boolean);
31rmSync(tmp, { recursive: true });
32if (out.length !== lines.length) throw new Error("answer count");
33// Keep every pair that is interesting (some predicate true) and a sample of the rest, to bound the file.
34const res = [];
35lines.forEach((l, i) => {
36 const interesting = out[i] !== "0 0 0 0 0" && out[i] !== "0 -1 0 0 0" && out[i] !== "0 1 0 0 0";
37 if (interesting || i % 7 === 0) res.push(`${l} ${out[i]}`);
38});
39process.stdout.write(res.join("\n") + "\n");