Ruby: add one-line pattern match test

This commit is contained in:
Arthur Baars
2023-02-02 14:45:43 +01:00
parent edbba85b96
commit 3c15fd266d
7 changed files with 51 additions and 7 deletions

View File

@@ -1259,6 +1259,22 @@ control/cases.rb:
# 157| getExpr: [AddExpr] ... + ...
# 157| getAnOperand/getLeftOperand/getReceiver: [IntegerLiteral] 1
# 157| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 1
# 160| getStmt: [TestPattern] ... in ...
# 160| getValue: [MethodCall] call to expr
# 160| getReceiver: [SelfVariableAccess] self
# 160| getPattern: [ArrayPattern] [ ..., * ]
# 160| getPrefixElement: [IntegerLiteral] 1
# 160| getPrefixElement: [IntegerLiteral] 2
# 162| getStmt: [MatchPattern] ... => ...
# 162| getValue: [MethodCall] call to expr
# 162| getReceiver: [SelfVariableAccess] self
# 162| getPattern: [HashPattern] { ..., ** }
# 162| getKey: [SymbolLiteral] :x
# 162| getComponent: [StringTextComponent] x
# 162| getValue: [LocalVariableAccess] v
# 162| getKey: [SymbolLiteral] :y
# 162| getComponent: [StringTextComponent] y
# 162| getValue: [IntegerLiteral] 1
modules/classes.rb:
# 2| [Toplevel] classes.rb
# 3| getStmt: [ClassDeclaration] Foo

View File

@@ -2732,6 +2732,30 @@ control/cases.rb:
# 157| 3: [ReservedWord] )
# 157| 2: [ReservedWord] ;
# 158| 5: [ReservedWord] end
# 160| 17: [TestPattern] TestPattern
# 160| 0: [Identifier] expr
# 160| 1: [ReservedWord] in
# 160| 2: [ArrayPattern] ArrayPattern
# 160| 0: [ReservedWord] [
# 160| 1: [Integer] 1
# 160| 2: [ReservedWord] ,
# 160| 3: [Integer] 2
# 160| 4: [ReservedWord] ]
# 162| 18: [MatchPattern] MatchPattern
# 162| 0: [Identifier] expr
# 162| 1: [ReservedWord] =>
# 162| 2: [HashPattern] HashPattern
# 162| 0: [ReservedWord] {
# 162| 1: [KeywordPattern] KeywordPattern
# 162| 0: [HashKeySymbol] x
# 162| 1: [ReservedWord] :
# 162| 2: [Identifier] v
# 162| 2: [ReservedWord] ,
# 162| 3: [KeywordPattern] KeywordPattern
# 162| 0: [HashKeySymbol] y
# 162| 1: [ReservedWord] :
# 162| 2: [Integer] 1
# 162| 4: [ReservedWord] }
# 1| [Comment] # Define some variables used below
# 7| [Comment] # A case expr with a value and an else branch
# 17| [Comment] # A case expr without a value or else branch

View File

@@ -263,6 +263,11 @@ exprValue
| control/cases.rb:157:8:157:8 | 1 | 1 | int |
| control/cases.rb:157:8:157:12 | ... + ... | 2 | int |
| control/cases.rb:157:12:157:12 | 1 | 1 | int |
| control/cases.rb:160:10:160:10 | 1 | 1 | int |
| control/cases.rb:160:13:160:13 | 2 | 2 | int |
| control/cases.rb:162:10:162:10 | :x | :x | symbol |
| control/cases.rb:162:16:162:16 | :y | :y | symbol |
| control/cases.rb:162:19:162:19 | 1 | 1 | int |
| control/conditionals.rb:2:5:2:5 | 0 | 0 | int |
| control/conditionals.rb:3:5:3:5 | 0 | 0 | int |
| control/conditionals.rb:4:5:4:5 | 0 | 0 | int |

View File

@@ -155,4 +155,8 @@ case expr
in ^(foo);
in ^(@foo);
in ^(1 + 1);
end
end
expr in [1, 2]
expr => {x: v, y: 1}

View File

@@ -1,3 +1 @@
| src/not_ruby.rb:5:25:5:26 | parse error | Extraction failed in src/not_ruby.rb with error parse error | 2 |
| src/unsupported_feature.rb:2:1:2:4 | parse error | Extraction failed in src/unsupported_feature.rb with error parse error | 2 |
| src/unsupported_feature.rb:3:1:3:8 | parse error | Extraction failed in src/unsupported_feature.rb with error parse error | 2 |

View File

@@ -1,3 +0,0 @@
# one line pattern matches
5 in 3
[1,2] => [x, *]