Skip to content

Commit dbd9c18

Browse files
committed
Add more test cases for &. operator
1 parent 76f8061 commit dbd9c18

File tree

9 files changed

+143
-1
lines changed

9 files changed

+143
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,15 @@ calls/calls.rb:
748748
# 363| getStmt: [MethodCall] call to empty?
749749
# 363| getReceiver: [MethodCall] call to list
750750
# 363| getReceiver: [SelfVariableAccess] self
751+
# 364| getStmt: [MethodCall] call to bar
752+
# 364| getReceiver: [MethodCall] call to foo
753+
# 364| getReceiver: [SelfVariableAccess] self
754+
# 364| getArgument: [IntegerLiteral] 1
755+
# 364| getArgument: [IntegerLiteral] 2
756+
# 364| getBlock: [BraceBlock] { ... }
757+
# 364| getParameter: [SimpleParameter] x
758+
# 364| getDefiningAccess: [LocalVariableAccess] x
759+
# 364| getStmt: [LocalVariableAccess] x
751760
control/cases.rb:
752761
# 1| [Toplevel] cases.rb
753762
# 2| getStmt: [AssignExpr] ... = ...

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,25 @@ calls/calls.rb:
292292
# 362| getCondition: [MethodCall] call to ==
293293
# 362| getArgument: [LocalVariableAccess] __synth__0__1
294294
# 362| getReceiver: [NilLiteral] nil
295+
# 364| [MethodCall] call to bar
296+
# 364| getDesugared: [StmtSequence] ...
297+
# 364| getStmt: [AssignExpr] ... = ...
298+
# 364| getAnOperand/getRightOperand: [MethodCall] call to foo
299+
# 364| getReceiver: [SelfVariableAccess] self
300+
# 364| getAnOperand/getLeftOperand: [LocalVariableAccess] __synth__0__1
301+
# 364| getStmt: [IfExpr] if ...
302+
# 364| getBranch/getElse: [MethodCall] call to bar
303+
# 364| getReceiver: [LocalVariableAccess] __synth__0__1
304+
# 364| getArgument: [IntegerLiteral] 1
305+
# 364| getArgument: [IntegerLiteral] 2
306+
# 364| getBlock: [BraceBlock] { ... }
307+
# 364| getParameter: [SimpleParameter] x
308+
# 364| getDefiningAccess: [LocalVariableAccess] x
309+
# 364| getStmt: [LocalVariableAccess] x
310+
# 364| getBranch/getThen: [NilLiteral] nil
311+
# 364| getCondition: [MethodCall] call to ==
312+
# 364| getArgument: [LocalVariableAccess] __synth__0__1
313+
# 364| getReceiver: [NilLiteral] nil
295314
control/cases.rb:
296315
# 90| [ArrayLiteral] %w(...)
297316
# 90| getDesugared: [MethodCall] call to []

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,24 @@ calls/calls.rb:
12811281
# 363| 0: [Identifier] list
12821282
# 363| 1: [ReservedWord] ::
12831283
# 363| 2: [Identifier] empty?
1284+
# 364| 120: [Call] Call
1285+
# 364| 0: [Identifier] foo
1286+
# 364| 1: [ReservedWord] &.
1287+
# 364| 2: [Identifier] bar
1288+
# 364| 3: [ArgumentList] ArgumentList
1289+
# 364| 0: [ReservedWord] (
1290+
# 364| 1: [Integer] 1
1291+
# 364| 2: [ReservedWord] ,
1292+
# 364| 3: [Integer] 2
1293+
# 364| 4: [ReservedWord] )
1294+
# 364| 4: [Block] Block
1295+
# 364| 0: [ReservedWord] {
1296+
# 364| 1: [BlockParameters] BlockParameters
1297+
# 364| 0: [ReservedWord] |
1298+
# 364| 1: [Identifier] x
1299+
# 364| 2: [ReservedWord] |
1300+
# 364| 2: [Identifier] x
1301+
# 364| 3: [ReservedWord] }
12841302
# 1| [Comment] # call with no receiver, arguments, or block
12851303
# 4| [Comment] # call whose name is a scope resolution
12861304
# 7| [Comment] # call whose name is a global scope resolution

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ exprValue
7676
| calls/calls.rb:350:5:350:5 | 1 | 1 | int |
7777
| calls/calls.rb:362:1:362:4 | nil | nil | nil |
7878
| calls/calls.rb:362:5:362:6 | nil | nil | nil |
79+
| calls/calls.rb:364:1:364:3 | nil | nil | nil |
80+
| calls/calls.rb:364:4:364:5 | nil | nil | nil |
81+
| calls/calls.rb:364:10:364:10 | 1 | 1 | int |
82+
| calls/calls.rb:364:12:364:12 | 2 | 2 | int |
7983
| constants/constants.rb:3:19:3:27 | "const_a" | const_a | string |
8084
| constants/constants.rb:6:15:6:23 | "const_b" | const_b | string |
8185
| constants/constants.rb:17:12:17:18 | "Hello" | Hello | string |
@@ -967,6 +971,10 @@ exprCfgNodeValue
967971
| calls/calls.rb:350:5:350:5 | 1 | 1 | int |
968972
| calls/calls.rb:362:1:362:4 | nil | nil | nil |
969973
| calls/calls.rb:362:5:362:6 | nil | nil | nil |
974+
| calls/calls.rb:364:1:364:3 | nil | nil | nil |
975+
| calls/calls.rb:364:4:364:5 | nil | nil | nil |
976+
| calls/calls.rb:364:10:364:10 | 1 | 1 | int |
977+
| calls/calls.rb:364:12:364:12 | 2 | 2 | int |
970978
| constants/constants.rb:3:19:3:27 | "const_a" | const_a | string |
971979
| constants/constants.rb:6:15:6:23 | "const_b" | const_b | string |
972980
| constants/constants.rb:17:12:17:18 | "Hello" | Hello | string |

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ callsWithArguments
115115
| calls.rb:347:1:347:7 | call to foo | foo | 0 | calls.rb:347:5:347:6 | Pair |
116116
| calls.rb:352:13:352:17 | call to foo | foo | 0 | calls.rb:352:17:352:17 | x |
117117
| calls.rb:362:5:362:6 | call to == | == | 0 | calls.rb:362:1:362:4 | __synth__0__1 |
118+
| calls.rb:364:1:364:23 | call to bar | bar | 0 | calls.rb:364:10:364:10 | 1 |
119+
| calls.rb:364:1:364:23 | call to bar | bar | 0 | calls.rb:364:10:364:10 | 1 |
120+
| calls.rb:364:1:364:23 | call to bar | bar | 1 | calls.rb:364:12:364:12 | 2 |
121+
| calls.rb:364:1:364:23 | call to bar | bar | 1 | calls.rb:364:12:364:12 | 2 |
122+
| calls.rb:364:4:364:5 | call to == | == | 0 | calls.rb:364:1:364:3 | __synth__0__1 |
118123
callsWithReceiver
119124
| calls.rb:2:1:2:5 | call to foo | calls.rb:2:1:2:5 | self |
120125
| calls.rb:5:1:5:10 | call to bar | calls.rb:5:1:5:3 | Foo |
@@ -381,6 +386,10 @@ callsWithReceiver
381386
| calls.rb:362:5:362:6 | call to == | calls.rb:362:5:362:6 | nil |
382387
| calls.rb:363:1:363:4 | call to list | calls.rb:363:1:363:4 | self |
383388
| calls.rb:363:1:363:12 | call to empty? | calls.rb:363:1:363:4 | call to list |
389+
| calls.rb:364:1:364:3 | call to foo | calls.rb:364:1:364:3 | self |
390+
| calls.rb:364:1:364:23 | call to bar | calls.rb:364:1:364:3 | __synth__0__1 |
391+
| calls.rb:364:1:364:23 | call to bar | calls.rb:364:1:364:3 | call to foo |
392+
| calls.rb:364:4:364:5 | call to == | calls.rb:364:4:364:5 | nil |
384393
callsWithBlock
385394
| calls.rb:17:1:17:17 | call to foo | calls.rb:17:5:17:17 | { ... } |
386395
| calls.rb:20:1:22:3 | call to foo | calls.rb:20:5:22:3 | do ... end |
@@ -394,6 +403,8 @@ callsWithBlock
394403
| calls.rb:292:5:292:30 | call to super | calls.rb:292:16:292:30 | { ... } |
395404
| calls.rb:293:5:293:33 | call to super | calls.rb:293:16:293:33 | do ... end |
396405
| calls.rb:340:1:342:3 | call to each | calls.rb:340:1:342:3 | { ... } |
406+
| calls.rb:364:1:364:23 | call to bar | calls.rb:364:15:364:23 | { ... } |
407+
| calls.rb:364:1:364:23 | call to bar | calls.rb:364:15:364:23 | { ... } |
397408
yieldCalls
398409
| calls.rb:31:3:31:7 | yield ... |
399410
| calls.rb:36:3:36:16 | yield ... |
@@ -435,3 +446,4 @@ setterCalls
435446
| calls.rb:320:1:320:32 | call to []= |
436447
callsWithSafeNavigationOperator
437448
| calls.rb:362:1:362:12 | call to empty? |
449+
| calls.rb:364:1:364:23 | call to bar |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,3 +361,4 @@ def foo(a, b, ...)
361361
list.empty?
362362
list&.empty?
363363
list::empty?
364+
foo&.bar(1,2) { |x| x }

ruby/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3593,7 +3593,8 @@ cfg.rb:
35933593
#-----| -> do ... end
35943594

35953595
# 202| call to times
3596-
#-----| -> exit cfg.rb (normal)
3596+
#-----| -> self
3597+
#-----| -> __synth__0__1
35973598

35983599
# 202| do ... end
35993600
#-----| -> call to times
@@ -3621,6 +3622,71 @@ cfg.rb:
36213622
# 202| c
36223623
#-----| -> call to puts
36233624

3625+
# 205| ... = ...
3626+
#-----| -> nil
3627+
3628+
# 205| __synth__0__1
3629+
#-----| -> self
3630+
3631+
# 205| __synth__0__1
3632+
#-----| -> call to ==
3633+
3634+
# 205| __synth__0__1
3635+
#-----| -> 1
3636+
3637+
# 205| call to foo
3638+
#-----| -> ... = ...
3639+
#-----| -> 1
3640+
3641+
# 205| nil
3642+
#-----| -> if ...
3643+
3644+
# 205| self
3645+
#-----| -> call to foo
3646+
3647+
# 205| ...
3648+
#-----| -> exit cfg.rb (normal)
3649+
3650+
# 205| call to bar
3651+
#-----| -> exit cfg.rb (normal)
3652+
3653+
# 205| call to bar
3654+
#-----| -> if ...
3655+
3656+
# 205| call to ==
3657+
#-----| false -> __synth__0__1
3658+
#-----| true -> nil
3659+
3660+
# 205| if ...
3661+
#-----| -> ...
3662+
3663+
# 205| nil
3664+
#-----| -> __synth__0__1
3665+
3666+
# 205| 1
3667+
#-----| -> 2
3668+
3669+
# 205| 2
3670+
#-----| -> { ... }
3671+
3672+
# 205| enter { ... }
3673+
#-----| -> x
3674+
3675+
# 205| exit { ... }
3676+
3677+
# 205| exit { ... } (normal)
3678+
#-----| -> exit { ... }
3679+
3680+
# 205| { ... }
3681+
#-----| -> call to bar
3682+
#-----| -> call to bar
3683+
3684+
# 205| x
3685+
#-----| -> x
3686+
3687+
# 205| x
3688+
#-----| -> exit { ... } (normal)
3689+
36243690
desugar.rb:
36253691
# 1| enter m1
36263692
#-----| -> x

ruby/ql/test/library-tests/controlflow/graph/Nodes.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ callsWithNoArguments
4141
| cfg.rb:194:1:194:23 | call to run_block |
4242
| cfg.rb:200:1:200:32 | call to times |
4343
| cfg.rb:202:1:202:35 | call to times |
44+
| cfg.rb:205:1:205:3 | call to foo |
4445
| desugar.rb:6:3:6:7 | call to foo |
4546
| desugar.rb:10:3:10:7 | call to foo |
4647
| desugar.rb:14:3:14:7 | call to foo |
@@ -203,6 +204,11 @@ positionalArguments
203204
| cfg.rb:197:3:197:13 | call to bar | cfg.rb:197:10:197:12 | ... |
204205
| cfg.rb:200:18:200:30 | call to puts | cfg.rb:200:30:200:30 | a |
205206
| cfg.rb:202:19:202:31 | call to puts | cfg.rb:202:31:202:31 | c |
207+
| cfg.rb:205:1:205:23 | call to bar | cfg.rb:205:10:205:10 | 1 |
208+
| cfg.rb:205:1:205:23 | call to bar | cfg.rb:205:10:205:10 | 1 |
209+
| cfg.rb:205:1:205:23 | call to bar | cfg.rb:205:12:205:12 | 2 |
210+
| cfg.rb:205:1:205:23 | call to bar | cfg.rb:205:12:205:12 | 2 |
211+
| cfg.rb:205:4:205:5 | call to == | cfg.rb:205:1:205:3 | __synth__0__1 |
206212
| desugar.rb:2:5:2:6 | ... + ... | desugar.rb:2:8:2:8 | 1 |
207213
| desugar.rb:6:3:6:13 | call to count= | desugar.rb:6:17:6:17 | ... = ... |
208214
| desugar.rb:10:3:10:10 | call to []= | desugar.rb:10:9:10:9 | 0 |

ruby/ql/test/library-tests/controlflow/graph/cfg.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ def forward_param(a, b, ...)
201201

202202
2.times do |c; d| Kernel.puts c end
203203

204+
# A call with a safe navigation operator
205+
foo&.bar(1,2) { |x| x }
206+
204207
__END__
205208

206209
Some ignored nonsense

0 commit comments

Comments
 (0)