forked from shrugal/PersoLootRoll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.lua
407 lines (368 loc) · 14.3 KB
/
Test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
local Name = debug.getinfo(1).source:gsub("\\", "/"):match("([^/]+)/[^/]+$") or (os.getenv("PWD") or ""):match("[^/]+$")
local Addon = {}
-- Static info
local BUILD = {"8.2.5", "32028", "Sep 30 2019", 80205}
local LOCALE = "enUS"
local REGION = 3
local REALM = "Mal'Ganis"
local REALM_CONNECTED = {"Echsenkessel", "Mal'Ganis", "Taerar"}
local VERSION = "0-dev0"
local FACTION = "Horde"
local RACE = 8
local CLASS = 8
local LEVEL = 120
local GUID = "Player-1612-054E4E80"
local CLASSES = {"Warrior", "Paladin", "Hunter", "Rogue", "Priest", "Death Knight", "Shaman", "Mage", "Warlock", "Monk", "Druid", "Demon Hunter"}
local RACES = {"Human", "Orc", "Dwarf", "Night Elf", "Undead", "Tauren", "Gnome", "Troll", "Goblin", "Blood Elf", "Draenei", "Fel Orc", "Naga", "Broken", "Skeleton", "Vrykul", "Tuskarr", "Forest Troll", "Taunka", "Northrend Skeleton", "Ice Troll", "Worgen", "Gilnean", "Pandaren", "Pandaren", "Pandaren", "Nightborne", "Highmountain Tauren", "Void Elf", "Lightforged Draenei", "Zandalari Troll", "Kul Tiran", "Human", "Dark Iron Dwarf", "Vulpera", "Mag'har Orc", "Mechagnome"}
-- Options
local options = {
build = false,
buildPath = ".release/" .. Name
}
local key
for i=1,select("#", ...) do
local arg = select(i, ...)
if arg:match("^%-%-") then
key = arg:gsub("^%-%-", "")
elseif arg:match("^%-[a-zA-Z]$") then
key = ({
b = "build"
})[arg:gsub("^-", "")]
options[key], key = true
else
if type(options[key]) == "boolean" then
arg = arg == "true" or arg == "1"
elseif type(options[key]) == "number" then
arg = tonumber(arg)
end
options[key], key = arg
end
end
local importPath = options.build and options.buildPath or "."
-------------------------------------------------------
-- Helper --
-------------------------------------------------------
local function checkfile(path)
local f = io.open(path)
return f and f:close()
end
local function readfile(path)
local file = io.open(path) or error("File " .. path .. " not found")
return file:read("*all"), file:close()
end
local function xml(s)
local function parseargs(s)
local arg = {}
string.gsub(s, "([%-%w]+)=([\"'])(.-)%2", function(w, _, a) arg[w] = a end)
return arg
end
-- Remove comments
s = s:gsub("<!%-%-.-%-%->", "")
local stack = {}
local top = {}
table.insert(stack, top)
local ni, c, label, xarg, empty
local i, j = 1, 1
while true do
ni, j, c, label, xarg, empty = string.find(s,
"<(%/?)([%w:]+)(.-)(%/?)>", i)
if not ni then break end
local text = string.sub(s, i, ni - 1)
if not string.find(text, "^%s*$") then table.insert(top, text) end
if empty == "/" then -- empty element tag
table.insert(top, {label = label, xarg = parseargs(xarg), empty = 1})
elseif c == "" then -- start tag
top = {label = label, xarg = parseargs(xarg)}
table.insert(stack, top) -- new level
else -- end tag
local toclose = table.remove(stack) -- remove top
top = stack[#stack]
if #stack < 1 then
error("nothing to close with " .. label)
end
if toclose.label ~= label then
error("trying to close " .. toclose.label .. " with " .. label)
end
table.insert(top, toclose)
end
i = j + 1
end
local text = string.sub(s, i)
if not string.find(text, "^%s*$") then table.insert(stack[#stack], text) end
if #stack > 1 then error("unclosed " .. stack[#stack].label) end
return stack[1]
end
local extensions = {lua = true, xml = true, toc = true}
local function import(file)
local path, ext = file:gsub("\\", "/"):match("^(.-)%.?([^.]+)$")
if not path:match("/") then
path = path:gsub("%.", "/")
end
if not extensions[ext] then
path = path ~= "" and path .. "/" .. ext or ext
for v in pairs(extensions) do
if checkfile(path .. "." .. v) then ext = v break end
end
end
path = path .. "." .. ext
local dir = path:match("^(.-)[^/]+$")
if ext == "lua" then
return loadfile(path)(Name, Addon)
elseif ext == "xml" then
for _,node in ipairs(xml(readfile(path))[1] or {}) do
if node.label == "Script" or node.label == "Include" then
import(dir .. node.xarg.file)
end
end
elseif ext == "toc" then
for line in readfile(path):gmatch("[^\r\n]+") do
if line ~= "" and line:sub(1, 1) ~= "#" then
import(dir .. line)
end
end
else
error("Unknown file extension " .. ext)
end
end
local frames = {}
local fire = function (...) for _,f in ipairs(frames) do f:FireEvent(...) end end
local update = function () for _,f in ipairs(frames) do f:FireUpdate() end end
local Fn = function () end
local Id = function (v) return v end
local Const = function (v) return function () return v end end
local Consts = function (...) local args = {...} return function () return unpack(args) end end
local Val = function (v) return function (a) if a then return v end end end
local Vals = function (...) local args = {...} return function (...) if ... then return unpack(args) end end end
local Meta = { __index = function (_, k) if k.match and k:match("^[A-Z]") and k:match("[^A-Z_]") then return Fn end end }
local Obj = setmetatable({}, Meta)
-------------------------------------------------------
-- WoW mocks --
-------------------------------------------------------
CreateFrame = function (_, name, parent)
parent = parent or UIParent
local scripts, events, points, lastUpdate, f = {}, {}, {}, 0
local CreateChild = function () return CreateFrame(nil, nil, f) end
f = setmetatable({
SetScript = function (_, k, v) scripts[k] = v end,
GetScript = function (_, k) return scripts[k] end,
HasScript = function (_, k) return not not scripts[k] end,
RegisterEvent = function (_, k) events[k] = true end,
UnregisterEvent = function (_, k) events[k] = nil end,
UnregisterAllEvents = function () wipe(events) end,
SetParent = function (v) parent = v end,
GetParent = function () return parent end,
SetPoint = function (_, ...)
local n, point, rel, relPoint, x, y = select("#", ...), ...
if n == 1 then rel, relPoint, x, y = parent, point, 0, 0 end
if n == 3 and type(rel) == "table" then x, y = 0, 0 end
if n == 3 and type(rel) == "number" then x, y, rel, relPoint = rel, relPoint, parent, point end
table.insert(points, {point, rel, relPoint, x, y})
end,
GetPoint = function (_, k) return unpack(points[k]) end,
GetNumPoints = function () return #points end,
ClearAllPoints = function () wipe(points) end,
NumLines = Const(0),
CreateTexture = CreateChild,
CreateFontString = CreateChild,
FireEvent = function (_, e, ...) if scripts.OnEvent and events[e] then scripts.OnEvent(f, e, ...) end end,
FireUpdate = function () if scripts.OnUpdate then scripts.OnUpdate(f, os.clock() - lastUpdate) lastUpdate = os.clock() end end
}, Meta)
table.insert(frames, f)
if name then _G[name] = f end
return f
end
CreateFrame(nil, "UIParent")
CreateFrame(nil, "DEFAULT_CHAT_FRAME")
loadstring = loadstring or load
geterrorhandler = Const(Fn)
seterrorhandler = Fn
wipe = function (t) for i in pairs(t) do t[i] = nil end end
issecurevariable = Const(false)
hooksecurefunc = function (tbl, name, fn)
if not fn then tbl, name, fn = _G, tbl, name end
local orig = tbl[name]
tbl[name] = function (...) local r = {orig(...)} fn(...) return unpack(r) end
end
string.split = function (del, str, n)
local t, i = {}, 0
local push = function (v) i = i + 1 if n and i > n then t[n] = t[n] .. del .. v else table.insert(t, v) end end
for a, b in string.gmatch(str, "([^" .. del .. "]*)" .. del .. "([^" .. del .. "]*)") do
if i == 0 or a:len() > 0 or b:len() == 0 then push(a) end
if i == 1 or b:len() > 0 then push(b) end
end
if i == 0 then table.insert(t, str) end
return unpack(t)
end
string.trim = function (s) return s:match("^%s*(.-)%s*$") end
strsplit = string.split
strmatch = string.match
strtrim = string.trim
strlen = string.len
format = string.format
tinsert = table.insert
tremove = table.remove
unpack = unpack or table.unpack
time = function (...) return math.floor(os.time(...)) end
max = math.max
min = math.min
ceil = math.ceil
floor = math.floor
GetClassInfo = function (i)
local c = CLASSES[i]
return c, c:upper():gsub(" ", "_"), i
end
GetLocale = Const(LOCALE)
GetRealmName = Const(REALM)
GetAutoCompleteRealms = Const(REALM_CONNECTED)
GetCurrentRegion = Const(REGION)
GetBuildInfo = Consts(unpack(BUILD))
GetAddOnMetadata = Val(VERSION)
GetTime = function (...) return math.floor(os.clock(...)) end
GetInstanceInfo = Fn
GetLootRollTimeLeft = Val(0)
GetLootRollItemInfo = Fn
GetLootRollItemLink = Fn
RollOnLoot = Fn
GroupLootContainer_RemoveFrame = Fn
SetLootRollItem = Fn
SetItemRef = Fn
UnitPopup_ShowMenu = Fn
UnitName = function (u) local unit, realm = strsplit("-", u) return unit, realm ~= GetRealmName() and realm or nil end
UnitFullName = UnitName
UnitClass = Vals(GetClassInfo(CLASS))
UnitRace = Vals(RACES[RACE], RACES[RACE], RACE)
UnitFactionGroup = Vals(FACTION, FACTION)
UnitGUID = Val(GUID)
UnitLevel = Val(LEVEL)
UnitIsUnit = function (a, b) return a and a == b end
UnitExists = Val(true)
UnitInParty = Val(false)
UnitInRaid = Val(false)
UnitIsDND = Val(false)
RegisterAddonMessagePrefix = Fn
IsInInstance = Const(false)
IsAddOnLoaded = function (n) return n == "WoWUnit" or n == Name end
InterfaceOptions_AddCategory = Fn
IsLoggedIn = Const(false)
GetNumGroupMembers = Const(0)
IsInGroup = Const(false)
IsInRaid = Const(false)
IsEquippableItem = Val(true)
ChatFrame_AddMessageEventFilter = Fn
GetGuildInfo = Fn
GetNumFriends = Const(0)
C_ChallengeMode = Obj
C_Club = { GetSubscribedClubs = Const({}) }
C_Timer = { After = function (t, fn) fn() end }
StaticPopupDialogs = {}
SlashCmdList = {}
AlertFrame = CreateFrame()
TRADE = "Trade"
PARTY = "Party"
RAID = "Raid"
GUILD = "Guild"
RAID_FINDER_PVEFRAME = "Raid Finder"
LOOKING_FOR_DUNGEON_PVEFRAME = "Dungeon Finder"
CLUB_FINDER_COMMUNITY_TYPE = "Community"
LE_UNIT_STAT_STRENGTH = 1
LE_UNIT_STAT_AGILITY = 2
LE_UNIT_STAT_INTELLECT = 4
ITEM_LEVEL = "Item Level %d"
ITEM_LEVEL_ALT = "Item Level %d (%d)"
ITEM_MIN_LEVEL = "Requires Level %d"
ITEM_LEVEL_RANGE = "Requires level %d to %d"
RELIC_TOOLTIP_TYPE = "%s Artifact Relic"
ITEM_CLASSES_ALLOWED = "Classes: %s"
ITEM_REQ_SPECIALIZATION = "Requires: %s"
ITEM_MOD_STRENGTH = "%c%s Strength"
ITEM_MOD_INTELLECT = "%c%s Intellect"
ITEM_MOD_AGILITY = "%c%s Agility"
ITEM_SOULBOUND = "Soulbound"
BIND_TRADE_TIME_REMAINING = "You may trade this item with players that were also eligible to loot this item for the next %s."
TRANSMOGRIFY_TOOLTIP_APPEARANCE_KNOWN = "You've collected this appearance"
TRANSMOGRIFY_TOOLTIP_APPEARANCE_UNKNOWN = "You haven't collected this appearance"
TRANSMOGRIFY_TOOLTIP_ITEM_UNKNOWN_APPEARANCE_KNOWN = "You've collected this appearance, but not from this item"
ERR_JOINED_GROUP_S = "%s joins the party."
ERR_INSTANCE_GROUP_ADDED_S = "%s has joined the instance group."
ERR_RAID_MEMBER_ADDED_S = "%s has joined the raid group."
ERR_LEFT_GROUP_S = "%s leaves the party."
ERR_INSTANCE_GROUP_REMOVED_S = "%s has left the instance group."
ERR_RAID_MEMBER_REMOVED_S = "%s has left the raid group."
AUTOFOLLOWSTART = "Following %s."
HIGHLIGHT_FONT_COLOR_CODE = ""
FONT_COLOR_CODE_CLOSE = ""
DIFFICULTY_DUNGEON_NORMAL = 1
DIFFICULTY_DUNGEON_HEROIC = 2
DIFFICULTY_RAID10_NORMAL = 3
DIFFICULTY_RAID25_NORMAL = 4
DIFFICULTY_RAID10_HEROIC = 5
DIFFICULTY_RAID25_HEROIC = 6
DIFFICULTY_RAID_LFR = 7
DIFFICULTY_DUNGEON_CHALLENGE = 8
DIFFICULTY_RAID40 = 9
DIFFICULTY_PRIMARYRAID_NORMAL = 14
DIFFICULTY_PRIMARYRAID_HEROIC = 15
DIFFICULTY_PRIMARYRAID_MYTHIC = 16
DIFFICULTY_PRIMARYRAID_LFR = 17
LE_PARTY_CATEGORY_INSTANCE = 2
NUM_GROUP_LOOT_FRAMES = 0
NUM_CHAT_WINDOWS = 0
LOOT_ITEM_BONUS_ROLL ="%s receives bonus loot: %s."
CREATED_ITEM ="%s creates: %s."
LOOT_ITEM_CREATED_SELF ="You create: %s."
RANDOM_ROLL_RESULT ="%s rolls %d (%d-%d)"
LE_ITEM_QUALITY_COMMON = 2
LE_ITEM_QUALITY_RARE = 3
LE_ITEM_QUALITY_EPIC = 4
LE_ITEM_QUALITY_LEGENDARY = 5
MAX_PLAYER_LEVEL = 120
NUM_BAG_SLOTS = 0
RAID_CLASS_COLORS = setmetatable({}, {__index = function () return {colorStr = "ffffffff", r = 1, g = 1, b = 1} end})
Enum = {
ClubType = { BattleNet = 0, Character = 1, Guild = 2, Other = 3 }
}
PLR_AwardLootButtonNormalText = CreateFrame()
-------------------------------------------------------
-- Run tests --
-------------------------------------------------------
-- Import WoWUnit
CreateFrame(nil, "WoWUnit")
import("Libs.WoWUnit.Classes.Group")
import("Libs.WoWUnit.Classes.Test")
import("Libs.WoWUnit.WoWUnit.lua")
fire("ADDON_LOADED", "WoWUnit")
-- Import addon
import(importPath .. "/" .. Name .. ".toc")
if options.build then
import("Tests.tests")
end
Addon.ScheduleRepeatingTimer = Addon.ScheduleTimer
fire("ADDON_LOADED", Name)
-- Startup process
fire("SPELLS_CHANGED")
IsLoggedIn = Const(true)
fire("PLAYER_LOGIN")
fire("PLAYER_ENTERING_WORLD")
fire("PLAYER_ALIVE")
update()
-- Run tests
print("[Testing]")
WoWUnit:RunTests("PLAYER_LOGIN")
-- Gather results
local passedGroups = 0
for _,group in ipairs(WoWUnit.children) do
local failed = {}
for i,test in ipairs(group.children) do
if test.numOk ~= 1 then table.insert(failed, i) end
end
print(group.name .. ": " .. (#failed == 0 and "Passed" or "FAILED") .. " (" .. (#group.children - #failed) .. "/" .. #group.children .. ")")
for _,i in ipairs(failed) do
local test = group.children[i]
print(" - " .. test.name .. " (" .. i .. "): " .. table.concat(test.errors, ", "):gsub("|n|n", ""):gsub("|n", " "))
end
passedGroups = passedGroups + (#failed == 0 and 1 or 0)
end
-- Show results
local success = passedGroups == #WoWUnit.children
print("[Result]: " .. (success and "Passed" or "FAILED") .. " (" .. passedGroups .. "/" .. #WoWUnit.children .. ")")
os.exit(not success and 1 or 0)