mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15: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:
42
src/utils/__tests__/xml.test.ts
Normal file
42
src/utils/__tests__/xml.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { escapeXml, escapeXmlAttr } from "../xml";
|
||||
|
||||
describe("escapeXml", () => {
|
||||
test("escapes ampersand", () => {
|
||||
expect(escapeXml("a & b")).toBe("a & b");
|
||||
});
|
||||
|
||||
test("escapes less-than", () => {
|
||||
expect(escapeXml("<div>")).toBe("<div>");
|
||||
});
|
||||
|
||||
test("escapes greater-than", () => {
|
||||
expect(escapeXml("a > b")).toBe("a > b");
|
||||
});
|
||||
|
||||
test("escapes multiple special chars", () => {
|
||||
expect(escapeXml("<a & b>")).toBe("<a & b>");
|
||||
});
|
||||
|
||||
test("returns empty string unchanged", () => {
|
||||
expect(escapeXml("")).toBe("");
|
||||
});
|
||||
|
||||
test("returns normal text unchanged", () => {
|
||||
expect(escapeXml("hello world")).toBe("hello world");
|
||||
});
|
||||
});
|
||||
|
||||
describe("escapeXmlAttr", () => {
|
||||
test("escapes double quotes", () => {
|
||||
expect(escapeXmlAttr('say "hello"')).toBe("say "hello"");
|
||||
});
|
||||
|
||||
test("escapes single quotes", () => {
|
||||
expect(escapeXmlAttr("it's")).toBe("it's");
|
||||
});
|
||||
|
||||
test("escapes all special chars", () => {
|
||||
expect(escapeXmlAttr('<a & "b">')).toBe("<a & "b">");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user