|
194 | 194 | end
|
195 | 195 | end
|
196 | 196 |
|
| 197 | + describe "rb_hash_bulk_insert" do |
| 198 | + it 'inserts key-value pairs into the hash' do |
| 199 | + arr = [:a, 1, :b, 2, :c, 3] |
| 200 | + hash = {} |
| 201 | + |
| 202 | + @s.rb_hash_bulk_insert(hash, arr.length, arr) |
| 203 | + |
| 204 | + hash.should == {a: 1, b: 2, c: 3} |
| 205 | + end |
| 206 | + |
| 207 | + it 'overwrites existing keys' do |
| 208 | + arr = [:a, 4, :b, 5, :c, 6] |
| 209 | + hash = {a: 1, b: 2} |
| 210 | + |
| 211 | + @s.rb_hash_bulk_insert(hash, arr.length, arr) |
| 212 | + |
| 213 | + hash.should == {a: 4, b: 5, c: 6} |
| 214 | + end |
| 215 | + |
| 216 | + it 'raises an ArgumentError if the array length is not a multiple of 2' do |
| 217 | + arr = [:a, 1, :b, 2, :c] |
| 218 | + hash = {} |
| 219 | + |
| 220 | + -> { @s.rb_hash_bulk_insert(hash, arr.length, arr) }.should raise_error(ArgumentError) |
| 221 | + end |
| 222 | + |
| 223 | + it 'does not include any keys after the given length' do |
| 224 | + arr = [:a, 1, :b, 2, :c, 3, :d, 4] |
| 225 | + hash = {} |
| 226 | + |
| 227 | + @s.rb_hash_bulk_insert(hash, arr.length - 2, arr) |
| 228 | + |
| 229 | + hash.should == {a: 1, b: 2, c: 3} |
| 230 | + end |
| 231 | + |
| 232 | + it 'does not modify the hash if the length is zero' do |
| 233 | + arr = [] |
| 234 | + hash = {a: 1, b: 2} |
| 235 | + |
| 236 | + @s.rb_hash_bulk_insert(hash, arr.length, arr) |
| 237 | + |
| 238 | + hash.should == {a: 1, b: 2} |
| 239 | + end |
| 240 | + end |
| 241 | + |
197 | 242 | describe "rb_hash_size" do
|
198 | 243 | it "returns the size of the hash" do
|
199 | 244 | hsh = {fast: 'car', good: 'music'}
|
|
0 commit comments