diff options
author | Benoit Daloze <eregontp@gmail.com> | 2022-09-28 18:37:17 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2022-09-28 18:37:17 +0200 |
commit | 31cf1bb5256314b69eae92673d3dd5815158ee91 (patch) | |
tree | 5ee049f751426794bfe47d0fa847f5621d3a039d /spec/ruby/core/string/split_spec.rb | |
parent | 5a1ab740fc287df8bf4038f19bd28bbb73e181b6 (diff) | |
download | ruby-31cf1bb5256314b69eae92673d3dd5815158ee91.tar.gz |
Update to ruby/spec@1d9d5c6
Diffstat (limited to 'spec/ruby/core/string/split_spec.rb')
-rw-r--r-- | spec/ruby/core/string/split_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index b57f660816..0417486692 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -29,9 +29,35 @@ describe "String#split with String" do "1,2,,3,4,,".split(',').should == ["1", "2", "", "3", "4"] "1,2,,3,4,,".split(',', 0).should == ["1", "2", "", "3", "4"] " a b c\nd ".split(" ").should == ["", "a", "b", "c\nd"] + " a あ c\nd ".split(" ").should == ["", "a", "あ", "c\nd"] "hai".split("hai").should == [] ",".split(",").should == [] ",".split(",", 0).should == [] + "あ".split("あ").should == [] + "あ".split("あ", 0).should == [] + end + + it "does not suppress trailing empty fields when a positive limit is given" do + " 1 2 ".split(" ", 2).should == ["1", "2 "] + " 1 2 ".split(" ", 3).should == ["1", "2", ""] + " 1 2 ".split(" ", 4).should == ["1", "2", ""] + " 1 あ ".split(" ", 2).should == ["1", "あ "] + " 1 あ ".split(" ", 3).should == ["1", "あ", ""] + " 1 あ ".split(" ", 4).should == ["1", "あ", ""] + + "1,2,".split(',', 2).should == ["1", "2,"] + "1,2,".split(',', 3).should == ["1", "2", ""] + "1,2,".split(',', 4).should == ["1", "2", ""] + "1,あ,".split(',', 2).should == ["1", "あ,"] + "1,あ,".split(',', 3).should == ["1", "あ", ""] + "1,あ,".split(',', 4).should == ["1", "あ", ""] + + "1 2 ".split(/ /, 2).should == ["1", "2 "] + "1 2 ".split(/ /, 3).should == ["1", "2", ""] + "1 2 ".split(/ /, 4).should == ["1", "2", ""] + "1 あ ".split(/ /, 2).should == ["1", "あ "] + "1 あ ".split(/ /, 3).should == ["1", "あ", ""] + "1 あ ".split(/ /, 4).should == ["1", "あ", ""] end it "returns an array with one entry if limit is 1: the original string" do |