Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure priority is parsed in heading
Browse files Browse the repository at this point in the history
GuiltyDolphin committed Jul 12, 2021
1 parent d870901 commit a092485
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/orga/src/parse/__tests__/headline.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {
heading,
testParse,
} from "./util";

import { Char } from '../../char';

describe("headings", () => {
const maxCheckDepth = 5;

describe(`supports headings of arbitrary depth (checked up to level ${maxCheckDepth})`, () => {
for (let level = 1; level <= maxCheckDepth; level++) {
testParse(`heading level ${level}`, `${"*".repeat(level)} Heading`, [heading(level, "Heading")]);
};
});

describe("keywords", () => {
testParse("with TODO keyword", "* TODO Heading", [heading(1, "Heading", { actionable: true, keyword: "TODO" })]);

testParse("with DONE keyword", "* DONE Heading", [heading(1, "Heading", { actionable: false, keyword: "DONE" })]);
});

describe("priority", () => {
for (const cookie of ["A", "a", "B"] as Char[]) {
testParse(`cookie "${cookie}"`, `* [#${cookie}] Heading`, [heading(1, "Heading", { priority: cookie })]);
}
});

describe("tags", () => {
testParse("separates colon-separated tags into list", "* Heading :tag1:tag2:",
[heading(1, "Heading", { tags: ["tag1", "tag2"] })]);

testParse("distinguishes non-tags when preceding tags",
"* Heading :nottags: :tags:",
[heading(1, "Heading :nottags:", { tags: ["tags"] })]);
});

testParse("complex heading", "* TODO [#A] Heading :nottags: stuff :tag1:tag2:",
[heading(1, "Heading :nottags: stuff", {
actionable: true,
keyword: "TODO",
tags: ["tag1", "tag2"],
})]);
});
4 changes: 4 additions & 0 deletions packages/orga/src/parse/headline.ts
Original file line number Diff line number Diff line change
@@ -27,6 +27,10 @@ export default function parseHeadline(minDepth: number = 0) {
headline.actionable = t.actionable
});

tryTo(eatTok('priority'))(t => {
headline.priority = t.value;
});

// actual title
tryMany(tokenValued())(t => {
headline.content += t.value

0 comments on commit a092485

Please sign in to comment.