Skip to content

Commit 7c5bef1

Browse files
committed
[GR-45043] Integrate YARP parser [Part 6]
PullRequest: truffleruby/4061
2 parents 045a0e8 + f4c702f commit 7c5bef1

File tree

304 files changed

+12871
-7521
lines changed

Some content is hidden

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

304 files changed

+12871
-7521
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
526526
"ruby-test-specs-darwin-aarch64-latest": $.platform.darwin_aarch64 + $.jdk.latest + $.env.jvm + gate_no_build + $.use.build + $.run.test_unit_tck + native_config + $.run.test_specs + { timelimit: "01:40:00" },
527527
"ruby-test-fast-linux-aarch64": $.platform.linux_aarch64 + $.jdk.stable + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "45:00" },
528528
"ruby-test-fast-linux-amd64": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_fast + { timelimit: "45:00" }, # To catch missing slow tags
529-
"ruby-test-mri-asserts": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_mri_fast + { timelimit: "01:30:00" },
529+
"ruby-test-mri-asserts": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_mri_fast + { timelimit: "02:00:00" },
530530
"ruby-test-mri-linux-amd64": $.platform.linux + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:20:00" },
531531
"ruby-test-mri-linux-aarch64": $.platform.linux_aarch64 + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:20:00" },
532532
"ruby-test-mri-darwin-amd64": $.platform.darwin_amd64 + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:30:00" },

spec/ruby/core/proc/arity_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@
268268
@a.arity.should == 3
269269
@b.arity.should == 3
270270
end
271+
272+
# implicit rest
273+
evaluate <<-ruby do
274+
@a = lambda { |a, | }
275+
ruby
276+
277+
@a.arity.should == 1
278+
end
271279
end
272280

273281
context "returns negative values" do
@@ -530,6 +538,14 @@
530538
@a.arity.should == 1
531539
@b.arity.should == 5
532540
end
541+
542+
# implicit rest
543+
evaluate <<-ruby do
544+
@a = proc { |a, | }
545+
ruby
546+
547+
@a.arity.should == 1
548+
end
533549
end
534550

535551
context "returns negative values" do

spec/ruby/core/proc/parameters_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
-> x {}.parameters.should == [[:req, :x]]
9696
end
9797

98+
it "ignores implicit rest arguments" do
99+
proc { |x, | }.parameters.should == [[:opt, :x]]
100+
lambda { |x, | }.parameters.should == [[:req, :x]]
101+
end
102+
98103
ruby_version_is '3.2' do
99104
it "adds rest arg with name * for \"star\" argument" do
100105
-> * {}.parameters.should == [[:rest, :*]]
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
require_relative '../spec_helper'
2+
3+
# Should be synchronized with spec/ruby/language/optional_assignments_spec.rb
4+
describe 'Assignments' do
5+
describe 'using +=' do
6+
describe 'using an accessor' do
7+
before do
8+
klass = Class.new { attr_accessor :b }
9+
@a = klass.new
10+
end
11+
12+
it 'does evaluate receiver only once when assigns' do
13+
ScratchPad.record []
14+
@a.b = 1
15+
16+
(ScratchPad << :evaluated; @a).b += 2
17+
18+
ScratchPad.recorded.should == [:evaluated]
19+
@a.b.should == 3
20+
end
21+
22+
it 'ignores method visibility when receiver is self' do
23+
klass_with_private_methods = Class.new do
24+
def initialize(n) @a = n end
25+
def public_method(n); self.a += n end
26+
private
27+
def a; @a end
28+
def a=(n) @a = n; 42 end
29+
end
30+
31+
a = klass_with_private_methods.new(0)
32+
a.public_method(2).should == 2
33+
end
34+
end
35+
36+
describe 'using a #[]' do
37+
before do
38+
klass = Class.new do
39+
def [](k)
40+
@hash ||= {}
41+
@hash[k]
42+
end
43+
44+
def []=(k, v)
45+
@hash ||= {}
46+
@hash[k] = v
47+
7
48+
end
49+
end
50+
@b = klass.new
51+
end
52+
53+
it 'evaluates receiver only once when assigns' do
54+
ScratchPad.record []
55+
a = {k: 1}
56+
57+
(ScratchPad << :evaluated; a)[:k] += 2
58+
59+
ScratchPad.recorded.should == [:evaluated]
60+
a[:k].should == 3
61+
end
62+
63+
it 'ignores method visibility when receiver is self' do
64+
klass_with_private_methods = Class.new do
65+
def initialize(h) @a = h end
66+
def public_method(k, n); self[k] += n end
67+
private
68+
def [](k) @a[k] end
69+
def []=(k, v) @a[k] = v; 42 end
70+
end
71+
72+
a = klass_with_private_methods.new(k: 0)
73+
a.public_method(:k, 2).should == 2
74+
end
75+
76+
context 'splatted argument' do
77+
it 'correctly handles it' do
78+
@b[:m] = 10
79+
(@b[*[:m]] += 10).should == 20
80+
@b[:m].should == 20
81+
82+
@b[:n] = 10
83+
(@b[*(1; [:n])] += 10).should == 20
84+
@b[:n].should == 20
85+
86+
@b[:k] = 10
87+
(@b[*begin 1; [:k] end] += 10).should == 20
88+
@b[:k].should == 20
89+
end
90+
91+
it 'calls #to_a only once' do
92+
k = Object.new
93+
def k.to_a
94+
ScratchPad << :to_a
95+
[:k]
96+
end
97+
98+
ScratchPad.record []
99+
@b[:k] = 10
100+
(@b[*k] += 10).should == 20
101+
@b[:k].should == 20
102+
ScratchPad.recorded.should == [:to_a]
103+
end
104+
105+
it 'correctly handles a nested splatted argument' do
106+
@b[:k] = 10
107+
(@b[*[*[:k]]] += 10).should == 20
108+
@b[:k].should == 20
109+
end
110+
111+
it 'correctly handles multiple nested splatted arguments' do
112+
klass_with_multiple_parameters = Class.new do
113+
def [](k1, k2, k3)
114+
@hash ||= {}
115+
@hash[:"#{k1}#{k2}#{k3}"]
116+
end
117+
118+
def []=(k1, k2, k3, v)
119+
@hash ||= {}
120+
@hash[:"#{k1}#{k2}#{k3}"] = v
121+
7
122+
end
123+
end
124+
a = klass_with_multiple_parameters.new
125+
126+
a[:a, :b, :c] = 10
127+
(a[*[:a], *[:b], *[:c]] += 10).should == 20
128+
a[:a, :b, :c].should == 20
129+
end
130+
end
131+
end
132+
133+
describe 'using compounded constants' do
134+
it 'causes side-effects of the module part to be applied only once (when assigns)' do
135+
module ConstantSpecs
136+
OpAssignTrue = 1
137+
end
138+
139+
suppress_warning do # already initialized constant
140+
x = 0
141+
(x += 1; ConstantSpecs)::OpAssignTrue += 2
142+
x.should == 1
143+
ConstantSpecs::OpAssignTrue.should == 3
144+
end
145+
146+
ConstantSpecs.send :remove_const, :OpAssignTrue
147+
end
148+
end
149+
end
150+
end

0 commit comments

Comments
 (0)