ruby-changes:3170
From: ko1@a...
Date: 25 Dec 2007 14:14:36 +0900
Subject: [ruby-changes:3170] jeg2 - Ruby:r14662 (trunk): * lib/csv.rb: Fixed test failures caused by changes to Ruby.
jeg2 2007-12-25 14:14:04 +0900 (Tue, 25 Dec 2007) New Revision: 14662 Modified files: trunk/ChangeLog trunk/lib/csv.rb trunk/test/csv/tc_csv_parsing.rb trunk/test/csv/tc_features.rb trunk/test/csv/tc_serialization.rb Log: * lib/csv.rb: Fixed test failures caused by changes to Ruby. * test/csv/tc_serialization, test/csv/tc_csv_parsing, test/csv/tc_features: Fixed test failures caused by changes to Ruby. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/csv/tc_csv_parsing.rb?r1=14662&r2=14661 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14662&r2=14661 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/csv/tc_features.rb?r1=14662&r2=14661 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/lib/csv.rb?r1=14662&r2=14661 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/test/csv/tc_serialization.rb?r1=14662&r2=14661 Index: ChangeLog =================================================================== --- ChangeLog (revision 14661) +++ ChangeLog (revision 14662) @@ -1,3 +1,10 @@ +Tue Dec 25 14:09:16 2007 James Edward Gray II <jeg2@r...> + + * lib/csv.rb: Fixed test failures caused by changes to Ruby. + + * test/csv/tc_serialization, test/csv/tc_csv_parsing, test/csv/tc_features: + Fixed test failures caused by changes to Ruby. + Tue Dec 25 14:11:57 2007 Nobuyoshi Nakada <nobu@r...> * io.c (io_encoding_set): missing return type. Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 14661) +++ lib/csv.rb (revision 14662) @@ -187,10 +187,12 @@ @header_row = header_row # handle extra headers or fields - @row = if headers.size > fields.size - headers.zip(fields) - else - fields.zip(headers).map { |pair| pair.reverse } + larger, smaller, transform = headers.size > fields.size ? + [headers, fields, :to_a] : + [fields, headers, :reverse] + @row = Array.new + larger.each_with_index do |e, i| + @row << [e, smaller[i]].send(transform) end end @@ -1812,7 +1814,8 @@ # see if we are converting headers or fields converters = headers ? @header_converters : @converters - fields.enum_for(:each_with_index).map do |field, index| # map_with_index + converted = Array.new + fields.each_with_index do |field, index| converters.each do |converter| field = if converter.arity == 1 # straight field converter converter[field] @@ -1822,8 +1825,9 @@ end break unless field.is_a? String # short-curcuit pipeline for speed end - field # return final state of each field, converted or original + converted << field # final state of each field, converted or original end + converted end # Index: test/csv/tc_serialization.rb =================================================================== --- test/csv/tc_serialization.rb (revision 14661) +++ test/csv/tc_serialization.rb (revision 14662) @@ -13,7 +13,7 @@ # An example of how to provide custom CSV serialization. class Hash def self.csv_load( meta, headers, fields ) - self[*headers.zip(fields).flatten.map { |e| eval(e) }] + self[*headers.zip(fields).to_a.flatten.map { |e| eval(e) }] end def csv_headers Index: test/csv/tc_csv_parsing.rb =================================================================== --- test/csv/tc_csv_parsing.rb (revision 14661) +++ test/csv/tc_csv_parsing.rb (revision 14662) @@ -123,7 +123,7 @@ line,4,some\rjunk line,5,jkl END_DATA - lines = bad_data.to_a + lines = bad_data.lines.to_a assert_equal(6, lines.size) assert_match(/\Aline,4/, lines.find { |l| l =~ /some\rjunk/ }) @@ -147,7 +147,7 @@ line,4,8'10" line,5,jkl END_DATA - lines = bad_data.to_a + lines = bad_data.lines.to_a assert_equal(6, lines.size) assert_match(/\Aline,4/, lines.find { |l| l =~ /8'10"/ }) Index: test/csv/tc_features.rb =================================================================== --- test/csv/tc_features.rb (revision 14661) +++ test/csv/tc_features.rb (revision 14662) @@ -82,7 +82,7 @@ end def test_lineno - assert_equal(5, @sample_data.to_a.size) + assert_equal(5, @sample_data.lines.to_a.size) 4.times do |line_count| assert_equal(line_count, @csv.lineno) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml