-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathasserts.lua
More file actions
124 lines (112 loc) · 3.19 KB
/
asserts.lua
File metadata and controls
124 lines (112 loc) · 3.19 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
function wowUnit:expect(numTests)
wowUnit.currentTestResults.expect = numTests
end
function wowUnit:assert(value, message)
if (value) then
wowUnit:CurrentTestSucceeded(message)
else
wowUnit:CurrentTestFailed(message)
end
end
function wowUnit:assertEquals(value1, value2, message)
if (value1 == value2) then
wowUnit:CurrentTestSucceeded(message)
else
wowUnit:CurrentTestFailed(message..' ('..tostringall(value2)..' expected, got '..tostringall(value1)..')')
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
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:isEmpty(value, message)
if (type(value) == "table") then
for _, _ in pairs(value) do
wowUnit:CurrentTestFailed(message)
return
end
wowUnit:CurrentTestSucceeded(message)
else
wowUnit:isNil(value, message)
end
end
function wowUnit:isFunction(value, message)
if (type(value) == "function") then
wowUnit:CurrentTestSucceeded(message)
else
wowUnit:CurrentTestFailed(message)
end
end