@@ -251,5 +251,55 @@ module Crystal
251251 end
252252 end
253253 end
254+
255+ it " normalizes with filename" do
256+ a_def = parse(" def foo(*args, **options); args + options; end" , filename: " foo.cr" ).as(Def )
257+ other_def = a_def.expand_default_arguments(Program .new, 2 , [" x" , " y" ])
258+ other_def.to_s.should eq <<-CRYSTAL
259+ def foo:x:y(__temp_cd6ae5dd_1, __temp_cd6ae5dd_2, x __temp_cd6ae5dd_3, y __temp_cd6ae5dd_4)
260+ args = {__temp_cd6ae5dd_1, __temp_cd6ae5dd_2}
261+ options = {x: __temp_cd6ae5dd_3, y: __temp_cd6ae5dd_4}
262+ args + options
263+ end
264+ CRYSTAL
265+
266+ a_def = parse(" def foo(*args, **options); args + options; end" , filename: " bar.cr" ).as(Def )
267+ other_def = a_def.expand_default_arguments(Program .new, 2 , [" x" , " y" ])
268+ other_def.to_s.should eq <<-CRYSTAL
269+ def foo:x:y(__temp_fbcf3d84_1, __temp_fbcf3d84_2, x __temp_fbcf3d84_3, y __temp_fbcf3d84_4)
270+ args = {__temp_fbcf3d84_1, __temp_fbcf3d84_2}
271+ options = {x: __temp_fbcf3d84_3, y: __temp_fbcf3d84_4}
272+ args + options
273+ end
274+ CRYSTAL
275+ end
276+
277+ it " normalizes `.new` with filename" do
278+ a_def = parse(" def new(y, **options); end" , filename: " foo.cr" ).as(Def )
279+ other_def = a_def.expand_new_default_arguments(Program .new, 0 , [" x" , " y" , " z" ])
280+ other_def.to_s.should eq <<-CRYSTAL
281+ def new:x:y:z(x __temp_cd6ae5dd_1, y __temp_cd6ae5dd_2, z __temp_cd6ae5dd_3)
282+ _ = allocate
283+ _.initialize(x: __temp_cd6ae5dd_1, y: __temp_cd6ae5dd_2, z: __temp_cd6ae5dd_3)
284+ if _.responds_to?(:finalize)
285+ ::GC.add_finalizer(_)
286+ end
287+ _
288+ end
289+ CRYSTAL
290+
291+ a_def = parse(" def new(y, **options); end" , filename: " bar.cr" ).as(Def )
292+ other_def = a_def.expand_new_default_arguments(Program .new, 0 , [" x" , " y" , " z" ])
293+ other_def.to_s.should eq <<-CRYSTAL
294+ def new:x:y:z(x __temp_fbcf3d84_1, y __temp_fbcf3d84_2, z __temp_fbcf3d84_3)
295+ _ = allocate
296+ _.initialize(x: __temp_fbcf3d84_1, y: __temp_fbcf3d84_2, z: __temp_fbcf3d84_3)
297+ if _.responds_to?(:finalize)
298+ ::GC.add_finalizer(_)
299+ end
300+ _
301+ end
302+ CRYSTAL
303+ end
254304 end
255305end
0 commit comments