Files
NetMesh/domain/notes/taskList.test.ts
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

92 lines
3.3 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import {
countTaskListItems,
isPointerOnTaskCheckbox,
toggleTaskListItemAtIndex,
} from "./taskList";
test("toggleTaskListItemAtIndex flips the Nth GFM checkbox", () => {
const src = [
"# List",
"",
"- [ ] one",
"- [x] two",
"* [ ] three",
"1. [ ] four",
].join("\n");
assert.equal(countTaskListItems(src), 4);
assert.match(toggleTaskListItemAtIndex(src, 0), /^- \[x\] one$/m);
assert.match(toggleTaskListItemAtIndex(src, 1), /^- \[ \] two$/m);
assert.match(toggleTaskListItemAtIndex(src, 2), /^\* \[x\] three$/m);
assert.match(toggleTaskListItemAtIndex(src, 3), /^1\. \[x\] four$/m);
assert.equal(toggleTaskListItemAtIndex(src, 9), src);
assert.equal(toggleTaskListItemAtIndex(src, -1), src);
});
test("toggleTaskListItemAtIndex preserves indentation and surrounding text", () => {
const src = " - [ ] nested code `apt`\n- [x] done";
const next = toggleTaskListItemAtIndex(src, 0);
assert.equal(next, " - [x] nested code `apt`\n- [x] done");
});
test("toggleTaskListItemAtIndex ignores checkboxes inside fenced code", () => {
const src = [
"- [ ] real",
"```",
"- [ ] fake",
"```",
"- [ ] second",
].join("\n");
assert.equal(countTaskListItems(src), 2);
const next = toggleTaskListItemAtIndex(src, 1);
assert.match(next, /^- \[ \] real$/m);
assert.match(next, /^- \[ \] fake$/m);
assert.match(next, /^- \[x\] second$/m);
});
test("toggleTaskListItemAtIndex handles blockquote task lines", () => {
const src = "> - [ ] quoted\n- [ ] plain";
assert.equal(countTaskListItems(src), 2);
assert.match(toggleTaskListItemAtIndex(src, 0), /^> - \[x\] quoted$/m);
});
test("toggleTaskListItemAtIndex recognizes parenthesized ordered markers", () => {
const src = "1) [ ] first\n2. [ ] second";
assert.equal(countTaskListItems(src), 2);
assert.match(toggleTaskListItemAtIndex(src, 0), /^1\) \[x\] first$/m);
});
test("toggleTaskListItemAtIndex counts nested list tasks", () => {
const src = "- parent\n - [ ] child\n- [ ] later";
assert.equal(countTaskListItems(src), 2);
assert.match(toggleTaskListItemAtIndex(src, 0), / {4}- \[x\] child/);
assert.match(toggleTaskListItemAtIndex(src, 1), /^- \[x\] later$/m);
});
test("toggleTaskListItemAtIndex ignores tasks without space after bracket", () => {
const src = "- [ ]foo\n- [ ] real";
assert.equal(countTaskListItems(src), 1);
assert.match(toggleTaskListItemAtIndex(src, 0), /^- \[x\] real$/m);
assert.match(toggleTaskListItemAtIndex(src, 0), /^- \[ \]foo$/m);
});
test("toggleTaskListItemAtIndex ignores tasks inside HTML comments", () => {
const src = "<!--\n- [ ] hidden\n-->\n- [ ] visible";
assert.equal(countTaskListItems(src), 1);
const next = toggleTaskListItemAtIndex(src, 0);
assert.match(next, /<!--\n- \[ \] hidden\n-->/);
assert.match(next, /^- \[x\] visible$/m);
});
test("isPointerOnTaskCheckbox only accepts the left hit box", () => {
const rect = { left: 100, right: 400 };
assert.equal(isPointerOnTaskCheckbox(rect, 100), true);
assert.equal(isPointerOnTaskCheckbox(rect, 120), true);
assert.equal(isPointerOnTaskCheckbox(rect, 128), true);
assert.equal(isPointerOnTaskCheckbox(rect, 129), false);
assert.equal(isPointerOnTaskCheckbox(rect, 99), false);
});