aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-20 00:24:44 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2003-03-20 00:24:44 +0000
commit53857360bb1ca9cd2080b69d930763ae59db9b06 (patch)
tree6c1bc6d6462695cf9048801b2244f7fd0cd21ad5 /test
parent7da19138e37c4e0123860f1fecbceb80c3d2627d (diff)
downloadluasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.gz
luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.tar.bz2
luasocket-53857360bb1ca9cd2080b69d930763ae59db9b06.zip
Finish port to Lua 5. Everything is working fine.
Still doesn't work in Windows.
Diffstat (limited to 'test')
-rw-r--r--test/ftptest.lua118
-rw-r--r--test/httptest.lua18
-rw-r--r--test/smtptest.lua161
-rw-r--r--test/urltest.lua21
4 files changed, 166 insertions, 152 deletions
diff --git a/test/ftptest.lua b/test/ftptest.lua
index 34cccf1..ee3af91 100644
--- a/test/ftptest.lua
+++ b/test/ftptest.lua
@@ -1,29 +1,32 @@
1dofile("noglobals.lua") 1dofile("noglobals.lua")
2 2
3local similar = function(s1, s2) 3local similar = function(s1, s2)
4 return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) 4 return
5 string.lower(string.gsub(s1, "%s", "")) ==
6 string.lower(string.gsub(s2, "%s", ""))
5end 7end
6 8
7local capture = function(cmd) 9local readfile = function(name)
8 readfrom("| " .. cmd) 10 local f = io.open(name, "r")
9 local s = read("*a") 11 if not f then return nil end
10 readfrom() 12 local s = f:read("*a")
13 f:close()
11 return s 14 return s
12end 15end
13 16
14local readfile = function(name) 17local capture = function(cmd)
15 local f = readfrom(name) 18 local f = io.popen(cmd)
16 if not f then return nil end 19 if not f then return nil end
17 local s = read("*a") 20 local s = f:read("*a")
18 readfrom() 21 f:close()
19 return s 22 return s
20end 23end
21 24
22local check = function(v, e, o) 25local check = function(v, e, o)
23 e = e or "failed!" 26 e = e or "failed!"
24 o = o or "ok" 27 o = o or "ok"
25 if v then print(o) 28 if v then print(o)
26 else print(e) exit() end 29 else print(e) os.exit() end
27end 30end
28 31
29-- needs an account luasocket:password 32-- needs an account luasocket:password
@@ -31,81 +34,82 @@ end
31 34
32local index, err, saved, back, expected 35local index, err, saved, back, expected
33 36
34local t = _time() 37local t = socket._time()
35 38
36index = readfile("index.html") 39index = readfile("test/index.html")
40
41io.write("testing wrong scheme: ")
42back, err = socket.ftp.get("wrong://banana.com/lixo")
43check(not back and err == "unknown scheme 'wrong'", err)
44
45io.write("testing invalid url: ")
46back, err = socket.ftp.get("localhost/dir1/index.html;type=i")
47local c, e = socket.connect("", 21)
48check(not back and err == e, err)
37 49
38write("testing file upload: ") 50io.write("testing anonymous file upload: ")
39remove("/var/ftp/dir1/index.up.html") 51os.remove("/var/ftp/pub/index.up.html")
40err = FTP.put("ftp://localhost/dir1/index.up.html;type=i", index) 52err = socket.ftp.put("ftp://localhost/pub/index.up.html;type=i", index)
41saved = readfile("/var/ftp/dir1/index.up.html") 53saved = readfile("/var/ftp/pub/index.up.html")
42check(not err and saved == index, err) 54check(not err and saved == index, err)
43 55
44write("testing file download: ") 56io.write("testing anonymous file download: ")
45back, err = FTP.get("ftp://localhost/dir1/index.up.html;type=i") 57back, err = socket.ftp.get("ftp://localhost/pub/index.up.html;type=i")
46check(not err and back == index, err) 58check(not err and back == index, err)
47 59
48write("testing no directory changes: ") 60io.write("testing no directory changes: ")
49back, err = FTP.get("ftp://localhost/index.html;type=i") 61back, err = socket.ftp.get("ftp://localhost/index.html;type=i")
50check(not err and back == index, err) 62check(not err and back == index, err)
51 63
52write("testing multiple directory changes: ") 64io.write("testing multiple directory changes: ")
53back, err = FTP.get("ftp://localhost/dir1/dir2/dir3/dir4/dir5/dir6/index.html;type=i") 65back, err = socket.ftp.get("ftp://localhost/pub/dir1/dir2/dir3/dir4/dir5/index.html;type=i")
54check(not err and back == index, err) 66check(not err and back == index, err)
55 67
56write("testing authenticated upload: ") 68io.write("testing authenticated upload: ")
57remove("/home/luasocket/index.up.html") 69os.remove("/home/luasocket/index.up.html")
58err = FTP.put("ftp://luasocket:password@localhost/index.up.html;type=i", index) 70err = socket.ftp.put("ftp://luasocket:password@localhost/index.up.html;type=i", index)
59saved = readfile("/home/luasocket/index.up.html") 71saved = readfile("/home/luasocket/index.up.html")
60check(not err and saved == index, err) 72check(not err and saved == index, err)
61 73
62write("testing authenticated download: ") 74io.write("testing authenticated download: ")
63back, err = FTP.get("ftp://luasocket:password@localhost/index.up.html;type=i") 75back, err = socket.ftp.get("ftp://luasocket:password@localhost/index.up.html;type=i")
64check(not err and back == index, err) 76check(not err and back == index, err)
65 77
66write("testing weird-character translation: ") 78io.write("testing weird-character translation: ")
67back, err = FTP.get("ftp://luasocket:password@localhost/%2fvar/ftp/dir1/index.html;type=i") 79back, err = socket.ftp.get("ftp://luasocket:password@localhost/%2fvar/ftp/pub/index.html;type=i")
68check(not err and back == index, err) 80check(not err and back == index, err)
69 81
70write("testing parameter overriding: ") 82io.write("testing parameter overriding: ")
71back, err = FTP.get { 83back, err = socket.ftp.get {
72 url = "//stupid:mistake@localhost/dir1/index.html", 84 url = "//stupid:mistake@localhost/index.html",
73 user = "luasocket", 85 user = "luasocket",
74 password = "password", 86 password = "password",
75 type = "i" 87 type = "i"
76} 88}
77check(not err and back == index, err) 89check(not err and back == index, err)
78 90
79write("testing wrong scheme: ") 91io.write("testing home directory listing: ")
80back, err = FTP.get("wrong://banana.com/lixo")
81check(not back and err == "unknown scheme 'wrong'", err)
82
83write("testing invalid url: ")
84back, err = FTP.get("localhost/dir1/index.html;type=i")
85local c, e = connect("", 21)
86check(not back and err == e, err)
87
88write("testing directory listing: ")
89expected = capture("ls -F /var/ftp/dir1 | grep -v /")
90back, err = FTP.get("ftp://localhost/dir1;type=d")
91check(similar(back, expected))
92
93write("testing home directory listing: ")
94expected = capture("ls -F /var/ftp | grep -v /") 92expected = capture("ls -F /var/ftp | grep -v /")
95back, err = FTP.get("ftp://localhost/") 93back, err = socket.ftp.get("ftp://localhost/")
96check(back and similar(back, expected), nil, err) 94check(back and similar(back, expected), nil, err)
97 95
98write("testing upload denial: ") 96io.write("testing directory listing: ")
99err = FTP.put("ftp://localhost/index.up.html;type=a", index) 97expected = capture("ls -F /var/ftp/pub | grep -v /")
98back, err = socket.ftp.get("ftp://localhost/pub;type=d")
99check(similar(back, expected))
100
101io.write("testing upload denial: ")
102err = socket.ftp.put("ftp://localhost/index.up.html;type=a", index)
100check(err, err) 103check(err, err)
101 104
102write("testing authentication failure: ") 105io.write("testing authentication failure: ")
103err = FTP.put("ftp://luasocket:wrong@localhost/index.html;type=a", index) 106err = socket.ftp.put("ftp://luasocket:wrong@localhost/index.html;type=a", index)
107print(err)
104check(err, err) 108check(err, err)
105 109
106write("testing wrong file: ") 110io.write("testing wrong file: ")
107back, err = FTP.get("ftp://localhost/index.wrong.html;type=a") 111back, err = socket.ftp.get("ftp://localhost/index.wrong.html;type=a")
108check(err, err) 112check(err, err)
109 113
110print("passed all tests") 114print("passed all tests")
111print(format("done in %.2fs", _time() - t)) 115print(string.format("done in %.2fs", socket._time() - t))
diff --git a/test/httptest.lua b/test/httptest.lua
index 2941390..8b84f84 100644
--- a/test/httptest.lua
+++ b/test/httptest.lua
@@ -31,7 +31,7 @@ local check = function (v, e)
31end 31end
32 32
33local check_request = function(request, expect, ignore) 33local check_request = function(request, expect, ignore)
34 local response = http.request(request) 34 local response = socket.http.request(request)
35 for i,v in response do 35 for i,v in response do
36 if not ignore[i] then 36 if not ignore[i] then
37 if v ~= expect[i] then %fail(i .. " differs!") end 37 if v ~= expect[i] then %fail(i .. " differs!") end
@@ -56,13 +56,13 @@ index = readfile("test/index.html")
56 56
57io.write("testing request uri correctness: ") 57io.write("testing request uri correctness: ")
58local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string" 58local forth = cgiprefix .. "/request-uri?" .. "this+is+the+query+string"
59local back = http.get("http://" .. HOST .. forth) 59local back = socket.http.get("http://" .. HOST .. forth)
60if similar(back, forth) then print("ok") 60if similar(back, forth) then print("ok")
61else fail("failed!") end 61else fail("failed!") end
62 62
63io.write("testing query string correctness: ") 63io.write("testing query string correctness: ")
64forth = "this+is+the+query+string" 64forth = "this+is+the+query+string"
65back = http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth) 65back = socket.http.get("http://" .. HOST .. cgiprefix .. "/query-string?" .. forth)
66if similar(back, forth) then print("ok") 66if similar(back, forth) then print("ok")
67else fail("failed!") end 67else fail("failed!") end
68 68
@@ -178,7 +178,7 @@ io.write("testing manual basic auth: ")
178request = { 178request = {
179 url = "http://" .. HOST .. prefix .. "/auth/index.html", 179 url = "http://" .. HOST .. prefix .. "/auth/index.html",
180 headers = { 180 headers = {
181 authorization = "Basic " .. Code.base64("luasocket:password") 181 authorization = "Basic " .. socket.code.base64("luasocket:password")
182 } 182 }
183} 183}
184expect = { 184expect = {
@@ -279,11 +279,11 @@ check_request(request, expect, ignore)
279 279
280local body 280local body
281io.write("testing simple get function: ") 281io.write("testing simple get function: ")
282body = http.get("http://" .. HOST .. prefix .. "/index.html") 282body = socket.http.get("http://" .. HOST .. prefix .. "/index.html")
283check(body == index) 283check(body == index)
284 284
285io.write("testing simple get function with table args: ") 285io.write("testing simple get function with table args: ")
286body = http.get { 286body = socket.http.get {
287 url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html", 287 url = "http://really:wrong@" .. HOST .. prefix .. "/auth/index.html",
288 user = "luasocket", 288 user = "luasocket",
289 password = "password" 289 password = "password"
@@ -291,18 +291,18 @@ body = http.get {
291check(body == index) 291check(body == index)
292 292
293io.write("testing simple post function: ") 293io.write("testing simple post function: ")
294body = http.post("http://" .. HOST .. cgiprefix .. "/cat", index) 294body = socket.http.post("http://" .. HOST .. cgiprefix .. "/cat", index)
295check(body == index) 295check(body == index)
296 296
297io.write("testing simple post function with table args: ") 297io.write("testing simple post function with table args: ")
298body = http.post { 298body = socket.http.post {
299 url = "http://" .. HOST .. cgiprefix .. "/cat", 299 url = "http://" .. HOST .. cgiprefix .. "/cat",
300 body = index 300 body = index
301} 301}
302check(body == index) 302check(body == index)
303 303
304io.write("testing HEAD method: ") 304io.write("testing HEAD method: ")
305response = http.request { 305response = socket.http.request {
306 method = "HEAD", 306 method = "HEAD",
307 url = "http://www.tecgraf.puc-rio.br/~diego/" 307 url = "http://www.tecgraf.puc-rio.br/~diego/"
308} 308}
diff --git a/test/smtptest.lua b/test/smtptest.lua
index 6b01134..1bba27f 100644
--- a/test/smtptest.lua
+++ b/test/smtptest.lua
@@ -1,122 +1,130 @@
1local sent = {} 1local sent = {}
2 2
3local from = "luasock@tecgraf.puc-rio.br" 3local from = "diego@localhost"
4local server = "mail.tecgraf.puc-rio.br" 4local server = "localhost"
5local rcpt = "luasock@tecgraf.puc-rio.br" 5local rcpt = "luasocket@localhost"
6 6
7local name = "/var/spool/mail/luasock" 7local files = {
8 "/var/spool/mail/luasocket",
9 "/var/spool/mail/luasock1",
10 "/var/spool/mail/luasock2",
11 "/var/spool/mail/luasock3",
12}
8 13
9local t = _time() 14local t = socket._time()
10local err 15local err
11 16
12dofile("parsembox.lua") 17dofile("mbox.lua")
13local parse = parse 18local parse = mbox.parse
14dofile("noglobals.lua") 19dofile("noglobals.lua")
15 20
16local total = function() 21local total = function()
17 local t = 0 22 local t = 0
18 for i = 1, getn(%sent) do 23 for i = 1, table.getn(sent) do
19 t = t + %sent[i].count 24 t = t + sent[i].count
20 end 25 end
21 return t 26 return t
22end 27end
23 28
24local similar = function(s1, s2) 29local similar = function(s1, s2)
25 return strlower(gsub(s1, "%s", "")) == strlower(gsub(s2, "%s", "")) 30 return
26end 31 string.lower(string.gsub(s1, "%s", "")) ==
27 32 string.lower(string.gsub(s2, "%s", ""))
28local readfile = function(name)
29 local f = readfrom(name)
30 if not f then return nil end
31 local s = read("*a")
32 readfrom()
33 return s
34end
35
36local capture = function(cmd)
37 readfrom("| " .. cmd)
38 local s = read("*a")
39 readfrom()
40 return s
41end 33end
42 34
43local fail = function(s) 35local fail = function(s)
44 s = s or "failed!" 36 s = s or "failed!"
45 print(s) 37 print(s)
46 exit() 38 os.exit()
47end 39end
48 40
49local empty = function() 41local readfile = function(name)
50 local f = openfile(%name, "w") 42 local f = io.open(name, "r")
51 closefile(f) 43 if not f then
44 fail("unable to open file!")
45 return nil
46 end
47 local s = f:read("*a")
48 f:close()
49 return s
52end 50end
53 51
54local get = function() 52local empty = function()
55 return %readfile(%name) 53 for i,v in ipairs(files) do
54 local f = io.open(v, "w")
55 if not f then
56 fail("unable to open file!")
57 end
58 f:close()
59 end
56end 60end
57 61
58local list = function() 62local get = function()
59 return %capture("ls -l " .. %name) 63 s = ""
64 for i,v in ipairs(files) do
65 s = s .. "\n" .. readfile(v)
66 end
67 return s
60end 68end
61 69
62local check_headers = function(sent, got) 70local check_headers = function(sent, got)
63 sent = sent or {} 71 sent = sent or {}
64 got = got or {} 72 got = got or {}
65 for i,v in sent do 73 for i,v in sent do
66 if not %similar(v, got[i]) then %fail("header " .. v .. "failed!") end 74 if not similar(v, got[i]) then fail("header " .. v .. "failed!") end
67 end 75 end
68end 76end
69 77
70local check_body = function(sent, got) 78local check_body = function(sent, got)
71 sent = sent or "" 79 sent = sent or ""
72 got = got or "" 80 got = got or ""
73 if not %similar(sent, got) then %fail("bodies differ!") end 81 if not similar(sent, got) then fail("bodies differ!") end
74end 82end
75 83
76local check = function(sent, m) 84local check = function(sent, m)
77 write("checking ", m.headers.title, ": ") 85 io.write("checking ", m.headers.title, ": ")
78 for i = 1, getn(sent) do 86 for i = 1, table.getn(sent) do
79 local s = sent[i] 87 local s = sent[i]
80 if s.title == m.headers.title and s.count > 0 then 88 if s.title == m.headers.title and s.count > 0 then
81 %check_headers(s.headers, m.headers) 89 check_headers(s.headers, m.headers)
82 %check_body(s.body, m.body) 90 check_body(s.body, m.body)
83 s.count = s.count - 1 91 s.count = s.count - 1
84 print("ok") 92 print("ok")
85 return 93 return
86 end 94 end
87 end 95 end
88 %fail("not found") 96 fail("not found")
89end 97end
90 98
91local insert = function(sent, message) 99local insert = function(sent, message)
92 if type(message.rcpt) == "table" then 100 if type(message.rcpt) == "table" then
93 message.count = getn(message.rcpt) 101 message.count = table.getn(message.rcpt)
94 else message.count = 1 end 102 else message.count = 1 end
95 message.headers = message.headers or {} 103 message.headers = message.headers or {}
96 message.headers.title = message.title 104 message.headers.title = message.title
97 tinsert(sent, message) 105 table.insert(sent, message)
98end 106end
99 107
100local mark = function() 108local mark = function()
101 local time = _time() 109 local time = socket._time()
102 return { time = time } 110 return { time = time }
103end 111end
104 112
105local wait = function(sentinel, n) 113local wait = function(sentinel, n)
106 local to 114 local to
107 write("waiting for ", n, " messages: ") 115 io.write("waiting for ", n, " messages: ")
108 while 1 do 116 while 1 do
109 local mbox = %parse.mbox(%get()) 117 local mbox = parse(get())
110 if n == getn(mbox) then break end 118 if n == table.getn(mbox) then break end
111 if _time() - sentinel.time > 50 then 119 if socket._time() - sentinel.time > 50 then
112 to = 1 120 to = 1
113 break 121 break
114 end 122 end
115 _sleep(1) 123 socket._sleep(1)
116 write(".") 124 io.write(".")
117 flush(_STDOUT) 125 io.stdout:flush()
118 end 126 end
119 if to then %fail("timeout") 127 if to then fail("timeout")
120 else print("ok") end 128 else print("ok") end
121end 129end
122 130
@@ -129,16 +137,16 @@ Otherwise the mailer would
129think that the dot 137think that the dot
130. 138.
131is the end of the message 139is the end of the message
132and the remaining will cause 140and the remaining text would cause
133a lot of trouble. 141a lot of trouble.
134]] 142]]
135 143
136insert(sent, { 144insert(sent, {
137 from = from, 145 from = from,
138 rcpt = { 146 rcpt = {
139 "luasock2@tecgraf.puc-rio.br", 147 "luasocket@localhost",
140 "luasock", 148 "luasock3@dell-diego.cs.princeton.edu",
141 "luasock1" 149 "luasock1@dell-diego.cs.princeton.edu"
142 }, 150 },
143 body = "multiple rcpt body", 151 body = "multiple rcpt body",
144 title = "multiple rcpt", 152 title = "multiple rcpt",
@@ -147,8 +155,8 @@ insert(sent, {
147insert(sent, { 155insert(sent, {
148 from = from, 156 from = from,
149 rcpt = { 157 rcpt = {
150 "luasock2@tecgraf.puc-rio.br", 158 "luasock2@localhost",
151 "luasock", 159 "luasock3",
152 "luasock1" 160 "luasock1"
153 }, 161 },
154 headers = { 162 headers = {
@@ -199,9 +207,9 @@ insert(sent, {
199 title = "minimum message" 207 title = "minimum message"
200}) 208})
201 209
202write("testing host not found: ") 210io.write("testing host not found: ")
203local c, e = connect("wrong.host", 25) 211local c, e = socket.connect("wrong.host", 25)
204local err = SMTP.mail{ 212local err = socket.smtp.mail{
205 from = from, 213 from = from,
206 rcpt = rcpt, 214 rcpt = rcpt,
207 server = "wrong.host" 215 server = "wrong.host"
@@ -209,44 +217,43 @@ local err = SMTP.mail{
209if e ~= err then fail("wrong error message") 217if e ~= err then fail("wrong error message")
210else print("ok") end 218else print("ok") end
211 219
212write("testing invalid from: ") 220io.write("testing invalid from: ")
213local err = SMTP.mail{ 221local err = socket.smtp.mail{
214 from = ' " " (( _ * ', 222 from = ' " " (( _ * ',
215 rcpt = rcpt, 223 rcpt = rcpt,
216} 224}
217if not err then fail("wrong error message") 225if not err then fail("wrong error message")
218else print(err) end 226else print(err) end
219 227
220write("testing no rcpt: ") 228io.write("testing no rcpt: ")
221local err = SMTP.mail{ 229local err = socket.smtp.mail{
222 from = from, 230 from = from,
223} 231}
224if not err then fail("wrong error message") 232if not err then fail("wrong error message")
225else print(err) end 233else print(err) end
226 234
227write("clearing mailbox: ") 235io.write("clearing mailbox: ")
228empty() 236empty()
229print("ok") 237print("ok")
230 238
231write("sending messages: ") 239io.write("sending messages: ")
232for i = 1, getn(sent) do 240for i = 1, table.getn(sent) do
233 err = SMTP.mail(sent[i]) 241 err = socket.smtp.mail(sent[i])
234 if err then fail(err) end 242 if err then fail(err) end
235 write("+") 243 io.write("+")
236 flush(_STDOUT) 244 io.stdout:flush()
237end 245end
238print("ok") 246print("ok")
239 247
240wait(mark(), total()) 248wait(mark(), total())
241 249
242write("parsing mailbox: ") 250io.write("parsing mailbox: ")
243local mbox = parse.mbox(get()) 251local mbox = parse(get())
244print(getn(mbox) .. " messages found!") 252print(table.getn(mbox) .. " messages found!")
245 253
246for i = 1, getn(mbox) do 254for i = 1, table.getn(mbox) do
247 check(sent, mbox[i]) 255 check(sent, mbox[i])
248end 256end
249 257
250
251print("passed all tests") 258print("passed all tests")
252print(format("done in %.2fs", _time() - t)) 259print(string.format("done in %.2fs", socket._time() - t))
diff --git a/test/urltest.lua b/test/urltest.lua
index 8ca36fe..b97844d 100644
--- a/test/urltest.lua
+++ b/test/urltest.lua
@@ -1,5 +1,8 @@
1
2
3
1local check_build_url = function(parsed) 4local check_build_url = function(parsed)
2 local built = URL.build_url(parsed) 5 local built = socket.url.build(parsed)
3 if built ~= parsed.url then 6 if built ~= parsed.url then
4 print("built is different from expected") 7 print("built is different from expected")
5 print(built) 8 print(built)
@@ -9,7 +12,7 @@ local check_build_url = function(parsed)
9end 12end
10 13
11local check_protect = function(parsed, path, unsafe) 14local check_protect = function(parsed, path, unsafe)
12 local built = URL.build_path(parsed, unsafe) 15 local built = socket.url.build_path(parsed, unsafe)
13 if built ~= path then 16 if built ~= path then
14 print(built, path) 17 print(built, path)
15 print("path composition failed.") 18 print("path composition failed.")
@@ -18,9 +21,9 @@ local check_protect = function(parsed, path, unsafe)
18end 21end
19 22
20local check_invert = function(url) 23local check_invert = function(url)
21 local parsed = URL.parse_url(url) 24 local parsed = socket.url.parse(url)
22 parsed.path = URL.build_path(URL.parse_path(parsed.path)) 25 parsed.path = socket.url.build_path(socket.url.parse_path(parsed.path))
23 local rebuilt = URL.build_url(parsed) 26 local rebuilt = socket.url.build(parsed)
24 if rebuilt ~= url then 27 if rebuilt ~= url then
25 print(url, rebuilt) 28 print(url, rebuilt)
26 print("original and rebuilt are different") 29 print("original and rebuilt are different")
@@ -29,7 +32,7 @@ local check_invert = function(url)
29end 32end
30 33
31local check_parse_path = function(path, expect) 34local check_parse_path = function(path, expect)
32 local parsed = URL.parse_path(path) 35 local parsed = socket.url.parse_path(path)
33 for i = 1, math.max(table.getn(parsed), table.getn(expect)) do 36 for i = 1, math.max(table.getn(parsed), table.getn(expect)) do
34 if parsed[i] ~= expect[i] then 37 if parsed[i] ~= expect[i] then
35 print(path) 38 print(path)
@@ -48,7 +51,7 @@ local check_parse_path = function(path, expect)
48 print("is_absolute mismatch") 51 print("is_absolute mismatch")
49 exit() 52 exit()
50 end 53 end
51 local built = URL.build_path(expect) 54 local built = socket.url.build_path(expect)
52 if built ~= path then 55 if built ~= path then
53 print(built, path) 56 print(built, path)
54 print("path composition failed.") 57 print("path composition failed.")
@@ -57,7 +60,7 @@ local check_parse_path = function(path, expect)
57end 60end
58 61
59local check_absolute_url = function(base, relative, absolute) 62local check_absolute_url = function(base, relative, absolute)
60 local res = URL.absolute_url(base, relative) 63 local res = socket.url.absolute(base, relative)
61 if res ~= absolute then 64 if res ~= absolute then
62 write("absolute: In test for '", relative, "' expected '", 65 write("absolute: In test for '", relative, "' expected '",
63 absolute, "' but got '", res, "'\n") 66 absolute, "' but got '", res, "'\n")
@@ -68,7 +71,7 @@ end
68local check_parse_url = function(gaba) 71local check_parse_url = function(gaba)
69 local url = gaba.url 72 local url = gaba.url
70 gaba.url = nil 73 gaba.url = nil
71 local parsed = URL.parse_url(url) 74 local parsed = socket.url.parse(url)
72 for i, v in gaba do 75 for i, v in gaba do
73 if v ~= parsed[i] then 76 if v ~= parsed[i] then
74 write("parse: In test for '", url, "' expected ", i, " = '", 77 write("parse: In test for '", url, "' expected ", i, " = '",