refactor: Address issues raised by linter
This commit is contained in:
parent
480c052572
commit
601ad8d59f
21 changed files with 187 additions and 198 deletions
|
@ -38,7 +38,7 @@ local function named(f, name)
|
|||
end
|
||||
|
||||
--------------------------------
|
||||
local function split(size)
|
||||
local function split(size)
|
||||
local buffer = ""
|
||||
local last_out = ""
|
||||
local last_in = ""
|
||||
|
@ -50,12 +50,12 @@ local function split(size)
|
|||
return last_out
|
||||
end
|
||||
return function(chunk, done)
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
end
|
||||
-- check if argument is consistent with state
|
||||
if not chunk then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
error("nil chunk following data chunk", 2)
|
||||
end
|
||||
if not last_out then error("extra nil chunk", 2) end
|
||||
|
@ -67,8 +67,8 @@ local function split(size)
|
|||
return output(chunk)
|
||||
else
|
||||
if not last_in then error("data chunk following nil chunk", 2) end
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
end
|
||||
buffer = chunk
|
||||
return output(chunk)
|
||||
|
@ -85,7 +85,7 @@ local function format(chunk)
|
|||
end
|
||||
|
||||
--------------------------------
|
||||
local function merge(size)
|
||||
local function merge(size)
|
||||
local buffer = ""
|
||||
local last_out = ""
|
||||
local last_in = ""
|
||||
|
@ -102,12 +102,12 @@ local function merge(size)
|
|||
return last_out
|
||||
end
|
||||
return function(chunk, done)
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
if done then
|
||||
return not last_in and not last_out
|
||||
end
|
||||
-- check if argument is consistent with state
|
||||
if not chunk then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
if last_in and last_in ~= "" and last_out ~= "" then
|
||||
error("nil chunk following data chunk", 2)
|
||||
end
|
||||
if not last_out then error("extra nil chunk", 2) end
|
||||
|
@ -119,8 +119,8 @@ local function merge(size)
|
|||
return output(chunk)
|
||||
else
|
||||
if not last_in then error("data chunk following nil chunk", 2) end
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
if last_in ~= "" and last_out ~= "" then
|
||||
error("data chunk following data chunk", 2)
|
||||
end
|
||||
buffer = buffer .. chunk
|
||||
return output(chunk)
|
||||
|
|
|
@ -15,27 +15,27 @@ local eb64test = "b64test.bin2"
|
|||
local db64test = "b64test.bin3"
|
||||
|
||||
|
||||
-- from Machado de Assis, "A Mão e a Rosa"
|
||||
-- from Machado de Assis, "A M<EFBFBD>o e a Rosa"
|
||||
local mao = [[
|
||||
Cursavam estes dois moços a academia de S. Paulo, estando
|
||||
Luís Alves no quarto ano e Estêvão no terceiro.
|
||||
Conheceram-se na academia, e ficaram amigos íntimos, tanto
|
||||
quanto podiam sê-lo dois espíritos diferentes, ou talvez por
|
||||
isso mesmo que o eram. Estêvão, dotado de extrema
|
||||
sensibilidade, e não menor fraqueza de ânimo, afetuoso e
|
||||
bom, não daquela bondade varonil, que é apanágio de uma alma
|
||||
forte, mas dessa outra bondade mole e de cera, que vai à
|
||||
mercê de todas as circunstâncias, tinha, além de tudo isso,
|
||||
o infortúnio de trazer ainda sobre o nariz os óculos
|
||||
cor-de-rosa de suas virginais ilusões. Luís Alves via bem
|
||||
com os olhos da cara. Não era mau rapaz, mas tinha o seu
|
||||
grão de egoísmo, e se não era incapaz de afeições, sabia
|
||||
regê-las, moderá-las, e sobretudo guiá-las ao seu próprio
|
||||
Cursavam estes dois mo<EFBFBD>os a academia de S. Paulo, estando
|
||||
Lu<EFBFBD>s Alves no quarto ano e Est<EFBFBD>v<EFBFBD>o no terceiro.
|
||||
Conheceram-se na academia, e ficaram amigos <EFBFBD>ntimos, tanto
|
||||
quanto podiam s<EFBFBD>-lo dois esp<EFBFBD>ritos diferentes, ou talvez por
|
||||
isso mesmo que o eram. Est<EFBFBD>v<EFBFBD>o, dotado de extrema
|
||||
sensibilidade, e n<EFBFBD>o menor fraqueza de <EFBFBD>nimo, afetuoso e
|
||||
bom, n<EFBFBD>o daquela bondade varonil, que <EFBFBD> apan<EFBFBD>gio de uma alma
|
||||
forte, mas dessa outra bondade mole e de cera, que vai <EFBFBD>
|
||||
merc<EFBFBD> de todas as circunst<EFBFBD>ncias, tinha, al<EFBFBD>m de tudo isso,
|
||||
o infort<EFBFBD>nio de trazer ainda sobre o nariz os <EFBFBD>culos
|
||||
cor-de-rosa de suas virginais ilus<EFBFBD>es. Lu<EFBFBD>s Alves via bem
|
||||
com os olhos da cara. N<EFBFBD>o era mau rapaz, mas tinha o seu
|
||||
gr<EFBFBD>o de ego<EFBFBD>smo, e se n<EFBFBD>o era incapaz de afei<EFBFBD><EFBFBD>es, sabia
|
||||
reg<EFBFBD>-las, moder<EFBFBD>-las, e sobretudo gui<EFBFBD>-las ao seu pr<EFBFBD>prio
|
||||
interesse. Entre estes dois homens travara-se amizade
|
||||
íntima, nascida para um na simpatia, para outro no costume.
|
||||
<EFBFBD>ntima, nascida para um na simpatia, para outro no costume.
|
||||
Eram eles os naturais confidentes um do outro, com a
|
||||
diferença que Luís Alves dava menos do que recebia, e, ainda
|
||||
assim, nem tudo o que dava exprimia grande confiança.
|
||||
diferen<EFBFBD>a que Lu<EFBFBD>s Alves dava menos do que recebia, e, ainda
|
||||
assim, nem tudo o que dava exprimia grande confian<EFBFBD>a.
|
||||
]]
|
||||
|
||||
local function random(handle, io_err)
|
||||
|
@ -44,8 +44,8 @@ local function random(handle, io_err)
|
|||
if not handle then error("source is empty!", 2) end
|
||||
local len = math.random(0, 1024)
|
||||
local chunk = handle:read(len)
|
||||
if not chunk then
|
||||
handle:close()
|
||||
if not chunk then
|
||||
handle:close()
|
||||
handle = nil
|
||||
end
|
||||
return chunk
|
||||
|
@ -62,7 +62,7 @@ local what = nil
|
|||
local function transform(input, output, filter)
|
||||
local source = random(io.open(input, "rb"))
|
||||
local sink = ltn12.sink.file(io.open(output, "wb"))
|
||||
if what then
|
||||
if what then
|
||||
sink = ltn12.sink.chain(filter, sink)
|
||||
else
|
||||
source = ltn12.source.chain(source, filter)
|
||||
|
@ -147,7 +147,7 @@ local function create_qptest()
|
|||
f:write(' ',string.char(32))
|
||||
end
|
||||
f:write("\r\n")
|
||||
|
||||
|
||||
f:close()
|
||||
end
|
||||
|
||||
|
@ -157,7 +157,7 @@ local function cleanup_qptest()
|
|||
os.remove(dqptest)
|
||||
end
|
||||
|
||||
-- create test file
|
||||
-- create test file
|
||||
local function create_b64test()
|
||||
local f = assert(io.open(b64test, "wb"))
|
||||
local t = {}
|
||||
|
|
|
@ -27,8 +27,8 @@ local total = function()
|
|||
end
|
||||
|
||||
local similar = function(s1, s2)
|
||||
return
|
||||
string.lower(string.gsub(s1, "%s", "")) ==
|
||||
return
|
||||
string.lower(string.gsub(s1, "%s", "")) ==
|
||||
string.lower(string.gsub(s2, "%s", ""))
|
||||
end
|
||||
|
||||
|
@ -40,9 +40,9 @@ end
|
|||
|
||||
local readfile = function(name)
|
||||
local f = io.open(name, "r")
|
||||
if not f then
|
||||
if not f then
|
||||
fail("unable to open file!")
|
||||
return nil
|
||||
return nil
|
||||
end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
|
@ -52,7 +52,7 @@ end
|
|||
local empty = function()
|
||||
for i,v in ipairs(files) do
|
||||
local f = io.open(v, "w")
|
||||
if not f then
|
||||
if not f then
|
||||
fail("unable to open file!")
|
||||
end
|
||||
f:close()
|
||||
|
@ -116,8 +116,8 @@ local wait = function(sentinel, n)
|
|||
while 1 do
|
||||
local mbox = parse(get())
|
||||
if n == #mbox then break end
|
||||
if socket.time() - sentinel.time > 50 then
|
||||
to = 1
|
||||
if socket.time() - sentinel.time > 50 then
|
||||
to = 1
|
||||
break
|
||||
end
|
||||
socket.sleep(1)
|
||||
|
@ -132,7 +132,7 @@ local stuffed_body = [[
|
|||
This message body needs to be
|
||||
stuffed because it has a dot
|
||||
.
|
||||
by itself on a line.
|
||||
by itself on a line.
|
||||
Otherwise the mailer would
|
||||
think that the dot
|
||||
.
|
||||
|
@ -219,7 +219,7 @@ else print("ok") end
|
|||
|
||||
io.write("testing invalid from: ")
|
||||
local ret, err = socket.smtp.mail{
|
||||
from = ' " " (( _ * ',
|
||||
from = ' " " (( _ * ',
|
||||
rcpt = rcpt,
|
||||
}
|
||||
if ret or not err then fail("wrong error message")
|
||||
|
@ -227,7 +227,7 @@ else print(err) end
|
|||
|
||||
io.write("testing no rcpt: ")
|
||||
local ret, err = socket.smtp.mail{
|
||||
from = from,
|
||||
from = from,
|
||||
}
|
||||
if ret or not err then fail("wrong error message")
|
||||
else print(err) end
|
||||
|
|
|
@ -19,7 +19,7 @@ for i = 1, 10 do
|
|||
assert(ss == sock)
|
||||
else
|
||||
assert('timeout' == err, 'unexpected error :' .. tostring(err))
|
||||
end
|
||||
end
|
||||
err = sock:getoption("error") -- i get 'connection refused' on WinXP
|
||||
if err then
|
||||
print("Passed! Error is '" .. err .. "'.")
|
||||
|
|
|
@ -34,11 +34,11 @@ r, e = smtp.send{
|
|||
|
||||
print(r, e)
|
||||
|
||||
-- creates a source to send a message with two parts. The first part is
|
||||
-- creates a source to send a message with two parts. The first part is
|
||||
-- plain text, the second part is a PNG image, encoded as base64.
|
||||
source = smtp.message{
|
||||
headers = {
|
||||
-- Remember that headers are *ignored* by smtp.send.
|
||||
-- Remember that headers are *ignored* by smtp.send.
|
||||
from = "Sicrano <sicrano@tecgraf.puc-rio.br>",
|
||||
to = "Fulano <fulano@tecgraf.puc-rio.br>",
|
||||
subject = "Here is a message with attachments"
|
||||
|
@ -49,18 +49,18 @@ source = smtp.message{
|
|||
"Preamble might show up even in a MIME enabled client.",
|
||||
-- first part: No headers means plain text, us-ascii.
|
||||
-- The mime.eol low-level filter normalizes end-of-line markers.
|
||||
[1] = {
|
||||
[1] = {
|
||||
body = mime.eol(0, [[
|
||||
Lines in a message body should always end with CRLF.
|
||||
Lines in a message body should always end with CRLF.
|
||||
The smtp module will *NOT* perform translation. It will
|
||||
perform necessary stuffing, though.
|
||||
]])
|
||||
},
|
||||
-- second part: Headers describe content the to be an image,
|
||||
-- second part: Headers describe content the to be an image,
|
||||
-- sent under the base64 transfer content encoding.
|
||||
-- Notice that nothing happens until the message is sent. Small
|
||||
-- Notice that nothing happens until the message is sent. Small
|
||||
-- chunks are loaded into memory and translation happens on the fly.
|
||||
[2] = {
|
||||
[2] = {
|
||||
headers = {
|
||||
["ConTenT-tYpE"] = 'image/png; name="luasocket.png"',
|
||||
["content-disposition"] = 'attachment; filename="luasocket.png"',
|
||||
|
|
|
@ -7,7 +7,7 @@ function readfile(name)
|
|||
end
|
||||
|
||||
function similar(s1, s2)
|
||||
return string.lower(string.gsub(s1 or "", "%s", "")) ==
|
||||
return string.lower(string.gsub(s1 or "", "%s", "")) ==
|
||||
string.lower(string.gsub(s2 or "", "%s", ""))
|
||||
end
|
||||
|
||||
|
|
114
test/urltest.lua
114
test/urltest.lua
|
@ -60,8 +60,8 @@ end
|
|||
|
||||
local check_absolute_url = function(base, relative, absolute)
|
||||
local res = socket.url.absolute(base, relative)
|
||||
if res ~= absolute then
|
||||
io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '",
|
||||
if res ~= absolute then
|
||||
io.write("absolute: In test for base='", base, "', rel='", relative, "' expected '",
|
||||
absolute, "' but got '", res, "'\n")
|
||||
os.exit()
|
||||
end
|
||||
|
@ -73,7 +73,7 @@ local check_parse_url = function(gaba)
|
|||
local parsed = socket.url.parse(url)
|
||||
for i, v in pairs(gaba) do
|
||||
if v ~= parsed[i] then
|
||||
io.write("parse: In test for '", url, "' expected ", i, " = '",
|
||||
io.write("parse: In test for '", url, "' expected ", i, " = '",
|
||||
v, "' but got '", tostring(parsed[i]), "'\n")
|
||||
for i,v in pairs(parsed) do print(i,v) end
|
||||
os.exit()
|
||||
|
@ -81,7 +81,7 @@ local check_parse_url = function(gaba)
|
|||
end
|
||||
for i, v in pairs(parsed) do
|
||||
if v ~= gaba[i] then
|
||||
io.write("parse: In test for '", url, "' expected ", i, " = '",
|
||||
io.write("parse: In test for '", url, "' expected ", i, " = '",
|
||||
tostring(gaba[i]), "' but got '", v, "'\n")
|
||||
for i,v in pairs(parsed) do print(i,v) end
|
||||
os.exit()
|
||||
|
@ -92,8 +92,8 @@ end
|
|||
print("testing URL parsing")
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass$%?#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass$%?#wd@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass$%?#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass$%?#wd",
|
||||
|
@ -106,8 +106,8 @@ check_parse_url{
|
|||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass?#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass?#wd@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass?#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass?#wd",
|
||||
|
@ -120,8 +120,8 @@ check_parse_url{
|
|||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass-wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass-wd@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass-wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass-wd",
|
||||
|
@ -134,8 +134,8 @@ check_parse_url{
|
|||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass#wd@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass#wd",
|
||||
|
@ -148,8 +148,8 @@ check_parse_url{
|
|||
}
|
||||
check_parse_url{
|
||||
url = "scheme://user:pass#wd@host:port/path;params?query",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:pass#wd@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:pass#wd",
|
||||
|
@ -161,8 +161,8 @@ check_parse_url{
|
|||
}
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -175,8 +175,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:password@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "user:password@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:password",
|
||||
|
@ -190,8 +190,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;params?query#",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -204,8 +204,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;params?#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -218,8 +218,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;params#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -231,8 +231,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path;?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -245,8 +245,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/path?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -258,8 +258,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port/;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -272,8 +272,8 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "scheme://userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
scheme = "scheme",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -282,7 +282,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//userinfo@host:port/path;params?query#fragment",
|
||||
authority = "userinfo@host:port",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -295,7 +295,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//userinfo@host:port/path",
|
||||
authority = "userinfo@host:port",
|
||||
authority = "userinfo@host:port",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -305,7 +305,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//userinfo@host/path",
|
||||
authority = "userinfo@host",
|
||||
authority = "userinfo@host",
|
||||
host = "host",
|
||||
userinfo = "userinfo",
|
||||
user = "userinfo",
|
||||
|
@ -314,7 +314,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//user:password@host/path",
|
||||
authority = "user:password@host",
|
||||
authority = "user:password@host",
|
||||
host = "host",
|
||||
userinfo = "user:password",
|
||||
password = "password",
|
||||
|
@ -324,7 +324,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//user:@host/path",
|
||||
authority = "user:@host",
|
||||
authority = "user:@host",
|
||||
host = "host",
|
||||
userinfo = "user:",
|
||||
password = "",
|
||||
|
@ -334,7 +334,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//user@host:port/path",
|
||||
authority = "user@host:port",
|
||||
authority = "user@host:port",
|
||||
host = "host",
|
||||
userinfo = "user",
|
||||
user = "user",
|
||||
|
@ -344,7 +344,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//host:port/path",
|
||||
authority = "host:port",
|
||||
authority = "host:port",
|
||||
port = "port",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
|
@ -352,14 +352,14 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//host/path",
|
||||
authority = "host",
|
||||
authority = "host",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
}
|
||||
|
||||
check_parse_url{
|
||||
url = "//host",
|
||||
authority = "host",
|
||||
authority = "host",
|
||||
host = "host",
|
||||
}
|
||||
|
||||
|
@ -433,7 +433,7 @@ check_parse_url{
|
|||
|
||||
check_parse_url{
|
||||
url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment",
|
||||
authority = "userinfo@[::FFFF:129.144.52.38]:port",
|
||||
authority = "userinfo@[::FFFF:129.144.52.38]:port",
|
||||
host = "::FFFF:129.144.52.38",
|
||||
port = "port",
|
||||
userinfo = "userinfo",
|
||||
|
@ -447,7 +447,7 @@ check_parse_url{
|
|||
check_parse_url{
|
||||
url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
authority = "user:password@[::192.9.5.5]:port",
|
||||
authority = "user:password@[::192.9.5.5]:port",
|
||||
host = "::192.9.5.5",
|
||||
port = "port",
|
||||
userinfo = "user:password",
|
||||
|
@ -462,7 +462,7 @@ check_parse_url{
|
|||
print("testing URL building")
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
port = "port",
|
||||
user = "user",
|
||||
|
@ -499,7 +499,7 @@ check_build_url{
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
user = "user",
|
||||
password = "password",
|
||||
|
@ -511,7 +511,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user@host/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
user = "user",
|
||||
path = "/path",
|
||||
|
@ -522,7 +522,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://host/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
|
@ -532,7 +532,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://host/path;params#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
|
@ -541,7 +541,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://host/path#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
fragment = "fragment"
|
||||
|
@ -549,7 +549,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://host/path",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
path = "/path",
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
port = "port",
|
||||
user = "user",
|
||||
|
@ -581,7 +581,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
port = "port",
|
||||
user = "user",
|
||||
|
@ -596,7 +596,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
host = "host",
|
||||
port = "port",
|
||||
userinfo = "user:password",
|
||||
|
@ -609,7 +609,7 @@ check_build_url {
|
|||
|
||||
check_build_url {
|
||||
url = "scheme://user:password@host:port/path;params?query#fragment",
|
||||
scheme = "scheme",
|
||||
scheme = "scheme",
|
||||
authority = "user:password@host:port",
|
||||
path = "/path",
|
||||
params = "params",
|
||||
|
@ -683,7 +683,7 @@ check_absolute_url("//a/b/c/d;p?q#f", "d/e/f", "//a/b/c/d/e/f")
|
|||
check_absolute_url("/a/b/c/d;p?q#f", "d/e/f", "/a/b/c/d/e/f")
|
||||
check_absolute_url("a/b/c/d", "d/e/f", "a/b/c/d/e/f")
|
||||
check_absolute_url("a/b/c/d/../", "d/e/f", "a/b/c/d/e/f")
|
||||
check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html",
|
||||
check_absolute_url("http://velox.telemar.com.br", "/dashboard/index.html",
|
||||
"http://velox.telemar.com.br/dashboard/index.html")
|
||||
check_absolute_url("http://example.com/", "../.badhost.com/", "http://example.com/.badhost.com/")
|
||||
check_absolute_url("http://example.com/", "...badhost.com/", "http://example.com/...badhost.com/")
|
||||
|
@ -700,11 +700,11 @@ check_absolute_url("http://example.com/a/b/c/d/", "../x/a/../y/z/../../../../q",
|
|||
print("testing path parsing and composition")
|
||||
check_parse_path("/eu/tu/ele", { "eu", "tu", "ele"; is_absolute = 1 })
|
||||
check_parse_path("/eu/", { "eu"; is_absolute = 1, is_directory = 1 })
|
||||
check_parse_path("eu/tu/ele/nos/vos/eles/",
|
||||
check_parse_path("eu/tu/ele/nos/vos/eles/",
|
||||
{ "eu", "tu", "ele", "nos", "vos", "eles"; is_directory = 1})
|
||||
check_parse_path("/", { is_absolute = 1, is_directory = 1})
|
||||
check_parse_path("", { })
|
||||
check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/",
|
||||
check_parse_path("eu%01/%02tu/e%03l%04e/nos/vos%05/e%12les/",
|
||||
{ "eu\1", "\2tu", "e\3l\4e", "nos", "vos\5", "e\18les"; is_directory = 1})
|
||||
check_parse_path("eu/tu", { "eu", "tu" })
|
||||
|
||||
|
|
|
@ -54,30 +54,30 @@ function check_timeout(tm, sl, elapsed, err, opp, mode, alldone)
|
|||
if not err then warn("must be buffered")
|
||||
elseif err == "timeout" then pass("proper timeout")
|
||||
else fail("unexpected error '%s'", err) end
|
||||
else
|
||||
if err ~= "timeout" then fail("should have timed out")
|
||||
else
|
||||
if err ~= "timeout" then fail("should have timed out")
|
||||
else pass("proper timeout") end
|
||||
end
|
||||
else
|
||||
if mode == "total" then
|
||||
if elapsed > tm then
|
||||
if elapsed > tm then
|
||||
if err ~= "timeout" then fail("should have timed out")
|
||||
else pass("proper timeout") end
|
||||
elseif elapsed < tm then
|
||||
if err then fail(err)
|
||||
if err then fail(err)
|
||||
else pass("ok") end
|
||||
else
|
||||
if alldone then
|
||||
if err then fail("unexpected error '%s'", err)
|
||||
else
|
||||
if alldone then
|
||||
if err then fail("unexpected error '%s'", err)
|
||||
else pass("ok") end
|
||||
else
|
||||
if err ~= "timeout" then fail(err)
|
||||
if err ~= "timeout" then fail(err)
|
||||
else pass("proper timeoutk") end
|
||||
end
|
||||
end
|
||||
else
|
||||
if err then fail(err)
|
||||
else pass("ok") end
|
||||
else
|
||||
if err then fail(err)
|
||||
else pass("ok") end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -104,7 +104,7 @@ function reconnect()
|
|||
print("done " .. i)
|
||||
]]
|
||||
data, err = uconnect(host, port)
|
||||
if not data then fail(err)
|
||||
if not data then fail(err)
|
||||
else pass("connected!") end
|
||||
end
|
||||
|
||||
|
@ -116,8 +116,8 @@ else pass("connected!") end
|
|||
------------------------------------------------------------------------
|
||||
function test_methods(sock, methods)
|
||||
for _, v in pairs(methods) do
|
||||
if type(sock[v]) ~= "function" then
|
||||
fail(sock.class .. " method '" .. v .. "' not registered")
|
||||
if type(sock[v]) ~= "function" then
|
||||
fail(sock.class .. " method '" .. v .. "' not registered")
|
||||
end
|
||||
end
|
||||
pass(sock.class .. " methods are ok")
|
||||
|
@ -132,7 +132,7 @@ function test_mixed(len)
|
|||
local p3 = "raw " .. string.rep("z", inter) .. "bytes"
|
||||
local p4 = "end" .. string.rep("w", inter) .. "bytes"
|
||||
local bp1, bp2, bp3, bp4
|
||||
remote (string.format("str = data:receive(%d)",
|
||||
remote (string.format("str = data:receive(%d)",
|
||||
string.len(p1)+string.len(p2)+string.len(p3)+string.len(p4)))
|
||||
sent, err = data:send(p1..p2..p3..p4)
|
||||
if err then fail(err) end
|
||||
|
@ -172,7 +172,7 @@ function test_rawline(len)
|
|||
reconnect()
|
||||
local str, str10, back, err
|
||||
str = string.rep(string.char(47), math.mod(len, 10))
|
||||
str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100),
|
||||
str10 = string.rep(string.char(120,21,77,4,5,0,7,36,44,100),
|
||||
math.floor(len/10))
|
||||
str = str .. str10
|
||||
remote "str = data:receive()"
|
||||
|
@ -221,7 +221,7 @@ function test_totaltimeoutreceive(len, tm, sl)
|
|||
data:settimeout(tm, "total")
|
||||
local t = socket.gettime()
|
||||
str, err, partial, elapsed = data:receive(2*len)
|
||||
check_timeout(tm, sl, elapsed, err, "receive", "total",
|
||||
check_timeout(tm, sl, elapsed, err, "receive", "total",
|
||||
string.len(str or partial) == 2*len)
|
||||
end
|
||||
|
||||
|
@ -241,7 +241,7 @@ function test_totaltimeoutsend(len, tm, sl)
|
|||
data:settimeout(tm, "total")
|
||||
str = string.rep("a", 2*len)
|
||||
total, err, partial, elapsed = data:send(str)
|
||||
check_timeout(tm, sl, elapsed, err, "send", "total",
|
||||
check_timeout(tm, sl, elapsed, err, "send", "total",
|
||||
total == 2*len)
|
||||
end
|
||||
|
||||
|
@ -261,7 +261,7 @@ function test_blockingtimeoutreceive(len, tm, sl)
|
|||
]], 2*tm, len, sl, sl))
|
||||
data:settimeout(tm)
|
||||
str, err, partial, elapsed = data:receive(2*len)
|
||||
check_timeout(tm, sl, elapsed, err, "receive", "blocking",
|
||||
check_timeout(tm, sl, elapsed, err, "receive", "blocking",
|
||||
string.len(str or partial) == 2*len)
|
||||
end
|
||||
|
||||
|
@ -294,10 +294,10 @@ function empty_connect()
|
|||
data = server:accept()
|
||||
]]
|
||||
data, err = socket.connect("", port)
|
||||
if not data then
|
||||
if not data then
|
||||
pass("ok")
|
||||
data = socket.connect(host, port)
|
||||
else
|
||||
else
|
||||
pass("gethostbyname returns localhost on empty string...")
|
||||
end
|
||||
end
|
||||
|
@ -331,7 +331,7 @@ function test_closed()
|
|||
data:close()
|
||||
data = nil
|
||||
]], str))
|
||||
-- try to get a line
|
||||
-- try to get a line
|
||||
back, err, partial = data:receive()
|
||||
if not err then fail("should have gotten 'closed'.")
|
||||
elseif err ~= "closed" then fail("got '"..err.."' instead of 'closed'.")
|
||||
|
@ -344,25 +344,25 @@ function test_closed()
|
|||
data = nil
|
||||
]]
|
||||
total, err, partial = data:send(string.rep("ugauga", 100000))
|
||||
if not err then
|
||||
if not err then
|
||||
pass("failed: output buffer is at least %d bytes long!", total)
|
||||
elseif err ~= "closed" then
|
||||
elseif err ~= "closed" then
|
||||
fail("got '"..err.."' instead of 'closed'.")
|
||||
else
|
||||
pass("graceful 'closed' received after %d bytes were sent", partial)
|
||||
else
|
||||
pass("graceful 'closed' received after %d bytes were sent", partial)
|
||||
end
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
function test_selectbugs()
|
||||
local r, s, e = socket.select(nil, nil, 0.1)
|
||||
assert(type(r) == "table" and type(s) == "table" and
|
||||
assert(type(r) == "table" and type(s) == "table" and
|
||||
(e == "timeout" or e == "error"))
|
||||
pass("both nil: ok")
|
||||
local udp = socket.udp()
|
||||
udp:close()
|
||||
r, s, e = socket.select({ udp }, { udp }, 0.1)
|
||||
assert(type(r) == "table" and type(s) == "table" and
|
||||
assert(type(r) == "table" and type(s) == "table" and
|
||||
(e == "timeout" or e == "error"))
|
||||
pass("closed sockets: ok")
|
||||
e = pcall(socket.select, "wrong", 1, 0.1)
|
||||
|
@ -380,7 +380,7 @@ function accept_timeout()
|
|||
local t = socket.gettime()
|
||||
s:settimeout(1)
|
||||
local c, e = s:accept()
|
||||
assert(not c, "should not accept")
|
||||
assert(not c, "should not accept")
|
||||
assert(e == "timeout", string.format("wrong error message (%s)", e))
|
||||
t = socket.gettime() - t
|
||||
assert(t < 2, string.format("took to long to give up (%gs)", t))
|
||||
|
@ -398,9 +398,9 @@ function connect_timeout()
|
|||
local t = socket.gettime()
|
||||
local r, e = c:connect("127.0.0.2", 80)
|
||||
assert(not r, "should not connect")
|
||||
assert(socket.gettime() - t < 2, "took too long to give up.")
|
||||
assert(socket.gettime() - t < 2, "took too long to give up.")
|
||||
c:close()
|
||||
print("ok")
|
||||
print("ok")
|
||||
end
|
||||
|
||||
------------------------------------------------------------------------
|
||||
|
@ -463,9 +463,9 @@ function getstats_test()
|
|||
data:receive(c)
|
||||
t = t + c
|
||||
local r, s, a = data:getstats()
|
||||
assert(r == t, "received count failed" .. tostring(r)
|
||||
assert(r == t, "received count failed" .. tostring(r)
|
||||
.. "/" .. tostring(t))
|
||||
assert(s == t, "sent count failed" .. tostring(s)
|
||||
assert(s == t, "sent count failed" .. tostring(s)
|
||||
.. "/" .. tostring(t))
|
||||
end
|
||||
print("ok")
|
||||
|
@ -473,7 +473,7 @@ end
|
|||
|
||||
|
||||
------------------------------------------------------------------------
|
||||
function test_nonblocking(size)
|
||||
function test_nonblocking(size)
|
||||
reconnect()
|
||||
print("Testing " .. 2*size .. " bytes")
|
||||
remote(string.format([[
|
||||
|
|
|
@ -9,7 +9,7 @@ ack = "\n";
|
|||
while 1 do
|
||||
print("server: waiting for client connection...");
|
||||
control = assert(server:accept());
|
||||
while 1 do
|
||||
while 1 do
|
||||
command = assert(control:receive());
|
||||
assert(control:send(ack));
|
||||
((loadstring or load)(command))();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue