aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ripper/test_scanner_events.rb9
-rw-r--r--test/ruby/test_string.rb43
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