aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mimetest.lua55
-rw-r--r--test/testsupport.lua2
2 files changed, 49 insertions, 8 deletions
diff --git a/test/mimetest.lua b/test/mimetest.lua
index 4a0a20a..3e57557 100644
--- a/test/mimetest.lua
+++ b/test/mimetest.lua
@@ -34,11 +34,52 @@ local mao = [[
34local function random(handle, io_err) 34local function random(handle, io_err)
35 if handle then 35 if handle then
36 return function() 36 return function()
37 local chunk = handle:read(math.random(0, 1024)) 37 local len = math.random(0, 1024)
38 local chunk = handle:read(len)
38 if not chunk then handle:close() end 39 if not chunk then handle:close() end
39 return chunk 40 return chunk
40 end 41 end
41 else source.empty(io_err or "unable to open file") end 42 else return ltn12.source.empty(io_err or "unable to open file") end
43end
44
45local function format(chunk)
46 if chunk then
47 if chunk == "" then return "''"
48 else return string.len(chunk) end
49 else return "nil" end
50end
51
52local function show(name, input, output)
53 local sin = format(input)
54 local sout = format(output)
55 io.write(name, ": ", sin, " -> ", sout, "\n")
56end
57
58local function chunked(length)
59 local tmp
60 return function(chunk)
61 local ret
62 if chunk and chunk ~= "" then
63 tmp = chunk
64 end
65 ret = string.sub(tmp, 1, length)
66 tmp = string.sub(tmp, length+1)
67 if not chunk and ret == "" then ret = nil end
68 return ret
69 end
70end
71
72--[[
73local function named(f, name)
74 return function(chunk)
75 local ret = f(chunk)
76 show(name, chunk, ret)
77 return ret
78 end
79end
80]]
81local function named(f)
82 return f
42end 83end
43 84
44local what = nil 85local what = nil
@@ -153,11 +194,11 @@ local function encode_b64test()
153end 194end
154 195
155local function decode_b64test() 196local function decode_b64test()
156 local d1 = mime.decode("base64") 197 local d1 = named(mime.decode("base64"), "d1")
157 local d2 = mime.decode("base64") 198 local d2 = named(mime.decode("base64"), "d2")
158 local d3 = mime.decode("base64") 199 local d3 = named(mime.decode("base64"), "d3")
159 local d4 = mime.decode("base64") 200 local d4 = named(mime.decode("base64"), "d4")
160 local chain = ltn12.filter.chain(d1, d2, d3, d4) 201 local chain = named(ltn12.filter.chain(d1, d2, d3, d4), "chain")
161 transform(eb64test, db64test, chain) 202 transform(eb64test, db64test, chain)
162end 203end
163 204
diff --git a/test/testsupport.lua b/test/testsupport.lua
index ca3cd95..acad8f5 100644
--- a/test/testsupport.lua
+++ b/test/testsupport.lua
@@ -1,5 +1,5 @@
1function readfile(name) 1function readfile(name)
2 local f = io.open(name, "r") 2 local f = io.open(name, "rb")
3 if not f then return nil end 3 if not f then return nil end
4 local s = f:read("*a") 4 local s = f:read("*a")
5 f:close() 5 f:close()