aboutsummaryrefslogtreecommitdiff
path: root/test/mimetest.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/mimetest.lua')
-rw-r--r--test/mimetest.lua13
1 files changed, 10 insertions, 3 deletions
diff --git a/test/mimetest.lua b/test/mimetest.lua
index 2f6b7a8..f52a351 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -39,9 +39,13 @@ local mao = [[
39local function random(handle, io_err) 39local function random(handle, io_err)
40 if handle then 40 if handle then
41 return function() 41 return function()
42 if not handle then error("source is empty!", 2) end
42 local len = math.random(0, 1024) 43 local len = math.random(0, 1024)
43 local chunk = handle:read(len) 44 local chunk = handle:read(len)
44 if not chunk then handle:close() end 45 if not chunk then
46 handle:close()
47 handle = nil
48 end
45 return chunk 49 return chunk
46 end 50 end
47 else return ltn12.source.empty(io_err or "unable to open file") end 51 else return ltn12.source.empty(io_err or "unable to open file") end
@@ -73,6 +77,7 @@ local function encode_qptest(mode)
73end 77end
74 78
75local function compare_qptest() 79local function compare_qptest()
80io.write("testing qp encoding and wrap: ")
76 compare(qptest, dqptest) 81 compare(qptest, dqptest)
77end 82end
78 83
@@ -173,7 +178,6 @@ local function encode_b64test()
173 local sp2 = mime.wrap("base64", 30) 178 local sp2 = mime.wrap("base64", 30)
174 local sp1 = mime.wrap(27) 179 local sp1 = mime.wrap(27)
175 local chain = ltn12.filter.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4) 180 local chain = ltn12.filter.chain(e1, sp1, e2, sp2, e3, sp3, e4, sp4)
176 chain = socket.protect(chain)
177 transform(b64test, eb64test, chain) 181 transform(b64test, eb64test, chain)
178end 182end
179 183
@@ -193,10 +197,12 @@ local function cleanup_b64test()
193end 197end
194 198
195local function compare_b64test() 199local function compare_b64test()
200io.write("testing b64 chained encode: ")
196 compare(b64test, db64test) 201 compare(b64test, db64test)
197end 202end
198 203
199local function identity_test() 204local function identity_test()
205io.write("testing identity: ")
200 local chain = named(ltn12.filter.chain( 206 local chain = named(ltn12.filter.chain(
201 named(mime.encode("quoted-printable"), "1 eq"), 207 named(mime.encode("quoted-printable"), "1 eq"),
202 named(mime.encode("base64"), "2 eb"), 208 named(mime.encode("base64"), "2 eb"),
@@ -223,11 +229,12 @@ local function chunkcheck(original, encoded)
223 local b = string.sub(original, i+1) 229 local b = string.sub(original, i+1)
224 local e, r = mime.b64(a, b) 230 local e, r = mime.b64(a, b)
225 local f = (mime.b64(r)) 231 local f = (mime.b64(r))
226 if (e .. f ~= encoded) then fail(e .. f) end 232 if (e .. (f or "") ~= encoded) then fail(e .. (f or "")) end
227 end 233 end
228end 234end
229 235
230local function padding_b64test() 236local function padding_b64test()
237io.write("testing b64 padding: ")
231 padcheck("a", "YQ==") 238 padcheck("a", "YQ==")
232 padcheck("ab", "YWI=") 239 padcheck("ab", "YWI=")
233 padcheck("abc", "YWJj") 240 padcheck("abc", "YWJj")