diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-01-28 17:08:57 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-01-28 17:08:57 +0100 |
commit | 2e32b919b4f2f5b7f2e1509d6fa985526ef1f61c (patch) | |
tree | aedadac3c99ca0097c2bbeaa95830332d6fb9971 /spec/ruby/core/string | |
parent | 1b377b32c8616f85c0a97e68758c5c2db83f2169 (diff) | |
download | ruby-2e32b919b4f2f5b7f2e1509d6fa985526ef1f61c.tar.gz |
Update to ruby/spec@8cafaa5
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r-- | spec/ruby/core/string/scrub_spec.rb | 7 | ||||
-rw-r--r-- | spec/ruby/core/string/shared/slice.rb | 10 | ||||
-rw-r--r-- | spec/ruby/core/string/split_spec.rb | 8 |
3 files changed, 25 insertions, 0 deletions
diff --git a/spec/ruby/core/string/scrub_spec.rb b/spec/ruby/core/string/scrub_spec.rb index 390035ef30..86fd4e85ba 100644 --- a/spec/ruby/core/string/scrub_spec.rb +++ b/spec/ruby/core/string/scrub_spec.rb @@ -39,6 +39,13 @@ describe "String#scrub with a custom replacement" do "abc\u3042#{x81}".scrub("*").should == "abc\u3042*" end + it "replaces invalid byte sequences in frozen strings" do + x81 = [0x81].pack('C').force_encoding('utf-8') + (-"abc\u3042#{x81}").scrub("*").should == "abc\u3042*" + utf16_str = ("abc".encode('UTF-16LE').bytes + [0x81]).pack('c*').force_encoding('UTF-16LE') + (-(utf16_str)).scrub("*".encode('UTF-16LE')).should == "abc*".encode('UTF-16LE') + end + it "replaces an incomplete character at the end with a single replacement" do xE3x80 = [0xE3, 0x80].pack('CC').force_encoding 'utf-8' xE3x80.scrub("*").should == "*" diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb index 69997b7c1d..a674e0b6ef 100644 --- a/spec/ruby/core/string/shared/slice.rb +++ b/spec/ruby/core/string/shared/slice.rb @@ -335,6 +335,16 @@ describe :string_slice_range, shared: true do "hello there".send(@method, eval("(-4...)")).should == "here" end end + + ruby_version_is "2.7" do + it "works with beginless ranges" do + "hello there".send(@method, eval("(..5)")).should == "hello " + "hello there".send(@method, eval("(...5)")).should == "hello" + "hello there".send(@method, eval("(..-4)")).should == "hello th" + "hello there".send(@method, eval("(...-4)")).should == "hello t" + "hello there".send(@method, eval("(...nil)")).should == "hello there" + end + end end describe :string_slice_regexp, shared: true do diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index c5441e3a49..2ebfe1e353 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -471,6 +471,14 @@ describe "String#split with Regexp" do a.should == ["Chunky", "Bacon"] end + it "yields each split substring with default pattern for a non-ASCII string" do + a = [] + returned_object = "l'été arrive bientôt".split { |str| a << str } + + returned_object.should == "l'été arrive bientôt" + a.should == ["l'été", "arrive", "bientôt"] + end + it "yields the string when limit is 1" do a = [] returned_object = "chunky bacon".split("", 1) { |str| a << str.capitalize } |