forked from Mirroar/wowUnit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasserts.lua
More file actions
139 lines (120 loc) · 3.42 KB
/
asserts.lua
File metadata and controls
139 lines (120 loc) · 3.42 KB
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
do -- string.format prints nils now: %s -> %t
local format = string.format
function strF(str, ...)
local args = {...}
local boolargs = {}
str = str:gsub("%%t", "%%%%t")
for i = #args, 1, -1 do
--if type(args[i]) == "boolean" or type(args[i]) == "nil" then
table.insert(boolargs, 1, args[i])
--table.remove(args, i)
--end
end
str = format(str, unpack(args))
local j = 0
return (str:gsub("%%t", function(spec) j = j + 1; return tostring(boolargs[j]) end))
end
end
function wowUnit:expect(numTests)
wowUnit.currentTestResults.expect = numTests;
end
function wowUnit:assert(value, message)
if (value) then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message.." Expected: true");
end
end
function wowUnit:assertEquals(value1, value2, message)
if (value1 == value2) then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message);
end
end
function wowUnit:assertNonEquals(value1, value2, message)
if (value1 ~= value2) then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message);
end
end
function wowUnit:assertSame(value1, value2, message)
if (type(value1) == "table" and type(value2) == "table") then
if (wowUnit:DeepEquals(value1, value2)) then
wowUnit:CurrentTestSucceeded(message);
else
value1 = tostring(value1)
value2 = tostring(value2)
wowUnit:CurrentTestFailed(message);
end
else
wowUnit:assertEquals(value1, value2, message);
end
end
function wowUnit:DeepEquals(table1, table2)
if (table1 == table2) then
return true;
else
for k, v1 in pairs(table1) do
local v2 = table2[k];
if v1 ~= v2 then
if (type(v1) == "table" and type(v2) == "table") then
if not wowUnit:DeepEquals(v1, v2) then
return false;
end
else
return false;
end
end
end
for k, v2 in pairs(table2) do
local v1 = table1[k];
if v1 ~= v2 then
if (type(v1) == "table" and type(v2) == "table") then
if not wowUnit:DeepEquals(v1, v2) then
return false;
end
else
return false;
end
end
end
end
return true;
end
function wowUnit:isTable(value, message)
if (type(value) == "table")then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message)
end
end
function wowUnit:isString(value, message)
if (type(value) == "string") then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message)
end
end
function wowUnit:isNumber(value, message)
if (type(value) == "number") then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message)
end
end
function wowUnit:isNil(value, message)
if (type(value) == "nil") then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message)
end
end
function wowUnit:isFunction(value, message)
if (type(value) == "function") then
wowUnit:CurrentTestSucceeded(message);
else
wowUnit:CurrentTestFailed(message);
end
end