1assert_equal %q{4}, %q{1 && 2 && 3 && 4}
2assert_equal %q{}, %q{1 && nil && 3 && 4}
3assert_equal %q{}, %q{1 && 2 && 3 && nil}
4assert_equal %q{false}, %q{1 && 2 && 3 && false}
5assert_equal %q{4}, %q{1 and 2 and 3 and 4}
6assert_equal %q{}, %q{1 and nil and 3 and 4}
7assert_equal %q{}, %q{1 and 2 and 3 and nil}
8assert_equal %q{false}, %q{1 and 2 and 3 and false}
9assert_equal %q{}, %q{nil && true}
10assert_equal %q{false}, %q{false && true}
11assert_equal %q{}, %q{
12  case 1
13  when 2
14    :ng
15  end}
16assert_equal %q{ok}, %q{
17  case 1
18  when 10,20,30
19    :ng1
20  when 1,2,3
21    :ok
22  when 100,200,300
23    :ng2
24  else
25    :elseng
26  end}
27assert_equal %q{elseok}, %q{
28  case 123
29  when 10,20,30
30    :ng1
31  when 1,2,3
32    :ng2
33  when 100,200,300
34    :ng3
35  else
36    :elseok
37  end
38}
39assert_equal %q{ok}, %q{
40  case 'test'
41  when /testx/
42    :ng1
43  when /test/
44    :ok
45  when /tetxx/
46    :ng2
47  else
48    :ng_else
49  end
50}
51assert_equal %q{ok}, %q{
52  case Object.new
53  when Object
54    :ok
55  end
56}
57assert_equal %q{ok}, %q{
58  case Object
59  when Object.new
60    :ng
61  else
62    :ok
63  end
64}
65assert_equal %q{ok}, %q{
66  case 'test'
67  when 'tes'
68    :ng
69  when 'te'
70    :ng
71  else
72    :ok
73  end
74}
75assert_equal %q{ok}, %q{
76  case 'test'
77  when 'tes'
78    :ng
79  when 'te'
80    :ng
81  when 'test'
82    :ok
83  end
84}
85assert_equal %q{ng}, %q{
86  case 'test'
87  when 'tes'
88    :ng
89  when /te/
90    :ng
91  else
92    :ok
93  end
94}
95assert_equal %q{ok}, %q{
96  case 'test'
97  when 'tes'
98    :ng
99  when /test/
100    :ok
101  else
102    :ng
103  end
104}
105assert_equal %q{100}, %q{
106  def test(arg)
107    case 1
108    when 2
109      3
110    end
111    return arg
112  end
113
114  test(100)
115}
116assert_equal %q{ok}, %q{
117  ary = [1, 2]
118  case 1
119  when *ary
120    :ok
121  else
122    :ng
123  end
124}
125assert_equal %q{ok}, %q{
126  ary = [1, 2]
127  case 3
128  when *ary
129    :ng
130  else
131    :ok
132  end
133}
134assert_equal %q{ok}, %q{
135  ary = [1, 2]
136  case 1
137  when :x, *ary
138    :ok
139  when :z
140    :ng1
141  else
142    :ng2
143  end
144}
145assert_equal %q{ok}, %q{
146  ary = [1, 2]
147  case 3
148  when :x, *ary
149    :ng1
150  when :z
151    :ng2
152  else
153    :ok
154  end
155}
156assert_equal %q{[:false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :false, :false, :false, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :then, :false, :then, :then, :then, :false, :false, :false, :false, :false, :false, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :false, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :false, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :false, :then, :then, :then, :then, :then, :then, :then, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep, :then, :sep]}, %q{
157
158  def make_perm ary, num
159    if num == 1
160      ary.map{|e| [e]}
161    else
162      base = make_perm(ary, num-1)
163      res  = []
164      base.each{|b|
165        ary.each{|e|
166          res << [e] + b
167        }
168      }
169      res
170    end
171  end
172
173  def each_test
174    conds = make_perm(['fv', 'tv'], 3)
175    bangs = make_perm(['', '!'], 3)
176    exprs = make_perm(['and', 'or'], 3)
177    ['if', 'unless'].each{|syn|
178      conds.each{|cs|
179        bangs.each{|bs|
180          exprs.each{|es|
181            yield(syn, cs, bs, es)
182          }
183        }
184      }
185    }
186  end
187
188  fv = false
189  tv = true
190
191  $ans = []
192  each_test{|syn, conds, bangs, exprs|
193    c1, c2, c3 = conds
194    bang1, bang2, bang3 = bangs
195    e1, e2 = exprs
196    eval %Q{
197      #{syn} #{bang1}#{c1} #{e1} #{bang2}#{c2} #{e2} #{bang3}#{c3}
198        $ans << :then
199      else
200        $ans << :false
201      end
202    }
203  }
204
205  each_test{|syn, conds, bangs, exprs|
206    c1, c2, c3 = conds
207    bang1, bang2, bang3 = bangs
208    e1, e2 = exprs
209    eval %Q{
210      #{syn} #{bang1}#{c1} #{e1} #{bang2}#{c2} #{e2} #{bang3}#{c3}
211        $ans << :then
212      end
213      $ans << :sep
214    }
215  }
216  $ans
217}
218assert_equal %q{}, %q{
219  defined?(m)
220}
221assert_equal %q{method}, %q{
222  def m
223  end
224  defined?(m)
225}
226assert_equal %q{}, %q{
227  defined?(a.class)
228}
229assert_equal %q{method}, %q{
230  a = 1
231  defined?(a.class)
232}
233assert_equal %q{["method", "method", "method", "method", nil, nil, "method", "method", "method", nil]}, %q{
234  class C
235    def test
236      [defined?(m1()), defined?(self.m1), defined?(C.new.m1),
237       defined?(m2()), defined?(self.m2), defined?(C.new.m2),
238       defined?(m3()), defined?(self.m3), defined?(C.new.m3)]
239    end
240    def m1
241    end
242    private
243    def m2
244    end
245    protected
246    def m3
247    end
248  end
249  C.new.test + [defined?(C.new.m3)]
250}
251assert_equal %q{[nil, nil, nil, nil, "global-variable", "global-variable", nil, nil]}, %q{
252  $ans = [defined?($1), defined?($2), defined?($3), defined?($4)]
253  /(a)(b)/ =~ 'ab'
254  $ans + [defined?($1), defined?($2), defined?($3), defined?($4)]
255}
256assert_equal %q{nilselftruefalse}, %q{
257  defined?(nil) + defined?(self) +
258    defined?(true) + defined?(false)
259}
260assert_equal %q{}, %q{
261  defined?(@a)
262}
263assert_equal %q{instance-variable}, %q{
264  @a = 1
265  defined?(@a)
266}
267assert_equal %q{}, %q{
268  defined?(@@a)
269}
270assert_equal %q{class variable}, %q{
271  @@a = 1
272  defined?(@@a)
273}
274assert_equal %q{}, %q{
275  defined?($a)
276}
277assert_equal %q{global-variable}, %q{
278  $a = 1
279  defined?($a)
280}
281assert_equal %q{}, %q{
282  defined?(C_definedtest)
283}
284assert_equal %q{constant}, %q{
285  C_definedtest = 1
286  defined?(C_definedtest)
287}
288assert_equal %q{}, %q{
289  defined?(::C_definedtest)
290}
291assert_equal %q{constant}, %q{
292  C_definedtest = 1
293  defined?(::C_definedtest)
294}
295assert_equal %q{}, %q{
296  defined?(C_definedtestA::C_definedtestB::C_definedtestC)
297}
298assert_equal %q{constant}, %q{
299  class C_definedtestA
300    class C_definedtestB
301      C_definedtestC = 1
302    end
303  end
304  defined?(C_definedtestA::C_definedtestB::C_definedtestC)
305}
306assert_equal %q{30}, %q{
307  sum = 0
308  30.times{|ib|
309    if ib % 10 == 0 .. true
310      sum += ib
311    end
312  }
313  sum
314}
315assert_equal %q{63}, %q{
316  sum = 0
317  30.times{|ib|
318    if ib % 10 == 0 ... true
319      sum += ib
320    end
321  }
322  sum
323}
324assert_equal %q{[["NUM", "Type: NUM\n"], ["NUM", "123\n"], ["NUM", "456\n"], ["NUM", "Type: ARP\n"], ["NUM", "aaa\n"], ["NUM", "bbb\n"], ["NUM", "\f\n"], ["ARP", "Type: ARP\n"], ["ARP", "aaa\n"], ["ARP", "bbb\n"]]}, %q{
325  t = nil
326  unless ''.respond_to? :lines
327    class String
328      def lines
329        self
330      end
331    end
332  end
333  ary = []
334"this must not print
335Type: NUM
336123
337456
338Type: ARP
339aaa
340bbb
341\f
342this must not print
343hoge
344Type: ARP
345aaa
346bbb
347".lines.each{|l|
348    if (t = l[/^Type: (.*)/, 1])..(/^\f/ =~ l)
349      ary << [t, l]
350    end
351  }
352  ary
353}
354assert_equal %q{1}, %q{if true  then 1 ; end}
355assert_equal %q{}, %q{if false then 1 ; end}
356assert_equal %q{1}, %q{if true  then 1 ; else; 2; end}
357assert_equal %q{2}, %q{if false then 1 ; else; 2; end}
358assert_equal %q{}, %q{if true  then   ; elsif true then ; 1 ; end}
359assert_equal %q{1}, %q{if false then   ; elsif true then ; 1 ; end}
360assert_equal %q{}, %q{unless true  then 1 ; end}
361assert_equal %q{1}, %q{unless false then 1 ; end}
362assert_equal %q{2}, %q{unless true  then 1 ; else; 2; end}
363assert_equal %q{1}, %q{unless false then 1 ; else; 2; end}
364assert_equal %q{1}, %q{1 if true}
365assert_equal %q{}, %q{1 if false}
366assert_equal %q{}, %q{1 if nil}
367assert_equal %q{}, %q{1 unless true}
368assert_equal %q{1}, %q{1 unless false}
369assert_equal %q{1}, %q{1 unless nil}
370assert_equal %q{1}, %q{1 || 2 || 3 || 4}
371assert_equal %q{1}, %q{1 || false || 3 || 4}
372assert_equal %q{2}, %q{nil || 2 || 3 || 4}
373assert_equal %q{2}, %q{false || 2 || 3 || 4}
374assert_equal %q{false}, %q{nil || false || nil || false}
375assert_equal %q{1}, %q{1 or 2 or 3 or 4}
376assert_equal %q{1}, %q{1 or false or 3 or 4}
377assert_equal %q{2}, %q{nil or 2 or 3 or 4}
378assert_equal %q{2}, %q{false or 2 or 3 or 4}
379assert_equal %q{false}, %q{nil or false or nil or false}
380assert_equal %q{elseng}, %q{
381  case
382  when 1==2, 2==3
383    :ng1
384  when false, 4==5
385    :ok
386  when false
387    :ng2
388  else
389    :elseng
390  end
391}
392assert_equal %q{ok}, %q{
393  case
394  when nil, nil
395    :ng1
396  when 1,2,3
397    :ok
398  when false, false
399    :ng2
400  else
401    :elseng
402  end
403}
404assert_equal %q{elseok}, %q{
405  case
406  when nil
407    :ng1
408  when false
409    :ng2
410  else
411    :elseok
412  end}
413assert_equal %q{}, %q{
414  case
415  when 1
416  end
417}
418assert_equal %q{ok}, %q{
419  r = nil
420  ary = []
421  case
422  when false
423    r = :ng1
424  when false, false
425    r = :ng2
426  when *ary
427    r = :ng3
428  when false, *ary
429    r = :ng4
430  when true, *ary
431    r = :ok
432  end
433  r
434}
435assert_equal %q{ok}, %q{
436  ary = []
437  case
438  when false, *ary
439    :ng
440  else
441    :ok
442  end
443}
444assert_equal %q{ok}, %q{
445  ary = [false, nil]
446  case
447  when *ary
448    :ng
449  else
450    :ok
451  end
452}
453assert_equal %q{ok}, %q{
454  ary = [false, nil]
455  case
456  when *ary
457    :ng
458  when true
459    :ok
460  else
461    :ng2
462  end
463}
464assert_equal %q{ng}, %q{
465  ary = [false, nil]
466  case
467  when *ary
468    :ok
469  else
470    :ng
471  end
472}
473assert_equal %q{ok}, %q{
474  ary = [false, true]
475  case
476  when *ary
477    :ok
478  else
479    :ng
480  end
481}
482assert_equal %q{ok}, %q{
483  ary = [false, true]
484  case
485  when false, false
486  when false, *ary
487    :ok
488  else
489    :ng
490  end
491}
492assert_equal %q{}, %q{
493  i = 0
494  while i < 10
495    i+=1
496  end}
497assert_equal %q{10}, %q{
498  i = 0
499  while i < 10
500    i+=1
501  end; i}
502assert_equal %q{}, %q{
503  i = 0
504  until i > 10
505    i+=1
506  end}
507assert_equal %q{11}, %q{
508  i = 0
509  until i > 10
510    i+=1
511  end; i}
512assert_equal %q{1}, %q{
513  i = 0
514  begin
515    i+=1
516  end while false
517  i
518}
519assert_equal %q{1}, %q{
520  i = 0
521  begin
522    i+=1
523  end until true
524  i
525}
526def assert_syntax_error expected, code, message = ''
527  assert_equal "#{expected}",
528    "begin eval(%q{#{code}}, nil, '', 0)"'; rescue SyntaxError => e; e.message[/\A:(?:\d+:)? (.*)/, 1] end', message
529end
530assert_syntax_error "unterminated string meets end of file", '().."', '[ruby-dev:29732]'
531assert_equal %q{[]}, %q{$&;[]}, '[ruby-dev:31068]'
532assert_syntax_error "syntax error, unexpected *, expecting '}'", %q{{*0}}, '[ruby-dev:31072]'
533assert_syntax_error "`@0' is not allowed as an instance variable name", %q{@0..0}, '[ruby-dev:31095]'
534assert_syntax_error "identifier $00 is not valid to get", %q{$00..0}, '[ruby-dev:31100]'
535assert_syntax_error "identifier $00 is not valid to set", %q{0..$00=1}
536assert_equal %q{0}, %q{[*0];0}, '[ruby-dev:31102]'
537assert_syntax_error "syntax error, unexpected ')'", %q{v0,(*,v1,) = 0}, '[ruby-dev:31104]'
538assert_equal %q{1}, %q{
539  class << (ary=[]); def []; 0; end; def []=(x); super(0,x);end;end; ary[]+=1
540}, '[ruby-dev:31110]'
541assert_syntax_error "Can't set variable $1", %q{0..$1=1}, '[ruby-dev:31118]'
542assert_valid_syntax %q{1.times{1+(1&&next)}}, '[ruby-dev:31119]'
543assert_valid_syntax %q{x=-1;loop{x+=1&&redo if (x+=1).zero?}}, '[ruby-dev:31119]'
544assert_syntax_error %q{syntax error, unexpected end-of-input}, %q{!}, '[ruby-dev:31243]'
545assert_equal %q{[nil]}, %q{[()]}, '[ruby-dev:31252]'
546assert_equal %q{true}, %q{!_=()}, '[ruby-dev:31263]'
547assert_equal 'ok', %q{while true; redo; end if 1 == 2; :ok}, '[ruby-dev:31360]'
548assert_equal 'ok', %q{
549  1.times {
550    begin
551    ensure
552      next
553    end
554  }; :ok
555}, '[ruby-dev:31373]'
556assert_equal 'ok', %q{
557  flag = false
558  1.times {
559    next if flag
560    flag = true
561    begin
562    ensure
563      redo
564    end
565  }; :ok
566}, '[ruby-dev:31373]'
567
568assert_equal 'ok', %q{
569  1.times{
570    p(1, (next; 2))
571  }; :ok
572}
573assert_equal '3', %q{
574  i = 0
575  1 + (while true
576         break 2 if (i+=1) > 1
577         next
578       end)
579}
580assert_equal '3', %q{
581  i = 0
582  1 + (while true
583         break 2 if (i+=1) > 1
584         p(1, (next; 2))
585       end)
586}
587# redo
588assert_equal 'ok', %q{
589  i = 0
590  1.times{
591    break if i>1
592    i+=1
593    p(1, (redo; 2))
594  }; :ok
595}
596assert_equal '3', %q{
597  i = 0
598  1 + (while true
599         break 2 if (i+=1) > 1
600         redo
601       end)
602}
603assert_equal '3', %q{
604  i = 0
605  1 + (while true
606         break 2 if (i+=1) > 1
607         p(1, (redo; 2))
608       end)
609}
610assert_equal '1', %q{
611  a = [0]
612  a[*a]+=1
613}
614assert_equal '2', %q{
615  ary = [0]
616  case 1
617  when *ary, 1
618    1
619  end +
620  case
621  when *ary
622    1
623  end
624}
625
626assert_match /invalid multibyte char/, %q{
627  STDERR.reopen(STDOUT)
628  eval("\"\xf0".force_encoding("utf-8"))
629}, '[ruby-dev:32429]'
630
631# method ! and !=
632assert_equal 'true', %q{!false}
633assert_equal 'true', %q{1 == 1}
634assert_equal 'true', %q{1 != 2}
635assert_equal 'true', %q{
636  class C; def !=(obj); true; end; end
637  C.new != 1
638}
639assert_equal 'true', %q{
640  class C; def !@; true; end; end
641  !C.new
642}
643assert_normal_exit %q{
644  eval "while true; return; end rescue p $!"
645}, '[ruby-dev:31663]'
646assert_equal '1', %q{
647  def bar
648    raise
649  end
650
651  def foo
652    1.times{
653      begin
654        return bar
655      rescue
656        :ok
657      end
658    }
659  end
660
661  foo
662}
663
664assert_equal 'ok', %q{
665  counter = 2
666  while true
667    counter -= 1
668    next if counter != 0
669    break
670  end
671  :ok
672}, '[ruby-core:14385]'
673
674assert_equal 'ok', %q{
675  counter = 2
676  while true
677    counter -= 1
678    next if counter != 0
679    break :ok
680  end # direct
681}, '[ruby-core:14385]'
682
683assert_equal 'ok', %q{
684  counter = 2
685  while true
686    counter -= 1
687    break if counter == 0
688    "#{next}"
689  end
690  :ok
691}, 'reported by Yusuke ENDOH'
692
693assert_equal 'ok', %q{
694  counter = 2
695  while true
696    counter -= 1
697    break if counter == 0
698    next
699    redo
700  end
701  :ok
702}, 'reported by Yusuke ENDOH'
703
704assert_equal 'ok', %q{
705  counter = 2
706  while true
707    counter -= 1
708    break if counter == 0
709    next
710    "#{ redo }"
711  end
712  :ok
713}, 'reported by Yusuke ENDOH'
714
715assert_normal_exit %q{
716  begin
717    raise
718  rescue
719    counter = 2
720    while true
721      counter -= 1
722      break if counter == 0
723      next
724      retry
725    end
726  end
727}, 'reported by Yusuke ENDOH'
728
729assert_normal_exit %q{
730  counter = 2
731  while true
732    counter -= 1
733    break if counter == 0
734    next
735    "#{ break }"
736  end
737}, 'reported by Yusuke ENDOH'
738
739assert_normal_exit %q{
740  counter = 2
741  while true
742    counter -= 1
743    next if counter != 0
744    "#{ break }"
745  end
746}, 'reported by Yusuke ENDOH'
747
748assert_equal 'ok', %q{
749  1.times do
750    [
751      1, 2, 3, 4, 5, 6, 7, 8,
752      begin
753        false ? next : p
754        break while true
755      end
756    ]
757  end
758  :ok
759}, '[ruby-dev:32882]'
760
761assert_equal "1\n2\n", %q{
762  i = 0
763  while i<2
764    i += 1
765    next p(i)
766  end
767}
768
769assert_valid_syntax('1.times {|i|print (42),1;}', '[ruby-list:44479]')
770
771assert_equal 'ok', %q{
772  def a() end
773  begin
774    if defined?(a(1).a)
775      :ng
776    else
777      :ok
778    end
779  rescue
780    :ng
781  end
782}, '[ruby-core:16010]'
783
784assert_equal 'ok', %q{
785  def a() end
786  begin
787    if defined?(a::B)
788      :ng
789    else
790      :ok
791    end
792  rescue
793    :ng
794  end
795}, '[ruby-core:16010]'
796
797assert_normal_exit %q{
798  defined? C && 0
799}
800
801assert_normal_exit %q{
802  class C
803    def m
804      defined?(super())
805    end
806  end
807  C.new.m
808}
809
810assert_equal 'ok', %q{
811  class X < RuntimeError;end
812  x = [X]
813  begin
814   raise X
815  rescue *x
816   :ok
817  end
818}, '[ruby-core:14537]'
819
820assert_equal 'ok', %q{
821  a = [false]
822  (a[0] &&= true) == false ? :ok : :ng
823}, '[ruby-dev:34679]'
824
825assert_normal_exit %q{
826  a = []
827  100.times {|i| a << i << nil << nil }
828  p a.compact!
829}
830
831assert_equal 'ok', %q{
832  "#{}""#{}ok"
833}, '[ruby-dev:38968]'
834
835
836assert_equal 'ok', %q{
837  "o" "#{}k"
838}, '[ruby-dev:38980]'
839
840bug2415 = '[ruby-core:26961]'
841assert_normal_exit %q{
842  0.times do
843    0.times do
844      def x(a=1, b, *rest); nil end
845    end
846  end
847}, bug2415
848
849assert_normal_exit %q{
850  0.times do
851    0.times do
852      def x@; nil end
853    end
854  end
855}, bug2415
856
857assert_normal_exit %q{
858  0.times do
859    0.times do
860      def x(a = 0.times do
861              def y(a=1, b, *rest); nil; end
862            end)
863        nil
864      end
865    end
866  end
867}, bug2415
868
869assert_normal_exit %q{
870  0.times do
871    0.times do
872      def x(a = 0.times do
873              def x@; nil; end
874            end)
875        nil
876      end
877    end
878  end
879}, bug2415
880
881assert_normal_exit %q{
882  a {
883    b {|c.d| }
884    e
885  }
886}, '[ruby-dev:39861]'
887
888bug1240 = '[ruby-core:22637]'
889assert_valid_syntax('x y { "#{}".z { } }', bug1240)
890assert_valid_syntax('x y { "#{}".z do end }', bug1240)
891
892assert_valid_syntax('y "#{a 1}" do end', '[ruby-core:29579]')
893assert_normal_exit %q{
894  def foo(&block)
895    yield
896  end
897
898  foo do
899    s = defined?(raise + 1)
900    Class
901  end
902}, '[ruby-core:30293]'
903