Skip to content

Commit 8979580

Browse files
committed
[GR-45043] Integrate YARP parser [Part 4]
PullRequest: truffleruby/4045
2 parents 3058b24 + ae0deb7 commit 8979580

File tree

245 files changed

+5995
-1253
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+5995
-1253
lines changed

spec/ruby/core/method/parameters_spec.rb

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def one_key(a: 1); end
77
def one_keyrest(**a); end
88

99
def one_keyreq(a:); end
10+
def one_nokey(**nil); end
1011

1112
def one_splat_one_req(*a,b); end
1213
def one_splat_two_req(*a,b,c); end
@@ -15,6 +16,7 @@ def one_splat_one_req_with_block(*a,b,&blk); end
1516
def one_opt_with_stabby(a=-> b { true }); end
1617

1718
def one_unnamed_splat(*); end
19+
def one_unnamed_keyrest(**); end
1820

1921
def one_splat_one_block(*args, &block)
2022
local_is_not_parameter = {}
@@ -178,6 +180,11 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
178180
m.parameters.should == [[:keyreq,:a]]
179181
end
180182

183+
it "returns [[:nokey]] for a method with a single **nil parameter" do
184+
m = MethodSpecs::Methods.instance_method(:one_nokey)
185+
m.parameters.should == [[:nokey]]
186+
end
187+
181188
it "works with ->(){} as the value of an optional argument" do
182189
m = MethodSpecs::Methods.instance_method(:one_opt_with_stabby)
183190
m.parameters.should == [[:opt,:a]]
@@ -225,17 +232,39 @@ def underscore_parameters(_, _, _ = 1, *_, _:, _: 2, **_, &_); end
225232
end
226233

227234
ruby_version_is '3.2' do
228-
it "adds * rest arg for \"star\" argument" do
235+
it "adds rest arg with name * for \"star\" argument" do
229236
m = MethodSpecs::Methods.new
230237
m.method(:one_unnamed_splat).parameters.should == [[:rest, :*]]
231238
end
239+
240+
it "adds keyrest arg with ** as a name for \"double star\" argument" do
241+
m = MethodSpecs::Methods.new
242+
m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest, :**]]
243+
end
232244
end
233245

234246
ruby_version_is ''...'3.2' do
235247
it "adds nameless rest arg for \"star\" argument" do
236248
m = MethodSpecs::Methods.new
237249
m.method(:one_unnamed_splat).parameters.should == [[:rest]]
238250
end
251+
252+
it "adds nameless keyrest arg for \"double star\" argument" do
253+
m = MethodSpecs::Methods.new
254+
m.method(:one_unnamed_keyrest).parameters.should == [[:keyrest]]
255+
end
256+
end
257+
258+
ruby_version_is '3.1' do
259+
it "adds block arg with name & for anonymous block argument" do
260+
object = Object.new
261+
262+
eval(<<~RUBY).should == [[:block, :&]]
263+
def object.foo(&)
264+
end
265+
object.method(:foo).parameters
266+
RUBY
267+
end
239268
end
240269

241270
it "returns the args and block for a splat and block argument" do

spec/ruby/core/proc/parameters_spec.rb

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
end
2222

2323
ruby_version_is "3.2" do
24-
it "sets the first element of each sub-Array to :req if argument would be required if a lambda if lambda keyword used" do
24+
it "sets the first element of each sub-Array to :req for required argument if lambda keyword used" do
2525
proc {|x| }.parameters(lambda: true).first.first.should == :req
2626
proc {|y,*x| }.parameters(lambda: true).first.first.should == :req
2727
end
@@ -91,19 +91,33 @@
9191
proc {|&block| }.parameters.first.last.should == :block
9292
end
9393

94-
it "ignores unnamed rest args" do
94+
it "ignores unnamed rest arguments" do
9595
-> x {}.parameters.should == [[:req, :x]]
9696
end
9797

9898
ruby_version_is '3.2' do
99-
it "adds * rest arg for \"star\" argument" do
100-
-> x, * {}.parameters.should == [[:req, :x], [:rest, :*]]
99+
it "adds rest arg with name * for \"star\" argument" do
100+
-> * {}.parameters.should == [[:rest, :*]]
101+
end
102+
103+
it "adds keyrest arg with ** as a name for \"double star\" argument" do
104+
-> ** {}.parameters.should == [[:keyrest, :**]]
101105
end
102106
end
103107

104108
ruby_version_is ''...'3.2' do
105109
it "adds nameless rest arg for \"star\" argument" do
106-
-> x, * {}.parameters.should == [[:req, :x], [:rest]]
110+
-> * {}.parameters.should == [[:rest]]
111+
end
112+
113+
it "adds nameless keyrest arg for \"double star\" argument" do
114+
-> ** {}.parameters.should == [[:keyrest]]
115+
end
116+
end
117+
118+
ruby_version_is '3.1' do
119+
it "adds block arg with name & for anonymous block argument" do
120+
eval('-> & {}.parameters').should == [[:block, :&]]
107121
end
108122
end
109123

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
fails:Method#parameters adds * rest arg for "star" argument
1+
fails:Method#parameters adds rest arg with name * for "star" argument
2+
fails:Method#parameters adds keyrest arg with ** as a name for "double star" argument
3+
fails:Method#parameters adds block arg with name & for anonymous block argument
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
fails:Proc#parameters sets the first element of each sub-Array to :req if argument would be required if a lambda if lambda keyword used
1+
fails:Proc#parameters sets the first element of each sub-Array to :req for required argument if lambda keyword used
22
fails:Proc#parameters regards named parameters in procs as required if lambda keyword used
33
fails:Proc#parameters regards named parameters in lambda as optional if lambda: false keyword used
4-
fails:Proc#parameters adds * rest arg for "star" argument
4+
fails:Proc#parameters adds rest arg with name * for "star" argument
5+
fails:Proc#parameters adds keyrest arg with ** as a name for "double star" argument
6+
fails:Proc#parameters adds block arg with name & for anonymous block argument

0 commit comments

Comments
 (0)