-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2276 from herwinw/spec_lang_delegation
- Loading branch information
Showing
2 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
require_relative '../spec_helper' | ||
require_relative 'fixtures/delegation' | ||
|
||
describe "delegation with def(...)" do | ||
it "delegates rest and kwargs" do | ||
a = Class.new(DelegationSpecs::Target) do | ||
def delegate(...) | ||
target(...) | ||
end | ||
end | ||
|
||
a.new.delegate(1, b: 2).should == [[1], {b: 2}] | ||
end | ||
|
||
it "delegates block" do | ||
a = Class.new(DelegationSpecs::Target) do | ||
def delegate_block(...) | ||
target_block(...) | ||
end | ||
end | ||
|
||
a.new.delegate_block(1, b: 2) { |x| x }.should == [{b: 2}, [1]] | ||
end | ||
|
||
it "parses as open endless Range when brackets are omitted" do | ||
a = Class.new(DelegationSpecs::Target) do | ||
suppress_warning do | ||
def delegate(...) | ||
target ... | ||
end | ||
end | ||
end | ||
|
||
a.new.delegate(1, b: 2).should == Range.new([[], {}], nil, true) | ||
end | ||
end | ||
|
||
describe "delegation with def(x, ...)" do | ||
# NATFIXME: Support Prism::ForwardingParameterNode | ||
xit "delegates rest and kwargs" do | ||
#a = Class.new(DelegationSpecs::Target) do | ||
#def delegate(x, ...) | ||
#target(...) | ||
#end | ||
#end | ||
|
||
#a.new.delegate(0, 1, b: 2).should == [[1], {b: 2}] | ||
end | ||
|
||
# NATFIXME: Support Prism::ForwardingParameterNode | ||
xit "delegates block" do | ||
#a = Class.new(DelegationSpecs::Target) do | ||
#def delegate_block(x, ...) | ||
#target_block(...) | ||
#end | ||
#end | ||
|
||
#a.new.delegate_block(0, 1, b: 2) { |x| x }.should == [{b: 2}, [1]] | ||
end | ||
end | ||
|
||
ruby_version_is "3.2" do | ||
describe "delegation with def(*)" do | ||
it "delegates rest" do | ||
a = Class.new(DelegationSpecs::Target) do | ||
def delegate(*) | ||
target(*) | ||
end | ||
end | ||
|
||
a.new.delegate(0, 1).should == [[0, 1], {}] | ||
end | ||
end | ||
end | ||
|
||
ruby_version_is "3.2" do | ||
describe "delegation with def(**)" do | ||
it "delegates kwargs" do | ||
a = Class.new(DelegationSpecs::Target) do | ||
def delegate(**) | ||
target(**) | ||
end | ||
end | ||
|
||
a.new.delegate(a: 1) { |x| x }.should == [[], {a: 1}] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |