summaryrefslogtreecommitdiff
path: root/test/csv/test_row.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 04:39:16 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 04:39:16 +0000
commit5c1941a9be56a979c27d740370b781882d344f79 (patch)
tree7478e42cde5b470b4df2eb40f89ee25f2621f5aa /test/csv/test_row.rb
parentdfc56b8c432d6a374c18cba7048d05175bcfba05 (diff)
Merge csv-1.0.2 from upstream.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/test_row.rb')
-rwxr-xr-xtest/csv/test_row.rb50
1 files changed, 46 insertions, 4 deletions
diff --git a/test/csv/test_row.rb b/test/csv/test_row.rb
index 1cb851b027..23df4d4fe6 100755
--- a/test/csv/test_row.rb
+++ b/test/csv/test_row.rb
@@ -4,9 +4,7 @@
# tc_row.rb
#
-# Created by James Edward Gray II on 2005-10-31.
-# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
-# under the terms of Ruby's license.
+# Created by James Edward Gray II on 2005-10-31.
require_relative "base"
@@ -304,6 +302,17 @@ class TestCSV::Row < TestCSV
end
end
+ def test_each_pair
+ assert_equal([
+ ["A", 1],
+ ["B", 2],
+ ["C", 3],
+ ["A", 4],
+ ["A", nil],
+ ],
+ @row.each_pair.to_a)
+ end
+
def test_enumerable
assert_equal( [["A", 1], ["A", 4], ["A", nil]],
@row.select { |pair| pair.first == "A" } )
@@ -323,7 +332,7 @@ class TestCSV::Row < TestCSV
def test_to_hash
hash = @row.to_hash
- assert_equal({"A" => nil, "B" => 2, "C" => 3}, hash)
+ assert_equal({"A" => @row["A"], "B" => @row["B"], "C" => @row["C"]}, hash)
hash.keys.each_with_index do |string_key, h|
assert_predicate(string_key, :frozen?)
assert_same(string_key, @row.headers[h])
@@ -377,4 +386,37 @@ class TestCSV::Row < TestCSV
r = @row == []
assert_equal false, r
end
+
+ def test_dig_by_index
+ assert_equal(2, @row.dig(1))
+
+ assert_nil(@row.dig(100))
+ end
+
+ def test_dig_by_header
+ assert_equal(2, @row.dig("B"))
+
+ assert_nil(@row.dig("Missing"))
+ end
+
+ def test_dig_cell
+ row = CSV::Row.new(%w{A}, [["foo", ["bar", ["baz"]]]])
+
+ assert_equal("foo", row.dig(0, 0))
+ assert_equal("bar", row.dig(0, 1, 0))
+
+ assert_equal("foo", row.dig("A", 0))
+ assert_equal("bar", row.dig("A", 1, 0))
+ end
+
+ def test_dig_cell_no_dig
+ row = CSV::Row.new(%w{A}, ["foo"])
+
+ assert_raise(TypeError) do
+ row.dig(0, 0)
+ end
+ assert_raise(TypeError) do
+ row.dig("A", 0)
+ end
+ end
end