Skip to content

Commit

Permalink
Merge pull request #2695 from obsidian-tasks-group/fix-priority-with-…
Browse files Browse the repository at this point in the history
…VS16

Fix priority with vs16
  • Loading branch information
claremacrae committed Mar 7, 2024
2 parents a9597eb + dfc857c commit 7a12bbb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/TaskSerializer/DefaultTaskSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export const DEFAULT_SYMBOLS: DefaultTaskSerializerSymbols = {
TaskFormatRegularExpressions: {
// The following regex's end with `$` because they will be matched and
// removed from the end until none are left.
priorityRegex: /([🔺⏫🔼🔽⏬])$/u,
// \uFE0F? allows an optional Variant Selector 16 on emojis.
priorityRegex: /([🔺⏫🔼🔽⏬])\uFE0F?$/u,
startDateRegex: /🛫 *(\d{4}-\d{2}-\d{2})$/u,
createdDateRegex: /➕ *(\d{4}-\d{2}-\d{2})$/u,
scheduledDateRegex: /[⏳⌛] *(\d{4}-\d{2}-\d{2})$/u,
Expand Down
28 changes: 28 additions & 0 deletions tests/TaskSerializer/DefaultTaskSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ type DefaultTaskSerializeSymbolMap = readonly {
// A map that facilitates parameterizing the tests over symbols
const symbolMap: DefaultTaskSerializeSymbolMap = [{ taskFormat: 'tasksPluginEmoji', symbols: DEFAULT_SYMBOLS }];

/**
* Since Variant Selectors are invisible, any tests whose behaviour is dependent on the
* presence or absence of one MUST 'expect' on the result of this function,
* to confirm that the test is doing what it claims to be doing.
* @param text
*/
function hasVariantSelector16(text: string) {
const vs16Regex = /\uFE0F/u;
return text.match(vs16Regex) !== null;
}

// NEW_TASK_FIELD_EDIT_REQUIRED

describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({ symbols }) => {
Expand Down Expand Up @@ -67,6 +78,23 @@ describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({
expect(taskDetails).toMatchTaskDetails({ priority });
}
});

it('should parse a high priority without Variant Selector 16', () => {
const line = '⏫';
expect(hasVariantSelector16(line)).toBe(false);

const taskDetails = deserialize(line);
expect(taskDetails).toMatchTaskDetails({ priority: Priority.High });
});

it('should parse a high priority with Variant Selector 16', () => {
// This test showed the existing of https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2273
const line = '⏫️'; // There is a hidden Variant Selector 16 character at the end of this string
expect(hasVariantSelector16(line)).toBe(true);

const taskDetails = deserialize(line);
expect(taskDetails).toMatchTaskDetails({ priority: Priority.High });
});
});

it('should parse a recurrence', () => {
Expand Down

0 comments on commit 7a12bbb

Please sign in to comment.