aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authoralexandre184 <110398901+alexandre184@users.noreply.github.com>2023-07-15 09:36:53 +0200
committerGitHub <noreply@github.com>2023-07-15 16:36:53 +0900
commite5825de7c9f07e4f7bd2b83ce8973e19a4652916 (patch)
tree92b04125daca166707c5465402469603d33fb619 /spec
parentf15123c34ce80f3928612befe2a9aaf4c9d27fda (diff)
downloadruby-e5825de7c9f07e4f7bd2b83ce8973e19a4652916.tar.gz
[Bug #19769] Fix range of size 1 in `String#tr`
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/string/tr_s_spec.rb9
-rw-r--r--spec/ruby/core/string/tr_spec.rb9
2 files changed, 18 insertions, 0 deletions
diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb
index b5c87d4e4e..3c31473044 100644
--- a/spec/ruby/core/string/tr_s_spec.rb
+++ b/spec/ruby/core/string/tr_s_spec.rb
@@ -17,6 +17,15 @@ describe "String#tr_s" do
"hello ^--^".tr_s("---", "_").should == "hello ^_^"
end
+ ruby_bug "#19769", ""..."3.3" do
+ it "accepts c1-c1 notation to denote range of one character" do
+ "hello".tr_s('e-e', 'x').should == "hxllo"
+ "123456789".tr_s("2-23","xy").should == "1xy456789"
+ "hello ^-^".tr_s("e-", "a-a_").should == "hallo ^_^"
+ "hello ^-^".tr_s("---o", "_a").should == "hella ^_^"
+ end
+ end
+
it "pads to_str with its last char if it is shorter than from_string" do
"this".tr_s("this", "x").should == "x"
end
diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb
index cf485d32a3..d60480dc7e 100644
--- a/spec/ruby/core/string/tr_spec.rb
+++ b/spec/ruby/core/string/tr_spec.rb
@@ -16,6 +16,15 @@ describe "String#tr" do
"hello ^-^".tr("---", "_").should == "hello ^_^"
end
+ ruby_bug "#19769", ""..."3.3" do
+ it "accepts c1-c1 notation to denote range of one character" do
+ "hello".tr('e-e', 'x').should == "hxllo"
+ "123456789".tr("2-23","xy").should == "1xy456789"
+ "hello ^-^".tr("e-", "a-a_").should == "hallo ^_^"
+ "hello ^-^".tr("---o", "_a").should == "hella ^_^"
+ end
+ end
+
it "pads to_str with its last char if it is shorter than from_string" do
"this".tr("this", "x").should == "xxxx"
"hello".tr("a-z", "A-H.").should == "HE..."