Commit 93a5db6f
93a5db6f3426Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 34 files · ~2 modified · -32 deleted
Description
test: collapse 17 redo_* tests into one redo.rb
PR #283 added redo support for every loop form (times / each /
while / until / for / loop / upto / downto / step / each_with_*
/ each_cons / each_slice / zip / cycle) with one .rb per form
plus a nested case. All 17 follow the exact same shape: an
attempts counter + a redo guard + per-iteration prints. Merge
into one file with each section wrapped in def t_<form>; ...; end; t_<form> so the per-section locals stay isolated.
17 .rb → 1. ~19s saved on Windows test step at the ~1.2s/test rate. The merged file is ~225 lines but each section is self- contained and clearly delimited.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 93a5db6f3426
- Parent
- abe0cdc196ba
test/redo.rbmodifiedView file
# RedoNode -- `redo` re-runs the current iteration of the# enclosing loop without re-evaluating the loop guard or# advancing the iterator. Spinel emits a labeled goto back# to the iteration top.# RedoNode coverage — `redo` re-runs the current iteration of the# enclosing loop without re-evaluating the guard or advancing the# iterator. Spinel emits a labeled goto back to the iteration top.# Each loop form needs the wrapping helper trio (push_redo_label /# emit_redo_label / pop_redo_label) so this file exercises every# form that has it.## Per-section `def t_<form>; ...; end; t_<form>` isolates the# `attempts` / `i` / `x` locals. Was 17 separate tests covering# each loop form individually plus a nested case.# === times ===def t_times attempts = 0 3.times do |i| attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_times# === Array#each ===def t_each attempts = 0 [10, 20, 30].each do |x| attempts += 1 if x == 20 && attempts < 5 redo end puts "x=#{x} attempt=#{attempts}" end puts "total=#{attempts}"endt_each# === while ===def t_while i = 0 attempts = 0 while i < 3 attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" i += 1 end puts "total=#{attempts}"endt_while# === until ===def t_until i = 0 attempts = 0 until i >= 3 attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" i += 1 end puts "total=#{attempts}"endt_until# === for-in over range ===def t_for_range attempts = 0 for i in 0..2 attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_for_range# === for-in over array ===def t_for_array attempts = 0 for x in [10, 20, 30] attempts += 1 if x == 20 && attempts < 5 redo end puts "x=#{x} attempt=#{attempts}" end puts "total=#{attempts}"endt_for_array# === Kernel#loop (uses break to terminate) ===def t_loop i = 0 attempts = 0 loop do attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" i += 1 break if i >= 3 end puts "total=#{attempts}"endt_loop# === Integer#upto ===def t_upto attempts = 0 0.upto(2) do |i| attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_upto# === Integer#downto ===def t_downto attempts = 0 2.downto(0) do |i| attempts += 1 if i == 1 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_downto# === Integer#step ===def t_step attempts = 0 0.step(4, 2) do |i| attempts += 1 if i == 2 && attempts < 5 redo end puts "i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_step# === Array#each_with_index ===def t_each_with_index attempts = 0 ["a", "b", "c"].each_with_index do |x, i| attempts += 1 if i == 1 && attempts < 5 redo end puts "x=#{x} i=#{i} attempt=#{attempts}" end puts "total=#{attempts}"endt_each_with_index# === Array#each_cons ===def t_each_cons attempts = 0 [1, 2, 3, 4].each_cons(2) do |pair| attempts += 1 if pair[0] == 2 && attempts < 5 redo end puts "pair=#{pair.inspect} attempt=#{attempts}" end puts "total=#{attempts}"endt_each_cons# === Array#each_slice ===def t_each_slice attempts = 0 [1, 2, 3, 4, 5].each_slice(2) do |chunk| attempts += 1 if chunk[0] == 3 && attempts < 5 redo end puts "chunk=#{chunk.inspect} attempt=#{attempts}" end puts "total=#{attempts}"endt_each_slice# === Array#each_with_object ===def t_each_with_object attempts = 0 result = [1, 2, 3].each_with_object([]) do |x, acc| attempts += 1 if x == 2 && attempts < 5 redo end acc << x * 10 end puts result.inspect puts "total=#{attempts}"endt_each_with_object# === Array#zip iteration ===def t_zip attempts = 0 [1, 2, 3].zip([10, 20, 30]) do |a, b| attempts += 1 if a == 2 && attempts < 5 redo end puts "a=#{a} b=#{b} attempt=#{attempts}" end puts "total=#{attempts}"endt_zip# === Array#cycle (with count to terminate) ===def t_cycle attempts = 0 [1, 2].cycle(2) do |x| attempts += 1 if x == 1 && attempts < 3 redo end puts "x=#{x} attempt=#{attempts}" end puts "total=#{attempts}"endt_cycle# A counter prevents infinite redo: redo only on the first attemptattempts = 03.times do |i| attempts += 1 if i == 1 && attempts < 5 redo# === Nested redo (mixed loop kinds) — exercises label-stack uniqueness ===def t_nested inner_attempts = 0 outer_done = 0 i = 0 while i < 2 outer_done += 1 3.times do |j| inner_attempts += 1 if i == 0 && j == 1 && inner_attempts < 4 redo end puts "i=#{i} j=#{j} attempt=#{inner_attempts}" end i += 1 end puts "i=#{i} attempt=#{attempts}" puts "outer_done=#{outer_done}" puts "inner_attempts=#{inner_attempts}"endputs "total=#{attempts}"t_nestedtest/redo.rb.expectedmodifiedView file
Loading diff…
test/redo_cycle.rbdeleted
Loading diff…
test/redo_cycle.rb.expecteddeleted
Loading diff…
test/redo_downto.rbdeleted
Loading diff…
test/redo_downto.rb.expecteddeleted
Loading diff…
test/redo_each.rbdeleted
Loading diff…
test/redo_each.rb.expecteddeleted
Loading diff…
test/redo_each_cons.rbdeleted
Loading diff…
test/redo_each_cons.rb.expecteddeleted
Loading diff…
test/redo_each_slice.rbdeleted
Loading diff…
test/redo_each_slice.rb.expecteddeleted
Loading diff…
test/redo_each_with_index.rbdeleted
Loading diff…
test/redo_each_with_index.rb.expecteddeleted
Loading diff…
test/redo_each_with_object.rbdeleted
Loading diff…
test/redo_each_with_object.rb.expecteddeleted
Loading diff…
test/redo_for_array.rbdeleted
Loading diff…
test/redo_for_array.rb.expecteddeleted
Loading diff…
test/redo_for_range.rbdeleted
Loading diff…
test/redo_for_range.rb.expecteddeleted
Loading diff…
test/redo_loop.rbdeleted
Loading diff…
test/redo_loop.rb.expecteddeleted
Loading diff…
test/redo_nested.rbdeleted
Loading diff…
test/redo_nested.rb.expecteddeleted
Loading diff…
test/redo_step.rbdeleted
Loading diff…
test/redo_step.rb.expecteddeleted
Loading diff…
test/redo_until.rbdeleted
Loading diff…
test/redo_until.rb.expecteddeleted
Loading diff…
test/redo_upto.rbdeleted
Loading diff…
test/redo_upto.rb.expecteddeleted
Loading diff…
test/redo_while.rbdeleted
Loading diff…
test/redo_while.rb.expecteddeleted
Loading diff…
test/redo_zip.rbdeleted
Loading diff…
test/redo_zip.rb.expecteddeleted
Loading diff…