aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_string.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-10-24 11:52:30 -0700
committerJeremy Evans <code@jeremyevans.net>2020-11-20 16:30:23 -0800
commit58325daae3beefda13ed100782cd19a89cc68771 (patch)
treefd1857904c1c86d9c7c21f6038535f3beeafc4bb /test/ruby/test_string.rb
parent4f5d14eb8cb7fba1c583d516d597c5e28d7a5540 (diff)
downloadruby-58325daae3beefda13ed100782cd19a89cc68771.tar.gz
Make String methods return String instances when called on a subclass instance
This modifies the following String methods to return String instances instead of subclass instances: * String#* * String#capitalize * String#center * String#chomp * String#chop * String#delete * String#delete_prefix * String#delete_suffix * String#downcase * String#dump * String#each/#each_line * String#gsub * String#ljust * String#lstrip * String#partition * String#reverse * String#rjust * String#rpartition * String#rstrip * String#scrub * String#slice! * String#slice/#[] * String#split * String#squeeze * String#strip * String#sub * String#succ/#next * String#swapcase * String#tr * String#tr_s * String#upcase This also fixes a bug in String#swapcase where it would return the receiver instead of a copy of the receiver if the receiver was the empty string. Some string methods were left to return subclass instances: * String#+@ * String#-@ Both of these methods will return the receiver (subclass instance) in some cases, so it is best to keep the returned class consistent. Fixes [#10845]
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r--test/ruby/test_string.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index 810c700c8c..4814872789 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -2089,6 +2089,8 @@ CODE
def test_swapcase
assert_equal(S("hi&LOW"), S("HI&low").swapcase)
+ s = S("")
+ assert_not_same(s, s.swapcase)
end
def test_swapcase!