Skip to content

Commit 604a154

Browse files
committed
Use the new assertions in base64 tests.
1 parent 4cab9bd commit 604a154

File tree

7 files changed

+60
-24
lines changed

7 files changed

+60
-24
lines changed

base64/test/test_api.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function TestEncodeToString(t)
3232
for _, tt in ipairs(tests) do
3333
t:Run(tt.name, function(t)
3434
local got = tt.encoder:encode_to_string(tt.input)
35-
assert:Equal(t, tt.expected , got)
35+
assert:Equal(t, tt.expected, got)
3636
end)
3737
end
3838
end
@@ -68,11 +68,11 @@ function TestDecodeString(t)
6868
t:Run(tt.name, function(t)
6969
local got, err = tt.encoder:decode_string(tt.input)
7070
if tt.want_err then
71-
assert(err, "expected err")
71+
assert:Error(t, err)
7272
return
7373
end
74-
assert(not err, err)
75-
assert(tt.expected == got, string.format("'%s' ~= '%s'", tt.expected, got))
74+
assert:NoError(t, err)
75+
assert:Equal(t, tt.expected, got)
7676
end)
7777
end
7878
end
@@ -104,8 +104,8 @@ function TestEncodeDecode(t)
104104
t:Run(tt.name, function(t)
105105
local encoded = tt.encoder:encode_to_string(tt.input)
106106
local decoded, err = tt.encoder:decode_string(encoded)
107-
assert(not err, err)
108-
assert(tt.input == decoded, string.format("'%s' ~= '%s'", tt.input, decoded))
107+
assert:NoError(t, err)
108+
assert:Equal(t, tt.input, decoded)
109109
end)
110110
end
111111
end
@@ -116,42 +116,42 @@ function TestEncoder(t)
116116
encoder:write("foo", "bar", "baz")
117117
encoder:close()
118118
local s = writer:string()
119-
assert(s == "Zm9vYmFyYmF6", string.format("'%s' ~= '%s'", s, "Zm9vYmFyYmF6"))
119+
assert:Equal(t, "Zm9vYmFyYmF6", s)
120120
end
121121

122122
function TestDecoder(t)
123123
local reader = strings.new_reader("Zm9vYmFyYmF6")
124124
local decoder = base64.new_decoder(base64.StdEncoding, reader)
125125
local s = decoder:read("*a")
126-
assert(s == "foobarbaz", string.format("'%s' ~= '%s'", s, "foobarbaz"))
126+
assert:Equal(t, "foobarbaz", s)
127127
end
128128

129129
function TestDecoderReadNum(t)
130130
local encoded = base64.StdEncoding:encode_to_string("123 456 789")
131131
local reader = strings.new_reader(encoded)
132132
local decoder = base64.new_decoder(base64.StdEncoding, reader)
133133
local n = decoder:read("*n")
134-
assert(n == 123, string.format("%d ~= %d", n, 123))
134+
assert:Equal(t, 123, n)
135135
n = decoder:read("*n")
136-
assert(n == 456, string.format("%d ~= %d", n, 456))
136+
assert:Equal(t, 456, n)
137137
n = decoder:read("*n")
138-
assert(n == 789, string.format("%d ~= %d", n, 789))
138+
assert:Equal(t, 789, n)
139139
end
140140

141141
function TestDecoderReadCount(t)
142142
local encoded = base64.StdEncoding:encode_to_string("123 456 789")
143143
local reader = strings.new_reader(encoded)
144144
local decoder = base64.new_decoder(base64.StdEncoding, reader)
145145
local s = decoder:read(3)
146-
assert(s == "123", string.format("'%s' ~= '%s'", s, "123"))
146+
assert:Equal(t, "123", s)
147147
end
148148

149149
function TestDecoderReadline(t)
150150
local encoded = base64.StdEncoding:encode_to_string("foo\nbar")
151151
local reader = strings.new_reader(encoded)
152152
local decoder = base64.new_decoder(base64.StdEncoding, reader)
153153
local s = decoder:read("*l")
154-
assert(s == "foo", string.format("'%s' ~= '%s'", s, "foo"))
154+
assert:Equal(t, "foo", s)
155155
s = decoder:read("*l")
156-
assert(s == "bar", string.format("'%s' ~= '%s'", s, "bar"))
156+
assert:Equal(t, "bar", s)
157157
end

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:27:20 PST 2022
4+
// generated: Fri Nov 11 18:29:58 PST 2022
55

66
package tests
77

tests/assertions.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,25 @@ Messages: %s
155155
]], err, fmt), ...)
156156
end
157157

158+
function assertions:Error(t, err, ...)
159+
if err then
160+
return true
161+
end
162+
return self:Fail(t, string.format([[
163+
164+
Error: An error is expected but got nil.
165+
Messages: ]], err), ...)
166+
end
167+
168+
function assertions:Errorf(t, err, fmt, ...)
169+
if err then
170+
return true
171+
end
172+
return self:Fail(t, string.format([[
173+
174+
Error: An error is expected but got nil.
175+
Messages: %s
176+
]], err, fmt), ...)
177+
end
178+
158179
return assertions

tests/assertions_const.go

Lines changed: 22 additions & 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: assertions.lua
4-
// generated: Fri Nov 11 18:27:19 PST 2022
4+
// generated: Fri Nov 11 18:29:57 PST 2022
55

66
package tests
77

@@ -162,5 +162,26 @@ Messages: %s
162162
]], err, fmt), ...)
163163
end
164164
165+
function assertions:Error(t, err, ...)
166+
if err then
167+
return true
168+
end
169+
return self:Fail(t, string.format([[
170+
171+
Error: An error is expected but got nil.
172+
Messages: ]], err), ...)
173+
end
174+
175+
function assertions:Errorf(t, err, fmt, ...)
176+
if err then
177+
return true
178+
end
179+
return self:Fail(t, string.format([[
180+
181+
Error: An error is expected but got nil.
182+
Messages: %s
183+
]], err, fmt), ...)
184+
end
185+
165186
return assertions
166187
`

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:27:19 PST 2022
4+
// generated: Fri Nov 11 18:29:56 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:27:21 PST 2022
4+
// generated: Fri Nov 11 18:29:59 PST 2022
55

66
package tests
77

tests/testutil_test.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,3 @@ func TestAssertions(t *testing.T) {
3232
assert.NotZero(t, RunLuaTestFile(t, preload, "testdata/test_assertions_failing.lua"))
3333
})
3434
}
35-
36-
func TestFail(t *testing.T) {
37-
assert.Equal(t, "foo", "bar", "yikes", "bob")
38-
assert.True(t, false, "another message")
39-
assert.NotEqual(t, 123, 123)
40-
}

0 commit comments

Comments
 (0)