Skip to content

Commit ea1c7b5

Browse files
committed
Add more operator assignment tests
1 parent 07c059c commit ea1c7b5

8 files changed

Lines changed: 278 additions & 1 deletion

File tree

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,21 @@ calls/calls.rb:
567567
# 319| getReceiver: [Self] self
568568
# 319| getArgument: [IntegerLiteral] 0
569569
# 319| getAnOperand/getRightOperand: [IntegerLiteral] 1
570+
# 320| getStmt: [AssignMulExpr] ... *= ...
571+
# 320| getAnOperand/getLeftOperand: [ElementReference, SetterMethodCall] ...[...]
572+
# 320| getReceiver: [MethodCall] call to bar
573+
# 320| getReceiver: [MethodCall] call to foo
574+
# 320| getReceiver: [Self] self
575+
# 320| getArgument: [IntegerLiteral] 0
576+
# 320| getArgument: [MethodCall] call to baz
577+
# 320| getReceiver: [MethodCall] call to foo
578+
# 320| getReceiver: [Self] self
579+
# 320| getArgument: [AddExpr] ... + ...
580+
# 320| getAnOperand/getLeftOperand: [MethodCall] call to boo
581+
# 320| getReceiver: [MethodCall] call to foo
582+
# 320| getReceiver: [Self] self
583+
# 320| getAnOperand/getRightOperand: [IntegerLiteral] 1
584+
# 320| getAnOperand/getRightOperand: [IntegerLiteral] 2
570585
control/cases.rb:
571586
# 1| [Toplevel] cases.rb
572587
# 2| getStmt: [AssignExpr] ... = ...
@@ -1718,6 +1733,25 @@ operations/operations.rb:
17181733
# 84| getStmt: [AssignBitwiseXorExpr] ... ^= ...
17191734
# 84| getAnOperand/getLeftOperand: [LocalVariableAccess] baz
17201735
# 84| getAnOperand/getRightOperand: [LocalVariableAccess] qux
1736+
# 86| getStmt: [ClassDeclaration] X
1737+
# 87| getStmt: [AssignExpr] ... = ...
1738+
# 87| getAnOperand/getLeftOperand: [InstanceVariableAccess] @x
1739+
# 87| getAnOperand/getRightOperand: [IntegerLiteral] 1
1740+
# 88| getStmt: [AssignAddExpr] ... += ...
1741+
# 88| getAnOperand/getLeftOperand: [InstanceVariableAccess] @x
1742+
# 88| getAnOperand/getRightOperand: [IntegerLiteral] 2
1743+
# 90| getStmt: [AssignExpr] ... = ...
1744+
# 90| getAnOperand/getLeftOperand: [ClassVariableAccess] @@y
1745+
# 90| getAnOperand/getRightOperand: [IntegerLiteral] 3
1746+
# 91| getStmt: [AssignDivExpr] ... /= ...
1747+
# 91| getAnOperand/getLeftOperand: [ClassVariableAccess] @@y
1748+
# 91| getAnOperand/getRightOperand: [IntegerLiteral] 4
1749+
# 94| getStmt: [AssignExpr] ... = ...
1750+
# 94| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var
1751+
# 94| getAnOperand/getRightOperand: [IntegerLiteral] 5
1752+
# 95| getStmt: [AssignMulExpr] ... *= ...
1753+
# 95| getAnOperand/getLeftOperand: [GlobalVariableAccess] $global_var
1754+
# 95| getAnOperand/getRightOperand: [IntegerLiteral] 6
17211755
params/params.rb:
17221756
# 1| [Toplevel] params.rb
17231757
# 4| getStmt: [Method] identifier_method_params

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ callsWithArguments
3636
| calls.rb:317:5:317:10 | ...[...] | []= | 0 | calls.rb:317:9:317:9 | 5 |
3737
| calls.rb:319:1:319:6 | ...[...] | [] | 0 | calls.rb:319:5:319:5 | 0 |
3838
| calls.rb:319:1:319:6 | ...[...] | []= | 0 | calls.rb:319:5:319:5 | 0 |
39+
| calls.rb:320:1:320:32 | ...[...] | [] | 0 | calls.rb:320:9:320:9 | 0 |
40+
| calls.rb:320:1:320:32 | ...[...] | [] | 1 | calls.rb:320:12:320:18 | call to baz |
41+
| calls.rb:320:1:320:32 | ...[...] | [] | 2 | calls.rb:320:21:320:31 | ... + ... |
42+
| calls.rb:320:1:320:32 | ...[...] | []= | 0 | calls.rb:320:9:320:9 | 0 |
43+
| calls.rb:320:1:320:32 | ...[...] | []= | 1 | calls.rb:320:12:320:18 | call to baz |
44+
| calls.rb:320:1:320:32 | ...[...] | []= | 2 | calls.rb:320:21:320:31 | ... + ... |
3945
callsWithReceiver
4046
| calls.rb:2:1:2:5 | call to foo | calls.rb:2:1:2:5 | self |
4147
| calls.rb:5:1:5:10 | call to bar | calls.rb:5:1:5:3 | Foo |
@@ -216,6 +222,13 @@ callsWithReceiver
216222
| calls.rb:318:1:318:10 | call to count/count= | calls.rb:318:1:318:4 | self |
217223
| calls.rb:319:1:319:3 | call to foo | calls.rb:319:1:319:3 | self |
218224
| calls.rb:319:1:319:6 | ...[...] | calls.rb:319:1:319:3 | call to foo |
225+
| calls.rb:320:1:320:3 | call to foo | calls.rb:320:1:320:3 | self |
226+
| calls.rb:320:1:320:7 | call to bar | calls.rb:320:1:320:3 | call to foo |
227+
| calls.rb:320:1:320:32 | ...[...] | calls.rb:320:1:320:7 | call to bar |
228+
| calls.rb:320:12:320:14 | call to foo | calls.rb:320:12:320:14 | self |
229+
| calls.rb:320:12:320:18 | call to baz | calls.rb:320:12:320:14 | call to foo |
230+
| calls.rb:320:21:320:23 | call to foo | calls.rb:320:21:320:23 | self |
231+
| calls.rb:320:21:320:27 | call to boo | calls.rb:320:21:320:23 | call to foo |
219232
callsWithBlock
220233
| calls.rb:17:1:17:17 | call to foo | calls.rb:17:5:17:17 | { ... } |
221234
| calls.rb:20:1:22:3 | call to foo | calls.rb:20:5:22:3 | do ... end |
@@ -262,3 +275,4 @@ setterCalls
262275
| calls.rb:317:5:317:10 | ...[...] |
263276
| calls.rb:318:1:318:10 | call to count/count= |
264277
| calls.rb:319:1:319:6 | ...[...] |
278+
| calls.rb:320:1:320:32 | ...[...] |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,4 @@ def another_method
317317
a, *foo[5] = [1, 2, 3]
318318
self.count += 1
319319
foo[0] += 1
320+
foo.bar[0, foo.baz, foo.boo + 1] *= 2

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ assignments
3030
| operations.rb:82:2:82:12 | ... &= ... | &= | operations.rb:82:2:82:4 | foo | operations.rb:82:9:82:12 | mask | AssignBitwiseAndExpr |
3131
| operations.rb:83:2:83:12 | ... \|= ... | \|= | operations.rb:83:2:83:4 | bar | operations.rb:83:9:83:12 | 0x01 | AssignBitwiseOrExpr |
3232
| operations.rb:84:2:84:11 | ... ^= ... | ^= | operations.rb:84:2:84:4 | baz | operations.rb:84:9:84:11 | qux | AssignBitwiseXorExpr |
33+
| operations.rb:87:3:87:8 | ... = ... | = | operations.rb:87:3:87:4 | @x | operations.rb:87:8:87:8 | 1 | AssignExpr |
34+
| operations.rb:88:3:88:9 | ... += ... | += | operations.rb:88:3:88:4 | @x | operations.rb:88:9:88:9 | 2 | AssignAddExpr |
35+
| operations.rb:90:3:90:9 | ... = ... | = | operations.rb:90:3:90:5 | @@y | operations.rb:90:9:90:9 | 3 | AssignExpr |
36+
| operations.rb:91:3:91:10 | ... /= ... | /= | operations.rb:91:3:91:5 | @@y | operations.rb:91:10:91:10 | 4 | AssignDivExpr |
37+
| operations.rb:94:1:94:15 | ... = ... | = | operations.rb:94:1:94:11 | $global_var | operations.rb:94:15:94:15 | 5 | AssignExpr |
38+
| operations.rb:95:1:95:16 | ... *= ... | *= | operations.rb:95:1:95:11 | $global_var | operations.rb:95:16:95:16 | 6 | AssignMulExpr |
3339
assignOperations
3440
| operations.rb:68:1:68:8 | ... += ... | += | operations.rb:68:1:68:1 | x | operations.rb:68:6:68:8 | 128 | AssignAddExpr |
3541
| operations.rb:69:1:69:7 | ... -= ... | -= | operations.rb:69:1:69:1 | y | operations.rb:69:6:69:7 | 32 | AssignSubExpr |
@@ -44,13 +50,19 @@ assignOperations
4450
| operations.rb:82:2:82:12 | ... &= ... | &= | operations.rb:82:2:82:4 | foo | operations.rb:82:9:82:12 | mask | AssignBitwiseAndExpr |
4551
| operations.rb:83:2:83:12 | ... \|= ... | \|= | operations.rb:83:2:83:4 | bar | operations.rb:83:9:83:12 | 0x01 | AssignBitwiseOrExpr |
4652
| operations.rb:84:2:84:11 | ... ^= ... | ^= | operations.rb:84:2:84:4 | baz | operations.rb:84:9:84:11 | qux | AssignBitwiseXorExpr |
53+
| operations.rb:88:3:88:9 | ... += ... | += | operations.rb:88:3:88:4 | @x | operations.rb:88:9:88:9 | 2 | AssignAddExpr |
54+
| operations.rb:91:3:91:10 | ... /= ... | /= | operations.rb:91:3:91:5 | @@y | operations.rb:91:10:91:10 | 4 | AssignDivExpr |
55+
| operations.rb:95:1:95:16 | ... *= ... | *= | operations.rb:95:1:95:11 | $global_var | operations.rb:95:16:95:16 | 6 | AssignMulExpr |
4756
assignArithmeticOperations
4857
| operations.rb:68:1:68:8 | ... += ... | += | operations.rb:68:1:68:1 | x | operations.rb:68:6:68:8 | 128 | AssignAddExpr |
4958
| operations.rb:69:1:69:7 | ... -= ... | -= | operations.rb:69:1:69:1 | y | operations.rb:69:6:69:7 | 32 | AssignSubExpr |
5059
| operations.rb:70:1:70:7 | ... *= ... | *= | operations.rb:70:1:70:1 | a | operations.rb:70:6:70:7 | 12 | AssignMulExpr |
5160
| operations.rb:71:1:71:6 | ... /= ... | /= | operations.rb:71:1:71:1 | b | operations.rb:71:6:71:6 | 4 | AssignDivExpr |
5261
| operations.rb:72:1:72:6 | ... %= ... | %= | operations.rb:72:1:72:1 | z | operations.rb:72:6:72:6 | 2 | AssignModuloExpr |
5362
| operations.rb:73:1:73:11 | ... **= ... | **= | operations.rb:73:1:73:3 | foo | operations.rb:73:9:73:11 | bar | AssignExponentExpr |
63+
| operations.rb:88:3:88:9 | ... += ... | += | operations.rb:88:3:88:4 | @x | operations.rb:88:9:88:9 | 2 | AssignAddExpr |
64+
| operations.rb:91:3:91:10 | ... /= ... | /= | operations.rb:91:3:91:5 | @@y | operations.rb:91:10:91:10 | 4 | AssignDivExpr |
65+
| operations.rb:95:1:95:16 | ... *= ... | *= | operations.rb:95:1:95:11 | $global_var | operations.rb:95:16:95:16 | 6 | AssignMulExpr |
5466
assignLogicalOperations
5567
| operations.rb:76:2:76:8 | ... &&= ... | &&= | operations.rb:76:2:76:2 | x | operations.rb:76:8:76:8 | y | AssignLogicalAndExpr |
5668
| operations.rb:77:2:77:8 | ... \|\|= ... | \|\|= | operations.rb:77:2:77:2 | a | operations.rb:77:8:77:8 | b | AssignLogicalOrExpr |

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,15 @@
116116
| operations.rb:83:2:83:12 | ... \|= ... | \|= | operations.rb:83:9:83:12 | 0x01 | AssignBitwiseOrExpr |
117117
| operations.rb:84:2:84:11 | ... ^= ... | ^= | operations.rb:84:2:84:4 | baz | AssignBitwiseXorExpr |
118118
| operations.rb:84:2:84:11 | ... ^= ... | ^= | operations.rb:84:9:84:11 | qux | AssignBitwiseXorExpr |
119+
| operations.rb:87:3:87:8 | ... = ... | = | operations.rb:87:3:87:4 | @x | AssignExpr |
120+
| operations.rb:87:3:87:8 | ... = ... | = | operations.rb:87:8:87:8 | 1 | AssignExpr |
121+
| operations.rb:88:3:88:9 | ... += ... | += | operations.rb:88:3:88:4 | @x | AssignAddExpr |
122+
| operations.rb:88:3:88:9 | ... += ... | += | operations.rb:88:9:88:9 | 2 | AssignAddExpr |
123+
| operations.rb:90:3:90:9 | ... = ... | = | operations.rb:90:3:90:5 | @@y | AssignExpr |
124+
| operations.rb:90:3:90:9 | ... = ... | = | operations.rb:90:9:90:9 | 3 | AssignExpr |
125+
| operations.rb:91:3:91:10 | ... /= ... | /= | operations.rb:91:3:91:5 | @@y | AssignDivExpr |
126+
| operations.rb:91:3:91:10 | ... /= ... | /= | operations.rb:91:10:91:10 | 4 | AssignDivExpr |
127+
| operations.rb:94:1:94:15 | ... = ... | = | operations.rb:94:1:94:11 | $global_var | AssignExpr |
128+
| operations.rb:94:1:94:15 | ... = ... | = | operations.rb:94:15:94:15 | 5 | AssignExpr |
129+
| operations.rb:95:1:95:16 | ... *= ... | *= | operations.rb:95:1:95:11 | $global_var | AssignMulExpr |
130+
| operations.rb:95:1:95:16 | ... *= ... | *= | operations.rb:95:16:95:16 | 6 | AssignMulExpr |

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,15 @@
8181
y >>= 3
8282
foo &= mask
8383
bar |= 0x01
84-
baz ^= qux
84+
baz ^= qux
85+
86+
class X
87+
@x = 1
88+
@x += 2
89+
90+
@@y = 3
91+
@@y /= 4
92+
end
93+
94+
$global_var = 5
95+
$global_var *= 6

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

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,6 +2083,177 @@ cfg.rb:
20832083
# 194| x
20842084
#-----| -> call to puts
20852085

2086+
desugar.rb:
2087+
# 1| enter m1
2088+
#-----| -> x
2089+
2090+
# 1| enter desugar.rb
2091+
#-----| -> m1
2092+
2093+
# 1| m1
2094+
#-----| -> m2
2095+
2096+
# 1| exit m1
2097+
2098+
# 1| exit desugar.rb
2099+
2100+
# 1| exit m1 (normal)
2101+
#-----| -> exit m1
2102+
2103+
# 1| exit desugar.rb (normal)
2104+
#-----| -> exit desugar.rb
2105+
2106+
# 1| x
2107+
#-----| -> x
2108+
2109+
# 2| ... += ...
2110+
#-----| -> exit m1 (normal)
2111+
2112+
# 2| x
2113+
#-----| -> 1
2114+
2115+
# 2| 1
2116+
#-----| -> ... += ...
2117+
2118+
# 5| enter m2
2119+
#-----| -> x
2120+
2121+
# 5| m2
2122+
#-----| -> m3
2123+
2124+
# 5| exit m2
2125+
2126+
# 5| exit m2 (normal)
2127+
#-----| -> exit m2
2128+
2129+
# 5| x
2130+
#-----| -> x
2131+
2132+
# 6| ... += ...
2133+
#-----| -> exit m2 (normal)
2134+
2135+
# 6| call to count/count=
2136+
#-----| -> 1
2137+
2138+
# 6| call to foo
2139+
#-----| -> call to count/count=
2140+
2141+
# 6| x
2142+
#-----| -> call to foo
2143+
2144+
# 6| 1
2145+
#-----| -> ... += ...
2146+
2147+
# 9| enter m3
2148+
#-----| -> x
2149+
2150+
# 9| m3
2151+
#-----| -> X
2152+
2153+
# 9| exit m3
2154+
2155+
# 9| exit m3 (normal)
2156+
#-----| -> exit m3
2157+
2158+
# 9| x
2159+
#-----| -> y
2160+
2161+
# 9| y
2162+
#-----| -> x
2163+
2164+
# 10| ... += ...
2165+
#-----| -> exit m3 (normal)
2166+
2167+
# 10| ...[...]
2168+
#-----| -> 1
2169+
2170+
# 10| call to foo
2171+
#-----| -> 0
2172+
2173+
# 10| x
2174+
#-----| -> call to foo
2175+
2176+
# 10| 0
2177+
#-----| -> y
2178+
2179+
# 10| call to bar
2180+
#-----| -> x
2181+
2182+
# 10| y
2183+
#-----| -> call to bar
2184+
2185+
# 10| ... + ...
2186+
#-----| -> ...[...]
2187+
2188+
# 10| call to baz
2189+
#-----| -> 3
2190+
2191+
# 10| x
2192+
#-----| -> call to baz
2193+
2194+
# 10| 3
2195+
#-----| -> ... + ...
2196+
2197+
# 10| 1
2198+
#-----| -> ... += ...
2199+
2200+
# 13| X
2201+
#-----| -> @x
2202+
2203+
# 14| ... = ...
2204+
#-----| -> @x
2205+
2206+
# 14| @x
2207+
#-----| -> 1
2208+
2209+
# 14| 1
2210+
#-----| -> ... = ...
2211+
2212+
# 15| ... += ...
2213+
#-----| -> @@y
2214+
2215+
# 15| @x
2216+
#-----| -> 2
2217+
2218+
# 15| 2
2219+
#-----| -> ... += ...
2220+
2221+
# 17| ... = ...
2222+
#-----| -> @@y
2223+
2224+
# 17| @@y
2225+
#-----| -> 3
2226+
2227+
# 17| 3
2228+
#-----| -> ... = ...
2229+
2230+
# 18| ... /= ...
2231+
#-----| -> $global_var
2232+
2233+
# 18| @@y
2234+
#-----| -> 4
2235+
2236+
# 18| 4
2237+
#-----| -> ... /= ...
2238+
2239+
# 21| ... = ...
2240+
#-----| -> $global_var
2241+
2242+
# 21| $global_var
2243+
#-----| -> 5
2244+
2245+
# 21| 5
2246+
#-----| -> ... = ...
2247+
2248+
# 22| ... *= ...
2249+
#-----| -> exit desugar.rb (normal)
2250+
2251+
# 22| $global_var
2252+
#-----| -> 6
2253+
2254+
# 22| 6
2255+
#-----| -> ... *= ...
2256+
20862257
exit.rb:
20872258
# 1| enter m1
20882259
#-----| -> x
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def m1 x
2+
x += 1
3+
end
4+
5+
def m2 x
6+
x.foo.count += 1
7+
end
8+
9+
def m3 x, y
10+
x.foo[0, y.bar, x.baz + 3] += 1
11+
end
12+
13+
class X
14+
@x = 1
15+
@x += 2
16+
17+
@@y = 3
18+
@@y /= 4
19+
end
20+
21+
$global_var = 5
22+
$global_var *= 6

0 commit comments

Comments
 (0)