def test_build_while_body_given_body_if(self): as_tree = ast.parse( ms("""\ while a < 3: # 1st block if a < 2: # 2nd block z = 2 # 3rd block b = 2 # 4th block """)) while_block = RawBasicBlock(1, 1, 'While') cfg_handler = Cfg() cfg_handler.as_tree = as_tree real_tail_list = cfg_handler.build_while_body(while_block) expected_block_list = build_blocks([1, 1, 'While'], [2, 2, 'If'], [3, 3, None], [4, 4, None], block_links={ '0': [1], '1': [2, 3], '2': [3], '3': [0] }) self.assertBasicBlockEqual(while_block, expected_block_list[0]) self.assertBasicBlockEqual(real_tail_list[0], expected_block_list[0])
def test_build_while_body_given_only_while(self): as_tree = ast.parse(ms("""\ while a < 3: # 1st block z = 4 # 2nd block """)) while_block = RawBasicBlock(1, 1, 'While') cfg_handler = Cfg() cfg_handler.as_tree = as_tree real_tail_list = cfg_handler.build_while_body(while_block) expected_block_list = build_blocks([1, 1, 'While'], [2, 2, None], block_links={'0': [1], '1': [0]}) self.assertBasicBlockEqual(while_block, expected_block_list[0]) self.assertBasicBlockEqual(real_tail_list[0], expected_block_list[0])