diff options
author | zverok <zverok.offline@gmail.com> | 2020-12-05 13:39:20 +0200 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-01-02 17:27:24 +0900 |
commit | b8d33df1d9799cd04b92c1c28e42cc3028cc7524 (patch) | |
tree | e84491b66b3adf71b6f78c18848c59c10ba21320 /test | |
parent | f690eb34e28b000627e5f0649dd81a04e252286f (diff) |
Add Enumerable#compact and Enumerator::Lazy#compact
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3851
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enum.rb | 15 | ||||
-rw-r--r-- | test/ruby/test_enumerator.rb | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/test/ruby/test_enum.rb b/test/ruby/test_enum.rb index 126b100b03..fc0220368b 100644 --- a/test/ruby/test_enum.rb +++ b/test/ruby/test_enum.rb @@ -1229,6 +1229,21 @@ class TestEnumerable < Test::Unit::TestCase assert_equal([1, [1, 2]], Foo.new.to_enum.uniq) end + def test_compact + class << (enum = Object.new) + include Enumerable + def each + yield 3 + yield nil + yield 7 + yield 9 + yield nil + end + end + + assert_equal([3, 7, 9], enum.compact) + end + def test_transient_heap_sort_by klass = Class.new do include Comparable diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index eb15d4b616..718bcb74b6 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -696,6 +696,11 @@ class TestEnumerator < Test::Unit::TestCase assert_equal([0, 1], u.force) end + def test_compact + u = [0, 1, nil, 2, 3, nil].to_enum.lazy.compact + assert_equal([0, 1, 2, 3], u.force) + end + def test_enum_chain_and_plus r = 1..5 |