Files
libdogtag-unit-3-0/test.lua
ckknight d56db6d9b8 - add support for MobHealth2, 3, and 4 for health-related tags
- Add PercentHP, MissingHP, FractionalHP, IsMaxHP, HPColor tags.
- for most HP tags, you can specify the optional kwarg "known", e.g. HP(unit='target', known=true), to only show known HP values, i.e. if they are in your party or if MobHealth can estimate its health. This eliminates the need for the SureHP tag as in LibDogTag-2.0
2008-03-15 20:22:12 +00:00

161 lines
5.3 KiB
Lua

local old_dofile = dofile
function dofile(file)
return old_dofile("../LibDogTag-3.0/" .. file)
end
old_dofile('../LibDogTag-3.0/test.lua')
dofile = old_dofile
local DogTag = LibStub("LibDogTag-3.0")
local units = {
player = {
hp = 1500,
maxhp = 2000,
exists = true,
},
pet = {
hp = 0,
maxhp = 1000,
exists = true,
},
target = {
hp = 2500,
maxhp = 2500,
exists = true,
},
pettarget = {
hp = 50,
maxhp = 100,
exists = true,
},
focus = {
exists = false,
}
}
local IsLegitimateUnit = { player = true, target = true, focus = true, pet = true, playerpet = true, mouseover = true, npc = true, NPC = true }
for i = 1, 4 do
IsLegitimateUnit["party" .. i] = true
IsLegitimateUnit["partypet" .. i] = true
IsLegitimateUnit["party" .. i .. "pet"] = true
end
for i = 1, 40 do
IsLegitimateUnit["raid" .. i] = true
IsLegitimateUnit["raidpet" .. i] = true
IsLegitimateUnit["raid" .. i .. "pet"] = true
end
setmetatable(IsLegitimateUnit, { __index = function(self, key)
if type(key) ~= "string" then
return false
end
if key:match("target$") then
self[key] = self[key:sub(1, -7)]
return self[key]
end
self[key] = false
return false
end, __call = function(self, key)
return self[key]
end})
function UnitExists(unit)
if not IsLegitimateUnit(unit) then
error(("Not a legitimate unit: %q"):format(unit), 2)
end
return units[unit] and units[unit].exists
end
function UnitHealth(unit)
if not IsLegitimateUnit(unit) then
error(("Not a legitimate unit: %q"):format(unit), 2)
end
return units[unit] and units[unit].hp
end
function UnitHealthMax(unit)
if not IsLegitimateUnit(unit) then
error(("Not a legitimate unit: %q"):format(unit), 2)
end
return units[unit] and units[unit].maxhp
end
MyUnit_data = "player"
DogTag:AddTag("Unit", "MyUnit", {
code = [=[return _G.MyUnit_data]=],
ret = "string",
})
MyValue_data = nil
DogTag:AddTag("Unit", "MyValue", {
code = [=[return _G.MyValue_data]=],
ret = "nil;number;string",
})
dofile("Localization/enUS.lua")
dofile("LibDogTag-Unit-3.0.lua")
dofile("Modules/Health.lua")
dofile("Cleanup.lua")
assert_equal(DogTag:Evaluate("[HP('player')]"), "Unknown tag HP")
assert_equal(DogTag:Evaluate("[HP('player')]", "Unit"), 1500)
assert_equal(DogTag:Evaluate("[HP(unit='player')]", "Unit"), 1500)
assert_equal(DogTag:Evaluate("[HP]", "Unit", { unit = 'player'}), 1500)
assert_equal(DogTag:Evaluate("[MaxHP('player')]", "Unit"), 2000)
assert_equal(DogTag:Evaluate("[MaxHP(unit='player')]", "Unit"), 2000)
assert_equal(DogTag:Evaluate("[PercentHP(unit='player')]", "Unit"), 75)
assert_equal(DogTag:Evaluate("[MissingHP(unit='player')]", "Unit"), 500)
assert_equal(DogTag:Evaluate("[FractionalHP(unit='player')]", "Unit"), "1500/2000")
assert_equal(DogTag:Evaluate("[HP(unit='pettarget', known=true)]", "Unit"), nil)
assert_equal(DogTag:Evaluate("[MissingHP(unit='pettarget', known=true)]", "Unit"), nil)
print(DogTag:CreateFunctionFromCode("[FractionalHP(unit='pettarget', known=true)]", "Unit"))
assert_equal(DogTag:Evaluate("[FractionalHP(unit='pettarget', known=true)]", "Unit"), nil)
assert_equal(DogTag:Evaluate("[HP('target')]", "Unit"), 2500)
assert_equal(DogTag:Evaluate("[MaxHP('target')]", "Unit"), 2500)
assert_equal(DogTag:Evaluate("[HP]", "Unit", { unit = 'target'}), 2500)
assert_equal(DogTag:Evaluate("[MaxHP]", "Unit", { unit = 'target'}), 2500)
assert_equal(DogTag:Evaluate("[HP('focus')]", "Unit"), nil)
assert_equal(DogTag:Evaluate("[MaxHP('focus')]", "Unit"), nil)
assert_equal(DogTag:Evaluate("[HP]", "Unit", { unit = 'focus'}), nil)
assert_equal(DogTag:Evaluate("[MaxHP]", "Unit", { unit = 'focus'}), nil)
assert_equal(DogTag:Evaluate("[HP('fakeunit')]", "Unit"), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[HP(unit='fakeunit')]", "Unit"), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[MaxHP('fakeunit')]", "Unit"), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[MaxHP(unit='fakeunit')]", "Unit"), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[HP]", "Unit", { unit = 'fakeunit'}), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[MaxHP]", "Unit", { unit = 'fakeunit'}), 'Bad unit: "fakeunit"')
assert_equal(DogTag:Evaluate("[HP]", "Unit", { unit = 50 }), 'Bad unit: "50"')
MyUnit_data = "player"
assert_equal(DogTag:Evaluate("[HP(MyUnit)]", "Unit"), 1500)
MyUnit_data = "target"
assert_equal(DogTag:Evaluate("[HP(MyUnit)]", "Unit"), 2500)
MyUnit_data = "focus"
assert_equal(DogTag:Evaluate("[HP(MyUnit)]", "Unit"), nil)
MyUnit_data = "fakeunit"
assert_equal(DogTag:Evaluate("[HP(MyUnit)]", "Unit"), 'Bad unit: "fakeunit"')
MyValue_data = "fakeunit"
assert_equal(DogTag:Evaluate("[HP(MyValue)]", "Unit"), 'Bad unit: "fakeunit"')
MyValue_data = 50
assert_equal(DogTag:Evaluate("[HP(MyValue)]", "Unit"), 'Bad unit: "50"')
MyValue_data = nil
assert_equal(DogTag:Evaluate("[HP(MyValue)]", "Unit"), nil)
local frame = CreateFrame("Frame")
local fs = frame:CreateFontString(nil, "ARTWORK")
DogTag:AddFontString(fs, frame, "[HP]", "Unit", { unit = "player" })
assert_equal(fs:GetText(), 1500)
units.player.hp = 1600
FireEvent("UNIT_HEALTH", "player")
FireOnUpdate(0.05)
assert_equal(fs:GetText(), 1600)
assert_equal(DogTag:Evaluate("[HPColor(unit='target')]", "Unit"), "|cff00ff00")
assert_equal(DogTag:Evaluate("[HPColor(unit='pet')]", "Unit"), "|cffff0000")
assert_equal(DogTag:Evaluate("[HPColor(unit='player')]", "Unit"), "|cff65ff00")
print("LibDogTag-Unit-3.0: Tests succeeded")