Skip to content

Commit d26b089

Browse files
committed
Ruby: also add an AST test
1 parent 038bdec commit d26b089

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,6 +2833,26 @@ operations/operations.rb:
28332833
# 96| getStmt: [AssignMulExpr] ... *= ...
28342834
# 96| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var
28352835
# 96| getAnOperand/getRightOperand: [IntegerLiteral] 6
2836+
# 98| getStmt: [AssignExpr] ... = ...
2837+
# 98| getAnOperand/getLeftOperand: [ConstantAssignment] CONSTANT1
2838+
# 98| getAnOperand/getRightOperand: [IntegerLiteral] 5
2839+
# 99| getStmt: [AssignAddExpr] ... += ...
2840+
# 99| getAnOperand/getLeftOperand: [ConstantAssignment, ConstantReadAccess] CONSTANT2
2841+
# 99| getAnOperand/getRightOperand: [IntegerLiteral] 6
2842+
# 100| getStmt: [AssignLogicalOrExpr] ... ||= ...
2843+
# 100| getAnOperand/getLeftOperand: [ConstantAssignment, ConstantReadAccess] CONSTANT3
2844+
# 100| getAnOperand/getRightOperand: [IntegerLiteral] 7
2845+
# 101| getStmt: [AssignLogicalOrExpr] ... ||= ...
2846+
# 101| getAnOperand/getLeftOperand: [ConstantAssignment, ConstantReadAccess] MemberConstant
2847+
# 101| getScopeExpr: [ConstantReadAccess] Foo
2848+
# 101| getAnOperand/getRightOperand: [IntegerLiteral] 8
2849+
# 102| getStmt: [AssignLogicalOrExpr] ... ||= ...
2850+
# 102| getAnOperand/getLeftOperand: [ConstantAssignment, ConstantReadAccess] OtherConstant
2851+
# 102| getScopeExpr: [MethodCall] call to bar
2852+
# 102| getReceiver: [MethodCall] call to foo
2853+
# 102| getReceiver: [SelfVariableAccess] self
2854+
# 102| getArgument: [IntegerLiteral] 1
2855+
# 102| getAnOperand/getRightOperand: [IntegerLiteral] 7
28362856
params/params.rb:
28372857
# 1| [Toplevel] params.rb
28382858
# 4| getStmt: [Method] identifier_method_params

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5537,6 +5537,40 @@ operations/operations.rb:
55375537
# 96| 0: [GlobalVariable] $global_var
55385538
# 96| 1: [ReservedWord] *=
55395539
# 96| 2: [Integer] 6
5540+
# 98| 66: [Assignment] Assignment
5541+
# 98| 0: [Constant] CONSTANT1
5542+
# 98| 1: [ReservedWord] =
5543+
# 98| 2: [Integer] 5
5544+
# 99| 67: [OperatorAssignment] OperatorAssignment
5545+
# 99| 0: [Constant] CONSTANT2
5546+
# 99| 1: [ReservedWord] +=
5547+
# 99| 2: [Integer] 6
5548+
# 100| 68: [OperatorAssignment] OperatorAssignment
5549+
# 100| 0: [Constant] CONSTANT3
5550+
# 100| 1: [ReservedWord] ||=
5551+
# 100| 2: [Integer] 7
5552+
# 101| 69: [OperatorAssignment] OperatorAssignment
5553+
# 101| 0: [ScopeResolution] ScopeResolution
5554+
# 101| 0: [Constant] Foo
5555+
# 101| 1: [ReservedWord] ::
5556+
# 101| 2: [Constant] MemberConstant
5557+
# 101| 1: [ReservedWord] ||=
5558+
# 101| 2: [Integer] 8
5559+
# 102| 70: [OperatorAssignment] OperatorAssignment
5560+
# 102| 0: [ScopeResolution] ScopeResolution
5561+
# 102| 0: [Call] Call
5562+
# 102| 0: [Call] Call
5563+
# 102| 0: [Identifier] foo
5564+
# 102| 1: [ArgumentList] ArgumentList
5565+
# 102| 0: [ReservedWord] (
5566+
# 102| 1: [Integer] 1
5567+
# 102| 2: [ReservedWord] )
5568+
# 102| 1: [ReservedWord] .
5569+
# 102| 2: [Identifier] bar
5570+
# 102| 1: [ReservedWord] ::
5571+
# 102| 2: [Constant] OtherConstant
5572+
# 102| 1: [ReservedWord] ||=
5573+
# 102| 2: [Integer] 7
55405574
# 1| [Comment] # Start with assignments to all the identifiers used below, so that they are
55415575
# 2| [Comment] # interpreted as variables.
55425576
# 22| [Comment] # Unary operations

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,12 @@ exprValue
888888
| operations/operations.rb:92:10:92:10 | 4 | 4 | int |
889889
| operations/operations.rb:95:15:95:15 | 5 | 5 | int |
890890
| operations/operations.rb:96:16:96:16 | 6 | 6 | int |
891+
| operations/operations.rb:98:13:98:13 | 5 | 5 | int |
892+
| operations/operations.rb:99:14:99:14 | 6 | 6 | int |
893+
| operations/operations.rb:100:15:100:15 | 7 | 7 | int |
894+
| operations/operations.rb:101:25:101:25 | 8 | 8 | int |
895+
| operations/operations.rb:102:5:102:5 | 1 | 1 | int |
896+
| operations/operations.rb:102:31:102:31 | 7 | 7 | int |
891897
| params/params.rb:41:46:41:46 | 7 | 7 | int |
892898
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
893899
| params/params.rb:47:24:47:24 | 2 | 2 | int |
@@ -1764,6 +1770,7 @@ exprCfgNodeValue
17641770
| operations/operations.rb:92:10:92:10 | 4 | 4 | int |
17651771
| operations/operations.rb:95:15:95:15 | 5 | 5 | int |
17661772
| operations/operations.rb:96:16:96:16 | 6 | 6 | int |
1773+
| operations/operations.rb:98:13:98:13 | 5 | 5 | int |
17671774
| params/params.rb:41:46:41:46 | 7 | 7 | int |
17681775
| params/params.rb:47:19:47:21 | :bar | :bar | symbol |
17691776
| params/params.rb:47:24:47:24 | 2 | 2 | int |

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ assignments
5252
| operations.rb:95:1:95:15 | ... = ... | = | operations.rb:95:1:95:11 | $global_var | operations.rb:95:15:95:15 | 5 | AssignExpr |
5353
| operations.rb:96:1:96:16 | ... *= ... | *= | operations.rb:96:1:96:11 | $global_var | operations.rb:96:16:96:16 | 6 | AssignMulExpr |
5454
| operations.rb:96:1:96:16 | ... = ... | = | operations.rb:96:1:96:11 | $global_var | operations.rb:96:13:96:14 | ... * ... | AssignExpr |
55+
| operations.rb:98:1:98:13 | ... = ... | = | operations.rb:98:1:98:9 | CONSTANT1 | operations.rb:98:13:98:13 | 5 | AssignExpr |
56+
| operations.rb:99:1:99:14 | ... += ... | += | operations.rb:99:1:99:9 | CONSTANT2 | operations.rb:99:14:99:14 | 6 | AssignAddExpr |
57+
| operations.rb:100:1:100:15 | ... \|\|= ... | \|\|= | operations.rb:100:1:100:9 | CONSTANT3 | operations.rb:100:15:100:15 | 7 | AssignLogicalOrExpr |
58+
| operations.rb:101:1:101:25 | ... \|\|= ... | \|\|= | operations.rb:101:1:101:19 | MemberConstant | operations.rb:101:25:101:25 | 8 | AssignLogicalOrExpr |
59+
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:1:102:25 | OtherConstant | operations.rb:102:31:102:31 | 7 | AssignLogicalOrExpr |
5560
assignOperations
5661
| operations.rb:69:1:69:8 | ... += ... | += | operations.rb:69:1:69:1 | x | operations.rb:69:6:69:8 | 128 | AssignAddExpr |
5762
| operations.rb:70:1:70:7 | ... -= ... | -= | operations.rb:70:1:70:1 | y | operations.rb:70:6:70:7 | 32 | AssignSubExpr |
@@ -69,6 +74,10 @@ assignOperations
6974
| operations.rb:89:3:89:9 | ... += ... | += | operations.rb:89:3:89:4 | @x | operations.rb:89:9:89:9 | 2 | AssignAddExpr |
7075
| operations.rb:92:3:92:10 | ... /= ... | /= | operations.rb:92:3:92:5 | @@y | operations.rb:92:10:92:10 | 4 | AssignDivExpr |
7176
| operations.rb:96:1:96:16 | ... *= ... | *= | operations.rb:96:1:96:11 | $global_var | operations.rb:96:16:96:16 | 6 | AssignMulExpr |
77+
| operations.rb:99:1:99:14 | ... += ... | += | operations.rb:99:1:99:9 | CONSTANT2 | operations.rb:99:14:99:14 | 6 | AssignAddExpr |
78+
| operations.rb:100:1:100:15 | ... \|\|= ... | \|\|= | operations.rb:100:1:100:9 | CONSTANT3 | operations.rb:100:15:100:15 | 7 | AssignLogicalOrExpr |
79+
| operations.rb:101:1:101:25 | ... \|\|= ... | \|\|= | operations.rb:101:1:101:19 | MemberConstant | operations.rb:101:25:101:25 | 8 | AssignLogicalOrExpr |
80+
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:1:102:25 | OtherConstant | operations.rb:102:31:102:31 | 7 | AssignLogicalOrExpr |
7281
assignArithmeticOperations
7382
| operations.rb:69:1:69:8 | ... += ... | += | operations.rb:69:1:69:1 | x | operations.rb:69:6:69:8 | 128 | AssignAddExpr |
7483
| operations.rb:70:1:70:7 | ... -= ... | -= | operations.rb:70:1:70:1 | y | operations.rb:70:6:70:7 | 32 | AssignSubExpr |
@@ -79,9 +88,13 @@ assignArithmeticOperations
7988
| operations.rb:89:3:89:9 | ... += ... | += | operations.rb:89:3:89:4 | @x | operations.rb:89:9:89:9 | 2 | AssignAddExpr |
8089
| operations.rb:92:3:92:10 | ... /= ... | /= | operations.rb:92:3:92:5 | @@y | operations.rb:92:10:92:10 | 4 | AssignDivExpr |
8190
| operations.rb:96:1:96:16 | ... *= ... | *= | operations.rb:96:1:96:11 | $global_var | operations.rb:96:16:96:16 | 6 | AssignMulExpr |
91+
| operations.rb:99:1:99:14 | ... += ... | += | operations.rb:99:1:99:9 | CONSTANT2 | operations.rb:99:14:99:14 | 6 | AssignAddExpr |
8292
assignLogicalOperations
8393
| operations.rb:77:2:77:8 | ... &&= ... | &&= | operations.rb:77:2:77:2 | x | operations.rb:77:8:77:8 | y | AssignLogicalAndExpr |
8494
| operations.rb:78:2:78:8 | ... \|\|= ... | \|\|= | operations.rb:78:2:78:2 | a | operations.rb:78:8:78:8 | b | AssignLogicalOrExpr |
95+
| operations.rb:100:1:100:15 | ... \|\|= ... | \|\|= | operations.rb:100:1:100:9 | CONSTANT3 | operations.rb:100:15:100:15 | 7 | AssignLogicalOrExpr |
96+
| operations.rb:101:1:101:25 | ... \|\|= ... | \|\|= | operations.rb:101:1:101:19 | MemberConstant | operations.rb:101:25:101:25 | 8 | AssignLogicalOrExpr |
97+
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:1:102:25 | OtherConstant | operations.rb:102:31:102:31 | 7 | AssignLogicalOrExpr |
8598
assignBitwiseOperations
8699
| operations.rb:81:2:81:8 | ... <<= ... | <<= | operations.rb:81:2:81:2 | x | operations.rb:81:8:81:8 | 2 | AssignLShiftExpr |
87100
| operations.rb:82:2:82:8 | ... >>= ... | >>= | operations.rb:82:2:82:2 | y | operations.rb:82:8:82:8 | 3 | AssignRShiftExpr |

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,13 @@
194194
| operations.rb:96:1:96:16 | ... = ... | = | operations.rb:96:13:96:14 | ... * ... | AssignExpr |
195195
| operations.rb:96:13:96:14 | ... * ... | * | operations.rb:96:1:96:11 | $global_var | MulExpr |
196196
| operations.rb:96:13:96:14 | ... * ... | * | operations.rb:96:16:96:16 | 6 | MulExpr |
197+
| operations.rb:98:1:98:13 | ... = ... | = | operations.rb:98:1:98:9 | CONSTANT1 | AssignExpr |
198+
| operations.rb:98:1:98:13 | ... = ... | = | operations.rb:98:13:98:13 | 5 | AssignExpr |
199+
| operations.rb:99:1:99:14 | ... += ... | += | operations.rb:99:1:99:9 | CONSTANT2 | AssignAddExpr |
200+
| operations.rb:99:1:99:14 | ... += ... | += | operations.rb:99:14:99:14 | 6 | AssignAddExpr |
201+
| operations.rb:100:1:100:15 | ... \|\|= ... | \|\|= | operations.rb:100:1:100:9 | CONSTANT3 | AssignLogicalOrExpr |
202+
| operations.rb:100:1:100:15 | ... \|\|= ... | \|\|= | operations.rb:100:15:100:15 | 7 | AssignLogicalOrExpr |
203+
| operations.rb:101:1:101:25 | ... \|\|= ... | \|\|= | operations.rb:101:1:101:19 | MemberConstant | AssignLogicalOrExpr |
204+
| operations.rb:101:1:101:25 | ... \|\|= ... | \|\|= | operations.rb:101:25:101:25 | 8 | AssignLogicalOrExpr |
205+
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:1:102:25 | OtherConstant | AssignLogicalOrExpr |
206+
| operations.rb:102:1:102:31 | ... \|\|= ... | \|\|= | operations.rb:102:31:102:31 | 7 | AssignLogicalOrExpr |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,9 @@ class X
9494

9595
$global_var = 5
9696
$global_var *= 6
97+
98+
CONSTANT1 = 5
99+
CONSTANT2 += 6
100+
CONSTANT3 ||= 7
101+
Foo::MemberConstant ||= 8
102+
foo(1).bar::OtherConstant ||= 7

0 commit comments

Comments
 (0)