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

Skip to content

Commit ed7431d

Browse files
committed
add tests
1 parent 96ff172 commit ed7431d

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
@@ -1062,6 +1062,41 @@ def test_conditional_jump_forward_non_const_condition(self):
10621062
consts=[0, 1, 2, 3, 4],
10631063
expected_consts=[0, 2, 3])
10641064

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

0 commit comments

Comments
 (0)
0