206 lines
6.7 KiB
Lua
206 lines
6.7 KiB
Lua
-- Runs Minimap.lua against a mock of the WoW API.
|
|
-- arg[1] = addon file
|
|
|
|
local completed, onQuest = {}, {}
|
|
C_QuestLog = {
|
|
IsQuestFlaggedCompleted = function(id) return completed[id] == true end,
|
|
IsOnQuest = function(id) return onQuest[id] == true end,
|
|
}
|
|
|
|
local level, raceID, classID = 20, 7, 1
|
|
function UnitLevel() return level end
|
|
function UnitRace() return "x", "X", raceID end
|
|
function UnitClass() return "x", "X", classID end
|
|
|
|
local shown = {}
|
|
local removals = 0
|
|
local pinsLib = {
|
|
AddMinimapIconMap = function(_, ref, pin, map, x, y, parent, edge)
|
|
shown[#shown + 1] = { ref = ref, pin = pin, map = map, x = x, y = y, parent = parent, edge = edge }
|
|
end,
|
|
RemoveAllMinimapIcons = function() removals = removals + 1; shown = {} end,
|
|
}
|
|
function LibStub(name)
|
|
assert(name == "HereBeDragonsQuestie-Pins-2.0", name)
|
|
return pinsLib
|
|
end
|
|
|
|
local timers = {}
|
|
local overlapTick
|
|
C_Timer = {
|
|
After = function(_, fn) timers[#timers + 1] = fn end,
|
|
NewTicker = function(_, fn) overlapTick = fn end,
|
|
}
|
|
local function flush()
|
|
local list = timers
|
|
timers = {}
|
|
for _, fn in ipairs(list) do fn() end
|
|
end
|
|
|
|
local created = 0
|
|
local function texture()
|
|
local t = {}
|
|
function t:SetAllPoints() end
|
|
function t:SetTexture(p) self.path = p end
|
|
function t:SetDesaturated(v) self.desaturated = v end
|
|
function t:SetVertexColor(r, g, b) self.color = { r, g, b } end
|
|
return t
|
|
end
|
|
|
|
local onEvent, registered = nil, {}
|
|
Minimap = { GetFrameLevel = function() return 1 end, GetCenter = function() return 100, 100 end }
|
|
CreateFrame = function(kind)
|
|
if kind == "Frame" and not onEvent and created == 0 and not registered.frame then
|
|
registered.frame = true
|
|
return {
|
|
RegisterEvent = function(_, e) registered[e] = true end,
|
|
SetScript = function(_, _, fn) onEvent = fn end,
|
|
}
|
|
end
|
|
created = created + 1
|
|
local f = { scripts = {} }
|
|
function f:Hide() self.hidden = true end
|
|
function f:SetSize() end
|
|
function f:SetFrameLevel() end
|
|
function f:CreateTexture() self.tex = texture(); return self.tex end
|
|
function f:EnableMouse(v) self.mouse = v end
|
|
function f:SetAlpha(a) self.alpha = a end
|
|
function f:IsShown() return self.visible ~= false end
|
|
function f:GetCenter() return self.cx, self.cy end
|
|
function f:SetScript(name, fn) self.scripts[name] = fn end
|
|
return f
|
|
end
|
|
|
|
local tip = {}
|
|
GameTooltip = {
|
|
SetOwner = function(_, o) tip.owner = o end,
|
|
SetText = function(_, t) tip.title = t end,
|
|
AddLine = function(_, l) tip.line = l end,
|
|
Show = function() end,
|
|
Hide = function() tip.hidden = true 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 SKYBORNE = 4294967296
|
|
local notForMe = {}
|
|
local ns = {
|
|
raceBits = { [7] = 64, [95] = SKYBORNE },
|
|
Describe = function(id) if notForMe[id] then return nil end return "Dungeon pre-quest: The Deadmines" end,
|
|
pinQuests = {},
|
|
}
|
|
local function quest(fields)
|
|
local q = { n = "Q", l = 1, r = 0, c = 0, nx = 0, b = 0, s = { 1436, 0.5, 0.5 } }
|
|
for k, v in pairs(fields or {}) do q[k] = v end
|
|
return q
|
|
end
|
|
|
|
assert(loadfile(arg[1]))("DungeonPreQuest", ns)
|
|
|
|
local function count(fields)
|
|
ns.pinQuests = { [100] = quest(fields) }
|
|
onEvent()
|
|
flush()
|
|
return #shown
|
|
end
|
|
|
|
check(count() == 1, "available quest gets a marker")
|
|
check(shown[1].map == 1436 and shown[1].x == 0.5 and shown[1].ref == ns, "marker is placed on the given map")
|
|
check(shown[1].edge == false, "markers out of range don't stick to the minimap edge")
|
|
check(shown[1].pin.tex.desaturated and shown[1].pin.tex.color[1] > shown[1].pin.tex.color[2], "marker is tinted purple")
|
|
|
|
check(count({ s = { 1, 0.1, 0.1, 2, 0.2, 0.2 } }) == 2, "every spawn gets a marker")
|
|
|
|
completed[100] = true
|
|
check(count() == 0, "finished quest has no marker")
|
|
completed[100] = nil
|
|
onQuest[100] = true
|
|
check(count() == 0, "quest already taken has no marker")
|
|
onQuest[100] = nil
|
|
|
|
check(count({ l = 21 }) == 0, "too low level")
|
|
check(count({ l = 20 }) == 1, "exactly the right level")
|
|
|
|
check(count({ r = 1 }) == 0, "wrong race")
|
|
check(count({ r = 64 + SKYBORNE }) == 1, "race check handles Forever's high race bits")
|
|
raceID = 95
|
|
check(count({ r = 64 + SKYBORNE }) == 1, "high race bit itself matches")
|
|
check(count({ r = 64 }) == 0, "high race bit doesn't match a low mask")
|
|
raceID = 7
|
|
|
|
check(count({ c = 2 }) == 0, "wrong class")
|
|
classID = 11
|
|
check(count({ c = 1024 }) == 1, "class ID 11 matches the druid bit")
|
|
classID = 1
|
|
|
|
check(count({ p = { 50, 51 } }) == 0, "prerequisite missing")
|
|
completed[51] = true
|
|
check(count({ p = { 50, 51 } }) == 1, "any one prerequisite is enough")
|
|
completed[51] = nil
|
|
|
|
completed[50] = true
|
|
check(count({ g = { 50, 51 } }) == 0, "group needs every prerequisite")
|
|
completed[51] = true
|
|
check(count({ g = { 50, 51 } }) == 1, "group satisfied")
|
|
completed[50], completed[51] = nil, nil
|
|
|
|
onQuest[60] = true
|
|
check(count({ x = { 60 } }) == 0, "exclusive quest in the log blocks it")
|
|
onQuest[60] = nil
|
|
completed[61] = true
|
|
check(count({ nx = 61 }) == 0, "already past this step")
|
|
check(count({ b = 61 }) == 0, "breadcrumb target already done")
|
|
completed[61] = nil
|
|
|
|
notForMe[100] = true
|
|
check(count() == 0, "chain that isn't for this character")
|
|
notForMe[100] = nil
|
|
|
|
-- Hover.
|
|
count({ n = "The Day After" })
|
|
local pin = shown[1].pin
|
|
pin.questID = 100
|
|
pin.scripts.OnEnter(pin)
|
|
check(tip.title == "The Day After" and tip.line == "Dungeon pre-quest: The Deadmines", "tooltip names quest and dungeon")
|
|
pin.scripts.OnLeave(pin)
|
|
check(tip.hidden, "tooltip hides on leave")
|
|
|
|
-- The player arrow stays visible.
|
|
pin.cx, pin.cy = 105, 103
|
|
overlapTick()
|
|
check(pin.alpha == 0 and pin.mouse == false, "marker over the player arrow steps aside")
|
|
pin.cx, pin.cy = 150, 150
|
|
overlapTick()
|
|
check(pin.alpha == 1 and pin.mouse == true, "marker returns once clear of the arrow")
|
|
pin.cx, pin.cy = 115, 100
|
|
overlapTick()
|
|
check(pin.alpha == 1, "marker just beyond the arrow stays visible")
|
|
pin.cx, pin.cy = 100, 100
|
|
pin.visible = false
|
|
overlapTick()
|
|
check(pin.alpha == 1, "out-of-range markers are skipped")
|
|
pin.visible = nil
|
|
pin.cx, pin.cy = nil, nil
|
|
overlapTick()
|
|
check(pin.alpha == 1, "marker with no position yet is left alone")
|
|
|
|
-- Pooling and batching.
|
|
local before = created
|
|
count()
|
|
count()
|
|
check(created == before, "markers are reused")
|
|
|
|
local removalsBefore = removals
|
|
onEvent(); onEvent(); onEvent()
|
|
check(#timers == 1, "several events only queue one refresh")
|
|
flush()
|
|
check(removals == removalsBefore + 1, "one refresh runs")
|
|
|
|
check(registered.QUEST_TURNED_IN and registered.PLAYER_LEVEL_UP and registered.PLAYER_ENTERING_WORLD, "listens for what changes availability")
|
|
|
|
print(failures == 0 and "ALL PASSED" or (failures .. " FAILED"))
|
|
os.exit(failures == 0 and 0 or 1)
|