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