summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby')
-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