PageRenderTime 36ms CodeModel.GetById 11ms app.highlight 21ms RepoModel.GetById 1ms app.codeStats 1ms

/IronPython_Main/Languages/Ruby/Tests/Compat/gen_ctrl_flow.rb

#
Ruby | 167 lines | 120 code | 26 blank | 21 comment | 18 complexity | 3f7071cb0959f27795bdd103b9d76d6d MD5 | raw file
  1# ****************************************************************************
  2#
  3# Copyright (c) Microsoft Corporation. 
  4#
  5# This source code is subject to terms and conditions of the Apache License, Version 2.0. A 
  6# copy of the license can be found in the License.html file at the root of this distribution. If 
  7# you cannot locate the  Apache License, Version 2.0, please send an email to 
  8# ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
  9# by the terms of the Apache License, Version 2.0.
 10#
 11# You must not remove this notice, or any other, from this software.
 12#
 13#
 14# ****************************************************************************
 15
 16require "pp"
 17require "compat_common"
 18
 19
 20def one_level_loop 
 21    bool_seq = Bool_Sequence.new(64)
 22    cb = Combination.new([1, 3, 5,], ['next', 'break', 'retry', 'redo'])
 23
 24    ['while', 'until'].each do |keyword|
 25        bool_seq.each do |bool_sequence|
 26            cb.generate do |number, flow|
 27                t = "bools ="
 28                PP.pp(bool_sequence + [keyword == 'while' ? false : true] * 2, t)
 29                
 30                t += "i = 0
 31$g = \"\"
 32#{keyword} bools[i] do
 33    i += 1
 34    $g += \"a1\"
 35    if i == #{number}
 36        $g += \"#{flow[0,1]}1\"
 37        #{flow}
 38        $g += \"#{flow[0,1]}2\"
 39    end    
 40    $g += \"a2\"
 41end
 42puts $g
 43"
 44                yield t
 45            end 
 46            
 47            cb.generate2 do |number1, flow1, number2, flow2|
 48                t = "bools ="
 49                PP.pp(bool_sequence + [keyword == 'while' ? false : true] * 3, t)
 50                
 51                t += "i = 0
 52$g = \"\"
 53#{keyword} bools[i] do
 54    i += 1
 55    $g += \"a1\"
 56
 57    if i == #{number1}
 58        $g += \"#{flow1[0,1]}1\"
 59        #{flow1}
 60        $g += \"#{flow1[0,1]}2\"
 61    end
 62    
 63    $g += \"a2\"
 64    
 65    if i == #{number2}
 66        $g += \"#{flow2[0,1]}1\"
 67        #{flow2}
 68        $g += \"#{flow2[0,1]}2\"
 69    end   
 70     
 71    $g += \"a3\"
 72end
 73puts $g
 74"
 75                yield t
 76            end 
 77        end 
 78    end
 79end
 80
 81
 82def three_level_loop
 83    bs2 = Bool_Sequence.new(8)
 84    bs3 = Bool_Sequence.new(8)
 85    cb1 = Combination.new([1, 2, 3,], ['next', 'break', 'retry', 'redo'])
 86    cb2 = Combination.new([1, 2, 3,], ['next', 'break', 'retry', 'redo'])
 87    
 88    [[true, true,], ].each do |bool_sequence1|
 89        bs2.each do |bool_sequence2|
 90            bs3.each do |bool_sequence3|
 91                cb1.generate do |number1, flow1|
 92                    cb2.generate do |number2, flow2|
 93                        t = "bools1 = "
 94                        PP.pp(bool_sequence1 + [false] * 2, t)
 95                        t += "bools2 = "
 96                        PP.pp(bool_sequence2 + [true] * 2, t)
 97                        t += "bools3 = "
 98                        PP.pp(bool_sequence3 + [false] * 2, t)
 99                        
100                        t += "
101$g = \"\"                        
102i = 0
103while bools1[i] do 
104    i += 1
105    $g += \"a1\"
106    
107    j = 0
108    until bools2[j] do 
109        j += 1
110        $g += \"b1\"
111        
112        if j == #{number1}
113            $g += \"#{flow1[0,1]}1\"
114            #{flow1}
115            $g += \"#{flow1[0,1]}2\"
116        end 
117        
118        k = 0
119        while bools3[k] 
120            k += 1
121            $g += \"c1\"
122            if k == #{number2}
123                $g += \"#{flow2[0,1]}1\"
124                #{flow2}
125                $g += \"#{flow2[0,1]}2\"
126            end 
127            $g += \"c2\"
128        end 
129        $g += \"b2\"
130        
131    end        
132    $g += \"a2\"
133end 
134puts $g
135    " 
136    
137                        yield t
138                    end                
139                end                
140            end 
141        end 
142    end 
143end 
144
145
146total = 0
147
148p = lambda do |t|
149    total += 1    
150    results = GenFile.create_temporaily(t).run()
151    if results[0] == 0
152        GenFile.create_sequentially(t + "\nraise if $g != \"#{results[1]}\"\n")
153    else
154        tf = GenFile.create_sequentially(t + "\n#expected to fail\n")
155        GenFile.add_negative_test(tf)
156    end 
157end
158
159GenFile.prepare("ctlf_one_")
160one_level_loop &p
161GenFile.finish
162
163GenFile.prepare("ctlf_three_")
164three_level_loop &p
165GenFile.finish
166
167printf("total generated: %s", total)