faker 1.0.0 → 6.6.6

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faker might be problematic. Click here for more details.

Files changed (60) hide show
  1. package/.eslintrc +54 -0
  2. package/.gitattributes +1 -0
  3. package/.github/FUNDING.yml +12 -0
  4. package/.travis.yml +7 -3
  5. package/.versions +23 -0
  6. package/Readme.md +1 -46
  7. package/package.json +70 -23
  8. package/.jshintrc +0 -87
  9. package/.npmignore +0 -16
  10. package/BUILD/BUILD.js +0 -139
  11. package/BUILD/Mustache.js +0 -296
  12. package/BUILD/docs.js +0 -62
  13. package/BUILD/main.js +0 -60
  14. package/MIT-LICENSE.txt +0 -20
  15. package/Makefile +0 -26
  16. package/examples/bigDataSet.json +0 -1
  17. package/examples/browser_test.html +0 -40
  18. package/examples/dataSet.json +0 -1
  19. package/examples/index.html +0 -77
  20. package/examples/js/faker.js +0 -730
  21. package/examples/js/jquery.js +0 -154
  22. package/examples/js/prettyPrint.js +0 -712
  23. package/examples/library_test.js +0 -9
  24. package/examples/node_generateSet.js +0 -20
  25. package/examples/node_min_test.js +0 -9
  26. package/faker.js +0 -730
  27. package/index.js +0 -31
  28. package/lib/address.js +0 -100
  29. package/lib/company.js +0 -36
  30. package/lib/date.js +0 -42
  31. package/lib/definitions.js +0 -1398
  32. package/lib/helpers.js +0 -124
  33. package/lib/image.js +0 -58
  34. package/lib/internet.js +0 -53
  35. package/lib/lorem.js +0 -45
  36. package/lib/name.js +0 -34
  37. package/lib/phone_number.js +0 -16
  38. package/lib/random.js +0 -106
  39. package/lib/tree.js +0 -69
  40. package/lib/version.js +0 -0
  41. package/logo.png +0 -0
  42. package/minfaker.js +0 -35
  43. package/test/address.unit.js +0 -293
  44. package/test/all.functional.js +0 -47
  45. package/test/browser.unit.html +0 -28
  46. package/test/company.unit.js +0 -110
  47. package/test/date.unit.js +0 -65
  48. package/test/helpers.unit.js +0 -62
  49. package/test/image.unit.js +0 -108
  50. package/test/internet.unit.js +0 -92
  51. package/test/lorem.unit.js +0 -178
  52. package/test/mocha.opts +0 -5
  53. package/test/name.unit.js +0 -87
  54. package/test/phone_number.unit.js +0 -29
  55. package/test/run.js +0 -68
  56. package/test/support/chai.js +0 -3403
  57. package/test/support/sinon-1.5.2.js +0 -4153
  58. package/test/support/walk_dir.js +0 -43
  59. package/test/tree.unit.js +0 -108
  60. /package/{.jshintignore → .eslintignore} +0 -0
@@ -1,3403 +0,0 @@
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
- * http://chaijs.com
57
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
58
- * MIT Licensed
59
- */
60
-
61
-
62
- /*!
63
- * Module dependencies.
64
- */
65
-
66
- var AssertionError = require('./browser/error')
67
- , toString = Object.prototype.toString
68
- , util = require('./utils')
69
- , flag = util.flag;
70
-
71
- /*!
72
- * Module export.
73
- */
74
-
75
- module.exports = Assertion;
76
-
77
-
78
- /*!
79
- * Assertion Constructor
80
- *
81
- * Creates object for chaining.
82
- *
83
- * @api private
84
- */
85
-
86
- function Assertion (obj, msg, stack) {
87
- flag(this, 'ssfi', stack || arguments.callee);
88
- flag(this, 'object', obj);
89
- flag(this, 'message', msg);
90
- }
91
-
92
- /*!
93
- * ### Assertion.includeStack
94
- *
95
- * User configurable property, influences whether stack trace
96
- * is included in Assertion error message. Default of false
97
- * suppresses stack trace in the error message
98
- *
99
- * Assertion.includeStack = true; // enable stack on error
100
- *
101
- * @api public
102
- */
103
-
104
- Assertion.includeStack = false;
105
-
106
- Assertion.addProperty = function (name, fn) {
107
- util.addProperty(this.prototype, name, fn);
108
- };
109
-
110
- Assertion.addMethod = function (name, fn) {
111
- util.addMethod(this.prototype, name, fn);
112
- };
113
-
114
- Assertion.addChainableMethod = function (name, fn, chainingBehavior) {
115
- util.addChainableMethod(this.prototype, name, fn, chainingBehavior);
116
- };
117
-
118
- Assertion.overwriteProperty = function (name, fn) {
119
- util.overwriteProperty(this.prototype, name, fn);
120
- };
121
-
122
- Assertion.overwriteMethod = function (name, fn) {
123
- util.overwriteMethod(this.prototype, name, fn);
124
- };
125
-
126
- /*!
127
- * ### .assert(expression, message, negateMessage, expected, actual)
128
- *
129
- * Executes an expression and check expectations. Throws AssertionError for reporting if test doesn't pass.
130
- *
131
- * @name assert
132
- * @param {Philosophical} expression to be tested
133
- * @param {String} message to display if fails
134
- * @param {String} negatedMessage to display if negated expression fails
135
- * @param {Mixed} expected value (remember to check for negation)
136
- * @param {Mixed} actual (optional) will default to `this.obj`
137
- * @api private
138
- */
139
-
140
- Assertion.prototype.assert = function (expr, msg, negateMsg, expected, _actual) {
141
- var msg = util.getMessage(this, arguments)
142
- , actual = util.getActual(this, arguments)
143
- , ok = util.test(this, arguments);
144
-
145
- if (!ok) {
146
- throw new AssertionError({
147
- message: msg
148
- , actual: actual
149
- , expected: expected
150
- , stackStartFunction: (Assertion.includeStack) ? this.assert : flag(this, 'ssfi')
151
- });
152
- }
153
- };
154
-
155
- /*!
156
- *
157
- * ### ._obj
158
- *
159
- * Quick reference to stored `actual` value for plugin developers.
160
- *
161
- * @api private
162
- */
163
-
164
- Object.defineProperty(Assertion.prototype, '_obj',
165
- { get: function () {
166
- return flag(this, 'object');
167
- }
168
- , set: function (val) {
169
- flag(this, 'object', val);
170
- }
171
- });
172
-
173
- /**
174
- * ### Language Chains
175
- *
176
- * The following are provide as chainable getters to
177
- * improve the readability of your assertions. They
178
- * do not provide an testing capability unless they
179
- * have been overwritten by a plugin.
180
- *
181
- * **Chains**
182
- *
183
- * - to
184
- * - be
185
- * - been
186
- * - is
187
- * - and
188
- * - have
189
- * - with
190
- *
191
- * @name language chains
192
- * @api public
193
- */
194
-
195
- [ 'to', 'be', 'been'
196
- , 'is', 'and', 'have'
197
- , 'with' ].forEach(function (chain) {
198
- Object.defineProperty(Assertion.prototype, chain,
199
- { get: function () {
200
- return this;
201
- }
202
- , configurable: true
203
- });
204
- });
205
-
206
- /**
207
- * ### .not
208
- *
209
- * Negates any of assertions following in the chain.
210
- *
211
- * expect(foo).to.not.equal('bar');
212
- * expect(goodFn).to.not.throw(Error);
213
- * expect({ foo: 'baz' }).to.have.property('foo')
214
- * .and.not.equal('bar');
215
- *
216
- * @name not
217
- * @api public
218
- */
219
-
220
- Object.defineProperty(Assertion.prototype, 'not',
221
- { get: function () {
222
- flag(this, 'negate', true);
223
- return this;
224
- }
225
- , configurable: true
226
- });
227
-
228
- /**
229
- * ### .deep
230
- *
231
- * Sets the `deep` flag, later used by the `equal` and
232
- * `property` assertions.
233
- *
234
- * expect(foo).to.deep.equal({ bar: 'baz' });
235
- * expect({ foo: { bar: { baz: 'quux' } } })
236
- * .to.have.deep.property('foo.bar.baz', 'quux');
237
- *
238
- * @name deep
239
- * @api public
240
- */
241
-
242
- Object.defineProperty(Assertion.prototype, 'deep',
243
- { get: function () {
244
- flag(this, 'deep', true);
245
- return this;
246
- }
247
- , configurable: true
248
- });
249
-
250
- /**
251
- * ### .a(type)
252
- *
253
- * The `a` and `an` assertions are aliases that can be
254
- * used either as language chains or to assert a value's
255
- * type (as revealed by `Object.prototype.toString`).
256
- *
257
- * // typeof
258
- * expect('test').to.be.a('string');
259
- * expect({ foo: 'bar' }).to.be.an('object');
260
- * expect(null).to.be.a('null');
261
- * expect(undefined).to.be.an('undefined');
262
- *
263
- * // language chain
264
- * expect(foo).to.be.an.instanceof(Foo);
265
- *
266
- * @name a
267
- * @alias an
268
- * @param {String} type
269
- * @api public
270
- */
271
-
272
- function an(type) {
273
- var obj = flag(this, 'object')
274
- , klassStart = type.charAt(0).toUpperCase()
275
- , klass = klassStart + type.slice(1)
276
- , article = ~[ 'A', 'E', 'I', 'O', 'U' ].indexOf(klassStart) ? 'an ' : 'a ';
277
-
278
- this.assert(
279
- '[object ' + klass + ']' === toString.call(obj)
280
- , 'expected #{this} to be ' + article + type
281
- , 'expected #{this} not to be ' + article + type
282
- , '[object ' + klass + ']'
283
- , toString.call(obj)
284
- );
285
- }
286
-
287
- Assertion.addChainableMethod('an', an);
288
- Assertion.addChainableMethod('a', an);
289
-
290
- /**
291
- * ### .include(value)
292
- *
293
- * The `include` and `contain` assertions can be used as either property
294
- * based language chains or as methods to assert the inclusion of an object
295
- * in an array or a substring in a string. When used as language chains,
296
- * they toggle the `contain` flag for the `keys` assertion.
297
- *
298
- * expect([1,2,3]).to.include(2);
299
- * expect('foobar').to.contain('foo');
300
- * expect({ foo: 'bar', hello: 'universe' }).to.include.keys('foo');
301
- *
302
- * @name include
303
- * @alias contain
304
- * @param {Object|String|Number} obj
305
- * @api public
306
- */
307
-
308
- function includeChainingBehavior () {
309
- flag(this, 'contains', true);
310
- }
311
-
312
- function include (val) {
313
- var obj = flag(this, 'object')
314
- this.assert(
315
- ~obj.indexOf(val)
316
- , 'expected #{this} to include ' + util.inspect(val)
317
- , 'expected #{this} to not include ' + util.inspect(val));
318
- }
319
-
320
- Assertion.addChainableMethod('include', include, includeChainingBehavior);
321
- Assertion.addChainableMethod('contain', include, includeChainingBehavior);
322
-
323
- /**
324
- * ### .ok
325
- *
326
- * Asserts that the target is truthy.
327
- *
328
- * expect('everthing').to.be.ok;
329
- * expect(1).to.be.ok;
330
- * expect(false).to.not.be.ok;
331
- * expect(undefined).to.not.be.ok;
332
- * expect(null).to.not.be.ok;
333
- *
334
- * @name ok
335
- * @api public
336
- */
337
-
338
- Object.defineProperty(Assertion.prototype, 'ok',
339
- { get: function () {
340
- this.assert(
341
- flag(this, 'object')
342
- , 'expected #{this} to be truthy'
343
- , 'expected #{this} to be falsy');
344
-
345
- return this;
346
- }
347
- , configurable: true
348
- });
349
-
350
- /**
351
- * ### .true
352
- *
353
- * Asserts that the target is `true`.
354
- *
355
- * expect(true).to.be.true;
356
- * expect(1).to.not.be.true;
357
- *
358
- * @name true
359
- * @api public
360
- */
361
-
362
- Object.defineProperty(Assertion.prototype, 'true',
363
- { get: function () {
364
- this.assert(
365
- true === flag(this, 'object')
366
- , 'expected #{this} to be true'
367
- , 'expected #{this} to be false'
368
- , this.negate ? false : true
369
- );
370
-
371
- return this;
372
- }
373
- , configurable: true
374
- });
375
-
376
- /**
377
- * ### .false
378
- *
379
- * Asserts that the target is `false`.
380
- *
381
- * expect(false).to.be.false;
382
- * expect(0).to.not.be.false;
383
- *
384
- * @name false
385
- * @api public
386
- */
387
-
388
- Object.defineProperty(Assertion.prototype, 'false',
389
- { get: function () {
390
- this.assert(
391
- false === flag(this, 'object')
392
- , 'expected #{this} to be false'
393
- , 'expected #{this} to be true'
394
- , this.negate ? true : false
395
- );
396
-
397
- return this;
398
- }
399
- , configurable: true
400
- });
401
-
402
- /**
403
- * ### .null
404
- *
405
- * Asserts that the target is `null`.
406
- *
407
- * expect(null).to.be.null;
408
- * expect(undefined).not.to.be.null;
409
- *
410
- * @name null
411
- * @api public
412
- */
413
-
414
- Object.defineProperty(Assertion.prototype, 'null',
415
- { get: function () {
416
- this.assert(
417
- null === flag(this, 'object')
418
- , 'expected #{this} to be null'
419
- , 'expected #{this} not to be null'
420
- , this.negate ? false : true
421
- );
422
-
423
- return this;
424
- }
425
- , configurable: true
426
- });
427
-
428
- /**
429
- * ### .undefined
430
- *
431
- * Asserts that the target is `undefined`.
432
- *
433
- * expect(undefined).to.be.undefined;
434
- * expect(null).to.not.be.undefined;
435
- *
436
- * @name undefined
437
- * @api public
438
- */
439
-
440
- Object.defineProperty(Assertion.prototype, 'undefined',
441
- { get: function () {
442
- this.assert(
443
- undefined === flag(this, 'object')
444
- , 'expected #{this} to be undefined'
445
- , 'expected #{this} not to be undefined'
446
- , this.negate ? false : true
447
- );
448
-
449
- return this;
450
- }
451
- , configurable: true
452
- });
453
-
454
- /**
455
- * ### .exist
456
- *
457
- * Asserts that the target is neither `null` nor `undefined`.
458
- *
459
- * var foo = 'hi'
460
- * , bar = null
461
- * , baz;
462
- *
463
- * expect(foo).to.exist;
464
- * expect(bar).to.not.exist;
465
- * expect(baz).to.not.exist;
466
- *
467
- * @name exist
468
- * @api public
469
- */
470
-
471
- Object.defineProperty(Assertion.prototype, 'exist',
472
- { get: function () {
473
- this.assert(
474
- null != flag(this, 'object')
475
- , 'expected #{this} to exist'
476
- , 'expected #{this} to not exist'
477
- );
478
-
479
- return this;
480
- }
481
- , configurable: true
482
- });
483
-
484
- /**
485
- * ### .empty
486
- *
487
- * Asserts that the target's length is `0`. For arrays, it checks
488
- * the `length` property. For objects, it gets the count of
489
- * enumerable keys.
490
- *
491
- * expect([]).to.be.empty;
492
- * expect('').to.be.empty;
493
- * expect({}).to.be.empty;
494
- *
495
- * @name empty
496
- * @api public
497
- */
498
-
499
- Object.defineProperty(Assertion.prototype, 'empty',
500
- { get: function () {
501
- var obj = flag(this, 'object')
502
- , expected = obj;
503
-
504
- if (Array.isArray(obj) || 'string' === typeof object) {
505
- expected = obj.length;
506
- } else if (typeof obj === 'object') {
507
- expected = Object.keys(obj).length;
508
- }
509
-
510
- this.assert(
511
- !expected
512
- , 'expected #{this} to be empty'
513
- , 'expected #{this} not to be empty');
514
-
515
- return this;
516
- }
517
- , configurable: true
518
- });
519
-
520
- /**
521
- * ### .arguments
522
- *
523
- * Asserts that the target is an arguments object.
524
- *
525
- * function test () {
526
- * expect(arguments).to.be.arguments;
527
- * }
528
- *
529
- * @name arguments
530
- * @alias Arguments
531
- * @api public
532
- */
533
-
534
- function checkArguments () {
535
- var obj = flag(this, 'object')
536
- , type = Object.prototype.toString.call(obj);
537
- this.assert(
538
- '[object Arguments]' === type
539
- , 'expected #{this} to be arguments but got ' + type
540
- , 'expected #{this} to not be arguments'
541
- );
542
- }
543
-
544
- Assertion.addProperty('arguments', checkArguments);
545
- Assertion.addProperty('Arguments', checkArguments);
546
-
547
- /**
548
- * ### .equal(value)
549
- *
550
- * Asserts that the target is strictly equal (`===`) to `value`.
551
- * Alternately, if the `deep` flag is set, asserts that
552
- * the target is deeply equal to `value`.
553
- *
554
- * expect('hello').to.equal('hello');
555
- * expect(42).to.equal(42);
556
- * expect(1).to.not.equal(true);
557
- * expect({ foo: 'bar' }).to.not.equal({ foo: 'bar' });
558
- * expect({ foo: 'bar' }).to.deep.equal({ foo: 'bar' });
559
- *
560
- * @name equal
561
- * @param {Mixed} value
562
- * @api public
563
- */
564
-
565
- Assertion.prototype.equal = function (val) {
566
- var obj = flag(this, 'object');
567
- if (flag(this, 'deep')) {
568
- return this.eql(val);
569
- } else {
570
- this.assert(
571
- val === obj
572
- , 'expected #{this} to equal #{exp}'
573
- , 'expected #{this} to not equal #{exp}'
574
- , val);
575
- }
576
-
577
- return this;
578
- };
579
-
580
- /**
581
- * ### .eql(value)
582
- *
583
- * Asserts that the target is deeply equal to `value`.
584
- *
585
- * expect({ foo: 'bar' }).to.eql({ foo: 'bar' });
586
- * expect([ 1, 2, 3 ]).to.eql([ 1, 2, 3 ]);
587
- *
588
- * @name eql
589
- * @param {Mixed} value
590
- * @api public
591
- */
592
-
593
- Assertion.prototype.eql = function (obj) {
594
- this.assert(
595
- util.eql(obj, flag(this, 'object'))
596
- , 'expected #{this} to deeply equal #{exp}'
597
- , 'expected #{this} to not deeply equal #{exp}'
598
- , obj );
599
-
600
- return this;
601
- };
602
-
603
- /**
604
- * ### .above(value)
605
- *
606
- * Asserts that the target is greater than `value`.
607
- *
608
- * expect(10).to.be.above(5);
609
- *
610
- * @name above
611
- * @alias gt
612
- * @param {Number} value
613
- * @api public
614
- */
615
-
616
- Assertion.prototype.above = function (val) {
617
- this.assert(
618
- flag(this, 'object') > val
619
- , 'expected #{this} to be above ' + val
620
- , 'expected #{this} to be below ' + val);
621
-
622
- return this;
623
- };
624
-
625
- /**
626
- * ### .below(value)
627
- *
628
- * Asserts that the target is less than `value`.
629
- *
630
- * expect(5).to.be.below(10);
631
- *
632
- * @name below
633
- * @alias lt
634
- * @param {Number} value
635
- * @api public
636
- */
637
-
638
- Assertion.prototype.below = function (val) {
639
- this.assert(
640
- flag(this, 'object') < val
641
- , 'expected #{this} to be below ' + val
642
- , 'expected #{this} to be above ' + val);
643
-
644
- return this;
645
- };
646
-
647
- /**
648
- * ### .within(start, finish)
649
- *
650
- * Asserts that the target is within a range.
651
- *
652
- * expect(7).to.be.within(5,10);
653
- *
654
- * @name within
655
- * @param {Number} start lowerbound inclusive
656
- * @param {Number} finish upperbound inclusive
657
- * @api public
658
- */
659
-
660
- Assertion.prototype.within = function (start, finish) {
661
- var obj = flag(this, 'object')
662
- , range = start + '..' + finish;
663
-
664
- this.assert(
665
- obj >= start && obj <= finish
666
- , 'expected #{this} to be within ' + range
667
- , 'expected #{this} to not be within ' + range);
668
-
669
- return this;
670
- };
671
-
672
- /**
673
- * ### .instanceof(constructor)
674
- *
675
- * Asserts that the target is an instance of `constructor`.
676
- *
677
- * var Tea = function (name) { this.name = name; }
678
- * , Chai = new Tea('chai');
679
- *
680
- * expect(Chai).to.be.an.instanceof(Tea);
681
- * expect([ 1, 2, 3 ]).to.be.instanceof(Array);
682
- *
683
- * @name instanceof
684
- * @param {Constructor} constructor
685
- * @alias instanceOf
686
- * @api public
687
- */
688
-
689
- Assertion.prototype.instanceOf = function (constructor) {
690
- var name = util.getName(constructor);
691
- this.assert(
692
- flag(this, 'object') instanceof constructor
693
- , 'expected #{this} to be an instance of ' + name
694
- , 'expected #{this} to not be an instance of ' + name);
695
-
696
- return this;
697
- };
698
-
699
- /**
700
- * ### .property(name, [value])
701
- *
702
- * Asserts that the target has a property `name`, optionally asserting that
703
- * the value of that property is strictly equal to `value`.
704
- * If the `deep` flag is set, you can use dot- and bracket-notation for deep
705
- * references into objects and arrays.
706
- *
707
- * // simple referencing
708
- * var obj = { foo: 'bar' };
709
- * expect(obj).to.have.property('foo');
710
- * expect(obj).to.have.property('foo', 'bar');
711
- * expect(obj).to.have.property('foo').to.be.a('string');
712
- *
713
- * // deep referencing
714
- * var deepObj = {
715
- * green: { tea: 'matcha' }
716
- * , teas: [ 'chai', 'matcha', { tea: 'konacha' } ]
717
- * };
718
-
719
- * expect(deepObj).to.have.deep.property('green.tea', 'matcha');
720
- * expect(deepObj).to.have.deep.property('teas[1]', 'matcha');
721
- * expect(deepObj).to.have.deep.property('teas[2].tea', 'konacha');
722
- *
723
- * @name property
724
- * @param {String} name
725
- * @param {Mixed} value (optional)
726
- * @returns value of property for chaining
727
- * @api public
728
- */
729
-
730
- Assertion.prototype.property = function (name, val) {
731
- var obj = flag(this, 'object')
732
- , value = flag(this, 'deep') ? util.getPathValue(name, obj) : obj[name]
733
- , descriptor = flag(this, 'deep') ? 'deep property ' : 'property '
734
- , negate = flag(this, 'negate');
735
-
736
- if (negate && undefined !== val) {
737
- if (undefined === value) {
738
- throw new Error(util.inspect(obj) + ' has no ' + descriptor + util.inspect(name));
739
- }
740
- } else {
741
- this.assert(
742
- undefined !== value
743
- , 'expected #{this} to have a ' + descriptor + util.inspect(name)
744
- , 'expected #{this} to not have ' + descriptor + util.inspect(name));
745
- }
746
-
747
- if (undefined !== val) {
748
- this.assert(
749
- val === value
750
- , 'expected #{this} to have a ' + descriptor + util.inspect(name) + ' of #{exp}, but got #{act}'
751
- , 'expected #{this} to not have a ' + descriptor + util.inspect(name) + ' of #{act}'
752
- , val
753
- , value
754
- );
755
- }
756
-
757
- flag(this, 'object', value);
758
- return this;
759
- };
760
-
761
- /**
762
- * ### .ownProperty(name)
763
- *
764
- * Asserts that the target has an own property `name`.
765
- *
766
- * expect('test').to.have.ownProperty('length');
767
- *
768
- * @name ownProperty
769
- * @alias haveOwnProperty
770
- * @param {String} name
771
- * @api public
772
- */
773
-
774
- Assertion.prototype.ownProperty = function (name) {
775
- var obj = flag(this, 'object');
776
- this.assert(
777
- obj.hasOwnProperty(name)
778
- , 'expected #{this} to have own property ' + util.inspect(name)
779
- , 'expected #{this} to not have own property ' + util.inspect(name));
780
- return this;
781
- };
782
-
783
- /**
784
- * ### .length(value)
785
- *
786
- * Asserts that the target's `length` property has the expected value.
787
- *
788
- * expect([1,2,3]).to.have.length(3);
789
- * expect('foobar').to.have.length(6);
790
- *
791
- * @name length
792
- * @alias lengthOf
793
- * @param {Number} length
794
- * @api public
795
- */
796
-
797
- Assertion.prototype.length = function (n) {
798
- var obj = flag(this, 'object');
799
- new Assertion(obj).to.have.property('length');
800
- var len = obj.length;
801
-
802
- this.assert(
803
- len == n
804
- , 'expected #{this} to have a length of #{exp} but got #{act}'
805
- , 'expected #{this} to not have a length of #{act}'
806
- , n
807
- , len
808
- );
809
-
810
- return this;
811
- };
812
-
813
- /**
814
- * ### .match(regexp)
815
- *
816
- * Asserts that the target matches a regular expression.
817
- *
818
- * expect('foobar').to.match(/^foo/);
819
- *
820
- * @name match
821
- * @param {RegExp} RegularExpression
822
- * @api public
823
- */
824
-
825
- Assertion.prototype.match = function (re) {
826
- var obj = flag(this, 'object');
827
- this.assert(
828
- re.exec(obj)
829
- , 'expected #{this} to match ' + re
830
- , 'expected #{this} not to match ' + re);
831
-
832
- return this;
833
- };
834
-
835
-
836
- /**
837
- * ### .string(string)
838
- *
839
- * Asserts that the string target contains another string.
840
- *
841
- * expect('foobar').to.have.string('bar');
842
- *
843
- * @name string
844
- * @param {String} string
845
- * @api public
846
- */
847
-
848
- Assertion.prototype.string = function (str) {
849
- var obj = flag(this, 'object');
850
- new Assertion(obj).is.a('string');
851
-
852
- this.assert(
853
- ~obj.indexOf(str)
854
- , 'expected #{this} to contain ' + util.inspect(str)
855
- , 'expected #{this} to not contain ' + util.inspect(str));
856
-
857
- return this;
858
- };
859
-
860
- /**
861
- * ### .keys(key1, [key2], [...])
862
- *
863
- * Asserts that the target has exactly the given keys, or
864
- * asserts the inclusion of some keys when using the
865
- * `include` or `contain` modifiers.
866
- *
867
- * expect({ foo: 1, bar: 2 }).to.have.keys(['foo', 'bar']);
868
- * expect({ foo: 1, bar: 2, baz: 3 }).to.contain.keys('foo', 'bar');
869
- *
870
- * @name keys
871
- * @alias key
872
- * @param {String...|Array} keys
873
- * @api public
874
- */
875
-
876
- Assertion.prototype.keys = function(keys) {
877
- var obj = flag(this, 'object')
878
- , str
879
- , ok = true;
880
-
881
- keys = keys instanceof Array
882
- ? keys
883
- : Array.prototype.slice.call(arguments);
884
-
885
- if (!keys.length) throw new Error('keys required');
886
-
887
- var actual = Object.keys(obj)
888
- , len = keys.length;
889
-
890
- // Inclusion
891
- ok = keys.every(function(key){
892
- return ~actual.indexOf(key);
893
- });
894
-
895
- // Strict
896
- if (!flag(this, 'negate') && !flag(this, 'contains')) {
897
- ok = ok && keys.length == actual.length;
898
- }
899
-
900
- // Key string
901
- if (len > 1) {
902
- keys = keys.map(function(key){
903
- return util.inspect(key);
904
- });
905
- var last = keys.pop();
906
- str = keys.join(', ') + ', and ' + last;
907
- } else {
908
- str = util.inspect(keys[0]);
909
- }
910
-
911
- // Form
912
- str = (len > 1 ? 'keys ' : 'key ') + str;
913
-
914
- // Have / include
915
- str = (flag(this, 'contains') ? 'contain ' : 'have ') + str;
916
-
917
- // Assertion
918
- this.assert(
919
- ok
920
- , 'expected #{this} to ' + str
921
- , 'expected #{this} to not ' + str
922
- , keys
923
- , Object.keys(obj)
924
- );
925
-
926
- return this;
927
- }
928
-
929
- /**
930
- * ### .throw(constructor)
931
- *
932
- * Asserts that the function target will throw a specific error, or specific type of error
933
- * (as determined using `instanceof`), optionally with a RegExp or string inclusion test
934
- * for the error's message.
935
- *
936
- * var err = new ReferenceError('This is a bad function.');
937
- * var fn = function () { throw err; }
938
- * expect(fn).to.throw(ReferenceError);
939
- * expect(fn).to.throw(Error);
940
- * expect(fn).to.throw(/bad function/);
941
- * expect(fn).to.not.throw('good function');
942
- * expect(fn).to.throw(ReferenceError, /bad function/);
943
- * expect(fn).to.throw(err);
944
- * expect(fn).to.not.throw(new RangeError('Out of range.'));
945
- *
946
- * Please note that when a throw expectation is negated, it will check each
947
- * parameter independently, starting with error constructor type. The appropriate way
948
- * to check for the existence of a type of error but for a message that does not match
949
- * is to use `and`.
950
- *
951
- * expect(fn).to.throw(ReferenceError)
952
- * .and.not.throw(/good function/);
953
- *
954
- * @name throw
955
- * @alias throws
956
- * @alias Throw
957
- * @param {ErrorConstructor} constructor
958
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
959
- * @api public
960
- */
961
-
962
- Assertion.prototype.Throw = function (constructor, msg) {
963
- var obj = flag(this, 'object');
964
- new Assertion(obj).is.a('function');
965
-
966
- var thrown = false
967
- , desiredError = null
968
- , name = null;
969
-
970
- if (arguments.length === 0) {
971
- msg = null;
972
- constructor = null;
973
- } else if (constructor && (constructor instanceof RegExp || 'string' === typeof constructor)) {
974
- msg = constructor;
975
- constructor = null;
976
- } else if (constructor && constructor instanceof Error) {
977
- desiredError = constructor;
978
- constructor = null;
979
- msg = null;
980
- } else if (typeof constructor === 'function') {
981
- name = (new constructor()).name;
982
- } else {
983
- constructor = null;
984
- }
985
-
986
- try {
987
- obj();
988
- } catch (err) {
989
- // first, check desired error
990
- if (desiredError) {
991
- this.assert(
992
- err === desiredError
993
- , 'expected #{this} to throw ' + util.inspect(desiredError) + ' but ' + util.inspect(err) + ' was thrown'
994
- , 'expected #{this} to not throw ' + util.inspect(desiredError)
995
- );
996
- return this;
997
- }
998
- // next, check constructor
999
- if (constructor) {
1000
- this.assert(
1001
- err instanceof constructor
1002
- , 'expected #{this} to throw ' + name + ' but a ' + err.name + ' was thrown'
1003
- , 'expected #{this} to not throw ' + name );
1004
- if (!msg) return this;
1005
- }
1006
- // next, check message
1007
- if (err.message && msg && msg instanceof RegExp) {
1008
- this.assert(
1009
- msg.exec(err.message)
1010
- , 'expected #{this} to throw error matching ' + msg + ' but got ' + util.inspect(err.message)
1011
- , 'expected #{this} to throw error not matching ' + msg
1012
- );
1013
- return this;
1014
- } else if (err.message && msg && 'string' === typeof msg) {
1015
- this.assert(
1016
- ~err.message.indexOf(msg)
1017
- , 'expected #{this} to throw error including #{exp} but got #{act}'
1018
- , 'expected #{this} to throw error not including #{act}'
1019
- , msg
1020
- , err.message
1021
- );
1022
- return this;
1023
- } else {
1024
- thrown = true;
1025
- }
1026
- }
1027
-
1028
- var expectedThrown = name ? name : desiredError ? util.inspect(desiredError) : 'an error';
1029
-
1030
- this.assert(
1031
- thrown === true
1032
- , 'expected #{this} to throw ' + expectedThrown
1033
- , 'expected #{this} to not throw ' + expectedThrown);
1034
-
1035
- return this;
1036
- };
1037
-
1038
- /**
1039
- * ### .respondTo(method)
1040
- *
1041
- * Asserts that the object or class target will respond to a method.
1042
- *
1043
- * Klass.prototype.bar = function(){};
1044
- * expect(Klass).to.respondTo('bar');
1045
- * expect(obj).to.respondTo('bar');
1046
- *
1047
- * To check if a constructor will respond to a static function,
1048
- * set the `itself` flag.
1049
- *
1050
- * Klass.baz = function(){};
1051
- * expect(Klass).itself.to.respondTo('baz');
1052
- *
1053
- * @name respondTo
1054
- * @param {String} method
1055
- * @api public
1056
- */
1057
-
1058
- Assertion.prototype.respondTo = function (method) {
1059
- var obj = flag(this, 'object')
1060
- , itself = flag(this, 'itself')
1061
- , context = ('function' === typeof obj && !itself)
1062
- ? obj.prototype[method]
1063
- : obj[method];
1064
-
1065
- this.assert(
1066
- 'function' === typeof context
1067
- , 'expected #{this} to respond to ' + util.inspect(method)
1068
- , 'expected #{this} to not respond to ' + util.inspect(method)
1069
- , 'function'
1070
- , typeof context
1071
- );
1072
-
1073
- return this;
1074
- };
1075
-
1076
- /**
1077
- * ### .itself
1078
- *
1079
- * Sets the `itself` flag, later used by the `respondTo` assertion.
1080
- *
1081
- * function Foo() {}
1082
- * Foo.bar = function() {}
1083
- * Foo.prototype.baz = function() {}
1084
- *
1085
- * expect(Foo).itself.to.respondTo('bar');
1086
- * expect(Foo).itself.not.to.respondTo('baz');
1087
- *
1088
- * @name itself
1089
- * @api public
1090
- */
1091
- Object.defineProperty(Assertion.prototype, 'itself',
1092
- { get: function () {
1093
- flag(this, 'itself', true);
1094
- return this;
1095
- }
1096
- , configurable: true
1097
- });
1098
-
1099
- /**
1100
- * ### .satisfy(method)
1101
- *
1102
- * Asserts that the target passes a given truth test.
1103
- *
1104
- * expect(1).to.satisfy(function(num) { return num > 0; });
1105
- *
1106
- * @name satisfy
1107
- * @param {Function} matcher
1108
- * @api public
1109
- */
1110
-
1111
- Assertion.prototype.satisfy = function (matcher) {
1112
- var obj = flag(this, 'object');
1113
- this.assert(
1114
- matcher(obj)
1115
- , 'expected #{this} to satisfy ' + util.inspect(matcher)
1116
- , 'expected #{this} to not satisfy' + util.inspect(matcher)
1117
- , this.negate ? false : true
1118
- , matcher(obj)
1119
- );
1120
-
1121
- return this;
1122
- };
1123
-
1124
- /**
1125
- * ### .closeTo(expected, delta)
1126
- *
1127
- * Asserts that the target is equal `expected`, to within a +/- `delta` range.
1128
- *
1129
- * expect(1.5).to.be.closeTo(1, 0.5);
1130
- *
1131
- * @name closeTo
1132
- * @param {Number} expected
1133
- * @param {Number} delta
1134
- * @api public
1135
- */
1136
-
1137
- Assertion.prototype.closeTo = function (expected, delta) {
1138
- var obj = flag(this, 'object');
1139
- this.assert(
1140
- (obj - delta === expected) || (obj + delta === expected)
1141
- , 'expected #{this} to be close to ' + expected + ' +/- ' + delta
1142
- , 'expected #{this} not to be close to ' + expected + ' +/- ' + delta);
1143
-
1144
- return this;
1145
- };
1146
-
1147
- /*!
1148
- * Aliases.
1149
- */
1150
-
1151
- (function alias(name, as){
1152
- Assertion.prototype[as] = Assertion.prototype[name];
1153
- return alias;
1154
- })
1155
- ('equal', 'eq')
1156
- ('above', 'gt')
1157
- ('below', 'lt')
1158
- ('length', 'lengthOf')
1159
- ('keys', 'key')
1160
- ('ownProperty', 'haveOwnProperty')
1161
- ('above', 'greaterThan')
1162
- ('below', 'lessThan')
1163
- ('Throw', 'throws')
1164
- ('Throw', 'throw')
1165
- ('instanceOf', 'instanceof');
1166
-
1167
- }); // module: assertion.js
1168
-
1169
- require.register("browser/error.js", function(module, exports, require){
1170
- /*!
1171
- * chai
1172
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
1173
- * MIT Licensed
1174
- */
1175
-
1176
- module.exports = AssertionError;
1177
-
1178
- function AssertionError (options) {
1179
- options = options || {};
1180
- this.message = options.message;
1181
- this.actual = options.actual;
1182
- this.expected = options.expected;
1183
- this.operator = options.operator;
1184
-
1185
- if (options.stackStartFunction && Error.captureStackTrace) {
1186
- var stackStartFunction = options.stackStartFunction;
1187
- Error.captureStackTrace(this, stackStartFunction);
1188
- }
1189
- }
1190
-
1191
- AssertionError.prototype = Object.create(Error.prototype);
1192
- AssertionError.prototype.name = 'AssertionError';
1193
- AssertionError.prototype.constructor = AssertionError;
1194
-
1195
- AssertionError.prototype.toString = function() {
1196
- return this.message;
1197
- };
1198
-
1199
- }); // module: browser/error.js
1200
-
1201
- require.register("chai.js", function(module, exports, require){
1202
- /*!
1203
- * chai
1204
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
1205
- * MIT Licensed
1206
- */
1207
-
1208
- var used = []
1209
- , exports = module.exports = {};
1210
-
1211
- /*!
1212
- * Chai version
1213
- */
1214
-
1215
- exports.version = '1.0.4';
1216
-
1217
- /*!
1218
- * Primary `Assertion` prototype
1219
- */
1220
-
1221
- exports.Assertion = require('./assertion');
1222
-
1223
- /*!
1224
- * Assertion Error
1225
- */
1226
-
1227
- exports.AssertionError = require('./browser/error');
1228
-
1229
- /*!
1230
- * Utils for plugins (not exported)
1231
- */
1232
-
1233
- var util = require('./utils');
1234
-
1235
- /**
1236
- * # .use(function)
1237
- *
1238
- * Provides a way to extend the internals of Chai
1239
- *
1240
- * @param {Function}
1241
- * @returns {this} for chaining
1242
- * @api public
1243
- */
1244
-
1245
- exports.use = function (fn) {
1246
- if (!~used.indexOf(fn)) {
1247
- fn(this, util);
1248
- used.push(fn);
1249
- }
1250
-
1251
- return this;
1252
- };
1253
-
1254
- /*!
1255
- * Expect interface
1256
- */
1257
-
1258
- var expect = require('./interface/expect');
1259
- exports.use(expect);
1260
-
1261
- /*!
1262
- * Should interface
1263
- */
1264
-
1265
- var should = require('./interface/should');
1266
- exports.use(should);
1267
-
1268
- /*!
1269
- * Assert interface
1270
- */
1271
-
1272
- var assert = require('./interface/assert');
1273
- exports.use(assert);
1274
-
1275
- }); // module: chai.js
1276
-
1277
- require.register("interface/assert.js", function(module, exports, require){
1278
- /*!
1279
- * chai
1280
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
1281
- * MIT Licensed
1282
- */
1283
-
1284
-
1285
- module.exports = function (chai, util) {
1286
-
1287
- /*!
1288
- * Chai dependencies.
1289
- */
1290
-
1291
- var Assertion = chai.Assertion
1292
- , flag = util.flag;
1293
-
1294
- /*!
1295
- * Module export.
1296
- */
1297
-
1298
- /**
1299
- * ### assert(expression, message)
1300
- *
1301
- * Write your own test expressions.
1302
- *
1303
- * assert('foo' !== 'bar', 'foo is not bar');
1304
- * assert(Array.isArray([]), 'empty arrays are arrays');
1305
- *
1306
- * @param {Mixed} expression to test for truthiness
1307
- * @param {String} message to display on error
1308
- * @name assert
1309
- * @api public
1310
- */
1311
-
1312
- var assert = chai.assert = function (express, errmsg) {
1313
- var test = new Assertion(null);
1314
- test.assert(
1315
- express
1316
- , errmsg
1317
- , '[ negation message unavailable ]'
1318
- );
1319
- };
1320
-
1321
- /**
1322
- * ### .fail(actual, expected, [message], [operator])
1323
- *
1324
- * Throw a failure. Node.js `assert` module-compatible.
1325
- *
1326
- * @name fail
1327
- * @param {Mixed} actual
1328
- * @param {Mixed} expected
1329
- * @param {String} message
1330
- * @param {String} operator
1331
- * @api public
1332
- */
1333
-
1334
- assert.fail = function (actual, expected, message, operator) {
1335
- throw new chai.AssertionError({
1336
- actual: actual
1337
- , expected: expected
1338
- , message: message
1339
- , operator: operator
1340
- , stackStartFunction: assert.fail
1341
- });
1342
- };
1343
-
1344
- /**
1345
- * ### .ok(object, [message])
1346
- *
1347
- * Asserts that `object` is truthy.
1348
- *
1349
- * assert.ok('everything', 'everything is ok');
1350
- * assert.ok(false, 'this will fail');
1351
- *
1352
- * @name ok
1353
- * @param {Mixed} object to test
1354
- * @param {String} message
1355
- * @api public
1356
- */
1357
-
1358
- assert.ok = function (val, msg) {
1359
- new Assertion(val, msg).is.ok;
1360
- };
1361
-
1362
- /**
1363
- * ### .equal(actual, expected, [message])
1364
- *
1365
- * Asserts non-strict equality (`==`) of `actual` and `expected`.
1366
- *
1367
- * assert.equal(3, '3', '== coerces values to strings');
1368
- *
1369
- * @name equal
1370
- * @param {Mixed} actual
1371
- * @param {Mixed} expected
1372
- * @param {String} message
1373
- * @api public
1374
- */
1375
-
1376
- assert.equal = function (act, exp, msg) {
1377
- var test = new Assertion(act, msg);
1378
-
1379
- test.assert(
1380
- exp == flag(test, 'object')
1381
- , 'expected #{this} to equal #{exp}'
1382
- , 'expected #{this} to not equal #{act}'
1383
- , exp
1384
- , act
1385
- );
1386
- };
1387
-
1388
- /**
1389
- * ### .notEqual(actual, expected, [message])
1390
- *
1391
- * Asserts non-strict inequality (`!=`) of `actual` and `expected`.
1392
- *
1393
- * assert.notEqual(3, 4, 'these numbers are not equal');
1394
- *
1395
- * @name notEqual
1396
- * @param {Mixed} actual
1397
- * @param {Mixed} expected
1398
- * @param {String} message
1399
- * @api public
1400
- */
1401
-
1402
- assert.notEqual = function (act, exp, msg) {
1403
- var test = new Assertion(act, msg);
1404
-
1405
- test.assert(
1406
- exp != flag(test, 'object')
1407
- , 'expected #{this} to not equal #{exp}'
1408
- , 'expected #{this} to equal #{act}'
1409
- , exp
1410
- , act
1411
- );
1412
- };
1413
-
1414
- /**
1415
- * ### .strictEqual(actual, expected, [message])
1416
- *
1417
- * Asserts strict equality (`===`) of `actual` and `expected`.
1418
- *
1419
- * assert.strictEqual(true, true, 'these booleans are strictly equal');
1420
- *
1421
- * @name strictEqual
1422
- * @param {Mixed} actual
1423
- * @param {Mixed} expected
1424
- * @param {String} message
1425
- * @api public
1426
- */
1427
-
1428
- assert.strictEqual = function (act, exp, msg) {
1429
- new Assertion(act, msg).to.equal(exp);
1430
- };
1431
-
1432
- /**
1433
- * ### .notStrictEqual(actual, expected, [message])
1434
- *
1435
- * Asserts strict inequality (`!==`) of `actual` and `expected`.
1436
- *
1437
- * assert.notStrictEqual(3, '3', 'no coercion for strict equality');
1438
- *
1439
- * @name notStrictEqual
1440
- * @param {Mixed} actual
1441
- * @param {Mixed} expected
1442
- * @param {String} message
1443
- * @api public
1444
- */
1445
-
1446
- assert.notStrictEqual = function (act, exp, msg) {
1447
- new Assertion(act, msg).to.not.equal(exp);
1448
- };
1449
-
1450
- /**
1451
- * ### .deepEqual(actual, expected, [message])
1452
- *
1453
- * Asserts that `actual` is deeply equal to `expected`.
1454
- *
1455
- * assert.deepEqual({ tea: 'green' }, { tea: 'green' });
1456
- *
1457
- * @name deepEqual
1458
- * @param {Mixed} actual
1459
- * @param {Mixed} expected
1460
- * @param {String} message
1461
- * @api public
1462
- */
1463
-
1464
- assert.deepEqual = function (act, exp, msg) {
1465
- new Assertion(act, msg).to.eql(exp);
1466
- };
1467
-
1468
- /**
1469
- * ### .notDeepEqual(actual, expected, [message])
1470
- *
1471
- * Assert that `actual` is not deeply equal to `expected`.
1472
- *
1473
- * assert.notDeepEqual({ tea: 'green' }, { tea: 'jasmine' });
1474
- *
1475
- * @name notDeepEqual
1476
- * @param {Mixed} actual
1477
- * @param {Mixed} expected
1478
- * @param {String} message
1479
- * @api public
1480
- */
1481
-
1482
- assert.notDeepEqual = function (act, exp, msg) {
1483
- new Assertion(act, msg).to.not.eql(exp);
1484
- };
1485
-
1486
- /**
1487
- * ### .isTrue(value, [message])
1488
- *
1489
- * Asserts that `value` is true.
1490
- *
1491
- * var teaServed = true;
1492
- * assert.isTrue(teaServed, 'the tea has been served');
1493
- *
1494
- * @name isTrue
1495
- * @param {Mixed} value
1496
- * @param {String} message
1497
- * @api public
1498
- */
1499
-
1500
- assert.isTrue = function (val, msg) {
1501
- new Assertion(val, msg).is['true'];
1502
- };
1503
-
1504
- /**
1505
- * ### .isFalse(value, [message])
1506
- *
1507
- * Asserts that `value` is false.
1508
- *
1509
- * var teaServed = false;
1510
- * assert.isFalse(teaServed, 'no tea yet? hmm...');
1511
- *
1512
- * @name isFalse
1513
- * @param {Mixed} value
1514
- * @param {String} message
1515
- * @api public
1516
- */
1517
-
1518
- assert.isFalse = function (val, msg) {
1519
- new Assertion(val, msg).is['false'];
1520
- };
1521
-
1522
- /**
1523
- * ### .isNull(value, [message])
1524
- *
1525
- * Asserts that `value` is null.
1526
- *
1527
- * assert.isNull(err, 'there was no error');
1528
- *
1529
- * @name isNull
1530
- * @param {Mixed} value
1531
- * @param {String} message
1532
- * @api public
1533
- */
1534
-
1535
- assert.isNull = function (val, msg) {
1536
- new Assertion(val, msg).to.equal(null);
1537
- };
1538
-
1539
- /**
1540
- * ### .isNotNull(value, [message])
1541
- *
1542
- * Asserts that `value` is not null.
1543
- *
1544
- * var tea = 'tasty chai';
1545
- * assert.isNotNull(tea, 'great, time for tea!');
1546
- *
1547
- * @name isNotNull
1548
- * @param {Mixed} value
1549
- * @param {String} message
1550
- * @api public
1551
- */
1552
-
1553
- assert.isNotNull = function (val, msg) {
1554
- new Assertion(val, msg).to.not.equal(null);
1555
- };
1556
-
1557
- /**
1558
- * ### .isUndefined(value, [message])
1559
- *
1560
- * Asserts that `value` is `undefined`.
1561
- *
1562
- * var tea;
1563
- * assert.isUndefined(tea, 'no tea defined');
1564
- *
1565
- * @name isUndefined
1566
- * @param {Mixed} value
1567
- * @param {String} message
1568
- * @api public
1569
- */
1570
-
1571
- assert.isUndefined = function (val, msg) {
1572
- new Assertion(val, msg).to.equal(undefined);
1573
- };
1574
-
1575
- /**
1576
- * ### .isDefined(value, [message])
1577
- *
1578
- * Asserts that `value` is not `undefined`.
1579
- *
1580
- * var tea = 'cup of chai';
1581
- * assert.isDefined(tea, 'tea has been defined');
1582
- *
1583
- * @name isUndefined
1584
- * @param {Mixed} value
1585
- * @param {String} message
1586
- * @api public
1587
- */
1588
-
1589
- assert.isDefined = function (val, msg) {
1590
- new Assertion(val, msg).to.not.equal(undefined);
1591
- };
1592
-
1593
- /**
1594
- * ### .isFunction(value, [message])
1595
- *
1596
- * Asserts that `value` is a function.
1597
- *
1598
- * function serveTea() { return 'cup of tea'; };
1599
- * assert.isFunction(serveTea, 'great, we can have tea now');
1600
- *
1601
- * @name isFunction
1602
- * @param {Mixed} value
1603
- * @param {String} message
1604
- * @api public
1605
- */
1606
-
1607
- assert.isFunction = function (val, msg) {
1608
- new Assertion(val, msg).to.be.a('function');
1609
- };
1610
-
1611
- /**
1612
- * ### .isNotFunction(value, [message])
1613
- *
1614
- * Asserts that `value` is _not_ a function.
1615
- *
1616
- * var serveTea = [ 'heat', 'pour', 'sip' ];
1617
- * assert.isNotFunction(serveTea, 'great, we have listed the steps');
1618
- *
1619
- * @name isNotFunction
1620
- * @param {Mixed} value
1621
- * @param {String} message
1622
- * @api public
1623
- */
1624
-
1625
- assert.isNotFunction = function (val, msg) {
1626
- new Assertion(val, msg).to.not.be.a('function');
1627
- };
1628
-
1629
- /**
1630
- * ### .isObject(value, [message])
1631
- *
1632
- * Asserts that `value` is an object (as revealed by
1633
- * `Object.prototype.toString`).
1634
- *
1635
- * var selection = { name: 'Chai', serve: 'with spices' };
1636
- * assert.isObject(selection, 'tea selection is an object');
1637
- *
1638
- * @name isObject
1639
- * @param {Mixed} value
1640
- * @param {String} message
1641
- * @api public
1642
- */
1643
-
1644
- assert.isObject = function (val, msg) {
1645
- new Assertion(val, msg).to.be.a('object');
1646
- };
1647
-
1648
- /**
1649
- * ### .isNotObject(value, [message])
1650
- *
1651
- * Asserts that `value` is _not_ an object.
1652
- *
1653
- * var selection = 'chai'
1654
- * assert.isObject(selection, 'tea selection is not an object');
1655
- * assert.isObject(null, 'null is not an object');
1656
- *
1657
- * @name isNotObject
1658
- * @param {Mixed} value
1659
- * @param {String} message
1660
- * @api public
1661
- */
1662
-
1663
- assert.isNotObject = function (val, msg) {
1664
- new Assertion(val, msg).to.not.be.a('object');
1665
- };
1666
-
1667
- /**
1668
- * ### .isArray(value, [message])
1669
- *
1670
- * Asserts that `value` is an array.
1671
- *
1672
- * var menu = [ 'green', 'chai', 'oolong' ];
1673
- * assert.isArray(menu, 'what kind of tea do we want?');
1674
- *
1675
- * @name isArray
1676
- * @param {Mixed} value
1677
- * @param {String} message
1678
- * @api public
1679
- */
1680
-
1681
- assert.isArray = function (val, msg) {
1682
- new Assertion(val, msg).to.be.an('array');
1683
- };
1684
-
1685
- /**
1686
- * ### .isNotArray(value, [message])
1687
- *
1688
- * Asserts that `value` is _not_ an array.
1689
- *
1690
- * var menu = 'green|chai|oolong';
1691
- * assert.isNotArray(menu, 'what kind of tea do we want?');
1692
- *
1693
- * @name isNotArray
1694
- * @param {Mixed} value
1695
- * @param {String} message
1696
- * @api public
1697
- */
1698
-
1699
- assert.isNotArray = function (val, msg) {
1700
- new Assertion(val, msg).to.not.be.an('array');
1701
- };
1702
-
1703
- /**
1704
- * ### .isString(value, [message])
1705
- *
1706
- * Asserts that `value` is a string.
1707
- *
1708
- * var teaOrder = 'chai';
1709
- * assert.isString(teaOrder, 'order placed');
1710
- *
1711
- * @name isString
1712
- * @param {Mixed} value
1713
- * @param {String} message
1714
- * @api public
1715
- */
1716
-
1717
- assert.isString = function (val, msg) {
1718
- new Assertion(val, msg).to.be.a('string');
1719
- };
1720
-
1721
- /**
1722
- * ### .isNotString(value, [message])
1723
- *
1724
- * Asserts that `value` is _not_ a string.
1725
- *
1726
- * var teaOrder = 4;
1727
- * assert.isNotString(teaOrder, 'order placed');
1728
- *
1729
- * @name isNotString
1730
- * @param {Mixed} value
1731
- * @param {String} message
1732
- * @api public
1733
- */
1734
-
1735
- assert.isNotString = function (val, msg) {
1736
- new Assertion(val, msg).to.not.be.a('string');
1737
- };
1738
-
1739
- /**
1740
- * ### .isNumber(value, [message])
1741
- *
1742
- * Asserts that `value` is a number.
1743
- *
1744
- * var cups = 2;
1745
- * assert.isNumber(cups, 'how many cups');
1746
- *
1747
- * @name isNumber
1748
- * @param {Number} value
1749
- * @param {String} message
1750
- * @api public
1751
- */
1752
-
1753
- assert.isNumber = function (val, msg) {
1754
- new Assertion(val, msg).to.be.a('number');
1755
- };
1756
-
1757
- /**
1758
- * ### .isNotNumber(value, [message])
1759
- *
1760
- * Asserts that `value` is _not_ a number.
1761
- *
1762
- * var cups = '2 cups please';
1763
- * assert.isNotNumber(cups, 'how many cups');
1764
- *
1765
- * @name isNotNumber
1766
- * @param {Mixed} value
1767
- * @param {String} message
1768
- * @api public
1769
- */
1770
-
1771
- assert.isNotNumber = function (val, msg) {
1772
- new Assertion(val, msg).to.not.be.a('number');
1773
- };
1774
-
1775
- /**
1776
- * ### .isBoolean(value, [message])
1777
- *
1778
- * Asserts that `value` is a boolean.
1779
- *
1780
- * var teaReady = true
1781
- * , teaServed = false;
1782
- *
1783
- * assert.isBoolean(teaReady, 'is the tea ready');
1784
- * assert.isBoolean(teaServed, 'has tea been served');
1785
- *
1786
- * @name isBoolean
1787
- * @param {Mixed} value
1788
- * @param {String} message
1789
- * @api public
1790
- */
1791
-
1792
- assert.isBoolean = function (val, msg) {
1793
- new Assertion(val, msg).to.be.a('boolean');
1794
- };
1795
-
1796
- /**
1797
- * ### .isNotBoolean(value, [message])
1798
- *
1799
- * Asserts that `value` is _not_ a boolean.
1800
- *
1801
- * var teaReady = 'yep'
1802
- * , teaServed = 'nope';
1803
- *
1804
- * assert.isNotBoolean(teaReady, 'is the tea ready');
1805
- * assert.isNotBoolean(teaServed, 'has tea been served');
1806
- *
1807
- * @name isNotBoolean
1808
- * @param {Mixed} value
1809
- * @param {String} message
1810
- * @api public
1811
- */
1812
-
1813
- assert.isNotBoolean = function (val, msg) {
1814
- new Assertion(val, msg).to.not.be.a('boolean');
1815
- };
1816
-
1817
- /**
1818
- * ### .typeOf(value, name, [message])
1819
- *
1820
- * Asserts that `value`'s type is `name`, as determined by
1821
- * `Object.prototype.toString`.
1822
- *
1823
- * assert.typeOf({ tea: 'chai' }, 'object', 'we have an object');
1824
- * assert.typeOf(['chai', 'jasmine'], 'array', 'we have an array');
1825
- * assert.typeOf('tea', 'string', 'we have a string');
1826
- * assert.typeOf(/tea/, 'regexp', 'we have a regular expression');
1827
- * assert.typeOf(null, 'null', 'we have a null');
1828
- * assert.typeOf(undefined, 'undefined', 'we have an undefined');
1829
- *
1830
- * @name typeOf
1831
- * @param {Mixed} value
1832
- * @param {String} name
1833
- * @param {String} message
1834
- * @api public
1835
- */
1836
-
1837
- assert.typeOf = function (val, type, msg) {
1838
- new Assertion(val, msg).to.be.a(type);
1839
- };
1840
-
1841
- /**
1842
- * ### .notTypeOf(value, name, [message])
1843
- *
1844
- * Asserts that `value`'s type is _not_ `name`, as determined by
1845
- * `Object.prototype.toString`.
1846
- *
1847
- * assert.notTypeOf('tea', 'number', 'strings are not numbers');
1848
- *
1849
- * @name notTypeOf
1850
- * @param {Mixed} value
1851
- * @param {String} typeof name
1852
- * @param {String} message
1853
- * @api public
1854
- */
1855
-
1856
- assert.notTypeOf = function (val, type, msg) {
1857
- new Assertion(val, msg).to.not.be.a(type);
1858
- };
1859
-
1860
- /**
1861
- * ### .instanceOf(object, constructor, [message])
1862
- *
1863
- * Asserts that `value` is an instance of `constructor`.
1864
- *
1865
- * var Tea = function (name) { this.name = name; }
1866
- * , chai = new Tea('chai');
1867
- *
1868
- * assert.instanceOf(chai, Tea, 'chai is an instance of tea');
1869
- *
1870
- * @name instanceOf
1871
- * @param {Object} object
1872
- * @param {Constructor} constructor
1873
- * @param {String} message
1874
- * @api public
1875
- */
1876
-
1877
- assert.instanceOf = function (val, type, msg) {
1878
- new Assertion(val, msg).to.be.instanceOf(type);
1879
- };
1880
-
1881
- /**
1882
- * ### .notInstanceOf(object, constructor, [message])
1883
- *
1884
- * Asserts `value` is not an instance of `constructor`.
1885
- *
1886
- * var Tea = function (name) { this.name = name; }
1887
- * , chai = new String('chai');
1888
- *
1889
- * assert.notInstanceOf(chai, Tea, 'chai is not an instance of tea');
1890
- *
1891
- * @name notInstanceOf
1892
- * @param {Object} object
1893
- * @param {Constructor} constructor
1894
- * @param {String} message
1895
- * @api public
1896
- */
1897
-
1898
- assert.notInstanceOf = function (val, type, msg) {
1899
- new Assertion(val, msg).to.not.be.instanceOf(type);
1900
- };
1901
-
1902
- /**
1903
- * ### .include(haystack, needle, [message])
1904
- *
1905
- * Asserts that `haystack` includes `needle`. Works
1906
- * for strings and arrays.
1907
- *
1908
- * assert.include('foobar', 'bar', 'foobar contains string "bar"');
1909
- * assert.include([ 1, 2, 3 ], 3, 'array contains value');
1910
- *
1911
- * @name include
1912
- * @param {Array|String} haystack
1913
- * @param {Mixed} needle
1914
- * @param {String} message
1915
- * @api public
1916
- */
1917
-
1918
- assert.include = function (exp, inc, msg) {
1919
- var obj = new Assertion(exp, msg);
1920
-
1921
- if (Array.isArray(exp)) {
1922
- obj.to.include(inc);
1923
- } else if ('string' === typeof exp) {
1924
- obj.to.contain.string(inc);
1925
- }
1926
- };
1927
-
1928
- /**
1929
- * ### .match(value, regexp, [message])
1930
- *
1931
- * Asserts that `value` matches the regular expression `regexp`.
1932
- *
1933
- * assert.match('foobar', /^foo/, 'regexp matches');
1934
- *
1935
- * @name match
1936
- * @param {Mixed} value
1937
- * @param {RegExp} regexp
1938
- * @param {String} message
1939
- * @api public
1940
- */
1941
-
1942
- assert.match = function (exp, re, msg) {
1943
- new Assertion(exp, msg).to.match(re);
1944
- };
1945
-
1946
- /**
1947
- * ### .notMatch(value, regexp, [message])
1948
- *
1949
- * Asserts that `value` does not match the regular expression `regexp`.
1950
- *
1951
- * assert.notMatch('foobar', /^foo/, 'regexp does not match');
1952
- *
1953
- * @name notMatch
1954
- * @param {Mixed} value
1955
- * @param {RegExp} regexp
1956
- * @param {String} message
1957
- * @api public
1958
- */
1959
-
1960
- assert.notMatch = function (exp, re, msg) {
1961
- new Assertion(exp, msg).to.not.match(re);
1962
- };
1963
-
1964
- /**
1965
- * ### .property(object, property, [message])
1966
- *
1967
- * Asserts that `object` has a property named by `property`.
1968
- *
1969
- * assert.property({ tea: { green: 'matcha' }}, 'tea');
1970
- *
1971
- * @name property
1972
- * @param {Object} object
1973
- * @param {String} property
1974
- * @param {String} message
1975
- * @api public
1976
- */
1977
-
1978
- assert.property = function (obj, prop, msg) {
1979
- new Assertion(obj, msg).to.have.property(prop);
1980
- };
1981
-
1982
- /**
1983
- * ### .notProperty(object, property, [message])
1984
- *
1985
- * Asserts that `object` does _not_ have a property named by `property`.
1986
- *
1987
- * assert.notProperty({ tea: { green: 'matcha' }}, 'coffee');
1988
- *
1989
- * @name notProperty
1990
- * @param {Object} object
1991
- * @param {String} property
1992
- * @param {String} message
1993
- * @api public
1994
- */
1995
-
1996
- assert.notProperty = function (obj, prop, msg) {
1997
- new Assertion(obj, msg).to.not.have.property(prop);
1998
- };
1999
-
2000
- /**
2001
- * ### .deepProperty(object, property, [message])
2002
- *
2003
- * Asserts that `object` has a property named by `property`, which can be a
2004
- * string using dot- and bracket-notation for deep reference.
2005
- *
2006
- * assert.deepProperty({ tea: { green: 'matcha' }}, 'tea.green');
2007
- *
2008
- * @name deepProperty
2009
- * @param {Object} object
2010
- * @param {String} property
2011
- * @param {String} message
2012
- * @api public
2013
- */
2014
-
2015
- assert.deepProperty = function (obj, prop, msg) {
2016
- new Assertion(obj, msg).to.have.deep.property(prop);
2017
- };
2018
-
2019
- /**
2020
- * ### .notDeepProperty(object, property, [message])
2021
- *
2022
- * Asserts that `object` does _not_ have a property named by `property`, which
2023
- * can be a string using dot- and bracket-notation for deep reference.
2024
- *
2025
- * assert.notDeepProperty({ tea: { green: 'matcha' }}, 'tea.oolong');
2026
- *
2027
- * @name notDeepProperty
2028
- * @param {Object} object
2029
- * @param {String} property
2030
- * @param {String} message
2031
- * @api public
2032
- */
2033
-
2034
- assert.notDeepProperty = function (obj, prop, msg) {
2035
- new Assertion(obj, msg).to.not.have.deep.property(prop);
2036
- };
2037
-
2038
- /**
2039
- * ### .propertyVal(object, property, value, [message])
2040
- *
2041
- * Asserts that `object` has a property named by `property` with value given
2042
- * by `value`.
2043
- *
2044
- * assert.propertyVal({ tea: 'is good' }, 'tea', 'is good');
2045
- *
2046
- * @name propertyVal
2047
- * @param {Object} object
2048
- * @param {String} property
2049
- * @param {Mixed} value
2050
- * @param {String} message
2051
- * @api public
2052
- */
2053
-
2054
- assert.propertyVal = function (obj, prop, val, msg) {
2055
- new Assertion(obj, msg).to.have.property(prop, val);
2056
- };
2057
-
2058
- /**
2059
- * ### .propertyNotVal(object, property, value, [message])
2060
- *
2061
- * Asserts that `object` has a property named by `property`, but with a value
2062
- * different from that given by `value`.
2063
- *
2064
- * assert.propertyNotVal({ tea: 'is good' }, 'tea', 'is bad');
2065
- *
2066
- * @name propertyNotVal
2067
- * @param {Object} object
2068
- * @param {String} property
2069
- * @param {Mixed} value
2070
- * @param {String} message
2071
- * @api public
2072
- */
2073
-
2074
- assert.propertyNotVal = function (obj, prop, val, msg) {
2075
- new Assertion(obj, msg).to.not.have.property(prop, val);
2076
- };
2077
-
2078
- /**
2079
- * ### .deepPropertyVal(object, property, value, [message])
2080
- *
2081
- * Asserts that `object` has a property named by `property` with value given
2082
- * by `value`. `property` can use dot- and bracket-notation for deep
2083
- * reference.
2084
- *
2085
- * assert.deepPropertyVal({ tea: { green: 'matcha' }}, 'tea.green', 'matcha');
2086
- *
2087
- * @name deepPropertyVal
2088
- * @param {Object} object
2089
- * @param {String} property
2090
- * @param {Mixed} value
2091
- * @param {String} message
2092
- * @api public
2093
- */
2094
-
2095
- assert.deepPropertyVal = function (obj, prop, val, msg) {
2096
- new Assertion(obj, msg).to.have.deep.property(prop, val);
2097
- };
2098
-
2099
- /**
2100
- * ### .deepPropertyNotVal(object, property, value, [message])
2101
- *
2102
- * Asserts that `object` has a property named by `property`, but with a value
2103
- * different from that given by `value`. `property` can use dot- and
2104
- * bracket-notation for deep reference.
2105
- *
2106
- * assert.deepPropertyNotVal({ tea: { green: 'matcha' }}, 'tea.green', 'konacha');
2107
- *
2108
- * @name deepPropertyNotVal
2109
- * @param {Object} object
2110
- * @param {String} property
2111
- * @param {Mixed} value
2112
- * @param {String} message
2113
- * @api public
2114
- */
2115
-
2116
- assert.deepPropertyNotVal = function (obj, prop, val, msg) {
2117
- new Assertion(obj, msg).to.not.have.deep.property(prop, val);
2118
- };
2119
-
2120
- /**
2121
- * ### .lengthOf(object, length, [message])
2122
- *
2123
- * Asserts that `object` has a `length` property with the expected value.
2124
- *
2125
- * assert.lengthOf([1,2,3], 3, 'array has length of 3');
2126
- * assert.lengthOf('foobar', 5, 'string has length of 6');
2127
- *
2128
- * @name lengthOf
2129
- * @param {Mixed} object
2130
- * @param {Number} length
2131
- * @param {String} message
2132
- * @api public
2133
- */
2134
-
2135
- assert.lengthOf = function (exp, len, msg) {
2136
- new Assertion(exp, msg).to.have.length(len);
2137
- };
2138
-
2139
- /**
2140
- * ### .throws(function, [constructor/regexp], [message])
2141
- *
2142
- * Asserts that `function` will throw an error that is an instance of
2143
- * `constructor`, or alternately that it will throw an error with message
2144
- * matching `regexp`.
2145
- *
2146
- * assert.throw(fn, ReferenceError, 'function throws a reference error');
2147
- *
2148
- * @name throws
2149
- * @alias throw
2150
- * @alias Throw
2151
- * @param {Function} function
2152
- * @param {ErrorConstructor} constructor
2153
- * @param {RegExp} regexp
2154
- * @param {String} message
2155
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2156
- * @api public
2157
- */
2158
-
2159
- assert.Throw = function (fn, type, msg) {
2160
- if ('string' === typeof type) {
2161
- msg = type;
2162
- type = null;
2163
- }
2164
-
2165
- new Assertion(fn, msg).to.Throw(type);
2166
- };
2167
-
2168
- /**
2169
- * ### .doesNotThrow(function, [constructor/regexp], [message])
2170
- *
2171
- * Asserts that `function` will _not_ throw an error that is an instance of
2172
- * `constructor`, or alternately that it will not throw an error with message
2173
- * matching `regexp`.
2174
- *
2175
- * assert.doesNotThrow(fn, Error, 'function does not throw');
2176
- *
2177
- * @name doesNotThrow
2178
- * @param {Function} function
2179
- * @param {ErrorConstructor} constructor
2180
- * @param {RegExp} regexp
2181
- * @param {String} message
2182
- * @see https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error#Error_types
2183
- * @api public
2184
- */
2185
-
2186
- assert.doesNotThrow = function (fn, type, msg) {
2187
- if ('string' === typeof type) {
2188
- msg = type;
2189
- type = null;
2190
- }
2191
-
2192
- new Assertion(fn, msg).to.not.Throw(type);
2193
- };
2194
-
2195
- /**
2196
- * ### .operator(val1, operator, val2, [message])
2197
- *
2198
- * Compares two values using `operator`.
2199
- *
2200
- * assert.operator(1, '<', 2, 'everything is ok');
2201
- * assert.operator(1, '>', 2, 'this will fail');
2202
- *
2203
- * @name operator
2204
- * @param {Mixed} val1
2205
- * @param {String} operator
2206
- * @param {Mixed} val2
2207
- * @param {String} message
2208
- * @api public
2209
- */
2210
-
2211
- assert.operator = function (val, operator, val2, msg) {
2212
- if (!~['==', '===', '>', '>=', '<', '<=', '!=', '!=='].indexOf(operator)) {
2213
- throw new Error('Invalid operator "' + operator + '"');
2214
- }
2215
- var test = new Assertion(eval(val + operator + val2), msg);
2216
- test.assert(
2217
- true === flag(test, 'object')
2218
- , 'expected ' + util.inspect(val) + ' to be ' + operator + ' ' + util.inspect(val2)
2219
- , 'expected ' + util.inspect(val) + ' to not be ' + operator + ' ' + util.inspect(val2) );
2220
- };
2221
-
2222
- /*!
2223
- * Undocumented / untested
2224
- */
2225
-
2226
- assert.ifError = function (val, msg) {
2227
- new Assertion(val, msg).to.not.be.ok;
2228
- };
2229
-
2230
- /*!
2231
- * Aliases.
2232
- */
2233
-
2234
- (function alias(name, as){
2235
- assert[as] = assert[name];
2236
- return alias;
2237
- })
2238
- ('Throw', 'throw')
2239
- ('Throw', 'throws');
2240
- };
2241
-
2242
- }); // module: interface/assert.js
2243
-
2244
- require.register("interface/expect.js", function(module, exports, require){
2245
- /*!
2246
- * chai
2247
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
2248
- * MIT Licensed
2249
- */
2250
-
2251
- module.exports = function (chai, util) {
2252
- chai.expect = function (val, message) {
2253
- return new chai.Assertion(val, message);
2254
- };
2255
- };
2256
-
2257
-
2258
- }); // module: interface/expect.js
2259
-
2260
- require.register("interface/should.js", function(module, exports, require){
2261
- /*!
2262
- * chai
2263
- * Copyright(c) 2011-2012 Jake Luer <jake@alogicalparadox.com>
2264
- * MIT Licensed
2265
- */
2266
-
2267
- module.exports = function (chai, util) {
2268
- var Assertion = chai.Assertion;
2269
-
2270
- function loadShould () {
2271
- // modify Object.prototype to have `should`
2272
- Object.defineProperty(Object.prototype, 'should',
2273
- { set: function () {}
2274
- , get: function(){
2275
- if (this instanceof String || this instanceof Number) {
2276
- return new Assertion(this.constructor(this));
2277
- } else if (this instanceof Boolean) {
2278
- return new Assertion(this == true);
2279
- }
2280
- return new Assertion(this);
2281
- }
2282
- , configurable: true
2283
- });
2284
-
2285
- var should = {};
2286
-
2287
- should.equal = function (val1, val2) {
2288
- new Assertion(val1).to.equal(val2);
2289
- };
2290
-
2291
- should.Throw = function (fn, errt, errs) {
2292
- new Assertion(fn).to.Throw(errt, errs);
2293
- };
2294
-
2295
- should.exist = function (val) {
2296
- new Assertion(val).to.exist;
2297
- }
2298
-
2299
- // negation
2300
- should.not = {}
2301
-
2302
- should.not.equal = function (val1, val2) {
2303
- new Assertion(val1).to.not.equal(val2);
2304
- };
2305
-
2306
- should.not.Throw = function (fn, errt, errs) {
2307
- new Assertion(fn).to.not.Throw(errt, errs);
2308
- };
2309
-
2310
- should.not.exist = function (val) {
2311
- new Assertion(val).to.not.exist;
2312
- }
2313
-
2314
- should['throw'] = should['Throw'];
2315
- should.not['throw'] = should.not['Throw'];
2316
-
2317
- return should;
2318
- };
2319
-
2320
- chai.should = loadShould;
2321
- chai.Should = loadShould;
2322
- };
2323
-
2324
- }); // module: interface/should.js
2325
-
2326
- require.register("utils/addChainableMethod.js", function(module, exports, require){
2327
- /*!
2328
- * Chai - addChainingMethod utility
2329
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2330
- * MIT Licensed
2331
- */
2332
-
2333
- /*!
2334
- * Module dependencies
2335
- */
2336
-
2337
- var transferFlags = require('./transferFlags');
2338
-
2339
- /**
2340
- * ### addChainableMethod (ctx, name, method, chainingBehavior)
2341
- *
2342
- * Adds a method to an object, such that the method can also be chained.
2343
- *
2344
- * utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
2345
- * var obj = utils.flag(this, 'object');
2346
- * new chai.Assertion(obj).to.be.equal(str);
2347
- * });
2348
- *
2349
- * Can also be accessed directly from `chai.Assertion`.
2350
- *
2351
- * chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
2352
- *
2353
- * The result can then be used as both a method assertion, executing both `method` and
2354
- * `chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
2355
- *
2356
- * expect(fooStr).to.be.foo('bar');
2357
- * expect(fooStr).to.be.foo.equal('foo');
2358
- *
2359
- * @param {Object} ctx object to which the method is added
2360
- * @param {String} name of method to add
2361
- * @param {Function} method function to be used for `name`, when called
2362
- * @param {Function} chainingBehavior function to be called every time the property is accessed
2363
- * @name addChainableMethod
2364
- * @api public
2365
- */
2366
-
2367
- module.exports = function (ctx, name, method, chainingBehavior) {
2368
- if (typeof chainingBehavior !== 'function')
2369
- chainingBehavior = function () { };
2370
-
2371
- Object.defineProperty(ctx, name,
2372
- { get: function () {
2373
- chainingBehavior.call(this);
2374
-
2375
- var assert = function () {
2376
- var result = method.apply(this, arguments);
2377
- return result === undefined ? this : result;
2378
- };
2379
-
2380
- // Re-enumerate every time to better accomodate plugins.
2381
- var asserterNames = Object.getOwnPropertyNames(ctx);
2382
- asserterNames.forEach(function (asserterName) {
2383
- var pd = Object.getOwnPropertyDescriptor(ctx, asserterName)
2384
- , functionProtoPD = Object.getOwnPropertyDescriptor(Function.prototype, asserterName);
2385
- // Avoid trying to overwrite things that we can't, like `length` and `arguments`.
2386
- if (functionProtoPD && !functionProtoPD.configurable) return;
2387
- if (asserterName === 'arguments') return; // @see chaijs/chai/issues/69
2388
- Object.defineProperty(assert, asserterName, pd);
2389
- });
2390
-
2391
- transferFlags(this, assert);
2392
- return assert;
2393
- }
2394
- , configurable: true
2395
- });
2396
- };
2397
-
2398
- }); // module: utils/addChainableMethod.js
2399
-
2400
- require.register("utils/addMethod.js", function(module, exports, require){
2401
- /*!
2402
- * Chai - addMethod utility
2403
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2404
- * MIT Licensed
2405
- */
2406
-
2407
- /**
2408
- * ### addMethod (ctx, name, method)
2409
- *
2410
- * Adds a method to the prototype of an object.
2411
- *
2412
- * utils.addMethod(chai.Assertion.prototype, 'foo', function (str) {
2413
- * var obj = utils.flag(this, 'object');
2414
- * new chai.Assertion(obj).to.be.equal(str);
2415
- * });
2416
- *
2417
- * Can also be accessed directly from `chai.Assertion`.
2418
- *
2419
- * chai.Assertion.addMethod('foo', fn);
2420
- *
2421
- * Then can be used as any other assertion.
2422
- *
2423
- * expect(fooStr).to.be.foo('bar');
2424
- *
2425
- * @param {Object} ctx object to which the method is added
2426
- * @param {String} name of method to add
2427
- * @param {Function} method function to be used for name
2428
- * @name addMethod
2429
- * @api public
2430
- */
2431
-
2432
- module.exports = function (ctx, name, method) {
2433
- ctx[name] = function () {
2434
- var result = method.apply(this, arguments);
2435
- return result === undefined ? this : result;
2436
- };
2437
- };
2438
-
2439
- }); // module: utils/addMethod.js
2440
-
2441
- require.register("utils/addProperty.js", function(module, exports, require){
2442
- /*!
2443
- * Chai - addProperty utility
2444
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2445
- * MIT Licensed
2446
- */
2447
-
2448
- /**
2449
- * ### addProperty (ctx, name, getter)
2450
- *
2451
- * Adds a property to the prototype of an object.
2452
- *
2453
- * utils.addProperty(chai.Assertion.prototype, 'foo', function () {
2454
- * var obj = utils.flag(this, 'object');
2455
- * new chai.Assertion(obj).to.be.instanceof(Foo);
2456
- * });
2457
- *
2458
- * Can also be accessed directly from `chai.Assertion`.
2459
- *
2460
- * chai.Assertion.addProperty('foo', fn);
2461
- *
2462
- * Then can be used as any other assertion.
2463
- *
2464
- * expect(myFoo).to.be.foo;
2465
- *
2466
- * @param {Object} ctx object to which the property is added
2467
- * @param {String} name of property to add
2468
- * @param {Function} getter function to be used for name
2469
- * @name addProperty
2470
- * @api public
2471
- */
2472
-
2473
- module.exports = function (ctx, name, getter) {
2474
- Object.defineProperty(ctx, name,
2475
- { get: function () {
2476
- var result = getter.call(this);
2477
- return result === undefined ? this : result;
2478
- }
2479
- , configurable: true
2480
- });
2481
- };
2482
-
2483
- }); // module: utils/addProperty.js
2484
-
2485
- require.register("utils/eql.js", function(module, exports, require){
2486
- // This is directly from Node.js assert
2487
- // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/assert.js
2488
-
2489
-
2490
- module.exports = _deepEqual;
2491
-
2492
- // For browser implementation
2493
- if (!Buffer) {
2494
- var Buffer = {
2495
- isBuffer: function () {
2496
- return false;
2497
- }
2498
- };
2499
- }
2500
-
2501
- function _deepEqual(actual, expected) {
2502
- // 7.1. All identical values are equivalent, as determined by ===.
2503
- if (actual === expected) {
2504
- return true;
2505
-
2506
- } else if (Buffer.isBuffer(actual) && Buffer.isBuffer(expected)) {
2507
- if (actual.length != expected.length) return false;
2508
-
2509
- for (var i = 0; i < actual.length; i++) {
2510
- if (actual[i] !== expected[i]) return false;
2511
- }
2512
-
2513
- return true;
2514
-
2515
- // 7.2. If the expected value is a Date object, the actual value is
2516
- // equivalent if it is also a Date object that refers to the same time.
2517
- } else if (actual instanceof Date && expected instanceof Date) {
2518
- return actual.getTime() === expected.getTime();
2519
-
2520
- // 7.3. Other pairs that do not both pass typeof value == 'object',
2521
- // equivalence is determined by ==.
2522
- } else if (typeof actual != 'object' && typeof expected != 'object') {
2523
- return actual === expected;
2524
-
2525
- // 7.4. For all other Object pairs, including Array objects, equivalence is
2526
- // determined by having the same number of owned properties (as verified
2527
- // with Object.prototype.hasOwnProperty.call), the same set of keys
2528
- // (although not necessarily the same order), equivalent values for every
2529
- // corresponding key, and an identical 'prototype' property. Note: this
2530
- // accounts for both named and indexed properties on Arrays.
2531
- } else {
2532
- return objEquiv(actual, expected);
2533
- }
2534
- }
2535
-
2536
- function isUndefinedOrNull(value) {
2537
- return value === null || value === undefined;
2538
- }
2539
-
2540
- function isArguments(object) {
2541
- return Object.prototype.toString.call(object) == '[object Arguments]';
2542
- }
2543
-
2544
- function objEquiv(a, b) {
2545
- if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
2546
- return false;
2547
- // an identical 'prototype' property.
2548
- if (a.prototype !== b.prototype) return false;
2549
- //~~~I've managed to break Object.keys through screwy arguments passing.
2550
- // Converting to array solves the problem.
2551
- if (isArguments(a)) {
2552
- if (!isArguments(b)) {
2553
- return false;
2554
- }
2555
- a = pSlice.call(a);
2556
- b = pSlice.call(b);
2557
- return _deepEqual(a, b);
2558
- }
2559
- try {
2560
- var ka = Object.keys(a),
2561
- kb = Object.keys(b),
2562
- key, i;
2563
- } catch (e) {//happens when one is a string literal and the other isn't
2564
- return false;
2565
- }
2566
- // having the same number of owned properties (keys incorporates
2567
- // hasOwnProperty)
2568
- if (ka.length != kb.length)
2569
- return false;
2570
- //the same set of keys (although not necessarily the same order),
2571
- ka.sort();
2572
- kb.sort();
2573
- //~~~cheap key test
2574
- for (i = ka.length - 1; i >= 0; i--) {
2575
- if (ka[i] != kb[i])
2576
- return false;
2577
- }
2578
- //equivalent values for every corresponding key, and
2579
- //~~~possibly expensive deep test
2580
- for (i = ka.length - 1; i >= 0; i--) {
2581
- key = ka[i];
2582
- if (!_deepEqual(a[key], b[key])) return false;
2583
- }
2584
- return true;
2585
- }
2586
- }); // module: utils/eql.js
2587
-
2588
- require.register("utils/flag.js", function(module, exports, require){
2589
- /*!
2590
- * Chai - flag utility
2591
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2592
- * MIT Licensed
2593
- */
2594
-
2595
- /**
2596
- * ### flag(object ,key, [value])
2597
- *
2598
- * Get or set a flag value on an object. If a
2599
- * value is provided it will be set, else it will
2600
- * return the currently set value or `undefined` if
2601
- * the value is not set.
2602
- *
2603
- * utils.flag(this, 'foo', 'bar'); // setter
2604
- * utils.flag(this, 'foo'); // getter, returns `bar`
2605
- *
2606
- * @param {Object} object (constructed Assertion
2607
- * @param {String} key
2608
- * @param {Mixed} value (optional)
2609
- * @name flag
2610
- * @api private
2611
- */
2612
-
2613
- module.exports = function (obj, key, value) {
2614
- var flags = obj.__flags || (obj.__flags = Object.create(null));
2615
- if (arguments.length === 3) {
2616
- flags[key] = value;
2617
- } else {
2618
- return flags[key];
2619
- }
2620
- };
2621
-
2622
- }); // module: utils/flag.js
2623
-
2624
- require.register("utils/getActual.js", function(module, exports, require){
2625
- /*!
2626
- * Chai - getActual utility
2627
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2628
- * MIT Licensed
2629
- */
2630
-
2631
- /**
2632
- * # getActual(object, [actual])
2633
- *
2634
- * Returns the `actual` value for an Assertion
2635
- *
2636
- * @param {Object} object (constructed Assertion)
2637
- * @param {Arguments} chai.Assertion.prototype.assert arguments
2638
- */
2639
-
2640
- module.exports = function (obj, args) {
2641
- var actual = args[4];
2642
- return 'undefined' !== actual ? actual : obj.obj;
2643
- };
2644
-
2645
- }); // module: utils/getActual.js
2646
-
2647
- require.register("utils/getMessage.js", function(module, exports, require){
2648
- /*!
2649
- * Chai - message composition utility
2650
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2651
- * MIT Licensed
2652
- */
2653
-
2654
- /*!
2655
- * Module dependancies
2656
- */
2657
-
2658
- var flag = require('./flag')
2659
- , getActual = require('./getActual')
2660
- , inspect = require('./inspect');
2661
-
2662
- /**
2663
- * # getMessage(object, message, negateMessage)
2664
- *
2665
- * Construct the error message based on flags
2666
- * and template tags. Template tags will return
2667
- * a stringified inspection of the object referenced.
2668
- *
2669
- * Messsage template tags:
2670
- * - `#{this}` current asserted object
2671
- * - `#{act}` actual value
2672
- * - `#{exp}` expected value
2673
- *
2674
- * @param {Object} object (constructed Assertion)
2675
- * @param {Arguments} chai.Assertion.prototype.assert arguments
2676
- */
2677
-
2678
- module.exports = function (obj, args) {
2679
- var negate = flag(obj, 'negate')
2680
- , val = flag(obj, 'object')
2681
- , expected = args[3]
2682
- , actual = getActual(obj, args)
2683
- , msg = negate ? args[2] : args[1]
2684
- , flagMsg = flag(obj, 'message');
2685
-
2686
- msg = msg || '';
2687
- msg = msg
2688
- .replace(/#{this}/g, inspect(val))
2689
- .replace(/#{act}/g, inspect(actual))
2690
- .replace(/#{exp}/g, inspect(expected));
2691
-
2692
- return flagMsg ? flagMsg + ': ' + msg : msg;
2693
- };
2694
-
2695
- }); // module: utils/getMessage.js
2696
-
2697
- require.register("utils/getName.js", function(module, exports, require){
2698
- /*!
2699
- * Chai - getName utility
2700
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2701
- * MIT Licensed
2702
- */
2703
-
2704
- /**
2705
- * # getName(func)
2706
- *
2707
- * Gets the name of a function, in a cross-browser way.
2708
- *
2709
- * @param {Function} a function (usually a constructor)
2710
- */
2711
-
2712
- module.exports = function (func) {
2713
- if (func.name) return func.name;
2714
-
2715
- var match = /^\s?function ([^(]*)\(/.exec(func);
2716
- return match && match[1] ? match[1] : "";
2717
- };
2718
-
2719
- }); // module: utils/getName.js
2720
-
2721
- require.register("utils/getPathValue.js", function(module, exports, require){
2722
- /*!
2723
- * Chai - getPathValue utility
2724
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
2725
- * @see https://github.com/logicalparadox/filtr
2726
- * MIT Licensed
2727
- */
2728
-
2729
- /**
2730
- * ### .getPathValue(path, object)
2731
- *
2732
- * This allows the retrieval of values in an
2733
- * object given a string path.
2734
- *
2735
- * var obj = {
2736
- * prop1: {
2737
- * arr: ['a', 'b', 'c']
2738
- * , str: 'Hello'
2739
- * }
2740
- * , prop2: {
2741
- * arr: [ { nested: 'Universe' } ]
2742
- * , str: 'Hello again!'
2743
- * }
2744
- * }
2745
- *
2746
- * The following would be the results.
2747
- *
2748
- * getPathValue('prop1.str', obj); // Hello
2749
- * getPathValue('prop1.att[2]', obj); // b
2750
- * getPathValue('prop2.arr[0].nested', obj); // Universe
2751
- *
2752
- * @param {String} path
2753
- * @param {Object} object
2754
- * @returns {Object} value or `undefined`
2755
- * @name getPathValue
2756
- * @api public
2757
- */
2758
-
2759
- var getPathValue = module.exports = function (path, obj) {
2760
- var parsed = parsePath(path);
2761
- return _getPathValue(parsed, obj);
2762
- };
2763
-
2764
- /*!
2765
- * ## parsePath(path)
2766
- *
2767
- * Helper function used to parse string object
2768
- * paths. Use in conjunction with `_getPathValue`.
2769
- *
2770
- * var parsed = parsePath('myobject.property.subprop');
2771
- *
2772
- * ### Paths:
2773
- *
2774
- * * Can be as near infinitely deep and nested
2775
- * * Arrays are also valid using the formal `myobject.document[3].property`.
2776
- *
2777
- * @param {String} path
2778
- * @returns {Object} parsed
2779
- * @api private
2780
- */
2781
-
2782
- function parsePath (path) {
2783
- var parts = path.split('.').filter(Boolean);
2784
- return parts.map(function (value) {
2785
- var re = /([A-Za-z0-9]+)\[(\d+)\]$/
2786
- , mArr = re.exec(value)
2787
- , val;
2788
- if (mArr) val = { p: mArr[1], i: parseFloat(mArr[2]) };
2789
- return val || value;
2790
- });
2791
- };
2792
-
2793
- /*!
2794
- * ## _getPathValue(parsed, obj)
2795
- *
2796
- * Helper companion function for `.parsePath` that returns
2797
- * the value located at the parsed address.
2798
- *
2799
- * var value = getPathValue(parsed, obj);
2800
- *
2801
- * @param {Object} parsed definition from `parsePath`.
2802
- * @param {Object} object to search against
2803
- * @returns {Object|Undefined} value
2804
- * @api private
2805
- */
2806
-
2807
- function _getPathValue (parsed, obj) {
2808
- var tmp = obj
2809
- , res;
2810
- for (var i = 0, l = parsed.length; i < l; i++) {
2811
- var part = parsed[i];
2812
- if (tmp) {
2813
- if ('object' === typeof part && tmp[part.p]) {
2814
- tmp = tmp[part.p][part.i];
2815
- } else {
2816
- tmp = tmp[part];
2817
- }
2818
- if (i == (l - 1)) res = tmp;
2819
- } else {
2820
- res = undefined;
2821
- }
2822
- }
2823
- return res;
2824
- };
2825
-
2826
- }); // module: utils/getPathValue.js
2827
-
2828
- require.register("utils/index.js", function(module, exports, require){
2829
- /*!
2830
- * chai
2831
- * Copyright(c) 2011 Jake Luer <jake@alogicalparadox.com>
2832
- * MIT Licensed
2833
- */
2834
-
2835
- /*!
2836
- * Main exports
2837
- */
2838
-
2839
- var exports = module.exports = {};
2840
-
2841
- /*!
2842
- * test utility
2843
- */
2844
-
2845
- exports.test = require('./test');
2846
-
2847
- /*!
2848
- * message utility
2849
- */
2850
-
2851
- exports.getMessage = require('./getMessage');
2852
-
2853
- /*!
2854
- * actual utility
2855
- */
2856
-
2857
- exports.getActual = require('./getActual');
2858
-
2859
- /*!
2860
- * Inspect util
2861
- */
2862
-
2863
- exports.inspect = require('./inspect');
2864
-
2865
- /*!
2866
- * Flag utility
2867
- */
2868
-
2869
- exports.flag = require('./flag');
2870
-
2871
- /*!
2872
- * Flag transferring utility
2873
- */
2874
-
2875
- exports.transferFlags = require('./transferFlags');
2876
-
2877
- /*!
2878
- * Deep equal utility
2879
- */
2880
-
2881
- exports.eql = require('./eql');
2882
-
2883
- /*!
2884
- * Deep path value
2885
- */
2886
-
2887
- exports.getPathValue = require('./getPathValue');
2888
-
2889
- /*!
2890
- * Function name
2891
- */
2892
-
2893
- exports.getName = require('./getName');
2894
-
2895
- /*!
2896
- * add Property
2897
- */
2898
-
2899
- exports.addProperty = require('./addProperty');
2900
-
2901
- /*!
2902
- * add Method
2903
- */
2904
-
2905
- exports.addMethod = require('./addMethod');
2906
-
2907
- /*!
2908
- * overwrite Property
2909
- */
2910
-
2911
- exports.overwriteProperty = require('./overwriteProperty');
2912
-
2913
- /*!
2914
- * overwrite Method
2915
- */
2916
-
2917
- exports.overwriteMethod = require('./overwriteMethod');
2918
-
2919
- /*!
2920
- * Add a chainable method
2921
- */
2922
-
2923
- exports.addChainableMethod = require('./addChainableMethod');
2924
-
2925
-
2926
- }); // module: utils/index.js
2927
-
2928
- require.register("utils/inspect.js", function(module, exports, require){
2929
- // This is (almost) directly from Node.js utils
2930
- // https://github.com/joyent/node/blob/f8c335d0caf47f16d31413f89aa28eda3878e3aa/lib/util.js
2931
-
2932
- var getName = require('./getName');
2933
-
2934
- module.exports = inspect;
2935
-
2936
- /**
2937
- * Echos the value of a value. Trys to print the value out
2938
- * in the best way possible given the different types.
2939
- *
2940
- * @param {Object} obj The object to print out.
2941
- * @param {Boolean} showHidden Flag that shows hidden (not enumerable)
2942
- * properties of objects.
2943
- * @param {Number} depth Depth in which to descend in object. Default is 2.
2944
- * @param {Boolean} colors Flag to turn on ANSI escape codes to color the
2945
- * output. Default is false (no coloring).
2946
- */
2947
- function inspect(obj, showHidden, depth, colors) {
2948
- var ctx = {
2949
- showHidden: showHidden,
2950
- seen: [],
2951
- stylize: function (str) { return str; }
2952
- };
2953
- return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
2954
- }
2955
-
2956
- function formatValue(ctx, value, recurseTimes) {
2957
- // Provide a hook for user-specified inspect functions.
2958
- // Check that value is an object with an inspect function on it
2959
- if (value && typeof value.inspect === 'function' &&
2960
- // Filter out the util module, it's inspect function is special
2961
- value.inspect !== exports.inspect &&
2962
- // Also filter out any prototype objects using the circular check.
2963
- !(value.constructor && value.constructor.prototype === value)) {
2964
- return value.inspect(recurseTimes);
2965
- }
2966
-
2967
- // Primitive types cannot have properties
2968
- var primitive = formatPrimitive(ctx, value);
2969
- if (primitive) {
2970
- return primitive;
2971
- }
2972
-
2973
- // Look up the keys of the object.
2974
- var visibleKeys = Object.keys(value);
2975
- var keys = ctx.showHidden ? Object.getOwnPropertyNames(value) : visibleKeys;
2976
-
2977
- // Some type of object without properties can be shortcutted.
2978
- // In IE, errors have a single `stack` property, or if they are vanilla `Error`,
2979
- // a `stack` plus `description` property; ignore those for consistency.
2980
- if (keys.length === 0 || (isError(value) && (
2981
- (keys.length === 1 && keys[0] === 'stack') ||
2982
- (keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
2983
- ))) {
2984
- if (typeof value === 'function') {
2985
- var name = getName(value);
2986
- var nameSuffix = name ? ': ' + name : '';
2987
- return ctx.stylize('[Function' + nameSuffix + ']', 'special');
2988
- }
2989
- if (isRegExp(value)) {
2990
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
2991
- }
2992
- if (isDate(value)) {
2993
- return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
2994
- }
2995
- if (isError(value)) {
2996
- return formatError(value);
2997
- }
2998
- }
2999
-
3000
- var base = '', array = false, braces = ['{', '}'];
3001
-
3002
- // Make Array say that they are Array
3003
- if (isArray(value)) {
3004
- array = true;
3005
- braces = ['[', ']'];
3006
- }
3007
-
3008
- // Make functions say that they are functions
3009
- if (typeof value === 'function') {
3010
- var n = value.name ? ': ' + value.name : '';
3011
- base = ' [Function' + n + ']';
3012
- }
3013
-
3014
- // Make RegExps say that they are RegExps
3015
- if (isRegExp(value)) {
3016
- base = ' ' + RegExp.prototype.toString.call(value);
3017
- }
3018
-
3019
- // Make dates with properties first say the date
3020
- if (isDate(value)) {
3021
- base = ' ' + Date.prototype.toUTCString.call(value);
3022
- }
3023
-
3024
- // Make error with message first say the error
3025
- if (isError(value)) {
3026
- return formatError(value);
3027
- }
3028
-
3029
- if (keys.length === 0 && (!array || value.length == 0)) {
3030
- return braces[0] + base + braces[1];
3031
- }
3032
-
3033
- if (recurseTimes < 0) {
3034
- if (isRegExp(value)) {
3035
- return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
3036
- } else {
3037
- return ctx.stylize('[Object]', 'special');
3038
- }
3039
- }
3040
-
3041
- ctx.seen.push(value);
3042
-
3043
- var output;
3044
- if (array) {
3045
- output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
3046
- } else {
3047
- output = keys.map(function(key) {
3048
- return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
3049
- });
3050
- }
3051
-
3052
- ctx.seen.pop();
3053
-
3054
- return reduceToSingleString(output, base, braces);
3055
- }
3056
-
3057
-
3058
- function formatPrimitive(ctx, value) {
3059
- switch (typeof value) {
3060
- case 'undefined':
3061
- return ctx.stylize('undefined', 'undefined');
3062
-
3063
- case 'string':
3064
- var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
3065
- .replace(/'/g, "\\'")
3066
- .replace(/\\"/g, '"') + '\'';
3067
- return ctx.stylize(simple, 'string');
3068
-
3069
- case 'number':
3070
- return ctx.stylize('' + value, 'number');
3071
-
3072
- case 'boolean':
3073
- return ctx.stylize('' + value, 'boolean');
3074
- }
3075
- // For some reason typeof null is "object", so special case here.
3076
- if (value === null) {
3077
- return ctx.stylize('null', 'null');
3078
- }
3079
- }
3080
-
3081
-
3082
- function formatError(value) {
3083
- return '[' + Error.prototype.toString.call(value) + ']';
3084
- }
3085
-
3086
-
3087
- function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
3088
- var output = [];
3089
- for (var i = 0, l = value.length; i < l; ++i) {
3090
- if (Object.prototype.hasOwnProperty.call(value, String(i))) {
3091
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3092
- String(i), true));
3093
- } else {
3094
- output.push('');
3095
- }
3096
- }
3097
- keys.forEach(function(key) {
3098
- if (!key.match(/^\d+$/)) {
3099
- output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
3100
- key, true));
3101
- }
3102
- });
3103
- return output;
3104
- }
3105
-
3106
-
3107
- function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
3108
- var name, str;
3109
- if (value.__lookupGetter__) {
3110
- if (value.__lookupGetter__(key)) {
3111
- if (value.__lookupSetter__(key)) {
3112
- str = ctx.stylize('[Getter/Setter]', 'special');
3113
- } else {
3114
- str = ctx.stylize('[Getter]', 'special');
3115
- }
3116
- } else {
3117
- if (value.__lookupSetter__(key)) {
3118
- str = ctx.stylize('[Setter]', 'special');
3119
- }
3120
- }
3121
- }
3122
- if (visibleKeys.indexOf(key) < 0) {
3123
- name = '[' + key + ']';
3124
- }
3125
- if (!str) {
3126
- if (ctx.seen.indexOf(value[key]) < 0) {
3127
- if (recurseTimes === null) {
3128
- str = formatValue(ctx, value[key], null);
3129
- } else {
3130
- str = formatValue(ctx, value[key], recurseTimes - 1);
3131
- }
3132
- if (str.indexOf('\n') > -1) {
3133
- if (array) {
3134
- str = str.split('\n').map(function(line) {
3135
- return ' ' + line;
3136
- }).join('\n').substr(2);
3137
- } else {
3138
- str = '\n' + str.split('\n').map(function(line) {
3139
- return ' ' + line;
3140
- }).join('\n');
3141
- }
3142
- }
3143
- } else {
3144
- str = ctx.stylize('[Circular]', 'special');
3145
- }
3146
- }
3147
- if (typeof name === 'undefined') {
3148
- if (array && key.match(/^\d+$/)) {
3149
- return str;
3150
- }
3151
- name = JSON.stringify('' + key);
3152
- if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
3153
- name = name.substr(1, name.length - 2);
3154
- name = ctx.stylize(name, 'name');
3155
- } else {
3156
- name = name.replace(/'/g, "\\'")
3157
- .replace(/\\"/g, '"')
3158
- .replace(/(^"|"$)/g, "'");
3159
- name = ctx.stylize(name, 'string');
3160
- }
3161
- }
3162
-
3163
- return name + ': ' + str;
3164
- }
3165
-
3166
-
3167
- function reduceToSingleString(output, base, braces) {
3168
- var numLinesEst = 0;
3169
- var length = output.reduce(function(prev, cur) {
3170
- numLinesEst++;
3171
- if (cur.indexOf('\n') >= 0) numLinesEst++;
3172
- return prev + cur.length + 1;
3173
- }, 0);
3174
-
3175
- if (length > 60) {
3176
- return braces[0] +
3177
- (base === '' ? '' : base + '\n ') +
3178
- ' ' +
3179
- output.join(',\n ') +
3180
- ' ' +
3181
- braces[1];
3182
- }
3183
-
3184
- return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
3185
- }
3186
-
3187
- function isArray(ar) {
3188
- return Array.isArray(ar) ||
3189
- (typeof ar === 'object' && objectToString(ar) === '[object Array]');
3190
- }
3191
-
3192
- function isRegExp(re) {
3193
- return typeof re === 'object' && objectToString(re) === '[object RegExp]';
3194
- }
3195
-
3196
- function isDate(d) {
3197
- return typeof d === 'object' && objectToString(d) === '[object Date]';
3198
- }
3199
-
3200
- function isError(e) {
3201
- return typeof e === 'object' && objectToString(e) === '[object Error]';
3202
- }
3203
-
3204
- function objectToString(o) {
3205
- return Object.prototype.toString.call(o);
3206
- }
3207
-
3208
- }); // module: utils/inspect.js
3209
-
3210
- require.register("utils/overwriteMethod.js", function(module, exports, require){
3211
- /*!
3212
- * Chai - overwriteMethod utility
3213
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
3214
- * MIT Licensed
3215
- */
3216
-
3217
- /**
3218
- * ### overwriteMethod (ctx, name, fn)
3219
- *
3220
- * Overwites an already existing method and provides
3221
- * access to previous function. Must return function
3222
- * to be used for name.
3223
- *
3224
- * utils.overwriteMethod(chai.Assertion.prototype, 'equal', function (_super) {
3225
- * return function (str) {
3226
- * var obj = utils.flag(this, 'object');
3227
- * if (obj instanceof Foo) {
3228
- * new chai.Assertion(obj.value).to.equal(str);
3229
- * } else {
3230
- * _super.apply(this, arguments);
3231
- * }
3232
- * }
3233
- * });
3234
- *
3235
- * Can also be accessed directly from `chai.Assertion`.
3236
- *
3237
- * chai.Assertion.overwriteMethod('foo', fn);
3238
- *
3239
- * Then can be used as any other assertion.
3240
- *
3241
- * expect(myFoo).to.equal('bar');
3242
- *
3243
- * @param {Object} ctx object whose method is to be overwritten
3244
- * @param {String} name of method to overwrite
3245
- * @param {Function} method function that returns a function to be used for name
3246
- * @name overwriteMethod
3247
- * @api public
3248
- */
3249
-
3250
- module.exports = function (ctx, name, method) {
3251
- var _method = ctx[name]
3252
- , _super = function () { return this; };
3253
-
3254
- if (_method && 'function' === typeof _method)
3255
- _super = _method;
3256
-
3257
- ctx[name] = function () {
3258
- var result = method(_super).apply(this, arguments);
3259
- return result === undefined ? this : result;
3260
- }
3261
- };
3262
-
3263
- }); // module: utils/overwriteMethod.js
3264
-
3265
- require.register("utils/overwriteProperty.js", function(module, exports, require){
3266
- /*!
3267
- * Chai - overwriteProperty utility
3268
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
3269
- * MIT Licensed
3270
- */
3271
-
3272
- /**
3273
- * ### overwriteProperty (ctx, name, fn)
3274
- *
3275
- * Overwites an already existing property getter and provides
3276
- * access to previous value. Must return function to use as getter.
3277
- *
3278
- * utils.overwriteProperty(chai.Assertion.prototype, 'ok', function (_super) {
3279
- * return function () {
3280
- * var obj = utils.flag(this, 'object');
3281
- * if (obj instanceof Foo) {
3282
- * new chai.Assertion(obj.name).to.equal('bar');
3283
- * } else {
3284
- * _super.call(this);
3285
- * }
3286
- * }
3287
- * });
3288
- *
3289
- *
3290
- * Can also be accessed directly from `chai.Assertion`.
3291
- *
3292
- * chai.Assertion.overwriteProperty('foo', fn);
3293
- *
3294
- * Then can be used as any other assertion.
3295
- *
3296
- * expect(myFoo).to.be.ok;
3297
- *
3298
- * @param {Object} ctx object whose property is to be overwritten
3299
- * @param {String} name of property to overwrite
3300
- * @param {Function} getter function that returns a getter function to be used for name
3301
- * @name overwriteProperty
3302
- * @api public
3303
- */
3304
-
3305
- module.exports = function (ctx, name, getter) {
3306
- var _get = Object.getOwnPropertyDescriptor(ctx, name)
3307
- , _super = function () {};
3308
-
3309
- if (_get && 'function' === typeof _get.get)
3310
- _super = _get.get
3311
-
3312
- Object.defineProperty(ctx, name,
3313
- { get: function () {
3314
- var result = getter(_super).call(this);
3315
- return result === undefined ? this : result;
3316
- }
3317
- , configurable: true
3318
- });
3319
- };
3320
-
3321
- }); // module: utils/overwriteProperty.js
3322
-
3323
- require.register("utils/test.js", function(module, exports, require){
3324
- /*!
3325
- * Chai - test utility
3326
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
3327
- * MIT Licensed
3328
- */
3329
-
3330
- /*!
3331
- * Module dependancies
3332
- */
3333
-
3334
- var flag = require('./flag');
3335
-
3336
- /**
3337
- * # test(object, expression)
3338
- *
3339
- * Test and object for expression.
3340
- *
3341
- * @param {Object} object (constructed Assertion)
3342
- * @param {Arguments} chai.Assertion.prototype.assert arguments
3343
- */
3344
-
3345
- module.exports = function (obj, args) {
3346
- var negate = flag(obj, 'negate')
3347
- , expr = args[0];
3348
- return negate ? !expr : expr;
3349
- };
3350
-
3351
- }); // module: utils/test.js
3352
-
3353
- require.register("utils/transferFlags.js", function(module, exports, require){
3354
- /*!
3355
- * Chai - transferFlags utility
3356
- * Copyright(c) 2012 Jake Luer <jake@alogicalparadox.com>
3357
- * MIT Licensed
3358
- */
3359
-
3360
- /**
3361
- * ### transferFlags(assertion, object, includeAll = true)
3362
- *
3363
- * Transfer all the flags for `assertion` to `object`. If
3364
- * `includeAll` is set to `false`, then the base Chai
3365
- * assertion flags (namely `object`, `ssfi`, and `message`)
3366
- * will not be transferred.
3367
- *
3368
- *
3369
- * var newAssertion = new Assertion();
3370
- * utils.transferFlags(assertion, newAssertion);
3371
- *
3372
- * var anotherAsseriton = new Assertion(myObj);
3373
- * utils.transferFlags(assertion, anotherAssertion, false);
3374
- *
3375
- * @param {Assertion} assertion the assertion to transfer the flags from
3376
- * @param {Object} object the object to transfer the flags too; usually a new assertion
3377
- * @param {Boolean} includeAll
3378
- * @name getAllFlags
3379
- * @api private
3380
- */
3381
-
3382
- module.exports = function (assertion, object, includeAll) {
3383
- var flags = assertion.__flags || (assertion.__flags = Object.create(null));
3384
-
3385
- if (!object.__flags) {
3386
- object.__flags = Object.create(null);
3387
- }
3388
-
3389
- includeAll = arguments.length === 3 ? includeAll : true;
3390
-
3391
- for (var flag in flags) {
3392
- if (includeAll ||
3393
- (flag !== 'object' && flag !== 'ssfi' && flag != 'message')) {
3394
- object.__flags[flag] = flags[flag];
3395
- }
3396
- }
3397
- };
3398
-
3399
- }); // module: utils/transferFlags.js
3400
-
3401
-
3402
- return require('chai');
3403
- });