Files

89 lines
4.9 KiB
Lua

local file = assert(io.open("SoulstoneTracker.lua", "r"))
local source = file:read("*a")
file:close()
assert(loadfile("SoulstoneTracker.lua"))
local function section(first, last)
local a = assert(string.find(source, first, 1, true))
local b = assert(string.find(source, last, a + string.len(first), true))
return string.sub(source, a, b - 1)
end
local hits = 0
m = {
classifySpell = function() return "CoE" end,
detectCurse = function() hits = hits + 1 end,
updateSoulstoneCooldown = function() end,
}
FULL_NAMES = { CoE = "Curse of the Elements" }
SHORT_NAMES = { ["Curse of the Elements"] = "CoE" }
UnitName = function() return "Tester" end
local body = section(' elseif event == "SPELL_GO_SELF" then', ' elseif event == "SPELL_GO_OTHER" then')
local run = assert(loadstring('if false then\n'..body..'end'))
event = "SPELL_GO_SELF"
for _, value in ipairs({0, -1, "bad", false}) do arg6 = value run() end
arg6 = nil run()
assert(hits == 0, "failed/unknown hits must not announce")
arg6 = 1 run()
assert(hits == 1, "successful hit must detect")
local fallback = section(' elseif event == "CHAT_MSG_SPELL_HOSTILEPLAYER_BUFF"', ' elseif event == "CHAT_MSG_COMBAT_FRIENDLY_DEATH"')
run = assert(loadstring('if false then\n'..fallback..'end'))
event = "CHAT_MSG_SPELL_SELF_DAMAGE"
for _, msg in ipairs({"Your Curse of the Elements was resisted by Enemy.", "Enemy is immune to your Curse of the Elements.", "Enemy is afflicted by Curse of the Elements.", "Other casts Curse of the Elements on Enemy."}) do arg1 = msg run() end
assert(hits == 1, "ambiguous/failure text must not detect")
arg1 = "You cast Curse of the Elements on Enemy." run()
assert(hits == 2)
hasNampower = true run() assert(hits == 2)
local sent, channel, muted, announce = 0, nil, false, true
local raid, party = 0, 1
cfg = function(key) if key == "muteChat" then return muted else return announce end end
GetNumRaidMembers = function() return raid end
GetNumPartyMembers = function() return party end
SendChatMessage = function(msg, ch) assert(string.find(msg, "[SST]", 1, true)) sent = sent + 1 channel = ch end
say = function() end
SendAddonMessage = function() end
local manual = section(' local msg = "[SST] "..wName', ' end\n UIDropDownMenu_AddButton(ci)')
local group = section('local function sendGroup(msg)', 'local function playSound')
run = assert(loadstring(group..'\nlocal wName, sn = "Tester", "CoE"\n'..manual))
run() assert(sent == 1 and channel == "PARTY")
raid = 10 run() assert(sent == 2 and channel == "RAID")
muted = true run() assert(sent == 2)
muted = false announce = false run() assert(sent == 2)
announce = true raid = 0 party = 0 run() assert(sent == 2)
assert(loadstring(section('function m.applyHeaderPalette(f)', '-- Same as makeRule')))()
local created = 0
local function region()
return {
SetGradientAlpha = function(self, ...) self.gradient = arg end,
SetTexture = function(self, path) self.path = path end,
SetTexCoord = function(self, ...) self.uv = arg end,
SetAllPoints = function(self, anchor) self.anchor = anchor end,
SetVertexColor = function(self, ...) self.color = arg end,
Show = function(self) self.visible = true end,
Hide = function(self) self.visible = false end,
}
end
local f = {titleRule = {left = region(), right = region()}, titleBar = {}}
f.titleBar.CreateTexture = function() created = created + 1 return region() end
m.applyHeaderPalette(f)
assert(f.titleStone.color[1] == 1 and f.titleStone.color[4] == 1)
assert(f.titleStone.uv[1] == 80/256 and f.titleStone.uv[4] == 32/256)
assert(f.titleStone.anchor == f.titleBar)
ShaguTweaks = {GoldMode = true, UITint = {r=.9,g=.8,b=.7}, UIBorder={r=.4,g=.3,b=.2}}
m.applyHeaderPalette(f)
assert(f.titleStone.color[1] == .9*.8 and f.titleStone.color[2] == .8*.63)
assert(f.titleRule.left.gradient[2] == .4)
ShaguTweaks.DarkMode = true m.applyHeaderPalette(f) assert(not f.titleStone.visible)
ShaguTweaks = nil m.applyHeaderPalette(f) assert(f.titleStone.visible and created == 1)
assert(loadstring(section('function m.applySettingsHeaderPalette(s)', 'function m.applyHeaderPalette(f)')))()
local settings = {headerMid = region(), headerLeft = region(), headerRight = region()}
ShaguTweaks = {GoldMode = true, UITint = {r=1,g=.78,b=.4}}
m.applySettingsHeaderPalette(settings)
assert(settings.headerMid.color[2] == .78 and settings.headerLeft.color[3] == .4 and settings.headerRight.color[4] == 1)
ShaguTweaks = {DarkMode = true, UITint = {r=.3,g=.3,b=.3}}
m.applySettingsHeaderPalette(settings)
assert(settings.headerMid.color[1] == .3 and settings.headerRight.color[2] == .3)
ShaguTweaks = nil
m.applySettingsHeaderPalette(settings)
assert(settings.headerLeft.color[1] == 1 and settings.headerMid.color[3] == 1)
m.applySettingsHeaderPalette({}) -- Shadow theme has no native plate.
print("PASS: Lua 5.0 parse, cast outcomes, routing, header palettes/reuse")