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

fix: Enable Tasks to read "no entry" emoji from Emoji Shortcodes plugin #2696

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/TaskSerializer/DefaultTaskSerializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const DEFAULT_SYMBOLS: DefaultTaskSerializerSymbols = {
doneDateSymbol: '✅',
cancelledDateSymbol: '❌',
recurrenceSymbol: '🔁',
dependsOnSymbol: '⛔️',
dependsOnSymbol: '⛔️', // TODO Remove Variant Selector 16 from this string
idSymbol: '🆔',
TaskFormatRegularExpressions: {
// The following regex's end with `$` because they will be matched and
Expand All @@ -83,7 +83,10 @@ export const DEFAULT_SYMBOLS: DefaultTaskSerializerSymbols = {
doneDateRegex: /✅ *(\d{4}-\d{2}-\d{2})$/u,
cancelledDateRegex: /❌ *(\d{4}-\d{2}-\d{2})$/u,
recurrenceRegex: /🔁 ?([a-zA-Z0-9, !]+)$/iu,
dependsOnRegex: new RegExp('⛔️ *(' + taskIdRegex.source + '( *, *' + taskIdRegex.source + ' *)*)$', 'iu'),
dependsOnRegex: new RegExp(
'⛔\uFE0F? *(' + taskIdRegex.source + '( *, *' + taskIdRegex.source + ' *)*)$',
'iu',
),
idRegex: new RegExp('🆔 *(' + taskIdRegex.source + ')$', 'iu'),
},
} as const;
Expand Down
38 changes: 36 additions & 2 deletions tests/TaskSerializer/DefaultTaskSerializer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import moment from 'moment';
import type { Settings } from '../../src/Config/Settings';
import { DefaultTaskSerializer } from '../../src/TaskSerializer';
import { RecurrenceBuilder } from '../TestingTools/RecurrenceBuilder';
import { DEFAULT_SYMBOLS, type DefaultTaskSerializerSymbols } from '../../src/TaskSerializer/DefaultTaskSerializer';
import {
DEFAULT_SYMBOLS,
type DefaultTaskSerializerSymbols,
allTaskPluginEmojis,
} from '../../src/TaskSerializer/DefaultTaskSerializer';
import { TaskBuilder } from '../TestingTools/TaskBuilder';
import { Priority } from '../../src/Task/Priority';

Expand All @@ -30,6 +34,19 @@ function hasVariantSelector16(text: string) {
return text.match(vs16Regex) !== null;
}

describe('validate emojis', () => {
// If these tests fail, paste the problem emoji in to https://apps.timwhitlock.info/unicode/inspect
it.each(allTaskPluginEmojis())('emoji does not contain Variant Selector 16: "%s"', (emoji: string) => {
if (emoji === DEFAULT_SYMBOLS.dependsOnSymbol) {
// TODO Remove the VS16 from the dependsOn symbol:
// see https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2693
expect(hasVariantSelector16(emoji)).toBe(true);
} else {
expect(hasVariantSelector16(emoji)).toBe(false);
}
});
});

// NEW_TASK_FIELD_EDIT_REQUIRED

describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({ symbols }) => {
Expand Down Expand Up @@ -88,7 +105,7 @@ describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({
});

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
// This test showed the existence 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);

Expand All @@ -111,6 +128,23 @@ describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({
expect(taskDetails).toMatchTaskDetails({ dependsOn: ['F12345'] });
});

it('should parse depends on one task - without Variant Selector 16', () => {
// This test showed the existence of https://github.com/obsidian-tasks-group/obsidian-tasks/issues/2693
const id = '⛔ F12345';
expect(hasVariantSelector16(id)).toBe(false);

const taskDetails = deserialize(id);
expect(taskDetails).toMatchTaskDetails({ dependsOn: ['F12345'] });
});

it('should parse depends on one task - with Variant Selector 16', () => {
const id = '⛔️ F12345'; // There is a hidden Variant Selector 16 character at the end of this string
expect(hasVariantSelector16(id)).toBe(true);

const taskDetails = deserialize(id);
expect(taskDetails).toMatchTaskDetails({ dependsOn: ['F12345'] });
});

it('should parse depends on two tasks', () => {
const id = `${dependsOnSymbol} 123456,abC123`;
const taskDetails = deserialize(id);
Expand Down