mocha_rails 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1990 @@
|
|
1
|
+
!function (name, definition) {
|
2
|
+
if (typeof define == 'function' && typeof define.amd == 'object') define(definition);
|
3
|
+
else this[name] = definition();
|
4
|
+
}('chai', function () {
|
5
|
+
|
6
|
+
// CommonJS require()
|
7
|
+
|
8
|
+
function require(p){
|
9
|
+
var path = require.resolve(p)
|
10
|
+
, mod = require.modules[path];
|
11
|
+
if (!mod) throw new Error('failed to require "' + p + '"');
|
12
|
+
if (!mod.exports) {
|
13
|
+
mod.exports = {};
|
14
|
+
mod.call(mod.exports, mod, mod.exports, require.relative(path));
|
15
|
+
}
|
16
|
+
return mod.exports;
|
17
|
+
}
|
18
|
+
|
19
|
+
require.modules = {};
|
20
|
+
|
21
|
+
require.resolve = function (path){
|
22
|
+
var orig = path
|
23
|
+
, reg = path + '.js'
|
24
|
+
, index = path + '/index.js';
|
25
|
+
return require.modules[reg] && reg
|
26
|
+
|| require.modules[index] && index
|
27
|
+
|| orig;
|
28
|
+
};
|
29
|
+
|
30
|
+
require.register = function (path, fn){
|
31
|
+
require.modules[path] = fn;
|
32
|
+
};
|
33
|
+
|
34
|
+
require.relative = function (parent) {
|
35
|
+
return function(p){
|
36
|
+
if ('.' != p[0]) return require(p);
|
37
|
+
|
38
|
+
var path = parent.split('/')
|
39
|
+
, segs = p.split('/');
|
40
|
+
path.pop();
|
41
|
+
|
42
|
+
for (var i = 0; i < segs.length; i++) {
|
43
|
+
var seg = segs[i];
|
44
|
+
if ('..' == seg) path.pop();
|
45
|
+
else if ('.' != seg) path.push(seg);
|
46
|
+
}
|
47
|
+
|
48
|
+
return require(path.join('/'));
|
49
|
+
};
|
50
|
+
};
|
51
|
+
|
52
|
+
|
53
|
+
require.register("assertion.js", function(module, exports, require){
|
54
|
+
/*!
|
55
|
+
* chai
|
56
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
57
|
+
* MIT Licensed
|
58
|
+
*
|
59
|
+
* Primarily a refactor of: should.js
|
60
|
+
* https://github.com/visionmedia/should.js
|
61
|
+
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
|
62
|
+
* MIT Licensed
|
63
|
+
*/
|
64
|
+
|
65
|
+
/**
|
66
|
+
* ### BDD Style Introduction
|
67
|
+
*
|
68
|
+
* The BDD style is exposed through `expect` or `should` interfaces. In both
|
69
|
+
* scenarios, you chain together natural language assertions.
|
70
|
+
*
|
71
|
+
* // expect
|
72
|
+
* var expect = require('chai').expect;
|
73
|
+
* expect(foo).to.equal('bar');
|
74
|
+
*
|
75
|
+
* // should
|
76
|
+
* var should = require('chai').should();
|
77
|
+
* foo.should.equal('bar');
|
78
|
+
*
|
79
|
+
* #### Differences
|
80
|
+
*
|
81
|
+
* The `expect` interface provides a function as a starting point for chaining
|
82
|
+
* your language assertions. It works on both node.js and in the browser.
|
83
|
+
*
|
84
|
+
* The `should` interface extends `Object.prototype` to provide a single getter as
|
85
|
+
* the starting point for your language assertions. Most browser don't like
|
86
|
+
* extensions to `Object.prototype` so it is not recommended for browser use.
|
87
|
+
*/
|
88
|
+
|
89
|
+
/*!
|
90
|
+
* Module dependencies.
|
91
|
+
*/
|
92
|
+
|
93
|
+
var AssertionError = require('./error')
|
94
|
+
, eql = require('./utils/eql')
|
95
|
+
, inspect = require('./utils/inspect');
|
96
|
+
|
97
|
+
/*!
|
98
|
+
* Module export.
|
99
|
+
*/
|
100
|
+
|
101
|
+
module.exports = Assertion;
|
102
|
+
|
103
|
+
/*!
|
104
|
+
* # Assertion Constructor
|
105
|
+
*
|
106
|
+
* Creates object for chaining.
|
107
|
+
*
|
108
|
+
* @api private
|
109
|
+
*/
|
110
|
+
|
111
|
+
function Assertion (obj, msg, stack) {
|
112
|
+
this.ssfi = stack || arguments.callee;
|
113
|
+
this.obj = obj;
|
114
|
+
this.msg = msg;
|
115
|
+
}
|
116
|
+
|
117
|
+
/*!
|
118
|
+
* # .assert(expression, message, negateMessage)
|
119
|
+
*
|
120
|
+
* Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
|
121
|
+
*
|
122
|
+
* @name assert
|
123
|
+
* @param {Philosophical} expression to be tested
|
124
|
+
* @param {String} message to display if fails
|
125
|
+
* @param {String} negatedMessage to display if negated expression fails
|
126
|
+
* @api privage
|
127
|
+
*/
|
128
|
+
|
129
|
+
Assertion.prototype.assert = function (expr, msg, negateMsg) {
|
130
|
+
var msg = (this.negate ? negateMsg : msg)
|
131
|
+
, ok = this.negate ? !expr : expr;
|
132
|
+
|
133
|
+
if (!ok) {
|
134
|
+
throw new AssertionError({
|
135
|
+
operator: this.msg,
|
136
|
+
message: msg,
|
137
|
+
stackStartFunction: this.ssfi
|
138
|
+
});
|
139
|
+
}
|
140
|
+
};
|
141
|
+
|
142
|
+
/*!
|
143
|
+
* # inspect
|
144
|
+
*
|
145
|
+
* Returns the current object stringified.
|
146
|
+
*
|
147
|
+
* @name inspect
|
148
|
+
* @api private
|
149
|
+
*/
|
150
|
+
|
151
|
+
Object.defineProperty(Assertion.prototype, 'inspect',
|
152
|
+
{ get: function () {
|
153
|
+
return inspect(this.obj);
|
154
|
+
}
|
155
|
+
});
|
156
|
+
|
157
|
+
/**
|
158
|
+
* # to
|
159
|
+
*
|
160
|
+
* Language chain.
|
161
|
+
*
|
162
|
+
* @name to
|
163
|
+
* @api public
|
164
|
+
*/
|
165
|
+
|
166
|
+
Object.defineProperty(Assertion.prototype, 'to',
|
167
|
+
{ get: function () {
|
168
|
+
return this;
|
169
|
+
}
|
170
|
+
});
|
171
|
+
|
172
|
+
/**
|
173
|
+
* # be
|
174
|
+
*
|
175
|
+
* Language chain.
|
176
|
+
*
|
177
|
+
* @name be
|
178
|
+
* @api public
|
179
|
+
*/
|
180
|
+
|
181
|
+
Object.defineProperty(Assertion.prototype, 'be',
|
182
|
+
{ get: function () {
|
183
|
+
return this;
|
184
|
+
}
|
185
|
+
});
|
186
|
+
|
187
|
+
/**
|
188
|
+
* # been
|
189
|
+
*
|
190
|
+
* Language chain. Also tests `tense` to past for addon
|
191
|
+
* modules that use the tense feature.
|
192
|
+
*
|
193
|
+
* @name been
|
194
|
+
* @api public
|
195
|
+
*/
|
196
|
+
|
197
|
+
Object.defineProperty(Assertion.prototype, 'been',
|
198
|
+
{ get: function () {
|
199
|
+
this.tense = 'past';
|
200
|
+
return this;
|
201
|
+
}
|
202
|
+
});
|
203
|
+
|
204
|
+
/**
|
205
|
+
* # an
|
206
|
+
*
|
207
|
+
* Language chain.
|
208
|
+
*
|
209
|
+
* @name an
|
210
|
+
* @api public
|
211
|
+
*/
|
212
|
+
|
213
|
+
Object.defineProperty(Assertion.prototype, 'an',
|
214
|
+
{ get: function () {
|
215
|
+
return this;
|
216
|
+
}
|
217
|
+
});
|
218
|
+
/**
|
219
|
+
* # is
|
220
|
+
*
|
221
|
+
* Language chain.
|
222
|
+
*
|
223
|
+
* @name is
|
224
|
+
* @api public
|
225
|
+
*/
|
226
|
+
|
227
|
+
Object.defineProperty(Assertion.prototype, 'is',
|
228
|
+
{ get: function () {
|
229
|
+
return this;
|
230
|
+
}
|
231
|
+
});
|
232
|
+
|
233
|
+
/**
|
234
|
+
* # and
|
235
|
+
*
|
236
|
+
* Language chain.
|
237
|
+
*
|
238
|
+
* @name and
|
239
|
+
* @api public
|
240
|
+
*/
|
241
|
+
|
242
|
+
Object.defineProperty(Assertion.prototype, 'and',
|
243
|
+
{ get: function () {
|
244
|
+
return this;
|
245
|
+
}
|
246
|
+
});
|
247
|
+
|
248
|
+
/**
|
249
|
+
* # have
|
250
|
+
*
|
251
|
+
* Language chain.
|
252
|
+
*
|
253
|
+
* @name have
|
254
|
+
* @api public
|
255
|
+
*/
|
256
|
+
|
257
|
+
Object.defineProperty(Assertion.prototype, 'have',
|
258
|
+
{ get: function () {
|
259
|
+
return this;
|
260
|
+
}
|
261
|
+
});
|
262
|
+
|
263
|
+
/**
|
264
|
+
* # with
|
265
|
+
*
|
266
|
+
* Language chain.
|
267
|
+
*
|
268
|
+
* @name with
|
269
|
+
* @api public
|
270
|
+
*/
|
271
|
+
|
272
|
+
Object.defineProperty(Assertion.prototype, 'with',
|
273
|
+
{ get: function () {
|
274
|
+
return this;
|
275
|
+
}
|
276
|
+
});
|
277
|
+
|
278
|
+
/**
|
279
|
+
* # .not
|
280
|
+
*
|
281
|
+
* Negates any of assertions following in the chain.
|
282
|
+
*
|
283
|
+
* @name not
|
284
|
+
* @api public
|
285
|
+
*/
|
286
|
+
|
287
|
+
Object.defineProperty(Assertion.prototype, 'not',
|
288
|
+
{ get: function () {
|
289
|
+
this.negate = true;
|
290
|
+
return this;
|
291
|
+
}
|
292
|
+
});
|
293
|
+
|
294
|
+
/**
|
295
|
+
* # .ok
|
296
|
+
*
|
297
|
+
* Assert object truthiness.
|
298
|
+
*
|
299
|
+
* expect('everthing').to.be.ok;
|
300
|
+
* expect(false).to.not.be.ok;
|
301
|
+
* expect(undefined).to.not.be.ok;
|
302
|
+
* expect(null).to.not.be.ok;
|
303
|
+
*
|
304
|
+
* @name ok
|
305
|
+
* @api public
|
306
|
+
*/
|
307
|
+
|
308
|
+
Object.defineProperty(Assertion.prototype, 'ok',
|
309
|
+
{ get: function () {
|
310
|
+
this.assert(
|
311
|
+
this.obj
|
312
|
+
, 'expected ' + this.inspect + ' to be truthy'
|
313
|
+
, 'expected ' + this.inspect + ' to be falsey');
|
314
|
+
|
315
|
+
return this;
|
316
|
+
}
|
317
|
+
});
|
318
|
+
|
319
|
+
/**
|
320
|
+
* # .true
|
321
|
+
*
|
322
|
+
* Assert object is true
|
323
|
+
*
|
324
|
+
* @name true
|
325
|
+
* @api public
|
326
|
+
*/
|
327
|
+
|
328
|
+
Object.defineProperty(Assertion.prototype, 'true',
|
329
|
+
{ get: function () {
|
330
|
+
this.assert(
|
331
|
+
true === this.obj
|
332
|
+
, 'expected ' + this.inspect + ' to be true'
|
333
|
+
, 'expected ' + this.inspect + ' to be false');
|
334
|
+
|
335
|
+
return this;
|
336
|
+
}
|
337
|
+
});
|
338
|
+
|
339
|
+
/**
|
340
|
+
* # .false
|
341
|
+
*
|
342
|
+
* Assert object is false
|
343
|
+
*
|
344
|
+
* @name false
|
345
|
+
* @api public
|
346
|
+
*/
|
347
|
+
|
348
|
+
Object.defineProperty(Assertion.prototype, 'false',
|
349
|
+
{ get: function () {
|
350
|
+
this.assert(
|
351
|
+
false === this.obj
|
352
|
+
, 'expected ' + this.inspect + ' to be false'
|
353
|
+
, 'expected ' + this.inspect + ' to be true');
|
354
|
+
|
355
|
+
return this;
|
356
|
+
}
|
357
|
+
});
|
358
|
+
|
359
|
+
/**
|
360
|
+
* # .exist
|
361
|
+
*
|
362
|
+
* Assert object exists (null).
|
363
|
+
*
|
364
|
+
* var foo = 'hi'
|
365
|
+
* , bar;
|
366
|
+
* expect(foo).to.exist;
|
367
|
+
* expect(bar).to.not.exist;
|
368
|
+
*
|
369
|
+
* @name exist
|
370
|
+
* @api public
|
371
|
+
*/
|
372
|
+
|
373
|
+
Object.defineProperty(Assertion.prototype, 'exist',
|
374
|
+
{ get: function () {
|
375
|
+
this.assert(
|
376
|
+
null != this.obj
|
377
|
+
, 'expected ' + this.inspect + ' to exist'
|
378
|
+
, 'expected ' + this.inspect + ' to not exist');
|
379
|
+
|
380
|
+
return this;
|
381
|
+
}
|
382
|
+
});
|
383
|
+
|
384
|
+
/**
|
385
|
+
* # .empty
|
386
|
+
*
|
387
|
+
* Assert object's length to be 0.
|
388
|
+
*
|
389
|
+
* expect([]).to.be.empty;
|
390
|
+
*
|
391
|
+
* @name empty
|
392
|
+
* @api public
|
393
|
+
*/
|
394
|
+
|
395
|
+
Object.defineProperty(Assertion.prototype, 'empty',
|
396
|
+
{ get: function () {
|
397
|
+
new Assertion(this.obj).to.have.property('length');
|
398
|
+
|
399
|
+
this.assert(
|
400
|
+
0 === this.obj.length
|
401
|
+
, 'expected ' + this.inspect + ' to be empty'
|
402
|
+
, 'expected ' + this.inspect + ' not to be empty');
|
403
|
+
|
404
|
+
return this;
|
405
|
+
}
|
406
|
+
});
|
407
|
+
|
408
|
+
/**
|
409
|
+
* # .arguments
|
410
|
+
*
|
411
|
+
* Assert object is an instanceof arguments.
|
412
|
+
*
|
413
|
+
* function test () {
|
414
|
+
* expect(arguments).to.be.arguments;
|
415
|
+
* }
|
416
|
+
*
|
417
|
+
* @name arguments
|
418
|
+
* @api public
|
419
|
+
*/
|
420
|
+
|
421
|
+
Object.defineProperty(Assertion.prototype, 'arguments',
|
422
|
+
{ get: function () {
|
423
|
+
this.assert(
|
424
|
+
'[object Arguments]' == Object.prototype.toString.call(this.obj)
|
425
|
+
, 'expected ' + this.inspect + ' to be arguments'
|
426
|
+
, 'expected ' + this.inspect + ' to not be arguments');
|
427
|
+
|
428
|
+
return this;
|
429
|
+
}
|
430
|
+
});
|
431
|
+
|
432
|
+
/**
|
433
|
+
* # .equal(value)
|
434
|
+
*
|
435
|
+
* Assert strict equality.
|
436
|
+
*
|
437
|
+
* expect('hello').to.equal('hello');
|
438
|
+
*
|
439
|
+
* @name equal
|
440
|
+
* @param {*} value
|
441
|
+
* @api public
|
442
|
+
*/
|
443
|
+
|
444
|
+
Assertion.prototype.equal = function (val) {
|
445
|
+
this.assert(
|
446
|
+
val === this.obj
|
447
|
+
, 'expected ' + this.inspect + ' to equal ' + inspect(val)
|
448
|
+
, 'expected ' + this.inspect + ' to not equal ' + inspect(val));
|
449
|
+
|
450
|
+
return this;
|
451
|
+
};
|
452
|
+
|
453
|
+
/**
|
454
|
+
* # .eql(value)
|
455
|
+
*
|
456
|
+
* Assert deep equality.
|
457
|
+
*
|
458
|
+
* expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
|
459
|
+
*
|
460
|
+
* @name eql
|
461
|
+
* @param {*} value
|
462
|
+
* @api public
|
463
|
+
*/
|
464
|
+
|
465
|
+
Assertion.prototype.eql = function (obj) {
|
466
|
+
this.assert(
|
467
|
+
eql(obj, this.obj)
|
468
|
+
, 'expected ' + this.inspect + ' to equal ' + inspect(obj)
|
469
|
+
, 'expected ' + this.inspect + ' to not equal ' + inspect(obj));
|
470
|
+
return this;
|
471
|
+
};
|
472
|
+
|
473
|
+
/**
|
474
|
+
* # .above(value)
|
475
|
+
*
|
476
|
+
* Assert greater than `value`.
|
477
|
+
*
|
478
|
+
* expect(10).to.be.above(5);
|
479
|
+
*
|
480
|
+
* @name above
|
481
|
+
* @param {Number} value
|
482
|
+
* @api public
|
483
|
+
*/
|
484
|
+
|
485
|
+
Assertion.prototype.above = function (val) {
|
486
|
+
this.assert(
|
487
|
+
this.obj > val
|
488
|
+
, 'expected ' + this.inspect + ' to be above ' + val
|
489
|
+
, 'expected ' + this.inspect + ' to be below ' + val);
|
490
|
+
|
491
|
+
return this;
|
492
|
+
};
|
493
|
+
|
494
|
+
/**
|
495
|
+
* # .below(value)
|
496
|
+
*
|
497
|
+
* Assert less than `value`.
|
498
|
+
*
|
499
|
+
* expect(5).to.be.below(10);
|
500
|
+
*
|
501
|
+
* @name below
|
502
|
+
* @param {Number} value
|
503
|
+
* @api public
|
504
|
+
*/
|
505
|
+
|
506
|
+
Assertion.prototype.below = function (val) {
|
507
|
+
this.assert(
|
508
|
+
this.obj < val
|
509
|
+
, 'expected ' + this.inspect + ' to be below ' + val
|
510
|
+
, 'expected ' + this.inspect + ' to be above ' + val);
|
511
|
+
|
512
|
+
return this;
|
513
|
+
};
|
514
|
+
|
515
|
+
/**
|
516
|
+
* # .within(start, finish)
|
517
|
+
*
|
518
|
+
* Assert that a number is within a range.
|
519
|
+
*
|
520
|
+
* expect(7).to.be.within(5,10);
|
521
|
+
*
|
522
|
+
* @name within
|
523
|
+
* @param {Number} start lowerbound inclusive
|
524
|
+
* @param {Number} finish upperbound inclusive
|
525
|
+
* @api public
|
526
|
+
*/
|
527
|
+
|
528
|
+
Assertion.prototype.within = function (start, finish) {
|
529
|
+
var range = start + '..' + finish;
|
530
|
+
|
531
|
+
this.assert(
|
532
|
+
this.obj >= start && this.obj <= finish
|
533
|
+
, 'expected ' + this.inspect + ' to be within ' + range
|
534
|
+
, 'expected ' + this.inspect + ' to not be within ' + range);
|
535
|
+
|
536
|
+
return this;
|
537
|
+
};
|
538
|
+
|
539
|
+
/**
|
540
|
+
* # .a(type)
|
541
|
+
*
|
542
|
+
* Assert typeof.
|
543
|
+
*
|
544
|
+
* expect('test').to.be.a('string');
|
545
|
+
*
|
546
|
+
* @name a
|
547
|
+
* @param {String} type
|
548
|
+
* @api public
|
549
|
+
*/
|
550
|
+
|
551
|
+
Assertion.prototype.a = function (type) {
|
552
|
+
this.assert(
|
553
|
+
type == typeof this.obj
|
554
|
+
, 'expected ' + this.inspect + ' to be a ' + type
|
555
|
+
, 'expected ' + this.inspect + ' not to be a ' + type);
|
556
|
+
|
557
|
+
return this;
|
558
|
+
};
|
559
|
+
|
560
|
+
/**
|
561
|
+
* # .instanceof(constructor)
|
562
|
+
*
|
563
|
+
* Assert instanceof.
|
564
|
+
*
|
565
|
+
* var Tea = function (name) { this.name = name; }
|
566
|
+
* , Chai = new Tea('chai');
|
567
|
+
*
|
568
|
+
* expect(Chai).to.be.an.instanceOf(Tea);
|
569
|
+
*
|
570
|
+
* @name instanceof
|
571
|
+
* @param {Constructor}
|
572
|
+
* @alias instanceOf
|
573
|
+
* @api public
|
574
|
+
*/
|
575
|
+
|
576
|
+
Assertion.prototype.instanceof = function (constructor) {
|
577
|
+
var name = constructor.name;
|
578
|
+
this.assert(
|
579
|
+
this.obj instanceof constructor
|
580
|
+
, 'expected ' + this.inspect + ' to be an instance of ' + name
|
581
|
+
, 'expected ' + this.inspect + ' to not be an instance of ' + name);
|
582
|
+
|
583
|
+
return this;
|
584
|
+
};
|
585
|
+
|
586
|
+
/**
|
587
|
+
* # .property(name, [value])
|
588
|
+
*
|
589
|
+
* Assert that property of `name` exists, optionally with `value`.
|
590
|
+
*
|
591
|
+
* var obj = { foo: 'bar' }
|
592
|
+
* expect(obj).to.have.property('foo');
|
593
|
+
* expect(obj).to.have.property('foo', 'bar');
|
594
|
+
* expect(obj).to.have.property('foo').to.be.a('string');
|
595
|
+
*
|
596
|
+
* @name property
|
597
|
+
* @param {String} name
|
598
|
+
* @param {*} value (optional)
|
599
|
+
* @returns value of property for chaining
|
600
|
+
* @api public
|
601
|
+
*/
|
602
|
+
|
603
|
+
Assertion.prototype.property = function (name, val) {
|
604
|
+
if (this.negate && undefined !== val) {
|
605
|
+
if (undefined === this.obj[name]) {
|
606
|
+
throw new Error(this.inspect + ' has no property ' + inspect(name));
|
607
|
+
}
|
608
|
+
} else {
|
609
|
+
this.assert(
|
610
|
+
undefined !== this.obj[name]
|
611
|
+
, 'expected ' + this.inspect + ' to have a property ' + inspect(name)
|
612
|
+
, 'expected ' + this.inspect + ' to not have property ' + inspect(name));
|
613
|
+
}
|
614
|
+
|
615
|
+
if (undefined !== val) {
|
616
|
+
this.assert(
|
617
|
+
val === this.obj[name]
|
618
|
+
, 'expected ' + this.inspect + ' to have a property ' + inspect(name) + ' of ' +
|
619
|
+
inspect(val) + ', but got ' + inspect(this.obj[name])
|
620
|
+
, 'expected ' + this.inspect + ' to not have a property ' + inspect(name) + ' of ' + inspect(val));
|
621
|
+
}
|
622
|
+
|
623
|
+
this.obj = this.obj[name];
|
624
|
+
return this;
|
625
|
+
};
|
626
|
+
|
627
|
+
/**
|
628
|
+
* # .ownProperty(name)
|
629
|
+
*
|
630
|
+
* Assert that has own property by `name`.
|
631
|
+
*
|
632
|
+
* expect('test').to.have.ownProperty('length');
|
633
|
+
*
|
634
|
+
* @name ownProperty
|
635
|
+
* @alias haveOwnProperty
|
636
|
+
* @param {String} name
|
637
|
+
* @api public
|
638
|
+
*/
|
639
|
+
|
640
|
+
Assertion.prototype.ownProperty = function (name) {
|
641
|
+
this.assert(
|
642
|
+
this.obj.hasOwnProperty(name)
|
643
|
+
, 'expected ' + this.inspect + ' to have own property ' + inspect(name)
|
644
|
+
, 'expected ' + this.inspect + ' to not have own property ' + inspect(name));
|
645
|
+
return this;
|
646
|
+
};
|
647
|
+
|
648
|
+
/**
|
649
|
+
* # .length(val)
|
650
|
+
*
|
651
|
+
* Assert that object has expected length.
|
652
|
+
*
|
653
|
+
* expect([1,2,3]).to.have.length(3);
|
654
|
+
* expect('foobar').to.have.length(6);
|
655
|
+
*
|
656
|
+
* @name length
|
657
|
+
* @alias lengthOf
|
658
|
+
* @param {Number} length
|
659
|
+
* @api public
|
660
|
+
*/
|
661
|
+
|
662
|
+
Assertion.prototype.length = function (n) {
|
663
|
+
new Assertion(this.obj).to.have.property('length');
|
664
|
+
var len = this.obj.length;
|
665
|
+
|
666
|
+
this.assert(
|
667
|
+
len == n
|
668
|
+
, 'expected ' + this.inspect + ' to have a length of ' + n + ' but got ' + len
|
669
|
+
, 'expected ' + this.inspect + ' to not have a length of ' + len);
|
670
|
+
|
671
|
+
return this;
|
672
|
+
};
|
673
|
+
|
674
|
+
/**
|
675
|
+
* # .match(regexp)
|
676
|
+
*
|
677
|
+
* Assert that matches regular expression.
|
678
|
+
*
|
679
|
+
* expect('foobar').to.match(/^foo/);
|
680
|
+
*
|
681
|
+
* @name match
|
682
|
+
* @param {RegExp} RegularExpression
|
683
|
+
* @api public
|
684
|
+
*/
|
685
|
+
|
686
|
+
Assertion.prototype.match = function (re) {
|
687
|
+
this.assert(
|
688
|
+
re.exec(this.obj)
|
689
|
+
, 'expected ' + this.inspect + ' to match ' + re
|
690
|
+
, 'expected ' + this.inspect + ' not to match ' + re);
|
691
|
+
|
692
|
+
return this;
|
693
|
+
};
|
694
|
+
|
695
|
+
/**
|
696
|
+
* # .include(obj)
|
697
|
+
*
|
698
|
+
* Assert the inclusion of an object in an Array or substring in string.
|
699
|
+
*
|
700
|
+
* expect([1,2,3]).to.contain(2);
|
701
|
+
*
|
702
|
+
* @name include
|
703
|
+
* @param {Object|String|Number} obj
|
704
|
+
* @api public
|
705
|
+
*/
|
706
|
+
|
707
|
+
Assertion.prototype.include = function (obj) {
|
708
|
+
this.assert(
|
709
|
+
~this.obj.indexOf(obj)
|
710
|
+
, 'expected ' + this.inspect + ' to include ' + inspect(obj)
|
711
|
+
, 'expected ' + this.inspect + ' to not include ' + inspect(obj));
|
712
|
+
|
713
|
+
return this;
|
714
|
+
};
|
715
|
+
|
716
|
+
/**
|
717
|
+
* # .string(string)
|
718
|
+
*
|
719
|
+
* Assert inclusion of string in string.
|
720
|
+
*
|
721
|
+
* expect('foobar').to.include.string('bar');
|
722
|
+
*
|
723
|
+
* @name string
|
724
|
+
* @param {String} string
|
725
|
+
* @api public
|
726
|
+
*/
|
727
|
+
|
728
|
+
Assertion.prototype.string = function (str) {
|
729
|
+
new Assertion(this.obj).is.a('string');
|
730
|
+
|
731
|
+
this.assert(
|
732
|
+
~this.obj.indexOf(str)
|
733
|
+
, 'expected ' + this.inspect + ' to contain ' + inspect(str)
|
734
|
+
, 'expected ' + this.inspect + ' to not contain ' + inspect(str));
|
735
|
+
|
736
|
+
return this;
|
737
|
+
};
|
738
|
+
|
739
|
+
|
740
|
+
|
741
|
+
/**
|
742
|
+
* # contain
|
743
|
+
*
|
744
|
+
* Toggles the `contain` flag for the `keys` assertion.
|
745
|
+
*
|
746
|
+
* @name contain
|
747
|
+
* @api public
|
748
|
+
*/
|
749
|
+
|
750
|
+
Object.defineProperty(Assertion.prototype, 'contain',
|
751
|
+
{ get: function () {
|
752
|
+
this.contains = true;
|
753
|
+
return this;
|
754
|
+
}
|
755
|
+
});
|
756
|
+
|
757
|
+
/**
|
758
|
+
* # .keys(key1, [key2], [...])
|
759
|
+
*
|
760
|
+
* Assert exact keys or the inclusing of keys using the `contain` modifier.
|
761
|
+
*
|
762
|
+
* expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
|
763
|
+
* expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
|
764
|
+
*
|
765
|
+
* @name keys
|
766
|
+
* @alias key
|
767
|
+
* @param {String|Array} Keys
|
768
|
+
* @api public
|
769
|
+
*/
|
770
|
+
|
771
|
+
Assertion.prototype.keys = function(keys) {
|
772
|
+
var str
|
773
|
+
, ok = true;
|
774
|
+
|
775
|
+
keys = keys instanceof Array
|
776
|
+
? keys
|
777
|
+
: Array.prototype.slice.call(arguments);
|
778
|
+
|
779
|
+
if (!keys.length) throw new Error('keys required');
|
780
|
+
|
781
|
+
var actual = Object.keys(this.obj)
|
782
|
+
, len = keys.length;
|
783
|
+
|
784
|
+
// Inclusion
|
785
|
+
ok = keys.every(function(key){
|
786
|
+
return ~actual.indexOf(key);
|
787
|
+
});
|
788
|
+
|
789
|
+
// Strict
|
790
|
+
if (!this.negate && !this.contains) {
|
791
|
+
ok = ok && keys.length == actual.length;
|
792
|
+
}
|
793
|
+
|
794
|
+
// Key string
|
795
|
+
if (len > 1) {
|
796
|
+
keys = keys.map(function(key){
|
797
|
+
return inspect(key);
|
798
|
+
});
|
799
|
+
var last = keys.pop();
|
800
|
+
str = keys.join(', ') + ', and ' + last;
|
801
|
+
} else {
|
802
|
+
str = inspect(keys[0]);
|
803
|
+
}
|
804
|
+
|
805
|
+
// Form
|
806
|
+
str = (len > 1 ? 'keys ' : 'key ') + str;
|
807
|
+
|
808
|
+
// Have / include
|
809
|
+
str = (this.contains ? 'contain ' : 'have ') + str;
|
810
|
+
|
811
|
+
// Assertion
|
812
|
+
this.assert(
|
813
|
+
ok
|
814
|
+
, 'expected ' + this.inspect + ' to ' + str
|
815
|
+
, 'expected ' + this.inspect + ' to not ' + str);
|
816
|
+
|
817
|
+
return this;
|
818
|
+
}
|
819
|
+
|
820
|
+
/**
|
821
|
+
* # .throw(constructor)
|
822
|
+
*
|
823
|
+
* Assert that a function will throw a specific type of error.
|
824
|
+
*
|
825
|
+
* var fn = function () { throw new ReferenceError(''); }
|
826
|
+
* expect(fn).to.throw(ReferenceError);
|
827
|
+
*
|
828
|
+
* @name throw
|
829
|
+
* @alias throws
|
830
|
+
* @alias Throw
|
831
|
+
* @param {ErrorConstructor} constructor
|
832
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
833
|
+
* @api public
|
834
|
+
*/
|
835
|
+
|
836
|
+
Assertion.prototype.throw = function (constructor) {
|
837
|
+
new Assertion(this.obj).is.a('function');
|
838
|
+
|
839
|
+
var thrown = false;
|
840
|
+
|
841
|
+
try {
|
842
|
+
this.obj();
|
843
|
+
} catch (err) {
|
844
|
+
if (constructor && 'function' === typeof constructor && constructor.constructor != RegExp) {
|
845
|
+
this.assert(
|
846
|
+
err instanceof constructor && err.name == constructor.name
|
847
|
+
, 'expected ' + this.inspect + ' to throw ' + constructor.name + ' but a ' + err.name + ' was thrown'
|
848
|
+
, 'expected ' + this.inspect + ' to not throw ' + constructor.name );
|
849
|
+
return this;
|
850
|
+
} else if (constructor && constructor instanceof RegExp) {
|
851
|
+
this.assert(
|
852
|
+
constructor.exec(err.message)
|
853
|
+
, 'expected ' + this.inspect + ' to throw error matching ' + constructor + ' but got ' + inspect(err.message)
|
854
|
+
, 'expected ' + this.inspect + ' to throw error not matching ' + constructor);
|
855
|
+
return this;
|
856
|
+
} else {
|
857
|
+
thrown = true;
|
858
|
+
}
|
859
|
+
}
|
860
|
+
|
861
|
+
var name = (constructor ? constructor.name : 'an error');
|
862
|
+
|
863
|
+
this.assert(
|
864
|
+
thrown === true
|
865
|
+
, 'expected ' + this.inspect + ' to throw ' + name
|
866
|
+
, 'expected ' + this.inspect + ' to not throw ' + name);
|
867
|
+
|
868
|
+
return this;
|
869
|
+
};
|
870
|
+
|
871
|
+
/*!
|
872
|
+
* Aliases.
|
873
|
+
*/
|
874
|
+
|
875
|
+
(function alias(name, as){
|
876
|
+
Assertion.prototype[as] = Assertion.prototype[name];
|
877
|
+
return alias;
|
878
|
+
})
|
879
|
+
('length', 'lengthOf')
|
880
|
+
('keys', 'key')
|
881
|
+
('ownProperty', 'haveOwnProperty')
|
882
|
+
('above', 'greaterThan')
|
883
|
+
('below', 'lessThan')
|
884
|
+
('throw', 'throws')
|
885
|
+
('throw', 'Throw') // for troublesome browsers
|
886
|
+
('instanceof', 'instanceOf');
|
887
|
+
|
888
|
+
}); // module: assertion.js
|
889
|
+
|
890
|
+
require.register("chai.js", function(module, exports, require){
|
891
|
+
/*!
|
892
|
+
* chai
|
893
|
+
* Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
|
894
|
+
* MIT Licensed
|
895
|
+
*/
|
896
|
+
|
897
|
+
var used = [];
|
898
|
+
var exports = module.exports = {};
|
899
|
+
|
900
|
+
exports.version = '0.3.2';
|
901
|
+
|
902
|
+
exports.Assertion = require('./assertion');
|
903
|
+
exports.AssertionError = require('./error');
|
904
|
+
|
905
|
+
exports.inspect = require('./utils/inspect');
|
906
|
+
|
907
|
+
exports.use = function (fn) {
|
908
|
+
if (!~used.indexOf(fn)) {
|
909
|
+
fn(this);
|
910
|
+
used.push(fn);
|
911
|
+
}
|
912
|
+
|
913
|
+
return this;
|
914
|
+
};
|
915
|
+
|
916
|
+
exports.fail = function (actual, expected, message, operator, stackStartFunction) {
|
917
|
+
throw new exports.AssertionError({
|
918
|
+
message: message,
|
919
|
+
actual: actual,
|
920
|
+
expected: expected,
|
921
|
+
operator: operator,
|
922
|
+
stackStartFunction: stackStartFunction
|
923
|
+
});
|
924
|
+
};
|
925
|
+
|
926
|
+
var expect = require('./interface/expect');
|
927
|
+
exports.use(expect);
|
928
|
+
|
929
|
+
var should = require('./interface/should');
|
930
|
+
exports.use(should);
|
931
|
+
|
932
|
+
var assert = require('./interface/assert');
|
933
|
+
exports.use(assert);
|
934
|
+
|
935
|
+
}); // module: chai.js
|
936
|
+
|
937
|
+
require.register("error.js", function(module, exports, require){
|
938
|
+
/*!
|
939
|
+
* chai
|
940
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
941
|
+
* MIT Licensed
|
942
|
+
*/
|
943
|
+
|
944
|
+
var fail = require('./chai').fail;
|
945
|
+
|
946
|
+
module.exports = AssertionError;
|
947
|
+
|
948
|
+
/*!
|
949
|
+
* Inspired by node.js assert module
|
950
|
+
* https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
951
|
+
*/
|
952
|
+
function AssertionError (options) {
|
953
|
+
options = options || {};
|
954
|
+
this.name = 'AssertionError';
|
955
|
+
this.message = options.message;
|
956
|
+
this.actual = options.actual;
|
957
|
+
this.expected = options.expected;
|
958
|
+
this.operator = options.operator;
|
959
|
+
var stackStartFunction = options.stackStartFunction || fail;
|
960
|
+
|
961
|
+
if (Error.captureStackTrace) {
|
962
|
+
Error.captureStackTrace(this, stackStartFunction);
|
963
|
+
}
|
964
|
+
}
|
965
|
+
|
966
|
+
AssertionError.prototype.__proto__ = Error.prototype;
|
967
|
+
|
968
|
+
AssertionError.prototype.summary = function() {
|
969
|
+
var str = '';
|
970
|
+
|
971
|
+
if (this.operator) {
|
972
|
+
str += 'In: \'' + this.operator + '\'\n\t';
|
973
|
+
}
|
974
|
+
|
975
|
+
str += '' + this.name + (this.message ? ': ' + this.message : '');
|
976
|
+
|
977
|
+
return str;
|
978
|
+
};
|
979
|
+
|
980
|
+
AssertionError.prototype.details = function() {
|
981
|
+
return this.summary();
|
982
|
+
};
|
983
|
+
|
984
|
+
AssertionError.prototype.toString = function() {
|
985
|
+
return this.summary();
|
986
|
+
};
|
987
|
+
}); // module: error.js
|
988
|
+
|
989
|
+
require.register("interface/assert.js", function(module, exports, require){
|
990
|
+
/*!
|
991
|
+
* chai
|
992
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
993
|
+
* MIT Licensed
|
994
|
+
*/
|
995
|
+
|
996
|
+
/**
|
997
|
+
* ### TDD Style Introduction
|
998
|
+
*
|
999
|
+
* The TDD style is exposed through `assert` interfaces. This provides
|
1000
|
+
* the classic assert.`test` notation, similiar to that packaged with
|
1001
|
+
* node.js. This assert module, however, provides several additional
|
1002
|
+
* tests and is browser compatible.
|
1003
|
+
*
|
1004
|
+
* // assert
|
1005
|
+
* var assert = require('chai').assert;
|
1006
|
+
* , foo = 'bar';
|
1007
|
+
*
|
1008
|
+
* assert.typeOf(foo, 'string');
|
1009
|
+
* assert.equal(foo, 'bar');
|
1010
|
+
*/
|
1011
|
+
|
1012
|
+
module.exports = function (chai) {
|
1013
|
+
/*!
|
1014
|
+
* Chai dependencies.
|
1015
|
+
*/
|
1016
|
+
var Assertion = chai.Assertion
|
1017
|
+
, inspect = chai.inspect;
|
1018
|
+
|
1019
|
+
/*!
|
1020
|
+
* Module export.
|
1021
|
+
*/
|
1022
|
+
|
1023
|
+
var assert = chai.assert = {};
|
1024
|
+
|
1025
|
+
/**
|
1026
|
+
* # .ok(object, [message])
|
1027
|
+
*
|
1028
|
+
* Assert object is truthy.
|
1029
|
+
*
|
1030
|
+
* assert.ok('everthing', 'everything is ok');
|
1031
|
+
* assert.ok(false, 'this will fail');
|
1032
|
+
*
|
1033
|
+
* @name ok
|
1034
|
+
* @param {*} object to test
|
1035
|
+
* @param {String} message
|
1036
|
+
* @api public
|
1037
|
+
*/
|
1038
|
+
|
1039
|
+
assert.ok = function (val, msg) {
|
1040
|
+
new Assertion(val, msg).is.ok;
|
1041
|
+
};
|
1042
|
+
|
1043
|
+
/**
|
1044
|
+
* # .equal(actual, expected, [message])
|
1045
|
+
*
|
1046
|
+
* Assert strict equality.
|
1047
|
+
*
|
1048
|
+
* assert.equal(3, 3, 'these numbers are equal');
|
1049
|
+
*
|
1050
|
+
* @name equal
|
1051
|
+
* @param {*} actual
|
1052
|
+
* @param {*} expected
|
1053
|
+
* @param {String} message
|
1054
|
+
* @api public
|
1055
|
+
*/
|
1056
|
+
|
1057
|
+
assert.equal = function (act, exp, msg) {
|
1058
|
+
var test = new Assertion(act, msg);
|
1059
|
+
|
1060
|
+
test.assert(
|
1061
|
+
exp == test.obj
|
1062
|
+
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
|
1063
|
+
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp));
|
1064
|
+
};
|
1065
|
+
|
1066
|
+
/**
|
1067
|
+
* # .notEqual(actual, expected, [message])
|
1068
|
+
*
|
1069
|
+
* Assert not equal.
|
1070
|
+
*
|
1071
|
+
* assert.notEqual(3, 4, 'these numbers are not equal');
|
1072
|
+
*
|
1073
|
+
* @name notEqual
|
1074
|
+
* @param {*} actual
|
1075
|
+
* @param {*} expected
|
1076
|
+
* @param {String} message
|
1077
|
+
* @api public
|
1078
|
+
*/
|
1079
|
+
|
1080
|
+
assert.notEqual = function (act, exp, msg) {
|
1081
|
+
var test = new Assertion(act, msg);
|
1082
|
+
|
1083
|
+
test.assert(
|
1084
|
+
exp != test.obj
|
1085
|
+
, 'expected ' + test.inspect + ' to equal ' + inspect(exp)
|
1086
|
+
, 'expected ' + test.inspect + ' to not equal ' + inspect(exp));
|
1087
|
+
};
|
1088
|
+
|
1089
|
+
/**
|
1090
|
+
* # .strictEqual(actual, expected, [message])
|
1091
|
+
*
|
1092
|
+
* Assert strict equality.
|
1093
|
+
*
|
1094
|
+
* assert.strictEqual(true, true, 'these booleans are strictly equal');
|
1095
|
+
*
|
1096
|
+
* @name strictEqual
|
1097
|
+
* @param {*} actual
|
1098
|
+
* @param {*} expected
|
1099
|
+
* @param {String} message
|
1100
|
+
* @api public
|
1101
|
+
*/
|
1102
|
+
|
1103
|
+
assert.strictEqual = function (act, exp, msg) {
|
1104
|
+
new Assertion(act, msg).to.equal(exp);
|
1105
|
+
};
|
1106
|
+
|
1107
|
+
/**
|
1108
|
+
* # .notStrictEqual(actual, expected, [message])
|
1109
|
+
*
|
1110
|
+
* Assert strict equality.
|
1111
|
+
*
|
1112
|
+
* assert.notStrictEqual(1, true, 'these booleans are not strictly equal');
|
1113
|
+
*
|
1114
|
+
* @name notStrictEqual
|
1115
|
+
* @param {*} actual
|
1116
|
+
* @param {*} expected
|
1117
|
+
* @param {String} message
|
1118
|
+
* @api public
|
1119
|
+
*/
|
1120
|
+
|
1121
|
+
assert.notStrictEqual = function (act, exp, msg) {
|
1122
|
+
new Assertion(act, msg).to.not.equal(exp);
|
1123
|
+
};
|
1124
|
+
|
1125
|
+
/**
|
1126
|
+
* # .deepEqual(actual, expected, [message])
|
1127
|
+
*
|
1128
|
+
* Assert not deep equality.
|
1129
|
+
*
|
1130
|
+
* assert.deepEqual({ tea: 'green' }, { tea: 'green' });
|
1131
|
+
*
|
1132
|
+
* @name deepEqual
|
1133
|
+
* @param {*} actual
|
1134
|
+
* @param {*} expected
|
1135
|
+
* @param {String} message
|
1136
|
+
* @api public
|
1137
|
+
*/
|
1138
|
+
|
1139
|
+
assert.deepEqual = function (act, exp, msg) {
|
1140
|
+
new Assertion(act, msg).to.eql(exp);
|
1141
|
+
};
|
1142
|
+
|
1143
|
+
/**
|
1144
|
+
* # .notDeepEqual(actual, expected, [message])
|
1145
|
+
*
|
1146
|
+
* Assert not deep equality.
|
1147
|
+
*
|
1148
|
+
* assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
|
1149
|
+
*
|
1150
|
+
* @name notDeepEqual
|
1151
|
+
* @param {*} actual
|
1152
|
+
* @param {*} expected
|
1153
|
+
* @param {String} message
|
1154
|
+
* @api public
|
1155
|
+
*/
|
1156
|
+
|
1157
|
+
assert.notDeepEqual = function (act, exp, msg) {
|
1158
|
+
new Assertion(act, msg).to.not.eql(exp);
|
1159
|
+
};
|
1160
|
+
|
1161
|
+
/**
|
1162
|
+
* # .isTrue(value, [message])
|
1163
|
+
*
|
1164
|
+
* Assert `value` is true.
|
1165
|
+
*
|
1166
|
+
* var tea_served = true;
|
1167
|
+
* assert.isTrue(tea_served, 'the tea has been served');
|
1168
|
+
*
|
1169
|
+
* @name isTrue
|
1170
|
+
* @param {Boolean} value
|
1171
|
+
* @param {String} message
|
1172
|
+
* @api public
|
1173
|
+
*/
|
1174
|
+
|
1175
|
+
assert.isTrue = function (val, msg) {
|
1176
|
+
new Assertion(val, msg).is.true;
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
/**
|
1180
|
+
* # .isFalse(value, [message])
|
1181
|
+
*
|
1182
|
+
* Assert `value` is false.
|
1183
|
+
*
|
1184
|
+
* var tea_served = false;
|
1185
|
+
* assert.isFalse(tea_served, 'no tea yet? hmm...');
|
1186
|
+
*
|
1187
|
+
* @name isFalse
|
1188
|
+
* @param {Boolean} value
|
1189
|
+
* @param {String} message
|
1190
|
+
* @api public
|
1191
|
+
*/
|
1192
|
+
|
1193
|
+
assert.isFalse = function (val, msg) {
|
1194
|
+
new Assertion(val, msg).is.false;
|
1195
|
+
};
|
1196
|
+
|
1197
|
+
/**
|
1198
|
+
* # .isNull(value, [message])
|
1199
|
+
*
|
1200
|
+
* Assert `value` is null.
|
1201
|
+
*
|
1202
|
+
* assert.isNull(err, 'no errors');
|
1203
|
+
*
|
1204
|
+
* @name isNull
|
1205
|
+
* @param {*} value
|
1206
|
+
* @param {String} message
|
1207
|
+
* @api public
|
1208
|
+
*/
|
1209
|
+
|
1210
|
+
assert.isNull = function (val, msg) {
|
1211
|
+
new Assertion(val, msg).to.not.exist;
|
1212
|
+
};
|
1213
|
+
|
1214
|
+
/**
|
1215
|
+
* # .isNotNull(value, [message])
|
1216
|
+
*
|
1217
|
+
* Assert `value` is not null.
|
1218
|
+
*
|
1219
|
+
* var tea = 'tasty chai';
|
1220
|
+
* assert.isNotNull(tea, 'great, time for tea!');
|
1221
|
+
*
|
1222
|
+
* @name isNotNull
|
1223
|
+
* @param {*} value
|
1224
|
+
* @param {String} message
|
1225
|
+
* @api public
|
1226
|
+
*/
|
1227
|
+
|
1228
|
+
assert.isNotNull = function (val, msg) {
|
1229
|
+
new Assertion(val, msg).to.exist;
|
1230
|
+
};
|
1231
|
+
|
1232
|
+
/**
|
1233
|
+
* # .isUndefined(value, [message])
|
1234
|
+
*
|
1235
|
+
* Assert `value` is undefined.
|
1236
|
+
*
|
1237
|
+
* assert.isUndefined(tea, 'no tea defined');
|
1238
|
+
*
|
1239
|
+
* @name isUndefined
|
1240
|
+
* @param {*} value
|
1241
|
+
* @param {String} message
|
1242
|
+
* @api public
|
1243
|
+
*/
|
1244
|
+
|
1245
|
+
assert.isUndefined = function (val, msg) {
|
1246
|
+
new Assertion(val, msg).to.equal(undefined);
|
1247
|
+
};
|
1248
|
+
|
1249
|
+
/**
|
1250
|
+
* # .isFunction(value, [message])
|
1251
|
+
*
|
1252
|
+
* Assert `value` is a function.
|
1253
|
+
*
|
1254
|
+
* var serve_tea = function () { return 'cup of tea'; };
|
1255
|
+
* assert.isFunction(serve_tea, 'great, we can have tea now');
|
1256
|
+
*
|
1257
|
+
* @name isFunction
|
1258
|
+
* @param {Function} value
|
1259
|
+
* @param {String} message
|
1260
|
+
* @api public
|
1261
|
+
*/
|
1262
|
+
|
1263
|
+
assert.isFunction = function (val, msg) {
|
1264
|
+
new Assertion(val, msg).to.be.a('function');
|
1265
|
+
};
|
1266
|
+
|
1267
|
+
/**
|
1268
|
+
* # .isObject(value, [message])
|
1269
|
+
*
|
1270
|
+
* Assert `value` is an object.
|
1271
|
+
*
|
1272
|
+
* var selection = { name: 'Chai', serve: 'with spices' };
|
1273
|
+
* assert.isObject(selection, 'tea selection is an object');
|
1274
|
+
*
|
1275
|
+
* @name isObject
|
1276
|
+
* @param {Object} value
|
1277
|
+
* @param {String} message
|
1278
|
+
* @api public
|
1279
|
+
*/
|
1280
|
+
|
1281
|
+
assert.isObject = function (val, msg) {
|
1282
|
+
new Assertion(val, msg).to.be.a('object');
|
1283
|
+
};
|
1284
|
+
|
1285
|
+
/**
|
1286
|
+
* # .isArray(value, [message])
|
1287
|
+
*
|
1288
|
+
* Assert `value` is an instance of Array.
|
1289
|
+
*
|
1290
|
+
* var menu = [ 'green', 'chai', 'oolong' ];
|
1291
|
+
* assert.isArray(menu, 'what kind of tea do we want?');
|
1292
|
+
*
|
1293
|
+
* @name isArray
|
1294
|
+
* @param {*} value
|
1295
|
+
* @param {String} message
|
1296
|
+
* @api public
|
1297
|
+
*/
|
1298
|
+
|
1299
|
+
assert.isArray = function (val, msg) {
|
1300
|
+
new Assertion(val, msg).to.be.instanceof(Array);
|
1301
|
+
};
|
1302
|
+
|
1303
|
+
/**
|
1304
|
+
* # .isString(value, [message])
|
1305
|
+
*
|
1306
|
+
* Assert `value` is a string.
|
1307
|
+
*
|
1308
|
+
* var teaorder = 'chai';
|
1309
|
+
* assert.isString(tea_order, 'order placed');
|
1310
|
+
*
|
1311
|
+
* @name isString
|
1312
|
+
* @param {String} value
|
1313
|
+
* @param {String} message
|
1314
|
+
* @api public
|
1315
|
+
*/
|
1316
|
+
|
1317
|
+
assert.isString = function (val, msg) {
|
1318
|
+
new Assertion(val, msg).to.be.a('string');
|
1319
|
+
};
|
1320
|
+
|
1321
|
+
/**
|
1322
|
+
* # .isNumber(value, [message])
|
1323
|
+
*
|
1324
|
+
* Assert `value` is a number
|
1325
|
+
*
|
1326
|
+
* var cups = 2;
|
1327
|
+
* assert.isNumber(cups, 'how many cups');
|
1328
|
+
*
|
1329
|
+
* @name isNumber
|
1330
|
+
* @param {Number} value
|
1331
|
+
* @param {String} message
|
1332
|
+
* @api public
|
1333
|
+
*/
|
1334
|
+
|
1335
|
+
assert.isNumber = function (val, msg) {
|
1336
|
+
new Assertion(val, msg).to.be.instanceof(Number);
|
1337
|
+
};
|
1338
|
+
|
1339
|
+
/**
|
1340
|
+
* # .isBoolean(value, [message])
|
1341
|
+
*
|
1342
|
+
* Assert `value` is a boolean
|
1343
|
+
*
|
1344
|
+
* var teaready = true
|
1345
|
+
* , teaserved = false;
|
1346
|
+
*
|
1347
|
+
* assert.isBoolean(tea_ready, 'is the tea ready');
|
1348
|
+
* assert.isBoolean(tea_served, 'has tea been served');
|
1349
|
+
*
|
1350
|
+
* @name isBoolean
|
1351
|
+
* @param {*} value
|
1352
|
+
* @param {String} message
|
1353
|
+
* @api public
|
1354
|
+
*/
|
1355
|
+
|
1356
|
+
assert.isBoolean = function (val, msg) {
|
1357
|
+
new Assertion(val, msg).to.be.a('boolean');
|
1358
|
+
};
|
1359
|
+
|
1360
|
+
/**
|
1361
|
+
* # .typeOf(value, name, [message])
|
1362
|
+
*
|
1363
|
+
* Assert typeof `value` is `name`.
|
1364
|
+
*
|
1365
|
+
* assert.typeOf('tea', 'string', 'we have a string');
|
1366
|
+
*
|
1367
|
+
* @name typeOf
|
1368
|
+
* @param {*} value
|
1369
|
+
* @param {String} typeof name
|
1370
|
+
* @param {String} message
|
1371
|
+
* @api public
|
1372
|
+
*/
|
1373
|
+
|
1374
|
+
assert.typeOf = function (val, type, msg) {
|
1375
|
+
new Assertion(val, msg).to.be.a(type);
|
1376
|
+
};
|
1377
|
+
|
1378
|
+
/**
|
1379
|
+
* # .instanceOf(object, constructor, [message])
|
1380
|
+
*
|
1381
|
+
* Assert `value` is instanceof `constructor`.
|
1382
|
+
*
|
1383
|
+
* var Tea = function (name) { this.name = name; }
|
1384
|
+
* , Chai = new Tea('chai');
|
1385
|
+
*
|
1386
|
+
* assert.instanceOf(Chai, Tea, 'chai is an instance of tea');
|
1387
|
+
*
|
1388
|
+
* @name instanceOf
|
1389
|
+
* @param {Object} object
|
1390
|
+
* @param {Constructor} constructor
|
1391
|
+
* @param {String} message
|
1392
|
+
* @api public
|
1393
|
+
*/
|
1394
|
+
|
1395
|
+
assert.instanceOf = function (val, type, msg) {
|
1396
|
+
new Assertion(val, msg).to.be.instanceof(type);
|
1397
|
+
};
|
1398
|
+
|
1399
|
+
/**
|
1400
|
+
* # .include(value, includes, [message])
|
1401
|
+
*
|
1402
|
+
* Assert the inclusion of an object in another. Works
|
1403
|
+
* for strings and arrays.
|
1404
|
+
*
|
1405
|
+
* assert.include('foobar', 'bar', 'foobar contains string `var`);
|
1406
|
+
* assert.include([ 1, 2, 3], 3, 'array contains value);
|
1407
|
+
*
|
1408
|
+
* @name include
|
1409
|
+
* @param {Array|String} value
|
1410
|
+
* @param {*} includes
|
1411
|
+
* @param {String} message
|
1412
|
+
* @api public
|
1413
|
+
*/
|
1414
|
+
|
1415
|
+
assert.include = function (exp, inc, msg) {
|
1416
|
+
var obj = new Assertion(exp, msg);
|
1417
|
+
|
1418
|
+
if (Array.isArray(exp)) {
|
1419
|
+
obj.to.include(inc);
|
1420
|
+
} else if ('string' === typeof exp) {
|
1421
|
+
obj.to.contain.string(inc);
|
1422
|
+
}
|
1423
|
+
};
|
1424
|
+
|
1425
|
+
/**
|
1426
|
+
* # .match(value, regex, [message])
|
1427
|
+
*
|
1428
|
+
* Assert that `value` matches regular expression.
|
1429
|
+
*
|
1430
|
+
* assert.match('foobar', /^foo/, 'Regexp matches');
|
1431
|
+
*
|
1432
|
+
* @name match
|
1433
|
+
* @param {*} value
|
1434
|
+
* @param {RegExp} RegularExpression
|
1435
|
+
* @param {String} message
|
1436
|
+
* @api public
|
1437
|
+
*/
|
1438
|
+
|
1439
|
+
assert.match = function (exp, re, msg) {
|
1440
|
+
new Assertion(exp, msg).to.match(re);
|
1441
|
+
};
|
1442
|
+
|
1443
|
+
/**
|
1444
|
+
* # .length(value, constructor, [message])
|
1445
|
+
*
|
1446
|
+
* Assert that object has expected length.
|
1447
|
+
*
|
1448
|
+
* assert.length([1,2,3], 3, 'Array has length of 3');
|
1449
|
+
* assert.length('foobar', 5, 'String has length of 6');
|
1450
|
+
*
|
1451
|
+
* @name length
|
1452
|
+
* @param {*} value
|
1453
|
+
* @param {Number} length
|
1454
|
+
* @param {String} message
|
1455
|
+
* @api public
|
1456
|
+
*/
|
1457
|
+
|
1458
|
+
assert.length = function (exp, len, msg) {
|
1459
|
+
new Assertion(exp, msg).to.have.length(len);
|
1460
|
+
};
|
1461
|
+
|
1462
|
+
/**
|
1463
|
+
* # .throws(function, [constructor/regexp], [message])
|
1464
|
+
*
|
1465
|
+
* Assert that a function will throw a specific
|
1466
|
+
* type of error.
|
1467
|
+
*
|
1468
|
+
* assert.throw(fn, ReferenceError, 'function throw reference error');
|
1469
|
+
*
|
1470
|
+
* @name throws
|
1471
|
+
* @alias throw
|
1472
|
+
* @param {Function} function to test
|
1473
|
+
* @param {ErrorConstructor} constructor
|
1474
|
+
* @param {String} message
|
1475
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
1476
|
+
* @api public
|
1477
|
+
*/
|
1478
|
+
|
1479
|
+
assert.throws = function (fn, type, msg) {
|
1480
|
+
if ('string' === typeof type) {
|
1481
|
+
msg = type;
|
1482
|
+
type = null;
|
1483
|
+
}
|
1484
|
+
|
1485
|
+
new Assertion(fn, msg).to.throw(type);
|
1486
|
+
};
|
1487
|
+
|
1488
|
+
/**
|
1489
|
+
* # .doesNotThrow(function, [constructor/regexp], [message])
|
1490
|
+
*
|
1491
|
+
* Assert that a function will throw a specific
|
1492
|
+
* type of error.
|
1493
|
+
*
|
1494
|
+
* var fn = function (err) { if (err) throw Error(err) };
|
1495
|
+
* assert.doesNotThrow(fn, Error, 'function throw reference error');
|
1496
|
+
*
|
1497
|
+
* @name doesNotThrow
|
1498
|
+
* @param {Function} function to test
|
1499
|
+
* @param {ErrorConstructor} constructor
|
1500
|
+
* @param {String} message
|
1501
|
+
* @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
|
1502
|
+
* @api public
|
1503
|
+
*/
|
1504
|
+
|
1505
|
+
assert.doesNotThrow = function (fn, type, msg) {
|
1506
|
+
if ('string' === typeof type) {
|
1507
|
+
msg = type;
|
1508
|
+
type = null;
|
1509
|
+
}
|
1510
|
+
|
1511
|
+
new Assertion(fn, msg).to.not.throw(type);
|
1512
|
+
};
|
1513
|
+
|
1514
|
+
/*!
|
1515
|
+
* Undocumented / untested
|
1516
|
+
*/
|
1517
|
+
|
1518
|
+
assert.ifError = function (val, msg) {
|
1519
|
+
new Assertion(val, msg).to.not.be.ok;
|
1520
|
+
};
|
1521
|
+
|
1522
|
+
/*!
|
1523
|
+
* Aliases.
|
1524
|
+
*/
|
1525
|
+
|
1526
|
+
(function alias(name, as){
|
1527
|
+
assert[as] = assert[name];
|
1528
|
+
return alias;
|
1529
|
+
})
|
1530
|
+
('length', 'lengthOf')
|
1531
|
+
('throws', 'throw');
|
1532
|
+
};
|
1533
|
+
|
1534
|
+
}); // module: interface/assert.js
|
1535
|
+
|
1536
|
+
require.register("interface/expect.js", function(module, exports, require){
|
1537
|
+
/*!
|
1538
|
+
* chai
|
1539
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
1540
|
+
* MIT Licensed
|
1541
|
+
*/
|
1542
|
+
|
1543
|
+
module.exports = function (chai) {
|
1544
|
+
chai.expect = function (val, message) {
|
1545
|
+
return new chai.Assertion(val, message);
|
1546
|
+
};
|
1547
|
+
};
|
1548
|
+
|
1549
|
+
|
1550
|
+
}); // module: interface/expect.js
|
1551
|
+
|
1552
|
+
require.register("interface/should.js", function(module, exports, require){
|
1553
|
+
/*!
|
1554
|
+
* chai
|
1555
|
+
* Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
|
1556
|
+
* MIT Licensed
|
1557
|
+
*/
|
1558
|
+
|
1559
|
+
module.exports = function (chai) {
|
1560
|
+
var Assertion = chai.Assertion;
|
1561
|
+
|
1562
|
+
chai.should = function () {
|
1563
|
+
// modify Object.prototype to have `should`
|
1564
|
+
Object.defineProperty(Object.prototype, 'should', {
|
1565
|
+
set: function(){},
|
1566
|
+
get: function(){
|
1567
|
+
if (this instanceof String || this instanceof Number) {
|
1568
|
+
return new Assertion(this.constructor(this));
|
1569
|
+
} else if (this instanceof Boolean) {
|
1570
|
+
return new Assertion(this == true);
|
1571
|
+
}
|
1572
|
+
return new Assertion(this);
|
1573
|
+
},
|
1574
|
+
configurable: true
|
1575
|
+
});
|
1576
|
+
|
1577
|
+
var should = {};
|
1578
|
+
|
1579
|
+
should.equal = function (val1, val2) {
|
1580
|
+
new Assertion(val1).to.equal(val2);
|
1581
|
+
};
|
1582
|
+
|
1583
|
+
should.throw = function (fn, err) {
|
1584
|
+
new Assertion(fn).to.throw(err);
|
1585
|
+
};
|
1586
|
+
|
1587
|
+
should.exist = function (val) {
|
1588
|
+
new Assertion(val).to.exist;
|
1589
|
+
}
|
1590
|
+
|
1591
|
+
// negation
|
1592
|
+
should.not = {}
|
1593
|
+
|
1594
|
+
should.not.equal = function (val1, val2) {
|
1595
|
+
new Assertion(val1).to.not.equal(val2);
|
1596
|
+
};
|
1597
|
+
|
1598
|
+
should.not.throw = function (fn, err) {
|
1599
|
+
new Assertion(fn).to.not.throw(err);
|
1600
|
+
};
|
1601
|
+
|
1602
|
+
should.not.exist = function (val) {
|
1603
|
+
new Assertion(val).to.not.exist;
|
1604
|
+
}
|
1605
|
+
|
1606
|
+
return should;
|
1607
|
+
};
|
1608
|
+
};
|
1609
|
+
|
1610
|
+
}); // module: interface/should.js
|
1611
|
+
|
1612
|
+
require.register("utils/eql.js", function(module, exports, require){
|
1613
|
+
// This is directly from Node.js assert
|
1614
|
+
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
|
1615
|
+
|
1616
|
+
|
1617
|
+
module.exports = _deepEqual;
|
1618
|
+
|
1619
|
+
// For browser implementation
|
1620
|
+
if (!Buffer) {
|
1621
|
+
var Buffer = {
|
1622
|
+
isBuffer: function () {
|
1623
|
+
return false;
|
1624
|
+
}
|
1625
|
+
};
|
1626
|
+
}
|
1627
|
+
|
1628
|
+
function _deepEqual(actual, expected) {
|
1629
|
+
// 7.1. All identical values are equivalent, as determined by ===.
|
1630
|
+
if (actual === expected) {
|
1631
|
+
return true;
|
1632
|
+
|
1633
|
+
} else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
|
1634
|
+
if (actual.length != expected.length) return false;
|
1635
|
+
|
1636
|
+
for (var i = 0; i < actual.length; i++) {
|
1637
|
+
if (actual[i] !== expected[i]) return false;
|
1638
|
+
}
|
1639
|
+
|
1640
|
+
return true;
|
1641
|
+
|
1642
|
+
// 7.2. If the expected value is a Date object, the actual value is
|
1643
|
+
// equivalent if it is also a Date object that refers to the same time.
|
1644
|
+
} else if (actual instanceof Date && expected instanceof Date) {
|
1645
|
+
return actual.getTime() === expected.getTime();
|
1646
|
+
|
1647
|
+
// 7.3. Other pairs that do not both pass typeof value == 'object',
|
1648
|
+
// equivalence is determined by ==.
|
1649
|
+
} else if (typeof actual != 'object' && typeof expected != 'object') {
|
1650
|
+
return actual === expected;
|
1651
|
+
|
1652
|
+
// 7.4. For all other Object pairs, including Array objects, equivalence is
|
1653
|
+
// determined by having the same number of owned properties (as verified
|
1654
|
+
// with Object.prototype.hasOwnProperty.call), the same set of keys
|
1655
|
+
// (although not necessarily the same order), equivalent values for every
|
1656
|
+
// corresponding key, and an identical 'prototype' property. Note: this
|
1657
|
+
// accounts for both named and indexed properties on Arrays.
|
1658
|
+
} else {
|
1659
|
+
return objEquiv(actual, expected);
|
1660
|
+
}
|
1661
|
+
}
|
1662
|
+
|
1663
|
+
function isUndefinedOrNull(value) {
|
1664
|
+
return value === null || value === undefined;
|
1665
|
+
}
|
1666
|
+
|
1667
|
+
function isArguments(object) {
|
1668
|
+
return Object.prototype.toString.call(object) == '[object Arguments]';
|
1669
|
+
}
|
1670
|
+
|
1671
|
+
function objEquiv(a, b) {
|
1672
|
+
if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
1673
|
+
return false;
|
1674
|
+
// an identical 'prototype' property.
|
1675
|
+
if (a.prototype !== b.prototype) return false;
|
1676
|
+
//~~~I've managed to break Object.keys through screwy arguments passing.
|
1677
|
+
// Converting to array solves the problem.
|
1678
|
+
if (isArguments(a)) {
|
1679
|
+
if (!isArguments(b)) {
|
1680
|
+
return false;
|
1681
|
+
}
|
1682
|
+
a = pSlice.call(a);
|
1683
|
+
b = pSlice.call(b);
|
1684
|
+
return _deepEqual(a, b);
|
1685
|
+
}
|
1686
|
+
try {
|
1687
|
+
var ka = Object.keys(a),
|
1688
|
+
kb = Object.keys(b),
|
1689
|
+
key, i;
|
1690
|
+
} catch (e) {//happens when one is a string literal and the other isn't
|
1691
|
+
return false;
|
1692
|
+
}
|
1693
|
+
// having the same number of owned properties (keys incorporates
|
1694
|
+
// hasOwnProperty)
|
1695
|
+
if (ka.length != kb.length)
|
1696
|
+
return false;
|
1697
|
+
//the same set of keys (although not necessarily the same order),
|
1698
|
+
ka.sort();
|
1699
|
+
kb.sort();
|
1700
|
+
//~~~cheap key test
|
1701
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
1702
|
+
if (ka[i] != kb[i])
|
1703
|
+
return false;
|
1704
|
+
}
|
1705
|
+
//equivalent values for every corresponding key, and
|
1706
|
+
//~~~possibly expensive deep test
|
1707
|
+
for (i = ka.length - 1; i >= 0; i--) {
|
1708
|
+
key = ka[i];
|
1709
|
+
if (!_deepEqual(a[key], b[key])) return false;
|
1710
|
+
}
|
1711
|
+
return true;
|
1712
|
+
}
|
1713
|
+
}); // module: utils/eql.js
|
1714
|
+
|
1715
|
+
require.register("utils/inspect.js", function(module, exports, require){
|
1716
|
+
// This is (almost) directly from Node.js utils
|
1717
|
+
// https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
|
1718
|
+
|
1719
|
+
module.exports = inspect;
|
1720
|
+
|
1721
|
+
/**
|
1722
|
+
* Echos the value of a value. Trys to print the value out
|
1723
|
+
* in the best way possible given the different types.
|
1724
|
+
*
|
1725
|
+
* @param {Object} obj The object to print out.
|
1726
|
+
* @param {Boolean} showHidden Flag that shows hidden (not enumerable)
|
1727
|
+
* properties of objects.
|
1728
|
+
* @param {Number} depth Depth in which to descend in object. Default is 2.
|
1729
|
+
* @param {Boolean} colors Flag to turn on ANSI escape codes to color the
|
1730
|
+
* output. Default is false (no coloring).
|
1731
|
+
*/
|
1732
|
+
function inspect(obj, showHidden, depth, colors) {
|
1733
|
+
var ctx = {
|
1734
|
+
showHidden: showHidden,
|
1735
|
+
seen: [],
|
1736
|
+
stylize: function (str) { return str; }
|
1737
|
+
};
|
1738
|
+
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
|
1739
|
+
}
|
1740
|
+
|
1741
|
+
function formatValue(ctx, value, recurseTimes) {
|
1742
|
+
// Provide a hook for user-specified inspect functions.
|
1743
|
+
// Check that value is an object with an inspect function on it
|
1744
|
+
if (value && typeof value.inspect === 'function' &&
|
1745
|
+
// Filter out the util module, it's inspect function is special
|
1746
|
+
value.inspect !== exports.inspect &&
|
1747
|
+
// Also filter out any prototype objects using the circular check.
|
1748
|
+
!(value.constructor && value.constructor.prototype === value)) {
|
1749
|
+
return value.inspect(recurseTimes);
|
1750
|
+
}
|
1751
|
+
|
1752
|
+
// Primitive types cannot have properties
|
1753
|
+
var primitive = formatPrimitive(ctx, value);
|
1754
|
+
if (primitive) {
|
1755
|
+
return primitive;
|
1756
|
+
}
|
1757
|
+
|
1758
|
+
// Look up the keys of the object.
|
1759
|
+
var visibleKeys = Object.keys(value);
|
1760
|
+
var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
|
1761
|
+
|
1762
|
+
// Some type of object without properties can be shortcutted.
|
1763
|
+
if (keys.length === 0) {
|
1764
|
+
if (typeof value === 'function') {
|
1765
|
+
var name = value.name ? ': ' + value.name : '';
|
1766
|
+
return ctx.stylize('[Function' + name + ']', 'special');
|
1767
|
+
}
|
1768
|
+
if (isRegExp(value)) {
|
1769
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
1770
|
+
}
|
1771
|
+
if (isDate(value)) {
|
1772
|
+
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
|
1773
|
+
}
|
1774
|
+
if (isError(value)) {
|
1775
|
+
return formatError(value);
|
1776
|
+
}
|
1777
|
+
}
|
1778
|
+
|
1779
|
+
var base = '', array = false, braces = ['{', '}'];
|
1780
|
+
|
1781
|
+
// Make Array say that they are Array
|
1782
|
+
if (isArray(value)) {
|
1783
|
+
array = true;
|
1784
|
+
braces = ['[', ']'];
|
1785
|
+
}
|
1786
|
+
|
1787
|
+
// Make functions say that they are functions
|
1788
|
+
if (typeof value === 'function') {
|
1789
|
+
var n = value.name ? ': ' + value.name : '';
|
1790
|
+
base = ' [Function' + n + ']';
|
1791
|
+
}
|
1792
|
+
|
1793
|
+
// Make RegExps say that they are RegExps
|
1794
|
+
if (isRegExp(value)) {
|
1795
|
+
base = ' ' + RegExp.prototype.toString.call(value);
|
1796
|
+
}
|
1797
|
+
|
1798
|
+
// Make dates with properties first say the date
|
1799
|
+
if (isDate(value)) {
|
1800
|
+
base = ' ' + Date.prototype.toUTCString.call(value);
|
1801
|
+
}
|
1802
|
+
|
1803
|
+
// Make error with message first say the error
|
1804
|
+
if (isError(value)) {
|
1805
|
+
base = ' ' + formatError(value);
|
1806
|
+
}
|
1807
|
+
|
1808
|
+
if (keys.length === 0 && (!array || value.length == 0)) {
|
1809
|
+
return braces[0] + base + braces[1];
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
if (recurseTimes < 0) {
|
1813
|
+
if (isRegExp(value)) {
|
1814
|
+
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
|
1815
|
+
} else {
|
1816
|
+
return ctx.stylize('[Object]', 'special');
|
1817
|
+
}
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
ctx.seen.push(value);
|
1821
|
+
|
1822
|
+
var output;
|
1823
|
+
if (array) {
|
1824
|
+
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
|
1825
|
+
} else {
|
1826
|
+
output = keys.map(function(key) {
|
1827
|
+
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
|
1828
|
+
});
|
1829
|
+
}
|
1830
|
+
|
1831
|
+
ctx.seen.pop();
|
1832
|
+
|
1833
|
+
return reduceToSingleString(output, base, braces);
|
1834
|
+
}
|
1835
|
+
|
1836
|
+
|
1837
|
+
function formatPrimitive(ctx, value) {
|
1838
|
+
switch (typeof value) {
|
1839
|
+
case 'undefined':
|
1840
|
+
return ctx.stylize('undefined', 'undefined');
|
1841
|
+
|
1842
|
+
case 'string':
|
1843
|
+
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
1844
|
+
.replace(/'/g, "\\'")
|
1845
|
+
.replace(/\\"/g, '"') + '\'';
|
1846
|
+
return ctx.stylize(simple, 'string');
|
1847
|
+
|
1848
|
+
case 'number':
|
1849
|
+
return ctx.stylize('' + value, 'number');
|
1850
|
+
|
1851
|
+
case 'boolean':
|
1852
|
+
return ctx.stylize('' + value, 'boolean');
|
1853
|
+
}
|
1854
|
+
// For some reason typeof null is "object", so special case here.
|
1855
|
+
if (value === null) {
|
1856
|
+
return ctx.stylize('null', 'null');
|
1857
|
+
}
|
1858
|
+
}
|
1859
|
+
|
1860
|
+
|
1861
|
+
function formatError(value) {
|
1862
|
+
return '[' + Error.prototype.toString.call(value) + ']';
|
1863
|
+
}
|
1864
|
+
|
1865
|
+
|
1866
|
+
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
|
1867
|
+
var output = [];
|
1868
|
+
for (var i = 0, l = value.length; i < l; ++i) {
|
1869
|
+
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
|
1870
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
1871
|
+
String(i), true));
|
1872
|
+
} else {
|
1873
|
+
output.push('');
|
1874
|
+
}
|
1875
|
+
}
|
1876
|
+
keys.forEach(function(key) {
|
1877
|
+
if (!key.match(/^\d+$/)) {
|
1878
|
+
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
|
1879
|
+
key, true));
|
1880
|
+
}
|
1881
|
+
});
|
1882
|
+
return output;
|
1883
|
+
}
|
1884
|
+
|
1885
|
+
|
1886
|
+
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
|
1887
|
+
var name, str;
|
1888
|
+
if (value.__lookupGetter__) {
|
1889
|
+
if (value.__lookupGetter__(key)) {
|
1890
|
+
if (value.__lookupSetter__(key)) {
|
1891
|
+
str = ctx.stylize('[Getter/Setter]', 'special');
|
1892
|
+
} else {
|
1893
|
+
str = ctx.stylize('[Getter]', 'special');
|
1894
|
+
}
|
1895
|
+
} else {
|
1896
|
+
if (value.__lookupSetter__(key)) {
|
1897
|
+
str = ctx.stylize('[Setter]', 'special');
|
1898
|
+
}
|
1899
|
+
}
|
1900
|
+
}
|
1901
|
+
if (visibleKeys.indexOf(key) < 0) {
|
1902
|
+
name = '[' + key + ']';
|
1903
|
+
}
|
1904
|
+
if (!str) {
|
1905
|
+
if (ctx.seen.indexOf(value[key]) < 0) {
|
1906
|
+
if (recurseTimes === null) {
|
1907
|
+
str = formatValue(ctx, value[key], null);
|
1908
|
+
} else {
|
1909
|
+
str = formatValue(ctx, value[key], recurseTimes - 1);
|
1910
|
+
}
|
1911
|
+
if (str.indexOf('\n') > -1) {
|
1912
|
+
if (array) {
|
1913
|
+
str = str.split('\n').map(function(line) {
|
1914
|
+
return ' ' + line;
|
1915
|
+
}).join('\n').substr(2);
|
1916
|
+
} else {
|
1917
|
+
str = '\n' + str.split('\n').map(function(line) {
|
1918
|
+
return ' ' + line;
|
1919
|
+
}).join('\n');
|
1920
|
+
}
|
1921
|
+
}
|
1922
|
+
} else {
|
1923
|
+
str = ctx.stylize('[Circular]', 'special');
|
1924
|
+
}
|
1925
|
+
}
|
1926
|
+
if (typeof name === 'undefined') {
|
1927
|
+
if (array && key.match(/^\d+$/)) {
|
1928
|
+
return str;
|
1929
|
+
}
|
1930
|
+
name = JSON.stringify('' + key);
|
1931
|
+
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
|
1932
|
+
name = name.substr(1, name.length - 2);
|
1933
|
+
name = ctx.stylize(name, 'name');
|
1934
|
+
} else {
|
1935
|
+
name = name.replace(/'/g, "\\'")
|
1936
|
+
.replace(/\\"/g, '"')
|
1937
|
+
.replace(/(^"|"$)/g, "'");
|
1938
|
+
name = ctx.stylize(name, 'string');
|
1939
|
+
}
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
return name + ': ' + str;
|
1943
|
+
}
|
1944
|
+
|
1945
|
+
|
1946
|
+
function reduceToSingleString(output, base, braces) {
|
1947
|
+
var numLinesEst = 0;
|
1948
|
+
var length = output.reduce(function(prev, cur) {
|
1949
|
+
numLinesEst++;
|
1950
|
+
if (cur.indexOf('\n') >= 0) numLinesEst++;
|
1951
|
+
return prev + cur.length + 1;
|
1952
|
+
}, 0);
|
1953
|
+
|
1954
|
+
if (length > 60) {
|
1955
|
+
return braces[0] +
|
1956
|
+
(base === '' ? '' : base + '\n ') +
|
1957
|
+
' ' +
|
1958
|
+
output.join(',\n ') +
|
1959
|
+
' ' +
|
1960
|
+
braces[1];
|
1961
|
+
}
|
1962
|
+
|
1963
|
+
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
|
1964
|
+
}
|
1965
|
+
|
1966
|
+
function isArray(ar) {
|
1967
|
+
return Array.isArray(ar) ||
|
1968
|
+
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
|
1969
|
+
}
|
1970
|
+
|
1971
|
+
function isRegExp(re) {
|
1972
|
+
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
|
1973
|
+
}
|
1974
|
+
|
1975
|
+
function isDate(d) {
|
1976
|
+
return typeof d === 'object' && objectToString(d) === '[object Date]';
|
1977
|
+
}
|
1978
|
+
|
1979
|
+
function isError(e) {
|
1980
|
+
return typeof e === 'object' && objectToString(e) === '[object Error]';
|
1981
|
+
}
|
1982
|
+
|
1983
|
+
function objectToString(o) {
|
1984
|
+
return Object.prototype.toString.call(o);
|
1985
|
+
}
|
1986
|
+
}); // module: utils/inspect.js
|
1987
|
+
|
1988
|
+
|
1989
|
+
return require('chai');
|
1990
|
+
});
|