diff options
Diffstat (limited to 'test/ruby/test_iterator.rb')
| -rw-r--r-- | test/ruby/test_iterator.rb | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 34652db2bb..ebfb60354a 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false require 'test/unit' class Array @@ -73,7 +74,7 @@ class TestIterator < Test::Unit::TestCase def test_break done = true loop{ - break + break if true done = false # should not reach here } assert(done) @@ -83,7 +84,7 @@ class TestIterator < Test::Unit::TestCase loop { break if done done = true - next + next if true bad = true # should not reach here } assert(!bad) @@ -93,7 +94,7 @@ class TestIterator < Test::Unit::TestCase loop { break if done done = true - redo + redo if true bad = true # should not reach here } assert(!bad) @@ -106,9 +107,19 @@ 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{|x|x}, x.iter_test2{|x|x}) + assert_equal(x.iter_test1{|e|e}, x.iter_test2{|e|e}) end class IterTest @@ -278,6 +289,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 @@ -299,6 +313,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 |
