mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-20 20:50:21 +02:00
72592665d7
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.
86 lines
3.2 KiB
Lua
86 lines
3.2 KiB
Lua
-- OverworldState:tryHiddenObject()'s "%s found\n%s!" message used to
|
|
-- substitute both the player name and the item name into one bare Lua
|
|
-- literal. The real _FoundHiddenItemText label leads with a {PLAYER}
|
|
-- named token, which romText auto-fills from a 2-arg call in the same
|
|
-- order the literal already used -- this test checks both slots land
|
|
-- correctly (an accidental argument swap is the easy mistake this shape
|
|
-- invites).
|
|
package.path = "./?.lua;./?/init.lua;" .. package.path
|
|
|
|
local T = require("tests.modkit")
|
|
local Data = T.fixtures.fresh()
|
|
|
|
local SaveData = require("src.core.SaveData")
|
|
local OW = require("src.world.OverworldController")
|
|
|
|
local function setUpvalue(fn, name, val)
|
|
local i = 1
|
|
while true do
|
|
local n = debug.getupvalue(fn, i)
|
|
if not n then return false end
|
|
if n == name then debug.setupvalue(fn, i, val); return true end
|
|
i = i + 1
|
|
end
|
|
end
|
|
|
|
local pushed = {}
|
|
local textBoxStub = {
|
|
new = function(_, text, onDone, opts)
|
|
return { text = text, onDone = onDone, opts = opts }
|
|
end,
|
|
soundOpts = function() return {} end,
|
|
}
|
|
|
|
local MAP_ID = "FIX_TOWN"
|
|
Data.field.hiddenItems[MAP_ID] = { { x = 3, y = 3, item = "FIX_BALL" } }
|
|
|
|
local function mkGame()
|
|
local save = SaveData.newGame()
|
|
save.player.name = "FAKEPLAYER"
|
|
pushed = {}
|
|
return {
|
|
data = Data, save = save,
|
|
stack = { push = function(_, item) pushed[#pushed + 1] = item end },
|
|
}
|
|
end
|
|
|
|
T.check(setUpvalue(OW.tryHiddenObject, "Game", mkGame()), "Game upvalue on tryHiddenObject")
|
|
T.check(setUpvalue(OW.tryHiddenObject, "TextBox", textBoxStub), "TextBox upvalue on tryHiddenObject")
|
|
|
|
local fakeSelf = setmetatable({ map = { id = MAP_ID } }, { __index = OW })
|
|
|
|
-- translated: player name and item name both land in the right slots
|
|
do
|
|
local game = mkGame()
|
|
setUpvalue(OW.tryHiddenObject, "Game", game)
|
|
Data.text._FoundHiddenItemText = "FAKE {PLAYER} found FAKE {RAM:wNameBuffer} FAKE!"
|
|
local found = fakeSelf:tryHiddenObject(3, 3)
|
|
T.check(found == true, "the hidden item at (3,3) is found")
|
|
T.eq(pushed[1] and pushed[1].text,
|
|
"FAKE FAKEPLAYER found FAKE FIX BALL FAKE!",
|
|
"a translated _FoundHiddenItemText fills both {PLAYER} and the item name")
|
|
Data.text._FoundHiddenItemText = nil
|
|
end
|
|
|
|
-- vanilla: no catalog entry, so romText falls back to plain
|
|
-- Strings(fallback, ...) -- the fallback literal is "%s found\n%s!" (both
|
|
-- slots plain %s, matching the pre-fix literal's own shape), not the
|
|
-- {PLAYER} token the real label uses, since Strings() never does
|
|
-- {TOKEN} substitution on its own. (A {PLAYER}-token fallback would
|
|
-- still render correctly too, since the real TextBox.new always runs
|
|
-- TextBox.substitute over whatever text it's given -- but this test
|
|
-- stubs TextBox without that call, and the fallback shouldn't lean on a
|
|
-- substitution pass happening downstream regardless.)
|
|
do
|
|
local game = mkGame()
|
|
setUpvalue(OW.tryHiddenObject, "Game", game)
|
|
game.save.hiddenTaken = {} -- fresh spot
|
|
local found = fakeSelf:tryHiddenObject(3, 3)
|
|
T.check(found == true, "the hidden item is found again in a fresh game")
|
|
T.eq(pushed[1] and pushed[1].text, "FAKEPLAYER found\nFIX BALL!",
|
|
"with no catalog entry, the fallback still fills both the player "
|
|
.. "and item name via plain %s substitution")
|
|
end
|
|
|
|
T.finish("overworld_hidden_item_romtext")
|