UNPKG

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