mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
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:
41
src/utils/__tests__/objectGroupBy.test.ts
Normal file
41
src/utils/__tests__/objectGroupBy.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user