Skip to content

Commit

Permalink
Merge pull request #76 from tobiasvl/patch-1
Browse files Browse the repository at this point in the history
Support alternative checkboxes
  • Loading branch information
lumoe committed Jan 22, 2024
2 parents 26c67d6 + 45449c5 commit 5b6c0b1
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/get-todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TodoParser {

// Returns true if string s is a todo-item
#isTodo(s) {
const r = new RegExp(`\\s*[${this.bulletSymbols.join("")}] \\[ \\].*`, "g"); // /\s*[-*+] \[ \].*/g;
const r = new RegExp(`\\s*[${this.bulletSymbols.join("")}] \\[[^xX-]\\].*`, "g"); // /\s*[-*+] \[[^xX-]\].*/g;
return r.test(s);
}

Expand Down
65 changes: 65 additions & 0 deletions src/get-todos.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,42 @@ test("single todo element should return itself", () => {
expect(result).toStrictEqual(todos);
});

test("single incomplete element should return itself", () => {
// GIVEN
const lines = ["- [/] tada"];

// WHEN
const result = getTodos({ lines });

// THEN
const todos = ["- [/] tada"];
expect(result).toStrictEqual(todos);
});

test("single done todo element should not return itself", () => {
// GIVEN
const lines = ["- [x] tada"];

// WHEN
const result = getTodos({ lines });

// THEN
const todos = [""];
expect(result).toStrictEqual(todos);
});

test("single canceled todo element should not return itself", () => {
// GIVEN
const lines = ["- [-] tada"];

// WHEN
const result = getTodos({ lines });

// THEN
const todos = [""];
expect(result).toStrictEqual(todos);
});

test("get todos with children", function () {
// GIVEN
const lines = [
Expand Down Expand Up @@ -142,6 +178,35 @@ test("get todos without children", () => {
expect(todos).toStrictEqual(result);
});

test("get todos with correct alternate checkbox children", function () {
// GIVEN
const lines = [
"- [ ] TODO",
" - [ ] Next",
" - [x] Completed task",
" - some stuff",
"- [ ] Another one",
" - [ ] Another child",
" - [/] More children",
" - another child",
"- this isn't copied",
];

// WHEN
const todos = getTodos({ lines: lines, withChildren: true });

// THEN
const result = [
"- [ ] TODO",
" - [ ] Next",
" - some stuff",
"- [ ] Another one",
" - [ ] Another child",
" - [/] More children",
" - another child",
];
expect(todos).toStrictEqual(result);
});
test("get todos with children doesn't fail if child at end of list", () => {
// GIVEN
const lines = [
Expand Down

0 comments on commit 5b6c0b1

Please sign in to comment.