Debian Codegraph @

test/-ext-/iter/test_yield_block.rb

raw
1 # frozen_string_literal: false
2 require 'test/unit'
3 require '-test-/iter'
4
5 module TestIter
6 end
7
8 class TestIter::YieldBlock < Test::Unit::TestCase
9 class YieldTest
10 include Bug::Iter::Yield
11 attr_reader :blockarg
12 def test(arg, &block)
13 block.call(arg) {|blockarg| @blockarg = blockarg}
14 end
15 def call_proc(&block)
16 block.call {}
17 end
18 def call_lambda(&block)
19 block.call(&->{})
20 end
21 end
22
23 def test_yield_block
24 a = YieldTest.new
25 a.yield_block(:test, "foo") {|x, &b| assert_kind_of(Proc, b); b.call(x)}
26 assert_equal("foo", a.blockarg)
27 end
28
29 def test_yield_lambda
30 a = YieldTest.new
31 assert_not_predicate a.yield_block(:call_proc) {|&b| b}, :lambda?
32 assert_predicate a.yield_block(:call_lambda) {|&b| b}, :lambda?
33 end
34 end