array.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. 'use strict';
  2. var falafel = require('falafel');
  3. var tape = require('../');
  4. var tap = require('tap');
  5. var concat = require('concat-stream');
  6. tap.test('array test', function (tt) {
  7. tt.plan(1);
  8. var test = tape.createHarness();
  9. test.createStream().pipe(concat(function (rows) {
  10. tt.same(rows.toString('utf8'), [
  11. 'TAP version 13',
  12. '# array',
  13. 'ok 1 should be equivalent',
  14. 'ok 2 should be equivalent',
  15. 'ok 3 should be equivalent',
  16. 'ok 4 should be equivalent',
  17. 'ok 5 should be equivalent',
  18. '',
  19. '1..5',
  20. '# tests 5',
  21. '# pass 5',
  22. '',
  23. '# ok'
  24. ].join('\n') + '\n');
  25. }));
  26. test('array', function (t) {
  27. t.plan(5);
  28. var src = '(' + function () {
  29. var xs = [1, 2, [3, 4]];
  30. var ys = [5, 6];
  31. g([xs, ys]);
  32. } + ')()';
  33. var output = falafel(src, function (node) {
  34. if (node.type === 'ArrayExpression') {
  35. node.update('fn(' + node.source() + ')');
  36. }
  37. });
  38. var arrays = [
  39. [3, 4],
  40. [1, 2, [3, 4]],
  41. [5, 6],
  42. [[1, 2, [3, 4]], [5, 6]]
  43. ];
  44. Function(['fn', 'g'], output)(
  45. function (xs) {
  46. t.same(arrays.shift(), xs);
  47. return xs;
  48. },
  49. function (xs) {
  50. t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
  51. }
  52. );
  53. });
  54. });