diff options
Diffstat (limited to 'spec/ruby/core/proc')
| -rw-r--r-- | spec/ruby/core/proc/element_reference_spec.rb | 2 | ||||
| -rw-r--r-- | spec/ruby/core/proc/parameters_spec.rb | 70 | ||||
| -rw-r--r-- | spec/ruby/core/proc/ruby2_keywords_spec.rb | 14 | ||||
| -rw-r--r-- | spec/ruby/core/proc/shared/dup.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/core/proc/source_location_spec.rb | 12 |
5 files changed, 57 insertions, 49 deletions
diff --git a/spec/ruby/core/proc/element_reference_spec.rb b/spec/ruby/core/proc/element_reference_spec.rb index 9077e44c34..81ceb91af5 100644 --- a/spec/ruby/core/proc/element_reference_spec.rb +++ b/spec/ruby/core/proc/element_reference_spec.rb @@ -17,7 +17,7 @@ describe "Proc#call on a Proc created with Kernel#lambda or Kernel#proc" do it_behaves_like :proc_call_on_proc_or_lambda, :call end -describe "Proc#[] with frozen_string_literals" do +describe "Proc#[] with frozen_string_literal: true/false" do it "doesn't duplicate frozen strings" do ProcArefSpecs.aref.frozen?.should be_false ProcArefSpecs.aref_freeze.frozen?.should be_true diff --git a/spec/ruby/core/proc/parameters_spec.rb b/spec/ruby/core/proc/parameters_spec.rb index 7a2723487d..cf8a8f5b12 100644 --- a/spec/ruby/core/proc/parameters_spec.rb +++ b/spec/ruby/core/proc/parameters_spec.rb @@ -20,29 +20,27 @@ describe "Proc#parameters" 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 for required argument 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 "sets the first element of each sub-Array to :req for required argument 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 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 - -> x { }.parameters(lambda: false).first.first.should == :opt - end + it "regards named parameters in lambda as optional if lambda: false keyword used" do + -> x { }.parameters(lambda: false).first.first.should == :opt + end - it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do - proc {|x| }.parameters(lambda: 123).first.first.should == :req - -> x { }.parameters(lambda: 123).first.first.should == :req - end + it "regards named parameters in procs and lambdas as required if lambda keyword is truthy" do + proc {|x| }.parameters(lambda: 123).first.first.should == :req + -> x { }.parameters(lambda: 123).first.first.should == :req + end - it "ignores the lambda keyword if it is nil" do - proc {|x|}.parameters(lambda: nil).first.first.should == :opt - -> x { }.parameters(lambda: nil).first.first.should == :req - end + it "ignores the lambda keyword if it is nil" do + proc {|x|}.parameters(lambda: nil).first.first.should == :opt + -> x { }.parameters(lambda: nil).first.first.should == :req end it "regards optional keyword parameters in procs as optional" do @@ -110,24 +108,12 @@ describe "Proc#parameters" do -> x { }.parameters.should == [[:req, :x]] end - ruby_version_is '3.2' do - it "adds rest arg with name * for \"star\" argument" do - -> * {}.parameters.should == [[:rest, :*]] - end - - it "adds keyrest arg with ** as a name for \"double star\" argument" do - -> ** {}.parameters.should == [[:keyrest, :**]] - end + it "adds rest arg with name * for \"star\" argument" do + -> * {}.parameters.should == [[:rest, :*]] end - ruby_version_is ''...'3.2' do - it "adds nameless rest arg for \"star\" argument" do - -> * {}.parameters.should == [[:rest]] - end - - it "adds nameless keyrest arg for \"double star\" argument" do - -> ** {}.parameters.should == [[:keyrest]] - end + it "adds keyrest arg with ** as a name for \"double star\" argument" do + -> ** {}.parameters.should == [[:keyrest, :**]] end it "adds block arg with name & for anonymous block argument" do @@ -172,4 +158,18 @@ describe "Proc#parameters" do it "returns :nokey for **nil parameter" do proc { |**nil| }.parameters.should == [[:nokey]] end + + ruby_version_is "3.4"..."4.0" do + it "handles the usage of `it` as a parameter" do + eval("proc { it }").parameters.should == [[:opt, nil]] + eval("lambda { it }").parameters.should == [[:req]] + end + end + + ruby_version_is "4.0" do + it "handles the usage of `it` as a parameter" do + eval("proc { it }").parameters.should == [[:opt]] + eval("lambda { it }").parameters.should == [[:req]] + end + end end diff --git a/spec/ruby/core/proc/ruby2_keywords_spec.rb b/spec/ruby/core/proc/ruby2_keywords_spec.rb index ab67302231..d7f8f592e1 100644 --- a/spec/ruby/core/proc/ruby2_keywords_spec.rb +++ b/spec/ruby/core/proc/ruby2_keywords_spec.rb @@ -39,7 +39,7 @@ describe "Proc#ruby2_keywords" do end it "prints warning when a proc accepts keywords" do - f = -> a:, b: { } + f = -> *a, b: { } -> { f.ruby2_keywords @@ -47,10 +47,20 @@ describe "Proc#ruby2_keywords" do end it "prints warning when a proc accepts keyword splat" do - f = -> **a { } + f = -> *a, **b { } -> { f.ruby2_keywords }.should complain(/Skipping set of ruby2_keywords flag for/) end + + ruby_version_is "4.0" do + it "prints warning when a proc accepts post arguments" do + f = -> *a, b { } + + -> { + f.ruby2_keywords + }.should complain(/Skipping set of ruby2_keywords flag for/) + end + end end diff --git a/spec/ruby/core/proc/shared/dup.rb b/spec/ruby/core/proc/shared/dup.rb index 818f5b858e..1266337f94 100644 --- a/spec/ruby/core/proc/shared/dup.rb +++ b/spec/ruby/core/proc/shared/dup.rb @@ -8,12 +8,10 @@ describe :proc_dup, shared: true do a.call.should == b.call end - ruby_version_is "3.2" do - it "returns an instance of subclass" do - cl = Class.new(Proc) + it "returns an instance of subclass" do + cl = Class.new(Proc) - cl.new{}.send(@method).class.should == cl - end + cl.new{}.send(@method).class.should == cl end ruby_version_is "3.4" do diff --git a/spec/ruby/core/proc/source_location_spec.rb b/spec/ruby/core/proc/source_location_spec.rb index 484466f577..fd33f21a26 100644 --- a/spec/ruby/core/proc/source_location_spec.rb +++ b/spec/ruby/core/proc/source_location_spec.rb @@ -53,15 +53,15 @@ describe "Proc#source_location" do end it "works even if the proc was created on the same line" do - ruby_version_is(""..."3.5") do + ruby_version_is(""..."4.1") do proc { true }.source_location.should == [__FILE__, __LINE__] Proc.new { true }.source_location.should == [__FILE__, __LINE__] -> { true }.source_location.should == [__FILE__, __LINE__] end - ruby_version_is("3.5") do + ruby_version_is("4.1") do proc { true }.source_location.should == [__FILE__, __LINE__, 11, __LINE__, 19] Proc.new { true }.source_location.should == [__FILE__, __LINE__, 15, __LINE__, 23] - -> { true }.source_location.should == [__FILE__, __LINE__, 8, __LINE__, 17] + -> { true }.source_location.should == [__FILE__, __LINE__, 6, __LINE__, 17] end end @@ -94,11 +94,11 @@ describe "Proc#source_location" do it "works for eval with a given line" do proc = eval('-> {}', nil, "foo", 100) location = proc.source_location - ruby_version_is(""..."3.5") do + ruby_version_is(""..."4.1") do location.should == ["foo", 100] end - ruby_version_is("3.5") do - location.should == ["foo", 100, 2, 100, 5] + ruby_version_is("4.1") do + location.should == ["foo", 100, 0, 100, 5] end end end |
