test: consolidate service and process fixtures

This commit is contained in:
morluto
2026-10-08 04:03:24 +08:00
parent d88d6c1897
commit f8a53a8c06
25 changed files with 471 additions and 1176 deletions
@@ -1,47 +1,14 @@
import { describe, expect, it } from "vitest";
import { expect, it } from "vitest";
import { compareDirectoryChildNames } from "./ArtifactGraphConstruction.js";
const tiedNames = ["a.txt", "a\u200b.txt", "a\u200c.txt", "a\u200d.txt"];
describe("directory child-name ordering", () => {
it("orders the tied subset lexically with reflexivity and antisymmetry", () => {
for (const left of tiedNames) {
expect(compareDirectoryChildNames(left, left)).toBe(0);
for (const right of tiedNames) {
expect(left.localeCompare(right)).toBe(0);
const compared = compareDirectoryChildNames(left, right);
const lexical = left < right ? -1 : left > right ? 1 : 0;
expect(compared).toBe(lexical);
expect(compared + compareDirectoryChildNames(right, left)).toBe(0);
}
}
});
it("is transitive across the tied subset", () => {
for (const first of tiedNames)
for (const second of tiedNames)
for (const third of tiedNames)
if (
compareDirectoryChildNames(first, second) <= 0 &&
compareDirectoryChildNames(second, third) <= 0
)
expect(
compareDirectoryChildNames(first, third),
).toBeLessThanOrEqual(0);
});
it.each([
["a.txt", "b.txt"],
["z.txt", "ä.txt"],
["Z", "a"],
["a/data.txt", "b/data.txt"],
])("preserves the current non-tied collation for %s / %s", (left, right) => {
const collated = left.localeCompare(right);
expect(collated).not.toBe(0);
expect(compareDirectoryChildNames(left, right)).toBe(collated);
expect(compareDirectoryChildNames(right, left)).toBe(
right.localeCompare(left),
);
});
it("breaks locale-collation ties deterministically by code unit", () => {
const names = ["a\u200d.txt", "a.txt", "a\u200b.txt", "a\u200c.txt"];
expect("a\u200d.txt".localeCompare("a.txt")).toBe(0);
expect(names.sort(compareDirectoryChildNames)).toEqual([
"a.txt",
"a\u200b.txt",
"a\u200c.txt",
"a\u200d.txt",
]);
});