Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(mention): fix mention matching
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 24, 2016
1 parent 869e4ca commit 2fe23cd
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ module.exports = function(options) {
notes: reNotes,
referenceParts: reReferenceParts,
references: reReferences,
mentions: /@(\S+)/g
mentions: /@([\w-]+)/g
};
};
65 changes: 65 additions & 0 deletions test/regex.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 2fe23cd

Please sign in to comment.