Files
WoW-Hybrid-gateway/tests/source_weapon_damage_comparison_test.lua

122 lines
6.8 KiB
Lua

-- Pinned70334 shopping tooltips pass ProcessInfo({tooltipData=data,append=true})
-- after GetItemByGUID/GetHyperlink. No getter name/args exists on that path.
local pre, linePre
local hidden = {}
issecretvalue = function(value) return value == hidden end
GetLocale = function() return "enUS" end
Enum = {TooltipDataType = {Item = 0}, TooltipDataLineType = {None = 0}}
TooltipDataProcessor = {
AddTooltipPostCall = function() end,
AddTooltipPreCall = function(_, callback) pre = callback end,
AddLinePreCall = function(_, callback) linePre = callback end,
}
C_Item = {
GetItemInfoInstant = function(id) return id, "Weapon", "Sword", "INVTYPE_WEAPON", 1, 2, 7 end,
GetItemInfo = function() return "Loaded", nil, 1, 15, 10, "Weapon", "Sword", 1, "INVTYPE_WEAPON", 1, 1, 2 end,
}
GatewaySourceWeaponDamageData = {schemaVersion = 5, locale = "enUS", baseEquivalentInstances = true,
schools = {}, items = {}, primary = {
[90053] = {minimum = 10, maximum = 20, delayMS = 2200, dps = 6.818181818181818, school = 0},
[93223] = {minimum = 12.8, maximum = 19, delayMS = 1500, dps = 10.6, school = 0},
}}
local function raw(id, damage, speed, dps)
return {type = 0, id = id, lines = {
{type = 0, leftText = "Loaded weapon"},
{type = 0, leftText = damage, rightText = speed},
{type = 0, leftText = dps},
{type = 0, leftText = "Enchant: unchanged instance effect"},
{type = 0, leftText = "Set bonus: unchanged"},
}}
end
local baseline = {
[90053] = raw(90053, "10 - 21 Damage", "Speed 2.20", "(7.0 damage per second)"),
[93223] = raw(93223, "12.8 - 19 Damage", "Speed 1.50", "(10.6 damage per second)"),
}
C_TooltipInfo = {GetItemByID = function(id) return baseline[id] end}
local source = arg[1] or "client_addons/GatewayDiagnostics/SourceWeaponDamage.lua"
if source:sub(-4) ~= ".lua" then source = source .. "/client_addons/GatewayDiagnostics/SourceWeaponDamage.lua" end
if arg[2] then
-- Exercise the real addon manifest's load path. The data slot supplies
-- the public synthetic Source profile above; the provider executes only
-- if its file is actually listed, in declared order, by that manifest.
local profile = GatewaySourceWeaponDamageData
GatewaySourceWeaponDamageData = nil
local dataLoaded, providerLoaded = false, false
for rawEntry in io.lines(arg[2]) do
local entry = rawEntry:gsub("\r$", "")
if entry == "SourceWeaponDamageData.lua" then
assert(not dataLoaded and not providerLoaded, "Source weapon data load order/duplicate")
GatewaySourceWeaponDamageData = profile
dataLoaded = true
elseif entry == "SourceWeaponDamage.lua" then
assert(dataLoaded and not providerLoaded, "Source weapon provider load order/duplicate")
dofile(source)
providerLoaded = true
end
end
assert(dataLoaded and providerLoaded and pre and linePre, "Source weapon provider is absent from the addon load path")
else
dofile(source)
end
local function process(data, info)
local tooltip = {rendered = {}, processingInfo = info}
function tooltip:GetProcessingTooltipInfo() return self.processingInfo end
function tooltip:AddDoubleLine(left, right) self.rendered[#self.rendered + 1] = left.."|"..right end
function tooltip:AddLine(left) self.rendered[#self.rendered + 1] = left end
pre(tooltip, data)
for _, line in ipairs(data.lines) do
if not linePre(tooltip, line) then
tooltip.rendered[#tooltip.rendered + 1] = line.leftText .. (line.rightText and "|"..line.rightText or "")
end
end
return tooltip
end
local function check(data, info, damage, dps)
local originalDamage, originalDPS = data.lines[2].leftText, data.lines[3].leftText
local enchant, bonus = data.lines[4], data.lines[5]
local t = process(data, info)
assert(t.rendered[2] == damage and t.rendered[3] == dps)
assert(data.lines[2].leftText == originalDamage and data.lines[3].leftText == originalDPS)
assert(data.lines[4] == enchant and data.lines[5] == bonus)
assert(t.rendered[4] == enchant.leftText and t.rendered[5] == bonus.leftText)
return t
end
for _, id in ipairs({90053, 93223}) do
local data = baseline[id]
local damage = id == 90053 and "10 - 20 Damage|Speed 2.20" or "12.8 - 19 Damage|Speed 1.50"
local dps = id == 90053 and "(6.8 damage per second)" or "(10.6 damage per second)"
check(data, {tooltipData = data, append = true}, damage, dps) -- Actual native shopping contract.
for _, getter in ipairs({"GetInventoryItem", "GetInventoryItemByID", "GetBagItem", "GetBagItemChild", "GetHyperlink", "GetItemByGUID"}) do
check(data, {getterName = getter, getterArgs = {"public fixture argument"}, tooltipData = data}, damage, dps)
end
end
-- Distinct raw comparison data with equal native bands is supported; identity
-- is only required between current ProcessInfo and its current callback data.
local instance = raw(90053, "10 - 21 Damage", "Speed 2.20", "(7.0 damage per second)")
check(instance, {tooltipData = instance, append = true}, "10 - 20 Damage|Speed 2.20", "(6.8 damage per second)")
for _, changed in ipairs({
raw(90053, "11 - 22 Damage", "Speed 2.20", "(7.5 damage per second)"),
raw(90053, "10 - 21 Damage", "Speed 2.30", "(7.0 damage per second)"),
raw(90053, "10 - 21 Damage", "Speed 2.20", "(7.1 damage per second)"),
raw(93223, "12.9 - 19 Damage", "Speed 1.50", "(10.6 damage per second)"),
}) do
check(changed, {tooltipData = changed, append = true}, changed.lines[2].leftText.."|"..changed.lines[2].rightText, changed.lines[3].leftText)
end
local data = baseline[90053]
for _, info in ipairs({{}, {tooltipData = baseline[93223], append = true},
{tooltipData = data, getterArgs = {}}, {tooltipData = data, getterName = "UnqualifiedGetter", getterArgs = {}},
{tooltipData = data, getterName = "GetItemByGUID"},
{tooltipData = data, getterArgs = hidden}, {tooltipData = hidden, append = true},
{tooltipData = data, getterFunction = hidden, append = true}}) do
check(data, info, "10 - 21 Damage|Speed 2.20", "(7.0 damage per second)")
end
-- Rebuild re-arms only the current item, and changed instances fail closed.
local t = check(data, {tooltipData = data, append = true}, "10 - 20 Damage|Speed 2.20", "(6.8 damage per second)")
t.processingInfo = {tooltipData = baseline[93223], append = true};pre(t, baseline[93223])
assert(not linePre(t, data.lines[2]))
assert(linePre(t, baseline[93223].lines[2]) and linePre(t, baseline[93223].lines[3]))
GatewaySourceWeaponDamageData.baseEquivalentInstances = false
check(data, {tooltipData = data, append = true}, "10 - 21 Damage|Speed 2.20", "(7.0 damage per second)")
assert(GatewaySourceWeaponDamageDiagnostics.errors == 0)
print("PASS: native data-only shopping, equipped/bag/GUID contexts, decimal damage and unchanged modified instances")