From 1ce89bbd254adaba52c5fe60b984cd42f88113a5 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Wed, 12 Feb 2020 13:53:04 -0500 Subject: [PATCH] Add args forwarding specs --- language/delegation_spec.rb | 39 +++++++++++++++++++++++++++++++++ language/fixtures/delegation.rb | 11 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 language/delegation_spec.rb create mode 100644 language/fixtures/delegation.rb 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