1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
9 | window.Should = require('./index');
|
10 |
|
11 | Object.defineProperty(window, 'should', {
|
12 | enumerable: false,
|
13 | configurable: true,
|
14 | value: window.Should
|
15 | });
|
16 |
|
17 | },{"./index":2}],2:[function(require,module,exports){
|
18 | var should = require('./lib/should');
|
19 |
|
20 | var defaultProto = Object.prototype;
|
21 | var defaultProperty = 'should';
|
22 |
|
23 |
|
24 | try {
|
25 | var prevShould = should.extend(defaultProperty, defaultProto);
|
26 | should._prevShould = prevShould;
|
27 | } catch(e) {
|
28 |
|
29 | }
|
30 |
|
31 | module.exports = should;
|
32 |
|
33 | },{"./lib/should":19}],3:[function(require,module,exports){
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | var util = require('./util');
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | var AssertionError = function AssertionError(options) {
|
50 | util.merge(this, options);
|
51 |
|
52 | if(!options.message) {
|
53 | Object.defineProperty(this, 'message', {
|
54 | get: function() {
|
55 | if(!this._message) {
|
56 | this._message = this.generateMessage();
|
57 | this.generatedMessage = true;
|
58 | }
|
59 | return this._message;
|
60 | },
|
61 | configurable: true,
|
62 | enumerable: false
|
63 | }
|
64 | );
|
65 | }
|
66 |
|
67 | if(Error.captureStackTrace) {
|
68 | Error.captureStackTrace(this, this.stackStartFunction);
|
69 | } else {
|
70 |
|
71 | var err = new Error();
|
72 | if(err.stack) {
|
73 | var out = err.stack;
|
74 |
|
75 | if(this.stackStartFunction) {
|
76 |
|
77 | var fn_name = util.functionName(this.stackStartFunction);
|
78 | var idx = out.indexOf('\n' + fn_name);
|
79 | if(idx >= 0) {
|
80 |
|
81 |
|
82 | var next_line = out.indexOf('\n', idx + 1);
|
83 | out = out.substring(next_line + 1);
|
84 | }
|
85 | }
|
86 |
|
87 | this.stack = out;
|
88 | }
|
89 | }
|
90 | };
|
91 |
|
92 |
|
93 | var indent = ' ';
|
94 | function prependIndent(line) {
|
95 | return indent + line;
|
96 | }
|
97 |
|
98 | function indentLines(text) {
|
99 | return text.split('\n').map(prependIndent).join('\n');
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 | AssertionError.prototype = Object.create(Error.prototype, {
|
105 | name: {
|
106 | value: 'AssertionError'
|
107 | },
|
108 |
|
109 | generateMessage: {
|
110 | value: function() {
|
111 | if(!this.operator && this.previous) {
|
112 | return this.previous.message;
|
113 | }
|
114 | var actual = util.format(this.actual);
|
115 | var expected = 'expected' in this ? ' ' + util.format(this.expected) : '';
|
116 | var details = 'details' in this && this.details ? ' (' + this.details + ')' : '';
|
117 |
|
118 | var previous = this.previous ? '\n' + indentLines(this.previous.message) : '';
|
119 |
|
120 | return 'expected ' + actual + (this.negate ? ' not ' : ' ') + this.operator + expected + details + previous;
|
121 | }
|
122 | }
|
123 | });
|
124 |
|
125 | module.exports = AssertionError;
|
126 |
|
127 | },{"./util":20}],4:[function(require,module,exports){
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | var AssertionError = require('./assertion-error');
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | function Assertion(obj) {
|
144 | this.obj = obj;
|
145 |
|
146 | this.anyOne = false;
|
147 | this.negate = false;
|
148 |
|
149 | this.params = {actual: obj};
|
150 | }
|
151 |
|
152 | Assertion.prototype = {
|
153 | constructor: Assertion,
|
154 |
|
155 | /**
|
156 | * Base method for assertions.
|
157 | *
|
158 | * Before calling this method need to fill Assertion#params object. This method usually called from other assertion methods.
|
159 | * `Assertion#params` can contain such properties:
|
160 | * * `operator` - required string containing description of this assertion
|
161 | * * `obj` - optional replacement for this.obj, it usefull if you prepare more clear object then given
|
162 | * * `message` - if this property filled with string any others will be ignored and this one used as assertion message
|
163 | * * `expected` - any object used when you need to assert relation between given object and expected. Like given == expected (== is a relation)
|
164 | * * `details` - additional string with details to generated message
|
165 | *
|
166 | * @memberOf Assertion
|
167 | * @category assertion
|
168 | * @param {*} expr Any expression that will be used as a condition for asserting.
|
169 | * @example
|
170 | *
|
171 | * var a = new should.Assertion(42);
|
172 | *
|
173 | * a.params = {
|
174 | * operator: 'to be magic number',
|
175 | * }
|
176 | *
|
177 | * a.assert(false);
|
178 | *
|
179 | */
|
180 | assert: function(expr) {
|
181 | if(expr) {
|
182 | return this;
|
183 | }
|
184 |
|
185 | var params = this.params;
|
186 |
|
187 | if('obj' in params && !('actual' in params)) {
|
188 | params.actual = params.obj;
|
189 | } else if(!('obj' in params) && !('actual' in params)) {
|
190 | params.actual = this.obj;
|
191 | }
|
192 |
|
193 | params.stackStartFunction = params.stackStartFunction || this.assert;
|
194 | params.negate = this.negate;
|
195 |
|
196 | params.assertion = this;
|
197 |
|
198 | throw new AssertionError(params);
|
199 | },
|
200 |
|
201 | |
202 |
|
203 |
|
204 |
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 | fail: function() {
|
218 | return this.assert(false);
|
219 | }
|
220 | };
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 | function PromisedAssertion(/* obj */) {
|
231 | Assertion.apply(this, arguments);
|
232 | }
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | PromisedAssertion.prototype.then = function(resolve, reject) {
|
241 | return this.obj.then(resolve, reject);
|
242 | };
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 | Assertion.add = function(name, func) {
|
265 | Object.defineProperty(Assertion.prototype, name, {
|
266 | enumerable: true,
|
267 | configurable: true,
|
268 | value: function() {
|
269 | var context = new Assertion(this.obj, this, name);
|
270 | context.anyOne = this.anyOne;
|
271 |
|
272 | try {
|
273 | func.apply(context, arguments);
|
274 | } catch (e) {
|
275 |
|
276 | if (e instanceof AssertionError) {
|
277 |
|
278 | if (this.negate) {
|
279 | this.obj = context.obj;
|
280 | this.negate = false;
|
281 | return this;
|
282 | }
|
283 |
|
284 | if (context !== e.assertion) {
|
285 | context.params.previous = e;
|
286 | }
|
287 |
|
288 |
|
289 | context.negate = false;
|
290 | context.fail();
|
291 | }
|
292 |
|
293 | throw e;
|
294 | }
|
295 |
|
296 |
|
297 | if (this.negate) {
|
298 | context.negate = true;
|
299 | context.params.details = 'false negative fail';
|
300 | context.fail();
|
301 | }
|
302 |
|
303 |
|
304 | if (!this.params.operator) {
|
305 | this.params = context.params;
|
306 | }
|
307 | this.obj = context.obj;
|
308 | this.negate = false;
|
309 | return this;
|
310 | }
|
311 | });
|
312 |
|
313 | Object.defineProperty(PromisedAssertion.prototype, name, {
|
314 | enumerable: true,
|
315 | configurable: true,
|
316 | value: function() {
|
317 | var args = arguments;
|
318 | this.obj = this.obj.then(function(a) {
|
319 | return a[name].apply(a, args);
|
320 | });
|
321 |
|
322 | return this;
|
323 | }
|
324 | });
|
325 | };
|
326 |
|
327 |
|
328 |
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 | Assertion.addChain = function(name, onCall) {
|
336 | onCall = onCall || function() {};
|
337 | Object.defineProperty(Assertion.prototype, name, {
|
338 | get: function() {
|
339 | onCall.call(this);
|
340 | return this;
|
341 | },
|
342 | enumerable: true
|
343 | });
|
344 |
|
345 | Object.defineProperty(PromisedAssertion.prototype, name, {
|
346 | enumerable: true,
|
347 | configurable: true,
|
348 | get: function() {
|
349 | this.obj = this.obj.then(function(a) {
|
350 | return a[name];
|
351 | });
|
352 |
|
353 | return this;
|
354 | }
|
355 | });
|
356 | };
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | Assertion.alias = function(from, to) {
|
370 | var desc = Object.getOwnPropertyDescriptor(Assertion.prototype, from);
|
371 | if (!desc) throw new Error('Alias ' + from + ' -> ' + to + ' could not be created as ' + from + ' not defined');
|
372 | Object.defineProperty(Assertion.prototype, to, desc);
|
373 |
|
374 | var desc2 = Object.getOwnPropertyDescriptor(PromisedAssertion.prototype, from);
|
375 | if (desc2) {
|
376 | Object.defineProperty(PromisedAssertion.prototype, to, desc2);
|
377 | }
|
378 | };
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 | Assertion.addChain('not', function() {
|
388 | this.negate = !this.negate;
|
389 | });
|
390 |
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 | Assertion.addChain('any', function() {
|
400 | this.anyOne = true;
|
401 | });
|
402 |
|
403 | module.exports = Assertion;
|
404 | module.exports.PromisedAssertion = PromisedAssertion;
|
405 |
|
406 | },{"./assertion-error":3}],5:[function(require,module,exports){
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 | var Formatter = require('should-format').Formatter;
|
414 |
|
415 | var config = {
|
416 | checkProtoEql: false,
|
417 |
|
418 | getFormatter: function(opts) {
|
419 | return new Formatter(opts || config);
|
420 | }
|
421 | };
|
422 |
|
423 | module.exports = config;
|
424 |
|
425 | },{"should-format":23}],6:[function(require,module,exports){
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | var Assertion = require('./../assertion');
|
456 |
|
457 | var _deepEqual = require('should-equal');
|
458 |
|
459 | var pSlice = Array.prototype.slice;
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 | var assert = module.exports = ok;
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 |
|
477 |
|
478 |
|
479 |
|
480 |
|
481 |
|
482 | function fail(actual, expected, message, operator, stackStartFunction) {
|
483 | var a = new Assertion(actual);
|
484 | a.params = {
|
485 | operator: operator,
|
486 | expected: expected,
|
487 | message: message,
|
488 | stackStartFunction: stackStartFunction || fail
|
489 | };
|
490 |
|
491 | a.fail();
|
492 | }
|
493 |
|
494 |
|
495 | assert.fail = fail;
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 | function ok(value, message) {
|
512 | if(!value) fail(value, true, message, '==', assert.ok);
|
513 | }
|
514 | assert.ok = ok;
|
515 |
|
516 |
|
517 |
|
518 |
|
519 |
|
520 |
|
521 |
|
522 |
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 | assert.equal = function equal(actual, expected, message) {
|
530 | if(actual != expected) fail(actual, expected, message, '==', assert.equal);
|
531 | };
|
532 |
|
533 |
|
534 |
|
535 |
|
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 |
|
542 |
|
543 |
|
544 | assert.notEqual = function notEqual(actual, expected, message) {
|
545 | if(actual == expected) {
|
546 | fail(actual, expected, message, '!=', assert.notEqual);
|
547 | }
|
548 | };
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 | assert.deepEqual = function deepEqual(actual, expected, message) {
|
564 | if(!_deepEqual(actual, expected).result) {
|
565 | fail(actual, expected, message, 'deepEqual', assert.deepEqual);
|
566 | }
|
567 | };
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 |
|
580 |
|
581 |
|
582 |
|
583 | assert.notDeepEqual = function notDeepEqual(actual, expected, message) {
|
584 | if(_deepEqual(actual, expected).result) {
|
585 | fail(actual, expected, message, 'notDeepEqual', assert.notDeepEqual);
|
586 | }
|
587 | };
|
588 |
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 | assert.strictEqual = function strictEqual(actual, expected, message) {
|
601 | if(actual !== expected) {
|
602 | fail(actual, expected, message, '===', assert.strictEqual);
|
603 | }
|
604 | };
|
605 |
|
606 |
|
607 |
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 | assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
618 | if(actual === expected) {
|
619 | fail(actual, expected, message, '!==', assert.notStrictEqual);
|
620 | }
|
621 | };
|
622 |
|
623 | function expectedException(actual, expected) {
|
624 | if(!actual || !expected) {
|
625 | return false;
|
626 | }
|
627 |
|
628 | if(Object.prototype.toString.call(expected) == '[object RegExp]') {
|
629 | return expected.test(actual);
|
630 | } else if(actual instanceof expected) {
|
631 | return true;
|
632 | } else if(expected.call({}, actual) === true) {
|
633 | return true;
|
634 | }
|
635 |
|
636 | return false;
|
637 | }
|
638 |
|
639 | function _throws(shouldThrow, block, expected, message) {
|
640 | var actual;
|
641 |
|
642 | if(typeof expected == 'string') {
|
643 | message = expected;
|
644 | expected = null;
|
645 | }
|
646 |
|
647 | try {
|
648 | block();
|
649 | } catch(e) {
|
650 | actual = e;
|
651 | }
|
652 |
|
653 | message = (expected && expected.name ? ' (' + expected.name + ')' : '.') +
|
654 | (message ? ' ' + message : '.');
|
655 |
|
656 | if(shouldThrow && !actual) {
|
657 | fail(actual, expected, 'Missing expected exception' + message);
|
658 | }
|
659 |
|
660 | if(!shouldThrow && expectedException(actual, expected)) {
|
661 | fail(actual, expected, 'Got unwanted exception' + message);
|
662 | }
|
663 |
|
664 | if((shouldThrow && actual && expected && !expectedException(actual, expected)) || (!shouldThrow && actual)) {
|
665 | throw actual;
|
666 | }
|
667 | }
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 | assert.throws = function(block, /*optional*/error, /*optional*/message) {
|
681 | _throws.apply(this, [true].concat(pSlice.call(arguments)));
|
682 | };
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 | assert.doesNotThrow = function(block, /*optional*/message) {
|
694 | _throws.apply(this, [false].concat(pSlice.call(arguments)));
|
695 | };
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 | assert.ifError = function(err) {
|
705 | if(err) {
|
706 | throw err;
|
707 | }
|
708 | };
|
709 |
|
710 | },{"./../assertion":4,"should-equal":22}],7:[function(require,module,exports){
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | var util = require('../util')
|
718 | , assert = require('./_assert')
|
719 | , AssertionError = require('../assertion-error');
|
720 |
|
721 | module.exports = function(should) {
|
722 | var i = should.format;
|
723 |
|
724 | |
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 | util.merge(should, assert);
|
734 |
|
735 | |
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 | should.exist = should.exists = function(obj, msg) {
|
750 | if(null == obj) {
|
751 | throw new AssertionError({
|
752 | message: msg || ('expected ' + i(obj) + ' to exist'), stackStartFunction: should.exist
|
753 | });
|
754 | }
|
755 | };
|
756 |
|
757 | should.not = {};
|
758 | |
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 |
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 |
|
772 |
|
773 | should.not.exist = should.not.exists = function(obj, msg) {
|
774 | if(null != obj) {
|
775 | throw new AssertionError({
|
776 | message: msg || ('expected ' + i(obj) + ' to not exist'), stackStartFunction: should.not.exist
|
777 | });
|
778 | }
|
779 | };
|
780 | };
|
781 | },{"../assertion-error":3,"../util":20,"./_assert":6}],8:[function(require,module,exports){
|
782 |
|
783 |
|
784 |
|
785 |
|
786 |
|
787 |
|
788 | module.exports = function(should, Assertion) {
|
789 | |
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 | Assertion.add('true', function() {
|
804 | this.is.exactly(true);
|
805 | });
|
806 |
|
807 | Assertion.alias('true', 'True');
|
808 |
|
809 | |
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 | Assertion.add('false', function() {
|
822 | this.is.exactly(false);
|
823 | });
|
824 |
|
825 | Assertion.alias('false', 'False');
|
826 |
|
827 | |
828 |
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 | Assertion.add('ok', function() {
|
844 | this.params = { operator: 'to be truthy' };
|
845 |
|
846 | this.assert(this.obj);
|
847 | });
|
848 | };
|
849 |
|
850 | },{}],9:[function(require,module,exports){
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 | module.exports = function(should, Assertion) {
|
858 | |
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 | ['an', 'of', 'a', 'and', 'be', 'has', 'have', 'with', 'is', 'which', 'the', 'it'].forEach(function(name) {
|
878 | Assertion.addChain(name);
|
879 | });
|
880 | };
|
881 |
|
882 | },{}],10:[function(require,module,exports){
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 | var util = require('../util');
|
890 | var eql = require('should-equal');
|
891 |
|
892 | module.exports = function(should, Assertion) {
|
893 | var i = should.format;
|
894 |
|
895 | |
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 | Assertion.add('containEql', function(other) {
|
920 | this.params = {operator: 'to contain ' + i(other)};
|
921 |
|
922 | this.is.not.null().and.not.undefined();
|
923 |
|
924 | var obj = this.obj;
|
925 |
|
926 | if(typeof obj == 'string') {
|
927 | this.assert(obj.indexOf(String(other)) >= 0);
|
928 | } else if(util.isIndexable(obj)) {
|
929 | this.assert(util.some(obj, function(v) {
|
930 | return eql(v, other).result;
|
931 | }));
|
932 | } else {
|
933 | this.have.properties(other);
|
934 | }
|
935 | });
|
936 |
|
937 | |
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 | Assertion.add('containDeepOrdered', function(other) {
|
957 | this.params = {operator: 'to contain ' + i(other)};
|
958 |
|
959 | var obj = this.obj;
|
960 | if(typeof obj == 'string') {
|
961 | this.is.equal(String(other));
|
962 | } else if(util.isIndexable(obj) && util.isIndexable(other)) {
|
963 | for(var objIdx = 0, otherIdx = 0, objLength = util.length(obj), otherLength = util.length(other); objIdx < objLength && otherIdx < otherLength; objIdx++) {
|
964 | try {
|
965 | should(obj[objIdx]).containDeepOrdered(other[otherIdx]);
|
966 | otherIdx++;
|
967 | } catch(e) {
|
968 | if(e instanceof should.AssertionError) {
|
969 | continue;
|
970 | }
|
971 | throw e;
|
972 | }
|
973 | }
|
974 |
|
975 | this.assert(otherIdx === otherLength);
|
976 | } else if(obj != null && other != null && typeof obj == 'object' && typeof other == 'object') {
|
977 | util.forEach(other, function(value, key) {
|
978 | should(obj[key]).containDeepOrdered(value);
|
979 | });
|
980 |
|
981 |
|
982 | if(util.isEmptyObject(other)) {
|
983 | this.eql(other);
|
984 | }
|
985 | } else {
|
986 | this.eql(other);
|
987 | }
|
988 | });
|
989 |
|
990 | |
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 | Assertion.add('containDeep', function(other) {
|
1003 | this.params = {operator: 'to contain ' + i(other)};
|
1004 |
|
1005 | var obj = this.obj;
|
1006 | if(typeof obj == 'string') {
|
1007 | this.is.equal(String(other));
|
1008 | } else if(util.isIndexable(obj) && util.isIndexable(other)) {
|
1009 | var usedKeys = {};
|
1010 | util.forEach(other, function(otherItem) {
|
1011 | this.assert(util.some(obj, function(item, index) {
|
1012 | if(index in usedKeys) return false;
|
1013 |
|
1014 | try {
|
1015 | should(item).containDeep(otherItem);
|
1016 | usedKeys[index] = true;
|
1017 | return true;
|
1018 | } catch(e) {
|
1019 | if(e instanceof should.AssertionError) {
|
1020 | return false;
|
1021 | }
|
1022 | throw e;
|
1023 | }
|
1024 | }));
|
1025 | }, this);
|
1026 | } else if(obj != null && other != null && typeof obj == 'object' && typeof other == 'object') {
|
1027 | util.forEach(other, function(value, key) {
|
1028 | should(obj[key]).containDeep(value);
|
1029 | });
|
1030 |
|
1031 |
|
1032 | if(util.isEmptyObject(other)) {
|
1033 | this.eql(other);
|
1034 | }
|
1035 | } else {
|
1036 | this.eql(other);
|
1037 | }
|
1038 | });
|
1039 |
|
1040 | };
|
1041 |
|
1042 | },{"../util":20,"should-equal":22}],11:[function(require,module,exports){
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 | var eql = require('should-equal');
|
1050 | var type = require('should-type');
|
1051 | var util = require('../util');
|
1052 |
|
1053 | function formatEqlResult(r, a, b) {
|
1054 | return ((r.path.length > 0 ? 'at ' + r.path.map(util.formatProp).join(' -> ') : '') +
|
1055 | (r.a === a ? '' : ', A has ' + util.format(r.a)) +
|
1056 | (r.b === b ? '' : ' and B has ' + util.format(r.b)) +
|
1057 | (r.showReason ? ' because ' + r.reason : '')).trim();
|
1058 | }
|
1059 |
|
1060 | module.exports = function(should, Assertion) {
|
1061 |
|
1062 | |
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 | Assertion.add('eql', function(val, description) {
|
1083 | this.params = {operator: 'to equal', expected: val, message: description};
|
1084 |
|
1085 | var result = eql(this.obj, val, should.config);
|
1086 | this.params.details = result.result ? '' : formatEqlResult(result, this.obj, val);
|
1087 |
|
1088 | this.params.showDiff = eql(type(this.obj), type(val)).result;
|
1089 |
|
1090 | this.assert(result.result);
|
1091 | });
|
1092 |
|
1093 | |
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 | Assertion.add('equal', function(val, description) {
|
1110 | this.params = {operator: 'to be', expected: val, message: description};
|
1111 |
|
1112 | this.params.showDiff = eql(type(this.obj), type(val)).result;
|
1113 |
|
1114 | this.assert(val === this.obj);
|
1115 | });
|
1116 |
|
1117 | Assertion.alias('equal', 'exactly');
|
1118 | Assertion.alias('eql', 'deepEqual');
|
1119 |
|
1120 | function addOneOf(name, message, method) {
|
1121 | Assertion.add(name, function(vals) {
|
1122 | if(arguments.length !== 1) {
|
1123 | vals = Array.prototype.slice.call(arguments);
|
1124 | } else {
|
1125 | should(vals).be.Array();
|
1126 | }
|
1127 |
|
1128 | this.params = {operator: message, expected: vals};
|
1129 |
|
1130 | var obj = this.obj;
|
1131 | var found = false;
|
1132 |
|
1133 | util.forEach(vals, function(val) {
|
1134 | try {
|
1135 | should(val)[method](obj);
|
1136 | found = true;
|
1137 | return false;
|
1138 | } catch(e) {
|
1139 | if(e instanceof should.AssertionError) {
|
1140 | return;
|
1141 | }
|
1142 | throw e;
|
1143 | }
|
1144 | });
|
1145 |
|
1146 | this.assert(found);
|
1147 | });
|
1148 | }
|
1149 |
|
1150 | |
1151 |
|
1152 |
|
1153 |
|
1154 |
|
1155 |
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 | addOneOf('equalOneOf', 'to be equals one of', 'equal');
|
1163 |
|
1164 | |
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 | addOneOf('oneOf', 'to be one of', 'eql');
|
1177 |
|
1178 | };
|
1179 |
|
1180 | },{"../util":20,"should-equal":22,"should-type":27}],12:[function(require,module,exports){
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 | var util = require('../util');
|
1187 |
|
1188 | module.exports = function(should, Assertion) {
|
1189 | var i = should.format;
|
1190 |
|
1191 | |
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 | Assertion.add('throw', function(message, properties) {
|
1216 | var fn = this.obj
|
1217 | , err = {}
|
1218 | , errorInfo = ''
|
1219 | , thrown = false;
|
1220 |
|
1221 | if(util.isGeneratorFunction(fn)) {
|
1222 | return should(fn()).throw(message, properties);
|
1223 | } else if(util.isGeneratorObject(fn)) {
|
1224 | return should(fn.next.bind(fn)).throw(message, properties);
|
1225 | }
|
1226 |
|
1227 | this.is.a.Function();
|
1228 |
|
1229 | var errorMatched = true;
|
1230 |
|
1231 | try {
|
1232 | fn();
|
1233 | } catch(e) {
|
1234 | thrown = true;
|
1235 | err = e;
|
1236 | }
|
1237 |
|
1238 | if(thrown) {
|
1239 | if(message) {
|
1240 | if('string' == typeof message) {
|
1241 | errorMatched = message == err.message;
|
1242 | } else if(message instanceof RegExp) {
|
1243 | errorMatched = message.test(err.message);
|
1244 | } else if('function' == typeof message) {
|
1245 | errorMatched = err instanceof message;
|
1246 | } else if(null != message) {
|
1247 | try {
|
1248 | should(err).match(message);
|
1249 | } catch(e) {
|
1250 | if(e instanceof should.AssertionError) {
|
1251 | errorInfo = ": " + e.message;
|
1252 | errorMatched = false;
|
1253 | } else {
|
1254 | throw e;
|
1255 | }
|
1256 | }
|
1257 | }
|
1258 |
|
1259 | if(!errorMatched) {
|
1260 | if('string' == typeof message || message instanceof RegExp) {
|
1261 | errorInfo = " with a message matching " + i(message) + ", but got '" + err.message + "'";
|
1262 | } else if('function' == typeof message) {
|
1263 | errorInfo = " of type " + util.functionName(message) + ", but got " + util.functionName(err.constructor);
|
1264 | }
|
1265 | } else if('function' == typeof message && properties) {
|
1266 | try {
|
1267 | should(err).match(properties);
|
1268 | } catch(e) {
|
1269 | if(e instanceof should.AssertionError) {
|
1270 | errorInfo = ": " + e.message;
|
1271 | errorMatched = false;
|
1272 | } else {
|
1273 | throw e;
|
1274 | }
|
1275 | }
|
1276 | }
|
1277 | } else {
|
1278 | errorInfo = " (got " + i(err) + ")";
|
1279 | }
|
1280 | }
|
1281 |
|
1282 | this.params = { operator: 'to throw exception' + errorInfo };
|
1283 |
|
1284 | this.assert(thrown);
|
1285 | this.assert(errorMatched);
|
1286 | });
|
1287 |
|
1288 | Assertion.alias('throw', 'throwError');
|
1289 | };
|
1290 |
|
1291 | },{"../util":20}],13:[function(require,module,exports){
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 | var util = require('../util');
|
1299 | var eql = require('should-equal');
|
1300 |
|
1301 | module.exports = function(should, Assertion) {
|
1302 | var i = should.format;
|
1303 |
|
1304 | |
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 | Assertion.add('match', function(other, description) {
|
1361 | this.params = {operator: 'to match ' + i(other), message: description};
|
1362 |
|
1363 | if(!eql(this.obj, other).result) {
|
1364 | if(other instanceof RegExp) {
|
1365 |
|
1366 | if(typeof this.obj == 'string') {
|
1367 |
|
1368 | this.assert(other.exec(this.obj));
|
1369 | } else if(util.isIndexable(this.obj)) {
|
1370 | util.forEach(this.obj, function(item) {
|
1371 | this.assert(other.exec(item));
|
1372 | }, this);
|
1373 | } else if(null != this.obj && typeof this.obj == 'object') {
|
1374 |
|
1375 | var notMatchedProps = [], matchedProps = [];
|
1376 | util.forEach(this.obj, function(value, name) {
|
1377 | if(other.exec(value)) matchedProps.push(util.formatProp(name));
|
1378 | else notMatchedProps.push(util.formatProp(name) + ' (' + i(value) + ')');
|
1379 | }, this);
|
1380 |
|
1381 | if(notMatchedProps.length)
|
1382 | this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', ');
|
1383 | if(matchedProps.length)
|
1384 | this.params.operator += '\n matched properties: ' + matchedProps.join(', ');
|
1385 |
|
1386 | this.assert(notMatchedProps.length === 0);
|
1387 | }
|
1388 | } else if(typeof other == 'function') {
|
1389 | var res;
|
1390 |
|
1391 | res = other(this.obj);
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 | if(typeof res == 'boolean') {
|
1399 | this.assert(res);
|
1400 | }
|
1401 | } else if(other != null && this.obj != null && typeof other == 'object') {
|
1402 | notMatchedProps = [];
|
1403 | matchedProps = [];
|
1404 |
|
1405 | util.forEach(other, function(value, key) {
|
1406 | try {
|
1407 | should(this.obj).have.property(key).which.match(value);
|
1408 | matchedProps.push(util.formatProp(key));
|
1409 | } catch(e) {
|
1410 | if(e instanceof should.AssertionError) {
|
1411 | notMatchedProps.push(util.formatProp(key) + ' (' + i(this.obj[key]) + ')');
|
1412 | } else {
|
1413 | throw e;
|
1414 | }
|
1415 | }
|
1416 | }, this);
|
1417 |
|
1418 | if(notMatchedProps.length)
|
1419 | this.params.operator += '\n not matched properties: ' + notMatchedProps.join(', ');
|
1420 | if(matchedProps.length)
|
1421 | this.params.operator += '\n matched properties: ' + matchedProps.join(', ');
|
1422 |
|
1423 | this.assert(notMatchedProps.length === 0);
|
1424 | } else {
|
1425 | this.assert(false);
|
1426 | }
|
1427 | }
|
1428 | });
|
1429 |
|
1430 | |
1431 |
|
1432 |
|
1433 |
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 | Assertion.add('matchEach', function(other, description) {
|
1452 | this.params = {operator: 'to match each ' + i(other), message: description};
|
1453 |
|
1454 | util.forEach(this.obj, function(value) {
|
1455 | should(value).match(other);
|
1456 | }, this);
|
1457 | });
|
1458 |
|
1459 | |
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 | Assertion.add('matchAny', function(other, description) {
|
1481 | this.params = {operator: 'to match any ' + i(other), message: description};
|
1482 |
|
1483 | this.assert(util.some(this.obj, function(value) {
|
1484 | try {
|
1485 | should(value).match(other);
|
1486 | return true;
|
1487 | } catch(e) {
|
1488 | if(e instanceof should.AssertionError) {
|
1489 |
|
1490 | return false;
|
1491 | }
|
1492 | throw e;
|
1493 | }
|
1494 | }));
|
1495 | });
|
1496 |
|
1497 | Assertion.alias('matchAny', 'matchSome');
|
1498 | Assertion.alias('matchEach', 'matchEvery');
|
1499 | };
|
1500 |
|
1501 | },{"../util":20,"should-equal":22}],14:[function(require,module,exports){
|
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 |
|
1507 |
|
1508 | module.exports = function(should, Assertion) {
|
1509 |
|
1510 | |
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 | Assertion.add('NaN', function() {
|
1521 | this.params = { operator: 'to be NaN' };
|
1522 |
|
1523 | this.assert(this.obj !== this.obj);
|
1524 | });
|
1525 |
|
1526 | |
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 | Assertion.add('Infinity', function() {
|
1538 | this.params = { operator: 'to be Infinity' };
|
1539 |
|
1540 | this.is.a.Number()
|
1541 | .and.not.a.NaN()
|
1542 | .and.assert(!isFinite(this.obj));
|
1543 | });
|
1544 |
|
1545 | |
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 | Assertion.add('within', function(start, finish, description) {
|
1559 | this.params = { operator: 'to be within ' + start + '..' + finish, message: description };
|
1560 |
|
1561 | this.assert(this.obj >= start && this.obj <= finish);
|
1562 | });
|
1563 |
|
1564 | |
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 | Assertion.add('approximately', function(value, delta, description) {
|
1578 | this.params = { operator: 'to be approximately ' + value + ' ±' + delta, message: description };
|
1579 |
|
1580 | this.assert(Math.abs(this.obj - value) <= delta);
|
1581 | });
|
1582 |
|
1583 | |
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 | Assertion.add('above', function(n, description) {
|
1597 | this.params = { operator: 'to be above ' + n, message: description };
|
1598 |
|
1599 | this.assert(this.obj > n);
|
1600 | });
|
1601 |
|
1602 | |
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 | Assertion.add('below', function(n, description) {
|
1616 | this.params = { operator: 'to be below ' + n, message: description };
|
1617 |
|
1618 | this.assert(this.obj < n);
|
1619 | });
|
1620 |
|
1621 | Assertion.alias('above', 'greaterThan');
|
1622 | Assertion.alias('below', 'lessThan');
|
1623 |
|
1624 | |
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 |
|
1634 |
|
1635 |
|
1636 |
|
1637 |
|
1638 | Assertion.add('aboveOrEqual', function(n, description) {
|
1639 | this.params = { operator: 'to be above or equal' + n, message: description };
|
1640 |
|
1641 | this.assert(this.obj >= n);
|
1642 | });
|
1643 |
|
1644 | |
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 | Assertion.add('belowOrEqual', function(n, description) {
|
1659 | this.params = { operator: 'to be below or equal' + n, message: description };
|
1660 |
|
1661 | this.assert(this.obj <= n);
|
1662 | });
|
1663 |
|
1664 | Assertion.alias('aboveOrEqual', 'greaterThanOrEqual');
|
1665 | Assertion.alias('belowOrEqual', 'lessThanOrEqual');
|
1666 |
|
1667 | };
|
1668 |
|
1669 | },{}],15:[function(require,module,exports){
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 | var util = require('../util');
|
1677 | var PromisedAssertion = require('../assertion').PromisedAssertion;
|
1678 | var Assertion = require('../assertion');
|
1679 |
|
1680 | module.exports = function(should) {
|
1681 | |
1682 |
|
1683 |
|
1684 |
|
1685 |
|
1686 |
|
1687 |
|
1688 |
|
1689 |
|
1690 |
|
1691 |
|
1692 |
|
1693 | Assertion.add('Promise', function() {
|
1694 | this.params = {operator: 'to be promise'};
|
1695 |
|
1696 | var obj = this.obj;
|
1697 |
|
1698 | should(obj).have.property('then')
|
1699 | .which.is.a.Function();
|
1700 | });
|
1701 |
|
1702 | |
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 | Assertion.prototype.fulfilled = function Assertion$fulfilled() {
|
1721 | this.params = {operator: 'to be fulfilled'};
|
1722 |
|
1723 | should(this.obj).be.a.Promise();
|
1724 |
|
1725 | var that = this;
|
1726 | return this.obj.then(function next$onResolve(value) {
|
1727 | if (that.negate) {
|
1728 | that.fail();
|
1729 | }
|
1730 | return value;
|
1731 | }, function next$onReject(err) {
|
1732 | if (!that.negate) {
|
1733 | that.fail();
|
1734 | }
|
1735 | return err;
|
1736 | });
|
1737 | };
|
1738 |
|
1739 | |
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 | Assertion.prototype.rejected = function() {
|
1759 | this.params = {operator: 'to be rejected'};
|
1760 |
|
1761 | should(this.obj).be.a.Promise();
|
1762 |
|
1763 | var that = this;
|
1764 | return this.obj.then(function(value) {
|
1765 | if (!that.negate) {
|
1766 | that.fail();
|
1767 | }
|
1768 | return value;
|
1769 | }, function next$onError(err) {
|
1770 | if (that.negate) {
|
1771 | that.fail();
|
1772 | }
|
1773 | return err;
|
1774 | });
|
1775 | };
|
1776 |
|
1777 | |
1778 |
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 |
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 |
|
1796 |
|
1797 | Assertion.prototype.fulfilledWith = function(expectedValue) {
|
1798 | this.params = {operator: 'to be fulfilled'};
|
1799 |
|
1800 | should(this.obj).be.a.Promise();
|
1801 |
|
1802 | var that = this;
|
1803 | return this.obj.then(function(value) {
|
1804 | if (that.negate) {
|
1805 | that.fail();
|
1806 | }
|
1807 | should(value).eql(expectedValue);
|
1808 | return value;
|
1809 | }, function next$onError(err) {
|
1810 | if (!that.negate) {
|
1811 | that.fail();
|
1812 | }
|
1813 | return err;
|
1814 | });
|
1815 | };
|
1816 |
|
1817 | |
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 | Assertion.prototype.rejectedWith = function(message, properties) {
|
1844 | this.params = {operator: 'to be rejected'};
|
1845 |
|
1846 | should(this.obj).be.a.Promise();
|
1847 |
|
1848 | var that = this;
|
1849 | return this.obj.then(function(value) {
|
1850 | if (!that.negate) {
|
1851 | that.fail();
|
1852 | }
|
1853 | return value;
|
1854 | }, function next$onError(err) {
|
1855 | if (that.negate) {
|
1856 | that.fail();
|
1857 | }
|
1858 |
|
1859 | var errorMatched = true;
|
1860 | var errorInfo = '';
|
1861 |
|
1862 | if ('string' === typeof message) {
|
1863 | errorMatched = message === err.message;
|
1864 | } else if (message instanceof RegExp) {
|
1865 | errorMatched = message.test(err.message);
|
1866 | } else if ('function' === typeof message) {
|
1867 | errorMatched = err instanceof message;
|
1868 | } else if (message !== null && typeof message === 'object') {
|
1869 | try {
|
1870 | should(err).match(message);
|
1871 | } catch (e) {
|
1872 | if (e instanceof should.AssertionError) {
|
1873 | errorInfo = ': ' + e.message;
|
1874 | errorMatched = false;
|
1875 | } else {
|
1876 | throw e;
|
1877 | }
|
1878 | }
|
1879 | }
|
1880 |
|
1881 | if (!errorMatched) {
|
1882 | if ( typeof message === 'string' || message instanceof RegExp) {
|
1883 | errorInfo = ' with a message matching ' + should.format(message) + ", but got '" + err.message + "'";
|
1884 | } else if ('function' === typeof message) {
|
1885 | errorInfo = ' of type ' + util.functionName(message) + ', but got ' + util.functionName(err.constructor);
|
1886 | }
|
1887 | } else if ('function' === typeof message && properties) {
|
1888 | try {
|
1889 | should(err).match(properties);
|
1890 | } catch (e) {
|
1891 | if (e instanceof should.AssertionError) {
|
1892 | errorInfo = ': ' + e.message;
|
1893 | errorMatched = false;
|
1894 | } else {
|
1895 | throw e;
|
1896 | }
|
1897 | }
|
1898 | }
|
1899 |
|
1900 | that.params.operator += errorInfo;
|
1901 |
|
1902 | that.assert(errorMatched);
|
1903 |
|
1904 | return err;
|
1905 | });
|
1906 | };
|
1907 |
|
1908 | |
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 | Object.defineProperty(Assertion.prototype, 'finally', {
|
1930 | get: function() {
|
1931 | should(this.obj).be.a.Promise();
|
1932 |
|
1933 | var that = this;
|
1934 |
|
1935 | return new PromisedAssertion(this.obj.then(function(obj) {
|
1936 | var a = should(obj);
|
1937 |
|
1938 | a.negate = that.negate;
|
1939 | a.anyOne = that.anyOne;
|
1940 |
|
1941 | return a;
|
1942 | }));
|
1943 | }
|
1944 | });
|
1945 |
|
1946 | Assertion.alias('finally', 'eventually');
|
1947 | };
|
1948 |
|
1949 | },{"../assertion":4,"../util":20}],16:[function(require,module,exports){
|
1950 |
|
1951 |
|
1952 |
|
1953 |
|
1954 |
|
1955 |
|
1956 | var util = require('../util');
|
1957 | var eql = require('should-equal');
|
1958 |
|
1959 | var aSlice = Array.prototype.slice;
|
1960 |
|
1961 | module.exports = function(should, Assertion) {
|
1962 | var i = should.format;
|
1963 | |
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 |
|
1975 | Assertion.add('propertyWithDescriptor', function(name, desc) {
|
1976 | this.params = {actual: this.obj, operator: 'to have own property with descriptor ' + i(desc)};
|
1977 | var obj = this.obj;
|
1978 | this.have.ownProperty(name);
|
1979 | should(Object.getOwnPropertyDescriptor(Object(obj), name)).have.properties(desc);
|
1980 | });
|
1981 |
|
1982 | function processPropsArgs() {
|
1983 | var args = {};
|
1984 | if(arguments.length > 1) {
|
1985 | args.names = aSlice.call(arguments);
|
1986 | } else {
|
1987 | var arg = arguments[0];
|
1988 | if(typeof arg === 'string') {
|
1989 | args.names = [arg];
|
1990 | } else if(util.isIndexable(arg)) {
|
1991 | args.names = arg;
|
1992 | } else {
|
1993 | args.names = Object.keys(arg);
|
1994 | args.values = arg;
|
1995 | }
|
1996 | }
|
1997 | return args;
|
1998 | }
|
1999 |
|
2000 |
|
2001 | |
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | Assertion.add('enumerable', function(name, val) {
|
2014 | name = util.convertPropertyName(name);
|
2015 |
|
2016 | this.params = {
|
2017 | operator: "to have enumerable property " + util.formatProp(name) + (arguments.length > 1 ? " equal to " + i(val): "")
|
2018 | };
|
2019 |
|
2020 | var desc = { enumerable: true };
|
2021 | if(arguments.length > 1) desc.value = val;
|
2022 | this.have.propertyWithDescriptor(name, desc);
|
2023 | });
|
2024 |
|
2025 | |
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 |
|
2036 | Assertion.add('enumerables', function(names) {
|
2037 | var args = processPropsArgs.apply(null, arguments);
|
2038 |
|
2039 | this.params = {
|
2040 | operator: "to have enumerables " + args.names.map(util.formatProp)
|
2041 | };
|
2042 |
|
2043 | var obj = this.obj;
|
2044 | args.names.forEach(function(name) {
|
2045 | should(obj).have.enumerable(name);
|
2046 | });
|
2047 | });
|
2048 |
|
2049 | |
2050 |
|
2051 |
|
2052 |
|
2053 |
|
2054 |
|
2055 |
|
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 | Assertion.add('property', function(name, val) {
|
2062 | name = util.convertPropertyName(name);
|
2063 | if(arguments.length > 1) {
|
2064 | var p = {};
|
2065 | p[name] = val;
|
2066 | this.have.properties(p);
|
2067 | } else {
|
2068 | this.have.properties(name);
|
2069 | }
|
2070 | this.obj = this.obj[name];
|
2071 | });
|
2072 |
|
2073 | |
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 |
|
2080 |
|
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 |
|
2086 | Assertion.add('properties', function(names) {
|
2087 | var values = {};
|
2088 | if(arguments.length > 1) {
|
2089 | names = aSlice.call(arguments);
|
2090 | } else if(!Array.isArray(names)) {
|
2091 | if(typeof names == 'string' || typeof names == 'symbol') {
|
2092 | names = [names];
|
2093 | } else {
|
2094 | values = names;
|
2095 | names = Object.keys(names);
|
2096 | }
|
2097 | }
|
2098 |
|
2099 | var obj = Object(this.obj), missingProperties = [];
|
2100 |
|
2101 |
|
2102 | names.forEach(function(name) {
|
2103 | if(!(name in obj)) missingProperties.push(util.formatProp(name));
|
2104 | });
|
2105 |
|
2106 | var props = missingProperties;
|
2107 | if(props.length === 0) {
|
2108 | props = names.map(util.formatProp);
|
2109 | } else if(this.anyOne) {
|
2110 | props = names.filter(function(name) {
|
2111 | return missingProperties.indexOf(util.formatProp(name)) < 0;
|
2112 | }).map(util.formatProp);
|
2113 | }
|
2114 |
|
2115 | var operator = (props.length === 1 ?
|
2116 | 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', ');
|
2117 |
|
2118 | this.params = {obj: this.obj, operator: operator};
|
2119 |
|
2120 |
|
2121 |
|
2122 | this.assert(missingProperties.length === 0 || (this.anyOne && missingProperties.length != names.length));
|
2123 |
|
2124 |
|
2125 | var valueCheckNames = Object.keys(values);
|
2126 | if(valueCheckNames.length) {
|
2127 | var wrongValues = [];
|
2128 | props = [];
|
2129 |
|
2130 |
|
2131 | valueCheckNames.forEach(function(name) {
|
2132 | var value = values[name];
|
2133 | if(!eql(obj[name], value).result) {
|
2134 | wrongValues.push(util.formatProp(name) + ' of ' + i(value) + ' (got ' + i(obj[name]) + ')');
|
2135 | } else {
|
2136 | props.push(util.formatProp(name) + ' of ' + i(value));
|
2137 | }
|
2138 | });
|
2139 |
|
2140 | if((wrongValues.length !== 0 && !this.anyOne) || (this.anyOne && props.length === 0)) {
|
2141 | props = wrongValues;
|
2142 | }
|
2143 |
|
2144 | operator = (props.length === 1 ?
|
2145 | 'to have property ' : 'to have ' + (this.anyOne ? 'any of ' : '') + 'properties ') + props.join(', ');
|
2146 |
|
2147 | this.params = {obj: this.obj, operator: operator};
|
2148 |
|
2149 |
|
2150 |
|
2151 | this.assert(wrongValues.length === 0 || (this.anyOne && wrongValues.length != valueCheckNames.length));
|
2152 | }
|
2153 | });
|
2154 |
|
2155 | |
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 |
|
2167 |
|
2168 | Assertion.add('length', function(n, description) {
|
2169 | this.have.property('length', n, description);
|
2170 | });
|
2171 |
|
2172 | Assertion.alias('length', 'lengthOf');
|
2173 |
|
2174 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
2175 |
|
2176 | |
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 | Assertion.add('ownProperty', function(name, description) {
|
2190 | name = util.convertPropertyName(name);
|
2191 | this.params = {
|
2192 | actual: this.obj,
|
2193 | operator: 'to have own property ' + util.formatProp(name),
|
2194 | message: description
|
2195 | };
|
2196 |
|
2197 | this.assert(hasOwnProperty.call(this.obj, name));
|
2198 |
|
2199 | this.obj = this.obj[name];
|
2200 | });
|
2201 |
|
2202 | Assertion.alias('ownProperty', 'hasOwnProperty');
|
2203 |
|
2204 | |
2205 |
|
2206 |
|
2207 |
|
2208 |
|
2209 |
|
2210 |
|
2211 |
|
2212 |
|
2213 |
|
2214 |
|
2215 |
|
2216 | Assertion.add('empty', function() {
|
2217 | this.params = {operator: 'to be empty'};
|
2218 |
|
2219 | if(util.length(this.obj) !== void 0) {
|
2220 | should(this.obj).have.property('length', 0);
|
2221 | } else {
|
2222 | var obj = Object(this.obj);
|
2223 | for(var prop in obj) {
|
2224 | should(this.obj).not.have.ownProperty(prop);
|
2225 | }
|
2226 | }
|
2227 | }, true);
|
2228 |
|
2229 | |
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 |
|
2242 |
|
2243 |
|
2244 | Assertion.add('keys', function(keys) {
|
2245 | if(arguments.length > 1) keys = aSlice.call(arguments);
|
2246 | else if(arguments.length === 1 && typeof keys === 'string') keys = [keys];
|
2247 | else if(arguments.length === 0) keys = [];
|
2248 |
|
2249 | keys = keys.map(String);
|
2250 |
|
2251 | var obj = Object(this.obj);
|
2252 |
|
2253 |
|
2254 | var missingKeys = [];
|
2255 | keys.forEach(function(key) {
|
2256 | if(!hasOwnProperty.call(this.obj, key))
|
2257 | missingKeys.push(util.formatProp(key));
|
2258 | }, this);
|
2259 |
|
2260 |
|
2261 | var extraKeys = [];
|
2262 | Object.keys(obj).forEach(function(key) {
|
2263 | if(keys.indexOf(key) < 0) {
|
2264 | extraKeys.push(util.formatProp(key));
|
2265 | }
|
2266 | });
|
2267 |
|
2268 | var verb = keys.length === 0 ? 'to be empty' :
|
2269 | 'to have ' + (keys.length === 1 ? 'key ' : 'keys ');
|
2270 |
|
2271 | this.params = {operator: verb + keys.map(util.formatProp).join(', ')};
|
2272 |
|
2273 | if(missingKeys.length > 0)
|
2274 | this.params.operator += '\n\tmissing keys: ' + missingKeys.join(', ');
|
2275 |
|
2276 | if(extraKeys.length > 0)
|
2277 | this.params.operator += '\n\textra keys: ' + extraKeys.join(', ');
|
2278 |
|
2279 | this.assert(missingKeys.length === 0 && extraKeys.length === 0);
|
2280 | });
|
2281 |
|
2282 | Assertion.alias("keys", "key");
|
2283 |
|
2284 | |
2285 |
|
2286 |
|
2287 |
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 | Assertion.add('propertyByPath', function(properties) {
|
2296 | if(arguments.length > 1) properties = aSlice.call(arguments);
|
2297 | else if(arguments.length === 1 && typeof properties == 'string') properties = [properties];
|
2298 | else if(arguments.length === 0) properties = [];
|
2299 |
|
2300 | var allProps = properties.map(util.formatProp);
|
2301 |
|
2302 | properties = properties.map(String);
|
2303 |
|
2304 | var obj = should(Object(this.obj));
|
2305 |
|
2306 | var foundProperties = [];
|
2307 |
|
2308 | var currentProperty;
|
2309 | while(currentProperty = properties.shift()) {
|
2310 | this.params = {operator: 'to have property by path ' + allProps.join(', ') + ' - failed on ' + util.formatProp(currentProperty)};
|
2311 | obj = obj.have.property(currentProperty);
|
2312 | foundProperties.push(currentProperty);
|
2313 | }
|
2314 |
|
2315 | this.params = {obj: this.obj, operator: 'to have property by path ' + allProps.join(', ')};
|
2316 |
|
2317 | this.obj = obj.obj;
|
2318 | });
|
2319 | };
|
2320 |
|
2321 | },{"../util":20,"should-equal":22}],17:[function(require,module,exports){
|
2322 |
|
2323 |
|
2324 |
|
2325 |
|
2326 |
|
2327 |
|
2328 | module.exports = function(should, Assertion) {
|
2329 | |
2330 |
|
2331 |
|
2332 |
|
2333 |
|
2334 |
|
2335 |
|
2336 |
|
2337 |
|
2338 |
|
2339 |
|
2340 | Assertion.add('startWith', function(str, description) {
|
2341 | this.params = { operator: 'to start with ' + should.format(str), message: description };
|
2342 |
|
2343 | this.assert(0 === this.obj.indexOf(str));
|
2344 | });
|
2345 |
|
2346 | |
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 |
|
2356 |
|
2357 | Assertion.add('endWith', function(str, description) {
|
2358 | this.params = { operator: 'to end with ' + should.format(str), message: description };
|
2359 |
|
2360 | this.assert(this.obj.indexOf(str, this.obj.length - str.length) >= 0);
|
2361 | });
|
2362 | };
|
2363 |
|
2364 | },{}],18:[function(require,module,exports){
|
2365 |
|
2366 |
|
2367 |
|
2368 |
|
2369 |
|
2370 |
|
2371 | var util = require('../util');
|
2372 |
|
2373 | module.exports = function(should, Assertion) {
|
2374 | |
2375 |
|
2376 |
|
2377 |
|
2378 |
|
2379 |
|
2380 | Assertion.add('Number', function() {
|
2381 | this.params = {operator: 'to be a number'};
|
2382 |
|
2383 | this.have.type('number');
|
2384 | });
|
2385 |
|
2386 | |
2387 |
|
2388 |
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 | Assertion.add('arguments', function() {
|
2394 | this.params = {operator: 'to be arguments'};
|
2395 |
|
2396 | this.have.class('Arguments');
|
2397 | });
|
2398 |
|
2399 | Assertion.alias('arguments', 'Arguments');
|
2400 |
|
2401 | |
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 | Assertion.add('type', function(type, description) {
|
2410 | this.params = {operator: 'to have type ' + type, message: description};
|
2411 |
|
2412 | should(typeof this.obj).be.exactly(type);
|
2413 | });
|
2414 |
|
2415 | |
2416 |
|
2417 |
|
2418 |
|
2419 |
|
2420 |
|
2421 |
|
2422 |
|
2423 |
|
2424 | Assertion.add('instanceof', function(constructor, description) {
|
2425 | this.params = {operator: 'to be an instance of ' + util.functionName(constructor), message: description};
|
2426 |
|
2427 | this.assert(Object(this.obj) instanceof constructor);
|
2428 | });
|
2429 |
|
2430 | Assertion.alias('instanceof', 'instanceOf');
|
2431 |
|
2432 | /**
|
2433 | * Assert given object is function
|
2434 | * @name Function
|
2435 | * @memberOf Assertion
|
2436 | * @category assertion types
|
2437 | */
|
2438 | Assertion.add('Function', function() {
|
2439 | this.params = {operator: 'to be a function'};
|
2440 |
|
2441 | this.have.type('function');
|
2442 | });
|
2443 |
|
2444 | |
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 | Assertion.add('Object', function() {
|
2451 | this.params = {operator: 'to be an object'};
|
2452 |
|
2453 | this.is.not.null().and.have.type('object');
|
2454 | });
|
2455 |
|
2456 | |
2457 |
|
2458 |
|
2459 |
|
2460 |
|
2461 |
|
2462 | Assertion.add('String', function() {
|
2463 | this.params = {operator: 'to be a string'};
|
2464 |
|
2465 | this.have.type('string');
|
2466 | });
|
2467 |
|
2468 | |
2469 |
|
2470 |
|
2471 |
|
2472 |
|
2473 |
|
2474 | Assertion.add('Array', function() {
|
2475 | this.params = {operator: 'to be an array'};
|
2476 |
|
2477 | this.have.class('Array');
|
2478 | });
|
2479 |
|
2480 | |
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 | Assertion.add('Boolean', function() {
|
2487 | this.params = {operator: 'to be a boolean'};
|
2488 |
|
2489 | this.have.type('boolean');
|
2490 | });
|
2491 |
|
2492 | |
2493 |
|
2494 |
|
2495 |
|
2496 |
|
2497 |
|
2498 | Assertion.add('Error', function() {
|
2499 | this.params = {operator: 'to be an error'};
|
2500 |
|
2501 | this.have.instanceOf(Error);
|
2502 | });
|
2503 |
|
2504 | |
2505 |
|
2506 |
|
2507 |
|
2508 |
|
2509 |
|
2510 | Assertion.add('Date', function() {
|
2511 | this.params = {operator: 'to be a date'};
|
2512 |
|
2513 | this.have.instanceOf(Date);
|
2514 | });
|
2515 |
|
2516 | |
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 | Assertion.add('null', function() {
|
2524 | this.params = {operator: 'to be null'};
|
2525 |
|
2526 | this.assert(this.obj === null);
|
2527 | });
|
2528 |
|
2529 | Assertion.alias('null', 'Null');
|
2530 |
|
2531 | |
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 | Assertion.add('class', function(cls) {
|
2539 | this.params = {operator: 'to have [[Class]] ' + cls};
|
2540 |
|
2541 | this.assert(Object.prototype.toString.call(this.obj) === '[object ' + cls + ']');
|
2542 | });
|
2543 |
|
2544 | Assertion.alias('class', 'Class');
|
2545 |
|
2546 | |
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 |
|
2552 |
|
2553 | Assertion.add('undefined', function() {
|
2554 | this.params = {operator: 'to be undefined'};
|
2555 |
|
2556 | this.assert(this.obj === void 0);
|
2557 | });
|
2558 |
|
2559 | Assertion.alias('undefined', 'Undefined');
|
2560 |
|
2561 | |
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 | Assertion.add('iterable', function() {
|
2569 | this.params = {operator: 'to be iterable'};
|
2570 |
|
2571 | should(this.obj).have.property(Symbol.iterator).which.is.a.Function();
|
2572 | });
|
2573 |
|
2574 | |
2575 |
|
2576 |
|
2577 |
|
2578 |
|
2579 |
|
2580 |
|
2581 | Assertion.add('iterator', function() {
|
2582 | this.params = {operator: 'to be iterator'};
|
2583 |
|
2584 | should(this.obj).have.property('next').which.is.a.Function();
|
2585 | });
|
2586 |
|
2587 | |
2588 |
|
2589 |
|
2590 |
|
2591 |
|
2592 |
|
2593 | Assertion.add('generator', function() {
|
2594 | this.params = {operator: 'to be generator'};
|
2595 |
|
2596 | should(this.obj).be.iterable
|
2597 | .and.iterator
|
2598 | .and.it.is.equal(this.obj[Symbol.iterator]());
|
2599 | });
|
2600 | };
|
2601 |
|
2602 | },{"../util":20}],19:[function(require,module,exports){
|
2603 |
|
2604 |
|
2605 |
|
2606 |
|
2607 |
|
2608 |
|
2609 |
|
2610 | var util = require('./util');
|
2611 |
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 |
|
2620 |
|
2621 |
|
2622 | function should(obj) {
|
2623 | return (new should.Assertion(obj));
|
2624 | }
|
2625 |
|
2626 | should.AssertionError = require('./assertion-error');
|
2627 | should.Assertion = require('./assertion');
|
2628 |
|
2629 | should.format = util.format;
|
2630 | should.type = require('should-type');
|
2631 | should.util = util;
|
2632 |
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 |
|
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 |
|
2644 |
|
2645 |
|
2646 |
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 | should.config = require('./config');
|
2656 |
|
2657 |
|
2658 | exports = module.exports = should;
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 |
|
2673 |
|
2674 |
|
2675 |
|
2676 |
|
2677 |
|
2678 |
|
2679 |
|
2680 | should.extend = function(propertyName, proto) {
|
2681 | propertyName = propertyName || 'should';
|
2682 | proto = proto || Object.prototype;
|
2683 |
|
2684 | var prevDescriptor = Object.getOwnPropertyDescriptor(proto, propertyName);
|
2685 |
|
2686 | Object.defineProperty(proto, propertyName, {
|
2687 | set: function() {
|
2688 | },
|
2689 | get: function() {
|
2690 | return should(util.isWrapperType(this) ? this.valueOf() : this);
|
2691 | },
|
2692 | configurable: true
|
2693 | });
|
2694 |
|
2695 | return { name: propertyName, descriptor: prevDescriptor, proto: proto };
|
2696 | };
|
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 |
|
2704 |
|
2705 |
|
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 |
|
2715 |
|
2716 |
|
2717 | should.noConflict = function(desc) {
|
2718 | desc = desc || should._prevShould;
|
2719 |
|
2720 | if(desc) {
|
2721 | delete desc.proto[desc.name];
|
2722 |
|
2723 | if(desc.descriptor) {
|
2724 | Object.defineProperty(desc.proto, desc.name, desc.descriptor);
|
2725 | }
|
2726 | }
|
2727 | return should;
|
2728 | };
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 |
|
2737 |
|
2738 |
|
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 |
|
2745 |
|
2746 |
|
2747 | should.use = function(f) {
|
2748 | f(should, should.Assertion);
|
2749 | return this;
|
2750 | };
|
2751 |
|
2752 | should
|
2753 | .use(require('./ext/assert'))
|
2754 | .use(require('./ext/chain'))
|
2755 | .use(require('./ext/bool'))
|
2756 | .use(require('./ext/number'))
|
2757 | .use(require('./ext/eql'))
|
2758 | .use(require('./ext/type'))
|
2759 | .use(require('./ext/string'))
|
2760 | .use(require('./ext/property'))
|
2761 | .use(require('./ext/error'))
|
2762 | .use(require('./ext/match'))
|
2763 | .use(require('./ext/contain'))
|
2764 | .use(require('./ext/promise'));
|
2765 |
|
2766 | },{"./assertion":4,"./assertion-error":3,"./config":5,"./ext/assert":7,"./ext/bool":8,"./ext/chain":9,"./ext/contain":10,"./ext/eql":11,"./ext/error":12,"./ext/match":13,"./ext/number":14,"./ext/promise":15,"./ext/property":16,"./ext/string":17,"./ext/type":18,"./util":20,"should-type":27}],20:[function(require,module,exports){
|
2767 |
|
2768 |
|
2769 |
|
2770 |
|
2771 |
|
2772 |
|
2773 | var type = require('should-type');
|
2774 | var config = require('./config');
|
2775 |
|
2776 |
|
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 |
|
2782 | exports.isWrapperType = function(obj) {
|
2783 | return obj instanceof Number || obj instanceof String || obj instanceof Boolean;
|
2784 | };
|
2785 |
|
2786 | exports.merge = function(a, b) {
|
2787 | if(a && b) {
|
2788 | for(var key in b) {
|
2789 | a[key] = b[key];
|
2790 | }
|
2791 | }
|
2792 | return a;
|
2793 | };
|
2794 |
|
2795 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
2796 |
|
2797 | exports.forEach = function forEach(obj, f, context) {
|
2798 | if(exports.isGeneratorFunction(obj)) {
|
2799 | return forEach(obj(), f, context);
|
2800 | } else if (exports.isGeneratorObject(obj)) {
|
2801 | var value = obj.next();
|
2802 | while(!value.done) {
|
2803 | if(f.call(context, value.value, 'value', obj) === false)
|
2804 | return;
|
2805 | value = obj.next();
|
2806 | }
|
2807 | } else {
|
2808 | for(var prop in obj) {
|
2809 | if(hasOwnProperty.call(obj, prop)) {
|
2810 | if(f.call(context, obj[prop], prop, obj) === false)
|
2811 | return;
|
2812 | }
|
2813 | }
|
2814 | }
|
2815 | };
|
2816 |
|
2817 | exports.some = function(obj, f, context) {
|
2818 | var res = false;
|
2819 | exports.forEach(obj, function(value, key) {
|
2820 | if(f.call(context, value, key, obj)) {
|
2821 | res = true;
|
2822 | return false;
|
2823 | }
|
2824 | }, context);
|
2825 | return res;
|
2826 | };
|
2827 |
|
2828 | exports.isEmptyObject = function(obj) {
|
2829 | for(var prop in obj) {
|
2830 | if(hasOwnProperty.call(obj, prop)) {
|
2831 | return false;
|
2832 | }
|
2833 | }
|
2834 | return true;
|
2835 | };
|
2836 |
|
2837 | exports.isIndexable = function(obj) {
|
2838 | var t = type(obj);
|
2839 | return (t.type === type.OBJECT && t.cls === type.ARRAY) ||
|
2840 | (t.type === type.OBJECT && t.cls === type.BUFFER) ||
|
2841 | (t.type === type.OBJECT && t.cls === type.ARGUMENTS) ||
|
2842 | (t.type === type.OBJECT && t.cls === type.ARRAY_BUFFER) ||
|
2843 | (t.type === type.OBJECT && t.cls === type.TYPED_ARRAY) ||
|
2844 | (t.type === type.OBJECT && t.cls === type.DATA_VIEW) ||
|
2845 | (t.type === type.OBJECT && t.cls === type.STRING) ||
|
2846 | (t.type === type.STRING);
|
2847 | };
|
2848 |
|
2849 | exports.length = function(obj) {
|
2850 | var t = type(obj);
|
2851 | switch(t.type) {
|
2852 | case type.STRING:
|
2853 | return obj.length;
|
2854 | case type.OBJECT:
|
2855 | switch(t.cls) {
|
2856 | case type.ARRAY_BUFFER:
|
2857 | case type.TYPED_ARRAY:
|
2858 | case type.DATA_VIEW:
|
2859 | return obj.byteLength;
|
2860 |
|
2861 | case type.ARRAY:
|
2862 | case type.BUFFER:
|
2863 | case type.ARGUMENTS:
|
2864 | case type.FUNCTION:
|
2865 | return obj.length;
|
2866 | }
|
2867 | }
|
2868 | };
|
2869 |
|
2870 | exports.convertPropertyName = function(name) {
|
2871 | if(typeof name == 'symbol') {
|
2872 | return name;
|
2873 | } else {
|
2874 | return String(name);
|
2875 | }
|
2876 | };
|
2877 |
|
2878 | exports.isGeneratorObject = function(obj) {
|
2879 | if(!obj) return false;
|
2880 |
|
2881 | return typeof obj.next == 'function' &&
|
2882 | typeof obj[Symbol.iterator] == 'function' &&
|
2883 | obj[Symbol.iterator]() === obj;
|
2884 | };
|
2885 |
|
2886 |
|
2887 | exports.isGeneratorFunction = function(f) {
|
2888 | if(typeof f != 'function') return false;
|
2889 |
|
2890 | return /^function\s*\*\s*/.test(f.toString());
|
2891 | };
|
2892 |
|
2893 | exports.format = function(value, opts) {
|
2894 | return config.getFormatter(opts).format(value);
|
2895 | };
|
2896 |
|
2897 | exports.functionName = require('should-format').Formatter.functionName;
|
2898 |
|
2899 | exports.formatProp = function(value) {
|
2900 | return config.getFormatter().formatPropertyName(String(value));
|
2901 | };
|
2902 |
|
2903 | },{"./config":5,"should-format":23,"should-type":27}],21:[function(require,module,exports){
|
2904 | module.exports = function format(msg) {
|
2905 | var args = arguments;
|
2906 | for(var i = 1, l = args.length; i < l; i++) {
|
2907 | msg = msg.replace(/%s/, args[i]);
|
2908 | }
|
2909 | return msg;
|
2910 | }
|
2911 |
|
2912 | },{}],22:[function(require,module,exports){
|
2913 | var getType = require('should-type');
|
2914 | var format = require('./format');
|
2915 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
2916 |
|
2917 | function makeResult(r, path, reason, a, b) {
|
2918 | var o = {result: r};
|
2919 | if(!r) {
|
2920 | o.path = path;
|
2921 | o.reason = reason;
|
2922 | o.a = a;
|
2923 | o.b = b;
|
2924 | }
|
2925 | return o;
|
2926 | }
|
2927 |
|
2928 | var EQUALS = makeResult(true);
|
2929 |
|
2930 | function typeToString(t) {
|
2931 | return t.type + (t.cls ? '(' + t.cls + (t.sub ? ' ' + t.sub : '') + ')' : '');
|
2932 | }
|
2933 |
|
2934 |
|
2935 |
|
2936 | var REASON = {
|
2937 | PLUS_0_AND_MINUS_0: '+0 is not equal to -0',
|
2938 | DIFFERENT_TYPES: 'A has type %s and B has type %s',
|
2939 | NAN_NUMBER: 'NaN is not equal to any number',
|
2940 | EQUALITY: 'A is not equal to B',
|
2941 | EQUALITY_PROTOTYPE: 'A and B have different prototypes',
|
2942 | WRAPPED_VALUE: 'A wrapped value is not equal to B wrapped value',
|
2943 | FUNCTION_SOURCES: 'function A is not equal to B by source code value (via .toString call)',
|
2944 | MISSING_KEY: '%s has no key %s',
|
2945 | CIRCULAR_VALUES: 'A has circular reference that was visited not in the same time as B',
|
2946 | SET_MAP_MISSING_KEY: 'Set/Map missing key',
|
2947 | MAP_VALUE_EQUALITY: 'Values of the same key in A and B is not equal'
|
2948 | };
|
2949 |
|
2950 |
|
2951 | function eqInternal(a, b, opts, stackA, stackB, path, fails) {
|
2952 | var r = EQUALS;
|
2953 |
|
2954 | function result(comparison, reason) {
|
2955 | if(arguments.length > 2) {
|
2956 | var args = Array.prototype.slice.call(arguments, 2);
|
2957 | reason = format.apply(null, [reason].concat(args));
|
2958 | }
|
2959 | var res = makeResult(comparison, path, reason, a, b);
|
2960 | if(!comparison && opts.collectAllFails) {
|
2961 | fails.push(res);
|
2962 | }
|
2963 | return res;
|
2964 | }
|
2965 |
|
2966 | function checkPropertyEquality(property) {
|
2967 | return eqInternal(a[property], b[property], opts, stackA, stackB, path.concat([property]), fails);
|
2968 | }
|
2969 |
|
2970 | function checkAlso(a1, b1) {
|
2971 | return eqInternal(a1, b1, opts, stackA, stackB, path, fails);
|
2972 | }
|
2973 |
|
2974 |
|
2975 | if(a === b) {
|
2976 |
|
2977 | return result(a !== 0 || (1 / a == 1 / b) || opts.plusZeroAndMinusZeroEqual, REASON.PLUS_0_AND_MINUS_0);
|
2978 | }
|
2979 |
|
2980 | var l, p;
|
2981 |
|
2982 | var typeA = getType(a),
|
2983 | typeB = getType(b);
|
2984 |
|
2985 | var key;
|
2986 |
|
2987 |
|
2988 | var typeDifferent = typeA.type !== typeB.type || typeA.cls !== typeB.cls;
|
2989 |
|
2990 | if(typeDifferent || ((opts.checkSubType && typeA.sub !== typeB.sub) || !opts.checkSubType)) {
|
2991 | return result(false, REASON.DIFFERENT_TYPES, typeToString(typeA), typeToString(typeB));
|
2992 | }
|
2993 |
|
2994 |
|
2995 | switch(typeA.type) {
|
2996 | case 'number':
|
2997 |
|
2998 | return (a !== a) ? result(b !== b, REASON.NAN_NUMBER)
|
2999 | : result(a === b, REASON.EQUALITY);
|
3000 |
|
3001 | case 'boolean':
|
3002 | case 'string':
|
3003 | return result(a === b, REASON.EQUALITY);
|
3004 |
|
3005 | case 'function':
|
3006 |
|
3007 | r = checkAlso(a.toString(), b.toString());
|
3008 | if(!r.result) {
|
3009 | r.reason = REASON.FUNCTION_SOURCES;
|
3010 | if(!opts.collectAllFails) return r;
|
3011 | }
|
3012 |
|
3013 | break;
|
3014 |
|
3015 | case 'object':
|
3016 |
|
3017 | switch(typeA.cls) {
|
3018 |
|
3019 |
|
3020 | case 'regexp':
|
3021 | p = ['source', 'global', 'multiline', 'lastIndex', 'ignoreCase'];
|
3022 | while(p.length) {
|
3023 | r = checkPropertyEquality(p.shift());
|
3024 | if(!r.result && !opts.collectAllFails) return r;
|
3025 | }
|
3026 | break;
|
3027 |
|
3028 |
|
3029 | case 'date':
|
3030 | if(+a !== +b) {
|
3031 | r = result(false, REASON.EQUALITY);
|
3032 | if(!r.result && !opts.collectAllFails) return r;
|
3033 | }
|
3034 | break;
|
3035 |
|
3036 |
|
3037 | case 'number':
|
3038 | case 'boolean':
|
3039 | case 'string':
|
3040 |
|
3041 | r = checkAlso(a.valueOf(), b.valueOf());
|
3042 | if(!r.result) {
|
3043 | r.reason = REASON.WRAPPED_VALUE;
|
3044 | if(!opts.collectAllFails) return r;
|
3045 | }
|
3046 | break;
|
3047 |
|
3048 |
|
3049 | case 'buffer':
|
3050 |
|
3051 | r = checkPropertyEquality('length');
|
3052 | if(!r.result && !opts.collectAllFails) return r;
|
3053 |
|
3054 | l = a.length;
|
3055 | while(l--) {
|
3056 | r = checkPropertyEquality(l);
|
3057 | if(!r.result && !opts.collectAllFails) return r;
|
3058 | }
|
3059 |
|
3060 |
|
3061 |
|
3062 | return EQUALS;
|
3063 |
|
3064 | case 'error':
|
3065 |
|
3066 | p = ['name', 'message'];
|
3067 | while(p.length) {
|
3068 | r = checkPropertyEquality(p.shift());
|
3069 | if(!r.result && !opts.collectAllFails) return r;
|
3070 | }
|
3071 |
|
3072 | break;
|
3073 |
|
3074 | case 'array':
|
3075 | case 'arguments':
|
3076 | case 'typed-array':
|
3077 | r = checkPropertyEquality('length');
|
3078 | if(!r.result && !opts.collectAllFails) return r;
|
3079 |
|
3080 | break;
|
3081 |
|
3082 | case 'array-buffer':
|
3083 | r = checkPropertyEquality('byteLength');
|
3084 | if(!r.result && !opts.collectAllFails) return r;
|
3085 |
|
3086 | break;
|
3087 |
|
3088 | case 'map':
|
3089 | case 'set':
|
3090 | r = checkPropertyEquality('size');
|
3091 | if(!r.result && !opts.collectAllFails) return r;
|
3092 |
|
3093 | stackA.push(a);
|
3094 | stackB.push(b);
|
3095 |
|
3096 | var itA = a.entries();
|
3097 | var nextA = itA.next();
|
3098 |
|
3099 | while(!nextA.done) {
|
3100 | key = nextA.value[0];
|
3101 |
|
3102 |
|
3103 | if(getType(key).type != 'object') {
|
3104 | if(b.has(key)) {
|
3105 | if(typeA.cls == 'map') {
|
3106 |
|
3107 | var value = b.get(key);
|
3108 | r = checkAlso(nextA.value[1], value);
|
3109 | if(!r.result) {
|
3110 | r.a = nextA.value;
|
3111 | r.b = value;
|
3112 | r.reason = REASON.MAP_VALUE_EQUALITY;
|
3113 |
|
3114 | if(!opts.collectAllFails) break;
|
3115 | }
|
3116 | }
|
3117 |
|
3118 | } else {
|
3119 | r = result(false, REASON.SET_MAP_MISSING_KEY);
|
3120 | r.a = key;
|
3121 | r.b = key;
|
3122 |
|
3123 | if(!opts.collectAllFails) break;
|
3124 | }
|
3125 | } else {
|
3126 |
|
3127 |
|
3128 | var itB = b.entries();
|
3129 | var nextB = itB.next();
|
3130 |
|
3131 | while(!nextB.done) {
|
3132 |
|
3133 | r = checkAlso(nextA.value[0], nextB.value[0]);
|
3134 |
|
3135 | if(!r.result) {
|
3136 | r.reason = REASON.SET_MAP_MISSING_KEY;
|
3137 | r.a = key;
|
3138 | r.b = key;
|
3139 | } else {
|
3140 | if(typeA.cls == 'map') {
|
3141 | r = checkAlso(nextA.value[1], nextB.value[1]);
|
3142 |
|
3143 | if(!r.result) {
|
3144 | r.a = nextA.value;
|
3145 | r.b = nextB.value;
|
3146 | r.reason = REASON.MAP_VALUE_EQUALITY;
|
3147 | }
|
3148 | }
|
3149 |
|
3150 | if(!opts.collectAllFails) break;
|
3151 | }
|
3152 |
|
3153 | nextB = itB.next();
|
3154 | }
|
3155 | }
|
3156 |
|
3157 | if(!r.result && !opts.collectAllFails) break;
|
3158 |
|
3159 | nextA = itA.next();
|
3160 | }
|
3161 |
|
3162 | stackA.pop();
|
3163 | stackB.pop();
|
3164 |
|
3165 | if(!r.result) {
|
3166 | r.reason = REASON.SET_MAP_MISSING_ENTRY;
|
3167 | if(!opts.collectAllFails) return r;
|
3168 | }
|
3169 |
|
3170 | break;
|
3171 | }
|
3172 | }
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 | l = stackA.length;
|
3179 | while(l--) {
|
3180 | if(stackA[l] == a) {
|
3181 | return result(stackB[l] == b, REASON.CIRCULAR_VALUES);
|
3182 | }
|
3183 | }
|
3184 |
|
3185 |
|
3186 | stackA.push(a);
|
3187 | stackB.push(b);
|
3188 |
|
3189 | for(key in b) {
|
3190 | if(hasOwnProperty.call(b, key)) {
|
3191 | r = result(hasOwnProperty.call(a, key), REASON.MISSING_KEY, 'A', key);
|
3192 | if(!r.result && !opts.collectAllFails) break;
|
3193 |
|
3194 | if(r.result) {
|
3195 | r = checkPropertyEquality(key);
|
3196 | if(!r.result && !opts.collectAllFails) break;
|
3197 | }
|
3198 | }
|
3199 | }
|
3200 |
|
3201 | if(r.result || opts.collectAllFails) {
|
3202 |
|
3203 | for(key in a) {
|
3204 | if(hasOwnProperty.call(a, key)) {
|
3205 | r = result(hasOwnProperty.call(b, key), REASON.MISSING_KEY, 'B', key);
|
3206 | if(!r.result && !opts.collectAllFails) return r;
|
3207 | }
|
3208 | }
|
3209 | }
|
3210 |
|
3211 | stackA.pop();
|
3212 | stackB.pop();
|
3213 |
|
3214 | if(!r.result && !opts.collectAllFails) return r;
|
3215 |
|
3216 | var prototypesEquals = false, canComparePrototypes = false;
|
3217 |
|
3218 | if(opts.checkProtoEql) {
|
3219 | if(Object.getPrototypeOf) {
|
3220 | prototypesEquals = Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
|
3221 | canComparePrototypes = true;
|
3222 | }
|
3223 |
|
3224 | if(canComparePrototypes && !prototypesEquals) {
|
3225 | r = result(prototypesEquals, REASON.EQUALITY_PROTOTYPE);
|
3226 | r.showReason = true;
|
3227 | if(!r.result && !opts.collectAllFails) {
|
3228 | return r;
|
3229 | }
|
3230 | }
|
3231 | }
|
3232 |
|
3233 | return EQUALS;
|
3234 | }
|
3235 |
|
3236 | var defaultOptions = {
|
3237 | checkProtoEql: true,
|
3238 | checkSubType: true,
|
3239 | plusZeroAndMinusZeroEqual: false
|
3240 | };
|
3241 |
|
3242 | function eq(a, b, opts) {
|
3243 | opts = opts || {};
|
3244 | if(typeof opts.checkProtoEql !== 'boolean') {
|
3245 | opts.checkProtoEql = defaultOptions.checkProtoEql;
|
3246 | }
|
3247 | if(typeof opts.checkSubType !== 'boolean') {
|
3248 | opts.checkSubType = defaultOptions.checkSubType;
|
3249 | }
|
3250 | if(typeof opts.plusZeroAndMinusZeroEqual !== 'boolean') {
|
3251 | opts.plusZeroAndMinusZeroEqual = defaultOptions.plusZeroAndMinusZeroEqual;
|
3252 | }
|
3253 |
|
3254 | var fails = [];
|
3255 | var r = eqInternal(a, b, opts, [], [], [], fails);
|
3256 | return opts.collectAllFails ? fails : r;
|
3257 | }
|
3258 |
|
3259 | module.exports = eq;
|
3260 |
|
3261 | eq.r = REASON;
|
3262 |
|
3263 | },{"./format":21,"should-type":27}],23:[function(require,module,exports){
|
3264 | var getType = require('should-type');
|
3265 | var util = require('./util');
|
3266 |
|
3267 | function genKeysFunc(f) {
|
3268 | return function(value) {
|
3269 | var k = f(value);
|
3270 | k.sort();
|
3271 | return k;
|
3272 | };
|
3273 | }
|
3274 |
|
3275 |
|
3276 | function Formatter(opts) {
|
3277 | opts = opts || {};
|
3278 |
|
3279 | this.seen = [];
|
3280 | this.keys = genKeysFunc(opts.keys === false ? Object.getOwnPropertyNames : Object.keys);
|
3281 |
|
3282 | this.maxLineLength = typeof opts.maxLineLength === 'number' ? opts.maxLineLength : 60;
|
3283 | this.propSep = opts.propSep || ',';
|
3284 |
|
3285 | this.isUTCdate = !!opts.isUTCdate;
|
3286 | }
|
3287 |
|
3288 | Formatter.prototype = {
|
3289 | constructor: Formatter,
|
3290 |
|
3291 | format: function(value) {
|
3292 | var t = getType(value);
|
3293 | var name1 = t.type, name2 = t.type;
|
3294 | if(t.cls) {
|
3295 | name1 += '_' + t.cls;
|
3296 | name2 += '_' + t.cls;
|
3297 | }
|
3298 | if(t.sub) {
|
3299 | name2 += '_' + t.sub;
|
3300 | }
|
3301 | var f = this['_format_' + name2] || this['_format_' + name1] || this['_format_' + t.type] || this.defaultFormat;
|
3302 | return f.call(this, value).trim();
|
3303 | },
|
3304 |
|
3305 | _formatObject: function(value, opts) {
|
3306 | opts = opts || {};
|
3307 | var mainKeys = opts.keys || this.keys(value);
|
3308 |
|
3309 | var len = 0;
|
3310 |
|
3311 | var formatPropertyValue = opts.formatPropertyValue || this.formatPropertyValue;
|
3312 | var formatPropertyName = opts.formatPropertyName || this.formatPropertyName;
|
3313 | var keyValueSep = opts.keyValueSep || ': ';
|
3314 | var keyFilter = opts.keyFilter || function() { return true; };
|
3315 |
|
3316 | this.seen.push(value);
|
3317 | var keys = [];
|
3318 |
|
3319 | mainKeys.forEach(function(key) {
|
3320 | if(!keyFilter(key)) return;
|
3321 |
|
3322 | var fName = formatPropertyName.call(this, key);
|
3323 |
|
3324 | var f = (fName ? fName + keyValueSep : '') + formatPropertyValue.call(this, value, key);
|
3325 | len += f.length;
|
3326 | keys.push(f);
|
3327 | }, this);
|
3328 | this.seen.pop();
|
3329 |
|
3330 | (opts.additionalProperties || []).forEach(function(keyValue) {
|
3331 | var f = keyValue[0] + keyValueSep + this.format(keyValue[1]);
|
3332 | len += f.length;
|
3333 | keys.push(f);
|
3334 | }, this);
|
3335 |
|
3336 | var prefix = opts.prefix || Formatter.constructorName(value) || '';
|
3337 | if(prefix.length > 0) prefix += ' ';
|
3338 |
|
3339 | var lbracket, rbracket;
|
3340 | if(Array.isArray(opts.brackets)) {
|
3341 | lbracket = opts.brackets && opts.brackets[0];
|
3342 | rbracket = opts.brackets && opts.brackets[1];
|
3343 | } else {
|
3344 | lbracket = '{';
|
3345 | rbracket = '}';
|
3346 | }
|
3347 |
|
3348 | var rootValue = opts.value || '';
|
3349 |
|
3350 | if(keys.length === 0)
|
3351 | return rootValue || (prefix + lbracket + rbracket);
|
3352 |
|
3353 | if(len <= this.maxLineLength) {
|
3354 | return prefix + lbracket + ' ' + (rootValue ? rootValue + ' ' : '') + keys.join(this.propSep + ' ') + ' ' + rbracket;
|
3355 | } else {
|
3356 | return prefix + lbracket + '\n' + (rootValue ? ' ' + rootValue + '\n' : '') + keys.map(util.addSpaces).join(this.propSep + '\n') + '\n' + rbracket;
|
3357 | }
|
3358 | },
|
3359 |
|
3360 | formatObject: function(value, prefix, props) {
|
3361 | props = props || this.keys(value);
|
3362 |
|
3363 | var len = 0;
|
3364 |
|
3365 | this.seen.push(value);
|
3366 | props = props.map(function(prop) {
|
3367 | var f = this.formatProperty(value, prop);
|
3368 | len += f.length;
|
3369 | return f;
|
3370 | }, this);
|
3371 | this.seen.pop();
|
3372 |
|
3373 | if(props.length === 0) return '{}';
|
3374 |
|
3375 | if(len <= this.maxLineLength) {
|
3376 | return '{ ' + (prefix ? prefix + ' ' : '') + props.join(this.propSep + ' ') + ' }';
|
3377 | } else {
|
3378 | return '{' + '\n' + (prefix ? ' ' + prefix + '\n' : '') + props.map(util.addSpaces).join(this.propSep + '\n') + '\n' + '}';
|
3379 | }
|
3380 | },
|
3381 |
|
3382 | formatPropertyName: function(name) {
|
3383 | return name.match(/^[a-zA-Z_$][a-zA-Z_$0-9]*$/) ? name : this.format(name);
|
3384 | },
|
3385 |
|
3386 | formatProperty: function(value, prop) {
|
3387 | var desc = Formatter.getPropertyDescriptor(value, prop);
|
3388 |
|
3389 | var propName = this.formatPropertyName(prop);
|
3390 |
|
3391 | var propValue = desc.get && desc.set ?
|
3392 | '[Getter/Setter]' : desc.get ?
|
3393 | '[Getter]' : desc.set ?
|
3394 | '[Setter]' : this.seen.indexOf(desc.value) >= 0 ?
|
3395 | '[Circular]' :
|
3396 | this.format(desc.value);
|
3397 |
|
3398 | return propName + ': ' + propValue;
|
3399 | },
|
3400 |
|
3401 | formatPropertyValue: function(value, prop) {
|
3402 | var desc = Formatter.getPropertyDescriptor(value, prop);
|
3403 |
|
3404 | var propValue = desc.get && desc.set ?
|
3405 | '[Getter/Setter]' : desc.get ?
|
3406 | '[Getter]' : desc.set ?
|
3407 | '[Setter]' : this.seen.indexOf(desc.value) >= 0 ?
|
3408 | '[Circular]' :
|
3409 | this.format(desc.value);
|
3410 |
|
3411 | return propValue;
|
3412 | }
|
3413 | };
|
3414 |
|
3415 | Formatter.add = function add(type, cls, sub, f) {
|
3416 | var args = Array.prototype.slice.call(arguments);
|
3417 | f = args.pop();
|
3418 | Formatter.prototype['_format_' + args.join('_')] = f;
|
3419 | };
|
3420 |
|
3421 | Formatter.formatObjectWithPrefix = function formatObjectWithPrefix(f) {
|
3422 | return function(value) {
|
3423 | var prefix = f.call(this, value);
|
3424 | var props = this.keys(value);
|
3425 | if(props.length == 0) return prefix;
|
3426 | else return this.formatObject(value, prefix, props);
|
3427 | };
|
3428 | };
|
3429 |
|
3430 | var functionNameRE = /^\s*function\s*(\S*)\s*\(/;
|
3431 |
|
3432 | Formatter.functionName = function functionName(f) {
|
3433 | if(f.name) {
|
3434 | return f.name;
|
3435 | }
|
3436 | var matches = f.toString().match(functionNameRE);
|
3437 | if (matches === null) {
|
3438 |
|
3439 | return '';
|
3440 | }
|
3441 | var name = matches[1];
|
3442 | return name;
|
3443 | };
|
3444 |
|
3445 | Formatter.constructorName = function(obj) {
|
3446 | while (obj) {
|
3447 | var descriptor = Object.getOwnPropertyDescriptor(obj, 'constructor');
|
3448 | if (descriptor !== undefined &&
|
3449 | typeof descriptor.value === 'function') {
|
3450 |
|
3451 | var name = Formatter.functionName(descriptor.value);
|
3452 | if(name !== '') {
|
3453 | return name;
|
3454 | }
|
3455 | }
|
3456 |
|
3457 | obj = Object.getPrototypeOf(obj);
|
3458 | }
|
3459 | };
|
3460 |
|
3461 | Formatter.getPropertyDescriptor = function(obj, value) {
|
3462 | var desc;
|
3463 | try {
|
3464 | desc = Object.getOwnPropertyDescriptor(obj, value) || {value: obj[value]};
|
3465 | } catch(e) {
|
3466 | desc = {value: e};
|
3467 | }
|
3468 | return desc;
|
3469 | };
|
3470 |
|
3471 | Formatter.generateFunctionForIndexedArray = function generateFunctionForIndexedArray(lengthProp, name, padding) {
|
3472 | return function(value) {
|
3473 | var max = this.byteArrayMaxLength || 50;
|
3474 | var length = value[lengthProp];
|
3475 | var formattedValues = [];
|
3476 | var len = 0;
|
3477 | for(var i = 0; i < max && i < length; i++) {
|
3478 | var b = value[i] || 0;
|
3479 | var v = util.pad0(b.toString(16), padding);
|
3480 | len += v.length;
|
3481 | formattedValues.push(v);
|
3482 | }
|
3483 | var prefix = value.constructor.name || name || '';
|
3484 | if(prefix) prefix += ' ';
|
3485 |
|
3486 | if(formattedValues.length === 0)
|
3487 | return prefix + '[]';
|
3488 |
|
3489 | if(len <= this.maxLineLength) {
|
3490 | return prefix + '[ ' + formattedValues.join(this.propSep + ' ') + ' ' + ']';
|
3491 | } else {
|
3492 | return prefix + '[\n' + formattedValues.map(util.addSpaces).join(this.propSep + '\n') + '\n' + ']';
|
3493 | }
|
3494 | };
|
3495 | };
|
3496 |
|
3497 | Formatter.add('undefined', function() { return 'undefined' });
|
3498 | Formatter.add('null', function() { return 'null' });
|
3499 | Formatter.add('boolean', function(value) { return value ? 'true': 'false' });
|
3500 | Formatter.add('symbol', function(value) { return value.toString() });
|
3501 |
|
3502 | ['number', 'boolean'].forEach(function(name) {
|
3503 | Formatter.add('object', name, function(value) {
|
3504 | return this._formatObject(value, {
|
3505 | additionalProperties: [['[[PrimitiveValue]]', value.valueOf()]]
|
3506 | });
|
3507 | });
|
3508 | });
|
3509 |
|
3510 | Formatter.add('object', 'string', function(value) {
|
3511 | var realValue = value.valueOf();
|
3512 |
|
3513 | return this._formatObject(value, {
|
3514 | keyFilter: function(key) {
|
3515 |
|
3516 | return !(key.match(/\d+/) && parseInt(key, 10) < realValue.length);
|
3517 | },
|
3518 | additionalProperties: [['[[PrimitiveValue]]', realValue]]
|
3519 | });
|
3520 | });
|
3521 |
|
3522 | Formatter.add('object', 'regexp', function(value) {
|
3523 | return this._formatObject(value, {
|
3524 | value: String(value)
|
3525 | });
|
3526 | });
|
3527 |
|
3528 | Formatter.add('number', function(value) {
|
3529 | if(value === 0 && 1 / value < 0) return '-0';
|
3530 | return String(value);
|
3531 | });
|
3532 |
|
3533 | Formatter.add('string', function(value) {
|
3534 | return '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
|
3535 | .replace(/'/g, "\\'")
|
3536 | .replace(/\\"/g, '"') + '\'';
|
3537 | });
|
3538 |
|
3539 | Formatter.add('object', function(value) {
|
3540 | return this._formatObject(value);
|
3541 | });
|
3542 |
|
3543 | Formatter.add('object', 'arguments', function(value) {
|
3544 | return this._formatObject(value, {
|
3545 | prefix: 'Arguments',
|
3546 | formatPropertyName: function(key) {
|
3547 | if(!key.match(/\d+/)) {
|
3548 | return this.formatPropertyName(key);
|
3549 | }
|
3550 | },
|
3551 | brackets: ['[', ']']
|
3552 | });
|
3553 | });
|
3554 |
|
3555 | Formatter.add('object', 'array', function(value) {
|
3556 | return this._formatObject(value, {
|
3557 | formatPropertyName: function(key) {
|
3558 | if(!key.match(/\d+/)) {
|
3559 | return this.formatPropertyName(key);
|
3560 | }
|
3561 | },
|
3562 | brackets: ['[', ']']
|
3563 | });
|
3564 | });
|
3565 |
|
3566 |
|
3567 | function formatDate(value, isUTC) {
|
3568 | var prefix = isUTC ? 'UTC' : '';
|
3569 |
|
3570 | var date = value['get' + prefix + 'FullYear']() +
|
3571 | '-' +
|
3572 | util.pad0(value['get' + prefix + 'Month']() + 1, 2) +
|
3573 | '-' +
|
3574 | util.pad0(value['get' + prefix + 'Date'](), 2);
|
3575 |
|
3576 | var time = util.pad0(value['get' + prefix + 'Hours'](), 2) +
|
3577 | ':' +
|
3578 | util.pad0(value['get' + prefix + 'Minutes'](), 2) +
|
3579 | ':' +
|
3580 | util.pad0(value['get' + prefix + 'Seconds'](), 2) +
|
3581 | '.' +
|
3582 | util.pad0(value['get' + prefix + 'Milliseconds'](), 3);
|
3583 |
|
3584 | var to = value.getTimezoneOffset();
|
3585 | var absTo = Math.abs(to);
|
3586 | var hours = Math.floor(absTo / 60);
|
3587 | var minutes = absTo - hours * 60;
|
3588 | var tzFormat = (to < 0 ? '+' : '-') + util.pad0(hours, 2) + util.pad0(minutes, 2);
|
3589 |
|
3590 | return date + ' ' + time + (isUTC ? '' : ' ' + tzFormat);
|
3591 | }
|
3592 |
|
3593 | Formatter.add('object', 'date', function(value) {
|
3594 | return this._formatObject(value, { value: formatDate(value, this.isUTCdate) });
|
3595 | });
|
3596 |
|
3597 | Formatter.add('function', function(value) {
|
3598 | return this._formatObject(value, {
|
3599 | additionalProperties: [['name', Formatter.functionName(value)]]
|
3600 | });
|
3601 | });
|
3602 |
|
3603 | Formatter.add('object', 'error', function(value) {
|
3604 | return this._formatObject(value, {
|
3605 | prefix: value.name,
|
3606 | additionalProperties: [['message', value.message]]
|
3607 | });
|
3608 | });
|
3609 |
|
3610 | Formatter.add('object', 'buffer', Formatter.generateFunctionForIndexedArray('length', 'Buffer', 2));
|
3611 |
|
3612 | Formatter.add('object', 'array-buffer', Formatter.generateFunctionForIndexedArray('byteLength', 'ArrayBuffer', 2));
|
3613 |
|
3614 | Formatter.add('object', 'typed-array', 'int8', Formatter.generateFunctionForIndexedArray('length', 'Int8Array', 2));
|
3615 | Formatter.add('object', 'typed-array', 'uint8', Formatter.generateFunctionForIndexedArray('length', 'Uint8Array', 2));
|
3616 | Formatter.add('object', 'typed-array', 'uint8clamped', Formatter.generateFunctionForIndexedArray('length', 'Uint8ClampedArray', 2));
|
3617 |
|
3618 | Formatter.add('object', 'typed-array', 'int16', Formatter.generateFunctionForIndexedArray('length', 'Int16Array', 4));
|
3619 | Formatter.add('object', 'typed-array', 'uint16', Formatter.generateFunctionForIndexedArray('length', 'Uint16Array', 4));
|
3620 |
|
3621 | Formatter.add('object', 'typed-array', 'int32', Formatter.generateFunctionForIndexedArray('length', 'Int32Array', 8));
|
3622 | Formatter.add('object', 'typed-array', 'uint32', Formatter.generateFunctionForIndexedArray('length', 'Uint32Array', 8));
|
3623 |
|
3624 |
|
3625 |
|
3626 | Formatter.add('object', 'promise', function() {
|
3627 | return '[Promise]';
|
3628 | });
|
3629 |
|
3630 | Formatter.add('object', 'xhr', function() {
|
3631 | return '[XMLHttpRequest]';
|
3632 | });
|
3633 |
|
3634 | Formatter.add('object', 'html-element', function(value) {
|
3635 | return value.outerHTML;
|
3636 | });
|
3637 |
|
3638 | Formatter.add('object', 'html-element', '#text', function(value) {
|
3639 | return value.nodeValue;
|
3640 | });
|
3641 |
|
3642 | Formatter.add('object', 'html-element', '#document', function(value) {
|
3643 | return value.documentElement.outerHTML;
|
3644 | });
|
3645 |
|
3646 | Formatter.add('object', 'host', function() {
|
3647 | return '[Host]';
|
3648 | });
|
3649 |
|
3650 | Formatter.add('object', 'set', function(value) {
|
3651 | var iter = value.values();
|
3652 | var len = 0;
|
3653 |
|
3654 | this.seen.push(value);
|
3655 |
|
3656 | var props = [];
|
3657 |
|
3658 | var next = iter.next();
|
3659 | while(!next.done) {
|
3660 | var val = next.value;
|
3661 | var f = this.format(val);
|
3662 | len += f.length;
|
3663 | props.push(f);
|
3664 |
|
3665 | next = iter.next();
|
3666 | }
|
3667 |
|
3668 | this.seen.pop();
|
3669 |
|
3670 | if(props.length === 0) return 'Set {}';
|
3671 |
|
3672 | if(len <= this.maxLineLength) {
|
3673 | return 'Set { ' + props.join(this.propSep + ' ') + ' }';
|
3674 | } else {
|
3675 | return 'Set {\n' + props.map(util.addSpaces).join(this.propSep + '\n') + '\n' + '}';
|
3676 | }
|
3677 | });
|
3678 |
|
3679 | Formatter.add('object', 'map', function(value) {
|
3680 | var iter = value.entries();
|
3681 | var len = 0;
|
3682 |
|
3683 | this.seen.push(value);
|
3684 |
|
3685 | var props = [];
|
3686 |
|
3687 | var next = iter.next();
|
3688 | while(!next.done) {
|
3689 | var val = next.value;
|
3690 | var fK = this.format(val[0]);
|
3691 | var fV = this.format(val[1]);
|
3692 |
|
3693 | var f;
|
3694 | if((fK.length + fV.length + 4) <= this.maxLineLength) {
|
3695 | f = fK + ' => ' + fV;
|
3696 | } else {
|
3697 | f = fK + ' =>\n' + fV;
|
3698 | }
|
3699 |
|
3700 | len += fK.length + fV.length + 4;
|
3701 | props.push(f);
|
3702 |
|
3703 | next = iter.next();
|
3704 | }
|
3705 |
|
3706 | this.seen.pop();
|
3707 |
|
3708 | if(props.length === 0) return 'Map {}';
|
3709 |
|
3710 | if(len <= this.maxLineLength) {
|
3711 | return 'Map { ' + props.join(this.propSep + ' ') + ' }';
|
3712 | } else {
|
3713 | return 'Map {\n' + props.map(util.addSpaces).join(this.propSep + '\n') + '\n' + '}';
|
3714 | }
|
3715 | });
|
3716 |
|
3717 | Formatter.prototype.defaultFormat = Formatter.prototype._format_object;
|
3718 |
|
3719 | function defaultFormat(value, opts) {
|
3720 | return new Formatter(opts).format(value);
|
3721 | }
|
3722 |
|
3723 | defaultFormat.Formatter = Formatter;
|
3724 | module.exports = defaultFormat;
|
3725 |
|
3726 | },{"./util":26,"should-type":24}],24:[function(require,module,exports){
|
3727 | var toString = Object.prototype.toString;
|
3728 |
|
3729 | var types = require('./types');
|
3730 |
|
3731 |
|
3732 |
|
3733 |
|
3734 |
|
3735 |
|
3736 |
|
3737 |
|
3738 |
|
3739 |
|
3740 |
|
3741 |
|
3742 |
|
3743 |
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 | function Type(type, cls, sub) {
|
3750 | this.type = type;
|
3751 | this.cls = cls;
|
3752 | this.sub = sub;
|
3753 | }
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 | function TypeChecker() {
|
3760 | this.checks = [];
|
3761 | }
|
3762 |
|
3763 | TypeChecker.prototype = {
|
3764 | add: function(func) {
|
3765 | this.checks.push(func);
|
3766 | return this;
|
3767 | },
|
3768 |
|
3769 | addTypeOf: function(type, res) {
|
3770 | return this.add(function(obj, tpeOf) {
|
3771 | if(tpeOf === type) {
|
3772 | return new Type(res);
|
3773 | }
|
3774 | });
|
3775 | },
|
3776 |
|
3777 | addClass: function(cls, res, sub) {
|
3778 | return this.add(function(obj, tpeOf, objCls) {
|
3779 | if(objCls === cls) {
|
3780 | return new Type(types.OBJECT, res, sub);
|
3781 | }
|
3782 | });
|
3783 | },
|
3784 |
|
3785 | getType: function(obj) {
|
3786 | var typeOf = typeof obj;
|
3787 | var cls = toString.call(obj);
|
3788 |
|
3789 | for(var i = 0, l = this.checks.length; i < l; i++) {
|
3790 | var res = this.checks[i].call(this, obj, typeOf, cls);
|
3791 | if(typeof res !== 'undefined') return res;
|
3792 | }
|
3793 |
|
3794 | }
|
3795 | };
|
3796 |
|
3797 | var main = new TypeChecker();
|
3798 |
|
3799 |
|
3800 |
|
3801 | main
|
3802 | .addTypeOf(types.NUMBER, types.NUMBER)
|
3803 | .addTypeOf(types.UNDEFINED, types.UNDEFINED)
|
3804 | .addTypeOf(types.STRING, types.STRING)
|
3805 | .addTypeOf(types.BOOLEAN, types.BOOLEAN)
|
3806 | .addTypeOf(types.FUNCTION, types.FUNCTION)
|
3807 | .addTypeOf(types.SYMBOL, types.SYMBOL)
|
3808 | .add(function(obj, tpeOf) {
|
3809 | if(obj === null) return new Type(types.NULL);
|
3810 | })
|
3811 | .addClass('[object String]', types.STRING)
|
3812 | .addClass('[object Boolean]', types.BOOLEAN)
|
3813 | .addClass('[object Number]', types.NUMBER)
|
3814 | .addClass('[object Array]', types.ARRAY)
|
3815 | .addClass('[object RegExp]', types.REGEXP)
|
3816 | .addClass('[object Error]', types.ERROR)
|
3817 | .addClass('[object Date]', types.DATE)
|
3818 | .addClass('[object Arguments]', types.ARGUMENTS)
|
3819 | .addClass('[object Math]')
|
3820 | .addClass('[object JSON]')
|
3821 | .addClass('[object ArrayBuffer]', types.ARRAY_BUFFER)
|
3822 | .addClass('[object Int8Array]', types.TYPED_ARRAY, 'int8')
|
3823 | .addClass('[object Uint8Array]', types.TYPED_ARRAY, 'uint8')
|
3824 | .addClass('[object Uint8ClampedArray]', types.TYPED_ARRAY, 'uint8clamped')
|
3825 | .addClass('[object Int16Array]', types.TYPED_ARRAY, 'int16')
|
3826 | .addClass('[object Uint16Array]', types.TYPED_ARRAY, 'uint16')
|
3827 | .addClass('[object Int32Array]', types.TYPED_ARRAY, 'int32')
|
3828 | .addClass('[object Uint32Array]', types.TYPED_ARRAY, 'uint32')
|
3829 | .addClass('[object Float32Array]', types.TYPED_ARRAY, 'float32')
|
3830 | .addClass('[object Float64Array]', types.TYPED_ARRAY, 'float64')
|
3831 | .addClass('[object DataView]', types.DATA_VIEW)
|
3832 | .addClass('[object Map]', types.MAP)
|
3833 | .addClass('[object WeakMap]', types.WEAK_MAP)
|
3834 | .addClass('[object Set]', types.SET)
|
3835 | .addClass('[object WeakSet]', types.WEAK_SET)
|
3836 | .addClass('[object Promise]', types.PROMISE)
|
3837 | .addClass('[object Blob]', types.BLOB)
|
3838 | .addClass('[object File]', types.FILE)
|
3839 | .addClass('[object FileList]', types.FILE_LIST)
|
3840 | .addClass('[object XMLHttpRequest]', types.XHR)
|
3841 | .add(function(obj) {
|
3842 | if((typeof Promise === types.FUNCTION && obj instanceof Promise) ||
|
3843 | (typeof obj.then === types.FUNCTION)) {
|
3844 | return new Type(types.OBJECT, types.PROMISE);
|
3845 | }
|
3846 | })
|
3847 | .add(function(obj) {
|
3848 | if(typeof Buffer !== 'undefined' && obj instanceof Buffer) {
|
3849 | return new Type(types.OBJECT, types.BUFFER);
|
3850 | }
|
3851 | })
|
3852 | .add(function(obj) {
|
3853 | if(typeof Node !== 'undefined' && obj instanceof Node) {
|
3854 | return new Type(types.OBJECT, types.HTML_ELEMENT, obj.nodeName);
|
3855 | }
|
3856 | })
|
3857 | .add(function(obj) {
|
3858 |
|
3859 | if(obj.Boolean === Boolean && obj.Number === Number && obj.String === String && obj.Date === Date) {
|
3860 | return new Type(types.OBJECT, types.HOST);
|
3861 | }
|
3862 | })
|
3863 | .add(function() {
|
3864 | return new Type(types.OBJECT);
|
3865 | });
|
3866 |
|
3867 |
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 |
|
3873 | function getGlobalType(obj) {
|
3874 | return main.getType(obj);
|
3875 | }
|
3876 |
|
3877 | getGlobalType.checker = main;
|
3878 | getGlobalType.TypeChecker = TypeChecker;
|
3879 | getGlobalType.Type = Type;
|
3880 |
|
3881 | Object.keys(types).forEach(function(typeName) {
|
3882 | getGlobalType[typeName] = types[typeName];
|
3883 | });
|
3884 |
|
3885 | module.exports = getGlobalType;
|
3886 |
|
3887 | },{"./types":25}],25:[function(require,module,exports){
|
3888 | var types = {
|
3889 | NUMBER: 'number',
|
3890 | UNDEFINED: 'undefined',
|
3891 | STRING: 'string',
|
3892 | BOOLEAN: 'boolean',
|
3893 | OBJECT: 'object',
|
3894 | FUNCTION: 'function',
|
3895 | NULL: 'null',
|
3896 | ARRAY: 'array',
|
3897 | REGEXP: 'regexp',
|
3898 | DATE: 'date',
|
3899 | ERROR: 'error',
|
3900 | ARGUMENTS: 'arguments',
|
3901 | SYMBOL: 'symbol',
|
3902 | ARRAY_BUFFER: 'array-buffer',
|
3903 | TYPED_ARRAY: 'typed-array',
|
3904 | DATA_VIEW: 'data-view',
|
3905 | MAP: 'map',
|
3906 | SET: 'set',
|
3907 | WEAK_SET: 'weak-set',
|
3908 | WEAK_MAP: 'weak-map',
|
3909 | PROMISE: 'promise',
|
3910 |
|
3911 |
|
3912 | BUFFER: 'buffer',
|
3913 |
|
3914 |
|
3915 | HTML_ELEMENT: 'html-element',
|
3916 | HTML_ELEMENT_TEXT: 'html-element-text',
|
3917 | DOCUMENT: 'document',
|
3918 | WINDOW: 'window',
|
3919 | FILE: 'file',
|
3920 | FILE_LIST: 'file-list',
|
3921 | BLOB: 'blob',
|
3922 |
|
3923 | HOST: 'host',
|
3924 |
|
3925 | XHR: 'xhr'
|
3926 | };
|
3927 |
|
3928 | module.exports = types;
|
3929 |
|
3930 | },{}],26:[function(require,module,exports){
|
3931 | function addSpaces(v) {
|
3932 | return v.split('\n').map(function(vv) { return ' ' + vv; }).join('\n');
|
3933 | }
|
3934 |
|
3935 | function pad(str, value, filler) {
|
3936 | str = String(str)
|
3937 | var isRight = false;
|
3938 |
|
3939 | if(value < 0) {
|
3940 | isRight = true;
|
3941 | value = -value;
|
3942 | }
|
3943 |
|
3944 | if(str.length < value) {
|
3945 | var padding = new Array(value - str.length + 1).join(filler);
|
3946 | return isRight ? str + padding : padding + str;
|
3947 | } else{
|
3948 | return str;
|
3949 | }
|
3950 | }
|
3951 |
|
3952 | module.exports = {
|
3953 | addSpaces: addSpaces,
|
3954 | pad: pad,
|
3955 | pad0: function(str, value) {
|
3956 | return pad(str, value, '0');
|
3957 | }
|
3958 | };
|
3959 |
|
3960 | },{}],27:[function(require,module,exports){
|
3961 | arguments[4][24][0].apply(exports,arguments)
|
3962 | },{"./types":28,"dup":24}],28:[function(require,module,exports){
|
3963 | arguments[4][25][0].apply(exports,arguments)
|
3964 | },{"dup":25}]},{},[1]);
|