summaryrefslogtreecommitdiff
path: root/bootstraptest
diff options
context:
space:
mode:
authorNoah Gibbs <noah.gibbs@shopify.com>2022-06-07 16:20:57 +0100
committerGitHub <noreply@github.com>2022-06-07 11:20:57 -0400
commit1598c9458a3ac8e0e4c179317a4e5bba506e3367 (patch)
tree707cfb4f9a94defcb78ff7fb4e06c52020b69e37 /bootstraptest
parentdeff9e2699c46075c3bb9b9e1bf9f721a12a2ca3 (diff)
Add special-case code for the String unary plus operator (#5982)
Notes
Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
Diffstat (limited to 'bootstraptest')
-rw-r--r--bootstraptest/test_yjit.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb
index 503af1ab80..3ae0cdb33a 100644
--- a/bootstraptest/test_yjit.rb
+++ b/bootstraptest/test_yjit.rb
@@ -1393,6 +1393,33 @@ assert_equal 'foo', %q{
make_str("foo")
}
+# Test that String unary plus returns the same object ID for an unfrozen string.
+assert_equal '', %q{
+ str = "bar"
+
+ old_obj_id = str.object_id
+ uplus_str = +str
+
+ if uplus_str.object_id != old_obj_id
+ raise "String unary plus on unfrozen should return the string exactly, not a duplicate"
+ end
+
+ ''
+}
+
+# Test that String unary plus returns a different unfrozen string when given a frozen string
+assert_equal 'false', %q{
+ frozen_str = "foo".freeze
+
+ old_obj_id = frozen_str.object_id
+ uplus_str = +frozen_str
+
+ if uplus_str.object_id == old_obj_id
+ raise "String unary plus on frozen should return a new duplicated string"
+ end
+
+ uplus_str.frozen?
+}
# test invokebuiltin as used in struct assignment
assert_equal '123', %q{