/
match.js
258 lines (237 loc) · 10.8 KB
/
match.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
'use strict';
var tape = require('../');
var tap = require('tap');
var concat = require('concat-stream');
var stripFullStack = require('./common').stripFullStack;
tap.test('match', function (tt) {
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# match',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: match',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: match',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input did not match the regular expression /abc/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" does not match /abc/',
' ---',
' operator: match',
' expected: /abc/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" does not match /abc/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'',
'ok 8 "I will pass" matches /pass$/',
'',
'1..8',
'# tests 8',
'# pass 2',
'# fail 6',
''
]);
};
test.createStream().pipe(concat(tc));
test('match', function (t) {
t.plan(8);
t.match(/abc/, 'string');
t.match(/abc/, 'string', 'regex arg must not be a string');
t.match({ abc: 123 }, /abc/);
t.match({ abc: 123 }, /abc/, 'string arg must not be an object');
t.match('string', /abc/);
t.match('string', /abc/, '"string" does not match /abc/');
t.match('I will pass', /pass$/);
t.match('I will pass', /pass$/, '"I will pass" matches /pass$/');
t.end();
});
});
tap.test('doesNotMatch', function (tt) {
tt.plan(1);
var test = tape.createHarness({ exit: false });
var tc = function (rows) {
tt.same(stripFullStack(rows.toString('utf8')), [
'TAP version 13',
'# doesNotMatch',
'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 2 regex arg must not be a string',
' ---',
' operator: doesNotMatch',
' expected: \'[object RegExp]\'',
' actual: \'[object String]\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: regex arg must not be a string',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 4 string arg must not be an object',
' ---',
' operator: doesNotMatch',
' expected: \'string\'',
' actual: \'object\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: string arg must not be an object',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /string/. Input: \'string\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 6 "string" should not match /string/',
' ---',
' operator: doesNotMatch',
' expected: /string/',
' actual: \'string\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "string" should not match /string/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'not ok 8 "I will pass" should not match /pass$/',
' ---',
' operator: doesNotMatch',
' expected: /pass$/',
' actual: \'I will pass\'',
' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' stack: |-',
' Error: "I will pass" should not match /pass$/',
' [... stack stripped ...]',
' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
' [... stack stripped ...]',
' ...',
'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'',
'ok 10 "I will fail" does not match /pass$/',
'',
'1..10',
'# tests 10',
'# pass 2',
'# fail 8',
''
]);
};
test.createStream().pipe(concat(tc));
test('doesNotMatch', function (t) {
t.plan(10);
t.doesNotMatch(/abc/, 'string');
t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string');
t.doesNotMatch({ abc: 123 }, /abc/);
t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object');
t.doesNotMatch('string', /string/);
t.doesNotMatch('string', /string/, '"string" should not match /string/');
t.doesNotMatch('I will pass', /pass$/);
t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/');
t.doesNotMatch('I will fail', /pass$/);
t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/');
t.end();
});
});