diff options
Diffstat (limited to 'test/ruby/test_iterator.rb')
| -rw-r--r-- | test/ruby/test_iterator.rb | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 4a9cfe46f0..820d5591c1 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -12,17 +12,12 @@ class Array end class TestIterator < Test::Unit::TestCase - def ttt - assert(iterator?) - end - - def test_iterator - assert(!iterator?) - - ttt{} - - # yield at top level !! here's not toplevel - assert(!defined?(yield)) + def test_yield_at_toplevel + assert_separately([],"#{<<~"begin;"}\n#{<<~'end;'}") + begin; + assert(!block_given?) + assert(!defined?(yield)) + end; end def test_array @@ -107,6 +102,16 @@ class TestIterator < Test::Unit::TestCase assert_equal([1, 2, 3, 4, 5, 6, 7], x) end + def test_array_for_masgn + a = [Struct.new(:to_ary).new([1,2])] + x = [] + a.each {|i,j|x << [i,j]} + assert_equal([[1,2]], x) + x = [] + for i,j in a; x << [i,j]; end + assert_equal([[1,2]], x) + end + def test_append_method_to_built_in_class x = [[1,2],[3,4],[5,6]] assert_equal(x.iter_test1{|e|e}, x.iter_test2{|e|e}) @@ -279,6 +284,9 @@ class TestIterator < Test::Unit::TestCase def proc_call(&b) b.call end + def proc_call2(b) + b.call + end def proc_yield() yield end @@ -300,6 +308,7 @@ class TestIterator < Test::Unit::TestCase def test_ljump assert_raise(LocalJumpError) {get_block{break}.call} + assert_raise(LocalJumpError) {proc_call2(get_block{break}){}} # cannot use assert_nothing_raised due to passing block. begin @@ -330,8 +339,7 @@ class TestIterator < Test::Unit::TestCase marity_test(:marity_test) marity_test(:p) - lambda(&method(:assert)).call(true) - lambda(&get_block{|a,n| assert(a,n)}).call(true, "marity") + get_block{|a,n| assert(a,n)}.call(true, "marity") end def foo |
