diff options
Diffstat (limited to 'spec/ruby/core/string/partition_spec.rb')
| -rw-r--r-- | spec/ruby/core/string/partition_spec.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/spec/ruby/core/string/partition_spec.rb b/spec/ruby/core/string/partition_spec.rb index 98311f2be4..29fe910b39 100644 --- a/spec/ruby/core/string/partition_spec.rb +++ b/spec/ruby/core/string/partition_spec.rb @@ -31,11 +31,33 @@ describe "String#partition with String" do end it "raises an error if not convertible to string" do - ->{ "hello".partition(5) }.should raise_error(TypeError) - ->{ "hello".partition(nil) }.should raise_error(TypeError) + ->{ "hello".partition(5) }.should.raise(TypeError) + ->{ "hello".partition(nil) }.should.raise(TypeError) end 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 |
