diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-10-24 15:52:37 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-10-24 15:53:53 +0200 |
commit | 148961adcd0704d964fce920330a6301b9704c25 (patch) | |
tree | 1f1f0cb7326775788683c77f0e2cceb495d3cc95 /spec/ruby/core/integer | |
parent | 342fbae83c2e80d1b49656bc7c689cc7fe8980ce (diff) |
Update to ruby/spec@4f59d86
Diffstat (limited to 'spec/ruby/core/integer')
-rw-r--r-- | spec/ruby/core/integer/chr_spec.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/spec/ruby/core/integer/chr_spec.rb b/spec/ruby/core/integer/chr_spec.rb index a8755eeb84..9f105e4241 100644 --- a/spec/ruby/core/integer/chr_spec.rb +++ b/spec/ruby/core/integer/chr_spec.rb @@ -240,4 +240,17 @@ describe "Integer#chr with an encoding argument" do -> { integer.chr(encoding_name) }.should raise_error(RangeError) end end + + ruby_version_is "2.7" do + it 'returns a String encoding self interpreted as a codepoint in the CESU-8 encoding' do + # see more details here https://en.wikipedia.org/wiki/CESU-8 + # code points from U+0000 to U+FFFF is encoded in the same way as in UTF-8 + 0x0045.chr(Encoding::CESU_8).bytes.should == 0x0045.chr(Encoding::UTF_8).bytes + + # code points in range from U+10000 to U+10FFFF is CESU-8 data containing a 6-byte surrogate pair, + # which decodes to a 4-byte UTF-8 string + 0x10400.chr(Encoding::CESU_8).bytes.should != 0x10400.chr(Encoding::UTF_8).bytes + 0x10400.chr(Encoding::CESU_8).bytes.to_a.should == [0xED, 0xA0, 0x81, 0xED, 0xB0, 0x80] + end + end end |