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