From 25a8d636358552ee515efb39cf23df79c07dd050 Mon Sep 17 00:00:00 2001 From: Ed Gibbs Date: Sat, 5 Sep 2026 15:51:40 -0700 Subject: [PATCH] Add a spec for Enumerator#size of zero `Enumerator#size` returns the size of the enumerator, or nil when the size cannot be determined without iterating. 'core/enumerator/size_spec.rb' pins an Integer size (100), nil, and a Proc, but never zero. The case cannot fail on CRuby, where 0 is truthy and INT2FIX(0) is a nonzero VALUE distinct from Qnil. It can fail on implementations hosted in a language where 0 is falsy: Opal returns nil for Enumerator.new(0) {}.size, because `opal/corelib/enumerator.rb` assigns the size with `arguments[0] || nil` and JS || collapses a size of 0 to nil. The neighbouring Enumerator.new(100) example passes there, so nothing in the suite currently detects this. Matchers follow the existing examples in the file. --- core/enumerator/size_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/enumerator/size_spec.rb b/core/enumerator/size_spec.rb index 4b2beffbb..ac8b9339e 100644 --- a/core/enumerator/size_spec.rb +++ b/core/enumerator/size_spec.rb @@ -5,6 +5,10 @@ Enumerator.new(100) {}.size.should == 100 end + it "returns 0 if set size is 0" do + Enumerator.new(0) {}.size.should == 0 + end + it "returns nil if set size is nil" do Enumerator.new(nil) {}.size.should == nil end