negative.js 556 B

123456789101112131415161718192021
  1. var Traverse = require('traverse');
  2. var assert = require('assert');
  3. exports['negative update test'] = function () {
  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. assert.deepEqual(fixed,
  9. [ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ],
  10. 'Negative values += 128'
  11. );
  12. assert.deepEqual(obj,
  13. [ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ],
  14. 'Original references not modified'
  15. );
  16. }