source: node_modules/traverse/test/subexpr.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 719 bytes
Line 
1'use strict';
2
3var traverse = require('../');
4var test = require('tape');
5
6test('subexpr', function (t) {
7 var obj = ['a', 4, 'b', 5, 'c', 6];
8 var r = traverse(obj).map(function (x) {
9 if (typeof x === 'number') {
10 this.update([x - 0.1, x, x + 0.1], true);
11 }
12 });
13
14 t.same(obj, ['a', 4, 'b', 5, 'c', 6]);
15 t.same(r, [
16 'a', [3.9, 4, 4.1],
17 'b', [4.9, 5, 5.1],
18 'c', [5.9, 6, 6.1],
19 ]);
20 t.end();
21});
22
23test('block', function (t) {
24 var obj = [[1], [2], [3]];
25 var r = traverse(obj).map(function (x) {
26 if (Array.isArray(x) && !this.isRoot) {
27 if (x[0] === 5) {
28 this.block();
29 } else {
30 this.update([[x[0] + 1]]);
31 }
32 }
33 });
34
35 t.same(r, [
36 [[[[[5]]]]],
37 [[[[5]]]],
38 [[[5]]],
39 ]);
40 t.end();
41});
Note: See TracBrowser for help on using the repository browser.