mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 12:55:51 +00:00
覆盖 xml, hash, stringUtils, semver, uuid, format, frontmatterParser, file, glob, diff 共 10 个模块的纯函数测试。 json.ts 因模块加载链路过重暂跳过。 共 190 个测试用例(含已有 array/set)全部通过。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { djb2Hash, hashContent, hashPair } from "../hash";
|
|
|
|
describe("djb2Hash", () => {
|
|
test("returns a number", () => {
|
|
expect(typeof djb2Hash("hello")).toBe("number");
|
|
});
|
|
|
|
test("returns 0 for empty string", () => {
|
|
expect(djb2Hash("")).toBe(0);
|
|
});
|
|
|
|
test("is deterministic", () => {
|
|
expect(djb2Hash("test")).toBe(djb2Hash("test"));
|
|
});
|
|
|
|
test("different strings produce different hashes", () => {
|
|
expect(djb2Hash("abc")).not.toBe(djb2Hash("def"));
|
|
});
|
|
|
|
test("returns 32-bit integer", () => {
|
|
const hash = djb2Hash("some long string to hash");
|
|
expect(hash).toBe(hash | 0); // bitwise OR with 0 preserves 32-bit int
|
|
});
|
|
});
|
|
|
|
describe("hashContent", () => {
|
|
test("returns a string", () => {
|
|
expect(typeof hashContent("hello")).toBe("string");
|
|
});
|
|
|
|
test("is deterministic", () => {
|
|
expect(hashContent("test")).toBe(hashContent("test"));
|
|
});
|
|
|
|
test("different strings produce different hashes", () => {
|
|
expect(hashContent("abc")).not.toBe(hashContent("def"));
|
|
});
|
|
});
|
|
|
|
describe("hashPair", () => {
|
|
test("returns a string", () => {
|
|
expect(typeof hashPair("a", "b")).toBe("string");
|
|
});
|
|
|
|
test("is deterministic", () => {
|
|
expect(hashPair("a", "b")).toBe(hashPair("a", "b"));
|
|
});
|
|
|
|
test("order matters", () => {
|
|
expect(hashPair("a", "b")).not.toBe(hashPair("b", "a"));
|
|
});
|
|
|
|
test("disambiguates different splits", () => {
|
|
expect(hashPair("ts", "code")).not.toBe(hashPair("tsc", "ode"));
|
|
});
|
|
});
|