diff options
author | Benoit Daloze <eregontp@gmail.com> | 2022-11-07 20:05:30 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2022-11-07 20:05:30 +0100 |
commit | 83decbb62b8b3f1638927033f12b55f9b11f78c6 (patch) | |
tree | 8995f5b5cdb615f3d19edded66c6a9a9e82f159c /spec/ruby/core/string/partition_spec.rb | |
parent | c99e4c427897e82a3419abed894d28705f70fa13 (diff) | |
download | ruby-83decbb62b8b3f1638927033f12b55f9b11f78c6.tar.gz |
Update to ruby/spec@740ccc8
Diffstat (limited to 'spec/ruby/core/string/partition_spec.rb')
-rw-r--r-- | spec/ruby/core/string/partition_spec.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/ruby/core/string/partition_spec.rb b/spec/ruby/core/string/partition_spec.rb index 98311f2be4..9cb3672881 100644 --- a/spec/ruby/core/string/partition_spec.rb +++ b/spec/ruby/core/string/partition_spec.rb @@ -38,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".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".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 |