Fix /amibis spec clear being stored as a spec override
The generic "spec <name>" branch matched before the "spec clear" check, so clearing an override set overrideSpec to "Clear" and the UI then looked for a spec called Clear instead of falling back to auto-detection. Check the clear command first, collapse whitespace so "spec clear" parses, and refresh the frame immediately when the override changes. Spec names are also title-cased per word now, so "/amibis spec beast mastery" resolves to "Beast Mastery". Add test_slash.lua covering set/clear, case/whitespace normalization, and the clear-as-spec-name regression. 93 tests passing.
This commit is contained in:
1 parent
907d274b3a
commit
912ed8f255
4 files changed
+76
-5
No files matched your search
+21
-5
@@ -488,21 +488,37 @@ eventFrame:SetScript("OnEvent", function(self, event, ...)
|
|||||||
end
|
end
|
||||||
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"
|
SLASH_AMIBIS1 = "/amibis"
|
||||||
SlashCmdList["AMIBIS"] = function(msg)
|
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
|
if cmd == "" then
|
||||||
Amibis:ToggleFrame()
|
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
|
elseif cmd:find("^spec%s+") then
|
||||||
local spec = cmd:match("^spec%s+(.+)")
|
local spec = cmd:match("^spec%s+(.+)")
|
||||||
if spec and spec ~= "" then
|
if spec and spec ~= "" then
|
||||||
spec = spec:gsub("^%l", string.upper)
|
spec = NormalizeSpecName(spec)
|
||||||
AmibisCharDB.overrideSpec = spec
|
AmibisCharDB.overrideSpec = spec
|
||||||
print("Amibis: Spec override set to " .. spec .. ". Type /amibis spec clear to reset.")
|
print("Amibis: Spec override set to " .. spec .. ". Type /amibis spec clear to reset.")
|
||||||
|
RefreshUI()
|
||||||
end
|
end
|
||||||
elseif cmd == "spec clear" then
|
|
||||||
AmibisCharDB.overrideSpec = nil
|
|
||||||
print("Amibis: Spec override cleared.")
|
|
||||||
else
|
else
|
||||||
Amibis:ToggleFrame()
|
Amibis:ToggleFrame()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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_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_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_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 <name>` parsing: override set/clear, case and multi-word normalization, `spec clear` not treated as a spec name |
|
||||||
|
|
||||||
## Layout
|
## Layout
|
||||||
|
|
||||||
|
|||||||
@@ -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_data.lua"))(ADDON_NAME, ns)
|
||||||
assert(loadfile("Amibis/Tests/test_stats.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_compare.lua"))(ADDON_NAME, ns)
|
||||||
|
assert(loadfile("Amibis/Tests/test_slash.lua"))(ADDON_NAME, ns)
|
||||||
|
|
||||||
local success = TestHarness_report()
|
local success = TestHarness_report()
|
||||||
os.exit(success and 0 or 1)
|
os.exit(success and 0 or 1)
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
-- Slash-command tests: /amibis spec <name> 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)
|
||||||
Reference in new issue
Block a user