2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-11-29 23:21:26 -05:00
|
|
|
require 'test/unit'
|
|
|
|
require '-test-/iter'
|
|
|
|
|
|
|
|
module TestIter
|
|
|
|
end
|
|
|
|
|
|
|
|
class TestIter::YieldBlock < Test::Unit::TestCase
|
|
|
|
class YieldTest
|
|
|
|
include Bug::Iter::Yield
|
|
|
|
attr_reader :blockarg
|
|
|
|
def test(arg, &block)
|
|
|
|
block.call(arg) {|blockarg| @blockarg = blockarg}
|
|
|
|
end
|
2017-01-01 03:22:02 -05:00
|
|
|
def call_proc(&block)
|
|
|
|
block.call {}
|
|
|
|
end
|
|
|
|
def call_lambda(&block)
|
|
|
|
block.call &->{}
|
|
|
|
end
|
2013-11-29 23:21:26 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_yield_block
|
|
|
|
a = YieldTest.new
|
|
|
|
a.yield_block(:test, "foo") {|x, &b| assert_kind_of(Proc, b); b.call(x)}
|
|
|
|
assert_equal("foo", a.blockarg)
|
|
|
|
end
|
2017-01-01 03:22:02 -05:00
|
|
|
|
|
|
|
def test_yield_lambda
|
|
|
|
a = YieldTest.new
|
|
|
|
assert_not_predicate a.yield_block(:call_proc) {|&b| b}, :lambda?
|
|
|
|
assert_predicate a.yield_block(:call_lambda) {|&b| b}, :lambda?
|
|
|
|
end
|
2013-11-29 23:21:26 -05:00
|
|
|
end
|