test: Phase 1 — 添加 8 个纯函数测试文件 (+134 tests)

- errors.test.ts: 28 tests (isAbortError, toError, errorMessage, getErrnoCode, isFsInaccessible, classifyAxiosError 等)
- shellRuleMatching.test.ts: 22 tests (permissionRuleExtractPrefix, hasWildcards, matchWildcardPattern, parsePermissionRule 等)
- argumentSubstitution.test.ts: 18 tests (parseArguments, parseArgumentNames, generateProgressiveArgumentHint, substituteArguments)
- CircularBuffer.test.ts: 12 tests (add, addAll, getRecent, toArray, clear, length)
- sanitization.test.ts: 14 tests (partiallySanitizeUnicode, recursivelySanitizeUnicode)
- slashCommandParsing.test.ts: 8 tests (parseSlashCommand)
- contentArray.test.ts: 6 tests (insertBlockAfterToolResults)
- objectGroupBy.test.ts: 5 tests (objectGroupBy)

总计:781 tests / 40 files

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
claude-code-best
2026-04-02 08:50:29 +08:00
parent 91c5bea27a
commit acfaac5f14
8 changed files with 876 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
import { describe, expect, test } from "bun:test";
import { objectGroupBy } from "../objectGroupBy";
describe("objectGroupBy", () => {
test("groups items by key", () => {
const result = objectGroupBy([1, 2, 3, 4], (n) =>
n % 2 === 0 ? "even" : "odd"
);
expect(result.even).toEqual([2, 4]);
expect(result.odd).toEqual([1, 3]);
});
test("returns empty object for empty input", () => {
const result = objectGroupBy([], () => "key");
expect(Object.keys(result)).toHaveLength(0);
});
test("handles single group", () => {
const result = objectGroupBy(["a", "b", "c"], () => "all");
expect(result.all).toEqual(["a", "b", "c"]);
});
test("passes index to keySelector", () => {
const result = objectGroupBy(["a", "b", "c", "d"], (_, i) =>
i < 2 ? "first" : "second"
);
expect(result.first).toEqual(["a", "b"]);
expect(result.second).toEqual(["c", "d"]);
});
test("works with objects", () => {
const items = [
{ name: "Alice", role: "admin" },
{ name: "Bob", role: "user" },
{ name: "Charlie", role: "admin" },
];
const result = objectGroupBy(items, (item) => item.role);
expect(result.admin).toHaveLength(2);
expect(result.user).toHaveLength(1);
});
});