diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-06 03:56:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-03-06 03:56:38 +0000 |
commit | 287a34ae0dfc23e4158f67cb7783d239f202c368 (patch) | |
tree | 5e35d5b41aae961b37cf6632f60c42f51c7aa775 /test/csv/test_csv_parsing.rb | |
parent | 9b52ae2e6491bb5d6c59e1799449f6268baf6f89 (diff) |
* {ext,lib,test}/**/*.rb: removed trailing spaces.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/test_csv_parsing.rb')
-rw-r--r-- | test/csv/test_csv_parsing.rb | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/test/csv/test_csv_parsing.rb b/test/csv/test_csv_parsing.rb index e391687537..a9e6cd400c 100644 --- a/test/csv/test_csv_parsing.rb +++ b/test/csv/test_csv_parsing.rb @@ -12,22 +12,22 @@ require "timeout" require "csv" -# -# Following tests are my interpretation of the -# {CSV RCF}[http://www.ietf.org/rfc/rfc4180.txt]. I only deviate from that +# +# Following tests are my interpretation of the +# {CSV RCF}[http://www.ietf.org/rfc/rfc4180.txt]. I only deviate from that # document in one place (intentionally) and that is to make the default row # 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", "It's \"10 Grand\", baby", "10K" ], CSV.parse_line(ex) ) end - + # Old Ruby 1.8 CSV library tests. def test_std_lib_csv [ ["\t", ["\t"]], @@ -79,7 +79,7 @@ class TestCSVParsing < Test::Unit::TestCase assert_equal(csv_test.last, CSV.parse_line(csv_test.first)) end end - + # From: http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-core/6496 def test_aras_edge_cases [ [%Q{a,b}, ["a", "b"]], @@ -102,35 +102,35 @@ class TestCSVParsing < Test::Unit::TestCase assert_equal(edge_case.last, CSV.parse_line(edge_case.first)) end end - + def test_james_edge_cases # A read at eof? should return nil. assert_equal(nil, CSV.parse_line("")) - # + # # With Ruby 1.8 CSV it's impossible to tell an empty line from a line # containing a single +nil+ field. The old CSV library returns # <tt>[nil]</tt> in these cases, but <tt>Array.new</tt> makes more sense to # me. - # + # assert_equal(Array.new, CSV.parse_line("\n1,2,3\n")) end - + def test_malformed_csv assert_raise(CSV::MalformedCSVError) do CSV.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.lines.to_a assert_equal(6, lines.size) assert_match(/\Aline,4/, lines.find { |l| l =~ /some\rjunk/ }) - + csv = CSV.new(bad_data) begin loop do @@ -141,20 +141,20 @@ class TestCSVParsing < Test::Unit::TestCase assert_equal( "Unquoted fields do not allow \\r or \\n (line 4).", $!.message ) end - + assert_raise(CSV::MalformedCSVError) { CSV.parse_line('1,2,"3...') } - + bad_data = <<-END_DATA.gsub(/^ +/, "") line,1,abc line,2,"def\nghi" - + line,4,8'10" line,5,jkl END_DATA lines = bad_data.lines.to_a assert_equal(6, lines.size) assert_match(/\Aline,4/, lines.find { |l| l =~ /8'10"/ }) - + csv = CSV.new(bad_data) begin loop do @@ -165,22 +165,22 @@ class TestCSVParsing < Test::Unit::TestCase 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 |