source: trip-planner-front/node_modules/deep-equal/test/cmp.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.7 KB
Line 
1var test = require('tape');
2require('./_tape');
3
4var equal = require('../');
5
6test('equal', function (t) {
7 t.deepEqualTest(
8 { a: [2, 3], b: [4] },
9 { a: [2, 3], b: [4] },
10 'two equal objects',
11 true,
12 true,
13 false
14 );
15 t.end();
16});
17
18test('not equal', function (t) {
19 t.deepEqualTest(
20 { x: 5, y: [6] },
21 { x: 5, y: 6 },
22 'two inequal objects are',
23 false,
24 false
25 );
26 t.end();
27});
28
29test('nested nulls', function (t) {
30 t.deepEqualTest(
31 [null, null, null],
32 [null, null, null],
33 'same-length arrays of nulls',
34 true,
35 true,
36 true
37 );
38 t.end();
39});
40
41test('objects with strings vs numbers', function (t) {
42 t.deepEqualTest(
43 [{ a: 3 }, { b: 4 }],
44 [{ a: '3' }, { b: '4' }],
45 'objects with equivalent string/number values',
46 true,
47 false
48 );
49 t.end();
50});
51
52test('non-objects', function (t) {
53 t.deepEqualTest(3, 3, 'same numbers', true, true, true);
54 t.deepEqualTest('beep', 'beep', 'same strings', true, true, true);
55 t.deepEqualTest('3', 3, 'numeric string and number', true, false);
56 t.deepEqualTest('3', [3], 'numeric string and array containing number', false, false);
57 t.deepEqualTest(3, [3], 'number and array containing number', false, false);
58
59 t.end();
60});
61
62test('infinities', function (t) {
63 t.deepEqualTest(Infinity, Infinity, '∞ and ∞', true, true, true);
64 t.deepEqualTest(-Infinity, -Infinity, '-∞ and -∞', true, true, true);
65 t.deepEqualTest(Infinity, -Infinity, '∞ and -∞', false, false);
66
67 t.end();
68});
69
70test('arguments class', function (t) {
71 function getArgs() {
72 return arguments;
73 }
74 t.ok(
75 equal(getArgs(1, 2, 3), getArgs(1, 2, 3)),
76 'equivalent arguments objects are equal'
77 );
78
79 t.deepEqualTest(
80 getArgs(1, 2, 3),
81 [1, 2, 3],
82 'array and arguments with same contents',
83 false,
84 false
85 );
86
87 t.end();
88});
89
90test('dates', function (t) {
91 var d0 = new Date(1387585278000);
92 var d1 = new Date('Fri Dec 20 2013 16:21:18 GMT-0800 (PST)');
93 t.deepEqualTest(d0, d1, 'equivalent Dates', true, true);
94 t.end();
95});
96
97test('buffers', function (t) {
98 /* eslint no-buffer-constructor: 1, new-cap: 1 */
99 t.ok(equal(Buffer('xyz'), Buffer('xyz')), 'buffers with same contents are equal');
100 t.ok(equal(Buffer('xyz'), Buffer('xyz'), { strict: true }), 'strict: buffers with same contents are equal');
101
102 t.deepEqualTest(
103 Buffer('abc'),
104 Buffer('xyz'),
105 'buffers with different contents',
106 false,
107 false
108 );
109
110 t.deepEqualTest(
111 Buffer(''),
112 [],
113 'empty buffer and empty array',
114 false,
115 false
116 );
117
118 t.end();
119});
120
121test('booleans and arrays', function (t) {
122 t.deepEqualTest(
123 true,
124 [],
125 'true and an empty array',
126 false,
127 false
128 );
129 t.deepEqualTest(
130 false,
131 [],
132 'false and an empty array',
133 true,
134 false
135 );
136 t.end();
137});
138
139test('arrays initiated', function (t) {
140 var a0 = [
141 undefined,
142 null,
143 -1,
144 0,
145 1,
146 false,
147 true,
148 undefined,
149 '',
150 'abc',
151 null,
152 undefined
153 ],
154 a1 = [
155 undefined,
156 null,
157 -1,
158 0,
159 1,
160 false,
161 true,
162 undefined,
163 '',
164 'abc',
165 null,
166 undefined
167 ];
168
169 t.ok(equal(a0, a1));
170 t.end();
171});
172
173// eslint-disable-next-line max-statements
174test('arrays assigned', function (t) {
175 var a0 = [
176 undefined,
177 null,
178 -1,
179 0,
180 1,
181 false,
182 true,
183 undefined,
184 '',
185 'abc',
186 null,
187 undefined
188 ];
189 var a1 = [];
190
191 a1[0] = undefined;
192 a1[1] = null;
193 a1[2] = -1;
194 a1[3] = 0;
195 a1[4] = 1;
196 a1[5] = false;
197 a1[6] = true;
198 a1[7] = undefined;
199 a1[8] = '';
200 a1[9] = 'abc';
201 a1[10] = null;
202 a1[11] = undefined;
203 a1.length = 12;
204
205 t.deepEqualTest(a0, a1, 'a literal array and an assigned array', true, true);
206 t.end();
207});
208
209// eslint-disable-next-line max-statements
210test('arrays push', function (t) {
211 var a0 = [
212 undefined,
213 null,
214 -1,
215 0,
216 1,
217 false,
218 true,
219 undefined,
220 '',
221 'abc',
222 null,
223 undefined
224 ],
225 a1 = [];
226
227 a1.push(undefined);
228 a1.push(null);
229 a1.push(-1);
230 a1.push(0);
231 a1.push(1);
232 a1.push(false);
233 a1.push(true);
234 a1.push(undefined);
235 a1.push('');
236 a1.push('abc');
237 a1.push(null);
238 a1.push(undefined);
239 a1.length = 12;
240
241 t.deepEqualTest(a0, a1, 'a literal array and a pushed array', true, true);
242 t.end();
243});
244
245test('null == undefined', function (t) {
246 t.deepEqualTest(null, undefined, 'null and undefined', true, false);
247
248 t.end();
249});
250
251test('NaNs', function (t) {
252 t.notOk(equal(NaN, NaN), 'NaN is not NaN');
253 t.ok(equal(NaN, NaN, { strict: true }), 'strict: NaN is NaN');
254
255 t.notOk(equal({ a: NaN }, { a: NaN }), 'two equiv objects with a NaN value are not equiv');
256 t.ok(equal({ a: NaN }, { a: NaN }, { strict: true }), 'strict: two equiv objects with a NaN value are equiv');
257
258 t.notOk(equal(NaN, 1), 'NaN !== 1');
259 t.notOk(equal(NaN, 1, { strict: true }), 'strict: NaN !== 1');
260
261 t.end();
262});
263
264test('zeroes', function (t) {
265 t.deepEqualTest(0, -0, '0 and -0', true, false);
266
267 t.deepEqualTest({ a: 0 }, { a: -0 }, 'two objects with a same-keyed 0/-0 value', true, false);
268
269 t.end();
270});
271
272test('Object.create', { skip: !Object.create }, function (t) {
273 var a = { a: 'A' };
274 var b = Object.create(a);
275 b.b = 'B';
276 var c = Object.create(a);
277 c.b = 'C';
278
279 t.deepEqualTest(
280 b,
281 c,
282 'two objects with the same [[Prototype]] but a different own property',
283 false,
284 false
285 );
286
287 t.end();
288});
289
290test('Object.create(null)', { skip: !Object.create }, function (t) {
291 t.deepEqualTest(
292 Object.create(null),
293 Object.create(null),
294 'two empty null objects',
295 true,
296 true,
297 true
298 );
299
300 t.deepEqualTest(
301 Object.create(null, { a: { value: 'b' } }),
302 Object.create(null, { a: { value: 'b' } }),
303 'two null objects with the same property pair',
304 true,
305 true,
306 true
307 );
308
309 t.end();
310});
311
312test('regexes vs dates', function (t) {
313 var d = new Date(1387585278000);
314 var r = /abc/;
315
316 t.deepEqualTest(d, r, 'Date and RegExp', false, false);
317
318 t.end();
319});
320
321test('regexen', function (t) {
322 t.deepEqualTest(/abc/, /xyz/, 'two different regexes', false, false);
323 t.deepEqualTest(/abc/, /abc/, 'two abc regexes', true, true, false);
324 t.deepEqualTest(/xyz/, /xyz/, 'two xyz regexes', true, true, false);
325
326 t.end();
327});
328
329test('arrays and objects', function (t) {
330 t.deepEqualTest([], {}, 'empty array and empty object', true, true);
331 t.deepEqualTest([], { length: 0 }, 'empty array and empty arraylike object', false, false);
332 t.deepEqualTest([1], { 0: 1 }, 'array and similar object', true, true);
333
334 t.end();
335});
336
337test('functions', function (t) {
338 function f() {}
339
340 t.deepEqualTest(f, f, 'a function and itself', true, true, true);
341 t.deepEqualTest(function () {}, function () {}, 'two distinct functions', false, false, true);
342
343 t.end();
344});
Note: See TracBrowser for help on using the repository browser.