1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/language/delegation_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.5 KiB
Ruby
Raw Permalink Normal View History

2020-02-28 13:07:17 -05:00
require_relative '../spec_helper'
require_relative 'fixtures/delegation'
2022-04-25 08:53:54 -04:00
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
2020-02-28 13:07:17 -05:00
2022-04-25 08:53:54 -04:00
a.new.delegate(1, b: 2).should == [[1], {b: 2}]
end
2020-02-28 13:07:17 -05:00
2022-04-25 08:53:54 -04:00
it "delegates block" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate_block(...)
target_block(...)
end
RUBY
2020-02-28 13:07:17 -05:00
2022-04-25 08:53:54 -04:00
a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end
2020-02-28 13:07:17 -05:00
2022-04-25 08:53:54 -04:00
it "parses as open endless Range when brackets are omitted" do
a = Class.new(DelegationSpecs::Target)
suppress_warning do
a.class_eval(<<-RUBY)
def delegate(...)
target ...
end
RUBY
end
2020-02-28 13:07:17 -05:00
2022-04-25 08:53:54 -04:00
a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true)
2020-02-28 13:07:17 -05:00
end
end
2021-07-29 16:11:21 -04:00
ruby_version_is "2.7.3" do
describe "delegation with def(x, ...)" do
it "delegates rest and kwargs" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate(x, ...)
target(...)
end
RUBY
a.new.delegate(0, 1, b: 2).should == [[1], {b: 2}]
end
it "delegates block" do
a = Class.new(DelegationSpecs::Target)
a.class_eval(<<-RUBY)
def delegate_block(x, ...)
target_block(...)
end
RUBY
a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]]
end
end
end