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

Fix mention matching #26

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});
});