Skip to content

Commit eb5a9cf

Browse files
committed
Add specs for rb_scan_args that shouldn't emit warnings when passed nil as last argument
``` require 'date' DateTime.rfc2822(nil) # The last argument is nil, treating as empty keywords # .../lib/truffle/truffle/cext.rb:1132:in `rb_exc_raise': invalid date (Date::Error) ```
1 parent f6b7b9e commit eb5a9cf

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

spec/ruby/library/datetime/rfc2822_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
describe "DateTime.rfc2822" do
55
it "needs to be reviewed for spec completeness"
6+
7+
it "raises DateError if passed nil" do
8+
-> { DateTime.rfc2822(nil) }.should raise_error(Date::Error, "invalid date")
9+
end
610
end

spec/ruby/optional/capi/util_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@
127127
ScratchPad.recorded.should == [1, 7, 4]
128128
end
129129

130+
it "assigns optional arguments with no hash argument given" do
131+
@o.rb_scan_args([1, 7], "02:", 3, @acc).should == 2
132+
ScratchPad.recorded.should == [1, 7, nil]
133+
end
134+
135+
it "assigns optional arguments with no hash argument given and rejects the use of optional nil argument as a hash" do
136+
-> {
137+
@o.rb_scan_args([1, nil], "02:", 3, @acc).should == 2
138+
}.should_not complain
139+
140+
ScratchPad.recorded.should == [1, nil, nil]
141+
end
142+
130143
it "assigns required, optional, splat, post-splat, Hash and block arguments" do
131144
h = {a: 1, b: 2}
132145
@o.rb_scan_args([1, 2, 3, 4, 5, h], "k11*1:&", 6, @acc, &@prc).should == 5

spec/tags/optional/capi/util_tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ fails:C-API Util function rb_scan_args rejects the use of nil as a hash
22
fails:C-API Util function rb_scan_args does not reject non-symbol keys in keyword arguments
33
fails:C-API Util function rb_scan_args does not reject non-symbol keys in keyword arguments with required argument
44
fails:C-API Util function rb_scan_args considers keyword arguments with non-symbol keys as keywords when using splat and post arguments
5+
fails:C-API Util function rb_scan_args assigns optional arguments with no hash argument given and rejects the use of optional nil argument as a hash

0 commit comments

Comments
 (0)