diff options
author | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-02 07:11:41 +0000 |
---|---|---|
committer | charliesome <charliesome@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-09-02 07:11:41 +0000 |
commit | a056098cb719312452eca309bec914406f9e5ca3 (patch) | |
tree | 36680bbcdabc53cd0a4132996d2b8984eaaa945d /test | |
parent | 78c75d91ae577df2c43ba5b41891572d75105b2d (diff) | |
download | ruby-a056098cb719312452eca309bec914406f9e5ca3.tar.gz |
* 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
Diffstat (limited to 'test')
-rw-r--r-- | test/ripper/test_scanner_events.rb | 9 | ||||
-rw-r--r-- | test/ruby/test_string.rb | 43 |
2 files changed, 52 insertions, 0 deletions
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index 2474588f76..3eed35718b 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -591,6 +591,15 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase scan('tstring_end', '%Q[abcdef]') end + def test_tstring_suffix + assert_equal ['"f'], + scan('tstring_end', '"abcdef"f') + assert_equal [']f'], + scan('tstring_end', '%q[abcdef]f') + assert_equal [']f'], + scan('tstring_end', '%Q[abcdef]f') + end + def test_regexp_beg assert_equal [], scan('regexp_beg', '') diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 83bf78adc9..faf28f5c8e 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -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 |