forked from jruby/jruby
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit fixes issue jruby#276 which is a regression introduced by http://jira.codehaus.org/browse/JRUBY-6729. The bug was caused by a erroneous behavour when yielding splat for a block of arity of one: MRI doesn't unsplat the passed value, whilst jruby was. See GH-276_yield_splat_behaviour_causes_pp_to_break.rb for details on behaviour
- Loading branch information
1 parent
fc44a6b
commit a2c6561
Showing
4 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
spec/regression/GH-276_yield_splat_behaviour_causes_pp_to_break.rb
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,55 @@ | ||
require 'rspec' | ||
|
||
def call_one | ||
yield(["a"]) | ||
end | ||
|
||
def call_two | ||
yield(["a","b"]) | ||
end | ||
|
||
def call_three | ||
yield(["a", "b", "c"]) | ||
end | ||
|
||
def yield_with_splat(method_name = 'call_two') | ||
send(method_name) { |*a| yield(*a) } | ||
end | ||
|
||
describe 'yield splat' do | ||
it 'yields an array when block has only one argument' do | ||
value = nil | ||
yield_with_splat("call_one") { |a| value = a } | ||
value.should == ["a"] | ||
end | ||
|
||
it 'yields an array when block as one argument and passed two' do | ||
value = nil | ||
yield_with_splat("call_two") { |a| value = a } | ||
value.should == ["a", "b"] | ||
end | ||
|
||
it 'yields one value when block has two arguments and passed one' do | ||
first_value = nil | ||
second_value = nil | ||
yield_with_splat("call_one") { |a,b| first_value = a; second_value = b } | ||
first_value.should == "a" | ||
second_value.should == nil | ||
end | ||
|
||
it 'yields two values when block has two arguments and passed two' do | ||
first_value = nil | ||
second_value = nil | ||
yield_with_splat { |a,b| first_value = a; second_value = b } | ||
first_value.should == "a" | ||
second_value.should == "b" | ||
end | ||
|
||
it 'yields two values when block has two arguments and passed three' do | ||
first_value = nil | ||
second_value = nil | ||
yield_with_splat("call_three") { |a,b| first_value = a; second_value = b } | ||
first_value.should == "a" | ||
second_value.should == "b" | ||
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
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
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
This restores the behaviour prior to JRUBY-6729