53 lines
2.6 KiB
Lua
53 lines
2.6 KiB
Lua
local root = assert(arg[1])
|
|
local hooks, events, requests, lines = {}, {}, {}, {}
|
|
local guid, now, visible = "Player-70-0000119D", 0, true
|
|
function UnitGUID() return guid end
|
|
function UnitName() return "Fixture" end
|
|
function GetTime() return now end
|
|
function CreateFrame()
|
|
return { RegisterEvent = function() end, SetScript = function(_, _, fn) events.receive = fn end }
|
|
end
|
|
C_ChatInfo = {
|
|
RegisterAddonMessagePrefix = function(p) assert(p == "GW_CHALLENGES") end,
|
|
SendAddonMessage = function(p, text, channel, owner)
|
|
assert(p == "TW_UI" and channel == "WHISPER" and owner == "Fixture")
|
|
requests[#requests+1] = text
|
|
end,
|
|
}
|
|
GameTooltip = {
|
|
GetUnit = function() return "Fixture", "mouseover" end,
|
|
HookScript = function(_, name, fn) hooks[name] = fn end,
|
|
AddLine = function(_, line) lines[#lines+1] = line end,
|
|
IsShown = function() return visible end,
|
|
Show = function() visible = true end,
|
|
}
|
|
Enum = { TooltipDataType = { Unit = 2 } }
|
|
TooltipDataProcessor = { AddTooltipPostCall = function(kind, fn) assert(kind == 2); hooks.update = fn end }
|
|
dofile(root .. "/client_addons/WoWHybridUI/NativePlayerChallenges.lua")
|
|
local function update() hooks.update(GameTooltip) end
|
|
local function reply(text) events.receive(nil, "CHAT_MSG_ADDON", "GW_CHALLENGES", text) end
|
|
local function clear() lines = {}; hooks.OnTooltipCleared() end
|
|
update(); update()
|
|
assert(#requests == 1 and requests[1] == "REQUEST_PLAYER_CHALLENGES;0x000000000000119D")
|
|
for _, bad in ipairs({ "0x000000000000119D:-1", "0x000000000000119D:1.5", "0x000000000000119D:4294967296", "0x000000000000119D:3072:extra", "0xF00000000000119D:3072", "junk" }) do reply(bad) end
|
|
assert(#lines == 0)
|
|
reply("0x000000000000119d:3072")
|
|
assert(#lines == 3 and lines[2] == "Samurai" and lines[3] == "Together Forever")
|
|
update(); assert(#lines == 3)
|
|
clear(); update(); assert(#lines == 3 and #requests == 1)
|
|
-- A delayed reply for the previous hover must never decorate the new unit.
|
|
clear(); now = 31; update()
|
|
guid = "Player-70-0000119E"; update()
|
|
reply("0x000000000000119D:1024"); assert(#lines == 0)
|
|
reply("0x000000000000119E:2048"); assert(#lines == 2 and lines[2] == "Together Forever")
|
|
-- Zero clears cached challenges, and unknown bits do not create empty headers.
|
|
clear(); now = 62; update(); reply("0x000000000000119E:0"); assert(#lines == 0)
|
|
clear(); now = 93; update(); reply("0x000000000000119E:4096"); assert(#lines == 0)
|
|
clear(); guid = "Creature-0-70-0-0-1-000000119D"; update(); assert(#lines == 0)
|
|
local count = #requests
|
|
guid = "Player-70-0000119D"
|
|
function issecretvalue(v) return v == guid end
|
|
update(); assert(#requests == count)
|
|
issecretvalue = nil
|
|
print("player challenges parser/tooltip: PASS")
|