Skip to content

Commit 7f3dbcf

Browse files
authored
Merge pull request #55 from scr-oath/add-nilness-and-greater
Add Nil, NotNil, Greater, GreaterOrEqual, Less, LessOrEqual and ..f variants.
2 parents bcf14a6 + 843c1d9 commit 7f3dbcf

File tree

7 files changed

+356
-14
lines changed

7 files changed

+356
-14
lines changed

tests/assert_const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// GENERATED BY textFileToGoConst
22
// GitHub: github.com/logrusorgru/textFileToGoConst
33
// input file: assert.lua
4-
// generated: Fri Nov 11 18:29:58 PST 2022
4+
// generated: Wed Nov 16 13:31:38 PST 2022
55

66
package tests
77

tests/assertions.lua

Lines changed: 134 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ function assertions:__call(...)
1515
end
1616

1717
function assertions:cleanseString(s)
18+
-- Protect against nil
19+
if s == nil then
20+
return s
21+
end
1822
s = string.gsub(s, '\n', '\\n')
1923
s = string.gsub(s, '\t', '\\t')
2024
s = string.gsub(s, '\r', '\\r')
@@ -155,25 +159,151 @@ Messages: %s
155159
]], err, fmt), ...)
156160
end
157161

162+
function assertions:NotNil(t, object, ...)
163+
if object ~= nil then
164+
return true
165+
end
166+
return self:Fail(t, string.format([[
167+
168+
Error: Expected value not to be nil.
169+
Messages: ]]), ...)
170+
end
171+
172+
function assertions:NotNilf(t, object, fmt, ...)
173+
if object ~= nil then
174+
return true
175+
end
176+
return self:Failf(t, string.format([[
177+
178+
Error: Expected value not to be nil.
179+
Messages: %s
180+
]], fmt), ...)
181+
end
182+
183+
function assertions:Nil(t, object, ...)
184+
if object == nil then
185+
return true
186+
end
187+
return self:Fail(t, string.format([[
188+
189+
Error: Expected nil but got "%s"
190+
Messages: ]], object), ...)
191+
end
192+
193+
function assertions:Nilf(t, object, fmt, ...)
194+
if object == nil then
195+
return true
196+
end
197+
return self:Failf(t, string.format([[
198+
199+
Error: Expected nil but got "%s"
200+
Messages: %s
201+
]], object, fmt), ...)
202+
end
203+
158204
function assertions:Error(t, err, ...)
159205
if err then
160206
return true
161207
end
162-
return self:Fail(t, string.format([[
208+
return self:Failf(t, string.format([[
163209
164210
Error: An error is expected but got nil.
165-
Messages: ]], err), ...)
211+
Messages: ]]), ...)
166212
end
167213

168214
function assertions:Errorf(t, err, fmt, ...)
169215
if err then
170216
return true
171217
end
172-
return self:Fail(t, string.format([[
218+
return self:Failf(t, string.format([[
173219
174220
Error: An error is expected but got nil.
175221
Messages: %s
176-
]], err, fmt), ...)
222+
]], fmt), ...)
223+
end
224+
225+
function assertions:Greater(t, x, y, ...)
226+
if x > y then
227+
return true
228+
end
229+
return self:Fail(t, string.format([[
230+
231+
Error: "%s" is not greater than "%s"
232+
Messages: ]], tostring(x), tostring(y)), ...)
233+
end
234+
235+
function assertions:Greaterf(t, x, y, fmt, ...)
236+
if x > y then
237+
return true
238+
end
239+
return self:Failf(t, string.format([[
240+
241+
Error: "%s" is not greater than "%s"
242+
Messages: %s
243+
]], tostring(x), tostring(y), fmt), ...)
244+
end
245+
246+
function assertions:GreaterOrEqual(t, x, y, ...)
247+
if x >= y then
248+
return true
249+
end
250+
return self:Fail(t, string.format([[
251+
252+
Error: "%s" is not greater or equal than "%s"
253+
Messages: ]], tostring(x), tostring(y)), ...)
254+
end
255+
256+
function assertions:GreaterOrEqualf(t, x, y, fmt, ...)
257+
if x >= y then
258+
return true
259+
end
260+
return self:Failf(t, string.format([[
261+
262+
Error: "%s" is not greater or equal than "%s"
263+
Messages: %s
264+
]], tostring(x), tostring(y), fmt), ...)
265+
end
266+
267+
function assertions:Less(t, x, y, ...)
268+
if x < y then
269+
return true
270+
end
271+
return self:Fail(t, string.format([[
272+
273+
Error: "%s" is not less than "%s"
274+
Messages: ]], tostring(x), tostring(y)), ...)
275+
end
276+
277+
function assertions:Lessf(t, x, y, fmt, ...)
278+
if x < y then
279+
return true
280+
end
281+
return self:Failf(t, string.format([[
282+
283+
Error: "%s" is not less than "%s"
284+
Messages: %s
285+
]], tostring(x), tostring(y), fmt), ...)
286+
end
287+
288+
function assertions:LessOrEqual(t, x, y, ...)
289+
if x <= y then
290+
return true
291+
end
292+
return self:Fail(t, string.format([[
293+
294+
Error: "%s" is not less or equal than "%s"
295+
Messages: ]], tostring(x), tostring(y)), ...)
296+
end
297+
298+
function assertions:LessOrEqualf(t, x, y, fmt, ...)
299+
if x <= y then
300+
return true
301+
end
302+
return self:Failf(t, string.format([[
303+
304+
Error: "%s" is not less or equal than "%s"
305+
Messages: %s
306+
]], tostring(x), tostring(y), fmt), ...)
177307
end
178308

179309
return assertions

tests/assertions_const.go

Lines changed: 135 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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

66
package tests
77

@@ -22,6 +22,10 @@ function assertions:__call(...)
2222
end
2323
2424
function 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), ...)
163167
end
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+
165211
function 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
171217
Error: An error is expected but got nil.
172-
Messages: ]], err), ...)
218+
Messages: ]]), ...)
173219
end
174220
175221
function 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
181227
Error: An error is expected but got nil.
182228
Messages: %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), ...)
184314
end
185315
186316
return assertions

tests/lua_const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// GENERATED BY textFileToGoConst
22
// GitHub: github.com/logrusorgru/textFileToGoConst
33
// input file: suite.lua
4-
// generated: Fri Nov 11 18:29:56 PST 2022
4+
// generated: Wed Nov 16 13:31:37 PST 2022
55

66
package tests
77

tests/require_const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// GENERATED BY textFileToGoConst
22
// GitHub: github.com/logrusorgru/textFileToGoConst
33
// input file: require.lua
4-
// generated: Fri Nov 11 18:29:59 PST 2022
4+
// generated: Wed Nov 16 13:31:39 PST 2022
55

66
package tests
77

0 commit comments

Comments
 (0)