aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_literal.rb
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-03 23:53:11 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-03 23:53:11 +0000
commit3b6321083a2e3525da3b34d08a0b68bac094bd7f (patch)
treec14d934377f5fa0713b179f99578cc36ff47b189 /test/ruby/test_literal.rb
parent7712ffc7ee0108c4061efffe773bb3e756193a26 (diff)
downloadruby-3b6321083a2e3525da3b34d08a0b68bac094bd7f.tar.gz
Collapse putobject, putobject, newarray
This collapses: ``` == disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE) 0000 putobject "a" ( 4)[LiCa] 0002 putobject "b" 0004 putobject "c" 0006 putobject "d" 0008 putobject "e" 0010 putobject "f" 0012 putobject "g" 0014 putobject "h" 0016 putobject "i" 0018 putobject "j" 0020 putobject "k" 0022 newarray 11 0024 leave ( 5)[Re] ``` In to this: ``` == disasm: #<ISeq:bar@bench.rb:3 (3,0)-(5,3)> (catch: FALSE) 0000 duparray ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"]( 4)[LiCa] 0002 leave ( 5)[Re] ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66174 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_literal.rb')
-rw-r--r--test/ruby/test_literal.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_literal.rb b/test/ruby/test_literal.rb
index 3b6aa0c096..178cc83fa3 100644
--- a/test/ruby/test_literal.rb
+++ b/test/ruby/test_literal.rb
@@ -177,6 +177,12 @@ class TestRubyLiteral < Test::Unit::TestCase
end
end
+ def test_frozen_string_in_array_literal
+ list = eval("# frozen-string-literal: true\n""['foo', 'bar']")
+ assert_equal 2, list.length
+ list.each { |str| assert_predicate str, :frozen? }
+ end
+
if defined?(RubyVM::InstructionSequence.compile_option) and
RubyVM::InstructionSequence.compile_option.key?(:debug_frozen_string_literal)
def test_debug_frozen_string
@@ -189,6 +195,17 @@ class TestRubyLiteral < Test::Unit::TestCase
str << "x"
}
end
+
+ def test_debug_frozen_string_in_array_literal
+ src = '["foo"]'; f = "test.rb"; n = 1
+ opt = {frozen_string_literal: true, debug_frozen_string_literal: true}
+ ary = RubyVM::InstructionSequence.compile(src, f, f, n, opt).eval
+ assert_equal("foo", ary.first)
+ assert_predicate(ary.first, :frozen?)
+ assert_raise_with_message(FrozenError, /created at #{Regexp.quote(f)}:#{n}/) {
+ ary.first << "x"
+ }
+ end
end
def test_regexp