Skip to content

Commit

Permalink
[GR-45043] Integrate YARP parser [Part 6]
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4061
  • Loading branch information
andrykonchin committed Jan 4, 2024
2 parents 045a0e8 + f4c702f commit 7c5bef1
Show file tree
Hide file tree
Showing 304 changed files with 12,871 additions and 7,521 deletions.
2 changes: 1 addition & 1 deletion ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ local composition_environment = utils.add_inclusion_tracking(part_definitions, "
"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" },
"ruby-test-fast-linux-aarch64": $.platform.linux_aarch64 + $.jdk.stable + $.env.jvm + gate + $.run.test_fast + native_config + { timelimit: "45:00" },
"ruby-test-fast-linux-amd64": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_fast + { timelimit: "45:00" }, # To catch missing slow tags
"ruby-test-mri-asserts": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_mri_fast + { timelimit: "01:30:00" },
"ruby-test-mri-asserts": $.platform.linux + $.jdk.stable + $.env.jvm + gate + $.run.test_mri_fast + { timelimit: "02:00:00" },
"ruby-test-mri-linux-amd64": $.platform.linux + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:20:00" },
"ruby-test-mri-linux-aarch64": $.platform.linux_aarch64 + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:20:00" },
"ruby-test-mri-darwin-amd64": $.platform.darwin_amd64 + $.jdk.stable + $.env.native + gate + $.run.test_mri + { timelimit: "01:30:00" },
Expand Down
16 changes: 16 additions & 0 deletions spec/ruby/core/proc/arity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@
@a.arity.should == 3
@b.arity.should == 3
end

# implicit rest
evaluate <<-ruby do
@a = lambda { |a, | }
ruby

@a.arity.should == 1
end
end

context "returns negative values" do
Expand Down Expand Up @@ -530,6 +538,14 @@
@a.arity.should == 1
@b.arity.should == 5
end

# implicit rest
evaluate <<-ruby do
@a = proc { |a, | }
ruby

@a.arity.should == 1
end
end

context "returns negative values" do
Expand Down
5 changes: 5 additions & 0 deletions spec/ruby/core/proc/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
-> x {}.parameters.should == [[:req, :x]]
end

it "ignores implicit rest arguments" do
proc { |x, | }.parameters.should == [[:opt, :x]]
lambda { |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, :*]]
Expand Down
150 changes: 150 additions & 0 deletions spec/ruby/language/assignments_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
require_relative '../spec_helper'

# Should be synchronized with spec/ruby/language/optional_assignments_spec.rb
describe 'Assignments' do
describe 'using +=' do
describe 'using an accessor' do
before do
klass = Class.new { attr_accessor :b }
@a = klass.new
end

it 'does evaluate receiver only once when assigns' do
ScratchPad.record []
@a.b = 1

(ScratchPad << :evaluated; @a).b += 2

ScratchPad.recorded.should == [:evaluated]
@a.b.should == 3
end

it 'ignores method visibility when receiver is self' do
klass_with_private_methods = Class.new do
def initialize(n) @a = n end
def public_method(n); self.a += n end
private
def a; @a end
def a=(n) @a = n; 42 end
end

a = klass_with_private_methods.new(0)
a.public_method(2).should == 2
end
end

describe 'using a #[]' do
before do
klass = Class.new do
def [](k)
@hash ||= {}
@hash[k]
end

def []=(k, v)
@hash ||= {}
@hash[k] = v
7
end
end
@b = klass.new
end

it 'evaluates receiver only once when assigns' do
ScratchPad.record []
a = {k: 1}

(ScratchPad << :evaluated; a)[:k] += 2

ScratchPad.recorded.should == [:evaluated]
a[:k].should == 3
end

it 'ignores method visibility when receiver is self' do
klass_with_private_methods = Class.new do
def initialize(h) @a = h end
def public_method(k, n); self[k] += n end
private
def [](k) @a[k] end
def []=(k, v) @a[k] = v; 42 end
end

a = klass_with_private_methods.new(k: 0)
a.public_method(:k, 2).should == 2
end

context 'splatted argument' do
it 'correctly handles it' do
@b[:m] = 10
(@b[*[:m]] += 10).should == 20
@b[:m].should == 20

@b[:n] = 10
(@b[*(1; [:n])] += 10).should == 20
@b[:n].should == 20

@b[:k] = 10
(@b[*begin 1; [:k] end] += 10).should == 20
@b[:k].should == 20
end

it 'calls #to_a only once' do
k = Object.new
def k.to_a
ScratchPad << :to_a
[:k]
end

ScratchPad.record []
@b[:k] = 10
(@b[*k] += 10).should == 20
@b[:k].should == 20
ScratchPad.recorded.should == [:to_a]
end

it 'correctly handles a nested splatted argument' do
@b[:k] = 10
(@b[*[*[:k]]] += 10).should == 20
@b[:k].should == 20
end

it 'correctly handles multiple nested splatted arguments' do
klass_with_multiple_parameters = Class.new do
def [](k1, k2, k3)
@hash ||= {}
@hash[:"#{k1}#{k2}#{k3}"]
end

def []=(k1, k2, k3, v)
@hash ||= {}
@hash[:"#{k1}#{k2}#{k3}"] = v
7
end
end
a = klass_with_multiple_parameters.new

a[:a, :b, :c] = 10
(a[*[:a], *[:b], *[:c]] += 10).should == 20
a[:a, :b, :c].should == 20
end
end
end

describe 'using compounded constants' do
it 'causes side-effects of the module part to be applied only once (when assigns)' do
module ConstantSpecs
OpAssignTrue = 1
end

suppress_warning do # already initialized constant
x = 0
(x += 1; ConstantSpecs)::OpAssignTrue += 2
x.should == 1
ConstantSpecs::OpAssignTrue.should == 3
end

ConstantSpecs.send :remove_const, :OpAssignTrue
end
end
end
end
Loading

0 comments on commit 7c5bef1

Please sign in to comment.