MCPcopy Create free account
hub / github.com/4RH1T3CT0R7/ttf-doom / test_multi_function_program

Method test_multi_function_program

tests/test_codegen.py:1317–1355  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1315 """Verify a more complex program compiles without errors."""
1316
1317 def test_multi_function_program(self) -> None:
1318 src = """\
1319const MAP_W = 8
1320const MAP_H = 8
1321var player_x: int = 100
1322var player_y: int = 200
1323array map_data[64]
1324
1325func get_cell(x: int, y: int) -> int:
1326 return map_data[y * MAP_W + x]
1327
1328func clamp(val: int, lo: int, hi: int) -> int:
1329 if val < lo:
1330 return lo
1331 if val > hi:
1332 return hi
1333 return val
1334
1335func game_tick():
1336 player_x = clamp(player_x, 0, 1000)
1337 player_y = clamp(player_y, 0, 1000)
1338 var cell: int = get_cell(1, 2)
1339 if cell > 0:
1340 player_x = player_x + 1
1341"""
1342 result = _compile(src)
1343
1344 # Should produce non-empty assembly for all three segments
1345 assert len(result["fpgm"]) > 0
1346 assert len(result["prep"]) > 0
1347 assert len(result["glyph"]) > 0
1348
1349 # All instructions should be valid
1350 for line in result["fpgm"]:
1351 assert _is_valid_instruction(line), f"Invalid: {line!r}"
1352 for line in result["prep"]:
1353 assert _is_valid_instruction(line), f"Invalid: {line!r}"
1354 for line in result["glyph"]:
1355 assert _is_valid_instruction(line), f"Invalid: {line!r}"
1356
1357 def test_nested_if_else(self) -> None:
1358 src = """\

Callers

nothing calls this directly

Calls 2

_compileFunction · 0.85
_is_valid_instructionFunction · 0.70

Tested by

no test coverage detected