ruby-changes:42832
From: ktsj <ko1@a...>
Date: Wed, 4 May 2016 17:50:10 +0900 (JST)
Subject: [ruby-changes:42832] ktsj:r54906 (trunk): * lib/net/http/header.rb (Net::HTTPHeader#{each_header, each_name,
ktsj 2016-05-04 18:46:46 +0900 (Wed, 04 May 2016) New Revision: 54906 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54906 Log: * 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. Modified files: trunk/ChangeLog trunk/lib/net/http/header.rb trunk/test/net/http/test_httpheader.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54905) +++ ChangeLog (revision 54906) @@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 4 18:38:00 2016 Kazuki Tsujimoto <kazuki@c...> + + * 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@c...> * lib/set.rb (Set#{delete_if,keep_if,collect!,reject!,select!,classify,divide}, Index: test/net/http/test_httpheader.rb =================================================================== --- test/net/http/test_httpheader.rb (revision 54905) +++ test/net/http/test_httpheader.rb (revision 54906) @@ -111,6 +111,12 @@ class HTTPHeaderTest < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L111 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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L127 @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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L142 @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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L157 @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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L170 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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L184 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::TestC https://github.com/ruby/ruby/blob/trunk/test/net/http/test_httpheader.rb#L198 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? Index: lib/net/http/header.rb =================================================================== --- lib/net/http/header.rb (revision 54905) +++ lib/net/http/header.rb (revision 54906) @@ -101,7 +101,7 @@ module Net::HTTPHeader https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L101 # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L112 # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L125 # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L134 # 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 https://github.com/ruby/ruby/blob/trunk/lib/net/http/header.rb#L165 # 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/