| 1 |
## |
| 2 |
# Codegen tests |
| 3 |
|
| 4 |
assert('peephole optimization does not eliminate move whose result is reused') do |
| 5 |
assert_raise LocalJumpError do |
| 6 |
def method |
| 7 |
yield |
| 8 |
end |
| 9 |
method(&a &&= 0) |
| 10 |
end |
| 11 |
end |
| 12 |
|
| 13 |
assert('empty condition in ternary expression parses correctly') do |
| 14 |
assert_equal(() ? 1 : 2, 2) |
| 15 |
end |
| 16 |
|
| 17 |
assert('method call with exactly 127 arguments') do |
| 18 |
def args_to_ary(*args) |
| 19 |
args |
| 20 |
end |
| 21 |
|
| 22 |
assert_equal [0]*127, args_to_ary( |
| 23 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ |
| 24 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ |
| 25 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ |
| 26 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ |
| 27 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, \ |
| 28 |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 |
| 29 |
) |
| 30 |
end |
| 31 |
|
| 32 |
assert('nested empty heredoc') do |
| 33 |
_, a = nil, <<B |
| 34 |
#{<<A} |
| 35 |
A |
| 36 |
B |
| 37 |
assert_equal "\n", a |
| 38 |
end |
| 39 |
|
| 40 |
assert('splat in case splat') do |
| 41 |
a = *case |
| 42 |
when 0 |
| 43 |
* = 1 |
| 44 |
end |
| 45 |
|
| 46 |
assert_equal [1], a |
| 47 |
end |
| 48 |
|
| 49 |
assert('undef with 127 or more arguments') do |
| 50 |
assert_raise NameError do |
| 51 |
undef |
| 52 |
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, |
| 53 |
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, |
| 54 |
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, |
| 55 |
a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a, a |
| 56 |
end |
| 57 |
end |
| 58 |
|
| 59 |
assert('break in normal loop with 127 arguments') do |
| 60 |
assert_equal 127, |
| 61 |
1.times{ |
| 62 |
break 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 |
| 63 |
}.size |
| 64 |
end |
| 65 |
|
| 66 |
assert('negate literal register alignment') do |
| 67 |
a = *case |
| 68 |
when 0 |
| 69 |
-0.0 |
| 70 |
2 |
| 71 |
end |
| 72 |
|
| 73 |
assert_equal [2], a |
| 74 |
end |
| 75 |
|
| 76 |
assert('register window of calls (#3783)') do |
| 77 |
# NODE_FOR |
| 78 |
assert_nothing_raised do |
| 79 |
for i in []; end |
| 80 |
end |
| 81 |
|
| 82 |
# NODE_SYMBOLS |
| 83 |
assert_nothing_raised do |
| 84 |
%i(sym) |
| 85 |
end |
| 86 |
|
| 87 |
# NODE_SCALL |
| 88 |
assert_nothing_raised do |
| 89 |
Object.new&.__id__ |
| 90 |
end |
| 91 |
|
| 92 |
# NODE_RESCUE with splat |
| 93 |
assert_nothing_raised do |
| 94 |
begin |
| 95 |
raise |
| 96 |
rescue *[Exception] |
| 97 |
end |
| 98 |
end |
| 99 |
|
| 100 |
# NODE_CASE |
| 101 |
assert_nothing_raised do |
| 102 |
case 1 |
| 103 |
when nil |
| 104 |
end |
| 105 |
end |
| 106 |
|
| 107 |
# NODE_CASE with splat |
| 108 |
assert_nothing_raised do |
| 109 |
case 1 |
| 110 |
when *nil |
| 111 |
end |
| 112 |
end |
| 113 |
|
| 114 |
# NODE_HASH |
| 115 |
assert_nothing_raised do |
| 116 |
{}.merge( |
| 117 |
0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5, 6=>6, 7=>7, 8=>8, 9=>9, |
| 118 |
10=>10, 11=>11, 12=>12, 13=>13, 14=>14, 15=>15, 16=>16, 17=>17, 18=>18, 19=>19, |
| 119 |
20=>20, 21=>21, 22=>22, 23=>23, 24=>24, 25=>25, 26=>26, 27=>27, 28=>28, 29=>29, |
| 120 |
30=>30, 31=>31, 32=>32, 33=>33, 34=>34, 35=>35, 36=>36, 37=>37, 38=>38, 39=>39, |
| 121 |
40=>40, 41=>41, 42=>42, 43=>43, 44=>44, 45=>45, 46=>46, 47=>47, 48=>48, 49=>49, |
| 122 |
50=>50, 51=>51, 52=>52, 53=>53, 54=>54, 55=>55, 56=>56, 57=>57, 58=>58, 59=>59, |
| 123 |
60=>60, 61=>61, 62=>62, 63=>63, 64=>64, 65=>65, 66=>66, 67=>67, 68=>68, 69=>69, |
| 124 |
70=>70, 71=>71, 72=>72, 73=>73, 74=>74, 75=>75, 76=>76, 77=>77, 78=>78, 79=>79, |
| 125 |
80=>80, 81=>81, 82=>82, 83=>83, 84=>84, 85=>85, 86=>86, 87=>87, 88=>88, 89=>89, |
| 126 |
90=>90, 91=>91, 92=>92, 93=>93, 94=>94, 95=>95, 96=>96, 97=>97, 98=>98, 99=>99, |
| 127 |
100=>100, 101=>101, 102=>102, 103=>103, 104=>104, 105=>105, 106=>106, 107=>107, 108=>108, 109=>109, |
| 128 |
110=>110, 111=>111, 112=>112, 113=>113, 114=>114, 115=>115, 116=>116, 117=>117, 118=>118, 119=>119, |
| 129 |
120=>120, 121=>121, 122=>122, 123=>123, 124=>124, 125=>125, 126=>126) |
| 130 |
end |
| 131 |
|
| 132 |
# NODE_OP_ASGN |
| 133 |
o = Object.new |
| 134 |
class << o |
| 135 |
attr_accessor :a |
| 136 |
end |
| 137 |
|
| 138 |
o.a = 1 |
| 139 |
assert_nothing_raised{ o.a += 1 } |
| 140 |
o.a = 1 |
| 141 |
assert_nothing_raised{ o.a <<= 1 } |
| 142 |
o.a = 1 |
| 143 |
assert_nothing_raised{ o.a &&= 1 } |
| 144 |
|
| 145 |
o = { k: 1 } |
| 146 |
assert_nothing_raised{ o[:k] += 1 } |
| 147 |
o = { k: 1 } |
| 148 |
assert_nothing_raised{ o[:k] <<= 1 } |
| 149 |
o = { k: 1 } |
| 150 |
assert_nothing_raised{ o[:k] &&= 1 } |
| 151 |
|
| 152 |
o = { k: 1 } |
| 153 |
assert_nothing_raised{ o[*[:k]] += 1 } |
| 154 |
o = { k: 1 } |
| 155 |
assert_nothing_raised{ o[*[:k]] <<= 1 } |
| 156 |
o = { k: 1 } |
| 157 |
assert_nothing_raised{ o[*[:k]] &&= 1 } |
| 158 |
|
| 159 |
# NODE_YIELD |
| 160 |
def check_node_yield |
| 161 |
yield |
| 162 |
end |
| 163 |
assert_nothing_raised do |
| 164 |
check_node_yield{} |
| 165 |
end |
| 166 |
|
| 167 |
# NODE_DXSTR |
| 168 |
assert_raise(NotImplementedError){ `#{:dynamic}` } |
| 169 |
|
| 170 |
# NODE_XSTR |
| 171 |
assert_raise(NotImplementedError){ `static` } |
| 172 |
|
| 173 |
# NODE_DREGX |
| 174 |
class Regexp; end |
| 175 |
assert_raise(NoMethodError){ /#{'dynamic'}tail/ } |
| 176 |
assert_raise(NoMethodError){ /#{'dynamic'}tail/iu } |
| 177 |
|
| 178 |
# NODE_REGX |
| 179 |
assert_raise(NoMethodError){ /static/ } |
| 180 |
assert_raise(NoMethodError){ /static/iu } |
| 181 |
Object.remove_const :Regexp |
| 182 |
|
| 183 |
# NODE_UNDEF |
| 184 |
assert_nothing_raised do |
| 185 |
class << Object.new |
| 186 |
undef inspect |
| 187 |
end |
| 188 |
end |
| 189 |
|
| 190 |
# NODE_ALIAS |
| 191 |
assert_nothing_raised do |
| 192 |
class << Object.new |
| 193 |
alias inspect2 inspect |
| 194 |
end |
| 195 |
end |
| 196 |
end |