Skip to content

Commit 1ebd451

Browse files
committed
add tests
1 parent 375e143 commit 1ebd451

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Lib/test/test_peepholer.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,41 @@ def test_conditional_jump_forward_non_const_condition(self):
10591059
consts=[0, 1, 2, 3, 4],
10601060
expected_consts=[0, 2, 3])
10611061

1062+
def test_multiple_foldings(self):
1063+
before = [
1064+
('LOAD_SMALL_INT', 1, 0),
1065+
('LOAD_SMALL_INT', 2, 0),
1066+
('BUILD_TUPLE', 1, 0),
1067+
('LOAD_SMALL_INT', 0, 0),
1068+
('BINARY_SUBSCR', None, 0),
1069+
('BUILD_TUPLE', 2, 0),
1070+
('RETURN_VALUE', None, 0)
1071+
]
1072+
after = [
1073+
('LOAD_CONST', 1, 0),
1074+
('RETURN_VALUE', None, 0)
1075+
]
1076+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[(2,), (1, 2)])
1077+
1078+
def test_fold_tuple_of_constants_nops(self):
1079+
before = [
1080+
('NOP', None, 0),
1081+
('LOAD_SMALL_INT', 1, 0),
1082+
('NOP', None, 0),
1083+
('LOAD_SMALL_INT', 2, 0),
1084+
('NOP', None, 0),
1085+
('NOP', None, 0),
1086+
('LOAD_SMALL_INT', 3, 0),
1087+
('NOP', None, 0),
1088+
('BUILD_TUPLE', 3, 0),
1089+
('RETURN_VALUE', None, 0),
1090+
]
1091+
after = [
1092+
('LOAD_CONST', 0, 0),
1093+
('RETURN_VALUE', None, 0),
1094+
]
1095+
self.cfg_optimization_test(before, after, consts=[], expected_consts=[(1, 2, 3)])
1096+
10621097
def test_conditional_jump_forward_const_condition(self):
10631098
# The unreachable branch of the jump is removed, the jump
10641099
# becomes redundant and is replaced by a NOP (for the lineno)

0 commit comments

Comments
 (0)