fail.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. 'use strict';
  2. var falafel = require('falafel');
  3. var tape = require('../');
  4. var tap = require('tap');
  5. var concat = require('concat-stream');
  6. var stripFullStack = require('./common').stripFullStack;
  7. tap.test('array test', function (tt) {
  8. tt.plan(1);
  9. var test = tape.createHarness({ exit: false });
  10. var tc = function (rows) {
  11. tt.same(stripFullStack(rows.toString('utf8')), [
  12. 'TAP version 13',
  13. '# array',
  14. 'ok 1 should be equivalent',
  15. 'ok 2 should be equivalent',
  16. 'ok 3 should be equivalent',
  17. 'ok 4 should be equivalent',
  18. 'not ok 5 should be equivalent',
  19. ' ---',
  20. ' operator: deepEqual',
  21. ' expected: [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]',
  22. ' actual: [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ]',
  23. ' at: <anonymous> ($TEST/fail.js:$LINE:$COL)',
  24. ' stack: |-',
  25. ' Error: should be equivalent',
  26. ' [... stack stripped ...]',
  27. ' at $TEST/fail.js:$LINE:$COL',
  28. ' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
  29. ' at eval (eval at <anonymous> ($TEST/fail.js:$LINE:$COL))',
  30. ' at Test.<anonymous> ($TEST/fail.js:$LINE:$COL)',
  31. ' [... stack stripped ...]',
  32. ' ...',
  33. '',
  34. '1..5',
  35. '# tests 5',
  36. '# pass 4',
  37. '# fail 1',
  38. ''
  39. ]);
  40. };
  41. test.createStream().pipe(concat(tc));
  42. test('array', function (t) {
  43. t.plan(5);
  44. var src = '(' + function () {
  45. var xs = [1, 2, [3, 4]];
  46. var ys = [5, 6];
  47. g([xs, ys]);
  48. } + ')()';
  49. var output = falafel(src, function (node) {
  50. if (node.type === 'ArrayExpression') {
  51. node.update('fn(' + node.source() + ')');
  52. }
  53. });
  54. var arrays = [
  55. [3, 4],
  56. [1, 2, [3, 4]],
  57. [5, 6],
  58. [[1, 2, [3, 4]], [5, 6]]
  59. ];
  60. Function(['fn', 'g'], output)(
  61. function (xs) {
  62. t.same(arrays.shift(), xs);
  63. return xs;
  64. },
  65. function (xs) {
  66. t.same(xs, [[1, 2, [3, 4444]], [5, 6]]);
  67. }
  68. );
  69. });
  70. });