@@ -9,11 +9,11 @@ import {u} from 'unist-builder'
9
9
import { select } from 'unist-util-select'
10
10
import { Index } from './index.js'
11
11
12
- test ( 'Index' , function ( t ) {
13
- var node = { type : 'a' , id : 1 }
14
- var alt = { type : 'b' , id : 1 }
15
- var tree = { type : 'root' , children : [ node , alt ] }
16
- var instance = new Index ( 'id' )
12
+ test ( 'Index' , ( t ) => {
13
+ const node = { type : 'a' , id : 1 }
14
+ const alt = { type : 'b' , id : 1 }
15
+ const tree = { type : 'root' , children : [ node , alt ] }
16
+ let instance = new Index ( 'id' )
17
17
instance . add ( node )
18
18
19
19
t . deepEqual (
@@ -55,14 +55,14 @@ test('Index', function (t) {
55
55
t . end ( )
56
56
} )
57
57
58
- test ( 'index.add' , function ( t ) {
59
- var ast = u ( 'root' , [ u ( 'node' , { word : 'foo' } ) , u ( 'node' , { word : 'bar' } ) ] )
60
- var extraNode = u ( 'node' , { word : 'foo' } )
58
+ test ( 'index.add' , ( t ) => {
59
+ const ast = u ( 'root' , [ u ( 'node' , { word : 'foo' } ) , u ( 'node' , { word : 'bar' } ) ] )
60
+ const extraNode = u ( 'node' , { word : 'foo' } )
61
61
62
- var index = new Index ( 'word' , ast )
62
+ const index = new Index ( 'word' , ast )
63
63
t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) ] )
64
64
65
- var result = index . add ( extraNode )
65
+ const result = index . add ( extraNode )
66
66
t . deepEqual ( index . get ( 'foo' ) , [ select ( '[word=foo]' , ast ) , extraNode ] )
67
67
68
68
t . equal ( result , index , 'returns this' )
@@ -76,9 +76,9 @@ test('index.add', function (t) {
76
76
t . end ( )
77
77
} )
78
78
79
- test ( 'index.get' , function ( t ) {
80
- t . test ( 'get' , function ( st ) {
81
- var ast = u ( 'node' , { color : 'black' , id : 0 } , [
79
+ test ( 'index.get' , ( t ) => {
80
+ t . test ( 'get' , ( st ) => {
81
+ const ast = u ( 'node' , { color : 'black' , id : 0 } , [
82
82
u ( 'node' , { color : 'black' , id : 1 } , [
83
83
u ( 'node' , { color : 'red' , id : 2 } , [
84
84
u ( 'node' , { color : 'black' , id : 3 } ) ,
@@ -101,7 +101,7 @@ test('index.get', function (t) {
101
101
] )
102
102
] )
103
103
104
- var index = new Index ( 'color' , ast )
104
+ const index = new Index ( 'color' , ast )
105
105
106
106
st . deepEqual ( index . get ( 'black' ) , [
107
107
select ( '[id=0]' , ast ) ,
@@ -129,32 +129,32 @@ test('index.get', function (t) {
129
129
st . end ( )
130
130
} )
131
131
132
- t . test ( 'degenerate keys' , function ( st ) {
133
- st . test ( 'Object.prototype keys' , function ( sst ) {
134
- var ast = u ( 'node' , { word : '__proto__' , id : 0 } , [
132
+ t . test ( 'degenerate keys' , ( st ) => {
133
+ st . test ( 'Object.prototype keys' , ( sst ) => {
134
+ const ast = u ( 'node' , { word : '__proto__' , id : 0 } , [
135
135
u ( 'node' , { word : 'constructor' , id : 1 } ) ,
136
136
u ( 'node' , { word : 'toString' , id : 2 } )
137
137
] )
138
- var index = new Index ( 'word' , ast )
138
+ const index = new Index ( 'word' , ast )
139
139
140
140
sst . deepEqual ( index . get ( '__proto__' ) , [ select ( '[id=0]' , ast ) ] )
141
141
sst . deepEqual ( index . get ( 'constructor' ) , [ select ( '[id=1]' , ast ) ] )
142
142
sst . deepEqual ( index . get ( 'toString' ) , [ select ( '[id=2]' , ast ) ] )
143
143
sst . end ( )
144
144
} )
145
145
146
- st . test ( 'identity keys' , function ( sst ) {
147
- var id1 = { foo : 'bar' }
148
- var id2 = { foo : 'bar' }
149
- var ast = u ( 'root' , [
146
+ st . test ( 'identity keys' , ( sst ) => {
147
+ const id1 = { foo : 'bar' }
148
+ const id2 = { foo : 'bar' }
149
+ const ast = u ( 'root' , [
150
150
u ( 'node' , { word : false , id : 0 } ) ,
151
151
u ( 'node' , { word : 'false' , id : 1 } ) ,
152
152
u ( 'node' , { word : 1 , id : 2 } ) ,
153
153
u ( 'node' , { word : '1' , id : 3 } ) ,
154
154
u ( 'node' , { word : id1 , id : 4 } ) ,
155
155
u ( 'node' , { word : id2 , id : 5 } )
156
156
] )
157
- var index = new Index ( 'word' , ast )
157
+ const index = new Index ( 'word' , ast )
158
158
159
159
sst . deepEqual ( index . get ( false ) , [ select ( '[id=0]' , ast ) ] )
160
160
sst . deepEqual ( index . get ( 'false' ) , [ select ( '[id=1]' , ast ) ] )
@@ -169,29 +169,29 @@ test('index.get', function (t) {
169
169
st . end ( )
170
170
} )
171
171
172
- t . test ( 'empty index' , function ( st ) {
172
+ t . test ( 'empty index' , ( st ) => {
173
173
st . deepEqual ( new Index ( 'foo' , null ) . get ( 'bar' ) , [ ] )
174
174
st . deepEqual ( new Index ( 'foo' ) . get ( 'bar' ) , [ ] )
175
175
st . end ( )
176
176
} )
177
177
178
- t . test ( 'Index filter' , function ( st ) {
179
- var ast = u ( 'root' , [
178
+ t . test ( 'Index filter' , ( st ) => {
179
+ const ast = u ( 'root' , [
180
180
u ( 'node' , { word : 'foo' } ) ,
181
181
u ( 'node' , { word : 'bar' } ) ,
182
182
u ( 'skip' , { word : 'foo' } ) ,
183
183
u ( 'skip' , { word : 'bar' } )
184
184
] )
185
185
186
- st . test ( 'type test' , function ( sst ) {
187
- var index = new Index ( 'word' , ast , 'node' )
186
+ st . test ( 'type test' , ( sst ) => {
187
+ const index = new Index ( 'word' , ast , 'node' )
188
188
sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
189
189
sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
190
190
sst . end ( )
191
191
} )
192
192
193
- st . test ( 'function test' , function ( sst ) {
194
- var index = new Index ( 'word' , ast , filter )
193
+ st . test ( 'function test' , ( sst ) => {
194
+ const index = new Index ( 'word' , ast , filter )
195
195
sst . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word="foo"]' , ast ) ] )
196
196
sst . deepEqual ( index . get ( 'bar' ) , [ select ( 'node[word="bar"]' , ast ) ] )
197
197
sst . end ( )
@@ -209,19 +209,19 @@ test('index.get', function (t) {
209
209
st . end ( )
210
210
} )
211
211
212
- t . test ( 'computed keys' , function ( st ) {
212
+ t . test ( 'computed keys' , ( st ) => {
213
213
/**
214
214
* @typedef {{x: number, y: number, z: number} } FunkyNode
215
215
*/
216
216
217
- var ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
217
+ const ast = u ( 'root' , { x : 0 , y : 4 , id : 0 } , [
218
218
u ( 'node' , { x : 3 , y : 2 , id : 1 } ) ,
219
219
u ( 'node' , { x : 2 , y : 2 , id : 2 } ) ,
220
220
u ( 'node' , { x : 3 , y : 1 , id : 3 } ) ,
221
221
u ( 'node' , { x : 4 , y : 1 , id : 4 } )
222
222
] )
223
223
// @ts -ignore it’s fine
224
- var index = new Index ( xPlusY , ast )
224
+ const index = new Index ( xPlusY , ast )
225
225
st . deepEqual ( index . get ( 4 ) , [
226
226
select ( '[id=0]' , ast ) ,
227
227
select ( '[id=2]' , ast ) ,
@@ -249,20 +249,20 @@ test('index.get', function (t) {
249
249
t . end ( )
250
250
} )
251
251
252
- test ( 'index.remove' , function ( t ) {
253
- var ast = u ( 'root' , [
252
+ test ( 'index.remove' , ( t ) => {
253
+ const ast = u ( 'root' , [
254
254
u ( 'bad' , { word : 'foo' } ) ,
255
255
u ( 'node' , { word : 'foo' } ) ,
256
256
u ( 'node' , { word : 'bar' } )
257
257
] )
258
258
259
- var index = new Index ( 'word' , ast )
259
+ const index = new Index ( 'word' , ast )
260
260
t . deepEqual ( index . get ( 'foo' ) , [
261
261
select ( 'bad[word=foo]' , ast ) ,
262
262
select ( 'node[word=foo]' , ast )
263
263
] )
264
264
265
- var result = index . remove ( select ( 'bad' , ast ) )
265
+ const result = index . remove ( select ( 'bad' , ast ) )
266
266
t . deepEqual ( index . get ( 'foo' ) , [ select ( 'node[word=foo]' , ast ) ] )
267
267
268
268
t . equal ( result , index , 'returns this' )
0 commit comments