|
5 | 5 | * Released under the MIT license. |
6 | 6 | */ |
7 | 7 |
|
8 | | -'use strict'; |
| 8 | +'use strict' |
9 | 9 |
|
10 | | -var assert = require('assert'); |
11 | | -var regexp = require('./index'); |
12 | | -var fixtures = require('./fixtures'); |
| 10 | +var test = require('assertit') |
| 11 | +var regexp = require('./index') |
| 12 | +var fixtures = require('./fixtures') |
13 | 13 |
|
14 | | -function match(str, dot) { |
15 | | - var ex = regexp(dot).exec(str); |
16 | | - return ex && ex[1] || null; |
| 14 | +function reMatch (str, dot) { |
| 15 | + var ex = regexp(dot).exec(str) |
| 16 | + return ex && ex[1] || null |
17 | 17 | } |
18 | 18 |
|
19 | | -function test(str, dot) { |
20 | | - return regexp(dot).test(str); |
| 19 | +function reTest (str, dot) { |
| 20 | + return regexp(dot).test(str) |
21 | 21 | } |
22 | 22 |
|
23 | | -describe('mentions-regex:', function() { |
24 | | - describe('when `dot` is true', function() { |
25 | | - it('should match `google.com` from `foo @google.com bar`', function(done) { |
26 | | - assert.strictEqual(match('foo @google.com bar', true), 'google.com'); |
27 | | - assert.strictEqual(test('foo @google.com bar', true), true); |
28 | | - done(); |
29 | | - }); |
30 | | - |
31 | | - it('should not match when `foo@bar.com qux`', function(done) { |
32 | | - assert.strictEqual(match('foo@bar.com qux', true), null); |
33 | | - assert.strictEqual(test('foo@bar.com qux', true), false); |
34 | | - done(); |
35 | | - }); |
36 | | - }); |
37 | | - |
38 | | - describe('when `dot` is falsey value', function() { |
39 | | - it('should match `google` from `foo @google.com bar`', function(done) { |
40 | | - assert.strictEqual(match('foo @google.com bar', false), 'google'); |
41 | | - assert.strictEqual(test('foo @google.com bar', false), true); |
42 | | - done(); |
43 | | - }); |
44 | | - |
45 | | - it('should not match when `foo@bar.com qux`', function(done) { |
46 | | - assert.strictEqual(match('foo@bar.com qux', false), null); |
47 | | - assert.strictEqual(test('foo@bar.com qux', false), false); |
48 | | - done(); |
49 | | - }); |
50 | | - }); |
51 | | - |
52 | | - describe('special cases', function() { |
53 | | - it('should match `bar_baz` from `foo @bar_baz qux`', function(done) { |
54 | | - assert.strictEqual(match('foo @bar_baz qux'), 'bar_baz'); |
55 | | - assert.strictEqual(test('foo @bar_baz qux'), true); |
56 | | - done(); |
57 | | - }); |
58 | | - |
59 | | - it('should match `_bar_baz` from `foo @_bar_baz qux`', function(done) { |
60 | | - assert.strictEqual(match('foo @_bar_baz qux'), '_bar_baz'); |
61 | | - assert.strictEqual(test('foo @_bar_baz qux'), true); |
62 | | - done(); |
63 | | - }); |
64 | | - |
65 | | - it('should match `_bar` from `foo @_bar baz qux`', function(done) { |
66 | | - assert.strictEqual(match('foo @_bar baz qux'), '_bar'); |
67 | | - assert.strictEqual(test('foo @_bar baz qux'), true); |
68 | | - done(); |
69 | | - }); |
70 | | - |
71 | | - it('should match `bar/baz` from `foo @bar/baz qux`', function(done) { |
72 | | - assert.strictEqual(match('foo @bar/baz qux'), 'bar/baz'); |
73 | | - assert.strictEqual(test('foo @bar/baz qux'), true); |
74 | | - done(); |
75 | | - }); |
76 | | - |
77 | | - it('should match `bar/baz` from `foo /@bar/baz qux`', function(done) { |
78 | | - assert.strictEqual(match('foo /@bar/baz qux'), 'bar/baz'); |
79 | | - assert.strictEqual(test('foo /@bar/baz qux'), true); |
80 | | - done(); |
81 | | - }); |
82 | | - |
83 | | - it('should match `bar` from `foo /@bar baz qux`', function(done) { |
84 | | - assert.strictEqual(match('foo /@bar baz qux'), 'bar'); |
85 | | - assert.strictEqual(test('foo /@bar baz qux'), true); |
86 | | - done(); |
87 | | - }); |
88 | | - |
89 | | - it('should match `222` from `foo @222 baz qux`', function(done) { |
90 | | - assert.strictEqual(match('foo @222 baz qux'), '222'); |
91 | | - assert.strictEqual(test('foo @222 baz qux'), true); |
92 | | - done(); |
93 | | - }); |
94 | | - |
95 | | - it('should not match from `foo @/bar/baz qux`', function(done) { |
96 | | - assert.strictEqual(match('foo @/bar/baz qux'), null); |
97 | | - assert.strictEqual(test('foo @/bar/baz qux'), false); |
98 | | - done(); |
99 | | - }); |
100 | | - |
101 | | - it('should not match from `foo @/bar baz qux`', function(done) { |
102 | | - assert.strictEqual(match('foo @/bar baz qux'), null); |
103 | | - assert.strictEqual(test('foo @/bar baz qux'), false); |
104 | | - done(); |
105 | | - }); |
106 | | - |
107 | | - it('should not match email addresses `foo@bar.com`', function(done) { |
108 | | - assert.strictEqual(match('foo@bar.com'), null); |
109 | | - assert.strictEqual(test('foo@bar.com'), false); |
110 | | - done(); |
111 | | - }); |
112 | | - }); |
113 | | - |
114 | | - describe('should match `bar` only', function() { |
115 | | - fixtures.shouldMatchBarOnly.forEach(function _each(item) { |
116 | | - it('from `' + item + '` string given', function(done) { |
117 | | - assert.strictEqual(match(item), 'bar'); |
118 | | - assert.strictEqual(test(item), true); |
119 | | - done(); |
120 | | - }); |
121 | | - }); |
122 | | - }); |
123 | | - |
124 | | - describe('should not match', function() { |
125 | | - fixtures.shouldNotMatch.forEach(function _each(item) { |
126 | | - it('from `' + item + '` string given', function(done) { |
127 | | - assert.strictEqual(match(item), null); |
128 | | - assert.strictEqual(test(item), false); |
129 | | - done(); |
130 | | - }); |
131 | | - }); |
132 | | - }); |
133 | | -}); |
| 23 | +test('mentions-regex:', function () { |
| 24 | + test('when `dot` is true', function () { |
| 25 | + test('should match `google.com` from `foo @google.com bar`', function (done) { |
| 26 | + test.equal(reMatch('foo @google.com bar', true), 'google.com') |
| 27 | + test.equal(reTest('foo @google.com bar', true), true) |
| 28 | + done() |
| 29 | + }) |
| 30 | + |
| 31 | + test('should not match when `foo@bar.com qux`', function (done) { |
| 32 | + test.equal(reMatch('foo@bar.com qux', true), null) |
| 33 | + test.equal(reTest('foo@bar.com qux', true), false) |
| 34 | + done() |
| 35 | + }) |
| 36 | + }) |
| 37 | + |
| 38 | + test('when `dot` is falsey value', function () { |
| 39 | + test('should match `google` from `foo @google.com bar`', function (done) { |
| 40 | + test.equal(reMatch('foo @google.com bar', false), 'google') |
| 41 | + test.equal(reTest('foo @google.com bar', false), true) |
| 42 | + done() |
| 43 | + }) |
| 44 | + |
| 45 | + test('should not match when `foo@bar.com qux`', function (done) { |
| 46 | + test.equal(reMatch('foo@bar.com qux', false), null) |
| 47 | + test.equal(reTest('foo@bar.com qux', false), false) |
| 48 | + done() |
| 49 | + }) |
| 50 | + }) |
| 51 | + |
| 52 | + test('special cases', function () { |
| 53 | + test('should match `bar_baz` from `foo @bar_baz qux`', function (done) { |
| 54 | + test.equal(reMatch('foo @bar_baz qux'), 'bar_baz') |
| 55 | + test.equal(reTest('foo @bar_baz qux'), true) |
| 56 | + done() |
| 57 | + }) |
| 58 | + |
| 59 | + test('should match `_bar_baz` from `foo @_bar_baz qux`', function (done) { |
| 60 | + test.equal(reMatch('foo @_bar_baz qux'), '_bar_baz') |
| 61 | + test.equal(reTest('foo @_bar_baz qux'), true) |
| 62 | + done() |
| 63 | + }) |
| 64 | + |
| 65 | + test('should match `_bar` from `foo @_bar baz qux`', function (done) { |
| 66 | + test.equal(reMatch('foo @_bar baz qux'), '_bar') |
| 67 | + test.equal(reTest('foo @_bar baz qux'), true) |
| 68 | + done() |
| 69 | + }) |
| 70 | + |
| 71 | + test('should match `bar/baz` from `foo @bar/baz qux`', function (done) { |
| 72 | + test.equal(reMatch('foo @bar/baz qux'), 'bar/baz') |
| 73 | + test.equal(reTest('foo @bar/baz qux'), true) |
| 74 | + done() |
| 75 | + }) |
| 76 | + |
| 77 | + test('should match `bar/baz` from `foo /@bar/baz qux`', function (done) { |
| 78 | + test.equal(reMatch('foo /@bar/baz qux'), 'bar/baz') |
| 79 | + test.equal(reTest('foo /@bar/baz qux'), true) |
| 80 | + done() |
| 81 | + }) |
| 82 | + |
| 83 | + test('should match `bar` from `foo /@bar baz qux`', function (done) { |
| 84 | + test.equal(reMatch('foo /@bar baz qux'), 'bar') |
| 85 | + test.equal(reTest('foo /@bar baz qux'), true) |
| 86 | + done() |
| 87 | + }) |
| 88 | + |
| 89 | + test('should match `222` from `foo @222 baz qux`', function (done) { |
| 90 | + test.equal(reMatch('foo @222 baz qux'), '222') |
| 91 | + test.equal(reTest('foo @222 baz qux'), true) |
| 92 | + done() |
| 93 | + }) |
| 94 | + |
| 95 | + test('should not match from `foo @/bar/baz qux`', function (done) { |
| 96 | + test.equal(reMatch('foo @/bar/baz qux'), null) |
| 97 | + test.equal(reTest('foo @/bar/baz qux'), false) |
| 98 | + done() |
| 99 | + }) |
| 100 | + |
| 101 | + test('should not match from `foo @/bar baz qux`', function (done) { |
| 102 | + test.equal(reMatch('foo @/bar baz qux'), null) |
| 103 | + test.equal(reTest('foo @/bar baz qux'), false) |
| 104 | + done() |
| 105 | + }) |
| 106 | + |
| 107 | + test('should not match email addresses `foo@bar.com`', function (done) { |
| 108 | + test.equal(reMatch('foo@bar.com'), null) |
| 109 | + test.equal(reTest('foo@bar.com'), false) |
| 110 | + done() |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + test('should match `bar` only', function () { |
| 115 | + fixtures.shouldMatchBarOnly.forEach(function _each (item) { |
| 116 | + test('from `' + item + '` string given', function (done) { |
| 117 | + test.equal(reMatch(item), 'bar') |
| 118 | + test.equal(reTest(item), true) |
| 119 | + done() |
| 120 | + }) |
| 121 | + }) |
| 122 | + }) |
| 123 | + |
| 124 | + test('should not match', function () { |
| 125 | + fixtures.shouldNotMatch.forEach(function _each (item) { |
| 126 | + test('from `' + item + '` string given', function (done) { |
| 127 | + test.equal(reMatch(item), null) |
| 128 | + test.equal(reTest(item), false) |
| 129 | + done() |
| 130 | + }) |
| 131 | + }) |
| 132 | + }) |
| 133 | +}) |
0 commit comments