File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,10 @@ class Node < Parser::AST::Node # rubocop:disable Metrics/ClassLength
116
116
117
117
block : :any_block ,
118
118
numblock : :any_block ,
119
- itblock : :any_block
119
+ itblock : :any_block ,
120
+
121
+ match_pattern : :any_match_pattern ,
122
+ match_pattern_p : :any_match_pattern
120
123
} . freeze
121
124
private_constant :GROUP_FOR_TYPE
122
125
@@ -540,6 +543,10 @@ def any_block_type?
540
543
GROUP_FOR_TYPE [ type ] == :any_block
541
544
end
542
545
546
+ def any_match_pattern_type?
547
+ GROUP_FOR_TYPE [ type ] == :any_match_pattern
548
+ end
549
+
543
550
def guard_clause?
544
551
node = operator_keyword? ? rhs : self
545
552
Original file line number Diff line number Diff line change @@ -1083,6 +1083,49 @@ class << expr
1083
1083
end
1084
1084
end
1085
1085
1086
+ describe '#any_match_pattern_type?' do
1087
+ # Ruby 2.7's one-line `in` pattern node type is `match-pattern`.
1088
+ context 'when `in` one-line pattern matching' , :ruby27 do
1089
+ let ( :src ) { 'expression in pattern' }
1090
+
1091
+ it 'is true' do
1092
+ expect ( node ) . to be_any_match_pattern_type
1093
+ end
1094
+ end
1095
+
1096
+ # Ruby 3.0's one-line `in` pattern node type is `match-pattern-p`.
1097
+ context 'when `in` one-line pattern matching' , :ruby30 do
1098
+ let ( :src ) { 'expression in pattern' }
1099
+
1100
+ it 'is true' do
1101
+ expect ( node ) . to be_any_match_pattern_type
1102
+ end
1103
+ end
1104
+
1105
+ # Ruby 3.0's one-line `=>` pattern node type is `match-pattern`.
1106
+ context 'when `=>` one-line pattern matching' , :ruby30 do
1107
+ let ( :src ) { 'expression => pattern' }
1108
+
1109
+ it 'is true' do
1110
+ expect ( node ) . to be_any_match_pattern_type
1111
+ end
1112
+ end
1113
+
1114
+ context 'when pattern matching' , :ruby27 do
1115
+ let ( :src ) do
1116
+ <<~RUBY
1117
+ case expression
1118
+ in pattern
1119
+ end
1120
+ RUBY
1121
+ end
1122
+
1123
+ it 'is false' do
1124
+ expect ( node ) . not_to be_any_match_pattern_type
1125
+ end
1126
+ end
1127
+ end
1128
+
1086
1129
describe '#type?' do
1087
1130
let ( :src ) do
1088
1131
<<~RUBY
You can’t perform that action at this time.
0 commit comments