diff options
Diffstat (limited to 'spec/ruby/core/string/partition_spec.rb')
-rw-r--r-- | spec/ruby/core/string/partition_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/ruby/core/string/partition_spec.rb b/spec/ruby/core/string/partition_spec.rb index 996368d6a4..d5370dcc73 100644 --- a/spec/ruby/core/string/partition_spec.rb +++ b/spec/ruby/core/string/partition_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' +require_relative 'shared/partition' describe "String#partition with String" do + it_behaves_like :string_partition, :partition + it "returns an array of substrings based on splitting on the given string" do "hello world".partition("o").should == ["hell", "o", " world"] end @@ -35,4 +38,26 @@ describe "String#partition with String" do it "takes precedence over a given block" do "hello world".partition("o") { true }.should == ["hell", "o", " world"] end + + it "handles a pattern in a superset encoding" do + string = "hello".dup.force_encoding(Encoding::US_ASCII) + + result = string.partition("é") + + result.should == ["hello", "", ""] + result[0].encoding.should == Encoding::US_ASCII + result[1].encoding.should == Encoding::US_ASCII + result[2].encoding.should == Encoding::US_ASCII + end + + it "handles a pattern in a subset encoding" do + pattern = "o".dup.force_encoding(Encoding::US_ASCII) + + result = "héllo world".partition(pattern) + + result.should == ["héll", "o", " world"] + result[0].encoding.should == Encoding::UTF_8 + result[1].encoding.should == Encoding::US_ASCII + result[2].encoding.should == Encoding::UTF_8 + end end |