index.js
849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var test = require('tape')
var src = require('fs').readFileSync(require.resolve('acorn'))
var parse = require('acorn').parse
var dash = require('../')
var NUM_NODES = 25426
test('dash-ast', function (t) {
var ast = parse(src)
var i = 0
dash(ast, function (node) { i++ })
t.equal(i, NUM_NODES)
t.comment('walked ' + i + ' nodes')
t.end()
})
test('dash-ast with .parent', function (t) {
var ast = parse(src)
var i = 0
dash.withParent(ast, function (node) { i++ })
t.equal(i, NUM_NODES)
t.comment('walked ' + i + ' nodes')
t.end()
})
test('dash-ast with enter/leave', function (t) {
var ast = parse(src)
var i = 0
var j = 0
dash(ast, {
enter: function (node) { i++ },
leave: function (node) { j++ }
})
t.equal(i, NUM_NODES)
t.equal(j, NUM_NODES)
t.comment('walked ' + [i, j] + ' nodes')
t.end()
})