test/tc_csv_parsing.rb in fastercsv-0.1.9 vs test/tc_csv_parsing.rb in fastercsv-0.2.0

- old
+ new

@@ -111,11 +111,54 @@ def test_malformed_csv assert_raise(FasterCSV::MalformedCSVError) do FasterCSV.parse_line("1,2\r,3", :row_sep => "\n") end + + bad_data = <<-END_DATA.gsub(/^ +/, "") + line,1,abc + line,2,"def\nghi" + + line,4,some\rjunk + line,5,jkl + END_DATA + lines = bad_data.to_a + assert_equal(6, lines.size) + assert_match(/\Aline,4/, lines.find { |l| l =~ /some\rjunk/ }) + + csv = FasterCSV.new(bad_data) + begin + loop do + assert_not_nil(csv.shift) + assert_send([csv.lineno, :<, 4]) + end + rescue FasterCSV::MalformedCSVError + assert_equal( "Unquoted fields do not allow \\r or \\n (line 4).", + $!.message ) + end assert_raise(FasterCSV::MalformedCSVError) do FasterCSV.parse_line('1,2,"3...') + end + + bad_data = <<-END_DATA.gsub(/^ +/, "") + line,1,abc + line,2,"def\nghi" + + line,4,8'10" + line,5,jkl + END_DATA + lines = bad_data.to_a + assert_equal(6, lines.size) + assert_match(/\Aline,4/, lines.find { |l| l =~ /8'10"/ }) + + csv = FasterCSV.new(bad_data) + begin + loop do + assert_not_nil(csv.shift) + assert_send([csv.lineno, :<, 4]) + end + rescue FasterCSV::MalformedCSVError + assert_equal("Unclosed quoted field on line 4.", $!.message) end end end