Skip to content

Commit 5b6c0b1

Browse files
authored
Merge pull request #76 from tobiasvl/patch-1
Support alternative checkboxes
2 parents 26c67d6 + 45449c5 commit 5b6c0b1

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/get-todos.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class TodoParser {
1515

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

src/get-todos.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,42 @@ test("single todo element should return itself", () => {
1313
expect(result).toStrictEqual(todos);
1414
});
1515

16+
test("single incomplete element should return itself", () => {
17+
// GIVEN
18+
const lines = ["- [/] tada"];
19+
20+
// WHEN
21+
const result = getTodos({ lines });
22+
23+
// THEN
24+
const todos = ["- [/] tada"];
25+
expect(result).toStrictEqual(todos);
26+
});
27+
28+
test("single done todo element should not return itself", () => {
29+
// GIVEN
30+
const lines = ["- [x] tada"];
31+
32+
// WHEN
33+
const result = getTodos({ lines });
34+
35+
// THEN
36+
const todos = [""];
37+
expect(result).toStrictEqual(todos);
38+
});
39+
40+
test("single canceled todo element should not return itself", () => {
41+
// GIVEN
42+
const lines = ["- [-] tada"];
43+
44+
// WHEN
45+
const result = getTodos({ lines });
46+
47+
// THEN
48+
const todos = [""];
49+
expect(result).toStrictEqual(todos);
50+
});
51+
1652
test("get todos with children", function () {
1753
// GIVEN
1854
const lines = [
@@ -142,6 +178,35 @@ test("get todos without children", () => {
142178
expect(todos).toStrictEqual(result);
143179
});
144180

181+
test("get todos with correct alternate checkbox children", function () {
182+
// GIVEN
183+
const lines = [
184+
"- [ ] TODO",
185+
" - [ ] Next",
186+
" - [x] Completed task",
187+
" - some stuff",
188+
"- [ ] Another one",
189+
" - [ ] Another child",
190+
" - [/] More children",
191+
" - another child",
192+
"- this isn't copied",
193+
];
194+
195+
// WHEN
196+
const todos = getTodos({ lines: lines, withChildren: true });
197+
198+
// THEN
199+
const result = [
200+
"- [ ] TODO",
201+
" - [ ] Next",
202+
" - some stuff",
203+
"- [ ] Another one",
204+
" - [ ] Another child",
205+
" - [/] More children",
206+
" - another child",
207+
];
208+
expect(todos).toStrictEqual(result);
209+
});
145210
test("get todos with children doesn't fail if child at end of list", () => {
146211
// GIVEN
147212
const lines = [

0 commit comments

Comments
 (0)