-- Runs FishKey.lua against a mock of the WoW API. -- arg[1] = addon file local spells = { [7620] = "Fishing", [7731] = "Fishing", [133] = "Fireball" } C_Spell = { GetSpellName = function(id) return spells[id] end } local actions = { [9] = { "spell", 7731 }, [30] = { "macro", 4 }, [40] = { "spell", 133 } } function GetActionInfo(slot) local a = actions[slot] if a then return a[1], a[2] end end local macros = { [4] = 7620, [5] = 133 } function GetMacroSpell(i) return macros[i] end local macroNames = { ["FishMacro"] = 4, ["Nuke"] = 5 } function GetMacroIndexByName(n) return macroNames[n] or 0 end ActionButton9 = { bindingAction = "ACTIONBUTTON9", action = 9 } ActionButton10 = { bindingAction = "ACTIONBUTTON10", action = 40 } MultiBarBottomLeftButton6 = { bindingAction = "MULTIACTIONBAR1BUTTON6", action = 30 } SomeAddonButton = { GetAttribute = function(_, k) if k == "action" then return 9 end end } local bindings = { { "ACTIONBUTTON9", "ACTIONBAR", "F", "SHIFT-1" }, { "ACTIONBUTTON10", "ACTIONBAR", "G" }, { "MULTIACTIONBAR1BUTTON6", "ACTIONBAR" }, { "SPELL Fishing", "SPELLS", "CTRL-F" }, { "MACRO FishMacro", "MACROS", "ALT-F" }, { "MACRO Nuke", "MACROS", "N" }, { "CLICK SomeAddonButton:LeftButton", "ADDONS", "BUTTON4" }, { "INTERACTTARGET", "TARGETING", "SHIFT-F" }, } function GetNumBindings() return #bindings end function GetBinding(i) return unpack(bindings[i]) end local overrides = {} function SetOverrideBinding(_, priority, key, command) overrides[key] = command end function ClearOverrideBindings() overrides = {} end local inCombat = false function InCombatLockdown() return inCombat end local cvars = { SoftTargetInteractRange = "10" } local temp = {} C_CVar = { GetCVar = function(n) return temp[n] or cvars[n] end, SetTempCVar = function(n, v) temp[n] = v end, RemoveTempCVar = function(n) temp[n] = nil end, } local handler CreateFrame = function() return { RegisterEvent = function() end, RegisterUnitEvent = function() end, SetScript = function(_, _, fn) handler = fn end, } end SlashCmdList = {} local printed = {} DEFAULT_CHAT_FRAME = { AddMessage = function(_, m) printed[#printed + 1] = m end } local failures = 0 local function check(cond, what) if not cond then failures = failures + 1 end print((cond and "ok " or "FAIL ") .. what) end local function count(t) local n = 0 for _ in pairs(t) do n = n + 1 end return n end assert(loadfile(arg[1]))("FishKey", {}) handler(nil, "ADDON_LOADED", "FishKey") check(FishKeyDB.enabled == true, "enabled by default") handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7731) check(overrides["F"] == "INTERACTTARGET", "action bar key becomes interact") check(overrides["SHIFT-1"] == "INTERACTTARGET", "second key on the same button too") check(overrides["CTRL-F"] == "INTERACTTARGET", "SPELL binding") check(overrides["ALT-F"] == "INTERACTTARGET", "macro binding casting Fishing") check(overrides["BUTTON4"] == "INTERACTTARGET", "CLICK binding to an addon button") check(overrides["G"] == nil and overrides["N"] == nil, "other spells untouched") check(count(overrides) == 5, "only Fishing keys overridden") check(C_CVar.GetCVar("SoftTargetInteractRange") == "30", "interact range raised while fishing") handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7731) check(count(overrides) == 0, "keys back to Fishing when the channel ends") check(C_CVar.GetCVar("SoftTargetInteractRange") == "10", "range restored") handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 133) check(count(overrides) == 0, "other channels ignored") handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620) handler(nil, "PLAYER_REGEN_DISABLED") check(count(overrides) == 0, "cleared when combat starts") inCombat = true handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620) check(count(overrides) == 0, "no override in combat") inCombat = false cvars.SoftTargetInteractRange = "40" handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620) check(temp.SoftTargetInteractRange == nil, "longer range left alone") handler(nil, "UNIT_SPELLCAST_CHANNEL_STOP", "player", "guid", 7620) SlashCmdList.FISHKEY("off") check(FishKeyDB.enabled == false, "/fish off") check(printed[#printed]:find("off", 1, true) and printed[#printed]:find("F, SHIFT-1", 1, true), "status lists keys") handler(nil, "UNIT_SPELLCAST_CHANNEL_START", "player", "guid", 7620) check(count(overrides) == 0, "nothing when off") SlashCmdList.FISHKEY("on") check(FishKeyDB.enabled == true, "/fish on") print(failures == 0 and "all passed" or (failures .. " failed")) os.exit(failures == 0 and 0 or 1)