<commit_before>require_relative '../../spec_helper'

describe "Proc#parameters" do
  it "returns an empty Array for a proc expecting no parameters" do
    proc {}.parameters.should == []
  end

  it "returns an Array of Arrays for a proc expecting parameters" do
    p = proc {|x| }
    p.parameters.should be_an_instance_of(Array)
    p.parameters.first.should be_an_instance_of(Array)
  end

  it "sets the first element of each sub-Array to :opt for optional arguments" do
    proc {|x| }.parameters.first.first.should == :opt
    proc {|y,*x| }.parameters.first.first.should == :opt
  end

  it "regards named parameters in procs as optional" do
    proc {|x| }.parameters.first.first.should == :opt
  end

  it "regards optional keyword parameters in procs as optional" do
    proc {|x: :y| }.parameters.first.first.should == :key
  end

  it "regards parameters with default values as optional" do
    -> x=1 { }.parameters.first.first.should == :opt
    proc {|x=1| }.parameters.first.first.should == :opt<commit_msg>Make Proc#parameters support lambda keyword for returning parameters as if lambda<commit_after>require_relative '../../spec_helper'

describe "Proc#parameters" do
  it "returns an empty Array for a proc expecting no parameters" do
    proc {}.parameters.should == []
  end

  it "returns an Array of Arrays for a proc expecting parameters" do
    p = proc {|x| }
    p.parameters.should be_an_instance_of(Array)
    p.parameters.first.should be_an_instance_of(Array)
  end

  it "sets the first element of each sub-Array to :opt for optional arguments" do
    proc {|x| }.parameters.first.first.should == :opt
    proc {|y,*x| }.parameters.first.first.should == :opt
  end

  it "regards named parameters in procs as optional" do
    proc {|x| }.parameters.first.first.should == :opt
  end

  ruby_version_is "3.2" do
    it "sets the first element of each sub-Array to :req if argument would be required if a lambda if lambda keyword used" do
      proc {|x| }.parameters(lambda: true).first.first.should == :req
      proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
    end

    it "regards named parameters in procs as required if lambda keyword used" do
      proc {|x| }.parameters(lambda: true).first.first.should == :req
    end

    it "regards named parameters in lambda as optional if lambda: false keyword used" do
      lambda {|x| }.parameters(lambda: false).first.first.should == :opt
    end
  end

  it "regards optional keyword parameters in procs as optional" do
    proc {|x: :y| }.parameters.first.first.should == :key
  end

  it "regards parameters with default values as optional" do
    -> x=1 { }.parameters.first.first.should == :opt
    proc {|x=1| }.parameters.first.first.should == :opt
{'fraction_non_alphanumeric': 0.11421319796954314, 'fraction_numerical': 0.002175489485134155, 'mean_word_length': 3.45718901453958, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6410237', 'n_tokens_mistral': 850, 'n_tokens_neox': 834, 'n_words': 304}