File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ def uses_method_chain?
30
30
end
31
31
32
32
def uses_method_chain_with_block?
33
+ arg = ArbitraryArg . new
33
34
matchers = [
34
35
{
35
36
method_name : :upcase ,
@@ -42,7 +43,7 @@ def uses_method_chain_with_block?
42
43
type : :block ,
43
44
method_name : :map ,
44
45
chained? : true ,
45
- arguments : s ( :args , s ( : arg, :word ) )
46
+ arguments : arg ,
46
47
} ,
47
48
{
48
49
method_name : :map ,
@@ -59,7 +60,7 @@ def uses_method_chain_with_block?
59
60
} ,
60
61
{
61
62
method_name : :chr ,
62
- receiver : s ( : lvar, :word )
63
+ receiver : arg . lvar
63
64
}
64
65
]
65
66
@@ -152,3 +153,25 @@ def ==(other)
152
153
other . type == :lvar
153
154
end
154
155
end
156
+
157
+ class NamedLvar
158
+ attr_accessor :name
159
+
160
+ def ==( other )
161
+ other == Parser ::AST ::Node . new ( :lvar , name )
162
+ end
163
+ end
164
+
165
+ class ArbitraryArg
166
+ def lvar
167
+ @lvar ||= NamedLvar . new
168
+ end
169
+
170
+ def ==( other )
171
+ if other . type == :args
172
+ lvar . name = other . first . node_parts
173
+ end
174
+
175
+ other . type == :args
176
+ end
177
+ end
Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ def self.abbreviate(words)
41
41
assert_equal [ "ruby.acronym.block_syntax.shorthand" ] , results [ :comments ]
42
42
end
43
43
44
+ def test_method_chaining_with_block_syntax_with_arbitrary_arg_passes
45
+ source = %q{
46
+ class Acronym
47
+ def self.abbreviate(words)
48
+ words.tr('-', ' ').split.map { |term| term.chr }.join.upcase
49
+ end
50
+ end
51
+ }
52
+ results = Acronym ::Analyze . ( source )
53
+ assert_equal :approve , results [ :status ]
54
+ assert_equal [ "ruby.acronym.block_syntax.shorthand" ] , results [ :comments ]
55
+ end
56
+
44
57
def test_module_method_passes
45
58
source = %q{
46
59
module Acronym
You can’t perform that action at this time.
0 commit comments