nested.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. var tc = function (rows) {
  10. tt.same(rows.toString('utf8'), [
  11. 'TAP version 13',
  12. '# nested array test',
  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. '# inside test',
  19. 'ok 6 should be truthy',
  20. 'ok 7 should be truthy',
  21. '# another',
  22. 'ok 8 should be truthy',
  23. '',
  24. '1..8',
  25. '# tests 8',
  26. '# pass 8',
  27. '',
  28. '# ok'
  29. ].join('\n') + '\n');
  30. };
  31. test.createStream().pipe(concat(tc));
  32. test('nested array test', function (t) {
  33. t.plan(6);
  34. var src = '(' + function () {
  35. var xs = [1, 2, [3, 4]];
  36. var ys = [5, 6];
  37. g([xs, ys]);
  38. } + ')()';
  39. var output = falafel(src, function (node) {
  40. if (node.type === 'ArrayExpression') {
  41. node.update('fn(' + node.source() + ')');
  42. }
  43. });
  44. t.test('inside test', function (q) {
  45. q.plan(2);
  46. q.ok(true);
  47. setTimeout(function () {
  48. q.ok(true);
  49. }, 100);
  50. });
  51. var arrays = [
  52. [3, 4],
  53. [1, 2, [3, 4]],
  54. [5, 6],
  55. [[1, 2, [3, 4]], [5, 6]]
  56. ];
  57. Function(['fn', 'g'], output)(
  58. function (xs) {
  59. t.same(arrays.shift(), xs);
  60. return xs;
  61. },
  62. function (xs) {
  63. t.same(xs, [[1, 2, [3, 4]], [5, 6]]);
  64. }
  65. );
  66. });
  67. test('another', function (t) {
  68. t.plan(1);
  69. setTimeout(function () {
  70. t.ok(true);
  71. }, 50);
  72. });
  73. });