Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3181203
D9056.id30680.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.id30680.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,57 @@
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 match raw chat mention with escaped squared closing brackets.', () => {
+ expect('@[[256|1:bar \\] \\]]]').toMatch(chatMentionRegex);
+ });
+
+ it('We do not expect to match raw chat mention with escaped squared closing brackets.', () => {
+ 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.', () => {
+ 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, 5:44 AM (21 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2449417
Default Alt Text
D9056.id30680.diff (2 KB)
Attached To
Mode
D9056: [lib] Add unit tests for chat mention regex
Attached
Detach File
Event Timeline
Log In to Comment