summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-12 12:21:49 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-12 12:21:49 +0900
commit1f0e0dfb228fd14b3f6687539ba274ba6a2d1643 (patch)
tree0d06f1dcea4a1d63004bf51f07408034dbf58f5e /test/ruby
parente8b210542b7d290d6c3feeff85221ed7303d2aab (diff)
Thread::Queue.new should accept an Enumerable [Feature #17327]
Enumerable implements #to_a but not #to_array.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_thread_queue.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index b0fa878814..6185abff9f 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -54,6 +54,28 @@ class TestThreadQueue < Test::Unit::TestCase
assert_equal 0, to_workers.size
end
+ def test_queue_initialize
+ e = Class.new do
+ include Enumerable
+ def initialize(list) @list = list end
+ def each(&block) @list.each(&block) end
+ end
+
+ all_assertions_foreach(nil,
+ [Array, "Array"],
+ [e, "Enumerable"],
+ [Struct.new(:to_a), "Array-like"],
+ ) do |a, type|
+ q = Queue.new(a.new([1,2,3]))
+ assert_equal(3, q.size, type)
+ assert_not_predicate(q, :empty?, type)
+ assert_equal(1, q.pop, type)
+ assert_equal(2, q.pop, type)
+ assert_equal(3, q.pop, type)
+ assert_predicate(q, :empty?, type)
+ end
+ end
+
def test_sized_queue_initialize
q = SizedQueue.new(1)
assert_equal 1, q.max