summaryrefslogtreecommitdiff
path: root/test/csv
diff options
context:
space:
mode:
authorjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 14:59:25 +0000
committerjeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-03-23 14:59:25 +0000
commit1bd1128989a339790a658c43ec3d9769b49265da (patch)
tree6efae89644fcd74cdab3f28209243b8e9c057cf1 /test/csv
parent0471422beb4d786ede528612c8486296761a59ee (diff)
* lib/csv.rb: Incorporating the fixes from the recent
FasterCSV releases: 1.5.2 and 1.5.3. [ruby-core:25038] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv')
-rw-r--r--test/csv/test_csv_parsing.rb12
-rw-r--r--test/csv/test_interface.rb7
-rw-r--r--test/csv/test_table.rb2
3 files changed, 20 insertions, 1 deletions
diff --git a/test/csv/test_csv_parsing.rb b/test/csv/test_csv_parsing.rb
index a9e6cd4..e3609b7 100644
--- a/test/csv/test_csv_parsing.rb
+++ b/test/csv/test_csv_parsing.rb
@@ -115,6 +115,18 @@ class TestCSVParsing < Test::Unit::TestCase
assert_equal(Array.new, CSV.parse_line("\n1,2,3\n"))
end
+ def test_non_regex_edge_cases
+ # An early version of the non-regex parser fails this test
+ [ [ "foo,\"foo,bar,baz,foo\",\"foo\"",
+ ["foo", "foo,bar,baz,foo", "foo"] ] ].each do |edge_case|
+ assert_equal(edge_case.last, CSV.parse_line(edge_case.first))
+ end
+
+ assert_raise(CSV::MalformedCSVError) do
+ CSV.parse_line("1,\"23\"4\"5\", 6")
+ end
+ end
+
def test_malformed_csv
assert_raise(CSV::MalformedCSVError) do
CSV.parse_line("1,2\r,3", row_sep: "\n")
diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb
index 5aedbbb..04d0edc 100644
--- a/test/csv/test_interface.rb
+++ b/test/csv/test_interface.rb
@@ -75,6 +75,11 @@ class TestCSVInterface < Test::Unit::TestCase
assert_equal(%w{1 2 3}, row)
end
+ def test_parse_line_with_empty_lines
+ assert_equal(nil, CSV.parse_line("")) # to signal eof
+ assert_equal(Array.new, CSV.parse_line("\n1,2,3"))
+ end
+
def test_read_and_readlines
assert_equal( @expected,
CSV.read(@path, col_sep: "\t", row_sep: "\r\n") )
@@ -167,7 +172,7 @@ class TestCSVInterface < Test::Unit::TestCase
csv << lines.first.keys
lines.each { |line| csv << line }
end
- CSV.open( @path, "w", headers: true,
+ CSV.open( @path, "r", headers: true,
converters: :all,
header_converters: :symbol ) do |csv|
csv.each { |line| assert_equal(lines.shift, line.to_hash) }
diff --git a/test/csv/test_table.rb b/test/csv/test_table.rb
index b7c72b8..d0b4217 100644
--- a/test/csv/test_table.rb
+++ b/test/csv/test_table.rb
@@ -253,6 +253,8 @@ class TestCSVTable < Test::Unit::TestCase
# with options
assert_equal( csv.gsub(",", "|").gsub("\n", "\r\n"),
@table.to_csv(col_sep: "|", row_sep: "\r\n") )
+ assert_equal( csv.lines.to_a[1..-1].join,
+ @table.to_csv(:write_headers => false) )
# with headers
assert_equal(csv, @header_table.to_csv)