mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
- 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>
87 lines
2.3 KiB
TypeScript
87 lines
2.3 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { CircularBuffer } from "../CircularBuffer";
|
|
|
|
describe("CircularBuffer", () => {
|
|
test("starts empty", () => {
|
|
const buf = new CircularBuffer<number>(5);
|
|
expect(buf.length()).toBe(0);
|
|
expect(buf.toArray()).toEqual([]);
|
|
});
|
|
|
|
test("adds items up to capacity", () => {
|
|
const buf = new CircularBuffer<number>(3);
|
|
buf.add(1);
|
|
buf.add(2);
|
|
buf.add(3);
|
|
expect(buf.length()).toBe(3);
|
|
expect(buf.toArray()).toEqual([1, 2, 3]);
|
|
});
|
|
|
|
test("evicts oldest when full", () => {
|
|
const buf = new CircularBuffer<number>(3);
|
|
buf.add(1);
|
|
buf.add(2);
|
|
buf.add(3);
|
|
buf.add(4);
|
|
expect(buf.length()).toBe(3);
|
|
expect(buf.toArray()).toEqual([2, 3, 4]);
|
|
});
|
|
|
|
test("evicts multiple oldest items", () => {
|
|
const buf = new CircularBuffer<number>(2);
|
|
buf.add(1);
|
|
buf.add(2);
|
|
buf.add(3);
|
|
buf.add(4);
|
|
buf.add(5);
|
|
expect(buf.toArray()).toEqual([4, 5]);
|
|
});
|
|
|
|
test("addAll adds multiple items", () => {
|
|
const buf = new CircularBuffer<number>(5);
|
|
buf.addAll([1, 2, 3]);
|
|
expect(buf.toArray()).toEqual([1, 2, 3]);
|
|
});
|
|
|
|
test("addAll with overflow", () => {
|
|
const buf = new CircularBuffer<number>(3);
|
|
buf.addAll([1, 2, 3, 4, 5]);
|
|
expect(buf.toArray()).toEqual([3, 4, 5]);
|
|
});
|
|
|
|
test("getRecent returns last N items", () => {
|
|
const buf = new CircularBuffer<number>(5);
|
|
buf.addAll([1, 2, 3, 4, 5]);
|
|
expect(buf.getRecent(3)).toEqual([3, 4, 5]);
|
|
});
|
|
|
|
test("getRecent returns fewer when not enough items", () => {
|
|
const buf = new CircularBuffer<number>(5);
|
|
buf.add(1);
|
|
buf.add(2);
|
|
expect(buf.getRecent(5)).toEqual([1, 2]);
|
|
});
|
|
|
|
test("getRecent works after wraparound", () => {
|
|
const buf = new CircularBuffer<number>(3);
|
|
buf.addAll([1, 2, 3, 4, 5]);
|
|
expect(buf.getRecent(2)).toEqual([4, 5]);
|
|
});
|
|
|
|
test("clear resets buffer", () => {
|
|
const buf = new CircularBuffer<number>(5);
|
|
buf.addAll([1, 2, 3]);
|
|
buf.clear();
|
|
expect(buf.length()).toBe(0);
|
|
expect(buf.toArray()).toEqual([]);
|
|
});
|
|
|
|
test("works with string type", () => {
|
|
const buf = new CircularBuffer<string>(2);
|
|
buf.add("a");
|
|
buf.add("b");
|
|
buf.add("c");
|
|
expect(buf.toArray()).toEqual(["b", "c"]);
|
|
});
|
|
});
|