-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.it.js
799 lines (709 loc) · 28.5 KB
/
test.it.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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
(function(scope) {
'use strict'
/** Context for printer strategies @constructor */
function printerFrom (strategy) {
this.print = strategy.print;
this.group = strategy.group;
this.test = strategy.test;
this.error = strategy.error;
}
function Testit () {
/** Printer object. It will be used for output results. */
var printer;
/** change default printer */
function _setPrinter(strategy) {
printer = new printerFrom(strategy);
};
/** get and set default printer */
this.printer = function (strategy) {
if (strategy) _setPrinter(strategy);
return printer;
}
/** group class @constructor */
function Group() {
this.type = 'group';
this.name = undefined;
this.status = undefined;
this.comment = undefined;
this.error = undefined;
this.time = 0;
this.result = {
pass: 0,
fail: 0,
error: 0,
total: 0
};
this.stack = [];
}
/** test class @constructor */
function Test() {
this.type = 'test';
this.status = undefined;
this.comment = undefined;
this.description = undefined;
this.error = undefined;
// this.time = new Date().getTime();
this.argument = [];
}
/** main group */
var root = new Group();
root.root = true;
root.name = 'root';
root.timestamp = new Date().getTime();
/** return root object */
function _returnRoot() {
return root;
}
this.getRoot = this.r = _returnRoot;
/** public interface for root @deprecated */
this.root = root;
/** make new instace of group, fill it, push it into stack of current level group */
function _makeGroup(name,fun,excluded) {
/** get timestamp */
var time = new Date().getTime();
/** var for the new instance of group */
var newgroup;
/** identify new group */
var groupAlreadyExist = false;
/** find group in current-level stack */
for (var i in this.stack) {
if (this.stack[i].type !== 'group') continue;
if (this.stack[i].name === name) {
newgroup = this.stack[i];
groupAlreadyExist = true;
break;
}
}
if (!groupAlreadyExist) newgroup = new Group();
newgroup.name = name;
/** add backlink to provide trace */
newgroup.linkBack = this;
/** set to pass as default. it's may be changed in some next lines */
var oldstatus;
if (groupAlreadyExist) oldstatus = newgroup.status;
newgroup.status ='pass';
/**
* try to execute fun() with tests and other groups in
* This part provides nesting.
* For this reason there are redefinition of root.
*/
var oldRoot = root;
root = newgroup;
try {
fun();
} catch(e) {
newgroup.status = 'error';
newgroup.error = generateError(e);
}
root = oldRoot;
/** update time */
newgroup.time += new Date().getTime() - time;
/** finally place this group into previous level stack (if it's a new group) */
if (!groupAlreadyExist && !excluded) this.stack.push(newgroup);
/** update counters */
updateCounters(newgroup);
/** return testit with link to this group */
return newgroup;
}
/** return group by it's name in stack of current level group */
function _getGroup(name) {
var stack = this.stack;
for (var i in stack) {
if (stack[i].type !== 'group') continue;
if (stack[i].name === name) {
return stack[i];
}
}
throw new ReferenceError('there is no group with name: '+name);
}
/* Interface for _makeGroup() and _getGroup() methods. */
function _group(name,fun) {
/**
* Here may be situations:
* this.link is root && root is root - test.group() called in root scope
* this.link is root && root is some group - test.group() called in some other group scope
* this.link is some group && root is root - .group() called in chain in root scope
* this.link is some group && root is some group - .group() called in chain in some other group scope
* look at it with:
* console.log(name,'\nlink: ',this.link,'\nroot: ',root);
*/
var currentLevel = (this.link)?this.link:root;
var linkToGroup;
switch (arguments.length) {
case 0 : throw new RangeError("test.group expect at least 1 argument");
case 1 : {
linkToGroup = _getGroup.call(currentLevel,name);
} break;
case 2 : {
linkToGroup = _makeGroup.call(currentLevel,name,fun,this.excluded);
} break;
default : throw new RangeError("test.group expect no more than 2 arguments");
}
/** get trace for this group */
var trace = getTrace();
return Object.create(this,{link:{value:linkToGroup},trace:{value:trace}});
};
this.group = _group;
/** Base for all tests. Make new instance of test, fill it using test-functions, push it into stack of current level group */
function _doTest(type,args) {
/** new instance of test */
var newtest = new Test();
/** fill newtest.agrument from method arguments */
for (var i in args) {
newtest.argument.push(args[i]);
}
/** execute test-function specified by type */
switch (type) {
case 'it' : _testIt(newtest); break;
case 'them' : _testThem(newtest); break;
case 'type' : _testType(newtest); break;
case 'types' : _testTypes(newtest); break;
case 'is' : _testIs(newtest); break;
case 'are' : _testAre(newtest); break;
}
/** calculate time, if .time was called before this test */
if (this.timestamp) newtest.time = new Date().getTime() - this.timestamp;
/** finally place this test into container stack */
if (!this.excluded) root.stack.push(newtest);
/** update counters of contained group */
updateCounters(root);
/** get trace for this test */
var trace = getTrace();
/** return testit with
* link to this test
* trace for this test
*/
return Object.create(this,{link:{value:newtest},trace:{value:trace}});
}
this.it = function(){return _doTest.call(this,'it',arguments)};
this.them = function(){return _doTest.call(this,'them',arguments)};
this.is = function(){return _doTest.call(this,'is',arguments)};
this.are = function(){return _doTest.call(this,'are',arguments)};
/** @deprecated */
this.type = function(){return _doTest.call(this,'type',arguments)};
/** @deprecated */
this.types = function(){return _doTest.call(this,'types',arguments)};
/** checks the argument for the true-like value */
function _testIt(testobj){
switch (testobj.argument.length) {
/** in case of no arguments - throw Reference error */
case 0 : {
testobj.status = 'error';
testobj.error = generateError(new RangeError("at least one argument expected"));
} break;
/** if there is only one argument - check it for truth */
case 1 : {
if (testobj.argument[0]) {
testobj.description = 'argument is true-like';
testobj.status = 'pass';
} else {
testobj.description = 'argument is false-like';
testobj.status = 'fail';
}
} break;
/** if there are two arguments - check equalence between them */
case 2 : {
if (typeOf(testobj.argument[0]) !== typeOf(testobj.argument[1])) {
testobj.description = 'argument hase different types';
testobj.status = 'fail';
} else if (deepCompare(testobj.argument[0],testobj.argument[1])) {
testobj.description = 'arguments are equal';
testobj.status = 'pass';
} else {
testobj.description = 'argument are not equal';
testobj.status = 'fail';
}
} break;
/** otherwise throw Range error */
default : {
testobj.status = 'error';
testobj.error = generateError(new RangeError("maximum of 2 arguments expected"));
}
}
}
/** checks array of values to be true-like */
function _testThem(testobj){
switch (testobj.argument.length) {
/** in case of no arguments - throw Reference error */
case 0 : {
testobj.status = 'error';
testobj.error = generateError(new RangeError("at least one argument expected"));
} break;
/** if there is only one argument - continue */
case 1 : {
/** if first argument is not an Array - throw TypeError */
if (typeOf(testobj.argument[0]) !== 'Array') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("argument should be an array"));
} else {
/** check elements of array to be true-like */
for (var i in testobj.argument[0]) {
if (!testobj.argument[0][i]) {
testobj.status = 'fail';
testobj.description = 'there are at least one false-like element';
}
}
/** test passed if there are no false-like elements found */
if (testobj.status !== 'fail') {
testobj.status = 'pass';
testobj.description = 'arguments are true-like';
}
}
} break;
/** otherwise throw Range error */
default : {
testobj.status = 'error';
testobj.error = generateError(new RangeError("maximum of 1 arguments expected"));
}
}
}
/**
* checks type of value to be equal to specified
* @deprecated use test.is instead
*/
function _testType(testobj) {
if (testobj.argument.length!==2) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("expect two arguments"));
} else if (typeOf(testobj.argument[1]) !== 'String') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a String"));
} else if (!arrayConsist(identifiedTypes,testobj.argument[1].toLowerCase())) {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a standart type"));
} else {
testobj.description = 'type of argument is ';
if (typeOf(testobj.argument[0]).toLowerCase() !== testobj.argument[1].toLowerCase()) {
testobj.description += 'not '+testobj.argument[1];
testobj.status = 'fail';
} else {
testobj.description += typeOf(testobj.argument[0]);
testobj.status = 'pass';
}
}
}
/**
* checks types of elements in array to be equal to specified and between each other
* @deprecated use test.are instead
*/
function _testTypes(testobj) {
if (testobj.argument.length==0) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("at least one argument expected"));
} else if (testobj.argument.length>2) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("maximum of two arguments expected"));
} else if (typeOf(testobj.argument[0]) !== 'Array') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("first argument should be an array"));
} else {
var type, types;
if (typeOf(testobj.argument[1]) === 'undefined') {
type = typeOf(testobj.argument[0][0]);
types = 'same';
} else if (typeOf(testobj.argument[1]) !== 'String') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a String"));
} else if (!arrayConsist(identifiedTypes,testobj.argument[1].toLowerCase())) {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a standart type"));
} else {
type = testobj.argument[1];
types = 'right';
}
if (testobj.status !== 'error') {
type = type.toLowerCase();
for (var i in testobj.argument[0]) {
if (typeOf(testobj.argument[0][i]).toLowerCase() !== type) {
testobj.status = 'fail';
testobj.description = 'There are at least one element with different type';
}
}
if (testobj.status !== 'fail') {
testobj.status = 'pass';
testobj.description = 'arguments are '+types+' type';
}
}
}
}
/** checks constructor of value to be equal to specified */
function _testIs(testobj) {
if (testobj.argument.length!==2) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("expect two arguments"));
} else if (typeOf(testobj.argument[1]) !== 'Function') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a constructor (function)"));
} else {
if (testobj.argument[1].name=='') {
testobj.description = 'argument has ';
if (testobj.argument[0].constructor !== testobj.argument[1]) {
testobj.description += 'wrong';
testobj.status = 'fail';
} else {
testobj.description += 'right';
testobj.status = 'pass';
}
testobj.description += ' constructor';
} else {
testobj.description = 'argument is ';
if (testobj.argument[0].constructor !== testobj.argument[1]) {
testobj.description += 'not '+testobj.argument[1].name;
testobj.status = 'fail';
} else {
testobj.description += testobj.argument[1].name;
testobj.status = 'pass';
}
}
}
}
/** checks constructors of elements in array to be equal to specified and between each other */
function _testAre(testobj) {
if (testobj.argument.length==0) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("at least one argument expected"));
} else if (testobj.argument.length>2) {
testobj.status = 'error';
testobj.error = generateError(new RangeError("maximum of two arguments expected"));
} else if (typeOf(testobj.argument[0]) !== 'Array') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("first argument should be an array"));
} else {
var constructor, constructors;
if (typeOf(testobj.argument[1]) === 'undefined') {
constructor = testobj.argument[0][0].constructor;
constructors = 'same';
} else if (typeOf(testobj.argument[1]) !== 'Function') {
testobj.status = 'error';
testobj.error = generateError(new TypeError("second argument should be a constructor (function)"));
} else {
constructor = testobj.argument[1];
constructors = 'right';
}
if (testobj.status !== 'error') {
for (var i in testobj.argument[0]) {
if (testobj.argument[0][i].constructor !== constructor) {
testobj.status = 'fail';
var num = 1 +parseInt(i);
testobj.description = 'There are at least one ('+num+') element with different constructor';
}
}
if (testobj.status !== 'fail') {
testobj.status = 'pass';
if (typeof testobj.argument[1]!=='undefined') {
testobj.description = 'arguments '+(testobj.argument[1].name!=='undefined')?'are '+testobj.argument[1].name:'has same constructor';
} else {
testobj.description = 'arguments has same constructor';
}
}
}
}
};
/** adds the time spent on test, into his result */
function _addTime () {
return Object.create(this,{timestamp:{value:new Date().getTime()}});
};
this.addTime = _addTime;
/**
* Old time attribute. It has bug! Do not use it!
* @deprecated
*/
this.time = Object.create(this,{timestamp:{value:new Date().getTime()}});
/** makes test/group unpushable into stack of current level group */
this.exclude = this.x = Object.create(this,{excluded:{value:true}});
/** add a comment for the linked test or group */
function _comment(text) {
/** add a comment, if there is something can be commented */
if (!this.link) throw new ReferenceError('comment can only be used in testit chain');
this.link.comment = text;
return this;
};
this.comment = _comment;
/** try to execute functions in arguments depending on test|group result */
function _callback(pass,fail,error) {
if (!this.link) throw new ReferenceError('callback can only be used in testit chain');
if (this.link.status === 'pass' && typeOf(pass) === 'Function' ) try {pass();} catch(e) {throw e;}
if (this.link.status === 'fail' && typeOf(fail) === 'Function' ) try {fail();} catch(e) {throw e;}
if (this.link.status === 'error' && typeOf(error) === 'Function' ) try {error();} catch(e) {throw e;}
return this;
};
this.callback = _callback;
/** add stack trace to test/group */
function _addTrace(level) {
if (!this.link) throw new ReferenceError('addTrace can only be used in testit chain');
if (this.trace) {
var trace = this.trace;
if (typeOf(level) === 'Number') trace = trace.split('\n').slice(0,level+1).join('\n');
this.link.trace = trace;
}
return this;
};
this.addTrace = _addTrace;
/** Final chain-link: returns result of test or group */
function _result() {
if (this.link) {
return (this.link.status == 'pass')? true : false;
} else {
return (root.status == 'pass')? true : false;
}
return undefined;
};
this.result = _result;
/** Final chain-link: returns arguments of test (not of group!) */
function _arguments() {
if (this.link) {
if (this.link.type!=='test') return TypeError('groups don\'t return arguments');
switch (this.link.argument.length) {
case 0 : return undefined
case 1 : return this.link.argument[0];
default : return this.link.argument;
}
}
return undefined;
};
this.arguments = _arguments;
/** output something into default or specified printer */
function _print (newPrinter) {
var entity = (this.link)?this.link:root;
if (newPrinter) (new printerFrom(newPrinter)).print(entity)
else if (printer) printer.print(entity)
else return false;
return true;
};
this.print = _print;
/** @deprecated */
this.done = _print;
/** update counters of contained object */
function updateCounters(link) {
link.result = {
pass: 0,
fail: 0,
error: 0,
total: 0
};
for (var i in link.stack) {
link.result.total++;
switch (link.stack[i].status) {
case 'pass' : {
link.result.pass++;
} break;
case 'fail' : {
link.result.fail++;
} break;
case 'error' : {
link.result.error++;
} break;
};
};
if (link.result.error || link.error) {link.status='error'}
else if (link.result.fail) {link.status='fail'}
else {link.status='pass'}
if (link.root) {
link.time = new Date().getTime() - link.timestamp;
}
if (link.linkBack) {
updateCounters(link.linkBack);
}
}
/** public interface for typeOf */
this.typeof = typeOf;
/** public interface for getTrace(error) */
this.trace = getTrace;
// return this;
return this;
}
/** determinates type of argument. More powerfull then typeof(). */
function typeOf (argument) {
var type;
try {
switch (argument.constructor) {
case Array : type='Array';break;
case Boolean : type='Boolean';break;
case Date : type='Date';break;
case Error : type='Error';break;
case EvalError : type='EvalError';break;
case Function : type='Function';break;
case Number : {type=(isNaN(argument))?'NaN':'Number';}break;
case Object : type='Object';break;
case RangeError : type='RangeError';break;
case ReferenceError : type='ReferenceError';break;
case RegExp : type='RegExp';break;
case String : type='String';break;
case SyntaxError : type='SyntaxError';break;
case TypeError : type='TypeError';break;
case URIError : type='URIError';break;
case Window : type='Window';break;
case HTMLDocument : type='HTML';break;
case NodeList : type='NodeList';break;
default : {
if (typeof argument === 'object'
&& argument.toString().indexOf('HTML') !== -1) {
type = 'HTML';
} else {
type = undefined;
}
}
}
} catch (e) {
type = (argument === null)? 'null' : typeof argument;
}
return type;
}
/** list of types, which can be identified by typeOf */
var identifiedTypes = ['array', 'boolean', 'date', 'error', 'evalerror', 'function', 'html', 'nan', 'nodelist', 'null', 'number', 'object', 'rangeerror', 'referenceerror', 'regexp', 'string', 'syntaxerror', 'typeerror', 'urierror', 'window'];
/**
* figure out what status will be used
* Depends on significance: More significant -> less significant.
* error -> fail -> pass -> undefined
*/
function updateStatus(oldstatus,newstatus) {
if (oldstatus===undefined) return newstatus;
if (newstatus===undefined) return oldstatus;
if (oldstatus==='error' || newstatus==='error') return 'error';
if (oldstatus==='fail' || newstatus==='fail') return 'fail';
return 'pass';
}
/** make the error object more clear and returns it */
function generateError(error) {
/** understandable error object */
var object = {
error: error
,type: typeOf(error)
,message: error.message
}
if (getTrace(error)) object.stack = getTrace(error);
return object;
}
/** returns a list of functions that have been performed to call the current line */
function getTrace(error) {
if (!error) error = new Error();
if (!error.stack) return;
var stack = '';
error.stack.split(/[\n]/).forEach(function(i,n){
var addToStack = true;
/** take off empty strings (FireBug) */
if (i==='') addToStack = false;
/** take off Errors (Chrome) */
if (i.indexOf(typeOf(error))!==-1) addToStack = false;
/** take off any references to testit files */
if (i.indexOf('test.it.js')!==-1 ||
i.indexOf('test.it.min.js')!==-1) addToStack = false;
/** take of reference to this function */
if (i.indexOf('getTrace')!==-1) addToStack = false;
/** fill the stack */
if (addToStack) {
stack += (stack)?'\n':'';
stack += i.replace(/((\s+at\s+)|(^@))/,'');
}
})
return stack;
}
/** finds val in array */
function arrayConsist(array, val) {
for (var i in array) if (array[i] === val) return true;
return false;
}
/**
* Compares any type of variables
* @return {Boolean} result of comparison
* {@link http://stackoverflow.com/a/1144249/1771942}
*/
function deepCompare() {
var leftChain, rightChain;
function compare2Objects(x, y) {
var p;
// remember that NaN === NaN returns false
// and isNaN(undefined) returns true
if (isNaN(x) && isNaN(y) && typeof x === 'number' && typeof y === 'number') {
return true;
}
// Compare primitives and functions.
// Check if both arguments link to the same object.
// Especially useful on step when comparing prototypes
if (x === y) {
return true;
}
// Works in case when functions are created in constructor.
// Comparing dates is a common scenario. Another built-ins?
// We can even handle functions passed across iframes
if ((typeof x === 'function' && typeof y === 'function') ||
(x instanceof Date && y instanceof Date) ||
(x instanceof RegExp && y instanceof RegExp) ||
(x instanceof String && y instanceof String) ||
(x instanceof Number && y instanceof Number)) {
return x.toString() === y.toString();
}
// Compare jQuery objects
if ((typeof window !== 'undefined') && (window.jQuery || false) && ((x instanceof jQuery) && (y instanceof jQuery))) {
return x.is(y);
}
// At last checking prototypes as good a we can
if (!(x instanceof Object && y instanceof Object)) {
return false;
}
if (x.isPrototypeOf(y) || y.isPrototypeOf(x)) {
return false;
}
if (x.constructor !== y.constructor) {
return false;
}
if (x.prototype !== y.prototype) {
return false;
}
// check for infinitive linking loops
if (leftChain.indexOf(x) > -1 || rightChain.indexOf(y) > -1) {
return false;
}
// Quick checking of one object being a subset of another.
for (p in y) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
}
else if (typeof y[p] !== typeof x[p]) {
return false;
}
}
for (p in x) {
if (y.hasOwnProperty(p) !== x.hasOwnProperty(p)) {
return false;
}
else if (typeof y[p] !== typeof x[p]) {
return false;
}
switch (typeof (x[p])) {
case 'object':
case 'function':
leftChain.push(x);
rightChain.push(y);
if (!compare2Objects(x[p], y[p])) {
return false;
}
leftChain.pop();
rightChain.pop();
break;
default:
if (x[p] !== y[p]) {
return false;
}
break;
}
}
return true;
}
if (arguments.length < 1) {
return true; //Die silently? Don't know how to handle such case, please help...
// throw "Need two or more arguments to compare";
}
for (var i = 1, l = arguments.length; i < l; i++) {
leftChain = [];
rightChain = [];
if (!compare2Objects(arguments[0], arguments[i])) {
return false;
}
}
return true;
}
/** new instance of testit, availible from outside. */
if (typeof module !== 'undefined' && module.exports) module.exports = new Testit();
else scope.test = new Testit();
})(this);