|
154 | 154 | end
|
155 | 155 | end
|
156 | 156 |
|
| 157 | + describe "rb_get_kwargs" do |
| 158 | + it "extracts required arguments in the order requested" do |
| 159 | + h = { :a => 7, :b => 5 } |
| 160 | + @o.rb_get_kwargs(h, [:b, :a], 2, 0).should == [5, 7] |
| 161 | + h.should == {} |
| 162 | + end |
| 163 | + |
| 164 | + it "extracts required and optional arguments in the order requested" do |
| 165 | + h = { :a => 7, :c => 12, :b => 5 } |
| 166 | + @o.rb_get_kwargs(h, [:b, :a, :c], 2, 1).should == [5, 7, 12] |
| 167 | + h.should == {} |
| 168 | + end |
| 169 | + |
| 170 | + it "accepts nil instead of a hash when only optional arguments are requested" do |
| 171 | + h = nil |
| 172 | + @o.rb_get_kwargs(h, [:b, :a, :c], 0, 3).should == [] |
| 173 | + h.should == nil |
| 174 | + end |
| 175 | + |
| 176 | + it "raises an error if a required argument is not in the hash" do |
| 177 | + h = { :a => 7, :c => 12, :b => 5 } |
| 178 | + lambda { @o.rb_get_kwargs(h, [:b, :d], 2, 0) }.should raise_error(ArgumentError, /missing keyword: d/) |
| 179 | + h.should == {:a => 7, :c => 12} |
| 180 | + end |
| 181 | + |
| 182 | + it "does not raise an error for an optional argument not in the hash" do |
| 183 | + h = { :a => 7, :b => 5 } |
| 184 | + @o.rb_get_kwargs(h, [:b, :a, :c], 2, 1).should == [5, 7] |
| 185 | + h.should == {} |
| 186 | + end |
| 187 | + |
| 188 | + it "raises an error if there are additional arguments and optional is positive" do |
| 189 | + h = { :a => 7, :c => 12, :b => 5 } |
| 190 | + lambda { @o.rb_get_kwargs(h, [:b, :a], 2, 0) }.should raise_error(ArgumentError, /unknown keyword: c/) |
| 191 | + h.should == {:c => 12} |
| 192 | + end |
| 193 | + |
| 194 | + it "leaves additional arguments in the hash if optional is negative" do |
| 195 | + h = { :a => 7, :c => 12, :b => 5 } |
| 196 | + @o.rb_get_kwargs(h, [:b, :a], 2, -1).should == [5, 7] |
| 197 | + h.should == {:c => 12} |
| 198 | + end |
| 199 | + end |
| 200 | + |
157 | 201 | platform_is wordsize: 64 do
|
158 | 202 | describe "rb_long2int" do
|
159 | 203 | it "raises a RangeError if the value is outside the range of a C int" do
|
|
0 commit comments