11// GENERATED BY textFileToGoConst
22// GitHub: github.com/logrusorgru/textFileToGoConst
33// input file: assertions.lua
4- // generated: Fri Nov 11 12:44:58 PST 2022
4+ // generated: Fri Nov 11 18:08:04 PST 2022
55
66package tests
77
@@ -21,13 +21,20 @@ function assertions:__call(...)
2121 return self.call(...)
2222end
2323
24+ function assertions:cleanseString(s)
25+ s = string.gsub(s, '\n', '\\n')
26+ s = string.gsub(s, '\t', '\\t')
27+ s = string.gsub(s, '\r', '\\r')
28+ return s
29+ end
30+
2431function assertions:Fail(t, ...)
2532 t:LogHelper(2, ...)
2633 if self.fail_now then
27- print("Failing now ")
34+ assert(t.FailNow, "First parameter must be t (the testing.T object) ")
2835 t:FailNow()
2936 else
30- print("Failing ")
37+ assert(t.Fail, "First parameter must be t (the testing.T object) ")
3138 t:Fail()
3239 end
3340 return false
3643function assertions:Failf(t, fmt, ...)
3744 t:LogHelperf(2, fmt, ...)
3845 if self.fail_now then
46+ assert(t.FailNow, "First parameter must be t (the testing.T object)")
3947 t:FailNow()
4048 else
49+ assert(t.Fail, "First parameter must be t (the testing.T object)")
4150 t:Fail()
4251 end
4352 return false
@@ -47,56 +56,89 @@ function assertions:Equal(t, expected, actual, ...)
4756 if expected == actual then
4857 return true
4958 end
50- return self:Fail(t, string.format([[expected "%s"; got "%s"]] .. '\n', expected, actual), ...)
59+ return self:Fail(t, string.format([[
60+
61+ Error: Not equal:
62+ expected: "%s"
63+ actual : "%s"
64+ Messages: ]], self:cleanseString(expected), self:cleanseString(actual)), ...)
5165end
5266
5367function assertions:Equalf(t, expected, actual, fmt, ...)
5468 if expected == actual then
5569 return true
5670 end
57- return self:Failf(t, string.format([[expected "%s"; got "%s"%s%s]], expected, actual, '\n', fmt), ...)
71+ return self:Failf(t, string.format([[
72+
73+ Error: Not equal:
74+ expected: "%s"
75+ actual : "%s"
76+ Messages: %s
77+ ]], self:cleanseString(expected), self:cleanseString(actual), fmt), ...)
5878end
5979
6080function assertions:NotEqual(t, expected, actual, ...)
6181 if expected ~= actual then
6282 return true
6383 end
64- return self:Fail(t, string.format([[expected ~= "%s";]] .. '\n', expected), ...)
84+ return self:Fail(t, string.format([[
85+
86+ Error: Should not be %s
87+ Messages: ]], expected), ...)
6588end
6689
6790function assertions:NotEqualf(t, expected, actual, fmt, ...)
6891 if expected ~= actual then
6992 return true
7093 end
71- return self:Failf(t, string.format([[expected ~= "%s"; got "%s"%s%s]], expected, '\n', fmt), ...)
94+ return self:Failf(t, string.format([[
95+
96+ Error: Should not be %s
97+ Messages: %s
98+ ]], expected, fmt), ...)
7299end
73100
74101function assertions:True(t, actual, ...)
75102 if actual then
76103 return true
77104 end
78- return self:Fail(t, string.format([[expected true; got %s]] .. '\n', actual), ...)
105+ return self:Fail(t, string.format([[
106+
107+ Error: Should be true
108+ Messages: ]]), ...)
79109end
80110
81111function assertions:Truef(t, actual, fmt, ...)
82112 if actual then
83113 return true
84114 end
85- return self:Failf(t, string.format([[expected true; got %s%s%s]], actual, '\n', fmt), ...)
115+ return self:Failf(t, string.format([[
116+
117+ Error: Should be true
118+ Messages: %s
119+ ]], fmt), ...)
120+
86121end
87122
88123function assertions:False(t, actual, ...)
89124 if not actual then
90125 return true
91126 end
92- return self:Fail(t, string.format([[expected false; got %s]] .. '\n', actual), ...)
127+ return self:Fail(t, string.format([[
128+
129+ Error Should be false
130+ Messages: ]]), ...)
93131end
94132
95133function assertions:Falsef(t, actual, fmt, ...)
96134 if not actual then
97135 return true
98136 end
99- return self:Failf(t, string.format([[expected false; got %s%s%s]], actual, '\n', fmt), ...)
137+ return self:Failf(t, string.format([[
138+
139+ Error: Should be false
140+ Messages: %s
141+ ]], fmt), ...)
100142end
101143
102144return assertions
0 commit comments