summaryrefslogtreecommitdiff
path: root/test/csv
diff options
context:
space:
mode:
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 a9e6cd400c..e3609b7648 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 5aedbbb075..04d0edc5f1 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 b7c72b8fcb..d0b421750f 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)