11// GENERATED BY textFileToGoConst
22// GitHub: github.com/logrusorgru/textFileToGoConst
33// input file: assertions.lua
4- // generated: Fri Nov 11 18:29:57 PST 2022
4+ // generated: Wed Nov 16 13:31:38 PST 2022
55
66package tests
77
@@ -22,6 +22,10 @@ function assertions:__call(...)
2222end
2323
2424function assertions:cleanseString(s)
25+ -- Protect against nil
26+ if s == nil then
27+ return s
28+ end
2529 s = string.gsub(s, '\n', '\\n')
2630 s = string.gsub(s, '\t', '\\t')
2731 s = string.gsub(s, '\r', '\\r')
@@ -162,25 +166,151 @@ Messages: %s
162166]], err, fmt), ...)
163167end
164168
169+ function assertions:NotNil(t, object, ...)
170+ if object ~= nil then
171+ return true
172+ end
173+ return self:Fail(t, string.format([[
174+
175+ Error: Expected value not to be nil.
176+ Messages: ]]), ...)
177+ end
178+
179+ function assertions:NotNilf(t, object, fmt, ...)
180+ if object ~= nil then
181+ return true
182+ end
183+ return self:Failf(t, string.format([[
184+
185+ Error: Expected value not to be nil.
186+ Messages: %s
187+ ]], fmt), ...)
188+ end
189+
190+ function assertions:Nil(t, object, ...)
191+ if object == nil then
192+ return true
193+ end
194+ return self:Fail(t, string.format([[
195+
196+ Error: Expected nil but got "%s"
197+ Messages: ]], object), ...)
198+ end
199+
200+ function assertions:Nilf(t, object, fmt, ...)
201+ if object == nil then
202+ return true
203+ end
204+ return self:Failf(t, string.format([[
205+
206+ Error: Expected nil but got "%s"
207+ Messages: %s
208+ ]], object, fmt), ...)
209+ end
210+
165211function assertions:Error(t, err, ...)
166212 if err then
167213 return true
168214 end
169- return self:Fail (t, string.format([[
215+ return self:Failf (t, string.format([[
170216
171217Error: An error is expected but got nil.
172- Messages: ]], err ), ...)
218+ Messages: ]]), ...)
173219end
174220
175221function assertions:Errorf(t, err, fmt, ...)
176222 if err then
177223 return true
178224 end
179- return self:Fail (t, string.format([[
225+ return self:Failf (t, string.format([[
180226
181227Error: An error is expected but got nil.
182228Messages: %s
183- ]], err, fmt), ...)
229+ ]], fmt), ...)
230+ end
231+
232+ function assertions:Greater(t, x, y, ...)
233+ if x > y then
234+ return true
235+ end
236+ return self:Fail(t, string.format([[
237+
238+ Error: "%s" is not greater than "%s"
239+ Messages: ]], tostring(x), tostring(y)), ...)
240+ end
241+
242+ function assertions:Greaterf(t, x, y, fmt, ...)
243+ if x > y then
244+ return true
245+ end
246+ return self:Failf(t, string.format([[
247+
248+ Error: "%s" is not greater than "%s"
249+ Messages: %s
250+ ]], tostring(x), tostring(y), fmt), ...)
251+ end
252+
253+ function assertions:GreaterOrEqual(t, x, y, ...)
254+ if x >= y then
255+ return true
256+ end
257+ return self:Fail(t, string.format([[
258+
259+ Error: "%s" is not greater or equal than "%s"
260+ Messages: ]], tostring(x), tostring(y)), ...)
261+ end
262+
263+ function assertions:GreaterOrEqualf(t, x, y, fmt, ...)
264+ if x >= y then
265+ return true
266+ end
267+ return self:Failf(t, string.format([[
268+
269+ Error: "%s" is not greater or equal than "%s"
270+ Messages: %s
271+ ]], tostring(x), tostring(y), fmt), ...)
272+ end
273+
274+ function assertions:Less(t, x, y, ...)
275+ if x < y then
276+ return true
277+ end
278+ return self:Fail(t, string.format([[
279+
280+ Error: "%s" is not less than "%s"
281+ Messages: ]], tostring(x), tostring(y)), ...)
282+ end
283+
284+ function assertions:Lessf(t, x, y, fmt, ...)
285+ if x < y then
286+ return true
287+ end
288+ return self:Failf(t, string.format([[
289+
290+ Error: "%s" is not less than "%s"
291+ Messages: %s
292+ ]], tostring(x), tostring(y), fmt), ...)
293+ end
294+
295+ function assertions:LessOrEqual(t, x, y, ...)
296+ if x <= y then
297+ return true
298+ end
299+ return self:Fail(t, string.format([[
300+
301+ Error: "%s" is not less or equal than "%s"
302+ Messages: ]], tostring(x), tostring(y)), ...)
303+ end
304+
305+ function assertions:LessOrEqualf(t, x, y, fmt, ...)
306+ if x <= y then
307+ return true
308+ end
309+ return self:Failf(t, string.format([[
310+
311+ Error: "%s" is not less or equal than "%s"
312+ Messages: %s
313+ ]], tostring(x), tostring(y), fmt), ...)
184314end
185315
186316return assertions
0 commit comments