@@ -149,7 +149,7 @@ defmodule NextLS.ASTHelpersVariablesTest do
149
149
describe ( "get_variable_definition/2" ) do
150
150
test "symbol defined in a match is found" , % { source: source } do
151
151
symbol = Variables . get_variable_definition ( source , { 7 , 25 } )
152
- assert symbol == { :charlie , { 5 .. 5 , 5 .. 12 } }
152
+ assert symbol == { :charlie , { 5 .. 5 , 5 .. 11 } }
153
153
end
154
154
155
155
test "returns nil when position is not a variable reference" , % { source: source } do
@@ -167,172 +167,170 @@ defmodule NextLS.ASTHelpersVariablesTest do
167
167
test "references that defined by same symbol as target reference" , % { source: source } do
168
168
refs = Variables . list_variable_references ( source , { 6 , 17 } )
169
169
assert length ( refs ) == 2
170
- assert exists_in? ( refs , { :charlie , { 6 .. 6 , 17 .. 24 } } )
171
- assert exists_in? ( refs , { :charlie , { 7 .. 7 , 25 .. 32 } } )
170
+ assert { :charlie , { 6 .. 6 , 17 .. 23 } } in refs
171
+ assert { :charlie , { 7 .. 7 , 25 .. 31 } } in refs
172
172
end
173
173
174
174
test "symbol set in a match and corrctly processing ^" , % { source: source } do
175
175
refs = Variables . list_variable_references ( source , { 5 , 5 } )
176
176
assert length ( refs ) == 2
177
- assert exists_in? ( refs , { :charlie , { 6 .. 6 , 17 .. 24 } } )
178
- assert exists_in? ( refs , { :charlie , { 7 .. 7 , 25 .. 32 } } )
177
+ assert { :charlie , { 6 .. 6 , 17 .. 23 } } in refs
178
+ assert { :charlie , { 7 .. 7 , 25 .. 31 } } in refs
179
179
end
180
180
181
181
test "symbol set in a function arguments" , % { source: source } do
182
182
refs = Variables . list_variable_references ( source , { 4 , 30 } )
183
183
assert length ( refs ) == 2
184
- assert exists_in? ( refs , { :alpha , { 6 .. 6 , 42 .. 47 } } )
185
- assert exists_in? ( refs , { :alpha , { 7 .. 7 , 11 .. 16 } } )
184
+ assert { :alpha , { 6 .. 6 , 42 .. 46 } } in refs
185
+ assert { :alpha , { 7 .. 7 , 11 .. 15 } } in refs
186
186
end
187
187
188
188
test "symbol set in a function arguments and referenced in 'when' clause" , % { source: source } do
189
189
refs = Variables . list_variable_references ( source , { 4 , 21 } )
190
190
assert length ( refs ) == 2
191
- assert exists_in? ( refs , { :bravo , { 4 .. 4 , 49 .. 54 } } )
192
- assert exists_in? ( refs , { :bravo , { 7 .. 7 , 18 .. 23 } } )
191
+ assert { :bravo , { 4 .. 4 , 49 .. 53 } } in refs
192
+ assert { :bravo , { 7 .. 7 , 18 .. 22 } } in refs
193
193
end
194
194
195
195
test "symbol set in a mattern match" , % { source: source } do
196
196
refs = Variables . list_variable_references ( source , { 6 , 33 } )
197
197
assert length ( refs ) == 1
198
- assert exists_in? ( refs , { :delta , { 7 .. 7 , 34 .. 39 } } )
198
+ assert { :delta , { 7 .. 7 , 34 .. 38 } } in refs
199
199
end
200
200
201
201
test "references shadowed by 'if/else' blocks" , % { source: source } do
202
202
refs = Variables . list_variable_references ( source , { 11 , 5 } )
203
203
assert length ( refs ) == 2
204
- assert exists_in? ( refs , { :alpha , { 14 .. 14 , 10 .. 15 } } )
205
- assert exists_in? ( refs , { :alpha , { 24 .. 24 , 11 .. 16 } } )
204
+ assert { :alpha , { 14 .. 14 , 10 .. 14 } } in refs
205
+ assert { :alpha , { 24 .. 24 , 11 .. 15 } } in refs
206
206
end
207
207
208
208
test "symbol set in 'if' block" , % { source: source } do
209
209
refs = Variables . list_variable_references ( source , { 15 , 9 } )
210
210
assert length ( refs ) == 1
211
- assert exists_in? ( refs , { :alpha , { 17 .. 17 , 20 .. 25 } } )
211
+ assert { :alpha , { 17 .. 17 , 20 .. 24 } } in refs
212
212
end
213
213
214
214
test "symbol set in match with 'if' containing it's shadow" , % { source: source } do
215
215
refs = Variables . list_variable_references ( source , { 13 , 5 } )
216
216
assert length ( refs ) == 1
217
- assert exists_in? ( refs , { :bravo , { 24 .. 24 , 18 .. 23 } } )
217
+ assert { :bravo , { 24 .. 24 , 18 .. 22 } } in refs
218
218
end
219
219
220
220
test "symbol set in 'case' clause" , % { source: source } do
221
221
refs = Variables . list_variable_references ( source , { 33 , 13 } )
222
222
assert length ( refs ) == 2
223
- assert exists_in? ( refs , { :bravo , { 33 .. 33 , 32 .. 37 } } )
224
- assert exists_in? ( refs , { :bravo , { 34 .. 34 , 19 .. 24 } } )
223
+ assert { :bravo , { 33 .. 33 , 32 .. 36 } } in refs
224
+ assert { :bravo , { 34 .. 34 , 19 .. 23 } } in refs
225
225
end
226
226
227
227
test "symbol referenced in 'cond' clause" , % { source: source } do
228
228
refs = Variables . list_variable_references ( source , { 46 , 5 } )
229
229
assert length ( refs ) == 2
230
- assert exists_in? ( refs , { :alpha , { 51 .. 51 , 9 .. 14 } } )
231
- assert exists_in? ( refs , { :alpha , { 58 .. 58 , 16 .. 21 } } )
230
+ assert { :alpha , { 51 .. 51 , 9 .. 13 } } in refs
231
+ assert { :alpha , { 58 .. 58 , 16 .. 20 } } in refs
232
232
end
233
233
234
234
test "symbol shadowed in 'for' and 'with'" , % { source: source } do
235
235
refs = Variables . list_variable_references ( source , { 62 , 12 } )
236
236
assert length ( refs ) == 4
237
- assert exists_in? ( refs , { :alpha , { 65 .. 65 , 18 .. 23 } } )
238
- assert exists_in? ( refs , { :alpha , { 69 .. 69 , 18 .. 23 } } )
239
- assert exists_in? ( refs , { :alpha , { 73 .. 73 , 26 .. 31 } } )
240
- assert exists_in? ( refs , { :alpha , { 81 .. 81 , 18 .. 23 } } )
237
+ assert { :alpha , { 65 .. 65 , 18 .. 22 } } in refs
238
+ assert { :alpha , { 69 .. 69 , 18 .. 22 } } in refs
239
+ assert { :alpha , { 73 .. 73 , 26 .. 30 } } in refs
240
+ assert { :alpha , { 81 .. 81 , 18 .. 22 } } in refs
241
241
242
242
refs2 = Variables . list_variable_references ( source , { 63 , 5 } )
243
243
assert length ( refs2 ) == 1
244
- assert exists_in? ( refs2 , { :bravo , { 81 .. 81 , 11 .. 16 } } )
244
+ assert { :bravo , { 81 .. 81 , 11 .. 15 } } in refs2
245
245
end
246
246
247
247
test "symbol defined in 'for'" , % { source: source } do
248
248
refs = Variables . list_variable_references ( source , { 65 , 9 } )
249
249
assert length ( refs ) == 1
250
- assert exists_in? ( refs , { :alpha , { 66 .. 66 , 18 .. 23 } } )
250
+ assert { :alpha , { 66 .. 66 , 18 .. 22 } } in refs
251
251
252
252
refs2 = Variables . list_variable_references ( source , { 69 , 9 } )
253
253
assert length ( refs2 ) == 1
254
- assert exists_in? ( refs2 , { :bravo , { 69 .. 69 , 47 .. 52 } } )
254
+ assert { :bravo , { 69 .. 69 , 47 .. 51 } } in refs2
255
255
256
256
refs3 = Variables . list_variable_references ( source , { 69 , 25 } )
257
257
assert length ( refs3 ) == 2
258
- assert exists_in? ( refs3 , { :charlie , { 69 .. 69 , 55 .. 62 } } )
259
- assert exists_in? ( refs3 , { :charlie , { 70 .. 70 , 18 .. 25 } } )
258
+ assert { :charlie , { 69 .. 69 , 55 .. 61 } } in refs3
259
+ assert { :charlie , { 70 .. 70 , 18 .. 24 } } in refs3
260
260
end
261
261
262
262
test "symbol defined in 'with'" , % { source: source } do
263
263
refs = Variables . list_variable_references ( source , { 73 , 16 } )
264
264
assert length ( refs ) == 1
265
- assert exists_in? ( refs , { :delta , { 74 .. 74 , 27 .. 32 } } )
265
+ assert { :delta , { 74 .. 74 , 27 .. 31 } } in refs
266
266
267
267
refs2 = Variables . list_variable_references ( source , { 74 , 11 } )
268
268
assert length ( refs2 ) == 1
269
- assert exists_in? ( refs2 , { :delta , { 75 .. 75 , 18 .. 23 } } )
269
+ assert { :delta , { 75 .. 75 , 18 .. 22 } } in refs2
270
270
271
271
refs3 = Variables . list_variable_references ( source , { 78 , 7 } )
272
272
assert length ( refs3 ) == 1
273
- assert exists_in? ( refs3 , { :error , { 78 .. 78 , 25 .. 30 } } )
273
+ assert { :error , { 78 .. 78 , 25 .. 29 } } in refs3
274
274
end
275
275
276
- test "symbol shadowed by anonymus funciton" , % { source: source } do
276
+ test "symbol shadowed by anonymous funciton" , % { source: source } do
277
277
refs = Variables . list_variable_references ( source , { 84 , 12 } )
278
278
assert length ( refs ) == 2
279
- assert exists_in? ( refs , { :alpha , { 96 .. 96 , 7 .. 12 } } )
280
- assert exists_in? ( refs , { :alpha , { 100 .. 100 , 21 .. 26 } } )
279
+ assert { :alpha , { 96 .. 96 , 7 .. 11 } } in refs
280
+ assert { :alpha , { 100 .. 100 , 21 .. 25 } } in refs
281
281
end
282
282
283
- test "symbol defined in anonymus funciton" , % { source: source } do
283
+ test "symbol defined in anonymous funciton" , % { source: source } do
284
284
refs = Variables . list_variable_references ( source , { 86 , 7 } )
285
285
assert length ( refs ) == 1
286
- assert exists_in? ( refs , { :charlie , { 88 .. 88 , 15 .. 22 } } )
286
+ assert { :charlie , { 88 .. 88 , 15 .. 21 } } in refs
287
287
288
288
refs2 = Variables . list_variable_references ( source , { 86 , 22 } )
289
289
assert length ( refs2 ) == 1
290
- assert exists_in? ( refs2 , { :delta , { 88 .. 88 , 24 .. 29 } } )
290
+ assert { :delta , { 88 .. 88 , 24 .. 28 } } in refs2
291
291
292
292
refs3 = Variables . list_variable_references ( source , { 86 , 31 } )
293
293
assert length ( refs3 ) == 1
294
- assert exists_in? ( refs3 , { :alpha , { 87 .. 87 , 20 .. 25 } } )
294
+ assert { :alpha , { 87 .. 87 , 20 .. 24 } } in refs3
295
295
296
296
refs4 = Variables . list_variable_references ( source , { 97 , 22 } )
297
297
assert length ( refs4 ) == 1
298
- assert exists_in? ( refs4 , { :alpha , { 97 .. 97 , 37 .. 42 } } )
298
+ assert { :alpha , { 97 .. 97 , 37 .. 41 } } in refs4
299
299
300
300
refs5 = Variables . list_variable_references ( source , { 98 , 25 } )
301
301
assert length ( refs5 ) == 1
302
- assert exists_in? ( refs5 , { :alpha , { 98 .. 98 , 51 .. 56 } } )
302
+ assert { :alpha , { 98 .. 98 , 51 .. 55 } } in refs5
303
303
end
304
304
305
305
test "symbols with 'receive' macro" , % { source: source } do
306
306
refs = Variables . list_variable_references ( source , { 103 , 12 } )
307
307
assert length ( refs ) == 2
308
- assert exists_in? ( refs , { :alpha , { 110 .. 110 , 10 .. 15 } } )
309
- assert exists_in? ( refs , { :alpha , { 113 .. 113 , 17 .. 22 } } )
308
+ assert { :alpha , { 110 .. 110 , 10 .. 14 } } in refs
309
+ assert { :alpha , { 113 .. 113 , 17 .. 21 } } in refs
310
310
311
311
refs2 = Variables . list_variable_references ( source , { 105 , 19 } )
312
312
assert length ( refs2 ) == 1
313
- assert exists_in? ( refs2 , { :bravo , { 107 .. 107 , 17 .. 22 } } )
313
+ assert { :bravo , { 107 .. 107 , 17 .. 21 } } in refs2
314
314
end
315
315
316
316
test "symbols set with 'destructure'" , % { source: source } do
317
317
refs = Variables . list_variable_references ( source , { 117 , 18 } )
318
318
assert length ( refs ) == 1
319
- assert exists_in? ( refs , { :alpha , { 118 .. 118 , 16 .. 21 } } )
319
+ assert { :alpha , { 118 .. 118 , 16 .. 20 } } in refs
320
320
end
321
321
322
322
test "symbols set in macro" , % { source: source } do
323
323
refs = Variables . list_variable_references ( source , { 121 , 37 } )
324
324
assert length ( refs ) == 1
325
- assert exists_in? ( refs , { :variables , { 122 .. 122 , 14 .. 23 } } )
325
+ assert { :variables , { 122 .. 122 , 14 .. 22 } } in refs
326
326
327
327
refs2 = Variables . list_variable_references ( source , { 124 , 7 } )
328
328
assert length ( refs2 ) == 1
329
- assert exists_in? ( refs2 , { :length , { 127 .. 127 , 32 .. 38 } } )
329
+ assert { :length , { 127 .. 127 , 32 .. 37 } } in refs2
330
330
331
331
refs3 = Variables . list_variable_references ( source , { 123 , 7 } )
332
332
assert length ( refs3 ) == 1
333
- assert exists_in? ( refs3 , { :var , { 127 .. 127 , 17 .. 20 } } )
333
+ assert { :var , { 127 .. 127 , 17 .. 19 } } in refs3
334
334
end
335
335
end
336
-
337
- defp exists_in? ( results , var ) , do: Enum . find ( results , & ( & 1 == var ) )
338
336
end
0 commit comments