(self)
| 1315 | """Verify a more complex program compiles without errors.""" |
| 1316 | |
| 1317 | def test_multi_function_program(self) -> None: |
| 1318 | src = """\ |
| 1319 | const MAP_W = 8 |
| 1320 | const MAP_H = 8 |
| 1321 | var player_x: int = 100 |
| 1322 | var player_y: int = 200 |
| 1323 | array map_data[64] |
| 1324 | |
| 1325 | func get_cell(x: int, y: int) -> int: |
| 1326 | return map_data[y * MAP_W + x] |
| 1327 | |
| 1328 | func 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 | |
| 1335 | func 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 = """\ |
nothing calls this directly
no test coverage detected