diff options
Diffstat (limited to 'spec/ruby/core/string/split_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/split_spec.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index 0417486692..519c5d845d 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -246,6 +246,13 @@ describe "String#split with String" do it "doesn't split on non-ascii whitespace" do "a\u{2008}b".split(" ").should == ["a\u{2008}b"] end + + it "returns Strings in the same encoding as self" do + strings = "hello world".encode("US-ASCII").split(" ") + + strings[0].encoding.should == Encoding::US_ASCII + strings[1].encoding.should == Encoding::US_ASCII + end end describe "String#split with Regexp" do @@ -443,13 +450,12 @@ describe "String#split with Regexp" do end end - it "retains the encoding of the source string" do + it "returns Strings in the same encoding as self" do ary = "а б в".split encodings = ary.map { |s| s.encoding } encodings.should == [Encoding::UTF_8, Encoding::UTF_8, Encoding::UTF_8] end - it "splits a string on each character for a multibyte encoding and empty split" do "That's why efficiency could not be helped".split("").size.should == 39 end @@ -598,4 +604,11 @@ describe "String#split with Regexp" do -> { "hello".split(false) }.should raise_error(TypeError) -> { "hello".split(Object.new) }.should raise_error(TypeError) end + + it "returns Strings in the same encoding as self" do + strings = "hello world".encode("US-ASCII").split(/ /) + + strings[0].encoding.should == Encoding::US_ASCII + strings[1].encoding.should == Encoding::US_ASCII + end end |
