1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/net/ftp/test_buffered_socket.rb
normal e56d34001f net/ftp: fix FrozenError in BufferedSocket
I noticed this bug while working on something else with
RUBYOPT=-d on, existing test cases all passed with it.

Note: I use String.new because it is the local style, here,
I prefer +'' (or ''.b, for a future commit)

* lib/net/ftp.rb (BufferedSocket#read): use String.new
* test/net/ftp/test_buffered_socket.rb (test_read_nil): new test
  [ruby-core:84675] [Bug #14323]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61639 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-06 09:21:35 +00:00

48 lines
1 KiB
Ruby

# frozen_string_literal: true
require "net/ftp"
require "test/unit"
require "ostruct"
require "stringio"
class BufferedSocketTest < Test::Unit::TestCase
def test_gets_empty
sock = create_buffered_socket("")
assert_equal(nil, sock.gets)
end
def test_gets_one_line
sock = create_buffered_socket("foo\n")
assert_equal("foo\n", sock.gets)
end
def test_gets_one_line_without_term
sock = create_buffered_socket("foo")
assert_equal("foo", sock.gets)
end
def test_gets_two_lines
sock = create_buffered_socket("foo\nbar\n")
assert_equal("foo\n", sock.gets)
assert_equal("bar\n", sock.gets)
end
def test_gets_two_lines_without_term
sock = create_buffered_socket("foo\nbar")
assert_equal("foo\n", sock.gets)
assert_equal("bar", sock.gets)
end
def test_read_nil
sock = create_buffered_socket("foo\nbar")
assert_equal("foo\nbar", sock.read)
assert_equal("", sock.read)
end
private
def create_buffered_socket(s)
io = StringIO.new(s)
return Net::FTP::BufferedSocket.new(io)
end
end