Commit 7ccaabf5

7ccaabf5083fMerged

ydah <[email protected]> · 6 months ago · 2 files · ~2 modified

Description

test(codegen): cover while length refresh variants

Details

Commit
7ccaabf5083f
Parent
22ec169361cc

test/while_condition_recomputed.rbmodifiedView file

@@ -11,3 +11,45 @@
1111
1212 puts sum
1313 puts items.length
14+
15+items2 = [4, 5, 6]
16+sum2 = 0
17+
18+while items2.length > 0
19+ sum2 += items2.pop
20+end
21+
22+puts sum2
23+puts items2.length
24+
25+items3 = [7, 8, 9]
26+packed = 0
27+
28+while items3.length != 0
29+ packed = packed * 10 + items3.shift
30+end
31+
32+puts packed
33+puts items3.length
34+
35+class IvarDrain
36+ def initialize
37+ @items = [10, 20, 30]
38+ end
39+
40+ def drain
41+ sum = 0
42+ while @items.length > 0
43+ sum += @items.pop
44+ end
45+ sum
46+ end
47+
48+ def remaining
49+ @items.length
50+ end
51+end
52+
53+drain = IvarDrain.new
54+puts drain.drain
55+puts drain.remaining