diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-06-02 14:34:07 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-06-02 14:34:07 +0200 |
commit | 22e2a6a999b958efe5d84d9c7314e450fda82254 (patch) | |
tree | b2dc946cf2fe2c250d0583675e548c67dca3e71a /spec/ruby/core/kernel/shared/sprintf.rb | |
parent | a4fbc7e2884ba694278adea3b32ddb8c2ac10efe (diff) |
Update to ruby/spec@a0b7d0d
Diffstat (limited to 'spec/ruby/core/kernel/shared/sprintf.rb')
-rw-r--r-- | spec/ruby/core/kernel/shared/sprintf.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/shared/sprintf.rb b/spec/ruby/core/kernel/shared/sprintf.rb index ca1e6bb2ed..6d62a65f7c 100644 --- a/spec/ruby/core/kernel/shared/sprintf.rb +++ b/spec/ruby/core/kernel/shared/sprintf.rb @@ -342,6 +342,23 @@ describe :kernel_sprintf, shared: true do sub_string = long_string[8, 5] sprintf("%.#{1 * 3}s", sub_string).should == "hel" end + + it "formats string with precision" do + Kernel.format("%.3s", "hello").should == "hel" + Kernel.format("%-3.3s", "hello").should == "hel" + end + + it "formats multibyte string with precision" do + Kernel.format("%.2s", "été").should == "ét" + end + + it "preserves encoding of the format string" do + str = format('%s'.encode(Encoding::UTF_8), 'foobar') + str.encoding.should == Encoding::UTF_8 + + str = format('%s'.encode(Encoding::US_ASCII), 'foobar') + str.encoding.should == Encoding::US_ASCII + end end describe "%" do |