diff options
author | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-25 05:14:04 +0000 |
---|---|---|
committer | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-12-25 05:14:04 +0000 |
commit | a2443bdcf9f0c57c6623524fa5f85cd0d3a8ed29 (patch) | |
tree | 26624021562311c0fa872fcaa8b514f44a5204cc | |
parent | 33a071016b312561e74470441bc512a13a9bf1d1 (diff) | |
download | ruby-a2443bdcf9f0c57c6623524fa5f85cd0d3a8ed29.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14662 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | lib/csv.rb | 16 | ||||
-rw-r--r-- | test/csv/tc_csv_parsing.rb | 4 | ||||
-rw-r--r-- | test/csv/tc_features.rb | 2 | ||||
-rw-r--r-- | test/csv/tc_serialization.rb | 2 |
5 files changed, 21 insertions, 10 deletions
@@ -1,3 +1,10 @@ +Tue Dec 25 14:09:16 2007 James Edward Gray II <jeg2@ruby-lang.org> + + * 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@ruby-lang.org> * io.c (io_encoding_set): missing return type. diff --git a/lib/csv.rb b/lib/csv.rb index a37bc700b2..b12142e50a 100644 --- a/lib/csv.rb +++ b/lib/csv.rb @@ -187,10 +187,12 @@ class CSV @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 @@ class CSV # 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 @@ class CSV 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 # diff --git a/test/csv/tc_csv_parsing.rb b/test/csv/tc_csv_parsing.rb index 9eb2e398d4..965af929f3 100644 --- a/test/csv/tc_csv_parsing.rb +++ b/test/csv/tc_csv_parsing.rb @@ -123,7 +123,7 @@ class TestCSVParsing < Test::Unit::TestCase 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 @@ class TestCSVParsing < Test::Unit::TestCase 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"/ }) diff --git a/test/csv/tc_features.rb b/test/csv/tc_features.rb index 6766839e10..ae5a8a451b 100644 --- a/test/csv/tc_features.rb +++ b/test/csv/tc_features.rb @@ -82,7 +82,7 @@ class TestCSVFeatures < Test::Unit::TestCase 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) diff --git a/test/csv/tc_serialization.rb b/test/csv/tc_serialization.rb index 45e26bc0b5..d9c37fde21 100644 --- a/test/csv/tc_serialization.rb +++ b/test/csv/tc_serialization.rb @@ -13,7 +13,7 @@ require "csv" # 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 |