mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 22:35:51 +00:00
test: 添加 Utils 纯函数单元测试 (测试计划 02)
覆盖 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>
This commit is contained in:
98
src/utils/__tests__/semver.test.ts
Normal file
98
src/utils/__tests__/semver.test.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { gt, gte, lt, lte, satisfies, order } from "../semver";
|
||||
|
||||
describe("gt", () => {
|
||||
test("returns true when a > b", () => {
|
||||
expect(gt("2.0.0", "1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false when a < b", () => {
|
||||
expect(gt("1.0.0", "2.0.0")).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when equal", () => {
|
||||
expect(gt("1.0.0", "1.0.0")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("gte", () => {
|
||||
test("returns true when a > b", () => {
|
||||
expect(gte("2.0.0", "1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns true when equal", () => {
|
||||
expect(gte("1.0.0", "1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false when a < b", () => {
|
||||
expect(gte("1.0.0", "2.0.0")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lt", () => {
|
||||
test("returns true when a < b", () => {
|
||||
expect(lt("1.0.0", "2.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false when a > b", () => {
|
||||
expect(lt("2.0.0", "1.0.0")).toBe(false);
|
||||
});
|
||||
|
||||
test("returns false when equal", () => {
|
||||
expect(lt("1.0.0", "1.0.0")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lte", () => {
|
||||
test("returns true when a < b", () => {
|
||||
expect(lte("1.0.0", "2.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns true when equal", () => {
|
||||
expect(lte("1.0.0", "1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("returns false when a > b", () => {
|
||||
expect(lte("2.0.0", "1.0.0")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("satisfies", () => {
|
||||
test("matches exact version", () => {
|
||||
expect(satisfies("1.2.3", "1.2.3")).toBe(true);
|
||||
});
|
||||
|
||||
test("matches range", () => {
|
||||
expect(satisfies("1.2.3", ">=1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("does not match out-of-range version", () => {
|
||||
expect(satisfies("0.9.0", ">=1.0.0")).toBe(false);
|
||||
});
|
||||
|
||||
test("matches caret range", () => {
|
||||
expect(satisfies("1.2.3", "^1.0.0")).toBe(true);
|
||||
});
|
||||
|
||||
test("does not match major bump in caret", () => {
|
||||
expect(satisfies("2.0.0", "^1.0.0")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("order", () => {
|
||||
test("returns 1 when a > b", () => {
|
||||
expect(order("2.0.0", "1.0.0")).toBe(1);
|
||||
});
|
||||
|
||||
test("returns -1 when a < b", () => {
|
||||
expect(order("1.0.0", "2.0.0")).toBe(-1);
|
||||
});
|
||||
|
||||
test("returns 0 when equal", () => {
|
||||
expect(order("1.0.0", "1.0.0")).toBe(0);
|
||||
});
|
||||
|
||||
test("compares patch versions", () => {
|
||||
expect(order("1.0.1", "1.0.0")).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user