UNPKG

11.1 kBJavaScriptView Raw
1'use strict';
2
3var tape = require('../');
4var tap = require('tap');
5var concat = require('concat-stream');
6
7var stripFullStack = require('./common').stripFullStack;
8
9tap.test('match', function (tt) {
10 tt.plan(1);
11
12 var test = tape.createHarness({ exit: false });
13 var tc = function (rows) {
14 tt.same(stripFullStack(rows.toString('utf8')), [
15 'TAP version 13',
16 '# match',
17 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
18 ' ---',
19 ' operator: match',
20 ' expected: \'[object RegExp]\'',
21 ' actual: \'[object String]\'',
22 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
23 ' stack: |-',
24 ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
25 ' [... stack stripped ...]',
26 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
27 ' [... stack stripped ...]',
28 ' ...',
29 'not ok 2 regex arg must not be a string',
30 ' ---',
31 ' operator: match',
32 ' expected: \'[object RegExp]\'',
33 ' actual: \'[object String]\'',
34 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
35 ' stack: |-',
36 ' Error: regex arg must not be a string',
37 ' [... stack stripped ...]',
38 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
39 ' [... stack stripped ...]',
40 ' ...',
41 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
42 ' ---',
43 ' operator: match',
44 ' expected: \'string\'',
45 ' actual: \'object\'',
46 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
47 ' stack: |-',
48 ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
49 ' [... stack stripped ...]',
50 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
51 ' [... stack stripped ...]',
52 ' ...',
53 'not ok 4 string arg must not be an object',
54 ' ---',
55 ' operator: match',
56 ' expected: \'string\'',
57 ' actual: \'object\'',
58 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
59 ' stack: |-',
60 ' Error: string arg must not be an object',
61 ' [... stack stripped ...]',
62 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
63 ' [... stack stripped ...]',
64 ' ...',
65 'not ok 5 The input did not match the regular expression /abc/. Input: \'string\'',
66 ' ---',
67 ' operator: match',
68 ' expected: /abc/',
69 ' actual: \'string\'',
70 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
71 ' stack: |-',
72 ' Error: The input did not match the regular expression /abc/. Input: \'string\'',
73 ' [... stack stripped ...]',
74 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
75 ' [... stack stripped ...]',
76 ' ...',
77 'not ok 6 "string" does not match /abc/',
78 ' ---',
79 ' operator: match',
80 ' expected: /abc/',
81 ' actual: \'string\'',
82 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
83 ' stack: |-',
84 ' Error: "string" does not match /abc/',
85 ' [... stack stripped ...]',
86 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
87 ' [... stack stripped ...]',
88 ' ...',
89 'ok 7 The input matched the regular expression /pass$/. Input: \'I will pass\'',
90 'ok 8 "I will pass" matches /pass$/',
91 '',
92 '1..8',
93 '# tests 8',
94 '# pass 2',
95 '# fail 6',
96 ''
97 ]);
98 };
99
100 test.createStream().pipe(concat(tc));
101
102 test('match', function (t) {
103 t.plan(8);
104
105 t.match(/abc/, 'string');
106 t.match(/abc/, 'string', 'regex arg must not be a string');
107
108 t.match({ abc: 123 }, /abc/);
109 t.match({ abc: 123 }, /abc/, 'string arg must not be an object');
110
111 t.match('string', /abc/);
112 t.match('string', /abc/, '"string" does not match /abc/');
113
114 t.match('I will pass', /pass$/);
115 t.match('I will pass', /pass$/, '"I will pass" matches /pass$/');
116
117 t.end();
118 });
119});
120
121tap.test('doesNotMatch', function (tt) {
122 tt.plan(1);
123
124 var test = tape.createHarness({ exit: false });
125 var tc = function (rows) {
126 tt.same(stripFullStack(rows.toString('utf8')), [
127 'TAP version 13',
128 '# doesNotMatch',
129 'not ok 1 The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
130 ' ---',
131 ' operator: doesNotMatch',
132 ' expected: \'[object RegExp]\'',
133 ' actual: \'[object String]\'',
134 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
135 ' stack: |-',
136 ' Error: The "regexp" argument must be an instance of RegExp. Received type string (\'string\')',
137 ' [... stack stripped ...]',
138 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
139 ' [... stack stripped ...]',
140 ' ...',
141 'not ok 2 regex arg must not be a string',
142 ' ---',
143 ' operator: doesNotMatch',
144 ' expected: \'[object RegExp]\'',
145 ' actual: \'[object String]\'',
146 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
147 ' stack: |-',
148 ' Error: regex arg must not be a string',
149 ' [... stack stripped ...]',
150 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
151 ' [... stack stripped ...]',
152 ' ...',
153 'not ok 3 The "string" argument must be of type string. Received type object ({ abc: 123 })',
154 ' ---',
155 ' operator: doesNotMatch',
156 ' expected: \'string\'',
157 ' actual: \'object\'',
158 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
159 ' stack: |-',
160 ' Error: The "string" argument must be of type string. Received type object ({ abc: 123 })',
161 ' [... stack stripped ...]',
162 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
163 ' [... stack stripped ...]',
164 ' ...',
165 'not ok 4 string arg must not be an object',
166 ' ---',
167 ' operator: doesNotMatch',
168 ' expected: \'string\'',
169 ' actual: \'object\'',
170 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
171 ' stack: |-',
172 ' Error: string arg must not be an object',
173 ' [... stack stripped ...]',
174 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
175 ' [... stack stripped ...]',
176 ' ...',
177 'not ok 5 The input was expected to not match the regular expression /string/. Input: \'string\'',
178 ' ---',
179 ' operator: doesNotMatch',
180 ' expected: /string/',
181 ' actual: \'string\'',
182 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
183 ' stack: |-',
184 ' Error: The input was expected to not match the regular expression /string/. Input: \'string\'',
185 ' [... stack stripped ...]',
186 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
187 ' [... stack stripped ...]',
188 ' ...',
189 'not ok 6 "string" should not match /string/',
190 ' ---',
191 ' operator: doesNotMatch',
192 ' expected: /string/',
193 ' actual: \'string\'',
194 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
195 ' stack: |-',
196 ' Error: "string" should not match /string/',
197 ' [... stack stripped ...]',
198 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
199 ' [... stack stripped ...]',
200 ' ...',
201 'not ok 7 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
202 ' ---',
203 ' operator: doesNotMatch',
204 ' expected: /pass$/',
205 ' actual: \'I will pass\'',
206 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
207 ' stack: |-',
208 ' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
209 ' [... stack stripped ...]',
210 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
211 ' [... stack stripped ...]',
212 ' ...',
213 'not ok 8 "I will pass" should not match /pass$/',
214 ' ---',
215 ' operator: doesNotMatch',
216 ' expected: /pass$/',
217 ' actual: \'I will pass\'',
218 ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
219 ' stack: |-',
220 ' Error: "I will pass" should not match /pass$/',
221 ' [... stack stripped ...]',
222 ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
223 ' [... stack stripped ...]',
224 ' ...',
225 'ok 9 The input did not match the regular expression /pass$/. Input: \'I will fail\'',
226 'ok 10 "I will fail" does not match /pass$/',
227 '',
228 '1..10',
229 '# tests 10',
230 '# pass 2',
231 '# fail 8',
232 ''
233 ]);
234 };
235
236 test.createStream().pipe(concat(tc));
237
238 test('doesNotMatch', function (t) {
239 t.plan(10);
240
241 t.doesNotMatch(/abc/, 'string');
242 t.doesNotMatch(/abc/, 'string', 'regex arg must not be a string');
243
244 t.doesNotMatch({ abc: 123 }, /abc/);
245 t.doesNotMatch({ abc: 123 }, /abc/, 'string arg must not be an object');
246
247 t.doesNotMatch('string', /string/);
248 t.doesNotMatch('string', /string/, '"string" should not match /string/');
249
250 t.doesNotMatch('I will pass', /pass$/);
251 t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/');
252
253 t.doesNotMatch('I will fail', /pass$/);
254 t.doesNotMatch('I will fail', /pass$/, '"I will fail" does not match /pass$/');
255
256 t.end();
257 });
258});