Page MenuHomePhabricator

D9056.id31241.diff
No OneTemporary

D9056.id31241.diff

diff --git a/lib/shared/markdown.test.js b/lib/shared/markdown.test.js
--- a/lib/shared/markdown.test.js
+++ b/lib/shared/markdown.test.js
@@ -1,6 +1,7 @@
// @flow
import { spoilerRegex } from './markdown.js';
+import { chatMentionRegex } from './mention-utils.js';
// Each of the below tests is subject to the following RegEx pattern:
// Spoiler RegEx: /^\|\|([^\n]+?)\|\|/g
@@ -86,3 +87,58 @@
expect(extracted ? extracted[0] : null).toMatch(' \\|\\| ');
});
});
+
+// Each of the below tests is subject to the following RegEx pattern:
+// Chat mention RegEx:
+// (?<!\\)(@\[\[(${idSchemaRegex}):(.{1,${chatNameMaxLength}?)(?<!\\)\]\])
+
+describe('chatMentionRegex', () => {
+ it('We do not expect an empty raw chat mention to match.', () => {
+ expect('@[[:]]').not.toMatch(chatMentionRegex);
+ expect('@[[]]').not.toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect a raw chat mention with invalid id to match.', () => {
+ expect('@[[|:]]').not.toMatch(chatMentionRegex);
+ expect('@[[256|:hello]]').not.toMatch(chatMentionRegex);
+ expect('@[[foo:]]').not.toMatch(chatMentionRegex);
+ expect('@[[:bar]]').not.toMatch(chatMentionRegex);
+ expect('@[[|:bar]]').not.toMatch(chatMentionRegex);
+ expect('@[[foo:bar]]').not.toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect to match raw chat mention with valid id and without text.', () => {
+ expect('@[[1:]]').not.toMatch(chatMentionRegex);
+ expect('@[[256|1:]]').not.toMatch(chatMentionRegex);
+ });
+
+ it('We do expect to match raw chat mention with valid id and text.', () => {
+ expect('@[[1:test]]').toMatch(chatMentionRegex);
+ expect('@[[256|1:test]]').toMatch(chatMentionRegex);
+ });
+
+ it('We do expect to properly match closed raw chat mention.', () => {
+ expect('@[[256|1:bar \\] \\]]]').toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect to improperly match closed raw chat mention.', () => {
+ expect('@[[256|1:bar \\]]').not.toMatch(chatMentionRegex);
+ expect('@[[256|1:bar \\] \\]]').not.toMatch(chatMentionRegex);
+ expect('@[[256|1:bar] ]').not.toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect to match raw chat mention with escaped @ char.', () => {
+ expect('\\@[[1:bar]]').not.toMatch(chatMentionRegex);
+ });
+
+ it('We do expect to match raw chat mention with escaped chars in default text field.', () => {
+ expect('@[[256|1:\\@\\[\\[1:test\\]\\] ]]').toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect an invalid raw chat mention format to match.', () => {
+ expect('@[256|1:test]').not.toMatch(chatMentionRegex);
+ expect('@test').not.toMatch(chatMentionRegex);
+ expect('@[256|1:test]]').not.toMatch(chatMentionRegex);
+ expect('@[[256|1:test]').not.toMatch(chatMentionRegex);
+ });
+});

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 8:53 AM (21 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2451062
Default Alt Text
D9056.id31241.diff (2 KB)

Event Timeline