HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/src/ruby-2.7.4/spec/ruby/core/enumerator/lazy/select_spec.rb
# -*- encoding: us-ascii -*-

require_relative '../../../spec_helper'
require_relative 'shared/select'

describe "Enumerator::Lazy#select" do
  it_behaves_like :enumerator_lazy_select, :select

  it "doesn't pre-evaluate the next element" do
    eval_count = 0
    enum = %w[Text1 Text2 Text3].lazy.select do
      eval_count += 1
      true
    end

    eval_count.should == 0
    enum.next
    eval_count.should == 1
  end

  it "doesn't over-evaluate when peeked" do
    eval_count = 0
    enum = %w[Text1 Text2 Text3].lazy.select do
      eval_count += 1
      true
    end

    eval_count.should == 0
    enum.peek
    enum.peek
    eval_count.should == 1
  end

  it "doesn't re-evaluate after peek" do
    eval_count = 0
    enum = %w[Text1 Text2 Text3].lazy.select do
      eval_count += 1
      true
    end

    eval_count.should == 0
    enum.peek
    eval_count.should == 1
    enum.next
    eval_count.should == 1
  end
end