aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_enumerator.rb
Commit message (Collapse)AuthorAgeFilesLines
* Add Enumerable#compact and Enumerator::Lazy#compactzverok2021-01-021-0/+5
|
* Enumerator.new: raise unless block given卜部昌平2020-12-221-10/+4
| | | | | Has been deprecated since c73b6bd7ebd01133538c645566944132dbde4d13. [Feature #17116] [ruby-dev:50945]
* test/ruby/test_enumerator.rb: check the deprecation warningYusuke Endoh2020-09-251-1/+9
| | | | | | | | | by explicitly setting `Warning[:deprecated] = true`. I removed "capture_io" at 79063d8cbfb7ce4740774289252a2a20dc9a5dc1, but it printed the warning when `RUBYOPT=-w`. This change makes the warnings enabled explicitly, capture and check the warning.
* test/ruby/test_enumerator.rb: remove capture_io that is no longer neededYusuke Endoh2020-09-251-3/+1
| | | | | | The deprecation warning was disabled, and the code to check the warning was removed at 996af2ce086249e904b2ce95ab2fcd1de7d757be, thus capture_io is no longer needed.
* Disable deprecation warning by the default [Feature #16345]Nobuyoshi Nakada2020-09-251-1/+0
| | | | And `-w` option turns it on.
* Make Enumerator::Chain#each treat lambdas as lambdaJeremy Evans2019-12-031-0/+16
| | | | | | | | Previously, lambdas were converted to procs because of how rb_block_call works. Switch to rb_funcall_with_block, which handles procs as procs and lambdas as lambdas. Fixes [Bug #15613]
* Add rb_enumeratorize_with_size_kw and related macrosJeremy Evans2019-09-301-0/+8
| | | | | | | | | | Currently, there is not a way to create a sized enumerator in C with a different set of arguments than provided by Ruby, and correctly handle keyword arguments. This function allows that. The need for this is fairly uncommon, but it occurs at least in Enumerator.produce, which takes arugments from Ruby but calls rb_enumeratorize_with_size with a different set of arguments.
* Document and test Enumerator.produceAkinori MUSHA2019-09-121-0/+45
| | | | Co-authored-by: Victor Shepelev <zverok.offline@gmail.com>
* Make size on an infinite each_slice enumerator return InfinityJeremy Evans2019-06-021-0/+5
| | | | Fixes [Bug #15889]
* Adding Enumerable#filter_mapAlfonso Jiménez2019-05-231-1/+1
| | | | | [Feature #15323] Closes: https://github.com/ruby/ruby/pull/2017
* Implement Enumerator::Yielder#to_procknu2019-03-111-0/+15
| | | | | | | | | | | | | | | A Yielder object can now be directly passed to another method as a block argument. ```ruby enum = Enumerator.new { |y| Dir.glob("*.rb") { |file| File.open(file) { |f| f.each_line(&y) } } } ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: fix inspect with the last empty hashnobu2018-12-241-0/+6
| | | | | | [ruby-core:90685] [Bug #15455] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Implement Enumerator#+ and Enumerable#chain [Feature #15144]knu2018-11-241-1/+115
| | | | | | | | | | | | | | | | They return an Enumerator::Chain object which is a subclass of Enumerator, which represents a chain of enumerables that works as a single enumerator. ```ruby e = (1..3).chain([4, 5]) e.to_a #=> [1, 2, 3, 4, 5] e = (1..3).each + [4, 5] e.to_a #=> [1, 2, 3, 4, 5] ``` git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65949 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Set the size of a new enumerator created by Enumerator#each with arguments ↵knu2018-10-221-2/+5
| | | | | | | | | | | to nil When each() takes arguments, it is never safe to assume that the iteration would repeat the same number of times as with each() without any argument. Actually, there is no way to get the exact number, so the size should be set to nil to denote that. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Tests of Enumerator::Yielder#yield with multiple argumentsnobu2018-09-181-0/+6
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64768 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: Introduce Enumerator::ArithmeticSequencemrkn2018-08-061-1/+1
| | | | | | | | | | | | | | | | | | | This commit introduces new core class Enumerator::ArithmeticSequence. Enumerator::ArithmeticSequence is a subclass of Enumerator, and represents a number generator of an arithmetic sequence. After this commit, Numeric#step and Range#step without blocks returned an ArithmeticSequence object instead of an Enumerator. This class introduces the following incompatibilities: - You can create a zero-step ArithmeticSequence, and its size is not ArgumentError, but Infinity. - You can create a negative-step ArithmeticSequence from a range. [ruby-core:82816] [Feature #13904] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test_enumerator.rb: duplicate assertionsnobu2018-03-131-4/+0
| | | | | | | | * test/ruby/test_enumerator.rb (test_uniq): remove assertions which ared duplicate of lazy enumerator tests in test_lazy_enumerator.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Bug Fix Enumerator::Lazy#uniq state for multiple callnobu2018-03-131-2/+7
| | | | | | | | | | | | | | | | | | | | | | * enumerator.c (lazy_uniq_i): create new hash for each calls. [Fix GH-1820] Currently 2.5.0-preview1 :001 > arr = (0..100).lazy.uniq{|i| i % 10} => #<Enumerator::Lazy: #<Enumerator::Lazy: 0..100>:uniq> 2.5.0-preview1 :002 > arr.to_a => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 2.5.0-preview1 :003 > arr.to_a => [] Expected arr.to_a to always return same output From: Anmol Chopra <anmolchopra@rocketbox.in> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a new #filter alias for #selecteregon2018-02-251-3/+3
| | | | | | | | | | | | | | | * In Enumerable, Enumerator::Lazy, Array, Hash and Set [Feature #13784] [ruby-core:82285] * Share specs for the various #select#select! methods and reuse them for #filter/#filter!. * Add corresponding filter tests for select tests. * Update NEWS. [Fix GH-1824] From: Alexander Patrick <adp90@case.edu> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62575 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add FrozenError as a subclass of RuntimeErrorshyouhei2017-12-121-2/+2
| | | | | | | | | | | | | | FrozenError will be used instead of RuntimeError for exceptions raised when there is an attempt to modify a frozen object. The reason for this change is to differentiate exceptions related to frozen objects from generic exceptions such as those generated by Kernel#raise without an exception class. From: Jeremy Evans <code@jeremyevans.net> Signed-off-by: Urabe Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61131 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enum.c: check argument firstnobu2017-11-051-0/+2
| | | | | | | * enum.c (enum_cycle_size): check an argument before the size of the receiver, if it is given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix size on Enumerable#cycle when the size is 0 [Bug #14082].marcandre2017-11-051-0/+7
| | | | | | Patch by Kenichi Kamiya git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: Enumerator::Lazy#uniqnobu2016-07-201-0/+5
| | | | | | | * enumerator.c (lazy_uniq): new method Enumerator::Lazy#uniq. [Feature #11090] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55710 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* test/ruby: suppress parser warningsnobu2016-02-191-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53872 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add frozen_string_literal: false for all filesnaruse2015-12-161-0/+1
| | | | | | When you change this to true, you may need to add more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Kernel#loop returns the result value of a finished iteratorknu2015-10-221-0/+8
| | | | | | | | * vm_eval.c (rb_f_loop): When a loop is stopped by a StopIteration exception, return what the enumerator has returned instead of nil. [ruby-core:71133] [Feature #11498] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* preserve encodings in error messagesnobu2015-09-281-0/+12
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51962 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/lib/envutil.rb: Moved from test/ruby/.akr2014-11-131-1/+0
| | | | | | | | | | | | | | * test/lib/find_executable.rb: Ditto. * test/lib/memory_status.rb: Ditto. * test/lib/test/unit.rb: require envutil. * test/: Don't require envutil in test files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* merge GH-558nobu2014-03-101-1/+1
| | | | | | | * test/ruby/test_enumerator.rb (test_iterators): fix test for hash iterators. [Fixes GH-558] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45303 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Additional test coverage to Enumerator#peek.nobu2013-12-141-0/+9
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* hash.c: rb_hash_reject without dupnobu2013-12-071-3/+7
| | | | | | | | * hash.c (rb_hash_reject): copy unrejected elements only to new hash, so that the change on the original receiver can affect. [ruby-core:58914] [Bug #9223] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44047 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: should not store local variable addressnobu2013-11-301-0/+10
| | | | | | | | * enumerator.c (enumerator_with_index): should not store local variable address to memoise the arguments. it is invalidated after the return. [ruby-core:58692] [Bug #9178] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43929 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enumerator.c: Allow Enumerator size argument to be any callable.marcandre2013-08-271-0/+3
| | | | | | | | Patch by Avdi Grimm. [bug #8641] [ruby-core:56032] [fix GH-362] * test/ruby/test_enumerator.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42698 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a frozenness check to Enumerator::Generator#initialize.knu2013-07-291-0/+5
| | | | | | * enumerator.c (generator_init): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add a frozenness check to Enumerator#initialize.knu2013-07-291-0/+10
| | | | | | | | | | * enumerator.c (enumerator_init): Add a frozenness check to prevent a frozen Enumerator object from being reinitialized with a different enumerable object. This is the least we should do, and more fixes will follow. [Fixes GH-368] Patch by Kenichi Kamiya. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42233 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: use VALUEnobu2013-05-181-0/+8
| | | | | | | * enumerator.c (inspect_enumerator): use VALUE instead of mere char* by using rb_sprintf() and rb_id2str(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40805 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enumerator.c (enumerator_with_index): try to convert given offset tonaruse2013-03-111-0/+12
| | | | | | integer. fix bug introduced in r39594. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* enumerator.c: allow Bignum for with_indexnobu2013-03-051-0/+8
| | | | | | | | | * enumerator.c (enumerator_with_index_i): allow Bignum as offset, to get rid of conversion exception and integer overflow. [ruby-dev:47131] [Bug #8010] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Fix tests of rb_warning().knu2012-11-241-2/+2
| | | | | | | | | | * test/ruby/envutil.rb (Test::Unit::Assertions#assert_warning) (Test::Unit::Assertions#assert_warn), test/ruby/envutil.rb, test/ruby/test_enumerator.rb, test/ruby/test_io_m17n.rb, test/ruby/test_regexp.rb, test/ruby/test_syntax.rb: assert_warn() and assert_warning() are reversed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37836 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Revert of 37541 "* test/ruby/test_enumerator.rb: Add test to shed light upon ↵marcandre2012-11-101-3/+0
| | | | | | | | | the bug" [#7298] This reverts commit 0ab21f9572d5d5f76b908aaf3381cde32a64c4c8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37609 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * test/ruby/test_enumerator.rb: Add test to shed light upon the bugayumin2012-11-071-0/+3
| | | | | | which made by r37498. See http://bugs.ruby-lang.org/issues/7298 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * string.c: Support for String#{each_byte,each_char,each_codepoint}.sizemarcandre2012-11-061-0/+6
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * numeric.c (int_dotimes): Support for Integer#times.sizemarcandre2012-11-061-0/+1
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37519 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * numeric.c (int_upto, int_downto): Support for Integer#{down|up}to.sizemarcandre2012-11-061-0/+6
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37518 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * range.c: Support for range.step.sizemarcandre2012-11-061-0/+6
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37517 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * numeric.c (num_step): Support for Numeric#step.sizemarcandre2012-11-061-0/+15
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37515 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * struct.c: Support for Struct's enumerators #sizemarcandre2012-11-061-0/+7
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37513 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c: Support for enumerators created by ENV:marcandre2012-11-061-0/+6
| | | | | | | each, each_value, ... [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37512 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * hash.c: Support for enumerators created by Hash:marcandre2012-11-061-0/+7
| | | | | | | delete_if, reject!, ... [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * enum.c (enum_cycle): Support for Enumerable#cycle.sizemarcandre2012-11-061-0/+5
| | | | | | [Feature #6636] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37510 b2dd03c8-39d4-4d8f-98ff-823fe69b080e