Files
wow-forever-addons/tests/test_leistenabstand.lua
T
mikeandClaude Opus 5.5 f1eca2d1c5 Fehler aus dem Code-Review behoben, Tests hinzugefügt
Leistenabstand: Leere, ausgeblendete Slots ("Immer Buttons anzeigen" aus)
werden mit angeordnet. Vorher wurde ihre Lücke zugeschoben, und sobald
sie wieder erschienen, lagen sie fast genau auf dem Nachbarbutton.
Buttons jenseits von "Anzahl Symbole" bleiben außen vor (numShowingButtons,
sonst bis zum letzten sichtbaren Button). Die Haltungsleiste ordnet weiter
nur sichtbare Buttons an.

Goldbeutel: "Diese Sitzung" läuft über /reload weiter (Startwert pro
Charakter gespeichert, Reset nur bei echtem Login). /gold forget findet
auch Namen mit Umlauten und Akzenten unabhängig von Groß-/Kleinschreibung.

ForeverScale: /fscale pixel ist jetzt ein Modus und wird bei jedem
Auflösungswechsel neu berechnet. Kann absichtlich unter 0,30 liegen.

README: Quellcode-Anhang auf den neuen Stand gebracht.
tests/: Mock-Tests für alle drei Addons (luajit tests/<datei>.lua).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 12:02:06 +01:00

135 lines
6.1 KiB
Lua

-- Aufruf aus dem Repo-Wurzelverzeichnis oder von ueberall: luajit tests/test_leistenabstand.lua
-- Testet das Addon in einer nachgebauten WoW-Umgebung (Mock), nicht im echten Client.
local ROOT = ((arg and arg[0] or ""):match("^(.*/)") or "./") .. "../"
-- Mock: TOPLEFT/CENTER-Anker, Skalierung 1, y nach oben positiv
local out = print
local Frame = {}; Frame.__index = Frame
local function new(w, h) return setmetatable({w=w or 0,h=h or 0,pts={},shown=true,scripts={}}, Frame) end
function Frame:SetSize(w,h) self.w,self.h=w,h end
function Frame:GetSize() return self.w,self.h end
function Frame:GetEffectiveScale() return 1 end
function Frame:IsShown() return self.shown end
function Frame:Show() self.shown=true end
function Frame:Hide() self.shown=false end
function Frame:ClearAllPoints() self.pts={} end
function Frame:SetPoint(p, rel, rp, x, y)
local r = rel; while r do assert(r ~= self, "Ankerschleife!"); r = r.pts[1] and r.pts[1][2] end
self.pts={{p,rel,rp,x or 0,y or 0}}
end
function Frame:GetNumPoints() return #self.pts end
function Frame:GetPoint(i) local q=self.pts[i]; return q[1],q[2],q[3],q[4],q[5] end
local function off(p,w,h) if p=="CENTER" then return w/2,-h/2 end return 0,0 end
function Frame:TopLeft()
if not self.pts[1] then return self.x or 0, self.y or 0 end
local p,rel,rp,x,y = unpack(self.pts[1])
local rx,ry = rel:TopLeft(); local ax,ay = off(rp,rel.w,rel.h); local sx,sy = off(p,self.w,self.h)
return rx+ax+x-sx, ry+ay+y-sy
end
function Frame:GetLeft() local x=self:TopLeft(); return x end
function Frame:GetRight() local x=self:TopLeft(); return x+self.w end
function Frame:GetTop() local _,y=self:TopLeft(); return y end
function Frame:GetBottom() local _,y=self:TopLeft(); return y-self.h end
function Frame:GetCenter() local x,y=self:TopLeft(); return x+self.w/2, y-self.h/2 end
function Frame:RegisterEvent() end
function Frame:UnregisterEvent() end
function Frame:SetScript(n,f) self.scripts[n]=f end
function Frame:HookScript() end
unpack = unpack or table.unpack
local W, BPAD = 45, 2
local timers, ev, btn, bar
local function setup(opts)
timers = {}
for _, n in ipairs({"MainActionBar","MainMenuBar","MultiBarBottomLeft","MultiBarBottomRight","MultiBarRight",
"MultiBarLeft","MultiBar5","MultiBar6","MultiBar7","StanceBar","PetActionBar"}) do _G[n] = nil end
LeistenabstandDB = opts.db
CreateFrame = function() ev = new(); return ev end
C_Timer = {After=function(_,f) timers[#timers+1]=f end}
InCombatLockdown = function() return false end
hooksecurefunc = function() end
strtrim = function(s) return (s:gsub("^%s+",""):gsub("%s+$","")) end
SlashCmdList = {}
print = function() end
UIParent = new(1000,800); UIParent.x, UIParent.y = 0, 800
local cols = opts.cols or 12
bar = new(cols*W+(cols-1)*BPAD, W); bar:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 100, -600)
bar.actionButtons = {}; bar.numShowingButtons = opts.numShowing
_G[opts.barName or "MultiBarBottomRight"] = bar
btn = bar.actionButtons
local count = opts.count or 12
for i=1,count do
local b = new(W,W); local c, r = (i-1)%cols, math.floor((i-1)/cols)
b:SetPoint("TOPLEFT", bar, "TOPLEFT", c*(W+BPAD), -r*(W+BPAD))
btn[i] = b
end
for _, i in ipairs(opts.hidden or {}) do btn[i]:Hide() end
assert(loadfile(ROOT .. "Leistenabstand/Leistenabstand.lua"))("Leistenabstand")
ev.scripts.OnEvent(ev, "ADDON_LOADED", "Leistenabstand")
ev.scripts.OnEvent(ev, "PLAYER_LOGIN")
while #timers > 0 do table.remove(timers,1)() end
end
local function run() while #timers > 0 do table.remove(timers,1)() end end
local function pos(i) return btn[i]:GetLeft() - bar:GetLeft(), bar:GetTop() - btn[i]:GetTop() end
local fails = 0
local function check(name, cond) out((cond and " OK " or " FEHLER ") .. name); if not cond then fails = fails + 1 end end
local function near(a, b) return math.abs(a - b) < 0.01 end
local function rowOK(from, to, pad, row)
for i = from, to do
local x, y = pos(i)
if not near(x, (i-from)*(W+pad)) or not near(y, (row or 0)*(W+pad)) then return false end
end
return true
end
local function overlaps()
for i = 1, #btn do for j = i+1, #btn do
if btn[i]:IsShown() and btn[j]:IsShown() then
local xi, yi = pos(i); local xj, yj = pos(j)
if math.abs(xi-xj) < W - 0.01 and math.abs(yi-yj) < W - 0.01 then return true end
end
end end
return false
end
out("A: Slot 3 leer und ausgeblendet, numShowingButtons = 12")
setup{numShowing = 12, hidden = {3}}
check("Luecke bleibt: Button 1-12 im Raster mit Abstand 0", rowOK(1, 12, 0))
btn[3]:Show()
check("Button 3 erscheint ohne Ueberlappung", not overlaps())
out("B: Anzahl Symbole = 8, Buttons 9-12 ausgeblendet")
setup{numShowing = 8, hidden = {9,10,11,12}}
local x9 = pos(9)
check("Button 1-8 zusammengeschoben", rowOK(1, 8, 0))
check("Button 9-12 nicht angefasst (Blizzard-Position)", near(x9, 8*(W+BPAD)) and btn[9].pts[1][2] == bar)
out("C: Feld numShowingButtons fehlt, Slot 3 und 12 leer")
setup{numShowing = nil, hidden = {3, 12}}
check("Button 1-11 im Raster (Luecke 3 bleibt)", rowOK(1, 11, 0))
check("Button 12 (nach dem letzten sichtbaren) nicht angefasst", btn[12].pts[1][2] == bar)
out("D: Haltungsleiste, 3 Haltungen, Rest ausgeblendet")
setup{barName = "StanceBar", count = 10, cols = 10, numShowing = 10, hidden = {4,5,6,7,8,9,10}}
check("Haltung 1-3 zusammengeschoben", rowOK(1, 3, 0))
check("Haltung 4-10 nicht angefasst", btn[4].pts[1][2] == bar)
out("E: Zweimal anwenden, dann /abstand 1,5")
setup{numShowing = 12, hidden = {3, 7}}
ev.scripts.OnEvent(ev, "PLAYER_ENTERING_WORLD"); run()
check("Zweiter Durchlauf verrutscht nichts", rowOK(1, 12, 0))
SlashCmdList.LEISTENABSTAND("1,5"); run()
check("Neuer Abstand 1,5 ohne Reload", rowOK(1, 12, 1.5))
out("F: Zwei Reihen à 6, Slot 8 leer")
setup{numShowing = 12, cols = 6, hidden = {8}}
check("Reihe 1 korrekt", rowOK(1, 6, 0, 0))
check("Reihe 2 korrekt, Luecke 8 bleibt", rowOK(7, 12, 0, 1))
out("G: /abstand rahmen mit leerem letzten Slot (numShowingButtons = 12)")
setup{numShowing = 12, hidden = {12}}
SlashCmdList.LEISTENABSTAND("rahmen"); run()
check("Rahmen umfasst alle 12 Slots", near(bar.w, 12*W))
out(fails == 0 and "\nAlle Tests bestanden." or ("\n" .. fails .. " Test(s) fehlgeschlagen."))
os.exit(fails == 0 and 0 or 1)