leaves.js 433 B

12345678910111213141516171819202122
  1. var assert = require('assert');
  2. var Traverse = require('traverse');
  3. exports['leaves test'] = function () {
  4. var acc = [];
  5. Traverse({
  6. a : [1,2,3],
  7. b : 4,
  8. c : [5,6],
  9. d : { e : [7,8], f : 9 }
  10. }).forEach(function (x) {
  11. if (this.isLeaf) acc.push(x);
  12. });
  13. assert.equal(
  14. acc.join(' '),
  15. '1 2 3 4 5 6 7 8 9',
  16. 'Traversal in the right(?) order'
  17. );
  18. };