Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added back Hash::Iterator because it's used in C-API.
- Loading branch information
Brian Ford
committed
Aug 1, 2011
1 parent
a4f6089
commit 59c5b96
Showing
6 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.expand_path('../../../../spec_helper', __FILE__) | ||
|
||
with_feature :hash_bucket do | ||
describe "Hash::Iterator#index" do | ||
ruby_version_is ""..."1.9" do | ||
it "returns the index of the last object returned by #next" do | ||
h = Hash.new | ||
a = Hash::Bucket.new 1, 2, 3 | ||
b = Hash::Bucket.new 4, 5, 6 | ||
e = h.instance_variable_get :@entries | ||
e[2] = a | ||
e[4] = b | ||
|
||
iter = h.to_iter | ||
|
||
(entry = iter.next(entry)).should == a | ||
(entry = iter.next(entry)).should == b | ||
|
||
iter.index.should == 4 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require File.expand_path('../../../../spec_helper', __FILE__) | ||
|
||
with_feature :hash_bucket do | ||
describe "Hash::Iterator.new" do | ||
ruby_version_is ""..."1.9" do | ||
it "initializes the iterator" do | ||
h = Hash[:a => 1, :b => 2] | ||
entries = h.instance_variable_get :@entries | ||
iter = h.to_iter | ||
iter.instance_variable_get(:@entries).should == entries | ||
iter.instance_variable_get(:@capacity).should == entries.size | ||
iter.instance_variable_get(:@index).should == -1 | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require File.expand_path('../../../../spec_helper', __FILE__) | ||
|
||
with_feature :hash_bucket do | ||
describe "Hash::Iterator#next" do | ||
before :each do | ||
ScratchPad.record [] | ||
end | ||
|
||
ruby_version_is ""..."1.9" do | ||
it "returns each non-nil entry from the storage vector" do | ||
h = Hash.new | ||
a = Hash::Bucket.new 1, 2, 3 | ||
b = Hash::Bucket.new 4, 5, 6 | ||
c = Hash::Bucket.new 7, 8, 9 | ||
e = h.instance_variable_get :@entries | ||
e[2] = a | ||
e[4] = b | ||
e[7] = c | ||
|
||
iter = h.to_iter | ||
|
||
while entry = iter.next(entry) | ||
ScratchPad << entry | ||
end | ||
ScratchPad.recorded.should == [a, b, c] | ||
end | ||
end | ||
|
||
ruby_version_is "1.9" do | ||
it "returns each entry in the Hash" do | ||
h = Hash[:a, 1, :b, 2, :c, 3] | ||
iter = h.to_iter | ||
|
||
while entry = iter.next(entry) | ||
ScratchPad << entry.key | ||
end | ||
ScratchPad.recorded.should == [:a, :b, :c] | ||
end | ||
end | ||
end | ||
end | ||
|
||
with_feature :hash_hamt do | ||
describe "Hash::Iterator#next" do | ||
before :each do | ||
ScratchPad.record [] | ||
end | ||
|
||
it "returns each entry in the Hash" do | ||
h = Hash[:a, 1, :b, 2, :c, 3] | ||
iter = h.to_iter | ||
|
||
while entry = iter.next(entry) | ||
ScratchPad << entry.key | ||
end | ||
ScratchPad.recorded.should == [:a, :b, :c] | ||
end | ||
end | ||
end |