Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3183347
D9056.id31241.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D9056.id31241.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D9056: [lib] Add unit tests for chat mention regex
Attached
Detach File
Event Timeline
Log In to Comment