@@ -3,14 +3,15 @@ Code.require_file("../../test_helper.exs", __DIR__)
33defmodule Module.Types.PatternTest do
44 use ExUnit.Case , async: true
55 import Module.Types.Infer , only: [ new_var: 2 ]
6- import Module.Types.Pattern
6+
77 alias Module.Types
8+ alias Module.Types.Pattern
89
910 defmacrop quoted_pattern ( patterns ) do
1011 quote do
1112 { patterns , true } = unquote ( Macro . escape ( expand_head ( patterns , true ) ) )
1213
13- of_pattern ( patterns , new_stack ( ) , new_context ( ) )
14+ Pattern . of_pattern ( patterns , new_stack ( ) , new_context ( ) )
1415 |> lift_result ( )
1516 end
1617 end
@@ -20,7 +21,7 @@ defmodule Module.Types.PatternTest do
2021 { vars , guards } = unquote ( Macro . escape ( expand_head ( vars , guards ) ) )
2122 context = Enum . reduce ( vars , new_context ( ) , & ( new_var ( & 1 , & 2 ) |> elem ( 1 ) ) )
2223
23- of_guard ( guards , new_stack ( ) , context )
24+ Pattern . of_guard ( guards , new_stack ( ) , context )
2425 end
2526 end
2627
@@ -242,16 +243,18 @@ end
242243defmodule Module.Types.TempTypesTest do
243244 use ExUnit.Case , async: true
244245 import Bitwise , warn: false
246+
245247 alias Module.Types
248+ alias Module.Types . { Expr , Pattern }
246249
247250 defmacrop quoted_head ( patterns , guards \\ [ true ] ) do
248251 quote do
249252 { patterns , guards } = unquote ( Macro . escape ( expand_head ( patterns , guards ) ) )
250253
251- Types . of_head (
254+ Pattern . of_head (
252255 patterns ,
253256 guards ,
254- def_expr ( ) ,
257+ new_stack ( ) ,
255258 new_context ( )
256259 )
257260 |> lift_result ( )
@@ -262,8 +265,8 @@ defmodule Module.Types.TempTypesTest do
262265 quote do
263266 { patterns , guards , body } = unquote ( Macro . escape ( expand_expr ( patterns , guards , body ) ) )
264267
265- with { :ok , _types , context } <- Types . of_head ( patterns , guards , def_expr ( ) , new_context ( ) ) ,
266- { :ok , type , context } <- Types . of_body ( body , context ) do
268+ with { :ok , _types , context } <- Pattern . of_head ( patterns , guards , new_stack ( ) , new_context ( ) ) ,
269+ { :ok , type , context } <- Expr . of_expr ( body , new_stack ( ) , context ) do
267270 { :ok , Types . lift_type ( type , context ) }
268271 else
269272 { :error , { type , reason , _context } } ->
@@ -304,8 +307,11 @@ defmodule Module.Types.TempTypesTest do
304307 Types . context ( "types_test.ex" , TypesTest , { :test , 0 } , [ ] , Module.ParallelChecker . test_cache ( ) )
305308 end
306309
307- defp def_expr ( ) do
308- { :def , [ ] , { :test , [ ] , [ ] } }
310+ defp new_stack ( ) do
311+ % {
312+ Types . stack ( )
313+ | last_expr: { :foo , [ ] , nil }
314+ }
309315 end
310316
311317 defp lift_result ( { :ok , types , context } ) when is_list ( types ) do
@@ -323,18 +329,18 @@ defmodule Module.Types.TempTypesTest do
323329 assert quoted_head ( [ a , a ] ) == { :ok , [ { :var , 0 } , { :var , 0 } ] }
324330
325331 assert { :ok , [ { :var , 0 } , { :var , 0 } ] , _ } =
326- Types . of_head (
332+ Pattern . of_head (
327333 [ { :a , [ version: 0 ] , :foo } , { :a , [ version: 0 ] , :foo } ] ,
328334 [ ] ,
329- def_expr ( ) ,
335+ new_stack ( ) ,
330336 new_context ( )
331337 )
332338
333339 assert { :ok , [ { :var , 0 } , { :var , 1 } ] , _ } =
334- Types . of_head (
340+ Pattern . of_head (
335341 [ { :a , [ version: 0 ] , :foo } , { :a , [ version: 1 ] , :foo } ] ,
336342 [ ] ,
337- def_expr ( ) ,
343+ new_stack ( ) ,
338344 new_context ( )
339345 )
340346 end
0 commit comments