1 | 'use strict';
|
2 |
|
3 | var tape = require('../');
|
4 | var tap = require('tap');
|
5 | var concat = require('concat-stream');
|
6 |
|
7 | var stripFullStack = require('./common').stripFullStack;
|
8 |
|
9 | tap.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 | 'ok 1 regex arg must be a regex',
|
18 | 'ok 2 string arg must be a string',
|
19 | 'not ok 3 The input did not match the regular expression /abc/. Input: \'string\'',
|
20 | ' ---',
|
21 | ' operator: match',
|
22 | ' expected: /abc/',
|
23 | ' actual: \'string\'',
|
24 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
25 | ' stack: |-',
|
26 | ' Error: The input did not match the regular expression /abc/. Input: \'string\'',
|
27 | ' [... stack stripped ...]',
|
28 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
29 | ' [... stack stripped ...]',
|
30 | ' ...',
|
31 | 'not ok 4 "string" does not match /abc/',
|
32 | ' ---',
|
33 | ' operator: match',
|
34 | ' expected: /abc/',
|
35 | ' actual: \'string\'',
|
36 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
37 | ' stack: |-',
|
38 | ' Error: "string" does not match /abc/',
|
39 | ' [... stack stripped ...]',
|
40 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
41 | ' [... stack stripped ...]',
|
42 | ' ...',
|
43 | 'ok 5 The input matched the regular expression /pass$/. Input: \'I will pass\'',
|
44 | 'ok 6 "I will pass" matches /pass$/',
|
45 | '',
|
46 | '1..6',
|
47 | '# tests 6',
|
48 | '# pass 4',
|
49 | '# fail 2',
|
50 | ''
|
51 | ].join('\n'));
|
52 | };
|
53 |
|
54 | test.createStream().pipe(concat(tc));
|
55 |
|
56 | test('match', function (t) {
|
57 | t.plan(6);
|
58 |
|
59 | t.throws(
|
60 | function () { t.match(/abc/, 'string'); },
|
61 | TypeError,
|
62 | 'regex arg must be a regex'
|
63 | );
|
64 |
|
65 | t.throws(
|
66 | function () { t.match({ abc: 123 }, /abc/); },
|
67 | TypeError,
|
68 | 'string arg must be a string'
|
69 | );
|
70 |
|
71 | t.match('string', /abc/);
|
72 | t.match('string', /abc/, '"string" does not match /abc/');
|
73 |
|
74 | t.match('I will pass', /pass$/);
|
75 | t.match('I will pass', /pass$/, '"I will pass" matches /pass$/');
|
76 |
|
77 | t.end();
|
78 | });
|
79 | });
|
80 |
|
81 | tap.test('doesNotMatch', function (tt) {
|
82 | tt.plan(1);
|
83 |
|
84 | var test = tape.createHarness({ exit: false });
|
85 | var tc = function (rows) {
|
86 | tt.same(stripFullStack(rows.toString('utf8')), [
|
87 | 'TAP version 13',
|
88 | '# doesNotMatch',
|
89 | 'ok 1 regex arg must be a regex',
|
90 | 'ok 2 string arg must be a string',
|
91 | 'not ok 3 The input was expected to not match the regular expression /string/. Input: \'string\'',
|
92 | ' ---',
|
93 | ' operator: doesNotMatch',
|
94 | ' expected: /string/',
|
95 | ' actual: \'string\'',
|
96 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
97 | ' stack: |-',
|
98 | ' Error: The input was expected to not match the regular expression /string/. Input: \'string\'',
|
99 | ' [... stack stripped ...]',
|
100 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
101 | ' [... stack stripped ...]',
|
102 | ' ...',
|
103 | 'not ok 4 "string" should not match /string/',
|
104 | ' ---',
|
105 | ' operator: doesNotMatch',
|
106 | ' expected: /string/',
|
107 | ' actual: \'string\'',
|
108 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
109 | ' stack: |-',
|
110 | ' Error: "string" should not match /string/',
|
111 | ' [... stack stripped ...]',
|
112 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
113 | ' [... stack stripped ...]',
|
114 | ' ...',
|
115 | 'not ok 5 The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
|
116 | ' ---',
|
117 | ' operator: doesNotMatch',
|
118 | ' expected: /pass$/',
|
119 | ' actual: \'I will pass\'',
|
120 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
121 | ' stack: |-',
|
122 | ' Error: The input was expected to not match the regular expression /pass$/. Input: \'I will pass\'',
|
123 | ' [... stack stripped ...]',
|
124 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
125 | ' [... stack stripped ...]',
|
126 | ' ...',
|
127 | 'not ok 6 "I will pass" should not match /pass$/',
|
128 | ' ---',
|
129 | ' operator: doesNotMatch',
|
130 | ' expected: /pass$/',
|
131 | ' actual: \'I will pass\'',
|
132 | ' at: Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
133 | ' stack: |-',
|
134 | ' Error: "I will pass" should not match /pass$/',
|
135 | ' [... stack stripped ...]',
|
136 | ' at Test.<anonymous> ($TEST/match.js:$LINE:$COL)',
|
137 | ' [... stack stripped ...]',
|
138 | ' ...',
|
139 | '',
|
140 | '1..6',
|
141 | '# tests 6',
|
142 | '# pass 2',
|
143 | '# fail 4',
|
144 | ''
|
145 | ].join('\n'));
|
146 | };
|
147 |
|
148 | test.createStream().pipe(concat(tc));
|
149 |
|
150 | test('doesNotMatch', function (t) {
|
151 | t.plan(6);
|
152 |
|
153 | t.throws(
|
154 | function () { t.doesNotMatch(/abc/, 'string'); },
|
155 | TypeError,
|
156 | 'regex arg must be a regex'
|
157 | );
|
158 |
|
159 | t.throws(
|
160 | function () { t.doesNotMatch({ abc: 123 }, /abc/); },
|
161 | TypeError,
|
162 | 'string arg must be a string'
|
163 | );
|
164 |
|
165 | t.doesNotMatch('string', /string/);
|
166 | t.doesNotMatch('string', /string/, '"string" should not match /string/');
|
167 |
|
168 | t.doesNotMatch('I will pass', /pass$/);
|
169 | t.doesNotMatch('I will pass', /pass$/, '"I will pass" should not match /pass$/');
|
170 |
|
171 | t.end();
|
172 | });
|
173 | });
|