diff --git a/Amibis/Amibis.lua b/Amibis/Amibis.lua index c0d6b81..b430ef9 100644 --- a/Amibis/Amibis.lua +++ b/Amibis/Amibis.lua @@ -488,21 +488,37 @@ eventFrame:SetScript("OnEvent", function(self, event, ...) end end) +local function RefreshUI() + if ns.UI and ns.UI.RefreshUI then + ns.UI.RefreshUI() + end +end + +-- Title-case each word so "/amibis spec beast mastery" -> "Beast Mastery". +local function NormalizeSpecName(value) + return (value:gsub("(%a)([%w']*)", function(first, rest) + return first:upper() .. rest:lower() + end)) +end + SLASH_AMIBIS1 = "/amibis" SlashCmdList["AMIBIS"] = function(msg) - local cmd = msg:trim():lower() + -- Collapse whitespace so "spec clear" and "spec beast mastery" parse. + local cmd = (msg:trim():lower():gsub("%s+", " ")) if cmd == "" then Amibis:ToggleFrame() + elseif cmd == "spec clear" then + AmibisCharDB.overrideSpec = nil + print("Amibis: Spec override cleared. Using auto-detected spec.") + RefreshUI() elseif cmd:find("^spec%s+") then local spec = cmd:match("^spec%s+(.+)") if spec and spec ~= "" then - spec = spec:gsub("^%l", string.upper) + spec = NormalizeSpecName(spec) AmibisCharDB.overrideSpec = spec print("Amibis: Spec override set to " .. spec .. ". Type /amibis spec clear to reset.") + RefreshUI() end - elseif cmd == "spec clear" then - AmibisCharDB.overrideSpec = nil - print("Amibis: Spec override cleared.") else Amibis:ToggleFrame() end diff --git a/Amibis/Tests/README.md b/Amibis/Tests/README.md index 402f040..4997e07 100644 --- a/Amibis/Tests/README.md +++ b/Amibis/Tests/README.md @@ -26,6 +26,7 @@ apt-get download lua5.4 && dpkg -x lua5.4_*.deb /tmp/lua && /tmp/lua/usr/bin/lua | `test_data.lua` | `BIS_DATA` registry: 9 classes × 3 specs, well-formed slot entries (valid slots, positive item IDs, non-empty names/sources, optional enchant shape), canonical phase order, `ResolvePhase` fallback, shared-list invariants, T4/T5/ZA spot checks | | `test_stats.lua` | `ScanItemStats`: MAX aggregation across alias keys (spell damage schools, healing, haste/crit/mp5 ratings), single-mapping pass-through, unmapped key filtering, nil handling | | `test_compare.lua` | `CompareGear`: BIS counting, upgrade ranking by stat gain, positive-diffs-only scoring, spec-specific stat keys (Shadow counts spell damage, Holy counts healing), phase resolution, `GetStatKeysForSpec`, `GetCompletionRatio` | +| `test_slash.lua` | `/amibis spec ` parsing: override set/clear, case and multi-word normalization, `spec clear` not treated as a spec name | ## Layout diff --git a/Amibis/Tests/run.lua b/Amibis/Tests/run.lua index d514cec..684b965 100644 --- a/Amibis/Tests/run.lua +++ b/Amibis/Tests/run.lua @@ -22,6 +22,7 @@ assert(loadfile("Amibis/Data/BISLists.lua"))(ADDON_NAME, ns) assert(loadfile("Amibis/Tests/test_data.lua"))(ADDON_NAME, ns) assert(loadfile("Amibis/Tests/test_stats.lua"))(ADDON_NAME, ns) assert(loadfile("Amibis/Tests/test_compare.lua"))(ADDON_NAME, ns) +assert(loadfile("Amibis/Tests/test_slash.lua"))(ADDON_NAME, ns) local success = TestHarness_report() os.exit(success and 0 or 1) diff --git a/Amibis/Tests/test_slash.lua b/Amibis/Tests/test_slash.lua new file mode 100644 index 0000000..b46f8df --- /dev/null +++ b/Amibis/Tests/test_slash.lua @@ -0,0 +1,53 @@ +-- Slash-command tests: /amibis spec and /amibis spec clear. +local _, ns = ... + +-- WoW exposes string:trim(); plain Lua does not. +if not string.trim then + function string.trim(s) + return (s:gsub("^%s+", ""):gsub("%s+$", "")) + end +end + +local function run(msg) + local output = {} + local realPrint = print + print = function(text) table.insert(output, tostring(text)) end + SlashCmdList["AMIBIS"](msg) + print = realPrint + return table.concat(output, "\n"), output +end + +describe("/amibis spec", function() + before_each(function() + AmibisCharDB.overrideSpec = nil + end) + + it("sets a spec override", function() + run("spec Holy") + expect(AmibisCharDB.overrideSpec).toEqual("Holy") + end) + + it("normalizes case and multi-word spec names", function() + run(" SPEC beast mastery ") + expect(AmibisCharDB.overrideSpec).toEqual("Beast Mastery") + end) + + it("clears the override instead of setting a spec named clear", function() + AmibisCharDB.overrideSpec = "Shadow" + local text = run("spec clear") + expect(AmibisCharDB.overrideSpec).toBeNil() + expect(text:find("cleared", 1, true)).toBeTruthy() + end) + + it("clears the override regardless of case or extra spaces", function() + AmibisCharDB.overrideSpec = "Shadow" + run(" SPEC CLEAR ") + expect(AmibisCharDB.overrideSpec).toBeNil() + end) + + it("keeps the override when the spec name is missing", function() + AmibisCharDB.overrideSpec = "Shadow" + run("spec") + expect(AmibisCharDB.overrideSpec).toEqual("Shadow") + end) +end)