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

@@ -1,15 +1,263 @@
1-# RedoNode -- `redo` re-runs the current iteration of the
2-# enclosing loop without re-evaluating the loop guard or
3-# advancing the iterator. Spinel emits a labeled goto back
4-# to the iteration top.
1+# RedoNode coverage — `redo` re-runs the current iteration of the
2+# enclosing loop without re-evaluating the guard or advancing the
3+# iterator. Spinel emits a labeled goto back to the iteration top.
4+# Each loop form needs the wrapping helper trio (push_redo_label /
5+# emit_redo_label / pop_redo_label) so this file exercises every
6+# form that has it.
7+#
8+# Per-section `def t_<form>; ...; end; t_<form>` isolates the
9+# `attempts` / `i` / `x` locals. Was 17 separate tests covering
10+# each loop form individually plus a nested case.
11+
12+# === times ===
13+def t_times
14+ attempts = 0
15+ 3.times do |i|
16+ attempts += 1
17+ if i == 1 && attempts < 5
18+ redo
19+ end
20+ puts "i=#{i} attempt=#{attempts}"
21+ end
22+ puts "total=#{attempts}"
23+end
24+t_times
25+
26+# === Array#each ===
27+def t_each
28+ attempts = 0
29+ [10, 20, 30].each do |x|
30+ attempts += 1
31+ if x == 20 && attempts < 5
32+ redo
33+ end
34+ puts "x=#{x} attempt=#{attempts}"
35+ end
36+ puts "total=#{attempts}"
37+end
38+t_each
39+
40+# === while ===
41+def t_while
42+ i = 0
43+ attempts = 0
44+ while i < 3
45+ attempts += 1
46+ if i == 1 && attempts < 5
47+ redo
48+ end
49+ puts "i=#{i} attempt=#{attempts}"
50+ i += 1
51+ end
52+ puts "total=#{attempts}"
53+end
54+t_while
55+
56+# === until ===
57+def t_until
58+ i = 0
59+ attempts = 0
60+ until i >= 3
61+ attempts += 1
62+ if i == 1 && attempts < 5
63+ redo
64+ end
65+ puts "i=#{i} attempt=#{attempts}"
66+ i += 1
67+ end
68+ puts "total=#{attempts}"
69+end
70+t_until
71+
72+# === for-in over range ===
73+def t_for_range
74+ attempts = 0
75+ for i in 0..2
76+ attempts += 1
77+ if i == 1 && attempts < 5
78+ redo
79+ end
80+ puts "i=#{i} attempt=#{attempts}"
81+ end
82+ puts "total=#{attempts}"
83+end
84+t_for_range
85+
86+# === for-in over array ===
87+def t_for_array
88+ attempts = 0
89+ for x in [10, 20, 30]
90+ attempts += 1
91+ if x == 20 && attempts < 5
92+ redo
93+ end
94+ puts "x=#{x} attempt=#{attempts}"
95+ end
96+ puts "total=#{attempts}"
97+end
98+t_for_array
99+
100+# === Kernel#loop (uses break to terminate) ===
101+def t_loop
102+ i = 0
103+ attempts = 0
104+ loop do
105+ attempts += 1
106+ if i == 1 && attempts < 5
107+ redo
108+ end
109+ puts "i=#{i} attempt=#{attempts}"
110+ i += 1
111+ break if i >= 3
112+ end
113+ puts "total=#{attempts}"
114+end
115+t_loop
116+
117+# === Integer#upto ===
118+def t_upto
119+ attempts = 0
120+ 0.upto(2) do |i|
121+ attempts += 1
122+ if i == 1 && attempts < 5
123+ redo
124+ end
125+ puts "i=#{i} attempt=#{attempts}"
126+ end
127+ puts "total=#{attempts}"
128+end
129+t_upto
130+
131+# === Integer#downto ===
132+def t_downto
133+ attempts = 0
134+ 2.downto(0) do |i|
135+ attempts += 1
136+ if i == 1 && attempts < 5
137+ redo
138+ end
139+ puts "i=#{i} attempt=#{attempts}"
140+ end
141+ puts "total=#{attempts}"
142+end
143+t_downto
144+
145+# === Integer#step ===
146+def t_step
147+ attempts = 0
148+ 0.step(4, 2) do |i|
149+ attempts += 1
150+ if i == 2 && attempts < 5
151+ redo
152+ end
153+ puts "i=#{i} attempt=#{attempts}"
154+ end
155+ puts "total=#{attempts}"
156+end
157+t_step
158+
159+# === Array#each_with_index ===
160+def t_each_with_index
161+ attempts = 0
162+ ["a", "b", "c"].each_with_index do |x, i|
163+ attempts += 1
164+ if i == 1 && attempts < 5
165+ redo
166+ end
167+ puts "x=#{x} i=#{i} attempt=#{attempts}"
168+ end
169+ puts "total=#{attempts}"
170+end
171+t_each_with_index
172+
173+# === Array#each_cons ===
174+def t_each_cons
175+ attempts = 0
176+ [1, 2, 3, 4].each_cons(2) do |pair|
177+ attempts += 1
178+ if pair[0] == 2 && attempts < 5
179+ redo
180+ end
181+ puts "pair=#{pair.inspect} attempt=#{attempts}"
182+ end
183+ puts "total=#{attempts}"
184+end
185+t_each_cons
186+
187+# === Array#each_slice ===
188+def t_each_slice
189+ attempts = 0
190+ [1, 2, 3, 4, 5].each_slice(2) do |chunk|
191+ attempts += 1
192+ if chunk[0] == 3 && attempts < 5
193+ redo
194+ end
195+ puts "chunk=#{chunk.inspect} attempt=#{attempts}"
196+ end
197+ puts "total=#{attempts}"
198+end
199+t_each_slice
200+
201+# === Array#each_with_object ===
202+def t_each_with_object
203+ attempts = 0
204+ result = [1, 2, 3].each_with_object([]) do |x, acc|
205+ attempts += 1
206+ if x == 2 && attempts < 5
207+ redo
208+ end
209+ acc << x * 10
210+ end
211+ puts result.inspect
212+ puts "total=#{attempts}"
213+end
214+t_each_with_object
215+
216+# === Array#zip iteration ===
217+def t_zip
218+ attempts = 0
219+ [1, 2, 3].zip([10, 20, 30]) do |a, b|
220+ attempts += 1
221+ if a == 2 && attempts < 5
222+ redo
223+ end
224+ puts "a=#{a} b=#{b} attempt=#{attempts}"
225+ end
226+ puts "total=#{attempts}"
227+end
228+t_zip
229+
230+# === Array#cycle (with count to terminate) ===
231+def t_cycle
232+ attempts = 0
233+ [1, 2].cycle(2) do |x|
234+ attempts += 1
235+ if x == 1 && attempts < 3
236+ redo
237+ end
238+ puts "x=#{x} attempt=#{attempts}"
239+ end
240+ puts "total=#{attempts}"
241+end
242+t_cycle
5243
6-# A counter prevents infinite redo: redo only on the first attempt
7-attempts = 0
8-3.times do |i|
9- attempts += 1
10- if i == 1 && attempts < 5
11- redo
244+# === Nested redo (mixed loop kinds) — exercises label-stack uniqueness ===
245+def t_nested
246+ inner_attempts = 0
247+ outer_done = 0
248+ i = 0
249+ while i < 2
250+ outer_done += 1
251+ 3.times do |j|
252+ inner_attempts += 1
253+ if i == 0 && j == 1 && inner_attempts < 4
254+ redo
255+ end
256+ puts "i=#{i} j=#{j} attempt=#{inner_attempts}"
257+ end
258+ i += 1
12259 end
13- puts "i=#{i} attempt=#{attempts}"
260+ puts "outer_done=#{outer_done}"
261+ puts "inner_attempts=#{inner_attempts}"
14262 end
15-puts "total=#{attempts}"
263+t_nested