aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2020-08-19 11:29:54 +0200
committerAaron Patterson <aaron.patterson@gmail.com>2020-08-19 08:08:56 -0700
commitaaf0e33c0a45e13d27e1009c7298fcb0a57c0d4f (patch)
tree46893bf3c8748d669a59ae430d940a0c5fa26140 /test
parent7f0ea20581082f627c2569fde3c69dc14a663b37 (diff)
downloadruby-aaf0e33c0a45e13d27e1009c7298fcb0a57c0d4f.tar.gz
register_fstring: avoid duping the passed string when possible
If the passed string is frozen, bare and not shared, then there is no need to duplicate it. Ref: 4ab69ebbd7cef8539f687e1f948845d076461dc6 Ref: https://bugs.ruby-lang.org/issues/11386
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_string.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 489eee33dc..529b1be828 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -3187,6 +3187,22 @@ CODE
assert_same(str, -bar, "uminus deduplicates [Feature #13077]")
end
+ def test_uminus_frozen
+ # embedded
+ str1 = ("foobar" * 3).freeze
+ str2 = ("foobar" * 3).freeze
+ assert_not_same str1, str2
+ assert_same str1, -str1
+ assert_same str1, -str2
+
+ # regular
+ str1 = ("foobar" * 4).freeze
+ str2 = ("foobar" * 4).freeze
+ assert_not_same str1, str2
+ assert_same str1, -str1
+ assert_same str1, -str2
+ end
+
def test_uminus_no_freeze_not_bare
str = @cls.new("foo")
assert_instance_of(@cls, -str)