From 2fe23cd8ec20ae901590c7a2833d6ceb851a9111 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sun, 24 Apr 2016 22:19:58 +0900 Subject: [PATCH] fix(mention): fix mention matching --- lib/regex.js | 2 +- test/regex.spec.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/lib/regex.js b/lib/regex.js index fdc5a8a..e719c1b 100644 --- a/lib/regex.js +++ b/lib/regex.js @@ -49,6 +49,6 @@ module.exports = function(options) { notes: reNotes, referenceParts: reReferenceParts, references: reReferences, - mentions: /@(\S+)/g + mentions: /@([\w-]+)/g }; }; diff --git a/test/regex.spec.js b/test/regex.spec.js index e361fce..eaef619 100644 --- a/test/regex.spec.js +++ b/test/regex.spec.js @@ -239,4 +239,69 @@ describe('regex', function() { expect(match).to.equal(null); }); }); + + describe('mentions', function() { + it('should match basically mention', function() { + var string = 'Thanks!! @someone'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@someone'); + expect(match[1]).to.equal('someone'); + }); + + it('should match mention with hyphen', function() { + var string = 'Thanks!! @some-one'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@some-one'); + expect(match[1]).to.equal('some-one'); + }); + + it('should match mention with underscore', function() { + var string = 'Thanks!! @some_one'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@some_one'); + expect(match[1]).to.equal('some_one'); + }); + + it('should match mention with parentheses', function() { + var string = 'Fix feature1 (by @someone)'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@someone'); + expect(match[1]).to.equal('someone'); + }); + + it('should match mention with brackets', function() { + var string = 'Fix feature1 [by @someone]'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@someone'); + expect(match[1]).to.equal('someone'); + }); + + it('should match mention with braces', function() { + var string = 'Fix feature1 {by @someone}'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@someone'); + expect(match[1]).to.equal('someone'); + }); + + it('should match mention with angle brackets', function() { + var string = 'Fix feature1 by <@someone>'; + var mentions = regex().mentions; + + var match = mentions.exec(string); + expect(match[0]).to.equal('@someone'); + expect(match[1]).to.equal('someone'); + }); + }); });