zelda-dungeon/test-polyfill.html
2026-07-03 01:08:48 +00:00

96 lines
4.0 KiB
HTML

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>Polyfill Test</title></head>
<body>
<pre id="output"></pre>
<script src="src/browser-polyfill.js"></script>
<script src="src/core/constants.js"></script>
<script src="src/core/rng.js"></script>
<script src="src/core/utils.js"></script>
<script src="src/data/themes.js"></script>
<script src="src/data/dungeons.js"></script>
<script src="src/data/enemies.js"></script>
<script src="src/data/weapons.js"></script>
<script src="src/data/bosses.js"></script>
<script src="src/data/items.js"></script>
<script src="src/generator/dungeon.js"></script>
<script src="src/generator/rooms.js"></script>
<script src="src/generator/puzzles.js"></script>
<script src="src/generator/placement.js"></script>
<script>
var output = document.getElementById('output');
var lines = [];
function assert(name, condition) {
var result = condition ? 'PASS' : 'FAIL';
lines.push(result + ': ' + name);
}
// Test polyfill created globals
assert('module exists', typeof module !== 'undefined');
assert('require exists', typeof require === 'function');
// Test constants.js exposed to window
assert('TILE on window', window.TILE === 32);
assert('COLS on window', window.COLS === 32);
assert('ROWS on window', window.ROWS === 24);
assert('TILE_TYPES exists', window.TILE_TYPES && typeof window.TILE_TYPES === 'object');
assert('TILE_TYPES.FLOOR', window.TILE_TYPES && window.TILE_TYPES.FLOOR === 0);
assert('TILE_TYPES.WALL', window.TILE_TYPES && window.TILE_TYPES.WALL === 1);
// Test backward-compat constants
assert('T_FLOOR', window.T_FLOOR === 0);
assert('T_WALL', window.T_WALL === 1);
// Test rng.js exposed to window
assert('createRNG exists', typeof createRNG === 'function');
assert('mulberry32 exists', typeof mulberry32 === 'function');
// Test utils.js require worked
assert('C from utils (via require)', typeof createEmptyLayout === 'function');
assert('createBorderLayout exists', typeof createBorderLayout === 'function');
assert('isPassable exists', typeof isPassable === 'function');
// Test data files exposed to window
assert('THEMES exists', window.THEMES && typeof window.THEMES === 'object');
assert('DUNGEONS exists', Array.isArray(window.DUNGEONS));
assert('DUNGEONS.length', window.DUNGEONS && window.DUNGEONS.length === 100);
assert('ENEMY_TYPES exists', Array.isArray(window.ENEMY_TYPES));
assert('ENEMY_TYPES.length', window.ENEMY_TYPES && window.ENEMY_TYPES.length === 22);
assert('WEAPONS exists', Array.isArray(window.WEAPONS));
assert('BOSS_TYPES exists', Array.isArray(window.BOSS_TYPES));
assert('ITEMS exists', Array.isArray(window.ITEMS));
// Test generator files
assert('generateDungeon exists', typeof generateDungeon === 'function');
assert('generateRoomLayout exists', typeof generateRoomLayout === 'function');
assert('generatePuzzles exists', typeof generatePuzzles === 'function');
assert('generatePlacement exists', typeof generatePlacement === 'function');
// Test require resolution
var constantsFromRequire = require('./core/constants');
assert('require constants TILE', constantsFromRequire.TILE === 32);
assert('require constants COLS', constantsFromRequire.COLS === 32);
assert('require constants ROWS', constantsFromRequire.ROWS === 24);
var rngFromRequire = require('./core/rng');
assert('require createRNG', typeof rngFromRequire.createRNG === 'function');
// Test dungeon generation
var dungeon = window.DUNGEONS[0];
var rooms = generateDungeon(dungeon);
assert('generateDungeon returns rooms', Array.isArray(rooms) && rooms.length > 0);
assert('dungeon #0 room count ~20', rooms.length >= 18 && rooms.length <= 26);
assert('entrance room assigned', rooms[0].type === 'entrance');
assert('boss room assigned', rooms[rooms.length - 1].type === 'boss');
assert('rooms connected', rooms.every(function(r) { return r.connections && r.connections.length > 0; }));
lines.push('');
lines.push('Total: ' + lines.filter(function(l) { return l.startsWith('PASS'); }).length + ' passed, ' + lines.filter(function(l) { return l.startsWith('FAIL'); }).length + ' failed');
output.textContent = lines.join('\n');
</script>
</body>
</html>