From 56893e9dcd1eeebffb42b227a2151e18d49bc370 Mon Sep 17 00:00:00 2001 From: Gerardo Marset Date: Mon, 25 Feb 2013 20:28:28 -0200 Subject: Use the length operator (#) instead of table.getn. table.getn was deprecated in Lua 5.1 in favor of #, the length operator. See: http://www.lua.org/manual/5.1/manual.html#7.2 --- test/httptest.lua | 2 +- test/smtptest.lua | 14 +++++++------- test/urltest.lua | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/httptest.lua b/test/httptest.lua index 614acf3..d5fbb37 100644 --- a/test/httptest.lua +++ b/test/httptest.lua @@ -66,7 +66,7 @@ local check_request = function(request, expect, ignore) local response = {} response.code, response.headers, response.status = socket.skip(1, http.request(request)) - if t and table.getn(t) > 0 then response.body = table.concat(t) end + if t and #t > 0 then response.body = table.concat(t) end check_result(response, expect, ignore) end diff --git a/test/smtptest.lua b/test/smtptest.lua index 5f0e0e5..b5380ff 100644 --- a/test/smtptest.lua +++ b/test/smtptest.lua @@ -20,7 +20,7 @@ dofile("testsupport.lua") local total = function() local t = 0 - for i = 1, table.getn(sent) do + for i = 1, #sent do t = t + sent[i].count end return t @@ -83,7 +83,7 @@ end local check = function(sent, m) io.write("checking ", m.headers.title, ": ") - for i = 1, table.getn(sent) do + for i = 1, #sent do local s = sent[i] if s.title == m.headers.title and s.count > 0 then check_headers(s.headers, m.headers) @@ -98,7 +98,7 @@ end local insert = function(sent, message) if type(message.rcpt) == "table" then - message.count = table.getn(message.rcpt) + message.count = #message.rcpt else message.count = 1 end message.headers = message.headers or {} message.headers.title = message.title @@ -115,7 +115,7 @@ local wait = function(sentinel, n) io.write("waiting for ", n, " messages: ") while 1 do local mbox = parse(get()) - if n == table.getn(mbox) then break end + if n == #mbox then break end if socket.time() - sentinel.time > 50 then to = 1 break @@ -237,7 +237,7 @@ empty() print("ok") io.write("sending messages: ") -for i = 1, table.getn(sent) do +for i = 1, #sent do ret, err = socket.smtp.mail(sent[i]) if not ret then fail(err) end io.write("+") @@ -249,9 +249,9 @@ wait(mark(), total()) io.write("parsing mailbox: ") local mbox = parse(get()) -print(table.getn(mbox) .. " messages found!") +print(#mbox .. " messages found!") -for i = 1, table.getn(mbox) do +for i = 1, #mbox do check(sent, mbox[i]) end diff --git a/test/urltest.lua b/test/urltest.lua index 71e4428..32cb348 100644 --- a/test/urltest.lua +++ b/test/urltest.lua @@ -34,7 +34,7 @@ end local check_parse_path = function(path, expect) local parsed = socket.url.parse_path(path) - for i = 1, math.max(table.getn(parsed), table.getn(expect)) do + for i = 1, math.max(#parsed, #expect) do if parsed[i] ~= expect[i] then print(path) os.exit() -- cgit v1.2.3-55-g6feb