diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-10-06 09:26:58 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2020-01-02 18:40:45 -0800 |
commit | e014e6bf6685f681998238ff005f6d161d43ce51 (patch) | |
tree | 1c373d95cdb9280ca051e9e66876ba6adc133f91 /spec/ruby/optional | |
parent | ff96565686c05919bcae3ea77831879e95f67457 (diff) | |
download | ruby-e014e6bf6685f681998238ff005f6d161d43ce51.tar.gz |
Update specs for keyword argument separation
Diffstat (limited to 'spec/ruby/optional')
-rw-r--r-- | spec/ruby/optional/capi/util_spec.rb | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/spec/ruby/optional/capi/util_spec.rb b/spec/ruby/optional/capi/util_spec.rb index 3556c8c010..cf19c55b57 100644 --- a/spec/ruby/optional/capi/util_spec.rb +++ b/spec/ruby/optional/capi/util_spec.rb @@ -115,11 +115,22 @@ describe "C-API Util function" do ScratchPad.recorded.should == [1, nil] end - it "assigns required and Hash arguments with nil Hash" do - suppress_warning do - @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 + ruby_version_is ''...'2.8' do + it "assigns required and Hash arguments with nil Hash" do + suppress_warning do + @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 + end + ScratchPad.recorded.should == [1, nil] + end + end + + ruby_version_is '2.8' do + it "rejects the use of nil as a hash" do + -> { + @o.rb_scan_args([1, nil], "1:", 2, @acc).should == 1 + }.should raise_error(ArgumentError) + ScratchPad.recorded.should == [] end - ScratchPad.recorded.should == [1, nil] end it "assigns required and optional arguments with no hash argument given" do @@ -133,33 +144,55 @@ describe "C-API Util function" do ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc] end - # r43934 - it "rejects non-keyword arguments" do - h = {1 => 2, 3 => 4} - -> { - suppress_warning do - @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc) - end - }.should raise_error(ArgumentError) - ScratchPad.recorded.should == [] - end + ruby_version_is ''...'2.8' do + # r43934 + it "rejects non-keyword arguments" do + h = {1 => 2, 3 => 4} + -> { + suppress_warning do + @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc) + end + }.should raise_error(ArgumentError) + ScratchPad.recorded.should == [] + end - it "rejects required and non-keyword arguments" do - h = {1 => 2, 3 => 4} - -> { + it "rejects required and non-keyword arguments" do + h = {1 => 2, 3 => 4} + -> { + suppress_warning do + @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc) + end + }.should raise_error(ArgumentError) + ScratchPad.recorded.should == [] + end + + it "considers the hash as a post argument when there is a splat" do + h = {1 => 2, 3 => 4} suppress_warning do - @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc) + @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 6 end - }.should raise_error(ArgumentError) - ScratchPad.recorded.should == [] + ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc] + end end - it "considers the hash as a post argument when there is a splat" do - h = {1 => 2, 3 => 4} - suppress_warning do - @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 6 + ruby_version_is '2.8' do + it "does not reject non-symbol keys in keyword arguments" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([h], "#{@keyword_prefix}0:", 1, @acc).should == 0 + ScratchPad.recorded.should == [h] + end + + it "does not reject non-symbol keys in keyword arguments with required argument" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([1, h], "#{@keyword_prefix}1:", 2, @acc).should == 1 + ScratchPad.recorded.should == [1, h] + end + + it "considers keyword arguments with non-symbol keys as keywords when using splat and post arguments" do + h = {1 => 2, 3 => 4} + @o.rb_scan_args([1, 2, 3, 4, 5, h], "#{@keyword_prefix}11*1:&", 6, @acc, &@prc).should == 5 + ScratchPad.recorded.should == [1, 2, [3, 4], 5, h, @prc] end - ScratchPad.recorded.should == [1, 2, [3, 4, 5], h, nil, @prc] end end |