diff options
author | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-27 16:15:53 +0000 |
---|---|---|
committer | jeg2 <jeg2@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-12-27 16:15:53 +0000 |
commit | 93030d0e4d93683346648b25bd69a3f33a5f0486 (patch) | |
tree | afffbf80d989e519a5b2f7131c46304de4d7d61b /test/csv | |
parent | 7b34c2f81aa300aa943479077c7c19c472b0c71c (diff) | |
download | ruby-93030d0e4d93683346648b25bd69a3f33a5f0486.tar.gz |
* lib/csv.rb: Added more Hash methods to CSV::Row.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv')
-rwxr-xr-x | test/csv/test_row.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/csv/test_row.rb b/test/csv/test_row.rb index 3016c5b57c..697c7d56c8 100755 --- a/test/csv/test_row.rb +++ b/test/csv/test_row.rb @@ -78,6 +78,33 @@ class TestCSV::Row < TestCSV assert_equal(nil, @row.field("A", 5)) end + def test_fetch + # only by name + assert_equal(2, @row.fetch('B')) + + # missing header raises KeyError + assert_raise KeyError do + @row.fetch('foo') + end + + # missing header yields itself to block + assert_equal 'bar', @row.fetch('foo') { |header| + header == 'foo' ? 'bar' : false } + + # missing header returns the given default value + assert_equal 'bar', @row.fetch('foo', 'bar') + + # more than one vararg raises ArgumentError + assert_raise ArgumentError do + @row.fetch('foo', 'bar', 'baz') + end + end + + def test_has_key? + assert_equal(true, @row.has_key?('B')) + assert_equal(false, @row.has_key?('foo')) + end + def test_set_field # set field by name assert_equal(100, @row["A"] = 100) |