1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/optional/capi/fiber_spec.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

2021-07-29 16:11:21 -04:00
require_relative 'spec_helper'
require 'fiber'
load_extension('fiber')
describe "C-API Fiber function" do
before :each do
@s = CApiFiberSpecs.new
end
describe "rb_fiber_current" do
it "returns the current fiber" do
result = @s.rb_fiber_current()
result.should be_an_instance_of(Fiber)
result.should == Fiber.current
end
end
describe "rb_fiber_alive_p" do
it "returns the fibers alive status" do
fiber = Fiber.new { Fiber.yield }
fiber.resume
@s.rb_fiber_alive_p(fiber).should be_true
fiber.resume
@s.rb_fiber_alive_p(fiber).should be_false
end
end
describe "rb_fiber_resume" do
it "resumes the fiber" do
fiber = Fiber.new { |arg| Fiber.yield arg }
@s.rb_fiber_resume(fiber, [1]).should == 1
@s.rb_fiber_resume(fiber, [2]).should == 2
end
end
describe "rb_fiber_yield" do
it "yields the fiber" do
fiber = Fiber.new { @s.rb_fiber_yield([1]) }
fiber.resume.should == 1
end
end
describe "rb_fiber_new" do
it "returns a new fiber" do
fiber = @s.rb_fiber_new
fiber.should be_an_instance_of(Fiber)
fiber.resume(42).should == "42"
end
end
end