@@ -153,7 +153,7 @@ defmodule Kernel.ExpansionTest do
153
153
end
154
154
155
155
test "locals: in guards" do
156
- assert expand ( quote ( do: fn pid when :erlang . == ( pid , self ) -> pid end ) ) ==
156
+ assert expand_and_clean ( quote ( do: fn pid when :erlang . == ( pid , self ) -> pid end ) , [ :import , :context ] ) ==
157
157
quote ( do: fn pid when :erlang . == ( pid , :erlang . self ( ) ) -> pid end )
158
158
end
159
159
@@ -337,22 +337,22 @@ defmodule Kernel.ExpansionTest do
337
337
## Cond
338
338
339
339
test "cond: expands each clause" do
340
- assert expand_and_clean ( quote do: ( cond do x = 1 -> x ; _ -> x end ) ) ==
340
+ assert expand ( quote do: ( cond do x = 1 -> x ; _ -> x end ) ) ==
341
341
quote do: ( cond do x = 1 -> x ; _ -> x ( ) end )
342
342
end
343
343
344
344
test "cond: does not share lexical scope between clauses" do
345
- assert expand_and_clean ( quote do: ( cond do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
345
+ assert expand ( quote do: ( cond do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
346
346
quote do: ( cond do 1 -> import :"Elixir.List" , [ ] ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end )
347
347
end
348
348
349
349
test "cond: does not leaks vars on head" do
350
- assert expand_and_clean ( quote do: ( cond do x = 1 -> x ; y = 2 -> y end ; :erlang . + ( x , y ) ) ) ==
350
+ assert expand ( quote do: ( cond do x = 1 -> x ; y = 2 -> y end ; :erlang . + ( x , y ) ) ) ==
351
351
quote do: ( cond do x = 1 -> x ; y = 2 -> y end ; :erlang . + ( x ( ) , y ( ) ) )
352
352
end
353
353
354
354
test "cond: leaks vars" do
355
- assert expand_and_clean ( quote do: ( cond do 1 -> x = 1 ; 2 -> y = 2 end ; :erlang . + ( x , y ) ) ) ==
355
+ assert expand ( quote do: ( cond do 1 -> x = 1 ; 2 -> y = 2 end ; :erlang . + ( x , y ) ) ) ==
356
356
quote do: ( cond do 1 -> x = 1 ; 2 -> y = 2 end ; :erlang . + ( x , y ) )
357
357
end
358
358
@@ -365,27 +365,27 @@ defmodule Kernel.ExpansionTest do
365
365
## Case
366
366
367
367
test "case: expands each clause" do
368
- assert expand_and_clean ( quote do: ( case w do x -> x ; _ -> x end ) ) ==
368
+ assert expand ( quote do: ( case w do x -> x ; _ -> x end ) ) ==
369
369
quote do: ( case w ( ) do x -> x ; _ -> x ( ) end )
370
370
end
371
371
372
372
test "case: does not share lexical scope between clauses" do
373
- assert expand_and_clean ( quote do: ( case w do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
373
+ assert expand ( quote do: ( case w do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
374
374
quote do: ( case w ( ) do 1 -> import :"Elixir.List" , [ ] ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end )
375
375
end
376
376
377
377
test "case: expands guards" do
378
- assert expand_and_clean ( quote do: ( case w do x when x when __ENV__ . context -> true end ) ) ==
378
+ assert expand ( quote do: ( case w do x when x when __ENV__ . context -> true end ) ) ==
379
379
quote do: ( case w ( ) do x when x when :guard -> true end )
380
380
end
381
381
382
382
test "case: does not leaks vars on head" do
383
- assert expand_and_clean ( quote do: ( case w do x -> x ; y -> y end ; :erlang . + ( x , y ) ) ) ==
383
+ assert expand ( quote do: ( case w do x -> x ; y -> y end ; :erlang . + ( x , y ) ) ) ==
384
384
quote do: ( case w ( ) do x -> x ; y -> y end ; :erlang . + ( x ( ) , y ( ) ) )
385
385
end
386
386
387
387
test "case: leaks vars" do
388
- assert expand_and_clean ( quote do: ( case w do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) ) ) ==
388
+ assert expand ( quote do: ( case w do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) ) ) ==
389
389
quote do: ( case w ( ) do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) )
390
390
end
391
391
@@ -398,32 +398,32 @@ defmodule Kernel.ExpansionTest do
398
398
## Receive
399
399
400
400
test "receive: expands each clause" do
401
- assert expand_and_clean ( quote do: ( receive do x -> x ; _ -> x end ) ) ==
401
+ assert expand ( quote do: ( receive do x -> x ; _ -> x end ) ) ==
402
402
quote do: ( receive do x -> x ; _ -> x ( ) end )
403
403
end
404
404
405
405
test "receive: does not share lexical scope between clauses" do
406
- assert expand_and_clean ( quote do: ( receive do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
406
+ assert expand ( quote do: ( receive do 1 -> import List ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end ) ) ==
407
407
quote do: ( receive do 1 -> import :"Elixir.List" , [ ] ; 2 -> flatten ( [ 1 , 2 , 3 ] ) end )
408
408
end
409
409
410
410
test "receive: expands guards" do
411
- assert expand_and_clean ( quote do: ( receive do x when x when __ENV__ . context -> true end ) ) ==
411
+ assert expand ( quote do: ( receive do x when x when __ENV__ . context -> true end ) ) ==
412
412
quote do: ( receive do x when x when :guard -> true end )
413
413
end
414
414
415
415
test "receive: does not leaks clause vars" do
416
- assert expand_and_clean ( quote do: ( receive do x -> x ; y -> y end ; :erlang . + ( x , y ) ) ) ==
416
+ assert expand ( quote do: ( receive do x -> x ; y -> y end ; :erlang . + ( x , y ) ) ) ==
417
417
quote do: ( receive do x -> x ; y -> y end ; :erlang . + ( x ( ) , y ( ) ) )
418
418
end
419
419
420
420
test "receive: leaks vars" do
421
- assert expand_and_clean ( quote do: ( receive do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) ) ) ==
421
+ assert expand ( quote do: ( receive do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) ) ) ==
422
422
quote do: ( receive do x -> x = x ; y -> y = y end ; :erlang . + ( x , y ) )
423
423
end
424
424
425
425
test "receive: leaks vars on after" do
426
- assert expand_and_clean ( quote do: ( receive do x -> x = x after y -> y ; w = y end ; :erlang . + ( x , w ) ) ) ==
426
+ assert expand ( quote do: ( receive do x -> x = x after y -> y ; w = y end ; :erlang . + ( x , w ) ) ) ==
427
427
quote do: ( receive do x -> x = x after y ( ) -> y ( ) ; w = y ( ) end ; :erlang . + ( x , w ) )
428
428
end
429
429
@@ -540,8 +540,8 @@ defmodule Kernel.ExpansionTest do
540
540
13
541
541
end
542
542
543
- defp expand_and_clean ( expr ) do
544
- cleaner = & Keyword . drop ( & 1 , [ :export ] )
543
+ defp expand_and_clean ( expr , vars ) do
544
+ cleaner = & Keyword . drop ( & 1 , vars )
545
545
expr
546
546
|> expand_env ( __ENV__ )
547
547
|> elem ( 0 )
0 commit comments