Stuff
This commit is contained in:
parent
ee33f94b4b
commit
f92d1504fa
547 changed files with 37597 additions and 0 deletions
54
tools/tests/test_usecode_structuring.py
Normal file
54
tools/tests/test_usecode_structuring.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from tools.poc_crusader_usecode_parser import render_structured_pseudocode
|
||||
|
||||
|
||||
class UsecodeStructuringTests(unittest.TestCase):
|
||||
def test_alarmbox_style_forward_flow_renders_without_block_labels(self) -> None:
|
||||
blocks = [
|
||||
("entry", ["set_info(0x0211, *(arg_06));", "process_exclude();", "if var goto block_0330;"]),
|
||||
("block_026D", ["if !Intrinsic0000() goto block_02CB;"]),
|
||||
("block_027C", ["if (Item.getFrame(arg_06) != 0) goto block_029B;"]),
|
||||
("block_028B", ["goto block_02BA;"]),
|
||||
("block_029B", ["if (Item.getFrame(arg_06) != 1) goto block_02BA;"]),
|
||||
("block_02AA", ["goto block_02BA;"]),
|
||||
("block_02BA", ["spawn class_0A0C_slot_3B(0x00000000);"]),
|
||||
("block_02CB", ["a = Item.getStatus(arg_06);", "if ((a & 4) != 0) goto block_032D;"]),
|
||||
("block_02E7", ["if (Item.getMapNum(arg_06) != 0) goto block_032D;"]),
|
||||
("block_02F9", ["spawn class_0A18_slot_20(pid, 0, *(arg_06), arg_06);", "suspend;"]),
|
||||
("block_032D", ["goto block_03C3;"]),
|
||||
("block_0330", ["if Intrinsic0000() goto block_03C3;"]),
|
||||
("block_033B", ["if (Item.getFrame(arg_06) != 2) goto block_035A;"]),
|
||||
("block_034A", ["goto block_0379;"]),
|
||||
("block_035A", ["if (Item.getFrame(arg_06) != 3) goto block_0379;"]),
|
||||
("block_0369", ["goto block_0379;"]),
|
||||
("block_0379", ["spawn class_0A0C_slot_3C(0x00000000);", "if (Item.getMapNum(arg_06) != 0) goto block_03C3;"]),
|
||||
("block_039C", ["spawn class_0A18_slot_20(pid, 1, *(arg_06), arg_06);", "suspend;"]),
|
||||
("block_03C3", ["return;"]),
|
||||
]
|
||||
|
||||
rendered = render_structured_pseudocode(blocks)
|
||||
|
||||
self.assertIsNotNone(rendered)
|
||||
text = "\n".join(rendered or [])
|
||||
self.assertNotIn("block_027C:", text)
|
||||
self.assertNotIn("goto block_03C3;", text)
|
||||
self.assertIn("if (!var) {", text)
|
||||
self.assertIn("if (Intrinsic0000()) {", text)
|
||||
self.assertIn("if ((a & 4) == 0) {", text)
|
||||
self.assertIn("if (!Intrinsic0000()) {", text)
|
||||
|
||||
def test_backward_jump_keeps_structured_renderer_disabled(self) -> None:
|
||||
blocks = [
|
||||
("entry", ["if flag goto block_0010;"]),
|
||||
("block_0004", ["return;"]),
|
||||
("block_0010", ["goto entry;"]),
|
||||
]
|
||||
|
||||
self.assertIsNone(render_structured_pseudocode(blocks))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue