mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/net/ftp.rb (getmultiline): refactor.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51818 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ffe47606cc
commit
5c09cb9c1e
3 changed files with 40 additions and 8 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Sep 10 15:16:02 2015 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* lib/net/ftp.rb (getmultiline): refactor.
|
||||
|
||||
Thu Sep 10 12:17:28 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* compile.c (iseq_build_from_ary_body): register cdhash to the
|
||||
|
|
|
@ -298,16 +298,16 @@ module Net
|
|||
|
||||
# Receive a section of lines until the response code's match.
|
||||
def getmultiline # :nodoc:
|
||||
line = getline
|
||||
buff = line
|
||||
if line[3] == ?-
|
||||
code = line[0, 3]
|
||||
lines = []
|
||||
lines << getline
|
||||
code = lines.last.slice(/\A([0-9a-zA-Z]{3})-/, 1)
|
||||
if code
|
||||
delimiter = code + " "
|
||||
begin
|
||||
line = getline
|
||||
buff << "\n" << line
|
||||
end until line[0, 3] == code and line[3] != ?-
|
||||
lines << getline
|
||||
end until lines.last.start_with?(delimiter)
|
||||
end
|
||||
return buff << "\n"
|
||||
return lines.join("\n") + "\n"
|
||||
end
|
||||
private :getmultiline
|
||||
|
||||
|
|
|
@ -1025,6 +1025,34 @@ EOF
|
|||
end
|
||||
end
|
||||
|
||||
def test_getmultiline
|
||||
server = create_ftp_server { |sock|
|
||||
sock.print("220 (test_ftp).\r\n")
|
||||
sock.print("123- foo\r\n")
|
||||
sock.print("bar\r\n")
|
||||
sock.print(" 123 baz\r\n")
|
||||
sock.print("123 quux\r\n")
|
||||
sock.print("123 foo\r\n")
|
||||
sock.print("foo\r\n")
|
||||
sock.print("\r\n")
|
||||
}
|
||||
begin
|
||||
begin
|
||||
ftp = Net::FTP.new
|
||||
ftp.connect(SERVER_ADDR, server.port)
|
||||
assert_equal("123- foo\nbar\n 123 baz\n123 quux\n",
|
||||
ftp.send(:getmultiline))
|
||||
assert_equal("123 foo\n", ftp.send(:getmultiline))
|
||||
assert_equal("foo\n", ftp.send(:getmultiline))
|
||||
assert_equal("\n", ftp.send(:getmultiline))
|
||||
ensure
|
||||
ftp.close if ftp
|
||||
end
|
||||
ensure
|
||||
server.close
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue