* NEWS: Add note about frozen string literals

* compile.c (case_when_optimizable_literal): optimize NODE_LIT strings
  in when clauses of case statements

* ext/ripper/eventids2.c: add tSTRING_SUFFIX

* parse.y: add 'f' suffix on string literals for frozen strings

* test/ripper/test_scanner_events.rb: add scanner tests

* test/ruby/test_string.rb: add frozen string tests

[Feature #8579] [ruby-core:55699]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
charliesome 2013-09-02 07:11:41 +00:00
parent 78c75d91ae
commit a056098cb7
7 changed files with 175 additions and 9 deletions

View file

@ -2192,6 +2192,49 @@ class TestString < Test::Unit::TestCase
assert_equal(false, "\u3042".byteslice(0, 2).valid_encoding?)
assert_equal(false, ("\u3042"*10).byteslice(0, 20).valid_encoding?)
end
def test_unknown_string_option
assert_raises(SyntaxError) do
eval(%{
"hello"x
})
end
end
def test_frozen_string
assert_equal "hello", "hello"f
assert_predicate "hello"f, :frozen?
f = -> { "hello"f }
assert_equal f.call.object_id, f.call.object_id
end
def test_frozen_dstring
assert_equal "hello123", "hello#{123}"f
assert_predicate "hello#{123}"f, :frozen?
i = 0
f = -> { "#{i += 1}"f }
assert_equal "1", f.call
assert_equal "2", f.call
end
def test_frozen_string_cannot_be_adjacent
assert_raises(SyntaxError) do
eval(%{
"hello"f "world"
})
end
assert_raises(SyntaxError) do
eval(%{
"hello"f "world"
})
end
end
end
class TestString2 < TestString