|
| 1 | +// GENERATED BY textFileToGoConst |
| 2 | +// GitHub: github.com/logrusorgru/textFileToGoConst |
| 3 | +// input file: assertions.lua |
| 4 | +// generated: Fri Nov 11 12:42:15 PST 2022 |
| 5 | + |
| 6 | +package tests |
| 7 | + |
| 8 | +const lua_assertions = `local assertions = { |
| 9 | + fail_now = false, |
| 10 | +} |
| 11 | +
|
| 12 | +function assertions:new(o) |
| 13 | + o = o or {} -- create object if user does not provide one |
| 14 | + setmetatable(o, self) |
| 15 | + self.__index = self |
| 16 | + return o |
| 17 | +end |
| 18 | +
|
| 19 | +function assertions:__call(...) |
| 20 | + assert(self.call, 'attempt to call a non-function object') |
| 21 | + return self.call(...) |
| 22 | +end |
| 23 | +
|
| 24 | +function assertions:Fail(t, ...) |
| 25 | + t:LogHelper(2, ...) |
| 26 | + if self.fail_now then |
| 27 | + print("Failing now") |
| 28 | + t:FailNow() |
| 29 | + else |
| 30 | + print("Failing") |
| 31 | + t:Fail() |
| 32 | + end |
| 33 | + return false |
| 34 | +end |
| 35 | +
|
| 36 | +function assertions:Failf(t, fmt, ...) |
| 37 | + t:LogHelperf(2, fmt, ...) |
| 38 | + if self.fail_now then |
| 39 | + t:FailNow() |
| 40 | + else |
| 41 | + t:Fail() |
| 42 | + end |
| 43 | + return false |
| 44 | +end |
| 45 | +
|
| 46 | +function assertions:Equal(t, expected, actual, ...) |
| 47 | + if expected == actual then |
| 48 | + return true |
| 49 | + end |
| 50 | + return self:Fail(t, string.format([[expected "%s"; got "%s"]] .. '\n', expected, actual), ...) |
| 51 | +end |
| 52 | +
|
| 53 | +function assertions:Equalf(t, expected, actual, fmt, ...) |
| 54 | + if expected == actual then |
| 55 | + return true |
| 56 | + end |
| 57 | + return self:Failf(t, string.format([[expected "%s"; got "%s"%s%s]], expected, actual, '\n', fmt), ...) |
| 58 | +end |
| 59 | +
|
| 60 | +function assertions:NotEqual(t, expected, actual, ...) |
| 61 | + if expected ~= actual then |
| 62 | + return true |
| 63 | + end |
| 64 | + return self:Fail(t, string.format([[expected ~= "%s";]] .. '\n', expected), ...) |
| 65 | +end |
| 66 | +
|
| 67 | +function assertions:NotEqualf(t, expected, actual, fmt, ...) |
| 68 | + if expected ~= actual then |
| 69 | + return true |
| 70 | + end |
| 71 | + return self:Failf(t, string.format([[expected ~= "%s"; got "%s"%s%s]], expected, '\n', fmt), ...) |
| 72 | +end |
| 73 | +
|
| 74 | +function assertions:True(t, actual, ...) |
| 75 | + if actual then |
| 76 | + return true |
| 77 | + end |
| 78 | + return self:Fail(t, string.format([[expected true; got %s]] .. '\n', actual), ...) |
| 79 | +end |
| 80 | +
|
| 81 | +function assertions:Truef(t, actual, fmt, ...) |
| 82 | + if actual then |
| 83 | + return true |
| 84 | + end |
| 85 | + return self:Failf(t, string.format([[expected true; got %s%s%s]], actual, '\n', fmt), ...) |
| 86 | +end |
| 87 | +
|
| 88 | +return assertions |
| 89 | +` |
0 commit comments