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_row.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_row.rb')
-rw-r--r-- | test/csv/test_row.rb | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/test/csv/test_row.rb b/test/csv/test_row.rb index d0b0cdc406..f9aa959701 100644 --- a/test/csv/test_row.rb +++ b/test/csv/test_row.rb @@ -15,27 +15,27 @@ class TestCSVRow < Test::Unit::TestCase def setup @row = CSV::Row.new(%w{A B C A A}, [1, 2, 3, 4]) end - + def test_initialize # basic row = CSV::Row.new(%w{A B C}, [1, 2, 3]) assert_not_nil(row) assert_instance_of(CSV::Row, row) assert_equal([["A", 1], ["B", 2], ["C", 3]], row.to_a) - + # missing headers row = CSV::Row.new(%w{A}, [1, 2, 3]) assert_not_nil(row) assert_instance_of(CSV::Row, row) assert_equal([["A", 1], [nil, 2], [nil, 3]], row.to_a) - + # missing fields row = CSV::Row.new(%w{A B C}, [1, 2]) assert_not_nil(row) assert_instance_of(CSV::Row, row) assert_equal([["A", 1], ["B", 2], ["C", nil]], row.to_a) end - + def test_row_type # field rows row = CSV::Row.new(%w{A B C}, [1, 2, 3]) # implicit @@ -50,11 +50,11 @@ class TestCSVRow < Test::Unit::TestCase assert(row.header_row?) assert(!row.field_row?) end - + def test_headers assert_equal(%w{A B C A A}, @row.headers) end - + def test_field # by name assert_equal(2, @row.field("B")) @@ -62,11 +62,11 @@ class TestCSVRow < Test::Unit::TestCase # by index assert_equal(3, @row.field(2)) - + # missing assert_nil(@row.field("Missing")) assert_nil(@row.field(10)) - + # minimum index assert_equal(1, @row.field("A")) assert_equal(1, @row.field("A", 0)) @@ -76,24 +76,24 @@ class TestCSVRow < Test::Unit::TestCase assert_equal(nil, @row.field("A", 4)) assert_equal(nil, @row.field("A", 5)) end - + def test_set_field # set field by name assert_equal(100, @row["A"] = 100) - + # set field by index assert_equal(300, @row[3] = 300) - + # set field by name and minimum index assert_equal([:a, :b, :c], @row["A", 4] = [:a, :b, :c]) - + # verify the changes assert_equal( [ ["A", 100], ["B", 2], ["C", 3], ["A", 300], ["A", [:a, :b, :c]] ], @row.to_a ) - + # assigning an index past the end assert_equal("End", @row[10] = "End") assert_equal( [ ["A", 100], @@ -107,7 +107,7 @@ class TestCSVRow < Test::Unit::TestCase [nil, nil], [nil, nil], [nil, "End"] ], @row.to_a ) - + # assigning a new field by header assert_equal("New", @row[:new] = "New") assert_equal( [ ["A", 100], @@ -123,7 +123,7 @@ class TestCSVRow < Test::Unit::TestCase [nil, "End"], [:new, "New"] ], @row.to_a ) end - + def test_append # add a value assert_equal(@row, @row << "Value") @@ -133,7 +133,7 @@ class TestCSVRow < Test::Unit::TestCase ["A", 4], ["A", nil], [nil, "Value"] ], @row.to_a ) - + # add a pair assert_equal(@row, @row << %w{Header Field}) assert_equal( [ ["A", 1], @@ -143,7 +143,7 @@ class TestCSVRow < Test::Unit::TestCase ["A", nil], [nil, "Value"], %w{Header Field} ], @row.to_a ) - + # a pair with Hash syntax assert_equal(@row, @row << {key: :value}) assert_equal( [ ["A", 1], @@ -154,7 +154,7 @@ class TestCSVRow < Test::Unit::TestCase [nil, "Value"], %w{Header Field}, [:key, :value] ], @row.to_a ) - + # multiple fields at once assert_equal(@row, @row.push(100, 200, [:last, 300])) assert_equal( [ ["A", 1], @@ -169,39 +169,39 @@ class TestCSVRow < Test::Unit::TestCase [nil, 200], [:last, 300] ], @row.to_a ) end - + def test_delete # by index assert_equal(["B", 2], @row.delete(1)) # by header assert_equal(["C", 3], @row.delete("C")) - + # using a block assert_equal(@row, @row.delete_if { |h, f| h == "A" and not f.nil? }) assert_equal([["A", nil]], @row.to_a) end - + def test_fields # all fields assert_equal([1, 2, 3, 4, nil], @row.fields) - + # by header assert_equal([1, 3], @row.fields("A", "C")) - + # by index assert_equal([2, 3, nil], @row.fields(1, 2, 10)) - + # by both assert_equal([2, 3, 4], @row.fields("B", "C", 3)) - + # with minimum indices assert_equal([2, 3, 4], @row.fields("B", "C", ["A", 3])) - + # by header range assert_equal([2, 3], @row.values_at("B".."C")) end - + def test_index # basic usage assert_equal(0, @row.index("A")) @@ -218,20 +218,20 @@ class TestCSVRow < Test::Unit::TestCase assert_equal(4, @row.index("A", 4)) assert_equal(nil, @row.index("A", 5)) end - + def test_queries # headers assert(@row.header?("A")) assert(@row.header?("C")) assert(!@row.header?("Z")) assert(@row.include?("A")) # alias - + # fields assert(@row.field?(4)) assert(@row.field?(nil)) assert(!@row.field?(10)) end - + def test_each # array style ary = @row.to_a @@ -239,25 +239,25 @@ class TestCSVRow < Test::Unit::TestCase assert_equal(ary.first.first, pair.first) assert_equal(ary.shift.last, pair.last) end - + # hash style ary = @row.to_a @row.each do |header, field| assert_equal(ary.first.first, header) assert_equal(ary.shift.last, field) end - + # verify that we can chain the call assert_equal(@row, @row.each { }) end - + def test_enumerable assert_equal( [["A", 1], ["A", 4], ["A", nil]], @row.select { |pair| pair.first == "A" } ) - + assert_equal(10, @row.inject(0) { |sum, (header, n)| sum + (n || 0) }) end - + def test_to_a row = CSV::Row.new(%w{A B C}, [1, 2, 3]).to_a assert_instance_of(Array, row) @@ -267,27 +267,27 @@ class TestCSVRow < Test::Unit::TestCase end assert_equal([["A", 1], ["B", 2], ["C", 3]], row) end - + def test_to_hash assert_equal({"A" => nil, "B" => 2, "C" => 3}, @row.to_hash) end - + def test_to_csv # normal conversion assert_equal("1,2,3,4,\n", @row.to_csv) assert_equal("1,2,3,4,\n", @row.to_s) # alias - + # with options assert_equal( "1|2|3|4|\r\n", @row.to_csv(col_sep: "|", row_sep: "\r\n") ) end - + def test_array_delegation assert(!@row.empty?, "Row was empty.") - + assert_equal([@row.headers.size, @row.fields.size].max, @row.size) end - + def test_inspect_shows_header_field_pairs str = @row.inspect @row.each do |header, field| @@ -295,13 +295,13 @@ class TestCSVRow < Test::Unit::TestCase "Header field pair not found." ) end end - + def test_inspect_encoding_is_ascii_compatible assert( Encoding.compatible?( Encoding.find("US-ASCII"), @row.inspect.encoding ), "inspect() was not ASCII compatible." ) end - + def test_inspect_shows_symbol_headers_as_bare_attributes str = CSV::Row.new(@row.headers.map { |h| h.to_sym }, @row.fields).inspect @row.each do |header, field| |