8000 add tests · python/cpython@eb99870 · GitHub
[go: up one dir, main page]

Skip to content

Commit eb99870

Browse files
committed
add tests
1 parent bb60d4c commit eb99870

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

Lib/test/test_peepholer.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,44 @@ def test_optimize_unary_not(self):
18591859
self.cfg_optimization_test(before, after, consts=[], expected_consts=[])
18601860

18611861
def test_optimize_if_const_unaryop(self):
1862-
pass
1862+
# test unary negative
1863+
before = [
1864+
('LOAD_SMALL_INT', 2, 0),
1865+
('UNARY_NEGATIVE', None, 0),
1866+
('UNARY_NEGATIVE', None, 0),
1867+
('RETURN_VALUE', None, 0)
1868+
]
1869+
after = [
1870+
('LOAD_SMALL_INT', 2, 0),
1871+
('RETURN_VALUE', None, 0),
1872+
]
1873+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[-2])
1874+
1875+
# test unary invert
1876+
before = [
1877+
('LOAD_SMALL_INT', 2, 0),
1878+
('UNARY_INVERT', None, 0),
1879+
('UNARY_INVERT', None, 0),
1880+
('RETURN_VALUE', None, 0)
1881+
]
1882+
after = [
1883+
('LOAD_SMALL_INT', 2, 0),
1884+
('RETURN_VALUE', None, 0),
1885+
]
1886+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[-3])
1887+
1888+
# test unary positive
1889+
before = [
1890+
('LOAD_SMALL_INT', 2, 0),
1891+
('CALL_INTRINSIC_1', 5, 0),
1892+
('CALL_INTRINSIC_1', 5, 0),
1893+
('RETURN_VALUE', None, 0)
1894+
]
1895+
after = [
1896+
('LOAD_SMALL_INT', 2, 0),
1897+
('RETURN_VALUE', None, 0),
1898+
]
1899+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[])
18631900

18641901
def test_optimize_if_const_binop(self):
18651902
add = get_binop_argval('NB_ADD')

0 commit comments

Comments
 (0)
0