Skip to content

Commit

Permalink
Merge branch 'release/3.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
evil-morfar committed Nov 11, 2021
2 parents a9e295b + b8dff57 commit 75518f2
Show file tree
Hide file tree
Showing 60 changed files with 971 additions and 794 deletions.
6 changes: 4 additions & 2 deletions .luaformat
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use_tab: true
indent_width: 1
keep_simple_function_one_line: false
break_before_functioncall_rp: true
break_after_operator: false
break_after_operator: false
column_limit: 120
chop_down_table: true
extra_sep_at_table_end: true
13 changes: 10 additions & 3 deletions .specs/AddonLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ function Loader.ReplaceXmlPathWith (xml, path)
return xml:gsub("[^\\]+$", path)
end

--- @param path string
function Loader.ExtractBasePath(path)
local base = path:match("^%w+[\\/]?")
return base or ""
end

function Loader.XmlHandler (path, level)
level = level or 0
local xmllines = Loader.lines_from(path)
local basePath = Loader.ExtractBasePath(path)
local ret = {}
Loader.Log(string.rep("\t", level),"XmlHandler", path,level)
for x, y in pairs(xmllines) do
Expand All @@ -112,7 +119,7 @@ function Loader.XmlHandler (path, level)
Loader.Log(string.rep("\t", level+1),x,y, ext)
if ext == ".xml" then
Loader.Log(string.rep("\t", level),"Found xml", string.rep("-", level*2 ).."->")
if level > 0 then
if level > 0 or basePath ~= "" then
y = Loader.ReplaceXmlPathWith(path, y)
end
Loader.AddTableToTable(Loader.XmlHandler(y, level + 1), ret)
Expand All @@ -130,8 +137,8 @@ function Loader.XmlHandler (path, level)
end

function Loader.LoadFiles (files)
require("__tests/wow_api")
require("__tests/wow_item_api")
require("wow_api")
require("wow_item_api")
require "bit"
Loader.Log "Loading files..."
for _, file in ipairs(files) do
Expand Down
41 changes: 22 additions & 19 deletions .specs/AddonLoader.spec.lua
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
require "busted.runner"()

insulate("AddonLoader", function()
it("should not crash", function()
assert.has_no.errors(
function()
loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc")
end
)
end)
it("should not crash", function()
assert.has_no.errors(function() loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc") end)
end)
end)


insulate("AddonLoader", function()
it("should load RCLootCouncil", function()
loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc")
assert.truthy(_G.RCLootCouncil)
end)
it("should load RCLootCouncil", function()
loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc")
assert.truthy(_G.RCLootCouncil)
end)
end)

insulate("AddonLoader", function()
it("should load files without errors", function()
local s = spy.on(_G, "_errorhandler")
loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc")
pending("Will error out, but it's hard to fix at this point")
WoWAPI_FireEvent("ADDON_LOADED", "RCLootCouncil")
assert.spy(s).was_not.called()
end)
it("should load files without errors", function()
local s = spy.on(_G, "_errorhandler")
loadfile(".specs/AddonLoader.lua")().LoadToc("RCLootCouncil.toc")
WoWAPI_FireEvent("ADDON_LOADED", "RCLootCouncil")
assert.spy(s).was_not.called()
end)

it("should be enabled without issues", function()
local s = spy.on(_G, "_errorhandler")
_G.IsLoggedIn = spy.new(function() return true end)
WoWAPI_FireEvent("PLAYER_LOGIN", "RCLootCouncil")
assert.truthy(_G.RCLootCouncil)
assert.True(_G.RCLootCouncil.TradeUI:IsEnabled())
assert.spy(s).was_not.called()
end)
end)
5 changes: 3 additions & 2 deletions .specs/Classes/Core.spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require "busted.runner"()

describe("#Core", function()
require "__tests/wow_api"
local addon = {}
before_each(function()
loadfile("Classes/Core.lua")("addon", addon)
loadfile(".specs/AddonLoader.lua")(nil, "addon", addon).LoadArray{
"Classes/Core.lua"
}
end)

describe("Init", function()
Expand Down
195 changes: 77 additions & 118 deletions .specs/Classes/Data/MLDB.spec.lua
Original file line number Diff line number Diff line change
@@ -1,132 +1,91 @@
require "busted.runner"()
local addon = {
realmName = "Realm1",
db = {global = {log = {}, cache = {}}, profile = {}},
defaults = {global = {logMaxEntries = 2000}}
realmName = "Realm1",
db = {global = {log = {}, cache = {}}, profile = {}},
defaults = {global = {logMaxEntries = 2000}}
}
loadfile(".specs/AddonLoader.lua")(nil, nil, addon).LoadArray {
[[Libs\LibStub\LibStub.lua]],
[[Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml]],
[[Libs\AceComm-3.0\AceComm-3.0.xml]],
[[Libs\AceLocale-3.0\AceLocale-3.0.xml]],
[[Libs\AceSerializer-3.0\AceSerializer-3.0.xml]],
[[Libs\AceEvent-3.0\AceEvent-3.0.xml]],
[[Locale\enUS.lua]],
[[Core\Constants.lua]],
[[Core\Defaults.lua]],
[[Classes\Core.lua]],
[[Classes\Lib\RxLua\embeds.xml]],
[[Libs\LibDeflate\LibDeflate.lua]],
[[Classes\Utils\Log.lua]],
[[Classes\Utils\TempTable.lua]],
[[Classes\Services\ErrorHandler.lua]],
[[Locale\enUS.lua]],
[[Utils\Utils.lua]],
[[Classes\Data\Player.lua]],
[[Classes\Services\Comms.lua]],
[[Classes\Data\MLDB.lua]]
[[Libs\LibStub\LibStub.lua]],
[[Libs\CallbackHandler-1.0\CallbackHandler-1.0.xml]],
[[Libs\AceComm-3.0\AceComm-3.0.xml]],
[[Libs\AceLocale-3.0\AceLocale-3.0.xml]],
[[Libs\AceSerializer-3.0\AceSerializer-3.0.xml]],
[[Libs\AceEvent-3.0\AceEvent-3.0.xml]],
[[Locale\enUS.lua]],
[[Core\Constants.lua]],
[[Core\Defaults.lua]],
[[Classes\Core.lua]],
[[Classes\Lib\RxLua\embeds.xml]],
[[Libs\LibDeflate\LibDeflate.lua]],
[[Classes\Utils\Log.lua]],
[[Classes\Utils\TempTable.lua]],
[[Classes\Services\ErrorHandler.lua]],
[[Locale\enUS.lua]],
[[Utils\Utils.lua]],
[[Classes\Data\Player.lua]],
[[Classes\Services\Comms.lua]],
[[Classes\Data\MLDB.lua]]
}

function addon:Getdb()
return self.db.profile
return self.db.profile
end

setmetatable(
addon.db.profile,
{
__index = addon.defaults.profile
}
)
setmetatable(addon.db.profile, {__index = addon.defaults.profile})

describe(
"#Data #MLDB",
function()
---@type Data.MLDB
local MLDB = addon.Require "Data.MLDB"
local AceSer = LibStub("AceSerializer-3.0")
describe(
"init",
function()
it(
"should contain basic functions",
function()
assert.is.Function(MLDB.GetForTransmit)
assert.is.Function(MLDB.RestoreFromTransmit)
assert.is.Function(MLDB.Send)
assert.is.Function(MLDB.Get)
assert.is.Function(MLDB.Update)
end
)
end
)
describe(
"functions",
function()
before_each(
function()
-- Always use a fresh copy
loadfile([[Core\Defaults.lua]])(nil, addon)
end
)
describe("#Data #MLDB", function()
---@type Data.MLDB
local MLDB = addon.Require "Data.MLDB"
local AceSer = LibStub("AceSerializer-3.0")
describe("init", function()
it("should contain basic functions", function()
assert.is.Function(MLDB.GetForTransmit)
assert.is.Function(MLDB.RestoreFromTransmit)
assert.is.Function(MLDB.Send)
assert.is.Function(MLDB.Get)
assert.is.Function(MLDB.Update)
end)
end)
describe("functions", function()
before_each(function()
-- Always use a fresh copy
loadfile([[Core\Defaults.lua]])(nil, addon)
end)

it(
"should get MLDB",
function()
local mldb = MLDB:Get()
assert.are.equal(60, mldb.timeout)
assert.are.equal(true, mldb.selfVote)
end
)
it("should get MLDB", function()
local mldb = MLDB:Get()
assert.are.equal(60, mldb.timeout)
assert.are.equal(true, mldb.selfVote)
end)

it(
"should compress the MLDB",
function()
local mldb = MLDB:Get()
local forTransmit = MLDB:GetForTransmit()
assert.are.equal(60, forTransmit["|12"]) -- timeout
assert.True(#AceSer:Serialize(mldb) > #AceSer:Serialize(forTransmit))
end
)
it("should compress the MLDB", function()
local mldb = MLDB:Get()
local forTransmit = MLDB:GetForTransmit()
assert.are.equal(60, forTransmit["|12"]) -- timeout
assert.True(#AceSer:Serialize(mldb) > #AceSer:Serialize(forTransmit))
end)

it(
"should restore a transmitted MLDB",
function()
local mldb = MLDB:Get()
local restored = MLDB:RestoreFromTransmit(MLDB:GetForTransmit())
assert.are.same(mldb, restored)
end
)
it("should restore a transmitted MLDB", function()
local mldb = MLDB:Get()
local restored = MLDB:RestoreFromTransmit(MLDB:GetForTransmit())
assert.are.same(mldb, restored)
end)

it(
"should update mldb",
function()
local mldb1 = MLDB:Get()
addon.db.profile.buttons.NEW = {
numButtons = 1,
{text = "Test"}
}
addon.db.profile.responses.NEW = {
{text = "Tester"}
}
local mldb2 = MLDB:Update()
assert.are_not.same(mldb1, mldb2)
assert.are.equal(1, #mldb2.buttons.NEW)
assert.are.equal("Test", mldb2.buttons.NEW[1].text)
end
)
it(
"should handle random added values",
function()
assert.has_no.errors(
function()
local mldb = MLDB:Get()
mldb.newValue = true
MLDB:GetForTransmit(mldb)
end
)
end
)
end
)
end
)
it("should update mldb", function()
local mldb1 = MLDB:Get()
addon.db.profile.buttons.NEW = {numButtons = 1, {text = "Test"}}
addon.db.profile.responses.NEW = {{text = "Tester"}}
local mldb2 = MLDB:Update()
assert.are_not.same(mldb1, mldb2)
assert.are.equal(1, #mldb2.buttons.NEW)
assert.are.equal("Test", mldb2.buttons.NEW[1].text)
end)
it("should handle random added values", function()
assert.has_no.errors(function()
local mldb = MLDB:Get()
mldb.newValue = true
MLDB:GetForTransmit(mldb)
end)
end)
end)
end)
Loading

0 comments on commit 75518f2

Please sign in to comment.