diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2023-09-07 10:57:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-07 10:57:52 -0700 |
commit | 5b5ae3d9e064e17e2a7d8d21d739fcc62ae1075c (patch) | |
tree | fde0e41fdd741cac9434969fa2d2a2df0d90e7e5 /test | |
parent | 4efcaf956e27df365a1cf9e0cbb8d9a68eeb6995 (diff) |
Rewrite Integer#times in Ruby (#8388)
Notes
Notes:
Merged-By: k0kubun <takashikkbn@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_backtrace.rb | 6 | ||||
-rw-r--r-- | test/ruby/test_integer.rb | 23 | ||||
-rw-r--r-- | test/ruby/test_settracefunc.rb | 18 |
3 files changed, 29 insertions, 18 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb index bb0562c0bb..d35dead95b 100644 --- a/test/ruby/test_backtrace.rb +++ b/test/ruby/test_backtrace.rb @@ -215,15 +215,15 @@ class TestBacktrace < Test::Unit::TestCase @res = caller_locations(2, 1).inspect end @line = __LINE__ + 1 - 1.times.map { 1.times.map { foo } } - assert_equal("[\"#{__FILE__}:#{@line}:in `times'\"]", @res) + [1].map.map { [1].map.map { foo } } + assert_equal("[\"#{__FILE__}:#{@line}:in `map'\"]", @res) end def test_caller_location_path_cfunc_iseq_no_pc def self.foo @res = caller_locations(2, 1)[0].path end - 1.times.map { 1.times.map { foo } } + [1].map.map { [1].map.map { foo } } assert_equal(__FILE__, @res) end diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 3e8d68702c..31cb8d6cf5 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -321,23 +321,34 @@ class TestInteger < Test::Unit::TestCase begin; called = false Integer.class_eval do - alias old_plus + - undef + - define_method(:+){|x| called = true; 1} + alias old_succ succ + undef succ + define_method(:succ){|x| called = true; x+1} alias old_lt < undef < define_method(:<){|x| called = true} end + + fix = 1 + fix.times{break 0} + fix_called = called + + called = false + big = 2**65 big.times{break 0} + big_called = called + Integer.class_eval do - undef + - alias + old_plus + undef succ + alias succ old_succ undef < alias < old_lt end + + # Asssert that Fixnum and Bignum behave consistently bug18377 = "[ruby-core:106361]" - assert_equal(false, called, bug18377) + assert_equal(fix_called, big_called, bug18377) end; end diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 3641bd0916..76891e3c97 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -504,7 +504,7 @@ class TestSetTraceFunc < Test::Unit::TestCase 1: trace = TracePoint.trace(*trace_events){|tp| next if !target_thread? 2: events << [tp.event, tp.lineno, tp.path, _defined_class.(tp), tp.method_id, tp.self, tp.binding&.eval("_local_var"), _get_data.(tp)] if tp.path == 'xyzzy' 3: } - 4: 1.times{|;_local_var| _local_var = :inner + 4: [1].each{|;_local_var| _local_var = :inner 5: tap{} 6: } 7: class XYZZY @@ -531,10 +531,10 @@ class TestSetTraceFunc < Test::Unit::TestCase answer_events = [ # [:line, 4, 'xyzzy', self.class, method, self, :outer, :nothing], - [:c_call, 4, 'xyzzy', Integer, :times, 1, nil, :nothing], + [:c_call, 4, 'xyzzy', Array, :each, [1], nil, :nothing], [:line, 4, 'xyzzy', self.class, method, self, nil, :nothing], [:line, 5, 'xyzzy', self.class, method, self, :inner, :nothing], - [:c_return, 4, "xyzzy", Integer, :times, 1, nil, 1], + [:c_return, 4, "xyzzy", Array, :each, [1], nil, [1]], [:line, 7, 'xyzzy', self.class, method, self, :outer, :nothing], [:c_call, 7, "xyzzy", Module, :const_added, TestSetTraceFunc, nil, :nothing], [:c_return, 7, "xyzzy", Module, :const_added, TestSetTraceFunc, nil, nil], @@ -639,7 +639,7 @@ CODE 1: set_trace_func(lambda{|event, file, line, id, binding, klass| 2: events << [event, line, file, klass, id, binding&.eval('self'), binding&.eval("_local_var")] if file == 'xyzzy' 3: }) - 4: 1.times{|;_local_var| _local_var = :inner + 4: [1].map{|;_local_var| _local_var = :inner 5: tap{} 6: } 7: class XYZZY @@ -994,7 +994,7 @@ CODE /return/ =~ tp.event ? tp.return_value : nil ] }.enable{ - 1.times{ + [1].map{ 3 } method_for_test_tracepoint_block{ @@ -1004,10 +1004,10 @@ CODE # pp events # expected_events = [[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], - [:c_call, :times, Integer, Integer, nil], + [:c_call, :map, Array, Array, nil], [:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 3], - [:c_return, :times, Integer, Integer, 1], + [:c_return, :map, Array, Array, [3]], [:call, :method_for_test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil], [:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 4], @@ -1310,7 +1310,7 @@ CODE next if !target_thread? events << tp.event }.enable{ - 1.times{ + [1].map{ 3 } method_for_test_tracepoint_block{ @@ -1332,7 +1332,7 @@ CODE next if !target_thread? events << tp.event }.enable{ - 1.times{ + [1].map{ 3 } method_for_test_tracepoint_block{ |