Skip to content

Commit

Permalink
Add args forwarding specs
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan authored and eregon committed Feb 15, 2020
1 parent e05a219 commit 10fe05c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
39 changes: 39 additions & 0 deletions language/delegation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require_relative '../spec_helper'
require_relative 'fixtures/delegation'

ruby_version_is "2.7" do
describe "delegation with def(...)" do
it "delegates rest and kwargs" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(...)
target(...)
end
RUBY

a.new.delegate(1, b: 2).should == [[1], {b: 2}]
end

it "delegates block" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate_block(...)
target_block(...)
end
RUBY

a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end

it "parses as open endless Range when brackets are ommitted" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(...)
target ...
end
RUBY

a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true)
end
end
end
11 changes: 11 additions & 0 deletions language/fixtures/delegation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module DelegationSpecs
class Target
def target(*args, **kwargs)
[args, kwargs]
end

def target_block(*args, **kwargs)
yield [kwargs, args]
end
end
end

0 comments on commit 10fe05c

Please sign in to comment.