summaryrefslogtreecommitdiff
path: root/bootstraptest/test_flow.rb
blob: 0390062a2435cc3a2200e3b6c3f471de083ffd8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
assert_equal %q{[1, 2, 4, 5, 6, 7, 8]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each{; $a << 2
    break; $a << 3
  }; $a << 4
  begin; $a << 5
  ensure; $a << 6
  end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 6, 7, 8]}, %q{$a = []; begin;  ; $a << 1
  begin; $a << 2
    [1,2].each do; $a << 3
      break; $a << 4
    end; $a << 5
  ensure; $a << 6
  end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{ok}, %q{
  ["a"].inject("ng"){|x,y|
    break :ok
  }
}
assert_equal %q{ok}, %q{
  unless ''.respond_to? :lines
    class String
      def lines
        self
      end
    end
  end

  ('a').lines.map{|e|
    break :ok
  }
}
assert_equal %q{[1, 2, 4, 5]}, %q{$a = []; begin; ; $a << 1
  ["a"].inject("ng"){|x,y|; $a << 2
    break :ok; $a << 3
  }; $a << 4
; $a << 5
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 4, 5]}, %q{$a = []; begin; ; $a << 1
  ('a'..'b').map{|e|; $a << 2
    break :ok; $a << 3
  }; $a << 4
; $a << 5
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 7, 8]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      break; $a << 4
    ensure; $a << 5
    end; $a << 6
  end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 9, 10]}, %q{$a = []; begin; ; $a << 1
  i=0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    begin; $a << 5
    ensure; $a << 6
      break; $a << 7
    end; $a << 8
  end; $a << 9
; $a << 10
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 7, 10, 11]}, %q{$a = []; begin; ; $a << 1
  i=0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    begin; $a << 5
      raise; $a << 6
    ensure; $a << 7
      break; $a << 8
    end; $a << 9
  end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 7, 10, 11]}, %q{$a = []; begin; ; $a << 1
  i=0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    begin; $a << 5
      raise; $a << 6
    rescue; $a << 7
      break; $a << 8
    end; $a << 9
  end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      raise StandardError; $a << 4
    ensure; $a << 5
      break; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      raise StandardError; $a << 4
    rescue; $a << 5
      break; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 6, 8, 10, 11]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      begin; $a << 4
        break; $a << 5
      ensure; $a << 6
      end; $a << 7
    ensure; $a << 8
    end; $a << 9
  end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15]}, %q{$a = []; begin; ; $a << 1
  i = 0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    j = 0; $a << 5
    while j<3; $a << 6
      j+=1; $a << 7
      begin; $a << 8
        raise; $a << 9
      rescue; $a << 10
        break; $a << 11
      end; $a << 12
    end; $a << 13
  end; $a << 14
; $a << 15
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 16, 17]}, %q{$a = []; begin; ; $a << 1
  i = 0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    j = 0; $a << 5
    while j<3; $a << 6
      j+=1; $a << 7
      1.times{; $a << 8
        begin; $a << 9
          raise; $a << 10
        rescue; $a << 11
          break; $a << 12
        end; $a << 13
      }; $a << 14
    end; $a << 15
  end; $a << 16
; $a << 17
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15]}, %q{$a = []; begin; ; $a << 1
  i = 0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    j = 0; $a << 5
    while j<3; $a << 6
      j+=1; $a << 7
      begin; $a << 8
        raise; $a << 9
      ensure; $a << 10
        break; $a << 11
      end; $a << 12
    end; $a << 13
  end; $a << 14
; $a << 15
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 3, 4, 5, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 6, 7, 8, 9, 11, 14, 15, 16, 17]}, %q{$a = []; begin; ; $a << 1
  i = 0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    j = 0; $a << 5
    while j<3; $a << 6
      j+=1; $a << 7
      1.times{; $a << 8
        begin; $a << 9
          raise; $a << 10
        ensure; $a << 11
          break; $a << 12
        end; $a << 13
      }; $a << 14
    end; $a << 15
  end; $a << 16
; $a << 17
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
  while true; $a << 2
    begin; $a << 3
      break; $a << 4
    ensure; $a << 5
      break; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 99]}, %q{
$a = [];
begin; ; $a << 1
  while true; $a << 2
    begin; $a << 3
      break; $a << 4
    ensure; $a << 5
      raise; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 6, 8, 9, 10, 11]}, %q{$a = []; begin;  ; $a << 1
  begin; $a << 2
    [1,2].each do; $a << 3
      begin; $a << 4
        break; $a << 5
      ensure; $a << 6
      end; $a << 7
    end; $a << 8
  ensure; $a << 9
  end; $a << 10
; $a << 11
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 4, 99]}, %q{$a = []; begin; ; $a << 1
  begin; $a << 2
    raise StandardError; $a << 3
  ensure; $a << 4
  end; $a << 5
; $a << 6
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4]}, %q{$a = []; begin;  ; $a << 1
  begin; $a << 2
  ensure; $a << 3
  end ; $a << 4
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 5, 99]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      break; $a << 4
    ensure; $a << 5
      raise StandardError; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{3}, %q{
  def m a, b
    a + b
  end
  m(1,
    while true
      break 2
    end
    )
}
assert_equal %q{4}, %q{
  def m a, b
    a + b
  end
  m(1,
    (i=0; while i<2
       i+=1
       class C
         next 2
       end
     end; 3)
    )
}
assert_equal %q{34}, %q{
  def m a, b
    a+b
  end
  m(1, 1.times{break 3}) +
  m(10, (1.times{next 3}; 20))
}
assert_equal %q{[1, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
  3.times{; $a << 2
    class C; $a << 3
      break; $a << 4
    end; $a << 5
  }; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
  3.times{; $a << 2
    class A; $a << 3
      class B; $a << 4
        break; $a << 5
      end; $a << 6
    end; $a << 7
  }; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 2, 3, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
  3.times{; $a << 2
    class C; $a << 3
      next; $a << 4
    end; $a << 5
  }; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 2, 3, 4, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
  3.times{; $a << 2
    class C; $a << 3
      class D; $a << 4
        next; $a << 5
      end; $a << 6
    end; $a << 7
  }; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 6, 7]}, %q{$a = []; begin; ; $a << 1
  while true; $a << 2
    class C; $a << 3
      break; $a << 4
    end; $a << 5
  end; $a << 6
; $a << 7
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 8, 9]}, %q{$a = []; begin; ; $a << 1
  while true; $a << 2
    class C; $a << 3
      class D; $a << 4
        break; $a << 5
      end; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
  i=0; $a << 2
  while i<3; $a << 3
    i+=1; $a << 4
    class C; $a << 5
      next 10; $a << 6
    end; $a << 7
  end; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{1}, %q{
  1.times{
    while true
      class C
        begin
          break
        ensure
          break
        end
      end
    end
  }
}
assert_equal %q{[1, 2, 3, 5, 2, 3, 5, 7, 8]}, %q{$a = []; begin;  ; $a << 1
  [1,2].each do; $a << 2
    begin; $a << 3
      next; $a << 4
    ensure; $a << 5
    end; $a << 6
  end; $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 2, 6, 3, 5, 7, 8]}, %q{$a = []; begin;  ; $a << 1
  o = "test"; $a << 2
  def o.test(a); $a << 3
    return a; $a << 4
  ensure; $a << 5
  end; $a << 6
  o.test(123); $a << 7
; $a << 8
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 4, 7, 5, 8, 9]}, %q{$a = []; begin; ; $a << 1
  def m1 *args; $a << 2
    ; $a << 3
  end; $a << 4
  def m2; $a << 5
    m1(:a, :b, (return 1; :c)); $a << 6
  end; $a << 7
  m2; $a << 8
; $a << 9
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 8, 2, 3, 4, 5, 9, 10]}, %q{$a = []; begin; ; $a << 1
  def m(); $a << 2
    begin; $a << 3
      2; $a << 4
    ensure; $a << 5
      return 3; $a << 6
    end; $a << 7
  end; $a << 8
  m; $a << 9
; $a << 10
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 3, 11, 4, 5, 6, 7, 12, 13]}, %q{$a = []; begin; ; $a << 1
  def m2; $a << 2
  end; $a << 3
  def m(); $a << 4
    m2(begin; $a << 5
         2; $a << 6
       ensure; $a << 7
         return 3; $a << 8
       end); $a << 9
    4; $a << 10
  end; $a << 11
  m(); $a << 12
; $a << 13
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[1, 16, 2, 3, 4, 5, 6, 7, 10, 11, 17, 18]}, %q{$a = []; begin; ; $a << 1
  def m; $a << 2
    1; $a << 3
    1.times{; $a << 4
      2; $a << 5
      begin; $a << 6
        3; $a << 7
        return; $a << 8
        4; $a << 9
      ensure; $a << 10
        5; $a << 11
      end; $a << 12
      6; $a << 13
    }; $a << 14
    7; $a << 15
  end; $a << 16
  m(); $a << 17
; $a << 18
; rescue Exception; $a << 99; end; $a}
assert_equal %q{[:ok, :ok2, :last]}, %q{
  a = []
  i = 0
  begin
    while i < 1
      i+=1
      begin
        begin
          next
        ensure
          a << :ok
        end
      ensure
        a << :ok2
      end
    end
  ensure
    a << :last
  end
  a
}
assert_equal %q{[:ok, :ok2, :last]}, %q{
  a = []
  i = 0
  begin
    while i < 1
      i+=1
      begin
        begin
          break
        ensure
          a << :ok
        end
      ensure
        a << :ok2
      end
    end
  ensure
    a << :last
  end
  a
}
assert_equal %q{[:ok, :ok2, :last]}, %q{
  a = []
  i = 0
  begin
    while i < 1
      if i>0
        break
      end
      i+=1
      begin
        begin
          redo
        ensure
          a << :ok
        end
      ensure
        a << :ok2
      end
    end
  ensure
    a << :last
  end
  a
}
assert_equal %Q{ENSURE\n}, %q{
  def test
    while true
      return
    end
  ensure
    puts("ENSURE")
  end
  test
}, '[ruby-dev:37967]'

[['[ruby-core:28129]', %q{
  class Bug2728
    include Enumerable
    define_method(:dynamic_method) do
      "dynamically defined method"
    end
    def each
      begin
        yield :foo
      ensure
        dynamic_method
      end
    end
  end
  e = Bug2728.new
}],
 ['[ruby-core:28132]', %q{
  class Bug2729
    include Enumerable
    def each
      begin
        yield :foo
      ensure
        proc {}.call
      end
    end
  end
  e = Bug2729.new
}],
 ['[ruby-core:39125]', %q{
  class Bug5234
    include Enumerable
    def each
      begin
        yield :foo
      ensure
        proc
      end
    end
  end
  e = Bug5234.new
}],
 ['[ruby-dev:45656]', %q{
  class Bug6460
    include Enumerable
    def each
      begin
        yield :foo
      ensure
        1.times { Proc.new }
      end
    end
  end
  e = Bug6460.new
}]].each do |bug, src|
  assert_equal "foo", src + %q{e.detect {true}}, bug
  assert_equal "true", src + %q{e.any? {true}}, bug
  assert_equal "false", src + %q{e.all? {false}}, bug
  assert_equal "true", src + %q{e.include?(:foo)}, bug
end

assert_equal "foo", %q{
  class Bug6460
    def m1
      m2 {|e|
        return e
      }
    end

    def m2
      begin
        yield :foo
      ensure
        begin
          begin
            yield :foo
          ensure
            Proc.new
            raise ''
          end
        rescue
        end
      end
    end
  end
  Bug6460.new.m1
}, '[ruby-dev:46372]'