Skip to content

Commit 4526b39

Browse files
committedFeb 20, 2020
[Tests] add tests for edge cases and numerics
1 parent 398503c commit 4526b39

File tree

2 files changed

+389
-0
lines changed

2 files changed

+389
-0
lines changed
 

‎test/edge-cases.js

+237
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
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('edge cases', function (tt) {
10+
tt.plan(1);
11+
12+
var test = tape.createHarness();
13+
test.createStream().pipe(concat(function (body) {
14+
tt.equal(
15+
stripFullStack(body.toString('utf8')),
16+
'TAP version 13\n'
17+
+ '# zeroes\n'
18+
+ 'ok 1 0 equal to -0\n'
19+
+ 'ok 2 -0 equal to 0\n'
20+
+ 'not ok 3 0 notEqual to -0\n'
21+
+ ' ---\n'
22+
+ ' operator: notEqual\n'
23+
+ ' expected: |-\n'
24+
+ ' -0\n'
25+
+ ' actual: |-\n'
26+
+ ' 0\n'
27+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
28+
+ ' stack: |-\n'
29+
+ ' Error: 0 notEqual to -0\n'
30+
+ ' [... stack stripped ...]\n'
31+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
32+
+ ' [... stack stripped ...]\n'
33+
+ ' ...\n'
34+
+ 'not ok 4 -0 notEqual to 0\n'
35+
+ ' ---\n'
36+
+ ' operator: notEqual\n'
37+
+ ' expected: |-\n'
38+
+ ' 0\n'
39+
+ ' actual: |-\n'
40+
+ ' -0\n'
41+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
42+
+ ' stack: |-\n'
43+
+ ' Error: -0 notEqual to 0\n'
44+
+ ' [... stack stripped ...]\n'
45+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
46+
+ ' [... stack stripped ...]\n'
47+
+ ' ...\n'
48+
+ 'ok 5 0 strictEqual to -0\n'
49+
+ 'ok 6 -0 strictEqual to 0\n'
50+
+ 'not ok 7 0 notStrictEqual to -0\n'
51+
+ ' ---\n'
52+
+ ' operator: notEqual\n'
53+
+ ' expected: |-\n'
54+
+ ' -0\n'
55+
+ ' actual: |-\n'
56+
+ ' 0\n'
57+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
58+
+ ' stack: |-\n'
59+
+ ' Error: 0 notStrictEqual to -0\n'
60+
+ ' [... stack stripped ...]\n'
61+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
62+
+ ' [... stack stripped ...]\n'
63+
+ ' ...\n'
64+
+ 'not ok 8 -0 notStrictEqual to 0\n'
65+
+ ' ---\n'
66+
+ ' operator: notEqual\n'
67+
+ ' expected: |-\n'
68+
+ ' 0\n'
69+
+ ' actual: |-\n'
70+
+ ' -0\n'
71+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
72+
+ ' stack: |-\n'
73+
+ ' Error: -0 notStrictEqual to 0\n'
74+
+ ' [... stack stripped ...]\n'
75+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
76+
+ ' [... stack stripped ...]\n'
77+
+ ' ...\n'
78+
+ 'ok 9 0 deepLooseEqual to -0\n'
79+
+ 'ok 10 -0 deepLooseEqual to 0\n'
80+
+ 'not ok 11 0 notDeepLooseEqual to -0\n'
81+
+ ' ---\n'
82+
+ ' operator: notDeepLooseEqual\n'
83+
+ ' expected: |-\n'
84+
+ ' -0\n'
85+
+ ' actual: |-\n'
86+
+ ' 0\n'
87+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
88+
+ ' stack: |-\n'
89+
+ ' Error: 0 notDeepLooseEqual to -0\n'
90+
+ ' [... stack stripped ...]\n'
91+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
92+
+ ' [... stack stripped ...]\n'
93+
+ ' ...\n'
94+
+ 'not ok 12 -0 notDeepLooseEqual to 0\n'
95+
+ ' ---\n'
96+
+ ' operator: notDeepLooseEqual\n'
97+
+ ' expected: |-\n'
98+
+ ' 0\n'
99+
+ ' actual: |-\n'
100+
+ ' -0\n'
101+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
102+
+ ' stack: |-\n'
103+
+ ' Error: -0 notDeepLooseEqual to 0\n'
104+
+ ' [... stack stripped ...]\n'
105+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
106+
+ ' [... stack stripped ...]\n'
107+
+ ' ...\n'
108+
+ 'not ok 13 0 deepEqual to -0\n'
109+
+ ' ---\n'
110+
+ ' operator: deepEqual\n'
111+
+ ' expected: |-\n'
112+
+ ' -0\n'
113+
+ ' actual: |-\n'
114+
+ ' 0\n'
115+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
116+
+ ' stack: |-\n'
117+
+ ' Error: 0 deepEqual to -0\n'
118+
+ ' [... stack stripped ...]\n'
119+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
120+
+ ' [... stack stripped ...]\n'
121+
+ ' ...\n'
122+
+ 'not ok 14 -0 deepEqual to 0\n'
123+
+ ' ---\n'
124+
+ ' operator: deepEqual\n'
125+
+ ' expected: |-\n'
126+
+ ' 0\n'
127+
+ ' actual: |-\n'
128+
+ ' -0\n'
129+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
130+
+ ' stack: |-\n'
131+
+ ' Error: -0 deepEqual to 0\n'
132+
+ ' [... stack stripped ...]\n'
133+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
134+
+ ' [... stack stripped ...]\n'
135+
+ ' ...\n'
136+
+ 'ok 15 0 notDeepEqual to -0\n'
137+
+ 'ok 16 -0 notDeepEqual to 0\n'
138+
+ '# NaNs\n'
139+
+ 'not ok 17 NaN equal to NaN\n'
140+
+ ' ---\n'
141+
+ ' operator: equal\n'
142+
+ ' expected: NaN\n'
143+
+ ' actual: NaN\n'
144+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
145+
+ ' stack: |-\n'
146+
+ ' Error: NaN equal to NaN\n'
147+
+ ' [... stack stripped ...]\n'
148+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
149+
+ ' [... stack stripped ...]\n'
150+
+ ' ...\n'
151+
+ 'ok 18 NaN notEqual to NaN\n'
152+
+ 'not ok 19 NaN strictEqual to NaN\n'
153+
+ ' ---\n'
154+
+ ' operator: equal\n'
155+
+ ' expected: NaN\n'
156+
+ ' actual: NaN\n'
157+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
158+
+ ' stack: |-\n'
159+
+ ' Error: NaN strictEqual to NaN\n'
160+
+ ' [... stack stripped ...]\n'
161+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
162+
+ ' [... stack stripped ...]\n'
163+
+ ' ...\n'
164+
+ 'ok 20 NaN notStrictEqual to NaN\n'
165+
+ 'not ok 21 NaN deepLooseEqual to NaN\n'
166+
+ ' ---\n'
167+
+ ' operator: deepLooseEqual\n'
168+
+ ' expected: NaN\n'
169+
+ ' actual: NaN\n'
170+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
171+
+ ' stack: |-\n'
172+
+ ' Error: NaN deepLooseEqual to NaN\n'
173+
+ ' [... stack stripped ...]\n'
174+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
175+
+ ' [... stack stripped ...]\n'
176+
+ ' ...\n'
177+
+ 'ok 22 NaN notDeepLooseEqual to NaN\n'
178+
+ 'ok 23 NaN deepEqual to NaN\n'
179+
+ 'not ok 24 NaN notDeepEqual to NaN\n'
180+
+ ' ---\n'
181+
+ ' operator: notDeepEqual\n'
182+
+ ' expected: NaN\n'
183+
+ ' actual: NaN\n'
184+
+ ' at: Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
185+
+ ' stack: |-\n'
186+
+ ' Error: NaN notDeepEqual to NaN\n'
187+
+ ' [... stack stripped ...]\n'
188+
+ ' at Test.<anonymous> ($TEST/edge-cases.js:$LINE:$COL)\n'
189+
+ ' [... stack stripped ...]\n'
190+
+ ' ...\n'
191+
+ '\n1..24\n'
192+
+ '# tests 24\n'
193+
+ '# pass 12\n'
194+
+ '# fail 12\n'
195+
);
196+
}));
197+
198+
test('zeroes', function (t) {
199+
t.equal(0, -0, '0 equal to -0');
200+
t.equal(-0, 0, '-0 equal to 0');
201+
t.notEqual(0, -0, '0 notEqual to -0');
202+
t.notEqual(-0, 0, '-0 notEqual to 0');
203+
204+
t.strictEqual(0, -0, '0 strictEqual to -0');
205+
t.strictEqual(-0, 0, '-0 strictEqual to 0');
206+
t.notStrictEqual(0, -0, '0 notStrictEqual to -0');
207+
t.notStrictEqual(-0, 0, '-0 notStrictEqual to 0');
208+
209+
t.deepLooseEqual(0, -0, '0 deepLooseEqual to -0');
210+
t.deepLooseEqual(-0, 0, '-0 deepLooseEqual to 0');
211+
t.notDeepLooseEqual(0, -0, '0 notDeepLooseEqual to -0');
212+
t.notDeepLooseEqual(-0, 0, '-0 notDeepLooseEqual to 0');
213+
214+
t.deepEqual(0, -0, '0 deepEqual to -0');
215+
t.deepEqual(-0, 0, '-0 deepEqual to 0');
216+
t.notDeepEqual(0, -0, '0 notDeepEqual to -0');
217+
t.notDeepEqual(-0, 0, '-0 notDeepEqual to 0');
218+
219+
t.end();
220+
});
221+
222+
test('NaNs', function (t) {
223+
t.equal(NaN, NaN, 'NaN equal to NaN');
224+
t.notEqual(NaN, NaN, 'NaN notEqual to NaN');
225+
226+
t.strictEqual(NaN, NaN, 'NaN strictEqual to NaN');
227+
t.notStrictEqual(NaN, NaN, 'NaN notStrictEqual to NaN');
228+
229+
t.deepLooseEqual(NaN, NaN, 'NaN deepLooseEqual to NaN');
230+
t.notDeepLooseEqual(NaN, NaN, 'NaN notDeepLooseEqual to NaN');
231+
232+
t.deepEqual(NaN, NaN, 'NaN deepEqual to NaN');
233+
t.notDeepEqual(NaN, NaN, 'NaN notDeepEqual to NaN');
234+
235+
t.end();
236+
});
237+
});

‎test/numerics.js

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
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('numerics', function (tt) {
10+
tt.plan(1);
11+
12+
var test = tape.createHarness();
13+
test.createStream().pipe(concat(function (body) {
14+
tt.equal(
15+
stripFullStack(body.toString('utf8')),
16+
'TAP version 13\n'
17+
+ '# numeric strings\n'
18+
+ 'not ok 1 number equal to string\n'
19+
+ ' ---\n'
20+
+ ' operator: equal\n'
21+
+ ' expected: \'3\'\n'
22+
+ ' actual: 3\n'
23+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
24+
+ ' stack: |-\n'
25+
+ ' Error: number equal to string\n'
26+
+ ' [... stack stripped ...]\n'
27+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
28+
+ ' [... stack stripped ...]\n'
29+
+ ' ...\n'
30+
+ 'not ok 2 string equal to number\n'
31+
+ ' ---\n'
32+
+ ' operator: equal\n'
33+
+ ' expected: 3\n'
34+
+ ' actual: \'3\'\n'
35+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
36+
+ ' stack: |-\n'
37+
+ ' Error: string equal to number\n'
38+
+ ' [... stack stripped ...]\n'
39+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
40+
+ ' [... stack stripped ...]\n'
41+
+ ' ...\n'
42+
+ 'ok 3 number notEqual to string\n'
43+
+ 'ok 4 string notEqual to number\n'
44+
+ 'not ok 5 number strictEqual to string\n'
45+
+ ' ---\n'
46+
+ ' operator: equal\n'
47+
+ ' expected: \'3\'\n'
48+
+ ' actual: 3\n'
49+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
50+
+ ' stack: |-\n'
51+
+ ' Error: number strictEqual to string\n'
52+
+ ' [... stack stripped ...]\n'
53+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
54+
+ ' [... stack stripped ...]\n'
55+
+ ' ...\n'
56+
+ 'not ok 6 string strictEqual to number\n'
57+
+ ' ---\n'
58+
+ ' operator: equal\n'
59+
+ ' expected: 3\n'
60+
+ ' actual: \'3\'\n'
61+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
62+
+ ' stack: |-\n'
63+
+ ' Error: string strictEqual to number\n'
64+
+ ' [... stack stripped ...]\n'
65+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
66+
+ ' [... stack stripped ...]\n'
67+
+ ' ...\n'
68+
+ 'ok 7 number notStrictEqual to string\n'
69+
+ 'ok 8 string notStrictEqual to number\n'
70+
+ 'ok 9 number deepLooseEqual to string\n'
71+
+ 'ok 10 string deepLooseEqual to number\n'
72+
+ 'not ok 11 number notDeepLooseEqual to string\n'
73+
+ ' ---\n'
74+
+ ' operator: notDeepLooseEqual\n'
75+
+ ' expected: \'3\'\n'
76+
+ ' actual: 3\n'
77+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
78+
+ ' stack: |-\n'
79+
+ ' Error: number notDeepLooseEqual to string\n'
80+
+ ' [... stack stripped ...]\n'
81+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
82+
+ ' [... stack stripped ...]\n'
83+
+ ' ...\n'
84+
+ 'not ok 12 string notDeepLooseEqual to number\n'
85+
+ ' ---\n'
86+
+ ' operator: notDeepLooseEqual\n'
87+
+ ' expected: 3\n'
88+
+ ' actual: \'3\'\n'
89+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
90+
+ ' stack: |-\n'
91+
+ ' Error: string notDeepLooseEqual to number\n'
92+
+ ' [... stack stripped ...]\n'
93+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
94+
+ ' [... stack stripped ...]\n'
95+
+ ' ...\n'
96+
+ 'not ok 13 number deepEqual to string\n'
97+
+ ' ---\n'
98+
+ ' operator: deepEqual\n'
99+
+ ' expected: \'3\'\n'
100+
+ ' actual: 3\n'
101+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
102+
+ ' stack: |-\n'
103+
+ ' Error: number deepEqual to string\n'
104+
+ ' [... stack stripped ...]\n'
105+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
106+
+ ' [... stack stripped ...]\n'
107+
+ ' ...\n'
108+
+ 'not ok 14 string deepEqual to number\n'
109+
+ ' ---\n'
110+
+ ' operator: deepEqual\n'
111+
+ ' expected: 3\n'
112+
+ ' actual: \'3\'\n'
113+
+ ' at: Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
114+
+ ' stack: |-\n'
115+
+ ' Error: string deepEqual to number\n'
116+
+ ' [... stack stripped ...]\n'
117+
+ ' at Test.<anonymous> ($TEST/numerics.js:$LINE:$COL)\n'
118+
+ ' [... stack stripped ...]\n'
119+
+ ' ...\n'
120+
+ 'ok 15 number notDeepEqual to string\n'
121+
+ 'ok 16 string notDeepEqual to number\n'
122+
+ '\n1..16\n'
123+
+ '# tests 16\n'
124+
+ '# pass 8\n'
125+
+ '# fail 8\n'
126+
);
127+
}));
128+
129+
test('numeric strings', function (t) {
130+
t.equal(3, '3', 'number equal to string');
131+
t.equal('3', 3, 'string equal to number');
132+
t.notEqual(3, '3', 'number notEqual to string');
133+
t.notEqual('3', 3, 'string notEqual to number');
134+
135+
t.strictEqual(3, '3', 'number strictEqual to string');
136+
t.strictEqual('3', 3, 'string strictEqual to number');
137+
t.notStrictEqual(3, '3', 'number notStrictEqual to string');
138+
t.notStrictEqual('3', 3, 'string notStrictEqual to number');
139+
140+
t.deepLooseEqual(3, '3', 'number deepLooseEqual to string');
141+
t.deepLooseEqual('3', 3, 'string deepLooseEqual to number');
142+
t.notDeepLooseEqual(3, '3', 'number notDeepLooseEqual to string');
143+
t.notDeepLooseEqual('3', 3, 'string notDeepLooseEqual to number');
144+
145+
t.deepEqual(3, '3', 'number deepEqual to string');
146+
t.deepEqual('3', 3, 'string deepEqual to number');
147+
t.notDeepEqual(3, '3', 'number notDeepEqual to string');
148+
t.notDeepEqual('3', 3, 'string notDeepEqual to number');
149+
150+
t.end();
151+
});
152+
});

0 commit comments

Comments
 (0)
Please sign in to comment.