mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
* refactor(domain): bound a first batch of constant-maximum slices with boundedList * fix(domain): describe a bounded list with nothing retained without a leading separator * refactor(domain): bound eleven counted list samples through boundedList (#11421) Desktop state differences, guidance subsection pointers, native output contract issues, APK v1 duplicate-name samples, environment write refusals, desktop build action logs and credential-named saved-value pointers already reported a count or a cut beside a sliced list; the slice and the count now come from one boundedList. constant-maximum-slice: 54 -> 43.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
import { expect, it } from "vitest";
|
|
|
|
import {
|
|
BoundedListCollector,
|
|
boundedList,
|
|
describeBoundedList,
|
|
} from "./boundedList.js";
|
|
|
|
it("retains up to the maximum and counts every item past it", () => {
|
|
expect(boundedList([1, 2], 3)).toEqual({ items: [1, 2], omitted: 0 });
|
|
expect(boundedList([1, 2, 3, 4, 5], 3)).toEqual({
|
|
items: [1, 2, 3],
|
|
omitted: 2,
|
|
});
|
|
// Re-bounding a list keeps the count an earlier bound recorded.
|
|
expect(boundedList([0, 1, 2, 3], 3, 2)).toEqual({
|
|
items: [0, 1, 2],
|
|
omitted: 3,
|
|
});
|
|
});
|
|
|
|
it("collects up to the maximum and counts later pushes", () => {
|
|
const collector = new BoundedListCollector<string>(2);
|
|
for (const item of ["a", "b", "c", "d"]) collector.push(item);
|
|
expect(collector.retains("a")).toBe(true);
|
|
expect(collector.retains("c")).toBe(false);
|
|
expect(collector.toList()).toEqual({ items: ["a", "b"], omitted: 2 });
|
|
});
|
|
|
|
it("names the retained items and counts the rest", () => {
|
|
expect(describeBoundedList(boundedList(["a", "b"], 3), "; ")).toBe("a; b");
|
|
expect(describeBoundedList(boundedList(["a", "b", "c", "d"], 2), ", ")).toBe(
|
|
"a, b, and 2 more",
|
|
);
|
|
// Nothing retained: no leading separator.
|
|
expect(describeBoundedList(boundedList(["a", "b"], 0), ", ")).toBe(
|
|
"and 2 more",
|
|
);
|
|
});
|