summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/util_spec.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-10-06 09:26:58 -0700
committerJeremy Evans <code@jeremyevans.net>2020-01-02 18:40:45 -0800
commite014e6bf6685f681998238ff005f6d161d43ce51 (patch)
tree1c373d95cdb9280ca051e9e66876ba6adc133f91 /spec/ruby/optional/capi/util_spec.rb
parentff96565686c05919bcae3ea77831879e95f67457 (diff)
Update specs for keyword argument separation
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/2794
Diffstat (limited to 'spec/ruby/optional/capi/util_spec.rb')
-rw-r--r--spec/ruby/optional/capi/util_spec.rb83
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