Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alternative checkboxes #76

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/get-todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class TodoParser {

// Returns true if string s is a todo-item
#isTodo(s) {
const r = /\s*- \[ \].*/g;
const r = /\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 @@ -65,6 +101,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
2 changes: 1 addition & 1 deletion src/ui/RolloverSettingTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class RolloverSettingTab extends PluginSettingTab {
new Setting(this.containerEl)
.setName("Roll over children of todos")
.setDesc(
`By default, only the acutal todos are rolled over. If you add nested Markdown-elements beneath your todos, these are not rolled over but stay in place, possibly altering the logic of your previous note. This setting allows for also migrating the nested elements.`
`By default, only the actual todos are rolled over. If you add nested Markdown-elements beneath your todos, these are not rolled over but stay in place, possibly altering the logic of your previous note. This setting allows for also migrating the nested elements.`
)
.addToggle((toggle) =>
toggle
Expand Down