Skip to content

Commit 29851ba

Browse files
committed
Move out the inline method definition for Ruby 2.7
1 parent 7432e1e commit 29851ba

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

test/prism/newline_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NewlineTest < TestCase
1717
result/breadth_first_search_test.rb
1818
result/static_literals_test.rb
1919
result/warnings_test.rb
20+
ruby/inline_method.rb
2021
ruby/parser_test.rb
2122
ruby/ruby_parser_test.rb
2223
]

test/prism/ruby/inline_method.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# A separate file because 2.7 can't parse this
2+
module Prism
3+
class NodeForTest < TestCase
4+
def inline_method = 42
5+
INLINE_LOCATION_AND_FILE = [[__LINE__-1, 4, __LINE__-1, 26], __FILE__]
6+
end
7+
end

test/prism/ruby/node_for_test.rb

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# Needs Prism.parse_file(file, version: "current")
77
return if RUBY_VERSION < "3.3"
88

9+
require_relative 'inline_method'
10+
911
module Prism
1012
class NodeForTest < TestCase
1113
INDENT = ' ' * 4
@@ -15,13 +17,12 @@ def m(foo)
1517
end
1618
M_LOCATION = [__LINE__-3, 4, __LINE__-1, 7]
1719

18-
def inline_method = 42
19-
INLINE_LOCATION = [__LINE__-1, 4, __LINE__-1, 26]
20-
2120
define_method(:define_method_method) { 42 }
2221
DEFINE_METHOD_LOCATION = [__LINE__-1, 41, __LINE__-1, 47]
2322

24-
def return_block(&block) = block
23+
def return_block(&block)
24+
block
25+
end
2526

2627
def with_location(callable, locs, file = __FILE__)
2728
source_location = [file, *locs]
@@ -44,7 +45,7 @@ def test_def_method
4445
end
4546

4647
def test_inline_method
47-
node = Prism.node_for(with_location(method(:inline_method), INLINE_LOCATION))
48+
node = Prism.node_for(with_location(method(:inline_method), *INLINE_LOCATION_AND_FILE))
4849
assert_instance_of(Prism::DefNode, node)
4950
assert_equal "def inline_method = 42", node.slice
5051
end
@@ -89,7 +90,7 @@ def test_proc
8990
end
9091

9192
def test_method_to_proc
92-
node = Prism.node_for(with_location(method(:inline_method).to_proc, INLINE_LOCATION))
93+
node = Prism.node_for(with_location(method(:inline_method).to_proc, *INLINE_LOCATION_AND_FILE))
9394
assert_instance_of(Prism::DefNode, node)
9495
assert_equal "def inline_method = 42", node.slice
9596
end

0 commit comments

Comments
 (0)