Skip to content

Commit 2c27987

Browse files
authored
Merge pull request #3190 from obsidian-tasks-group/test-parsing-emojis
test: - Capture string representation of emoji-parsing regexes
2 parents ce4ff38 + 9f6ead0 commit 2c27987

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

tests/TaskSerializer/DefaultTaskSerializer.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,42 @@ describe('validate emojis', () => {
4242
});
4343
});
4444

45+
describe('validate emoji regular expressions', () => {
46+
/**
47+
* Generate a string representation of all regular expressions
48+
* in TaskFormatRegularExpressions by concatenating their source and flags.
49+
*/
50+
function generateRegexApprovalTest(): string {
51+
const regexMap = DEFAULT_SYMBOLS.TaskFormatRegularExpressions;
52+
const regexDetails = Object.entries(regexMap).map(([key, regex]) => {
53+
// Get the source and flags for each regex
54+
if (regex instanceof RegExp) {
55+
return `${key}: /${regex.source}/${regex.flags}`;
56+
} else {
57+
throw new Error(`Unexpected value for ${key}: Not a regular expression.`);
58+
}
59+
});
60+
// Concatenate all entries into a single string
61+
return regexDetails.join('\n');
62+
}
63+
64+
it('regular expressions should have expected source', () => {
65+
expect(generateRegexApprovalTest()).toMatchInlineSnapshot(`
66+
"priorityRegex: /([🔺⏫🔼🔽⏬])\\uFE0F?$/u
67+
startDateRegex: /🛫 *(\\d{4}-\\d{2}-\\d{2})$/u
68+
createdDateRegex: /➕ *(\\d{4}-\\d{2}-\\d{2})$/u
69+
scheduledDateRegex: /[⏳⌛] *(\\d{4}-\\d{2}-\\d{2})$/u
70+
dueDateRegex: /[📅📆🗓] *(\\d{4}-\\d{2}-\\d{2})$/u
71+
doneDateRegex: /✅ *(\\d{4}-\\d{2}-\\d{2})$/u
72+
cancelledDateRegex: /❌ *(\\d{4}-\\d{2}-\\d{2})$/u
73+
recurrenceRegex: /🔁 ?([a-zA-Z0-9, !]+)$/iu
74+
onCompletionRegex: /🏁 ?([a-zA-Z]+)$/iu
75+
dependsOnRegex: /⛔️? *([a-zA-Z0-9-_]+( *, *[a-zA-Z0-9-_]+ *)*)$/iu
76+
idRegex: /🆔 *([a-zA-Z0-9-_]+)$/iu"
77+
`);
78+
});
79+
});
80+
4581
// NEW_TASK_FIELD_EDIT_REQUIRED
4682

4783
describe.each(symbolMap)("DefaultTaskSerializer with '$taskFormat' symbols", ({ symbols }) => {

0 commit comments

Comments
 (0)