feat: 新增 validateTaskFormat 校验函数
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { parseTasks } from "../../src/core/task-parser.ts";
|
||||
import { parseTasks, validateTaskFormat, TaskFormatError } from "../../src/core/task-parser.ts";
|
||||
|
||||
describe("parseTasks", () => {
|
||||
it("解析标准 checkbox 格式", () => {
|
||||
@@ -52,3 +52,29 @@ describe("parseTasks", () => {
|
||||
expect(tasks.length).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("validateTaskFormat", () => {
|
||||
it("合法 task 内容通过校验", () => {
|
||||
expect(() => validateTaskFormat("- [x] 已完成\n- [ ] 未完成")).not.toThrow();
|
||||
});
|
||||
|
||||
it("无 checkbox 项时抛错", () => {
|
||||
expect(() => validateTaskFormat("# 标题\n一些描述")).toThrow(TaskFormatError);
|
||||
});
|
||||
|
||||
it("空内容抛错", () => {
|
||||
expect(() => validateTaskFormat("")).toThrow(TaskFormatError);
|
||||
});
|
||||
|
||||
it("checkbox 文本为空时抛错", () => {
|
||||
expect(() => validateTaskFormat("- [ ] \n- [x] 有内容")).toThrow(TaskFormatError);
|
||||
});
|
||||
|
||||
it("checkbox 文本仅空格时抛错", () => {
|
||||
expect(() => validateTaskFormat("- [ ] ")).toThrow(TaskFormatError);
|
||||
});
|
||||
|
||||
it("有 checkbox 且文本非空时通过", () => {
|
||||
expect(() => validateTaskFormat("- [ ] 实现功能A")).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user