Skip to content

Commit 429c757

Browse files
committed
Add astcompile tests for compound assignment (AugAssign, AugSetItem, AugSetAttr)
1 parent 53136b5 commit 429c757

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

spy/tests/test_astcompile.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,41 @@ def foo() -> i32:
177177
return x
178178
"""
179179
self.assert_dump_decls(expected)
180+
181+
def test_augassign(self):
182+
self.compile_src("""
183+
def foo(x: i32) -> i32:
184+
x += 1
185+
return x
186+
""")
187+
expected = """
188+
def foo(x: i32) -> i32:
189+
x = x + 1
190+
return x
191+
"""
192+
self.assert_dump(expected)
193+
194+
def test_augsetitem(self):
195+
self.compile_src("""
196+
def foo(items: dynamic, idx: i32, val: i32) -> None:
197+
items[idx] += val
198+
""")
199+
expected = """
200+
def foo(items: dynamic, idx: i32, val: i32) -> None:
201+
_$aug_target0 = items
202+
_$aug_arg0_0 = idx
203+
_$aug_target0[_$aug_arg0_0] = _$aug_target0[_$aug_arg0_0] + val
204+
"""
205+
self.assert_dump(expected)
206+
207+
def test_augsetattr(self):
208+
self.compile_src("""
209+
def foo(obj: dynamic, val: i32) -> None:
210+
obj.x += val
211+
""")
212+
expected = """
213+
def foo(obj: dynamic, val: i32) -> None:
214+
_$aug_target0 = obj
215+
_$aug_target0.x = _$aug_target0.x + val
216+
"""
217+
self.assert_dump(expected)

spy/tests/test_cli.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,6 @@ def main() -> None:
145145
assert "while " in stdout
146146
assert stdout.startswith("def main() -> None:")
147147

148-
def test_astcompile_spy_output_augsetitem(self):
149-
src = """
150-
def main() -> None:
151-
items = make_items()
152-
items[index()] += value()
153-
"""
154-
f = self.write("test.spy", src)
155-
_, stdout = self.run("astcompile", "--format", "spy", f)
156-
assert "+=" not in stdout
157-
assert "_$aug_target0" in stdout
158-
assert "_$aug_arg0_0" in stdout
159-
160148
def test_execute(self):
161149
argsets = [["execute"], []] # No subcommand is equivalent to execute command
162150
for argset in argsets:

0 commit comments

Comments
 (0)