1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/net/http/header.rb (Net::HTTPHeader#{each_header,each_name,

each_capitalized_name,each_value,each_capitalized}): Return
  sized enumerators.

* test/net/http/test_httpheader.rb: add test for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54906 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ktsj 2016-05-04 09:46:46 +00:00
parent 803177b38e
commit 6da2214119
3 changed files with 53 additions and 5 deletions

View file

@ -1,3 +1,11 @@
Wed May 4 18:38:00 2016 Kazuki Tsujimoto <kazuki@callcc.net>
* lib/net/http/header.rb (Net::HTTPHeader#{each_header,each_name,
each_capitalized_name,each_value,each_capitalized}): Return
sized enumerators.
* test/net/http/test_httpheader.rb: add test for above.
Wed May 4 17:53:15 2016 Kazuki Tsujimoto <kazuki@callcc.net>
* lib/set.rb (Set#{delete_if,keep_if,collect!,reject!,select!,classify,divide},

View file

@ -101,7 +101,7 @@ module Net::HTTPHeader
# response.header.each_header {|key,value| puts "#{key} = #{value}" }
#
def each_header #:yield: +key+, +value+
block_given? or return enum_for(__method__)
block_given? or return enum_for(__method__) { @header.size }
@header.each do |k,va|
yield k, va.join(', ')
end
@ -112,7 +112,7 @@ module Net::HTTPHeader
# Iterates through the header names in the header, passing
# each header name to the code block.
def each_name(&block) #:yield: +key+
block_given? or return enum_for(__method__)
block_given? or return enum_for(__method__) { @header.size }
@header.each_key(&block)
end
@ -125,7 +125,7 @@ module Net::HTTPHeader
# capitalization may not match that used by the remote HTTP
# server in its response.
def each_capitalized_name #:yield: +key+
block_given? or return enum_for(__method__)
block_given? or return enum_for(__method__) { @header.size }
@header.each_key do |k|
yield capitalize(k)
end
@ -134,7 +134,7 @@ module Net::HTTPHeader
# Iterates through header values, passing each value to the
# code block.
def each_value #:yield: +value+
block_given? or return enum_for(__method__)
block_given? or return enum_for(__method__) { @header.size }
@header.each_value do |va|
yield va.join(', ')
end
@ -165,7 +165,7 @@ module Net::HTTPHeader
# capitalization may not match that used by the remote HTTP
# server in its response.
def each_capitalized
block_given? or return enum_for(__method__)
block_given? or return enum_for(__method__) { @header.size }
@header.each do |k,v|
yield capitalize(k), v.join(', ')
end

View file

@ -111,6 +111,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal 'my-header', k
assert_equal 'test', v
end
e = @c.each
assert_equal 1, e.size
e.each do |k, v|
assert_equal 'my-header', k
assert_equal 'test', v
end
end
def test_each_key
@ -121,6 +127,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
@c.each_key do |k|
assert_equal 'my-header', k
end
e = @c.each_key
assert_equal 1, e.size
e.each do |k|
assert_equal 'my-header', k
end
end
def test_each_capitalized_name
@c['my-header'] = 'test'
@ -130,6 +142,11 @@ class HTTPHeaderTest < Test::Unit::TestCase
@c.each_capitalized_name do |k|
assert_equal 'My-Header', k
end
e = @c.each_capitalized_name
assert_equal 1, e.size
e.each do |k|
assert_equal 'My-Header', k
end
end
def test_each_value
@ -140,6 +157,11 @@ class HTTPHeaderTest < Test::Unit::TestCase
@c.each_value do |v|
assert_equal 'test', v
end
e = @c.each_value
assert_equal 1, e.size
e.each do |v|
assert_equal 'test', v
end
end
def test_canonical_each
@ -148,6 +170,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal 'My-Header', k
assert_equal 'a, b', v
end
e = @c.canonical_each
assert_equal 1, e.size
e.each do |k,v|
assert_equal 'My-Header', k
assert_equal 'a, b', v
end
end
def test_each_capitalized
@ -156,6 +184,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal 'My-Header', k
assert_equal 'a, b', v
end
e = @c.each_capitalized
assert_equal 1, e.size
e.each do |k,v|
assert_equal 'My-Header', k
assert_equal 'a, b', v
end
end
def test_each_capitalized_with_symbol
@ -164,6 +198,12 @@ class HTTPHeaderTest < Test::Unit::TestCase
assert_equal "My_header", k
assert_equal 'a, b', v
end
e = @c.each_capitalized
assert_equal 1, e.size
e.each do |k,v|
assert_equal 'My_header', k
assert_equal 'a, b', v
end
end
def test_key?