negative.js 542 B

123456789101112131415161718192021
  1. var traverse = require('../');
  2. var test = require('tape');
  3. test('negative update test', function (t) {
  4. var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];
  5. var fixed = traverse.map(obj, function (x) {
  6. if (x < 0) this.update(x + 128);
  7. });
  8. t.same(fixed,
  9. [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ],
  10. 'Negative values += 128'
  11. );
  12. t.same(obj,
  13. [ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ],
  14. 'Original references not modified'
  15. );
  16. t.end();
  17. });