2
2
3
3
var test = require ( 'tape' )
4
4
var u = require ( 'unist-builder' )
5
- var select = require ( 'unist-util-select' )
5
+ var select = require ( 'unist-util-select' ) . select
6
6
var Index = require ( '.' )
7
7
8
8
var index = Index
@@ -93,21 +93,20 @@ test('Index', function(t) {
93
93
test ( 'index.add' , function ( t ) {
94
94
var ast = u ( 'root' , [ u ( 'node' , { word : 'foo' } ) , u ( 'node' , { word : 'bar' } ) ] )
95
95
var extraNode = u ( 'node' , { word : 'foo' } )
96
- var $ = select . one ( ast )
97
96
98
97
var index = new Index ( ast , 'word' )
99
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( '[word=foo]' ) ] )
98
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) ] )
100
99
101
100
var result = index . add ( extraNode )
102
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( '[word=foo]' ) , extraNode ] )
101
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) , extraNode ] )
103
102
104
103
t . equal ( result , index , 'returns this' )
105
104
106
- index . add ( $ ( '[word=foo]' ) )
107
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( '[word=foo]' ) , extraNode ] )
105
+ index . add ( select ( '[word=foo]' , ast ) )
106
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) , extraNode ] )
108
107
109
108
index . add ( extraNode )
110
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( '[word=foo]' ) , extraNode ] )
109
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) , extraNode ] )
111
110
112
111
t . end ( )
113
112
} )
@@ -136,26 +135,29 @@ test('index.get', function(t) {
136
135
] )
137
136
] )
138
137
] )
139
- var $ = select . one ( ast )
140
138
141
139
var index = new Index ( ast , 'color' )
142
140
143
141
st . deepEqual ( index . get ( 'black' ) , [
144
- $ ( '[id=0]' ) ,
145
- $ ( '[id=1]' ) ,
146
- $ ( '[id=3]' ) ,
147
- $ ( '[id=4]' ) ,
148
- $ ( '[id=5]' ) ,
149
- $ ( '[id=7]' ) ,
150
- $ ( '[id=8]' ) ,
151
- $ ( '[id=9]' ) ,
152
- $ ( '[id=10]' ) ,
153
- $ ( '[id=12]' ) ,
154
- $ ( '[id=13]' ) ,
155
- $ ( '[id=14]' )
142
+ select ( '[id=0]' , ast ) ,
143
+ select ( '[id=1]' , ast ) ,
144
+ select ( '[id=3]' , ast ) ,
145
+ select ( '[id=4]' , ast ) ,
146
+ select ( '[id=5]' , ast ) ,
147
+ select ( '[id=7]' , ast ) ,
148
+ select ( '[id=8]' , ast ) ,
149
+ select ( '[id=9]' , ast ) ,
150
+ select ( '[id=10]' , ast ) ,
151
+ select ( '[id=12]' , ast ) ,
152
+ select ( '[id=13]' , ast ) ,
153
+ select ( '[id=14]' , ast )
156
154
] )
157
155
158
- st . deepEqual ( index . get ( 'red' ) , [ $ ( '[id=2]' ) , $ ( '[id=6]' ) , $ ( '[id=11]' ) ] )
156
+ st . deepEqual ( index . get ( 'red' ) , [
157
+ select ( '[id=2]' , ast ) ,
158
+ select ( '[id=6]' , ast ) ,
159
+ select ( '[id=11]' , ast )
160
+ ] )
159
161
160
162
st . deepEqual ( index . get ( 'yellow' ) , [ ] )
161
163
@@ -168,12 +170,11 @@ test('index.get', function(t) {
168
170
u ( 'node' , { word : 'constructor' , id : 1 } ) ,
169
171
u ( 'node' , { word : 'toString' , id : 2 } )
170
172
] )
171
- var $$ = select ( ast )
172
173
var index = new Index ( ast , 'word' )
173
174
174
- sst . deepEqual ( index . get ( '__proto__' ) , $$ ( '[id=0]' ) )
175
- sst . deepEqual ( index . get ( 'constructor' ) , $$ ( '[id=1]' ) )
176
- sst . deepEqual ( index . get ( 'toString' ) , $$ ( '[id=2]' ) )
175
+ sst . deepEqual ( index . get ( '__proto__' ) , [ select ( '[id=0]' , ast ) ] )
176
+ sst . deepEqual ( index . get ( 'constructor' ) , [ select ( '[id=1]' , ast ) ] )
177
+ sst . deepEqual ( index . get ( 'toString' ) , [ select ( '[id=2]' , ast ) ] )
177
178
sst . end ( )
178
179
} )
179
180
@@ -188,15 +189,14 @@ test('index.get', function(t) {
188
189
u ( 'node' , { word : id1 , id : 4 } ) ,
189
190
u ( 'node' , { word : id2 , id : 5 } )
190
191
] )
191
- var $$ = select ( ast )
192
192
var index = new Index ( ast , 'word' )
193
193
194
- sst . deepEqual ( index . get ( false ) , $$ ( '[id=0]' ) )
195
- sst . deepEqual ( index . get ( 'false' ) , $$ ( '[id=1]' ) )
196
- sst . deepEqual ( index . get ( 1 ) , $$ ( '[id=2]' ) )
197
- sst . deepEqual ( index . get ( '1' ) , $$ ( '[id=3]' ) )
198
- sst . deepEqual ( index . get ( id1 ) , $$ ( '[id=4]' ) )
199
- sst . deepEqual ( index . get ( id2 ) , $$ ( '[id=5]' ) )
194
+ sst . deepEqual ( index . get ( false ) , [ select ( '[id=0]' , ast ) ] )
195
+ sst . deepEqual ( index . get ( 'false' ) , [ select ( '[id=1]' , ast ) ] )
196
+ sst . deepEqual ( index . get ( 1 ) , [ select ( '[id=2]' , ast ) ] )
197
+ sst . deepEqual ( index . get ( '1' ) , [ select ( '[id=3]' , ast ) ] )
198
+ sst . deepEqual ( index . get ( id1 ) , [ select ( '[id=4]' , ast ) ] )
199
+ sst . deepEqual ( index . get ( id2 ) , [ select ( '[id=5]' , ast ) ] )
200
200
sst . deepEqual ( index . get ( { foo : 'bar' } ) , [ ] )
201
201
sst . end ( )
202
202
} )
@@ -217,19 +217,18 @@ test('index.get', function(t) {
217
217
u ( 'skip' , { word : 'foo' } ) ,
218
218
u ( 'skip' , { word : 'bar' } )
219
219
] )
220
- var $$ = select ( ast )
221
220
222
221
st . test ( 'type test' , function ( sst ) {
223
222
var index = new Index ( ast , 'node' , 'word' )
224
- sst . deepEqual ( index . get ( 'foo' ) , $$ ( 'node[word="foo"]' ) )
225
- sst . deepEqual ( index . get ( 'bar' ) , $$ ( 'node[word="bar"]' ) )
223
+ sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
224
+ sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
226
225
sst . end ( )
227
226
} )
228
227
229
228
st . test ( 'function test' , function ( sst ) {
230
229
var index = new Index ( ast , filter , 'word' )
231
- sst . deepEqual ( index . get ( 'foo' ) , $$ ( 'node[word="foo"]' ) )
232
- sst . deepEqual ( index . get ( 'bar' ) , $$ ( 'node[word="bar"]' ) )
230
+ sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
231
+ sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
233
232
sst . end ( )
234
233
235
234
function filter ( node , index , parent ) {
@@ -247,17 +246,20 @@ test('index.get', function(t) {
247
246
u ( 'node' , { x : 3 , y : 1 , id : 3 } ) ,
248
247
u ( 'node' , { x : 4 , y : 1 , id : 4 } )
249
248
] )
250
- var $ = select . one ( ast )
251
249
var index
252
250
253
251
index = new Index ( ast , xPlusY )
254
- st . deepEqual ( index . get ( 4 ) , [ $ ( '[id=0]' ) , $ ( '[id=2]' ) , $ ( '[id=3]' ) ] )
252
+ st . deepEqual ( index . get ( 4 ) , [
253
+ select ( '[id=0]' , ast ) ,
254
+ select ( '[id=2]' , ast ) ,
255
+ select ( '[id=3]' , ast )
256
+ ] )
255
257
st . deepEqual ( index . get ( 0 ) , [ ] )
256
- st . deepEqual ( index . get ( 5 ) , [ $ ( '[id=1]' ) , $ ( '[id=4]' ) ] )
258
+ st . deepEqual ( index . get ( 5 ) , [ select ( '[id=1]' , ast ) , select ( '[id=4]' , ast ) ] )
257
259
258
260
st . deepEqual ( new Index ( ast , 'node' , xPlusY ) . get ( 4 ) , [
259
- $ ( '[id=2]' ) ,
260
- $ ( '[id=3]' )
261
+ select ( '[id=2]' , ast ) ,
262
+ select ( '[id=3]' , ast )
261
263
] )
262
264
263
265
st . end ( )
@@ -276,23 +278,25 @@ test('index.remove', function(t) {
276
278
u ( 'node' , { word : 'foo' } ) ,
277
279
u ( 'node' , { word : 'bar' } )
278
280
] )
279
- var $ = select . one ( ast )
280
281
281
282
var index = new Index ( ast , 'word' )
282
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( 'bad[word=foo]' ) , $ ( 'node[word=foo]' ) ] )
283
+ t . deepEqual ( index . get ( 'foo' ) , [
284
+ select ( 'bad[word=foo]' , ast ) ,
285
+ select ( 'node[word=foo]' , ast )
286
+ ] )
283
287
284
- var result = index . remove ( $ ( 'bad' ) )
285
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( 'node[word=foo]' ) ] )
288
+ var result = index . remove ( select ( 'bad' , ast ) )
289
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word=foo]' , ast ) ] )
286
290
287
291
t . equal ( result , index , 'returns this' )
288
292
289
- index . remove ( $ ( 'bad' ) )
290
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( 'node[word=foo]' ) ] )
293
+ index . remove ( select ( 'bad' , ast ) )
294
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word=foo]' , ast ) ] )
291
295
292
296
index . remove ( u ( 'terrible' , { word : 'baz' } ) )
293
- t . deepEqual ( index . get ( 'foo' ) , [ $ ( 'node[word=foo]' ) ] )
297
+ t . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word=foo]' , ast ) ] )
294
298
295
- index . remove ( $ ( 'node[word=foo]' ) )
299
+ index . remove ( select ( 'node[word=foo]' , ast ) )
296
300
t . deepEqual ( index . get ( 'foo' ) , [ ] )
297
301
298
302
t . end ( )
0 commit comments