diff options
author | Benoit Daloze <eregontp@gmail.com> | 2022-09-03 12:46:57 +0200 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2022-09-10 19:02:15 +0200 |
commit | 14bcf69c9c36875c7956d0ec8c04bfeaec514dd1 (patch) | |
tree | fd61c7b98e61ce27c2ee9421d5a6ea6d5278203b /spec/ruby/core | |
parent | f64117952534b71a11636837bddbfea7506ee785 (diff) | |
download | ruby-14bcf69c9c36875c7956d0ec8c04bfeaec514dd1.tar.gz |
Deprecate Encoding#replicate
* See [Feature #18949].
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/encoding/replicate_spec.rb | 108 |
1 files changed, 58 insertions, 50 deletions
diff --git a/spec/ruby/core/encoding/replicate_spec.rb b/spec/ruby/core/encoding/replicate_spec.rb index 45727a5c0d..848415eeb4 100644 --- a/spec/ruby/core/encoding/replicate_spec.rb +++ b/spec/ruby/core/encoding/replicate_spec.rb @@ -2,66 +2,74 @@ require_relative '../../spec_helper' describe "Encoding#replicate" do - before :all do - @i = 0 - end + ruby_version_is ""..."3.3" do + before :all do + @i = 0 + end - before :each do - @i += 1 - @prefix = "RS#{@i}" - end + before :each do + @i += 1 + @prefix = "RS#{@i}" + end - it "returns a replica of ASCII" do - name = @prefix + '-ASCII' - e = Encoding::ASCII.replicate(name) - e.name.should == name - Encoding.find(name).should == e + it "returns a replica of ASCII" do + name = @prefix + '-ASCII' + e = suppress_warning { Encoding::ASCII.replicate(name) } + e.name.should == name + Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false - end + "a".force_encoding(e).valid_encoding?.should be_true + "\x80".force_encoding(e).valid_encoding?.should be_false + end - it "returns a replica of UTF-8" do - name = @prefix + 'UTF-8' - e = Encoding::UTF_8.replicate(name) - e.name.should == name - Encoding.find(name).should == e + it "returns a replica of UTF-8" do + name = @prefix + 'UTF-8' + e = suppress_warning { Encoding::UTF_8.replicate(name) } + e.name.should == name + Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_true - "\u3042".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false - end + "a".force_encoding(e).valid_encoding?.should be_true + "\u3042".force_encoding(e).valid_encoding?.should be_true + "\x80".force_encoding(e).valid_encoding?.should be_false + end - it "returns a replica of UTF-16BE" do - name = @prefix + 'UTF-16-BE' - e = Encoding::UTF_16BE.replicate(name) - e.name.should == name - Encoding.find(name).should == e + it "returns a replica of UTF-16BE" do + name = @prefix + 'UTF-16-BE' + e = suppress_warning { Encoding::UTF_16BE.replicate(name) } + e.name.should == name + Encoding.find(name).should == e - "a".force_encoding(e).valid_encoding?.should be_false - "\x30\x42".force_encoding(e).valid_encoding?.should be_true - "\x80".force_encoding(e).valid_encoding?.should be_false - end + "a".force_encoding(e).valid_encoding?.should be_false + "\x30\x42".force_encoding(e).valid_encoding?.should be_true + "\x80".force_encoding(e).valid_encoding?.should be_false + end - it "returns a replica of ISO-2022-JP" do - name = @prefix + 'ISO-2022-JP' - e = Encoding::ISO_2022_JP.replicate(name) - Encoding.find(name).should == e + it "returns a replica of ISO-2022-JP" do + name = @prefix + 'ISO-2022-JP' + e = suppress_warning { Encoding::ISO_2022_JP.replicate(name) } + Encoding.find(name).should == e - e.name.should == name - e.dummy?.should be_true - end + e.name.should == name + e.dummy?.should be_true + end - # NOTE: it's unclear of the value of this (for the complexity cost of it), - # but it is the current CRuby behavior. - it "can be associated with a String" do - name = @prefix + '-US-ASCII' - e = Encoding::US_ASCII.replicate(name) - e.name.should == name - Encoding.find(name).should == e + # NOTE: it's unclear of the value of this (for the complexity cost of it), + # but it is the current CRuby behavior. + it "can be associated with a String" do + name = @prefix + '-US-ASCII' + e = suppress_warning { Encoding::US_ASCII.replicate(name) } + e.name.should == name + Encoding.find(name).should == e + + s = "abc".force_encoding(e) + s.encoding.should == e + s.encoding.name.should == name + end + end - s = "abc".force_encoding(e) - s.encoding.should == e - s.encoding.name.should == name + ruby_version_is "3.3" do + it "has been removed" do + Encoding::US_ASCII.should_not.respond_to?(:replicate, true) + end end end |