-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#60,tasks][m]: implement extract markdown tasks i.e.
- [ ]
.
* extract tasks (find all list items and then only those with checked property or not) * fix linting * Add changeset * Run format
- Loading branch information
1 parent
dfe0cb5
commit 6a8a952
Showing
7 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"mddb": minor | ||
--- | ||
|
||
[ #60 , extract tasks ] | ||
Add tasks extraction from files. e.g `- [ ] task` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { extractTasks, processAST } from "../lib/parseFile"; | ||
|
||
const getTasksFromSource = (source: string) => { | ||
const ast = processAST(source, {}); | ||
const tasks = extractTasks(ast); | ||
return tasks; | ||
}; | ||
|
||
describe("extractTasks", () => { | ||
test("should extract uncompleted tasks from body", () => { | ||
const tasks = getTasksFromSource( | ||
"- [] uncompleted task 1\n- [ ] uncompleted task 2" | ||
); | ||
const expectedTasks = [ | ||
{ description: "uncompleted task 2", checked: false }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
|
||
test("should extract completed tasks from body", () => { | ||
const tasks = getTasksFromSource( | ||
"- [x] completed task 1\n- [X] completed task 2" | ||
); | ||
const expectedTasks = [ | ||
{ description: "completed task 1", checked: true }, | ||
{ description: "completed task 2", checked: true }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
|
||
test("should handle mixed completed and uncompleted tasks", () => { | ||
const tasks = getTasksFromSource( | ||
"- [x] completed task\n- [ ] uncompleted task" | ||
); | ||
const expectedTasks = [ | ||
{ description: "completed task", checked: true }, | ||
{ description: "uncompleted task", checked: false }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
|
||
test("should handle tasks with leading and trailing spaces", () => { | ||
const tasks = getTasksFromSource( | ||
"- [x] completed task \n- [ ] uncompleted task " | ||
); | ||
const expectedTasks = [ | ||
{ description: "completed task", checked: true }, | ||
{ description: "uncompleted task", checked: false }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
|
||
test("should handle tasks with different checkbox formats", () => { | ||
const tasks = getTasksFromSource( | ||
"- [x] task 1\n- [X] task 2\n- [ ] task 3" | ||
); | ||
const expectedTasks = [ | ||
{ description: "task 1", checked: true }, | ||
{ description: "task 2", checked: true }, | ||
{ description: "task 3", checked: false }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
|
||
test("should handle tasks with special characters", () => { | ||
const tasks = getTasksFromSource("- [x] task with $pecial character$"); | ||
const expectedTasks = [ | ||
{ description: "task with $pecial character$", checked: true }, | ||
]; | ||
expect(tasks).toEqual(expectedTasks); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters