mirror of
https://github.com/ruby/ruby.git
synced 2025-08-27 23:16:42 +02:00
Remove Encoding#replicate
This commit is contained in:
parent
d831b1d5ce
commit
6abe20e87b
Notes:
git
2023-01-11 12:42:09 +00:00
8 changed files with 203 additions and 113 deletions
15
test/-ext-/string/test_too_many_dummy_encodings.rb
Normal file
15
test/-ext-/string/test_too_many_dummy_encodings.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
# frozen_string_literal: false
|
||||
require 'test/unit'
|
||||
require "-test-/string"
|
||||
|
||||
class Test_TooManyDummyEncodings < Test::Unit::TestCase
|
||||
def test_exceed_encoding_table_size
|
||||
assert_separately(%w[--disable=gems], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||
begin;
|
||||
require "-test-/string"
|
||||
assert_raise_with_message(EncodingError, /too many encoding/) do
|
||||
1_000.times{|i| Bug::String.rb_define_dummy_encoding("R_#{i}") } # now 256 entries
|
||||
end
|
||||
end;
|
||||
end
|
||||
end
|
|
@ -55,40 +55,6 @@ class TestEncoding < Test::Unit::TestCase
|
|||
assert_raise(TypeError, bug5150) {Encoding.find(1)}
|
||||
end
|
||||
|
||||
def test_replicate
|
||||
assert_separately([], "#{<<~'END;'}")
|
||||
Warning[:deprecated] = false
|
||||
assert_instance_of(Encoding, Encoding::UTF_8.replicate("UTF-8-ANOTHER#{Time.now.to_f}"))
|
||||
assert_instance_of(Encoding, Encoding::ISO_2022_JP.replicate("ISO-2022-JP-ANOTHER#{Time.now.to_f}"))
|
||||
bug3127 = '[ruby-dev:40954]'
|
||||
assert_raise(TypeError, bug3127) {Encoding::UTF_8.replicate(0)}
|
||||
assert_raise_with_message(ArgumentError, /\bNUL\b/, bug3127) {Encoding::UTF_8.replicate("\0")}
|
||||
END;
|
||||
end
|
||||
|
||||
def test_extra_encoding
|
||||
assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||
begin;
|
||||
100.times {|i|
|
||||
EnvUtil.suppress_warning { Encoding::UTF_8.replicate("dummy#{i}") }
|
||||
}
|
||||
e = Encoding.list.last
|
||||
format = "%d".force_encoding(e)
|
||||
assert_equal("0", format % 0)
|
||||
assert_equal(e, format.dup.encoding)
|
||||
assert_equal(e, (format*1).encoding)
|
||||
|
||||
assert_equal(e, (("x"*30).force_encoding(e)*1).encoding)
|
||||
GC.start
|
||||
|
||||
name = "A" * 64
|
||||
Encoding.list.each do |enc|
|
||||
assert_raise(ArgumentError) { EnvUtil.suppress_warning { enc.replicate(name) } }
|
||||
name.succ!
|
||||
end
|
||||
end;
|
||||
end
|
||||
|
||||
def test_dummy_p
|
||||
assert_equal(true, Encoding::ISO_2022_JP.dummy?)
|
||||
assert_equal(false, Encoding::UTF_8.dummy?)
|
||||
|
@ -160,18 +126,4 @@ class TestEncoding < Test::Unit::TestCase
|
|||
end
|
||||
end;
|
||||
end
|
||||
|
||||
def test_exceed_encoding_table_size
|
||||
assert_separately(%w[--disable=gems], "#{<<~"begin;"}\n#{<<~'end;'}")
|
||||
begin;
|
||||
begin
|
||||
enc = Encoding::UTF_8
|
||||
1_000.times{|i| EnvUtil.suppress_warning{ enc.replicate("R_#{i}") } } # now 256 entries
|
||||
rescue EncodingError => e
|
||||
assert_match(/too many encoding/, e.message)
|
||||
else
|
||||
assert false
|
||||
end
|
||||
end;
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue