Skip to content

Commit

Permalink
Merge pull request #55 from scr-oath/add-nilness-and-greater
Browse files Browse the repository at this point in the history
Add Nil, NotNil, Greater, GreaterOrEqual, Less, LessOrEqual and ..f variants.
  • Loading branch information
scr-oath authored Nov 17, 2022
2 parents bcf14a6 + 843c1d9 commit 7f3dbcf
Show file tree
Hide file tree
Showing 7 changed files with 356 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/assert_const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// GENERATED BY textFileToGoConst
// GitHub: github.com/logrusorgru/textFileToGoConst
// input file: assert.lua
// generated: Fri Nov 11 18:29:58 PST 2022
// generated: Wed Nov 16 13:31:38 PST 2022

package tests

Expand Down
138 changes: 134 additions & 4 deletions tests/assertions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ function assertions:__call(...)
end

function assertions:cleanseString(s)
-- Protect against nil
if s == nil then
return s
end
s = string.gsub(s, '\n', '\\n')
s = string.gsub(s, '\t', '\\t')
s = string.gsub(s, '\r', '\\r')
Expand Down Expand Up @@ -155,25 +159,151 @@ Messages: %s
]], err, fmt), ...)
end

function assertions:NotNil(t, object, ...)
if object ~= nil then
return true
end
return self:Fail(t, string.format([[
Error: Expected value not to be nil.
Messages: ]]), ...)
end

function assertions:NotNilf(t, object, fmt, ...)
if object ~= nil then
return true
end
return self:Failf(t, string.format([[
Error: Expected value not to be nil.
Messages: %s
]], fmt), ...)
end

function assertions:Nil(t, object, ...)
if object == nil then
return true
end
return self:Fail(t, string.format([[
Error: Expected nil but got "%s"
Messages: ]], object), ...)
end

function assertions:Nilf(t, object, fmt, ...)
if object == nil then
return true
end
return self:Failf(t, string.format([[
Error: Expected nil but got "%s"
Messages: %s
]], object, fmt), ...)
end

function assertions:Error(t, err, ...)
if err then
return true
end
return self:Fail(t, string.format([[
return self:Failf(t, string.format([[
Error: An error is expected but got nil.
Messages: ]], err), ...)
Messages: ]]), ...)
end

function assertions:Errorf(t, err, fmt, ...)
if err then
return true
end
return self:Fail(t, string.format([[
return self:Failf(t, string.format([[
Error: An error is expected but got nil.
Messages: %s
]], err, fmt), ...)
]], fmt), ...)
end

function assertions:Greater(t, x, y, ...)
if x > y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not greater than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end

function assertions:Greaterf(t, x, y, fmt, ...)
if x > y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not greater than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end

function assertions:GreaterOrEqual(t, x, y, ...)
if x >= y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not greater or equal than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end

function assertions:GreaterOrEqualf(t, x, y, fmt, ...)
if x >= y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not greater or equal than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end

function assertions:Less(t, x, y, ...)
if x < y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not less than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end

function assertions:Lessf(t, x, y, fmt, ...)
if x < y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not less than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end

function assertions:LessOrEqual(t, x, y, ...)
if x <= y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not less or equal than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end

function assertions:LessOrEqualf(t, x, y, fmt, ...)
if x <= y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not less or equal than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end

return assertions
140 changes: 135 additions & 5 deletions tests/assertions_const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// GENERATED BY textFileToGoConst
// GitHub: github.com/logrusorgru/textFileToGoConst
// input file: assertions.lua
// generated: Fri Nov 11 18:29:57 PST 2022
// generated: Wed Nov 16 13:31:38 PST 2022

package tests

Expand All @@ -22,6 +22,10 @@ function assertions:__call(...)
end
function assertions:cleanseString(s)
-- Protect against nil
if s == nil then
return s
end
s = string.gsub(s, '\n', '\\n')
s = string.gsub(s, '\t', '\\t')
s = string.gsub(s, '\r', '\\r')
Expand Down Expand Up @@ -162,25 +166,151 @@ Messages: %s
]], err, fmt), ...)
end
function assertions:NotNil(t, object, ...)
if object ~= nil then
return true
end
return self:Fail(t, string.format([[
Error: Expected value not to be nil.
Messages: ]]), ...)
end
function assertions:NotNilf(t, object, fmt, ...)
if object ~= nil then
return true
end
return self:Failf(t, string.format([[
Error: Expected value not to be nil.
Messages: %s
]], fmt), ...)
end
function assertions:Nil(t, object, ...)
if object == nil then
return true
end
return self:Fail(t, string.format([[
Error: Expected nil but got "%s"
Messages: ]], object), ...)
end
function assertions:Nilf(t, object, fmt, ...)
if object == nil then
return true
end
return self:Failf(t, string.format([[
Error: Expected nil but got "%s"
Messages: %s
]], object, fmt), ...)
end
function assertions:Error(t, err, ...)
if err then
return true
end
return self:Fail(t, string.format([[
return self:Failf(t, string.format([[
Error: An error is expected but got nil.
Messages: ]], err), ...)
Messages: ]]), ...)
end
function assertions:Errorf(t, err, fmt, ...)
if err then
return true
end
return self:Fail(t, string.format([[
return self:Failf(t, string.format([[
Error: An error is expected but got nil.
Messages: %s
]], err, fmt), ...)
]], fmt), ...)
end
function assertions:Greater(t, x, y, ...)
if x > y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not greater than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end
function assertions:Greaterf(t, x, y, fmt, ...)
if x > y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not greater than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end
function assertions:GreaterOrEqual(t, x, y, ...)
if x >= y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not greater or equal than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end
function assertions:GreaterOrEqualf(t, x, y, fmt, ...)
if x >= y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not greater or equal than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end
function assertions:Less(t, x, y, ...)
if x < y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not less than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end
function assertions:Lessf(t, x, y, fmt, ...)
if x < y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not less than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end
function assertions:LessOrEqual(t, x, y, ...)
if x <= y then
return true
end
return self:Fail(t, string.format([[
Error: "%s" is not less or equal than "%s"
Messages: ]], tostring(x), tostring(y)), ...)
end
function assertions:LessOrEqualf(t, x, y, fmt, ...)
if x <= y then
return true
end
return self:Failf(t, string.format([[
Error: "%s" is not less or equal than "%s"
Messages: %s
]], tostring(x), tostring(y), fmt), ...)
end
return assertions
Expand Down
2 changes: 1 addition & 1 deletion tests/lua_const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// GENERATED BY textFileToGoConst
// GitHub: github.com/logrusorgru/textFileToGoConst
// input file: suite.lua
// generated: Fri Nov 11 18:29:56 PST 2022
// generated: Wed Nov 16 13:31:37 PST 2022

package tests

Expand Down
2 changes: 1 addition & 1 deletion tests/require_const.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// GENERATED BY textFileToGoConst
// GitHub: github.com/logrusorgru/textFileToGoConst
// input file: require.lua
// generated: Fri Nov 11 18:29:59 PST 2022
// generated: Wed Nov 16 13:31:39 PST 2022

package tests

Expand Down
Loading

0 comments on commit 7f3dbcf

Please sign in to comment.