Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/proc/fixtures/syntax_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Avoids warnings on Ruby 3.3
module ProcSpecs
module SyntaxTree
def self.lambda_it
-> { it }
end
LAMBDA_IT_LINE = __LINE__ - 2

def self.proc_it
proc { it }
end
PROC_IT_LINE = __LINE__ - 2
end
end
12 changes: 6 additions & 6 deletions core/proc/syntax_tree_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
require_relative '../../fixtures/source_range_helpers'

ruby_version_is "4.1" do
require_relative 'fixtures/syntax_tree' # avoids warnings on Ruby 3.3

describe "Proc#syntax_tree" do
before :each do
skip "parse.y" unless syntax_tree_returns_prism_node
Expand Down Expand Up @@ -38,26 +40,24 @@ def return_block(&b)
node.should.is_a?(Ruby::Prism::LambdaNode)
end

quarantine! do # NoMethodError: undefined method 'start_line' for nil
it "does not return implicit parameter nodes" do
# Interesting because the BlockNode and the ItParametersNode/NumberedParametersNode are fully overlapping
node = eval('-> { it }.syntax_tree') # emits a warning on Ruby 3.3
node.start_line.should == __LINE__ - 1
node = ProcSpecs::SyntaxTree.lambda_it.syntax_tree
node.start_line.should == ProcSpecs::SyntaxTree::LAMBDA_IT_LINE
node.should.is_a?(Ruby::Prism::LambdaNode)

node = -> { _1 }.syntax_tree
node.start_line.should == __LINE__ - 1
node.should.is_a?(Ruby::Prism::LambdaNode)

node = eval('proc { it }.syntax_tree') # emits a warning on Ruby 3.3
node.start_line.should == __LINE__ - 1
node = ProcSpecs::SyntaxTree.proc_it.syntax_tree
node.start_line.should == ProcSpecs::SyntaxTree::PROC_IT_LINE
node.should.is_a?(Ruby::Prism::CallNode)

node = proc { _1 }.syntax_tree
node.start_line.should == __LINE__ - 1
node.should.is_a?(Ruby::Prism::CallNode)
end
end

it "returns a ForNode for a for-loop block" do
iter = Object.new
Expand Down
Loading