diff options
author | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-21 00:39:03 +0000 |
---|---|---|
committer | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-21 00:39:03 +0000 |
commit | 280cbe0b1fb807ee0de9ea3e862d556763e08811 (patch) | |
tree | 119a30ce987d3db1cba06d7b3a02b2fcf8d06b6c /test/csv/tc_csv_parsing.rb | |
parent | 31eacb6ed129b7483f6f8a74034986cb7ead1836 (diff) | |
download | ruby-280cbe0b1fb807ee0de9ea3e862d556763e08811.tar.gz |
* 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_csv_parsing.rb')
-rw-r--r-- | test/csv/tc_csv_parsing.rb | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/test/csv/tc_csv_parsing.rb b/test/csv/tc_csv_parsing.rb index 965af929f3..635ae90531 100644 --- a/test/csv/tc_csv_parsing.rb +++ b/test/csv/tc_csv_parsing.rb @@ -1,4 +1,5 @@ -#!/usr/local/bin/ruby -w +#!/usr/bin/env ruby -w +# encoding: UTF-8 # tc_csv_parsing.rb # @@ -7,6 +8,7 @@ # under the terms of Ruby's license. require "test/unit" +require "timeout" require "csv" @@ -17,6 +19,8 @@ require "csv" # separator <tt>$/</tt>. # class TestCSVParsing < Test::Unit::TestCase + BIG_DATA = "123456789\n" * 1024 + def test_mastering_regex_example ex = %Q{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K} assert_equal( [ "Ten Thousand", "10000", " 2710 ", nil, "10,000", @@ -158,7 +162,31 @@ class TestCSVParsing < Test::Unit::TestCase assert_send([csv.lineno, :<, 4]) end rescue CSV::MalformedCSVError - assert_equal("Unclosed quoted field on line 4.", $!.message) + assert_equal("Illegal quoting on line 4.", $!.message) + end + end + + def test_the_parse_fails_fast_when_it_can_for_unquoted_fields + assert_parse_errors_out('valid,fields,bad start"' + BIG_DATA) + end + + def test_the_parse_fails_fast_when_it_can_for_unescaped_quotes + assert_parse_errors_out('valid,fields,"bad start"unescaped' + BIG_DATA) + end + + def test_field_size_limit_controls_lookahead + assert_parse_errors_out( 'valid,fields,"' + BIG_DATA + '"', + :field_size_limit => 2048 ) + end + + private + + def assert_parse_errors_out(*args) + assert_raise(CSV::MalformedCSVError) do + Timeout.timeout(0.2) do + CSV.parse(*args) + fail("Parse didn't error out") + end end end end |