diff options
author | 卜部昌平 <[email protected]> | 2020-07-27 11:15:50 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-12-03 12:47:51 +0900 |
commit | 43b95bafd57d04c8fb401d3a9b52aca3f5b4b0be (patch) | |
tree | 642b463fce3ff7c5d683eb6e8068cf2dfa2c14df /test | |
parent | 84eb2bfab940fc9c6962c10ede7f72cee3fb9899 (diff) |
delete deprecated IO-like methods
This commit deletes
{IO,ARGF,StringIO,Zib::GZipReader}#{bytes,chars,lines,codepoints}, which
have been deprecated since c47c095b9740e7c19d6fdca29ab661c1089221d4.
Note that String also has those methods. They are neither depreacted
nor deleted because they are not aliases of counterpart each_something.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_argf.rb | 37 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 68 |
2 files changed, 57 insertions, 48 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb index e558f7648d..6262514241 100644 --- a/test/ruby/test_argf.rb +++ b/test/ruby/test_argf.rb @@ -998,43 +998,10 @@ class TestArgf < Test::Unit::TestCase assert_ruby_status(["-e", "2.times {STDIN.tty?; readlines}"], "", bug5952) end - def test_lines + def test_each_codepoint ruby('-W1', '-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| {# - $stderr = $stdout - s = [] - ARGF.lines {|l| s << l } - p s - }; - assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read) - end - end - - def test_bytes - ruby('-W1', '-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| - {# - $stderr = $stdout - print Marshal.dump(ARGF.bytes.to_a) - }; - assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read)) - end - end - - def test_chars - ruby('-W1', '-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| - {# - $stderr = $stdout - print [Marshal.dump(ARGF.chars.to_a)].pack('m') - }; - assert_equal(["1", "\n", "2", "\n", "3", "\n", "4", "\n", "5", "\n", "6", "\n"], Marshal.load(f.read.unpack('m').first)) - end - end - - def test_codepoints - ruby('-W1', '-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f| - {# - $stderr = $stdout - print Marshal.dump(ARGF.codepoints.to_a) + print Marshal.dump(ARGF.each_codepoint.to_a) }; assert_equal([49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10], Marshal.load(f.read)) end diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index f02ce6d31a..9ce05e93fd 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -405,19 +405,6 @@ class TestIO < Test::Unit::TestCase } end - def test_each_codepoint_enumerator - make_tempfile {|t| - a = "" - b = "" - File.open(t, 'rt') {|f| - a = f.each_codepoint.take(4).pack('U*') - b = f.read(8) - } - assert_equal("foo\n", a) - assert_equal("bar\nbaz\n", b) - } - end - def test_rubydev33072 t = make_tempfile path = t.path @@ -1822,6 +1809,61 @@ class TestIO < Test::Unit::TestCase end) end + def test_each_line + pipe(proc do |w| + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_line + } + assert_equal("foo\n", e.next) + assert_equal("bar\n", e.next) + assert_equal("baz\n", e.next) + assert_raise(StopIteration) { e.next } + end) + end + + def test_each_byte + pipe(proc do |w| + w.binmode + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_byte + } + (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| + assert_equal(c.ord, e.next) + end + assert_raise(StopIteration) { e.next } + end) + end + + def test_each_char + pipe(proc do |w| + w.puts "foo" + w.puts "bar" + w.puts "baz" + w.close + end, proc do |r| + e = nil + assert_warn('') { + e = r.each_char + } + (%w(f o o) + ["\n"] + %w(b a r) + ["\n"] + %w(b a z) + ["\n"]).each do |c| + assert_equal(c, e.next) + end + assert_raise(StopIteration) { e.next } + end) + end + def test_readbyte pipe(proc do |w| w.binmode |