UNPKG

72.7 kBJavaScriptView Raw
1(function (root, factory) {
2 'use strict';
3 if (typeof define === 'function' && define.amd) {
4 define(['power-assert-formatter', 'empower', 'espower', 'esprima', 'escodegen', 'assert'], factory);
5 } else if (typeof exports === 'object') {
6 factory(require('..'), require('empower'), require('espower'), require('esprima'), require('escodegen'), require('assert'));
7 } else {
8 factory(root.powerAssertFormatter, root.empower, root.espower, root.esprima, root.escodegen, root.assert);
9 }
10}(this, function (
11 createFormatter,
12 empower,
13 espower,
14 esprima,
15 escodegen,
16 baseAssert
17) {
18
19 function weave (line) {
20 var filepath = '/absolute/path/to/project/test/some_test.js';
21 var sourceRoot = '/absolute/path/to/project';
22 var options = {sourceType: 'module', tolerant: true, loc: true, tokens: true, raw: true};
23 var jsAST = esprima.parse(line, options);
24 var espoweredAST = espower(jsAST, {source: line, path: filepath, sourceRoot: sourceRoot});
25 return escodegen.generate(espoweredAST, {format: {compact: true}});
26 }
27
28 var assert = empower(baseAssert, createFormatter()),
29 assertPowerAssertContextFormatting = function (body, expectedLines) {
30 try {
31 body();
32 baseAssert.fail('AssertionError should be thrown');
33 } catch (e) {
34 baseAssert.equal(e.message, expectedLines.join('\n'));
35 }
36 };
37
38suite('power-assert-formatter', function () {
39
40
41 test('line number detection', function () {
42 var falsyStr = '';
43 assertPowerAssertContextFormatting(function () {
44 eval(weave('var i = 0;\n\nassert(falsyStr);'));
45 }, [
46 ' # test/some_test.js:3',
47 ' ',
48 ' assert(falsyStr)',
49 ' | ',
50 ' "" ',
51 ' '
52 ]);
53 });
54
55
56 test('Identifier with empty string', function () {
57 var falsyStr = '';
58 assertPowerAssertContextFormatting(function () {
59 eval(weave('assert(falsyStr);'));
60 }, [
61 ' # test/some_test.js:1',
62 ' ',
63 ' assert(falsyStr)',
64 ' | ',
65 ' "" ',
66 ' '
67 ]);
68 });
69
70
71 test('Identifier with falsy number', function () {
72 var falsyNum = 0;
73 assertPowerAssertContextFormatting(function () {
74 eval(weave('assert(falsyNum);'));
75 }, [
76 ' # test/some_test.js:1',
77 ' ',
78 ' assert(falsyNum)',
79 ' | ',
80 ' 0 ',
81 ' '
82 ]);
83 });
84
85
86 test('UnaryExpression, negation', function () {
87 var truth = true;
88 assertPowerAssertContextFormatting(function () {
89 eval(weave('assert(!truth);'));
90 }, [
91 ' # test/some_test.js:1',
92 ' ',
93 ' assert(!truth)',
94 ' || ',
95 ' |true ',
96 ' false ',
97 ' '
98 ]);
99 });
100
101
102 test('UnaryExpression, double negative', function () {
103 var some = '';
104 assertPowerAssertContextFormatting(function () {
105 eval(weave('assert(!!some);'));
106 }, [
107 ' # test/some_test.js:1',
108 ' ',
109 ' assert(!!some)',
110 ' ||| ',
111 ' ||"" ',
112 ' |true ',
113 ' false ',
114 ' '
115 ]);
116 });
117
118
119 test('typeof operator: assert(typeof foo !== "undefined");', function () {
120 assertPowerAssertContextFormatting(function () {
121 eval(weave('assert(typeof foo !== "undefined");'));
122 }, [
123 ' # test/some_test.js:1',
124 ' ',
125 ' assert(typeof foo !== "undefined")',
126 ' | | ',
127 ' | false ',
128 ' "undefined" ',
129 ' '
130 ]);
131 });
132
133
134 test('undefined property: assert({}.hoge === "xxx");', function () {
135 assertPowerAssertContextFormatting(function () {
136 eval(weave('assert({}.hoge === "xxx");'));
137 }, [
138 ' # test/some_test.js:1',
139 ' ',
140 ' assert({}.hoge === "xxx")',
141 ' | | | ',
142 ' | | false ',
143 ' | undefined ',
144 ' Object{} ',
145 ' ',
146 ' [string] "xxx"',
147 ' => "xxx"',
148 ' [undefined] {}.hoge',
149 ' => undefined',
150 ' '
151 ]);
152 });
153
154
155 test('assert((delete foo.bar) === false);', function () {
156 var foo = {
157 bar: {
158 baz: false
159 }
160 };
161 assertPowerAssertContextFormatting(function () {
162 eval(weave('assert((delete foo.bar) === false);'));
163 }, [
164 ' # test/some_test.js:1',
165 ' ',
166 ' assert(delete foo.bar === false)',
167 ' | | | | ',
168 ' | | | false ',
169 ' | | Object{baz:false}',
170 ' true Object{bar:#Object#}',
171 ' ',
172 ' [boolean] false',
173 ' => false',
174 ' [boolean] delete foo.bar',
175 ' => true',
176 ' '
177 ]);
178 });
179
180
181 test('assert(fuga === piyo);', function () {
182 var fuga = 'foo';
183 var piyo = 8;
184 assertPowerAssertContextFormatting(function () {
185 eval(weave('assert(fuga === piyo);'));
186 }, [
187 ' # test/some_test.js:1',
188 ' ',
189 ' assert(fuga === piyo)',
190 ' | | | ',
191 ' | | 8 ',
192 ' | false ',
193 ' "foo" ',
194 ' ',
195 ' [number] piyo',
196 ' => 8',
197 ' [string] fuga',
198 ' => "foo"',
199 ' '
200 ]);
201 });
202
203
204 test('Loose equality: assert(truthy == falsy);', function () {
205 var truthy = '1';
206 var falsy = false;
207 assertPowerAssertContextFormatting(function () {
208 eval(weave('assert(truthy == falsy);'));
209 }, [
210 ' # test/some_test.js:1',
211 ' ',
212 ' assert(truthy == falsy)',
213 ' | | | ',
214 ' | | false ',
215 ' "1" false ',
216 ' ',
217 ' [boolean] falsy',
218 ' => false',
219 ' [string] truthy',
220 ' => "1"',
221 ' '
222 ]);
223 });
224
225
226 test('assert(fuga !== piyo);', function () {
227 var fuga = 'foo';
228 var piyo = 'foo';
229 assertPowerAssertContextFormatting(function () {
230 eval(weave('assert(fuga !== piyo);'));
231 }, [
232 ' # test/some_test.js:1',
233 ' ',
234 ' assert(fuga !== piyo)',
235 ' | | | ',
236 ' | | "foo"',
237 ' | false ',
238 ' "foo" ',
239 ' '
240 ]);
241 });
242
243
244 test('Literal and UnaryExpression: assert(4 === -4);', function () {
245 assertPowerAssertContextFormatting(function () {
246 eval(weave('assert(4 === -4);'));
247 }, [
248 ' # test/some_test.js:1',
249 ' ',
250 ' assert(4 === -4)',
251 ' | | ',
252 ' | -4 ',
253 ' false ',
254 ' ',
255 ' [number] -4',
256 ' => -4',
257 ' [number] 4',
258 ' => 4',
259 ' '
260 ]);
261 });
262
263
264 test('assert(nan1 === nan2);', function () {
265 var nan1 = NaN;
266 var nan2 = NaN;
267 assertPowerAssertContextFormatting(function () {
268 eval(weave('assert(nan1 === nan2);'));
269 }, [
270 ' # test/some_test.js:1',
271 ' ',
272 ' assert(nan1 === nan2)',
273 ' | | | ',
274 ' | | NaN ',
275 ' NaN false ',
276 ' ',
277 ' [number] nan2',
278 ' => NaN',
279 ' [number] nan1',
280 ' => NaN',
281 ' '
282 ]);
283 });
284
285
286 test('assert(positiveInfinity === negativeInfinity);', function () {
287 var positiveInfinity = Infinity;
288 var negativeInfinity = -Infinity;
289 assertPowerAssertContextFormatting(function () {
290 eval(weave('assert(positiveInfinity === negativeInfinity);'));
291 }, [
292 ' # test/some_test.js:1',
293 ' ',
294 ' assert(positiveInfinity === negativeInfinity)',
295 ' | | | ',
296 ' | | -Infinity ',
297 ' Infinity false ',
298 ' ',
299 ' [number] negativeInfinity',
300 ' => -Infinity',
301 ' [number] positiveInfinity',
302 ' => Infinity',
303 ' '
304 ]);
305 });
306
307
308 test('BinaryExpression with Literal and Identifier: assert(fuga !== 4);', function () {
309 var fuga = 4;
310 assertPowerAssertContextFormatting(function () {
311 eval(weave('assert(fuga !== 4);'));
312 }, [
313 ' # test/some_test.js:1',
314 ' ',
315 ' assert(fuga !== 4)',
316 ' | | ',
317 ' 4 false ',
318 ' '
319 ]);
320 });
321
322
323 test('assert(4 !== 4);', function () {
324 assertPowerAssertContextFormatting(function () {
325 eval(weave('assert(4 !== 4);'));
326 }, [
327 ' # test/some_test.js:1',
328 ' ',
329 ' assert(4 !== 4)',
330 ' | ',
331 ' false ',
332 ' '
333 ]);
334 });
335
336
337 (function () {
338 test('assert(foo instanceof Foo);', function () {
339 var Foo = function () {
340 };
341 var foo = 'hoge';
342 assertPowerAssertContextFormatting(function () {
343 eval(weave('assert(foo instanceof Foo);'));
344 }, [
345 ' # test/some_test.js:1',
346 ' ',
347 ' assert(foo instanceof Foo)',
348 ' | | | ',
349 ' | false #function#',
350 ' "hoge" ',
351 ' '
352 ]);
353 });
354 })();
355
356
357 test('MemberExpression: assert(ary1.length === ary2.length);', function () {
358 var ary1 = ['foo', 'bar'];
359 var ary2 = ['aaa', 'bbb', 'ccc'];
360 assertPowerAssertContextFormatting(function () {
361 eval(weave('assert(ary1.length === ary2.length);'));
362 }, [
363 ' # test/some_test.js:1',
364 ' ',
365 ' assert(ary1.length === ary2.length)',
366 ' | | | | | ',
367 ' | | | | 3 ',
368 ' | | | ["aaa","bbb","ccc"]',
369 ' | 2 false ',
370 ' ["foo","bar"] ',
371 ' ',
372 ' [number] ary2.length',
373 ' => 3',
374 ' [number] ary1.length',
375 ' => 2',
376 ' '
377 ]);
378 });
379
380
381 test('LogicalExpression: assert(5 < actual && actual < 13);', function () {
382 var actual = 16;
383 assertPowerAssertContextFormatting(function () {
384 eval(weave('assert(5 < actual && actual < 13);'));
385 }, [
386 ' # test/some_test.js:1',
387 ' ',
388 ' assert(5 < actual && actual < 13)',
389 ' | | | | | ',
390 ' | | | 16 false',
391 ' | 16 false ',
392 ' true ',
393 ' '
394 ]);
395 });
396
397
398 test('LogicalExpression OR: assert.ok(actual < 5 || 13 < actual);', function () {
399 var actual = 10;
400 assertPowerAssertContextFormatting(function () {
401 eval(weave('assert.ok(actual < 5 || 13 < actual);'));
402 }, [
403 ' # test/some_test.js:1',
404 ' ',
405 ' assert.ok(actual < 5 || 13 < actual)',
406 ' | | | | | ',
407 ' | | | | 10 ',
408 ' | | false false ',
409 ' 10 false ',
410 ' '
411 ]);
412 });
413
414
415 test('Characterization test of LogicalExpression current spec: assert(2 > actual && actual < 13);', function () {
416 var actual = 5;
417 assertPowerAssertContextFormatting(function () {
418 eval(weave('assert(2 > actual && actual < 13);'));
419 }, [
420 ' # test/some_test.js:1',
421 ' ',
422 ' assert(2 > actual && actual < 13)',
423 ' | | | ',
424 ' | 5 false ',
425 ' false ',
426 ' '
427 ]);
428 });
429
430
431 test('Deep MemberExpression chain: assert(foo.bar.baz);', function () {
432 var foo = {
433 bar: {
434 baz: false
435 }
436 };
437 assertPowerAssertContextFormatting(function () {
438 eval(weave('assert(foo.bar.baz);'));
439 }, [
440 ' # test/some_test.js:1',
441 ' ',
442 ' assert(foo.bar.baz)',
443 ' | | | ',
444 ' | | false',
445 ' | Object{baz:false}',
446 ' Object{bar:#Object#}',
447 ' '
448 ]);
449 });
450
451
452 test('computed MemberExpression with Literal key: assert(foo["bar"].baz);', function () {
453 var foo = {
454 bar: {
455 baz: false
456 }
457 };
458 assertPowerAssertContextFormatting(function () {
459 eval(weave('assert(foo["bar"].baz);'));
460 }, [
461 ' # test/some_test.js:1',
462 ' ',
463 ' assert(foo["bar"].baz)',
464 ' | | | ',
465 ' | | false',
466 ' | Object{baz:false}',
467 ' Object{bar:#Object#}',
468 ' '
469 ]);
470 });
471
472
473 test('computed MemberExpression with Identifier key: assert(foo[propName].baz);', function () {
474 var propName = 'bar';
475 var foo = {
476 bar: {
477 baz: false
478 }
479 };
480 assertPowerAssertContextFormatting(function () {
481 eval(weave('assert(foo[propName].baz);'));
482 }, [
483 ' # test/some_test.js:1',
484 ' ',
485 ' assert(foo[propName].baz)',
486 ' | || | ',
487 ' | |"bar" false',
488 ' | Object{baz:false}',
489 ' Object{bar:#Object#}',
490 ' '
491 ]);
492 });
493
494
495 test('CallExpression with computed MemberExpression with Identifier key: assert(foo[propName]());', function () {
496 var propName = 'bar';
497 var foo = {
498 bar: function () {
499 return false;
500 }
501 };
502 assertPowerAssertContextFormatting(function () {
503 eval(weave('assert(foo[propName]());'));
504 }, [
505 ' # test/some_test.js:1',
506 ' ',
507 ' assert(foo[propName]())',
508 ' | || ',
509 ' | |"bar" ',
510 ' | false ',
511 ' Object{bar:#function#}',
512 ' '
513 ]);
514 });
515
516
517 test('CallExpression with deep computed MemberExpression: assert(foo[hoge[fuga[piyo]]]());', function () {
518 var piyo = 'piyoKey';
519 var fuga = {
520 piyoKey: 'fugaKey'
521 };
522 var hoge = {
523 fugaKey: 'func'
524 };
525 var foo = {
526 func: function () {
527 return false;
528 }
529 };
530 assertPowerAssertContextFormatting(function () {
531 eval(weave('assert(foo[hoge[fuga[piyo]]]());'));
532 }, [
533 ' # test/some_test.js:1',
534 ' ',
535 ' assert(foo[hoge[fuga[piyo]]]())',
536 ' | || || || ',
537 ' | || || |"piyoKey" ',
538 ' | || || "fugaKey" ',
539 ' | || |Object{piyoKey:"fugaKey"}',
540 ' | || "func" ',
541 ' | |Object{fugaKey:"func"}',
542 ' | false ',
543 ' Object{func:#function#} ',
544 ' '
545 ]);
546 });
547
548
549 test('computed MemberExpression chain with various key: assert(foo[propName]["baz"][keys()[0]]);', function () {
550 var keys = function () { return ["toto"]; };
551 var propName = "bar";
552 var foo = {
553 bar: {
554 baz: {
555 toto: false
556 }
557 }
558 };
559 assertPowerAssertContextFormatting(function () {
560 eval(weave('assert(foo[propName]["baz"][keys()[0]]);'));
561 }, [
562 ' # test/some_test.js:1',
563 ' ',
564 ' assert(foo[propName]["baz"][keys()[0]])',
565 ' | || | || | ',
566 ' | || | || "toto"',
567 ' | || | |["toto"] ',
568 ' | || | false ',
569 ' | |"bar" Object{toto:false} ',
570 ' | Object{baz:#Object#} ',
571 ' Object{bar:#Object#} ',
572 ' '
573 ]);
574 });
575
576
577 test('assert(func());', function () {
578 var func = function () { return false; };
579 assertPowerAssertContextFormatting(function () {
580 eval(weave('assert(func());'));
581 }, [
582 ' # test/some_test.js:1',
583 ' ',
584 ' assert(func())',
585 ' | ',
586 ' false ',
587 ' '
588 ]);
589 });
590
591
592 test('assert(obj.age());', function () {
593 var obj = {
594 age: function () {
595 return 0;
596 }
597 };
598 assertPowerAssertContextFormatting(function () {
599 eval(weave('assert(obj.age());'));
600 }, [
601 ' # test/some_test.js:1',
602 ' ',
603 ' assert(obj.age())',
604 ' | | ',
605 ' | 0 ',
606 ' Object{age:#function#}',
607 ' '
608 ]);
609 });
610
611
612 test('CallExpression with arguments: assert(isFalsy(positiveInt));', function () {
613 var isFalsy = function (arg) {
614 return !(arg);
615 };
616 var positiveInt = 50;
617 assertPowerAssertContextFormatting(function () {
618 eval(weave('assert(isFalsy(positiveInt));'));
619 }, [
620 ' # test/some_test.js:1',
621 ' ',
622 ' assert(isFalsy(positiveInt))',
623 ' | | ',
624 ' false 50 ',
625 ' '
626 ]);
627 });
628
629
630 test('assert(sum(one, two, three) === seven);', function () {
631 var sum = function () {
632 var result = 0;
633 for (var i = 0; i < arguments.length; i += 1) {
634 result += arguments[i];
635 }
636 return result;
637 };
638 var one = 1, two = 2, three = 3, seven = 7, ten = 10;
639 assertPowerAssertContextFormatting(function () {
640 eval(weave('assert(sum(one, two, three) === seven);'));
641 }, [
642 ' # test/some_test.js:1',
643 ' ',
644 ' assert(sum(one, two, three) === seven)',
645 ' | | | | | | ',
646 ' | | | | | 7 ',
647 ' 6 1 2 3 false ',
648 ' ',
649 ' [number] seven',
650 ' => 7',
651 ' [number] sum(one, two, three)',
652 ' => 6',
653 ' '
654 ]);
655 });
656
657
658 test('nexted CallExpression: assert(sum(sum(one, two), three) === sum(sum(two, three), seven));', function () {
659 var sum = function () {
660 var result = 0;
661 for (var i = 0; i < arguments.length; i += 1) {
662 result += arguments[i];
663 }
664 return result;
665 };
666 var one = 1, two = 2, three = 3, seven = 7, ten = 10;
667 assertPowerAssertContextFormatting(function () {
668 eval(weave('assert(sum(sum(one, two), three) === sum(sum(two, three), seven));'));
669 }, [
670 ' # test/some_test.js:1',
671 ' ',
672 ' assert(sum(sum(one, two), three) === sum(sum(two, three), seven))',
673 ' | | | | | | | | | | | ',
674 ' | | | | | | 12 5 2 3 7 ',
675 ' 6 3 1 2 3 false ',
676 ' ',
677 ' [number] sum(sum(two, three), seven)',
678 ' => 12',
679 ' [number] sum(sum(one, two), three)',
680 ' => 6',
681 ' '
682 ]);
683 });
684
685
686 test('assert(math.calc.sum(one, two, three) === seven);', function () {
687 var math = {
688 calc: {
689 sum: function () {
690 var result = 0;
691 for (var i = 0; i < arguments.length; i += 1) {
692 result += arguments[i];
693 }
694 return result;
695 }
696 }
697 };
698 var one = 1, two = 2, three = 3, seven = 7, ten = 10;
699 assertPowerAssertContextFormatting(function () {
700 eval(weave('assert(math.calc.sum(one, two, three) === seven);'));
701 }, [
702 ' # test/some_test.js:1',
703 ' ',
704 ' assert(math.calc.sum(one, two, three) === seven)',
705 ' | | | | | | | | ',
706 ' | | | | | | | 7 ',
707 ' | | 6 1 2 3 false ',
708 ' | Object{sum:#function#} ',
709 ' Object{calc:#Object#} ',
710 ' ',
711 ' [number] seven',
712 ' => 7',
713 ' [number] math.calc.sum(one, two, three)',
714 ' => 6',
715 ' '
716 ]);
717 });
718
719
720 test('Nested CallExpression with BinaryExpression: assert((three * (seven * ten)) === three);', function () {
721 var one = 1, two = 2, three = 3, seven = 7, ten = 10;
722 assertPowerAssertContextFormatting(function () {
723 eval(weave('assert((three * (seven * ten)) === three);'));
724 }, [
725 ' # test/some_test.js:1',
726 ' ',
727 ' assert(three * (seven * ten) === three)',
728 ' | | | | | | | ',
729 ' | | | | | | 3 ',
730 ' | | | | 10 false ',
731 ' | | 7 70 ',
732 ' 3 210 ',
733 ' ',
734 ' [number] three',
735 ' => 3',
736 ' [number] three * (seven * ten)',
737 ' => 210',
738 ' '
739 ]);
740 });
741
742
743 test('Simple BinaryExpression with comment', function () {
744 var hoge = 'foo';
745 var fuga = 'bar';
746 assertPowerAssertContextFormatting(function () {
747 eval(weave('assert.ok(hoge === fuga, "comment");'));
748 }, [
749 'comment # test/some_test.js:1',
750 ' ',
751 ' assert.ok(hoge === fuga, "comment")',
752 ' | | | ',
753 ' | | "bar" ',
754 ' | false ',
755 ' "foo" ',
756 ' ',
757 ' --- [string] fuga',
758 ' +++ [string] hoge',
759 ' @@ -1,3 +1,3 @@',
760 ' -bar',
761 ' +foo',
762 ' ',
763 ' '
764 ]);
765 });
766
767
768 test('Looooong string', function () {
769 var longString = 'very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message';
770 var anotherLongString = 'yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message';
771 assertPowerAssertContextFormatting(function () {
772 eval(weave('assert(longString === anotherLongString);'));
773 }, [
774 ' # test/some_test.js:1',
775 ' ',
776 ' assert(longString === anotherLongString)',
777 ' | | | ',
778 ' | | "yet another loooooooooooooooooooooooooooooooooooooooooooooooooooong message"',
779 ' | false ',
780 ' "very very loooooooooooooooooooooooooooooooooooooooooooooooooooong message"',
781 ' ',
782 ' --- [string] anotherLongString',
783 ' +++ [string] longString',
784 ' @@ -1,15 +1,13 @@',
785 ' -yet anoth',
786 ' +very v',
787 ' er',
788 ' +y',
789 ' loo',
790 ' ',
791 ' '
792 ]);
793 });
794
795
796 test('double byte character width', function () {
797 var fuga = 'あい';
798 var piyo = 'うえお';
799 var concat = function (a, b) {
800 return a + b;
801 };
802 assertPowerAssertContextFormatting(function () {
803 eval(weave('assert(!concat(fuga, piyo));'));
804 }, [
805 ' # test/some_test.js:1',
806 ' ',
807 ' assert(!concat(fuga, piyo))',
808 ' || | | ',
809 ' || | "うえお"',
810 ' || "あい" ',
811 ' |"あいうえお" ',
812 ' false ',
813 ' '
814 ]);
815
816 });
817
818
819 test('Japanese zenkaku string literal adjustment', function () {
820 var piyo = 'うえお';
821 var concat = function (a, b) {
822 return a + b;
823 };
824 assertPowerAssertContextFormatting(function () {
825 eval(weave('assert.equal(concat("ほげ", piyo), concat("あい", piyo));'));
826 }, [
827 ' # test/some_test.js:1',
828 ' ',
829 ' assert.equal(concat("ほげ", piyo), concat("あい", piyo))',
830 ' | | | | ',
831 ' | | "あいうえお" "うえお"',
832 ' "ほげうえお" "うえお" ',
833 ' '
834 ]);
835
836 });
837
838
839 test('Japanese hankaku width', function () {
840 var fuga = 'アイ';
841 var piyo = 'ウエオ';
842 var concat = function (a, b) {
843 return a + b;
844 };
845 assertPowerAssertContextFormatting(function () {
846 eval(weave('assert(!concat(fuga, piyo));'));
847 }, [
848 ' # test/some_test.js:1',
849 ' ',
850 ' assert(!concat(fuga, piyo))',
851 ' || | | ',
852 ' || "アイ" "ウエオ" ',
853 ' |"アイウエオ" ',
854 ' false ',
855 ' '
856 ]);
857 });
858
859
860 test('Ambiguous EastAsianWidth', function () {
861 var suffix1 = '…';
862 var suffix2 = '☆';
863 assertPowerAssertContextFormatting(function () {
864 eval(weave('assert("※ただしイケメンに限る" + suffix1 === "○ただしイケメンに限る" + suffix2);'));
865 }, [
866 ' # test/some_test.js:1',
867 ' ',
868 ' assert("※ただしイケメンに限る" + suffix1 === "○ただしイケメンに限る" + suffix2)',
869 ' | | | | | ',
870 ' | | | | "☆" ',
871 ' | "…" false "○ただしイケメンに限る☆"',
872 ' "※ただしイケメンに限る…" ',
873 ' ',
874 ' --- [string] "○ただしイケメンに限る" + suffix2',
875 ' +++ [string] "※ただしイケメンに限る" + suffix1',
876 ' @@ -1,5 +1,5 @@',
877 ' -○',
878 ' +※',
879 ' ただしイ',
880 ' @@ -8,5 +8,5 @@',
881 ' ンに限る',
882 ' -☆',
883 ' +…',
884 ' ',
885 ' '
886 ]);
887 });
888
889
890 test('Object having circular structure', function () {
891 var cyclic = [], two = 2;
892 cyclic.push('foo');
893 cyclic.push(cyclic);
894 cyclic.push('baz');
895 assertPowerAssertContextFormatting(function () {
896 eval(weave('assert.ok(cyclic[two] === cyclic);'));
897 }, [
898 ' # test/some_test.js:1',
899 ' ',
900 ' assert.ok(cyclic[two] === cyclic)',
901 ' | || | | ',
902 ' | || | ["foo",#@Circular#,"baz"]',
903 ' | |2 false ',
904 ' | "baz" ',
905 ' ["foo",#@Circular#,"baz"]',
906 ' ',
907 ' [Array] cyclic',
908 ' => ["foo",#@Circular#,"baz"]',
909 ' [string] cyclic[two]',
910 ' => "baz"',
911 ' '
912 ]);
913 });
914
915
916 test('UnaryExpression of UnaryExpression: assert(typeof + twoStr === -twoStr);', function () {
917 var twoStr = '2';
918 assertPowerAssertContextFormatting(function () {
919 eval(weave('assert(typeof + twoStr === -twoStr);'));
920 }, [
921 ' # test/some_test.js:1',
922 ' ',
923 ' assert(typeof +twoStr === -twoStr)',
924 ' | || | || ',
925 ' | || | |"2" ',
926 ' | || | -2 ',
927 ' | |"2" false ',
928 ' | 2 ',
929 ' "number" ',
930 ' ',
931 ' [number] -twoStr',
932 ' => -2',
933 ' [string] typeof +twoStr',
934 ' => "number"',
935 ' '
936 ]);
937 });
938
939
940 test('AssignmentExpression: assert(minusOne += 1);', function () {
941 var minusOne = -1;
942 assertPowerAssertContextFormatting(function () {
943 eval(weave('assert(minusOne += 1);'));
944 }, [
945 ' # test/some_test.js:1',
946 ' ',
947 ' assert(minusOne += 1)',
948 ' | ',
949 ' 0 ',
950 ' '
951 ]);
952 });
953
954
955 test('AssignmentExpression with MemberExpression: assert((dog.age += 1) === four);', function () {
956 var dog = { age: 2 }, four = 4;
957 assertPowerAssertContextFormatting(function () {
958 eval(weave('assert((dog.age += 1) === four);'));
959 }, [
960 ' # test/some_test.js:1',
961 ' ',
962 ' assert((dog.age += 1) === four)',
963 ' | | | ',
964 ' | | 4 ',
965 ' 3 false ',
966 ' ',
967 ' [number] four',
968 ' => 4',
969 ' [number] dog.age += 1',
970 ' => 3',
971 ' '
972 ]);
973 });
974
975
976 test('ArrayExpression: assert([foo, bar].length === four);', function () {
977 var foo = 'hoge', bar = 'fuga', four = 4;
978 assertPowerAssertContextFormatting(function () {
979 eval(weave('assert([foo, bar].length === four);'));
980 }, [
981 ' # test/some_test.js:1',
982 ' ',
983 ' assert([foo,bar].length === four)',
984 ' || | | | | ',
985 ' || | | | 4 ',
986 ' || | 2 false ',
987 ' || "fuga" ',
988 ' |"hoge" ',
989 ' ["hoge","fuga"] ',
990 ' ',
991 ' [number] four',
992 ' => 4',
993 ' [number] [foo,bar].length',
994 ' => 2',
995 ' '
996 ]);
997 });
998
999
1000 test('various expressions in ArrayExpression: assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");', function () {
1001 var foo = {bar: 'fuga'}, baz = function (arg) { return null; }, moo = 'boo', fourStr = '4';
1002 assertPowerAssertContextFormatting(function () {
1003 eval(weave('assert(typeof [[foo.bar, baz(moo)], + fourStr] === "number");'));
1004 }, [
1005 ' # test/some_test.js:1',
1006 ' ',
1007 ' assert(typeof [[foo.bar,baz(moo)],+fourStr] === "number")',
1008 ' | ||| | | | || | ',
1009 ' | ||| | | | |"4" false ',
1010 ' | ||| | | "boo" 4 ',
1011 ' | ||| | null ',
1012 ' | ||| "fuga" ',
1013 ' | ||Object{bar:"fuga"} ',
1014 ' | |["fuga",null] ',
1015 ' | [#Array#,4] ',
1016 ' "object" ',
1017 ' ',
1018 ' --- [string] "number"',
1019 ' +++ [string] typeof [[foo.bar,baz(moo)],+fourStr]',
1020 ' @@ -1,6 +1,6 @@',
1021 ' -number',
1022 ' +object',
1023 ' ',
1024 ' '
1025 ]);
1026 });
1027
1028
1029 test('prefix UpdateExpression: assert(++minusOne);', function () {
1030 var minusOne = -1;
1031 assertPowerAssertContextFormatting(function () {
1032 eval(weave('assert(++minusOne);'));
1033 }, [
1034 ' # test/some_test.js:1',
1035 ' ',
1036 ' assert(++minusOne)',
1037 ' | ',
1038 ' 0 ',
1039 ' '
1040 ]);
1041 });
1042
1043
1044 test('suffix UpdateExpression: assert(zero--);', function () {
1045 var zero = 0;
1046 assertPowerAssertContextFormatting(function () {
1047 eval(weave('assert(zero--);'));
1048 }, [
1049 ' # test/some_test.js:1',
1050 ' ',
1051 ' assert(zero--)',
1052 ' | ',
1053 ' 0 ',
1054 ' '
1055 ]);
1056 });
1057
1058
1059 test('ConditionalExpression: assert(truthy ? falsy : anotherFalsy);', function () {
1060 var truthy = 'truthy', falsy = 0, anotherFalsy = null;
1061 assertPowerAssertContextFormatting(function () {
1062 eval(weave('assert(truthy ? falsy : anotherFalsy);'));
1063 }, [
1064 ' # test/some_test.js:1',
1065 ' ',
1066 ' assert(truthy ? falsy : anotherFalsy)',
1067 ' | | ',
1068 ' "truthy" 0 ',
1069 ' '
1070 ]);
1071 });
1072
1073
1074 test('ConditionalExpression of ConditionalExpression: assert(falsy ? truthy : truthy ? anotherFalsy : truthy);', function () {
1075 var truthy = 'truthy', falsy = 0, anotherFalsy = null;
1076 assertPowerAssertContextFormatting(function () {
1077 eval(weave('assert(falsy ? truthy : truthy ? anotherFalsy : truthy);'));
1078 }, [
1079 ' # test/some_test.js:1',
1080 ' ',
1081 ' assert(falsy ? truthy : truthy ? anotherFalsy : truthy)',
1082 ' | | | ',
1083 ' 0 "truthy" null ',
1084 ' '
1085 ]);
1086 });
1087
1088
1089 test('RegularExpression will not be instrumented: assert(/^not/.exec(str));', function () {
1090 var str = 'ok';
1091 assertPowerAssertContextFormatting(function () {
1092 eval(weave('assert(/^not/.exec(str));'));
1093 }, [
1094 ' # test/some_test.js:1',
1095 ' ',
1096 ' assert(/^not/.exec(str))',
1097 ' | | ',
1098 ' null "ok" ',
1099 ' '
1100 ]);
1101 });
1102
1103
1104
1105 test('ObjectExpression: assert(!({foo: bar, hoge: fuga}));', function () {
1106 var bar = 'toto', fuga = 100;
1107 assertPowerAssertContextFormatting(function () {
1108 eval(weave('assert(!({foo: bar, hoge: fuga}));'));
1109 }, [
1110 ' # test/some_test.js:1',
1111 ' ',
1112 ' assert(!{foo: bar,hoge: fuga})',
1113 ' || | | ',
1114 ' || "toto" 100 ',
1115 ' |Object{foo:"toto",hoge:100}',
1116 ' false ',
1117 ' '
1118 ]);
1119 });
1120
1121
1122 test('complex ObjectExpression: assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));', function () {
1123 var bar = { baz: 'BAZ' }, first = 'Brendan', last = 'Eich';
1124 var nameOf = function (person) { return person.firstName + ' ' + person.lastName; };
1125 assertPowerAssertContextFormatting(function () {
1126 eval(weave('assert(!({ foo: bar.baz, name: nameOf({firstName: first, lastName: last}) }));'));
1127 }, [
1128 ' # test/some_test.js:1',
1129 ' ',
1130 ' assert(!{foo: bar.baz,name: nameOf({firstName: first,lastName: last})})',
1131 ' || | | | | | | ',
1132 ' || | | | | "Brendan" "Eich" ',
1133 ' || | | | Object{firstName:"Brendan",lastName:"Eich"}',
1134 ' || | "BAZ" "Brendan Eich" ',
1135 ' || Object{baz:"BAZ"} ',
1136 ' |Object{foo:"BAZ",name:"Brendan Eich"} ',
1137 ' false ',
1138 ' '
1139 ]);
1140 });
1141
1142
1143 test('NewExpression: assert(!(new Array(foo, bar, baz)));', function () {
1144 var foo = 'foo', bar = 'bar', baz = 'baz';
1145 assertPowerAssertContextFormatting(function () {
1146 eval(weave('assert(!(new Array(foo, bar, baz)));'));
1147 }, [
1148 ' # test/some_test.js:1',
1149 ' ',
1150 ' assert(!new Array(foo, bar, baz))',
1151 ' || | | | ',
1152 ' || | | "baz"',
1153 ' || | "bar" ',
1154 ' || "foo" ',
1155 ' |["foo","bar","baz"] ',
1156 ' false ',
1157 ' '
1158 ]);
1159 });
1160
1161
1162 test('NewExpression: assert(baz === new Array(foo, bar, baz)[1]);', function () {
1163 var foo = 'foo', bar = 'bar', baz = 'baz';
1164 assertPowerAssertContextFormatting(function () {
1165 eval(weave('assert(baz === new Array(foo, bar, baz)[1]);'));
1166 }, [
1167 ' # test/some_test.js:1',
1168 ' ',
1169 ' assert(baz === new Array(foo, bar, baz)[1])',
1170 ' | | | | | | | ',
1171 ' | | | | | | "bar"',
1172 ' | | | | | "baz" ',
1173 ' | | | | "bar" ',
1174 ' | | | "foo" ',
1175 ' | | ["foo","bar","baz"] ',
1176 ' | false ',
1177 ' "baz" ',
1178 ' ',
1179 ' --- [string] new Array(foo, bar, baz)[1]',
1180 ' +++ [string] baz',
1181 ' @@ -1,3 +1,3 @@',
1182 ' ba',
1183 ' -r',
1184 ' +z',
1185 ' ',
1186 ' '
1187 ]);
1188 });
1189
1190
1191 test('FunctionExpression will not be instrumented: assert(baz === (function (a, b) { return a + b; })(foo, bar));', function () {
1192 var foo = 'foo', bar = 'bar', baz = 'baz';
1193 assertPowerAssertContextFormatting(function () {
1194 eval(weave('assert(baz === (function (a, b) { return a + b; })(foo, bar));'));
1195 }, [
1196 ' # test/some_test.js:1',
1197 ' ',
1198 ' assert(baz === function (a, b) {return a + b;}(foo, bar))',
1199 ' | | | | | ',
1200 ' | | | | "bar"',
1201 ' | | "foobar" "foo" ',
1202 ' | false ',
1203 ' "baz" ',
1204 ' ',
1205 ' --- [string] function (a, b) {return a + b;}(foo, bar)',
1206 ' +++ [string] baz',
1207 ' @@ -1,6 +1,3 @@',
1208 ' -foo',
1209 ' ba',
1210 ' -r',
1211 ' +z',
1212 ' ',
1213 ' '
1214 ]);
1215 });
1216
1217
1218
1219 test('Bug reproduction: BinaryExpression with Literal in FunctionExpression: ', function () {
1220 var ary = ['foo', 'bar', 'baz', 'hoge'];
1221 assertPowerAssertContextFormatting(function () {
1222 eval(weave('assert(ary.every(function (element, index, array) { return element.length === 3; }));'));
1223 }, [
1224 ' # test/some_test.js:1',
1225 ' ',
1226 ' assert(ary.every(function (element, index, array) {return element.length === 3;}))',
1227 ' | | ',
1228 ' | false ',
1229 ' ["foo","bar","baz","hoge"] ',
1230 ' '
1231 ]);
1232 });
1233
1234
1235
1236 test('equal with Literal and Identifier: assert.equal(1, minusOne);', function () {
1237 var minusOne = -1;
1238 assertPowerAssertContextFormatting(function () {
1239 eval(weave('assert.equal(1, minusOne)'));
1240 }, [
1241 ' # test/some_test.js:1',
1242 ' ',
1243 ' assert.equal(1, minusOne)',
1244 ' | ',
1245 ' -1 ',
1246 ' '
1247 ]);
1248 });
1249
1250
1251 test('equal with UpdateExpression and Literal: assert.equal(++minusOne, 1);', function () {
1252 var minusOne = -1;
1253 assertPowerAssertContextFormatting(function () {
1254 eval(weave('assert.equal(++minusOne, 1)'));
1255 }, [
1256 ' # test/some_test.js:1',
1257 ' ',
1258 ' assert.equal(++minusOne, 1)',
1259 ' | ',
1260 ' 0 ',
1261 ' '
1262 ]);
1263 });
1264
1265
1266 test('notEqual with ConditionalExpression and AssignmentExpression: assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1);', function () {
1267 var truthy = 3, fiveInStr = '5', tenInStr = '10', four = 4;
1268 assertPowerAssertContextFormatting(function () {
1269 eval(weave('assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1)'));
1270 }, [
1271 ' # test/some_test.js:1',
1272 ' ',
1273 ' assert.notEqual(truthy ? fiveInStr : tenInStr, four += 1)',
1274 ' | | | ',
1275 ' 3 "5" 5 ',
1276 ' '
1277 ]);
1278 });
1279
1280
1281 test('strictEqual with CallExpression and BinaryExpression, Identifier: assert.strictEqual(obj.truthy(), three == threeInStr);', function () {
1282 var obj = { truthy: function () { return 'true'; }}, three = 3, threeInStr = '3';
1283 assertPowerAssertContextFormatting(function () {
1284 eval(weave('assert.strictEqual(obj.truthy(), three == threeInStr);'));
1285 }, [
1286 ' # test/some_test.js:1',
1287 ' ',
1288 ' assert.strictEqual(obj.truthy(), three == threeInStr)',
1289 ' | | | | | ',
1290 ' | | | | "3" ',
1291 ' | "true" 3 true ',
1292 ' Object{truthy:#function#} ',
1293 ' '
1294 ]);
1295 });
1296
1297
1298 test('notStrictEqual with MemberExpression and UnaryExpression: assert.notStrictEqual(typeof undefinedVar, types.undef);', function () {
1299 var types = { undef: 'undefined' };
1300 assertPowerAssertContextFormatting(function () {
1301 eval(weave('assert.notStrictEqual(typeof undefinedVar, types.undef)'));
1302 }, [
1303 ' # test/some_test.js:1',
1304 ' ',
1305 ' assert.notStrictEqual(typeof undefinedVar, types.undef)',
1306 ' | | | ',
1307 ' | | "undefined"',
1308 ' "undefined" Object{undef:"undefined"}',
1309 ' '
1310 ]);
1311 });
1312
1313
1314 test('deepEqual with LogicalExpression and ObjectExpression: assert.deepEqual(alice || bob, {name: kenName, age: four});', function () {
1315 var alice = {name: 'alice', age: 3}, bob = {name: 'bob', age: 5}, kenName = 'ken', four = 4;
1316 assertPowerAssertContextFormatting(function () {
1317 eval(weave('assert.deepEqual(alice || bob, {name: kenName, age: four});'));
1318 }, [
1319 ' # test/some_test.js:1',
1320 ' ',
1321 ' assert.deepEqual(alice || bob, {name: kenName,age: four})',
1322 ' | | | | | ',
1323 ' | | | "ken" 4 ',
1324 ' | | Object{name:"ken",age:4} ',
1325 ' | Object{name:"alice",age:3} ',
1326 ' Object{name:"alice",age:3} ',
1327 ' '
1328 ]);
1329 });
1330
1331
1332 test('notDeepEqual with ArrayExpression and NewExpression: assert.notDeepEqual([foo, bar, baz], new Array(foo, bar, baz));', function () {
1333 var foo = 'foo', bar = ['toto', 'tata'], baz = {name: 'hoge'};
1334 assertPowerAssertContextFormatting(function () {
1335 eval(weave('assert.notDeepEqual([foo, bar, baz], new Array(foo, bar, baz));'));
1336 }, [
1337 ' # test/some_test.js:1',
1338 ' ',
1339 ' assert.notDeepEqual([foo,bar,baz], new Array(foo, bar, baz))',
1340 ' || | | | | | | ',
1341 ' || | | | | | Object{name:"hoge"}',
1342 ' || | | | | ["toto","tata"]',
1343 ' || | | | "foo" ',
1344 ' || | | ["foo",#Array#,#Object#] ',
1345 ' || | Object{name:"hoge"} ',
1346 ' || ["toto","tata"] ',
1347 ' |"foo" ',
1348 ' ["foo",#Array#,#Object#] ',
1349 ' '
1350 ]);
1351 });
1352
1353
1354 test('assert(str1 === str2);', function () {
1355 var str1 = 'abcdef', str2 = 'abcdff';
1356 assertPowerAssertContextFormatting(function () {
1357 eval(weave('assert(str1 === str2);'));
1358 }, [
1359 ' # test/some_test.js:1',
1360 ' ',
1361 ' assert(str1 === str2)',
1362 ' | | | ',
1363 ' | | "abcdff"',
1364 ' | false ',
1365 ' "abcdef" ',
1366 ' ',
1367 ' --- [string] str2',
1368 ' +++ [string] str1',
1369 ' @@ -1,6 +1,6 @@',
1370 ' abcd',
1371 ' -f',
1372 ' +e',
1373 ' f',
1374 ' ',
1375 ' '
1376 ]);
1377 });
1378
1379
1380 test('spockish diff with multibyte characters: assert(str1 === str2);', function () {
1381 var str1 = 'あいうえおかきくけこ', str2 = 'あれうえおかきくげこ';
1382 assertPowerAssertContextFormatting(function () {
1383 eval(weave('assert(str1 === str2);'));
1384 }, [
1385 ' # test/some_test.js:1',
1386 ' ',
1387 ' assert(str1 === str2)',
1388 ' | | | ',
1389 ' | | "あれうえおかきくげこ"',
1390 ' | false ',
1391 ' "あいうえおかきくけこ"',
1392 ' ',
1393 ' --- [string] str2',
1394 ' +++ [string] str1',
1395 ' @@ -1,10 +1,10 @@',
1396 ' あ',
1397 ' -れ',
1398 ' +い',
1399 ' うえおかきく',
1400 ' -げ',
1401 ' +け',
1402 ' こ',
1403 ' ',
1404 ' '
1405 ]);
1406 });
1407
1408
1409 test('spockish diff with literal: assert(str1 === "abcdff");', function () {
1410 var str1 = 'abcdef';
1411 assertPowerAssertContextFormatting(function () {
1412 eval(weave('assert(str1 === "abcdff");'));
1413 }, [
1414 ' # test/some_test.js:1',
1415 ' ',
1416 ' assert(str1 === "abcdff")',
1417 ' | | ',
1418 ' | false ',
1419 ' "abcdef" ',
1420 ' ',
1421 ' --- [string] "abcdff"',
1422 ' +++ [string] str1',
1423 ' @@ -1,6 +1,6 @@',
1424 ' abcd',
1425 ' -f',
1426 ' +e',
1427 ' f',
1428 ' ',
1429 ' '
1430 ]);
1431 });
1432
1433
1434 test('Multi hunk diff', function () {
1435 var longString = 'very very looooooooooo ooooooooooooooooooooooooooooooooooooooooong message';
1436 var anotherLongString = 'yet another looooooooooo oooooooo0000ooooooooooooooooooooooooooooooong massage';
1437 assertPowerAssertContextFormatting(function () {
1438 eval(weave('assert(longString === anotherLongString);'));
1439 }, [
1440 ' # test/some_test.js:1',
1441 ' ',
1442 ' assert(longString === anotherLongString)',
1443 ' | | | ',
1444 ' | | "yet another looooooooooo oooooooo0000ooooooooooooooooooooooooooooooong massage"',
1445 ' | false ',
1446 ' "very very looooooooooo ooooooooooooooooooooooooooooooooooooooooong message"',
1447 ' ',
1448 ' --- [string] anotherLongString',
1449 ' +++ [string] longString',
1450 ' @@ -1,15 +1,13 @@',
1451 ' -yet anoth',
1452 ' +very v',
1453 ' er',
1454 ' +y',
1455 ' loo',
1456 ' @@ -20,20 +20,19 @@',
1457 ' ooo ',
1458 ' + ',
1459 ' oooooooo',
1460 ' -0000',
1461 ' +oo',
1462 ' oooo',
1463 ' @@ -62,14 +62,14 @@',
1464 ' oooong m',
1465 ' -a',
1466 ' +e',
1467 ' ssage',
1468 ' ',
1469 ' '
1470 ]);
1471 });
1472
1473
1474 test('Line level diff', function () {
1475 var html1,html2;
1476
1477 html1 = '<!doctype html>\n';
1478 html1 += '<html>\n';
1479 html1 += '<head>\n';
1480 html1 += ' <title>Example Domain</title>\n';
1481 html1 += '\n';
1482 html1 += ' <meta charset="utf-8" />\n';
1483 html1 += ' <meta http-equiv="Content-type" content="text/html; charset=utf-8" />\n';
1484 html1 += ' <meta name="viewport" content="width=device-width, initial-scale=1" />\n';
1485 html1 += ' <style type="text/css">\n';
1486 html1 += ' body {\n';
1487 html1 += ' background-color: #f0f0f2;\n';
1488 html1 += ' margin: 0;\n';
1489 html1 += ' padding: 0;\n';
1490 html1 += ' font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;\n';
1491 html1 += ' \n';
1492 html1 += ' }\n';
1493 html1 += ' div {\n';
1494 html1 += ' width: 600px;\n';
1495 html1 += ' margin: 5em auto;\n';
1496 html1 += ' padding: 50px;\n';
1497 html1 += ' background-color: #fff;\n';
1498 html1 += ' border-radius: 1em;\n';
1499 html1 += ' }\n';
1500 html1 += ' a:link, a:visited {\n';
1501 html1 += ' color: #38488f;\n';
1502 html1 += ' text-decoration: none;\n';
1503 html1 += ' }\n';
1504 html1 += ' @media (max-width: 700px) {\n';
1505 html1 += ' body {\n';
1506 html1 += ' background-color: #fff;\n';
1507 html1 += ' }\n';
1508 html1 += ' div {\n';
1509 html1 += ' width: auto;\n';
1510 html1 += ' margin: 0 auto;\n';
1511 html1 += ' border-radius: 0;\n';
1512 html1 += ' padding: 1em;\n';
1513 html1 += ' }\n';
1514 html1 += ' }\n';
1515 html1 += ' </style>\n';
1516 html1 += '</head>\n';
1517 html1 += '\n';
1518 html1 += '<body>\n';
1519 html1 += '<div>\n';
1520 html1 += ' <h1>Example Domain</h1>\n';
1521 html1 += ' <p>This domain is established to be used for illustrative examples in documents. You may use this\n';
1522 html1 += ' domain in examples without prior coordination or asking for permission.</p>\n';
1523 html1 += ' <p><a href="http://www.iana.org/domains/example">More information...</a></p>\n';
1524 html1 += '</div>\n';
1525 html1 += '</body>\n';
1526 html1 += '</html>';
1527
1528 html2 = html1.replace(/Example Domain/gm, 'Example Site');
1529
1530 assertPowerAssertContextFormatting(function () {
1531 eval(weave('assert(html1 === html2);'));
1532 }, [
1533 ' # test/some_test.js:1',
1534 ' ',
1535 ' assert(html1 === html2)',
1536 ' | | | ',
1537 ' | | "<!doctype html>\\n<html>\\n<head>\\n <title>Example Site</title>\\n\\n <meta charset=\\"utf-8\\" />\\n <meta http-equiv=\\"Content-type\\" content=\\"text/html; charset=utf-8\\" />\\n <meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\" />\\n <style type=\\"text/css\\">\\n body {\\n background-color: #f0f0f2;\\n margin: 0;\\n padding: 0;\\n font-family: \\"Open Sans\\", \\"Helvetica Neue\\", Helvetica, Arial, sans-serif;\\n \\n }\\n div {\\n width: 600px;\\n margin: 5em auto;\\n padding: 50px;\\n background-color: #fff;\\n border-radius: 1em;\\n }\\n a:link, a:visited {\\n color: #38488f;\\n text-decoration: none;\\n }\\n @media (max-width: 700px) {\\n body {\\n background-color: #fff;\\n }\\n div {\\n width: auto;\\n margin: 0 auto;\\n border-radius: 0;\\n padding: 1em;\\n }\\n }\\n </style>\\n</head>\\n\\n<body>\\n<div>\\n <h1>Example Site</h1>\\n <p>This domain is established to be used for illustrative examples in documents. You may use this\\n domain in examples without prior coordination or asking for permission.</p>\\n <p><a href=\\"http://www.iana.org/domains/example\\">More information...</a></p>\\n</div>\\n</body>\\n</html>"',
1538 ' | false ',
1539 ' "<!doctype html>\\n<html>\\n<head>\\n <title>Example Domain</title>\\n\\n <meta charset=\\"utf-8\\" />\\n <meta http-equiv=\\"Content-type\\" content=\\"text/html; charset=utf-8\\" />\\n <meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1\\" />\\n <style type=\\"text/css\\">\\n body {\\n background-color: #f0f0f2;\\n margin: 0;\\n padding: 0;\\n font-family: \\"Open Sans\\", \\"Helvetica Neue\\", Helvetica, Arial, sans-serif;\\n \\n }\\n div {\\n width: 600px;\\n margin: 5em auto;\\n padding: 50px;\\n background-color: #fff;\\n border-radius: 1em;\\n }\\n a:link, a:visited {\\n color: #38488f;\\n text-decoration: none;\\n }\\n @media (max-width: 700px) {\\n body {\\n background-color: #fff;\\n }\\n div {\\n width: auto;\\n margin: 0 auto;\\n border-radius: 0;\\n padding: 1em;\\n }\\n }\\n </style>\\n</head>\\n\\n<body>\\n<div>\\n <h1>Example Domain</h1>\\n <p>This domain is established to be used for illustrative examples in documents. You may use this\\n domain in examples without prior coordination or asking for permission.</p>\\n <p><a href=\\"http://www.iana.org/domains/example\\">More information...</a></p>\\n</div>\\n</body>\\n</html>"',
1540 ' ',
1541 ' --- [string] html2',
1542 ' +++ [string] html1',
1543 ' @@ -27,40 +27,42 @@',
1544 ' ad>',
1545 ' ',
1546 ' - <title>Example Site</title>',
1547 ' ',
1548 ' + <title>Example Domain</title>',
1549 ' ',
1550 ' ',
1551 ' ',
1552 ' @@ -949,34 +949,36 @@',
1553 ' iv>',
1554 ' ',
1555 ' - <h1>Example Site</h1>',
1556 ' ',
1557 ' + <h1>Example Domain</h1>',
1558 ' ',
1559 ' ',
1560 ' ',
1561 ' '
1562 ]);
1563 });
1564
1565
1566
1567 suite('Wrapper objects', function () {
1568
1569 test('String object loose equality', function () {
1570 var orig = 'abcdef', str1 = new String(orig), str2 = new String(orig);
1571 assertPowerAssertContextFormatting(function () {
1572 eval(weave('assert(str1 == str2);'));
1573 }, [
1574 ' # test/some_test.js:1',
1575 ' ',
1576 ' assert(str1 == str2)',
1577 ' | | | ',
1578 ' | | new String("abcdef")',
1579 ' | false ',
1580 ' new String("abcdef")',
1581 ' ',
1582 ' [String] str2',
1583 ' => new String("abcdef")',
1584 ' [String] str1',
1585 ' => new String("abcdef")',
1586 ' '
1587 ]);
1588 });
1589
1590 test('Number object loose equality', function () {
1591 var eightStr = '8', num1 = new Number(eightStr);
1592 assertPowerAssertContextFormatting(function () {
1593 eval(weave('assert(num1 == new Number(eightStr));'));
1594 }, [
1595 ' # test/some_test.js:1',
1596 ' ',
1597 ' assert(num1 == new Number(eightStr))',
1598 ' | | | | ',
1599 ' | | | "8" ',
1600 ' | | new Number(8) ',
1601 ' | false ',
1602 ' new Number(8) ',
1603 ' ',
1604 ' [Number] new Number(eightStr)',
1605 ' => new Number(8)',
1606 ' [Number] num1',
1607 ' => new Number(8)',
1608 ' '
1609 ]);
1610 });
1611
1612 test('Boolean object loose equality', function () {
1613 var oneStr = '1', bool1 = new Boolean(oneStr);
1614 assertPowerAssertContextFormatting(function () {
1615 eval(weave('assert(bool1 == new Boolean(oneStr));'));
1616 }, [
1617 ' # test/some_test.js:1',
1618 ' ',
1619 ' assert(bool1 == new Boolean(oneStr))',
1620 ' | | | | ',
1621 ' | | | "1" ',
1622 ' | | new Boolean(true) ',
1623 ' | false ',
1624 ' new Boolean(true) ',
1625 ' ',
1626 ' [Boolean] new Boolean(oneStr)',
1627 ' => new Boolean(true)',
1628 ' [Boolean] bool1',
1629 ' => new Boolean(true)',
1630 ' '
1631 ]);
1632 });
1633
1634 test('Date object loose equality', function () {
1635 var dateStr = '1990-01-01';
1636 var dateObj = new Date(dateStr);
1637 assertPowerAssertContextFormatting(function () {
1638 eval(weave('assert(dateObj == dateStr);'));
1639 }, [
1640 ' # test/some_test.js:1',
1641 ' ',
1642 ' assert(dateObj == dateStr)',
1643 ' | | | ',
1644 ' | | "1990-01-01"',
1645 ' | false ',
1646 ' new Date("1990-01-01T00:00:00.000Z")',
1647 ' ',
1648 ' [string] dateStr',
1649 ' => "1990-01-01"',
1650 ' [Date] dateObj',
1651 ' => new Date("1990-01-01T00:00:00.000Z")',
1652 ' '
1653 ]);
1654 });
1655
1656 test('Date object strict equality', function () {
1657 var dateStr = '1990-01-01';
1658 var dateObj = new Date(dateStr);
1659 assertPowerAssertContextFormatting(function () {
1660 eval(weave('assert(dateObj === dateStr);'));
1661 }, [
1662 ' # test/some_test.js:1',
1663 ' ',
1664 ' assert(dateObj === dateStr)',
1665 ' | | | ',
1666 ' | | "1990-01-01"',
1667 ' | false ',
1668 ' new Date("1990-01-01T00:00:00.000Z")',
1669 ' ',
1670 ' [string] dateStr',
1671 ' => "1990-01-01"',
1672 ' [Date] dateObj',
1673 ' => new Date("1990-01-01T00:00:00.000Z")',
1674 ' '
1675 ]);
1676 });
1677
1678 test('RegExp object loose equality', function () {
1679 var pattern = '^not', flag = 'g', re = /^not/g;
1680 assertPowerAssertContextFormatting(function () {
1681 eval(weave('assert(re == new RegExp(pattern, flag));'));
1682 }, [
1683 ' # test/some_test.js:1',
1684 ' ',
1685 ' assert(re == new RegExp(pattern, flag))',
1686 ' | | | | | ',
1687 ' | | /^not/g "^not" "g" ',
1688 ' | false ',
1689 ' /^not/g ',
1690 ' ',
1691 ' [RegExp] new RegExp(pattern, flag)',
1692 ' => /^not/g',
1693 ' [RegExp] re',
1694 ' => /^not/g',
1695 ' '
1696 ]);
1697 });
1698
1699 test('RegExp literal and object loose equality', function () {
1700 var pattern = '^not', flag = 'g', re = /^not/g;
1701 assertPowerAssertContextFormatting(function () {
1702 eval(weave('assert(/^not/g == new RegExp(pattern, flag));'));
1703 }, [
1704 ' # test/some_test.js:1',
1705 ' ',
1706 ' assert(/^not/g == new RegExp(pattern, flag))',
1707 ' | | | | ',
1708 ' | /^not/g "^not" "g" ',
1709 ' false ',
1710 ' ',
1711 ' [RegExp] new RegExp(pattern, flag)',
1712 ' => /^not/g',
1713 ' [RegExp] /^not/g',
1714 ' => /^not/g',
1715 ' '
1716 ]);
1717 });
1718
1719 test('Function object equality', function () {
1720 assertPowerAssertContextFormatting(function () {
1721 eval(weave('assert(function(x,y){ return x + y; } == new Function("x", "y", "return x + y"));'));
1722 }, [
1723 ' # test/some_test.js:1',
1724 ' ',
1725 ' assert(function (x, y) {return x + y;} == new Function("x", "y", "return x + y"))',
1726 ' | | ',
1727 ' | #function# ',
1728 ' false ',
1729 ' '
1730 ]);
1731 });
1732
1733 });
1734
1735
1736 suite('User-defined class', function () {
1737
1738 test('assert(alice === bob);', function () {
1739 function Person(name, age) {
1740 this.name = name;
1741 this.age = age;
1742 }
1743 var alice = new Person('alice', 3), bob = new Person('bob', 4);
1744 assertPowerAssertContextFormatting(function () {
1745 eval(weave('assert(alice === bob);'));
1746 }, [
1747 ' # test/some_test.js:1',
1748 ' ',
1749 ' assert(alice === bob)',
1750 ' | | | ',
1751 ' | | Person{name:"bob",age:4}',
1752 ' | false ',
1753 ' Person{name:"alice",age:3}',
1754 ' ',
1755 ' [Person] bob',
1756 ' => Person{name:"bob",age:4}',
1757 ' [Person] alice',
1758 ' => Person{name:"alice",age:3}',
1759 ' '
1760 ]);
1761 });
1762
1763 test('assert(alice.age === bob.age);', function () {
1764 function Person(name, age) {
1765 this.name = name;
1766 this.age = age;
1767 }
1768 var alice = new Person('alice', 3), bob = new Person('bob', 4);
1769 assertPowerAssertContextFormatting(function () {
1770 eval(weave('assert(alice.age === bob.age);'));
1771 }, [
1772 ' # test/some_test.js:1',
1773 ' ',
1774 ' assert(alice.age === bob.age)',
1775 ' | | | | | ',
1776 ' | | | | 4 ',
1777 ' | | | Person{name:"bob",age:4}',
1778 ' | 3 false ',
1779 ' Person{name:"alice",age:3}',
1780 ' ',
1781 ' [number] bob.age',
1782 ' => 4',
1783 ' [number] alice.age',
1784 ' => 3',
1785 ' '
1786 ]);
1787 });
1788
1789 test('assert.deepEqual(alice, new Person(kenName, four));', function () {
1790 function Person(name, age) {
1791 this.name = name;
1792 this.age = age;
1793 }
1794 var alice = new Person('alice', 3), kenName = 'ken', four = 4;
1795 assertPowerAssertContextFormatting(function () {
1796 eval(weave('assert.deepEqual(alice, new Person(kenName, four));'));
1797 }, [
1798 ' # test/some_test.js:1',
1799 ' ',
1800 ' assert.deepEqual(alice, new Person(kenName, four))',
1801 ' | | | | ',
1802 ' | | "ken" 4 ',
1803 ' | Person{name:"ken",age:4} ',
1804 ' Person{name:"alice",age:3} ',
1805 ' '
1806 ]);
1807 });
1808
1809 test('anonymous class: assert.deepEqual(alice, new Person(kenName, four));', function () {
1810 var Person = function(name, age) {
1811 this.name = name;
1812 this.age = age;
1813 };
1814 var alice = new Person('alice', 3), kenName = 'ken', four = 4;
1815 assertPowerAssertContextFormatting(function () {
1816 eval(weave('assert.deepEqual(alice, new Person(kenName, four));'));
1817 }, [
1818 ' # test/some_test.js:1',
1819 ' ',
1820 ' assert.deepEqual(alice, new Person(kenName, four))',
1821 ' | | | | ',
1822 ' | | "ken" 4 ',
1823 ' | Object{name:"ken",age:4} ',
1824 ' Object{name:"alice",age:3} ',
1825 ' '
1826 ]);
1827 });
1828
1829 test('User-defined class with Date member: assert.deepEqual(alice, bob);', function () {
1830 function Person(name, birthday) {
1831 this.name = name;
1832 this.birthday = birthday;
1833 }
1834 var alice = new Person('alice', new Date('1990-01-01'));
1835 var bob = new Person('bob', new Date('1985-04-01'));
1836 assertPowerAssertContextFormatting(function () {
1837 eval(weave('assert.deepEqual(alice, bob);'));
1838 }, [
1839 ' # test/some_test.js:1',
1840 ' ',
1841 ' assert.deepEqual(alice, bob)',
1842 ' | | ',
1843 ' | Person{name:"bob",birthday:new Date("1985-04-01T00:00:00.000Z")}',
1844 ' Person{name:"alice",birthday:new Date("1990-01-01T00:00:00.000Z")}',
1845 ' '
1846 ]);
1847 });
1848
1849 test('User-defined class with user-defined member: assert.deepEqual(session1, session2);', function () {
1850 function PairProgramming(driver, navigator) {
1851 this.driver = driver;
1852 this.navigator = navigator;
1853 }
1854 function Person(name, age) {
1855 this.name = name;
1856 this.age = age;
1857 }
1858 var alice = new Person('alice', 3);
1859 var ken = new Person('ken', 4);
1860 var session1 = new PairProgramming(alice, ken);
1861 var session2 = new PairProgramming(ken, alice);
1862 assertPowerAssertContextFormatting(function () {
1863 eval(weave('assert.deepEqual(session1, session2);'));
1864 }, [
1865 ' # test/some_test.js:1',
1866 ' ',
1867 ' assert.deepEqual(session1, session2)',
1868 ' | | ',
1869 ' | PairProgramming{driver:#Person#,navigator:#Person#}',
1870 ' PairProgramming{driver:#Person#,navigator:#Person#}',
1871 ' '
1872 ]);
1873 });
1874
1875 test('User-defined class with user-defined member: assert.deepEqual(new PairProgramming(alice, ken), new PairProgramming(ken, alice));', function () {
1876 function PairProgramming(driver, navigator) {
1877 this.driver = driver;
1878 this.navigator = navigator;
1879 }
1880 function Person(name, age) {
1881 this.name = name;
1882 this.age = age;
1883 }
1884 var alice = new Person('alice', 3);
1885 var ken = new Person('ken', 4);
1886 assertPowerAssertContextFormatting(function () {
1887 eval(weave('assert.deepEqual(new PairProgramming(alice, ken), new PairProgramming(ken, alice));'));
1888 }, [
1889 ' # test/some_test.js:1',
1890 ' ',
1891 ' assert.deepEqual(new PairProgramming(alice, ken), new PairProgramming(ken, alice))',
1892 ' | | | | | | ',
1893 ' | | | | | Person{name:"alice",age:3}',
1894 ' | | | | Person{name:"ken",age:4}',
1895 ' | | | PairProgramming{driver:#Person#,navigator:#Person#}',
1896 ' | | Person{name:"ken",age:4} ',
1897 ' | Person{name:"alice",age:3} ',
1898 ' PairProgramming{driver:#Person#,navigator:#Person#} ',
1899 ' '
1900 ]);
1901 });
1902
1903 });
1904
1905});
1906
1907}));