Files
gen1recomp/tests/engine/battle_catch_messages_romtext.lua
T
thibautbus 72592665d7 Cover the romText fixes with targeted regression tests
Every existing test around these callsites only ever runs with an
empty/fixture Data.text, so none of them could tell a properly-wired
romText/t._X call apart from a literal that never looked at the
catalog at all -- every assertion passed either way, the same coverage
gap the museum ticket clerk and status abbreviation fixes hit earlier.

Seven new tests fake the real label for each fix and assert the pushed
or queued message uses the translated value, plus a vanilla case per
fix confirming the no-catalog fallback still matches the original
English literal exactly:
- box_release_confirmation_romtext.lua (BoxMenu _OnceReleasedText, via
  a TextBox.new spy so real pagination/choice behavior stays intact)
- slot_machine_lined_up_romtext.lua (SlotMachine _LinedUpText, symbol
  concatenated in front of the translated suffix)
- battle_fainted_message_romtext.lua (BattleState onFaint, both
  _PlayerMonFaintedText and _EnemyMonFaintedText, confirming the raw
  name reaches each without a duplicated "Enemy")
- battle_catch_messages_romtext.lua (BattleState storeCaughtMon,
  _ItemUseBallText06 plus both _ItemUseBallText07/08 branches on
  EVENT_MET_BILL)
- battle_ball_dodge_romtext.lua (BattleState throwBall,
  _ItemUseBallText00's \f-merge collapsing to exactly one queued
  message)
- overworld_field_faint_heal_romtext.lua (OverworldController
  applyFieldPoison's _PokemonFaintedText, and
  useSoftboiledFieldMove's _ItemUseNoEffectText/_PotionText including
  the recovered-amount slot the old literal never showed)
- overworld_hidden_item_romtext.lua (OverworldController
  tryHiddenObject's _FoundHiddenItemText, both the {PLAYER} token and
  the item name landing in the right slots)

Confirmed several of these fail against the pre-fix code and pass
against the current code, not just reasoned about it. Not every one of
the 15 fixed callsites has its own dedicated test -- the ShopMenu,
LinkBattle, trainer-withdraw/sent-out and the normal (non-hidden)
found-item sites share the same romText mechanism already proven
correct by the seven tests above, and building the heavier fixtures
each would need (a full mart flow, a link session, a trainer AI
switch, an object_event NPC) wasn't judged worth it for what would be
the same assertion shape again.
2026-08-20 09:18:56 +02:00

78 lines
2.9 KiB
Lua

-- BattleState:storeCaughtMon() queues up to two plain-Lua-literal
-- messages: the new-Pokedex-data line (_ItemUseBallText06) and, when the
-- party is full, the box-transfer line (_ItemUseBallText07/08, keyed on
-- EVENT_MET_BILL -- two full, independently-translated ROM strings, not
-- one template with a substituted PC name). This test fakes all three
-- labels and checks the queued messages use them, not the English
-- literals.
package.path = "./?.lua;./?/init.lua;" .. package.path
local T = require("tests.modkit")
local Data = T.fixtures.fresh()
require("src.render.Font").load(Data)
local BattleState = require("src.battle.BattleState")
local Pokemon = require("src.pokemon.Pokemon")
local SaveData = require("src.core.SaveData")
local function findText(battle, needle)
for _, entry in ipairs(battle.queue) do
if entry.text and entry.text:find(needle, 1, true) then return entry.text end
end
return nil
end
local function mkbattle(partySize, metBill)
local save = SaveData.newGame()
save.party = {}
for i = 1, partySize do
save.party[i] = Pokemon.new(Data, "FIXMON_A", 5)
end
save.flags = save.flags or {}
save.flags.EVENT_MET_BILL = metBill
local game = { data = Data, save = save,
stack = { top = function() return nil end, push = function() end } }
return BattleState.newWild(game, "FIXMON_C", 8)
end
-- empty party: Party.add succeeds, only the new-Pokedex-data message fires
do
local battle = mkbattle(0, false)
Data.text._ItemUseBallText06 = "FAKE-DEX {RAM:wEnemyMonNick} FAKE!"
battle:storeCaughtMon()
T.eq(findText(battle, "FAKE-DEX"), "FAKE-DEX " .. battle.enemy.name .. " FAKE!",
"a translated _ItemUseBallText06 reaches the new-Pokedex-data message")
Data.text._ItemUseBallText06 = nil
end
-- full party, EVENT_MET_BILL true: box transfer via _ItemUseBallText07
do
local battle = mkbattle(6, true)
Data.text._ItemUseBallText07 = "FAKE-BILL {RAM:wBoxMonNicks} FAKE!"
battle:storeCaughtMon()
T.eq(findText(battle, "FAKE-BILL"), "FAKE-BILL " .. battle.enemy.name .. " FAKE!",
"EVENT_MET_BILL true routes through the translated _ItemUseBallText07")
Data.text._ItemUseBallText07 = nil
end
-- full party, EVENT_MET_BILL false: box transfer via _ItemUseBallText08
do
local battle = mkbattle(6, false)
Data.text._ItemUseBallText08 = "FAKE-SOMEONE {RAM:wBoxMonNicks} FAKE!"
battle:storeCaughtMon()
T.eq(findText(battle, "FAKE-SOMEONE"), "FAKE-SOMEONE " .. battle.enemy.name .. " FAKE!",
"EVENT_MET_BILL false routes through the translated _ItemUseBallText08")
Data.text._ItemUseBallText08 = nil
end
-- vanilla, full party, EVENT_MET_BILL true: English literal, BILL's PC
do
local battle = mkbattle(6, true)
battle:storeCaughtMon()
T.eq(findText(battle, "transferred"),
battle.enemy.name .. " was\ntransferred to\nBILL's PC!",
"no catalog entry falls back to the English BILL's-PC literal")
end
T.finish("battle_catch_messages_romtext")