diff --git a/language/delegation_spec.rb b/language/delegation_spec.rb new file mode 100644 index 0000000000..252c3104ef --- /dev/null +++ b/language/delegation_spec.rb @@ -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 diff --git a/language/fixtures/delegation.rb b/language/fixtures/delegation.rb new file mode 100644 index 0000000000..527d928390 --- /dev/null +++ b/language/fixtures/delegation.rb @@ -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