summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/array_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/optional/capi/array_spec.rb')
-rw-r--r--spec/ruby/optional/capi/array_spec.rb44
1 files changed, 40 insertions, 4 deletions
diff --git a/spec/ruby/optional/capi/array_spec.rb b/spec/ruby/optional/capi/array_spec.rb
index 8d003fb2b1..7e87859856 100644
--- a/spec/ruby/optional/capi/array_spec.rb
+++ b/spec/ruby/optional/capi/array_spec.rb
@@ -343,10 +343,46 @@ describe "C-API Array function" do
end
end
- describe "rb_iterate" do
+ ruby_version_is ""..."4.0" do
+ describe "rb_iterate" do
+ it "calls an callback function as a block passed to an method" do
+ s = [1,2,3,4]
+ s2 = @s.rb_iterate(s)
+
+ s2.should == s
+
+ # Make sure they're different objects
+ s2.equal?(s).should be_false
+ end
+
+ it "calls a function with the other function available as a block" do
+ h = {a: 1, b: 2}
+
+ @s.rb_iterate_each_pair(h).sort.should == [1,2]
+ end
+
+ it "calls a function which can yield into the original block" do
+ s2 = []
+
+ o = Object.new
+ def o.each
+ yield 1
+ yield 2
+ yield 3
+ yield 4
+ end
+
+ @s.rb_iterate_then_yield(o) { |x| s2 << x }
+
+ s2.should == [1,2,3,4]
+ end
+ end
+ end
+
+ describe "rb_block_call" do
it "calls an callback function as a block passed to an method" do
s = [1,2,3,4]
- s2 = @s.rb_iterate(s)
+ s2 = @s.rb_block_call(s)
s2.should == s
@@ -357,7 +393,7 @@ describe "C-API Array function" do
it "calls a function with the other function available as a block" do
h = {a: 1, b: 2}
- @s.rb_iterate_each_pair(h).sort.should == [1,2]
+ @s.rb_block_call_each_pair(h).sort.should == [1,2]
end
it "calls a function which can yield into the original block" do
@@ -371,7 +407,7 @@ describe "C-API Array function" do
yield 4
end
- @s.rb_iterate_then_yield(o) { |x| s2 << x }
+ @s.rb_block_call_then_yield(o) { |x| s2 << x }
s2.should == [1,2,3,4]
end