Skip to content

Commit a819797

Browse files
committed
Ruby: add test case of destructured assignment with contants
1 parent 8b90d02 commit a819797

File tree

8 files changed

+88
-0
lines changed

8 files changed

+88
-0
lines changed

ruby/ql/test/library-tests/ast/Ast.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,6 +2878,16 @@ operations/operations.rb:
28782878
# 103| getStmt: [AssignLogicalOrExpr] ... ||= ...
28792879
# 103| getAnOperand/getLeftOperand: [ConstantAssignment, ConstantReadAccess] CONSTANT4
28802880
# 103| getAnOperand/getRightOperand: [IntegerLiteral] 7
2881+
# 104| getStmt: [AssignExpr] ... = ...
2882+
# 104| getAnOperand/getLeftOperand: [DestructuredLhsExpr] (..., ...)
2883+
# 104| getElement: [ConstantAssignment] FOO
2884+
# 104| getElement: [ConstantAssignment] BAR
2885+
# 104| getElement: [ConstantAssignment] FOO
2886+
# 104| getScopeExpr: [LocalVariableAccess] foo
2887+
# 104| getAnOperand/getRightOperand: [ArrayLiteral] [...]
2888+
# 104| getElement: [IntegerLiteral] 1
2889+
# 104| getElement: [IntegerLiteral] 2
2890+
# 104| getElement: [IntegerLiteral] 3
28812891
params/params.rb:
28822892
# 1| [Toplevel] params.rb
28832893
# 4| getStmt: [Method] identifier_method_params

ruby/ql/test/library-tests/ast/AstDesugar.expected

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,33 @@ operations/operations.rb:
946946
# 103| getAnOperand/getRightOperand: [LogicalOrExpr] ... || ...
947947
# 103| getAnOperand/getLeftOperand/getReceiver: [ConstantReadAccess] CONSTANT4
948948
# 103| getAnOperand/getArgument/getRightOperand: [IntegerLiteral] 7
949+
# 104| [AssignExpr] ... = ...
950+
# 104| getDesugared: [StmtSequence] ...
951+
# 104| getStmt: [AssignExpr] ... = ...
952+
# 104| getAnOperand/getLeftOperand: [ConstantAssignment] FOO
953+
# 104| getAnOperand/getRightOperand: [MethodCall] call to []
954+
# 104| getReceiver: [LocalVariableAccess] __synth__3
955+
# 104| getArgument: [IntegerLiteral] 0
956+
# 104| getStmt: [AssignExpr] ... = ...
957+
# 104| getAnOperand/getLeftOperand: [ConstantAssignment] BAR
958+
# 104| getAnOperand/getRightOperand: [MethodCall] call to []
959+
# 104| getReceiver: [LocalVariableAccess] __synth__3
960+
# 104| getArgument: [IntegerLiteral] 1
961+
# 104| getStmt: [AssignExpr] ... = ...
962+
# 104| getAnOperand/getLeftOperand: [ConstantAssignment] FOO
963+
# 104| getScopeExpr: [LocalVariableAccess] foo
964+
# 104| getAnOperand/getRightOperand: [MethodCall] call to []
965+
# 104| getReceiver: [LocalVariableAccess] __synth__3
966+
# 104| getArgument: [IntegerLiteral] 2
967+
# 104| getStmt: [AssignExpr] ... = ...
968+
# 104| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__3
969+
# 104| getAnOperand/getRightOperand: [SplatExpr] * ...
970+
# 104| getAnOperand/getOperand/getReceiver: [ArrayLiteral] [...]
971+
# 104| getDesugared: [MethodCall] call to []
972+
# 104| getReceiver: [ConstantReadAccess] Array
973+
# 104| getArgument: [IntegerLiteral] 1
974+
# 104| getArgument: [IntegerLiteral] 2
975+
# 104| getArgument: [IntegerLiteral] 3
949976
params/params.rb:
950977
# 8| [HashLiteral] {...}
951978
# 8| getDesugared: [MethodCall] call to []

ruby/ql/test/library-tests/ast/TreeSitter.expected

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5615,6 +5615,27 @@ operations/operations.rb:
56155615
# 103| 1: [Constant] CONSTANT4
56165616
# 103| 1: [ReservedWord] ||=
56175617
# 103| 2: [Integer] 7
5618+
# 104| 72: [Assignment] Assignment
5619+
# 104| 0: [LeftAssignmentList] LeftAssignmentList
5620+
# 104| 0: [Constant] FOO
5621+
# 104| 1: [ReservedWord] ,
5622+
# 104| 2: [ScopeResolution] ScopeResolution
5623+
# 104| 0: [ReservedWord] ::
5624+
# 104| 1: [Constant] BAR
5625+
# 104| 3: [ReservedWord] ,
5626+
# 104| 4: [ScopeResolution] ScopeResolution
5627+
# 104| 0: [Identifier] foo
5628+
# 104| 1: [ReservedWord] ::
5629+
# 104| 2: [Constant] FOO
5630+
# 104| 1: [ReservedWord] =
5631+
# 104| 2: [Array] Array
5632+
# 104| 0: [ReservedWord] [
5633+
# 104| 1: [Integer] 1
5634+
# 104| 2: [ReservedWord] ,
5635+
# 104| 3: [Integer] 2
5636+
# 104| 4: [ReservedWord] ,
5637+
# 104| 5: [Integer] 3
5638+
# 104| 6: [ReservedWord] ]
56185639
# 1| [Comment] # Start with assignments to all the identifiers used below, so that they are
56195640
# 2| [Comment] # interpreted as variables.
56205641
# 22| [Comment] # Unary operations

ruby/ql/test/library-tests/ast/ValueText.expected

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,12 @@ exprValue
903903
| operations/operations.rb:102:5:102:5 | 1 | 1 | int |
904904
| operations/operations.rb:102:31:102:31 | 7 | 7 | int |
905905
| operations/operations.rb:103:17:103:17 | 7 | 7 | int |
906+
| operations/operations.rb:104:1:104:3 | 0 | 0 | int |
907+
| operations/operations.rb:104:6:104:10 | 1 | 1 | int |
908+
| operations/operations.rb:104:13:104:20 | 2 | 2 | int |
909+
| operations/operations.rb:104:25:104:25 | 1 | 1 | int |
910+
| operations/operations.rb:104:28:104:28 | 2 | 2 | int |
911+
| operations/operations.rb:104:31:104:31 | 3 | 3 | int |
906912
| params/params.rb:41:46:41:46 | 7 | 7 | int |
907913
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
908914
| params/params.rb:47:24:47:24 | 2 | 2 | int |
@@ -1792,6 +1798,12 @@ exprCfgNodeValue
17921798
| operations/operations.rb:102:5:102:5 | 1 | 1 | int |
17931799
| operations/operations.rb:102:31:102:31 | 7 | 7 | int |
17941800
| operations/operations.rb:103:17:103:17 | 7 | 7 | int |
1801+
| operations/operations.rb:104:1:104:3 | 0 | 0 | int |
1802+
| operations/operations.rb:104:6:104:10 | 1 | 1 | int |
1803+
| operations/operations.rb:104:13:104:20 | 2 | 2 | int |
1804+
| operations/operations.rb:104:25:104:25 | 1 | 1 | int |
1805+
| operations/operations.rb:104:28:104:28 | 2 | 2 | int |
1806+
| operations/operations.rb:104:31:104:31 | 3 | 3 | int |
17951807
| params/params.rb:41:46:41:46 | 7 | 7 | int |
17961808
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
17971809
| params/params.rb:47:24:47:24 | 2 | 2 | int |

ruby/ql/test/library-tests/ast/operations/assignment.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ assignments
6565
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:1:102:25 | OtherConstant | operations.rb:102:31:102:31 | 7 | AssignLogicalOrExpr |
6666
| operations.rb:103:1:103:17 | ... = ... | = | operations.rb:103:1:103:11 | CONSTANT4 | operations.rb:103:13:103:15 | ... \|\| ... | AssignExpr |
6767
| operations.rb:103:1:103:17 | ... \|\|= ... | \|\|= | operations.rb:103:1:103:11 | CONSTANT4 | operations.rb:103:17:103:17 | 7 | AssignLogicalOrExpr |
68+
| operations.rb:104:1:104:3 | ... = ... | = | operations.rb:104:1:104:3 | FOO | operations.rb:104:1:104:3 | call to [] | AssignExpr |
69+
| operations.rb:104:1:104:32 | ... = ... | = | operations.rb:104:1:104:20 | (..., ...) | operations.rb:104:24:104:32 | [...] | AssignExpr |
70+
| operations.rb:104:6:104:10 | ... = ... | = | operations.rb:104:6:104:10 | BAR | operations.rb:104:6:104:10 | call to [] | AssignExpr |
71+
| operations.rb:104:13:104:20 | ... = ... | = | operations.rb:104:13:104:20 | FOO | operations.rb:104:13:104:20 | call to [] | AssignExpr |
72+
| operations.rb:104:24:104:32 | ... = ... | = | operations.rb:104:24:104:32 | __synth__3 | operations.rb:104:24:104:32 | * ... | AssignExpr |
6873
assignOperations
6974
| operations.rb:69:1:69:8 | ... += ... | += | operations.rb:69:1:69:1 | x | operations.rb:69:6:69:8 | 128 | AssignAddExpr |
7075
| operations.rb:70:1:70:7 | ... -= ... | -= | operations.rb:70:1:70:1 | y | operations.rb:70:6:70:7 | 32 | AssignSubExpr |

ruby/ql/test/library-tests/ast/operations/operation.expected

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,14 @@
230230
| operations.rb:103:1:103:17 | ... \|\|= ... | \|\|= | operations.rb:103:17:103:17 | 7 | AssignLogicalOrExpr |
231231
| operations.rb:103:13:103:15 | ... \|\| ... | \|\| | operations.rb:103:1:103:11 | CONSTANT4 | LogicalOrExpr |
232232
| operations.rb:103:13:103:15 | ... \|\| ... | \|\| | operations.rb:103:17:103:17 | 7 | LogicalOrExpr |
233+
| operations.rb:104:1:104:3 | ... = ... | = | operations.rb:104:1:104:3 | FOO | AssignExpr |
234+
| operations.rb:104:1:104:3 | ... = ... | = | operations.rb:104:1:104:3 | call to [] | AssignExpr |
235+
| operations.rb:104:1:104:32 | ... = ... | = | operations.rb:104:1:104:20 | (..., ...) | AssignExpr |
236+
| operations.rb:104:1:104:32 | ... = ... | = | operations.rb:104:24:104:32 | [...] | AssignExpr |
237+
| operations.rb:104:6:104:10 | ... = ... | = | operations.rb:104:6:104:10 | BAR | AssignExpr |
238+
| operations.rb:104:6:104:10 | ... = ... | = | operations.rb:104:6:104:10 | call to [] | AssignExpr |
239+
| operations.rb:104:13:104:20 | ... = ... | = | operations.rb:104:13:104:20 | FOO | AssignExpr |
240+
| operations.rb:104:13:104:20 | ... = ... | = | operations.rb:104:13:104:20 | call to [] | AssignExpr |
241+
| operations.rb:104:24:104:32 | * ... | * | operations.rb:104:24:104:32 | [...] | SplatExpr |
242+
| operations.rb:104:24:104:32 | ... = ... | = | operations.rb:104:24:104:32 | * ... | AssignExpr |
243+
| operations.rb:104:24:104:32 | ... = ... | = | operations.rb:104:24:104:32 | __synth__3 | AssignExpr |

ruby/ql/test/library-tests/ast/operations/operations.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ class X
101101
Foo::MemberConstant ||= 8
102102
foo(1).bar::OtherConstant ||= 7
103103
::CONSTANT4 ||= 7
104+
FOO, ::BAR, foo::FOO = [1, 2, 3]

ruby/ql/test/library-tests/ast/operations/unary.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ unaryOperations
77
| operations.rb:28:1:28:12 | defined? ... | defined? | operations.rb:28:10:28:12 | foo | DefinedExpr |
88
| operations.rb:29:20:29:23 | * ... | * | operations.rb:29:21:29:23 | [...] | SplatExpr |
99
| operations.rb:29:31:29:42 | ** ... | ** | operations.rb:29:33:29:42 | {...} | HashSplatExpr |
10+
| operations.rb:104:24:104:32 | * ... | * | operations.rb:104:24:104:32 | [...] | SplatExpr |
1011
unaryLogicalOperations
1112
| operations.rb:23:1:23:2 | ! ... | ! | operations.rb:23:2:23:2 | a | NotExpr |
1213
| operations.rb:24:1:24:5 | not ... | not | operations.rb:24:5:24:5 | b | NotExpr |

0 commit comments

Comments
 (0)