mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +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:
55
src/utils/__tests__/contentArray.test.ts
Normal file
55
src/utils/__tests__/contentArray.test.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { insertBlockAfterToolResults } from "../contentArray";
|
||||
|
||||
describe("insertBlockAfterToolResults", () => {
|
||||
test("inserts after last tool_result", () => {
|
||||
const content: any[] = [
|
||||
{ type: "tool_result", content: "r1" },
|
||||
{ type: "text", text: "hello" },
|
||||
];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "inserted" });
|
||||
expect(content[1]).toEqual({ type: "text", text: "inserted" });
|
||||
expect(content).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("inserts after last of multiple tool_results", () => {
|
||||
const content: any[] = [
|
||||
{ type: "tool_result", content: "r1" },
|
||||
{ type: "tool_result", content: "r2" },
|
||||
{ type: "text", text: "end" },
|
||||
];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "new" });
|
||||
expect(content[2]).toEqual({ type: "text", text: "new" });
|
||||
});
|
||||
|
||||
test("appends continuation when inserted block would be last", () => {
|
||||
const content: any[] = [{ type: "tool_result", content: "r1" }];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "new" });
|
||||
expect(content).toHaveLength(3); // original + inserted + continuation
|
||||
expect(content[2]).toEqual({ type: "text", text: "." });
|
||||
});
|
||||
|
||||
test("inserts before last block when no tool_results", () => {
|
||||
const content: any[] = [
|
||||
{ type: "text", text: "a" },
|
||||
{ type: "text", text: "b" },
|
||||
];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "new" });
|
||||
expect(content[1]).toEqual({ type: "text", text: "new" });
|
||||
expect(content).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("handles empty array", () => {
|
||||
const content: any[] = [];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "new" });
|
||||
expect(content).toHaveLength(1);
|
||||
expect(content[0]).toEqual({ type: "text", text: "new" });
|
||||
});
|
||||
|
||||
test("handles single element array with no tool_result", () => {
|
||||
const content: any[] = [{ type: "text", text: "only" }];
|
||||
insertBlockAfterToolResults(content, { type: "text", text: "new" });
|
||||
expect(content[0]).toEqual({ type: "text", text: "new" });
|
||||
expect(content[1]).toEqual({ type: "text", text: "only" });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user