summaryrefslogtreecommitdiff
path: root/test/csv/tc_headers.rb
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-21 00:39:03 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-09-21 00:39:03 +0000
commit280cbe0b1fb807ee0de9ea3e862d556763e08811 (patch)
tree119a30ce987d3db1cba06d7b3a02b2fcf8d06b6c /test/csv/tc_headers.rb
parent31eacb6ed129b7483f6f8a74034986cb7ead1836 (diff)
* lib/csv/csv.rb: Reworked CSV's parser and generator to be m17n. Data
is now parsed in the Encoding it is in without need for translation. * lib/csv/csv.rb: Improved inspect() messages for better IRb support. * lib/csv/csv.rb: Fixed header writing bug reported by Dov Murik. * lib/csv/csv.rb: Use custom separators in parsing header Strings as suggested by Shmulik Regev. * lib/csv/csv.rb: Added a :write_headers option for outputting headers. * lib/csv/csv.rb: Handle open() calls in binary mode whenever we can to workaround a Windows issue where line-ending translation can cause an off-by-one error in seeking back to a non-zero starting position after auto-discovery for :row_sep as suggested by Robert Battle. * lib/csv/csv.rb: Improved the parser to fail faster when fed some forms of invalid CSV that can be detected without reading ahead. * lib/csv/csv.rb: Added a :field_size_limit option to control CSV's lookahead and prevent the parser from biting off more data than it can chew. * lib/csv/csv.rb: Added readers for CSV attributes: col_sep(), row_sep(), quote_char(), field_size_limit(), converters(), unconverted_fields?(), headers(), return_headers?(), write_headers?(), header_converters(), skip_blanks?(), and force_quotes?(). * lib/csv/csv.rb: Cleaned up code syntax to be more inline with Ruby 1.9 than 1.8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/tc_headers.rb')
-rw-r--r--test/csv/tc_headers.rb29
1 files changed, 28 insertions, 1 deletions
diff --git a/test/csv/tc_headers.rb b/test/csv/tc_headers.rb
index 74e2f54ad4..e0f544dadf 100644
--- a/test/csv/tc_headers.rb
+++ b/test/csv/tc_headers.rb
@@ -1,4 +1,5 @@
-#!/usr/local/bin/ruby -w
+#!/usr/bin/env ruby -w
+# encoding: UTF-8
# tc_headers.rb
#
@@ -129,6 +130,21 @@ class TestCSVHeaders < Test::Unit::TestCase
assert(!row.field_row?)
end
+ def test_csv_header_string_inherits_separators
+ # parse with custom col_sep
+ csv = nil
+ assert_nothing_raised(Exception) do
+ csv = CSV.parse( @data.tr(",", "|"), :col_sep => "|",
+ :headers => "my|new|headers" )
+ end
+
+ # verify headers were recognized
+ row = csv[0]
+ assert_not_nil(row)
+ assert_instance_of(CSV::Row, row)
+ assert_equal([%w{my first}, %w{new second}, %w{headers third}], row.to_a)
+ end
+
def test_return_headers
# activate headers and request they are returned
csv = nil
@@ -250,6 +266,17 @@ class TestCSVHeaders < Test::Unit::TestCase
end
end
+ def test_headers_reader
+ # no headers
+ assert_nil(CSV.new(@data).headers)
+
+ # headers
+ csv = CSV.new(@data, :headers => true)
+ assert_equal(true, csv.headers) # before headers are read
+ csv.shift # set headers
+ assert_equal(%w[first second third], csv.headers) # after headers are read
+ end
+
def test_blank_row_bug_fix
@data += "\n#{@data}" # add a blank row