diff options
author | ktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-07 06:06:09 +0000 |
---|---|---|
committer | ktsj <ktsj@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-07 06:06:09 +0000 |
commit | a496a95eaba3c9edf3c38fbc0f57cde85c9defd8 (patch) | |
tree | 203abbebd3964eb0c682b1ba0a7ab88ee04a6f08 /test/csv/test_row.rb | |
parent | ca5afd8e70bc0329e8a94217b03040b8b27a2662 (diff) | |
download | ruby-a496a95eaba3c9edf3c38fbc0f57cde85c9defd8.tar.gz |
* lib/csv.rb (CSV::{Row,Table}#{each,delete_if}): returns an enumerator
if no block is given. [ruby-core:75346] [Feature #11058]
* test/csv/test_row.rb: add test for above.
* test/csv/test_table.rb: ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/test_row.rb')
-rwxr-xr-x | test/csv/test_row.rb | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/test/csv/test_row.rb b/test/csv/test_row.rb index 1fa15d392a..1cb851b027 100755 --- a/test/csv/test_row.rb +++ b/test/csv/test_row.rb @@ -209,9 +209,20 @@ class TestCSV::Row < TestCSV # by header assert_equal(["C", 3], @row.delete("C")) - # using a block + end + + def test_delete_if assert_equal(@row, @row.delete_if { |h, f| h == "A" and not f.nil? }) - assert_equal([["A", nil]], @row.to_a) + assert_equal([["B", 2], ["C", 3], ["A", nil]], @row.to_a) + end + + def test_delete_if_without_block + enum = @row.delete_if + assert_instance_of(Enumerator, enum) + assert_equal(@row.size, enum.size) + + assert_equal(@row, enum.each { |h, f| h == "A" and not f.nil? }) + assert_equal([["B", 2], ["C", 3], ["A", nil]], @row.to_a) end def test_fields @@ -281,6 +292,16 @@ class TestCSV::Row < TestCSV # verify that we can chain the call assert_equal(@row, @row.each { }) + + # without block + ary = @row.to_a + enum = @row.each + assert_instance_of(Enumerator, enum) + assert_equal(@row.size, enum.size) + enum.each do |pair| + assert_equal(ary.first.first, pair.first) + assert_equal(ary.shift.last, pair.last) + end end def test_enumerable |