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_features.rb | |
parent | 9b52ae2e6491bb5d6c59e1799449f6268baf6f89 (diff) | |
download | ruby-287a34ae0dfc23e4158f67cb7783d239f202c368.tar.gz |
* {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_features.rb')
-rw-r--r-- | test/csv/test_features.rb | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb index 9ed3f98191..58efd1c9b3 100644 --- a/test/csv/test_features.rb +++ b/test/csv/test_features.rb @@ -30,17 +30,17 @@ class TestCSVFeatures < Test::Unit::TestCase [%Q{,"\r"}, [nil,"\r"]], [%Q{"\r\n,"}, ["\r\n,"]], [%Q{"\r\n,",}, ["\r\n,", nil]] ] - + def setup @sample_data = <<-END_DATA.gsub(/^ +/, "") line,1,abc line,2,"def\nghi" - + line,4,jkl END_DATA @csv = CSV.new(@sample_data) end - + def test_col_sep [";", "\t"].each do |sep| TEST_CASES.each do |test_case| @@ -51,7 +51,7 @@ class TestCSVFeatures < Test::Unit::TestCase end assert_equal([",,,", nil], CSV.parse_line(",,,;", col_sep: ";")) end - + def test_row_sep assert_raise(CSV::MalformedCSVError) do CSV.parse_line("1,2,3\n,4,5\r\n", row_sep: "\r\n") @@ -59,7 +59,7 @@ class TestCSVFeatures < Test::Unit::TestCase assert_equal( ["1", "2", "3\n", "4", "5"], CSV.parse_line(%Q{1,2,"3\n",4,5\r\n}, row_sep: "\r\n")) end - + def test_quote_char TEST_CASES.each do |test_case| assert_equal( test_case.last.map { |t| t.tr('"', "'") unless t.nil? }, @@ -67,31 +67,31 @@ class TestCSVFeatures < Test::Unit::TestCase quote_char: "'" ) ) end end - + def test_csv_char_readers %w[col_sep row_sep quote_char].each do |reader| csv = CSV.new("abc,def", reader.to_sym => "|") assert_equal("|", csv.send(reader)) end end - + def test_row_sep_auto_discovery ["\r\n", "\n", "\r"].each do |line_end| data = "1,2,3#{line_end}4,5#{line_end}" discovered = CSV.new(data).row_sep assert_equal(line_end, discovered) end - + assert_equal("\n", CSV.new("\n\r\n\r").row_sep) - + assert_equal($/, CSV.new("").row_sep) - + assert_equal($/, CSV.new(STDERR).row_sep) end - + def test_lineno assert_equal(5, @sample_data.lines.to_a.size) - + 4.times do |line_count| assert_equal(line_count, @csv.lineno) assert_not_nil(@csv.shift) @@ -99,24 +99,24 @@ class TestCSVFeatures < Test::Unit::TestCase end assert_nil(@csv.shift) end - + def test_readline test_lineno - + @csv.rewind - + test_lineno end - + def test_unknown_options assert_raise(ArgumentError) { CSV.new(String.new, unknown: :error) } end - + def test_skip_blanks assert_equal(4, @csv.to_a.size) @csv = CSV.new(@sample_data, skip_blanks: true) - + count = 0 @csv.each do |row| count += 1 @@ -124,7 +124,7 @@ class TestCSVFeatures < Test::Unit::TestCase end assert_equal(3, count) end - + def test_csv_behavior_readers %w[ unconverted_fields return_headers write_headers skip_blanks force_quotes ].each do |behavior| @@ -134,47 +134,47 @@ class TestCSVFeatures < Test::Unit::TestCase assert(csv.send("#{behavior}?"), "Behavior change now registered.") end end - + def test_converters_reader # no change assert_equal( [:integer], CSV.new("abc,def", converters: [:integer]).converters ) - + # just one assert_equal( [:integer], CSV.new("abc,def", converters: :integer).converters ) - + # expanded assert_equal( [:integer, :float], CSV.new("abc,def", converters: :numeric).converters ) - + # custom csv = CSV.new("abc,def", converters: [:integer, lambda { }]) assert_equal(2, csv.converters.size) assert_equal(:integer, csv.converters.first) assert_instance_of(Proc, csv.converters.last) end - + def test_header_converters_reader # no change hc = :header_converters assert_equal([:downcase], CSV.new("abc,def", hc => [:downcase]).send(hc)) - + # just one assert_equal([:downcase], CSV.new("abc,def", hc => :downcase).send(hc)) - + # custom csv = CSV.new("abc,def", hc => [:symbol, lambda { }]) assert_equal(2, csv.send(hc).size) assert_equal(:symbol, csv.send(hc).first) assert_instance_of(Proc, csv.send(hc).last) end - + # reported by Kev Jackson def test_failing_to_escape_col_sep_bug_fix assert_nothing_raised(Exception) { CSV.new(String.new, col_sep: "|") } end - + # reported by Chris Roos def test_failing_to_reset_headers_in_rewind_bug_fix csv = CSV.new("forename,surname", headers: true, return_headers: true) @@ -182,7 +182,7 @@ class TestCSVFeatures < Test::Unit::TestCase csv.rewind csv.each { |row| assert row.header_row? } end - + # reported by Dave Burt def test_leading_empty_fields_with_multibyte_col_sep_bug_fix data = <<-END_DATA.gsub(/^\s+/, "") @@ -192,7 +192,7 @@ class TestCSVFeatures < Test::Unit::TestCase parsed = CSV.parse(data, col_sep: "<=>") assert_equal([[nil, nil, "A", "B", "C"], ["1", "2", "3"]], parsed) end - + def test_gzip_reader_bug_fix zipped = nil assert_nothing_raised(NoMethodError) do @@ -204,7 +204,7 @@ class TestCSVFeatures < Test::Unit::TestCase end assert_equal("\r\n", zipped.row_sep) end - + def test_gzip_writer_bug_fix file = File.join(File.dirname(__FILE__), "temp.gz") zipped = nil @@ -214,13 +214,13 @@ class TestCSVFeatures < Test::Unit::TestCase zipped << %w[one two three] zipped << [1, 2, 3] zipped.close - + assert( Zlib::GzipReader.open(file) { |f| f.read }. include?($INPUT_RECORD_SEPARATOR), "@row_sep did not default" ) File.unlink(file) end - + def test_inspect_is_smart_about_io_types str = CSV.new("string,data").inspect assert(str.include?("io_type:StringIO"), "IO type not detected.") @@ -234,14 +234,14 @@ class TestCSVFeatures < Test::Unit::TestCase assert(str.include?("io_type:File"), "IO type not detected.") File.unlink(path) end - + def test_inspect_shows_key_attributes str = @csv.inspect %w[lineno col_sep row_sep quote_char].each do |attr_name| assert_match(/\b#{attr_name}:[^\s>]+/, str) end end - + def test_inspect_shows_headers_when_available CSV.new("one,two,three\n1,2,3\n", headers: true) do |csv| assert(csv.inspect.include?("headers:true"), "Header hint not shown.") @@ -249,7 +249,7 @@ class TestCSVFeatures < Test::Unit::TestCase assert_match(/headers:\[[^\]]+\]/, csv.inspect) end end - + def test_inspect_encoding_is_ascii_compatible CSV.new("one,two,three\n1,2,3\n".encode("UTF-16BE")) do |csv| assert( Encoding.compatible?( Encoding.find("US-ASCII"), @@ -257,7 +257,7 @@ class TestCSVFeatures < Test::Unit::TestCase "inspect() was not ASCII compatible." ) end end - + def test_version assert_not_nil(CSV::VERSION) assert_instance_of(String, CSV::VERSION) |