summaryrefslogtreecommitdiff
path: root/jni/ruby/bootstraptest/test_massign.rb
blob: 0f63dd424afa60d6225d726fee8ba7f8e17297ea (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
assert_equal '[[1], 2, 3]', '*v1, (a, b) = [1,[2, 3]]; [v1, a, b]'
assert_equal '[[1], 2, 3]', '*v1,(*), (a, b) = [1,:x,[2, 3]]; [v1, a, b]'

assert_equal '[]',          '*a = *nil; a'
assert_equal '[nil]',       '*a = nil; a'
assert_equal '2',           'a, a = 1, 2; a', "[ruby-dev:31522]"
assert_equal '[1, 2]',      'a, b = 1, 2'
assert_equal '[1, 2]', %q{
  ans = []
  trace_var(:$a){|v| ans << v}
  trace_var(:$b){|v| ans << v}
  $a, $b = 1, 2
  ans
}

assert_equal 'ok', %q{
  r = :ok
  :ng.tap {|(r)|}
  r
}, '[ruby-dev:31507]'

=begin
# generated by this script:

3.times{|i|
  8.times{|e|
    ary = (0...e).to_a
    a,b,c,d,e,f = nil
    vals = %w(a b c d e f)
    vals[i] = '*' + vals[i]
    program = "#{vals.join(", ")} = *ary"
    eval(program)
    ans = [a,b,c,d,e,f]
    puts %Q{
      assert_equal "#{ans.inspect}", %q{
        ary = #{ary.inspect}
        #{program}; [a, b, c, d, e, f]
      }}
  }
}
=end

      assert_equal "[[], nil, nil, nil, nil, nil]", %q{
        ary = []
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[], 0, nil, nil, nil, nil]", %q{
        ary = [0]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[], 0, 1, nil, nil, nil]", %q{
        ary = [0, 1]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[], 0, 1, 2, nil, nil]", %q{
        ary = [0, 1, 2]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[], 0, 1, 2, 3, nil]", %q{
        ary = [0, 1, 2, 3]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[], 0, 1, 2, 3, 4]", %q{
        ary = [0, 1, 2, 3, 4]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[0], 1, 2, 3, 4, 5]", %q{
        ary = [0, 1, 2, 3, 4, 5]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[[0, 1], 2, 3, 4, 5, 6]", %q{
        ary = [0, 1, 2, 3, 4, 5, 6]
        *a, b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[nil, [], nil, nil, nil, nil]", %q{
        ary = []
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [], nil, nil, nil, nil]", %q{
        ary = [0]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [], 1, nil, nil, nil]", %q{
        ary = [0, 1]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [], 1, 2, nil, nil]", %q{
        ary = [0, 1, 2]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [], 1, 2, 3, nil]", %q{
        ary = [0, 1, 2, 3]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [], 1, 2, 3, 4]", %q{
        ary = [0, 1, 2, 3, 4]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [1], 2, 3, 4, 5]", %q{
        ary = [0, 1, 2, 3, 4, 5]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, [1, 2], 3, 4, 5, 6]", %q{
        ary = [0, 1, 2, 3, 4, 5, 6]
        a, *b, c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[nil, nil, [], nil, nil, nil]", %q{
        ary = []
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, nil, [], nil, nil, nil]", %q{
        ary = [0]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [], nil, nil, nil]", %q{
        ary = [0, 1]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [], 2, nil, nil]", %q{
        ary = [0, 1, 2]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [], 2, 3, nil]", %q{
        ary = [0, 1, 2, 3]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [], 2, 3, 4]", %q{
        ary = [0, 1, 2, 3, 4]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [2], 3, 4, 5]", %q{
        ary = [0, 1, 2, 3, 4, 5]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }

      assert_equal "[0, 1, [2, 3], 4, 5, 6]", %q{
        ary = [0, 1, 2, 3, 4, 5, 6]
        a, b, *c, d, e, f = *ary; [a, b, c, d, e, f]
      }


#
assert_equal 'ok', %q{
  a,s=[],"aaa"
  300.times { a<<s; s=s.succ }
  eval <<-END__
  GC.stress=true
  Fiber.new do
    #{ a.join(",") },*zzz=1
  end.resume
  END__
  :ok
}, '[ruby-dev:32581]'

assert_equal 'ok', %q{
  while true
    *, z = 1
    break
  end
  :ok
}, '[ruby-dev:32892]'