Skip to content

Commit

Permalink
Add tests for DataC_Title_NewGameFlags_eFlag_arr
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsteele committed Sep 4, 2024
1 parent 8afd015 commit e19327c
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/newgame.asm
Original file line number Diff line number Diff line change
Expand Up @@ -227,42 +227,42 @@ _SetFlags:
;;; A list of all flags that can potentially be set when starting a new game,
;;; in collection order.
.PROC DataC_Title_NewGameFlags_eFlag_arr
.byte eFlag::PaperJerome36
.byte eFlag::PaperManual2
.byte eFlag::PaperJerome36 ; room: PrisonCell
.byte eFlag::PaperManual2 ; room: PrisonEscape
.byte eFlag::PrisonCellReachedTunnel
.byte eFlag::PrisonCellBlastedRocks
.byte eFlag::GardenLandingDroppedIn
.byte eFlag::PaperJerome13
.byte eFlag::PaperJerome13 ; room: GardenLanding
.byte eFlag::UpgradeOpIf
.byte eFlag::PaperManual3
.byte eFlag::PaperJerome12
.byte eFlag::PaperManual3 ; room: GardenCrossroad
.byte eFlag::PaperJerome12 ; room: GardenHallway
.byte eFlag::GardenEastTalkedToCorra
.byte eFlag::MermaidHut1MetQueen
.byte eFlag::MermaidHut4MetFlorist
.byte eFlag::GardenTowerCratesPlaced
.byte eFlag::FlowerMermaid
.byte eFlag::PaperManual6
.byte eFlag::PaperManual6 ; room: GardenShaft
.byte eFlag::GardenTowerWallBroken
.byte eFlag::BossGarden
.byte eFlag::UpgradeRam1
.byte eFlag::BreakerGarden
.byte eFlag::TempleEntryPermission
.byte eFlag::TempleEntryColumnRaised
.byte eFlag::PaperManual1
.byte eFlag::PaperManual1 ; room: TempleFoyer
.byte eFlag::UpgradeOpTil
.byte eFlag::TempleAltarColumnBroken
.byte eFlag::PaperJerome28
.byte eFlag::PaperManual9
.byte eFlag::PaperJerome28 ; room: TempleChevet
.byte eFlag::PaperManual9 ; room: TempleApse
.byte eFlag::BossTemple
.byte eFlag::UpgradeRam2
.byte eFlag::BreakerTemple
.byte eFlag::FlowerTemple
.byte eFlag::PaperJerome29
.byte eFlag::PaperJerome07
.byte eFlag::PaperJerome29 ; room: MermaidElevator
.byte eFlag::PaperJerome07 ; room: FactoryBridge
.byte eFlag::FlowerFactory
.byte eFlag::PaperManual5
.byte eFlag::PaperManual5 ; room: FactoryUpper
.byte eFlag::CoreSouthCorraWaiting
.byte eFlag::PaperJerome18
.byte eFlag::PaperJerome18 ; room: FactoryWest
.byte eFlag::CoreSouthCorraHelped
.byte eFlag::PrisonEastEastGateOpen
.byte eFlag::PrisonEastLowerGateShut
Expand All @@ -276,82 +276,82 @@ _SetFlags:
.byte eFlag::PrisonCellGateOpen
.byte eFlag::FlowerPrison
.byte eFlag::MermaidHut1AlexPetition
.byte eFlag::PaperJerome31
.byte eFlag::PaperJerome31 ; room: CoreFlower
.byte eFlag::FlowerCore
.byte eFlag::TempleNaveAlexWaiting
.byte eFlag::TempleNaveTalkedToAlex
.byte eFlag::PaperJerome34
.byte eFlag::PaperJerome34 ; room: TemplePit
.byte eFlag::CryptLandingDroppedIn
.byte eFlag::PaperJerome08
.byte eFlag::PaperJerome11
.byte eFlag::PaperJerome08 ; room: CryptCenter
.byte eFlag::PaperJerome11 ; room: CryptSpiral
.byte eFlag::UpgradeOpGoto
.byte eFlag::CryptSouthBrokeFloor
.byte eFlag::CryptTombBrokeFloors
.byte eFlag::BossCrypt
.byte eFlag::UpgradeOpRest
.byte eFlag::BreakerCrypt
.byte eFlag::PaperJerome21
.byte eFlag::PaperJerome21 ; room: CryptEscape
.byte eFlag::TempleEntryTalkedToCorra
.byte eFlag::FlowerCrypt
.byte eFlag::CityOutskirtsTalkedToAlex
.byte eFlag::UpgradeOpSkip
.byte eFlag::PaperJerome14
.byte eFlag::PaperJerome14 ; room: GardenFlower
.byte eFlag::FlowerGarden
.byte eFlag::MermaidSpringConsoleFixed
.byte eFlag::MermaidSpringUnplugged
.byte eFlag::LavaWestDroppedIn
.byte eFlag::UpgradeOpCopy
.byte eFlag::PaperManual4
.byte eFlag::PaperJerome10
.byte eFlag::PaperManual4 ; room: LavaStation
.byte eFlag::PaperJerome10 ; room: LavaWest
.byte eFlag::LavaCenterChain3Broken
.byte eFlag::LavaCenterChain1Broken
.byte eFlag::LavaCenterChain2Broken
.byte eFlag::PaperJerome27
.byte eFlag::PaperJerome27 ; room: LavaTunnel
.byte eFlag::BossLava
.byte eFlag::UpgradeRam3
.byte eFlag::BreakerLava
.byte eFlag::UpgradeOpSync
.byte eFlag::PaperJerome09
.byte eFlag::PaperJerome09 ; room: MineNorth
.byte eFlag::BossMine
.byte eFlag::UpgradeRam4
.byte eFlag::BreakerMine
.byte eFlag::PaperJerome19
.byte eFlag::PaperJerome19 ; room: SewerBasin
.byte eFlag::UpgradeOpAddSub
.byte eFlag::FactoryPassLoweredRocks
.byte eFlag::FactoryElevatorTalkedToBruno
.byte eFlag::PaperJerome23
.byte eFlag::PaperJerome23 ; room: CoreLock
.byte eFlag::FlowerMine
.byte eFlag::FactoryVaultTalkedToAlex
.byte eFlag::FactoryEastCorraHelped
.byte eFlag::FlowerLava
.byte eFlag::PaperJerome05
.byte eFlag::PaperJerome03
.byte eFlag::PaperJerome05 ; room: SewerWest
.byte eFlag::PaperJerome03 ; room: SewerPipe
.byte eFlag::FlowerSewer
.byte eFlag::CityCenterEnteredCity
.byte eFlag::CityOutskirtsBlastedRocks
.byte eFlag::CityCenterKeygenConnected
.byte eFlag::PaperJerome35
.byte eFlag::PaperJerome35 ; room: CityDump
.byte eFlag::FlowerCity
.byte eFlag::CityBuilding3BlastedCrates
.byte eFlag::PaperManual8
.byte eFlag::PaperManual8 ; room: CityBuilding3
.byte eFlag::CityCenterDoorUnlocked
.byte eFlag::BossCity
.byte eFlag::UpgradeBRemote
.byte eFlag::BreakerCity
.byte eFlag::CityCenterTalkedToAlex
.byte eFlag::ShadowTeleportEnteredLab
.byte eFlag::PaperJerome01
.byte eFlag::PaperJerome01 ; room: ShadowEntry
.byte eFlag::ShadowHallInitialized
.byte eFlag::ShadowHallGlassBroken
.byte eFlag::PaperJerome02
.byte eFlag::PaperJerome02 ; room: ShadowHall
.byte eFlag::ShadowDrillClearedGoo
.byte eFlag::ShadowTrapDisarmed
.byte eFlag::PaperJerome04
.byte eFlag::PaperJerome04 ; room: ShadowHeart
.byte eFlag::ShadowHeartTaggedGhost
.byte eFlag::PaperJerome06
.byte eFlag::PaperJerome06 ; room: ShadowOffice
.byte eFlag::ShadowOfficeRemovedWall
.byte eFlag::ShadowOfficeTaggedGhost
.byte eFlag::PaperJerome20
.byte eFlag::PaperJerome20 ; room: ShadowDescent
.byte eFlag::BossShadow
.byte eFlag::UpgradeOpMul
.byte eFlag::BreakerShadow
Expand Down
61 changes: 61 additions & 0 deletions tests/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@

D_STRUCT_RE = re.compile(r'^:? *D_STRUCT +(s[A-Za-z0-9]+)')

FLAG_ENUM_RE = re.compile(r'^\.ENUM +eFlag')
NEWGAME_FLAGS_RE = re.compile(r'^\.PROC +DataC_Title_NewGameFlags_eFlag_arr')
NEWGAME_FLAG_RE = re.compile(
r'^ *\.byte +eFlag::([A-Za-z0-9]+)(?: *; *room: *([A-Za-z0-9]+))?')

MARKER_ROW_RE = re.compile(r'^ *d_byte +Row_u8, *([0-9]+)')
MARKER_COL_RE = re.compile(
r'^ *d_byte +Col_u8, *([0-9]+) *; *room: *([A-Za-z0-9]+)')
Expand Down Expand Up @@ -151,6 +156,32 @@ def scan_for_int(file, pattern, radix=10):

#=============================================================================#

def load_all_flags():
flags = []
with open('src/flag.inc') as file:
scan_for_match(file, FLAG_ENUM_RE)
for line in file:
assert line, f'unclosed .ENUM eFlag in {file.name}'
line = line.lstrip()
if line.startswith(';'): continue
if line.startswith('.ENDENUM'): break
flag = line.split(maxsplit=1)[0]
if flag == 'NUM_VALUES': continue
flags.append(flag)
return flags

def load_newgame_flags():
flags = []
with open('src/newgame.asm') as file:
scan_for_match(file, NEWGAME_FLAGS_RE)
while True:
match = scan_for_match(file, NEWGAME_FLAG_RE)
flag = match.group(1)
room = match.group(2)
flags.append((flag, room))
if flag == 'None': break
return flags

def load_minimap():
minimap = set()
with open('src/minimap.bg') as file:
Expand Down Expand Up @@ -545,6 +576,33 @@ def test_paper_rooms(areas, papers):
failed = True
return failed

def test_newgame_flags(newgame_flags, all_flags, papers):
failed = False
unused_flags = set(all_flags)
for flag, room in newgame_flags:
if flag not in unused_flags:
print(f'SCENARIO: repeated newgame flag {flag}')
failed = True
continue
unused_flags.remove(flag)
if flag.startswith('Paper'):
if room != papers[flag]['room']:
print(f'SCENARIO: newgame flag {flag} has room {room} instead'
f" of {papers[flag]['room']}")
failed = True
elif room is not None:
print(f'SCENARIO: newgame flag {flag} has needless room comment')
failed = True
# TODO: remove this filter once all papers are added
unused_flags = set(flag for flag in unused_flags
if not flag.startswith('Paper'))
if unused_flags:
print('SCENARIO: missing newgame flags:')
for flag in sorted(unused_flags):
print(f' {flag}')
failed = True
return failed

#=============================================================================#

def run_tests():
Expand All @@ -563,6 +621,9 @@ def run_tests():
failed |= test_flower_rooms(areas, markers)
papers = load_papers()
failed |= test_paper_rooms(areas, papers)
all_flags = load_all_flags()
newgame_flags = load_newgame_flags()
failed |= test_newgame_flags(newgame_flags, all_flags, papers)
return failed

#=============================================================================#
Expand Down

0 comments on commit e19327c

Please sign in to comment.