diff options
author | Diego Nehab <diego.nehab@gmail.com> | 2012-04-23 00:18:45 +0800 |
---|---|---|
committer | Diego Nehab <diego.nehab@gmail.com> | 2012-04-23 00:18:45 +0800 |
commit | f960b3872a668ed1b53bd50c5b6a708367332f3c (patch) | |
tree | e82a1b113ed40d70afae36d230b6a6048e1d9fab /test | |
parent | f37e0260261f7691246429d227cf7124c291e8b1 (diff) | |
download | luasocket-f960b3872a668ed1b53bd50c5b6a708367332f3c.tar.gz luasocket-f960b3872a668ed1b53bd50c5b6a708367332f3c.tar.bz2 luasocket-f960b3872a668ed1b53bd50c5b6a708367332f3c.zip |
Making progress toward a release
Documented headers.lua
Update copyright date everywhere
Remove RCSID from files
Move version back to 2.1 rather than 2.1.1
Fixed url package to support ipv6 hosts
Changed "domain" to "family" in tcp and udp structures
Implemented getfamily methods
Diffstat (limited to 'test')
-rw-r--r-- | test/urltest.lua | 131 |
1 files changed, 121 insertions, 10 deletions
diff --git a/test/urltest.lua b/test/urltest.lua index d46cb03..71e4428 100644 --- a/test/urltest.lua +++ b/test/urltest.lua | |||
@@ -8,7 +8,7 @@ local check_build_url = function(parsed) | |||
8 | print("built is different from expected") | 8 | print("built is different from expected") |
9 | print(built) | 9 | print(built) |
10 | print(expected) | 10 | print(expected) |
11 | exit() | 11 | os.exit() |
12 | end | 12 | end |
13 | end | 13 | end |
14 | 14 | ||
@@ -17,7 +17,7 @@ local check_protect = function(parsed, path, unsafe) | |||
17 | if built ~= path then | 17 | if built ~= path then |
18 | print(built, path) | 18 | print(built, path) |
19 | print("path composition failed.") | 19 | print("path composition failed.") |
20 | exit() | 20 | os.exit() |
21 | end | 21 | end |
22 | end | 22 | end |
23 | 23 | ||
@@ -28,7 +28,7 @@ local check_invert = function(url) | |||
28 | if rebuilt ~= url then | 28 | if rebuilt ~= url then |
29 | print(url, rebuilt) | 29 | print(url, rebuilt) |
30 | print("original and rebuilt are different") | 30 | print("original and rebuilt are different") |
31 | exit() | 31 | os.exit() |
32 | end | 32 | end |
33 | end | 33 | end |
34 | 34 | ||
@@ -37,24 +37,24 @@ local check_parse_path = function(path, expect) | |||
37 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do | 37 | for i = 1, math.max(table.getn(parsed), table.getn(expect)) do |
38 | if parsed[i] ~= expect[i] then | 38 | if parsed[i] ~= expect[i] then |
39 | print(path) | 39 | print(path) |
40 | exit() | 40 | os.exit() |
41 | end | 41 | end |
42 | end | 42 | end |
43 | if expect.is_directory ~= parsed.is_directory then | 43 | if expect.is_directory ~= parsed.is_directory then |
44 | print(path) | 44 | print(path) |
45 | print("is_directory mismatch") | 45 | print("is_directory mismatch") |
46 | exit() | 46 | os.exit() |
47 | end | 47 | end |
48 | if expect.is_absolute ~= parsed.is_absolute then | 48 | if expect.is_absolute ~= parsed.is_absolute then |
49 | print(path) | 49 | print(path) |
50 | print("is_absolute mismatch") | 50 | print("is_absolute mismatch") |
51 | exit() | 51 | os.exit() |
52 | end | 52 | end |
53 | local built = socket.url.build_path(expect) | 53 | local built = socket.url.build_path(expect) |
54 | if built ~= path then | 54 | if built ~= path then |
55 | print(built, path) | 55 | print(built, path) |
56 | print("path composition failed.") | 56 | print("path composition failed.") |
57 | exit() | 57 | os.exit() |
58 | end | 58 | end |
59 | end | 59 | end |
60 | 60 | ||
@@ -63,7 +63,7 @@ local check_absolute_url = function(base, relative, absolute) | |||
63 | if res ~= absolute then | 63 | if res ~= absolute then |
64 | io.write("absolute: In test for '", relative, "' expected '", | 64 | io.write("absolute: In test for '", relative, "' expected '", |
65 | absolute, "' but got '", res, "'\n") | 65 | absolute, "' but got '", res, "'\n") |
66 | exit() | 66 | os.exit() |
67 | end | 67 | end |
68 | end | 68 | end |
69 | 69 | ||
@@ -76,7 +76,7 @@ local check_parse_url = function(gaba) | |||
76 | io.write("parse: In test for '", url, "' expected ", i, " = '", | 76 | io.write("parse: In test for '", url, "' expected ", i, " = '", |
77 | v, "' but got '", tostring(parsed[i]), "'\n") | 77 | v, "' but got '", tostring(parsed[i]), "'\n") |
78 | for i,v in pairs(parsed) do print(i,v) end | 78 | for i,v in pairs(parsed) do print(i,v) end |
79 | exit() | 79 | os.exit() |
80 | end | 80 | end |
81 | end | 81 | end |
82 | for i, v in pairs(parsed) do | 82 | for i, v in pairs(parsed) do |
@@ -84,7 +84,7 @@ local check_parse_url = function(gaba) | |||
84 | io.write("parse: In test for '", url, "' expected ", i, " = '", | 84 | io.write("parse: In test for '", url, "' expected ", i, " = '", |
85 | tostring(gaba[i]), "' but got '", v, "'\n") | 85 | tostring(gaba[i]), "' but got '", v, "'\n") |
86 | for i,v in pairs(parsed) do print(i,v) end | 86 | for i,v in pairs(parsed) do print(i,v) end |
87 | exit() | 87 | os.exit() |
88 | end | 88 | end |
89 | end | 89 | end |
90 | end | 90 | end |
@@ -304,6 +304,92 @@ check_parse_url{ | |||
304 | path = "path", | 304 | path = "path", |
305 | } | 305 | } |
306 | 306 | ||
307 | -- IPv6 tests | ||
308 | |||
309 | check_parse_url{ | ||
310 | url = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", | ||
311 | scheme = "http", | ||
312 | host = "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", | ||
313 | authority = "[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80", | ||
314 | port = "80", | ||
315 | path = "/index.html" | ||
316 | } | ||
317 | |||
318 | check_parse_url{ | ||
319 | url = "http://[1080:0:0:0:8:800:200C:417A]/index.html", | ||
320 | scheme = "http", | ||
321 | host = "1080:0:0:0:8:800:200C:417A", | ||
322 | authority = "[1080:0:0:0:8:800:200C:417A]", | ||
323 | path = "/index.html" | ||
324 | } | ||
325 | |||
326 | check_parse_url{ | ||
327 | url = "http://[3ffe:2a00:100:7031::1]", | ||
328 | scheme = "http", | ||
329 | host = "3ffe:2a00:100:7031::1", | ||
330 | authority = "[3ffe:2a00:100:7031::1]", | ||
331 | } | ||
332 | |||
333 | check_parse_url{ | ||
334 | url = "http://[1080::8:800:200C:417A]/foo", | ||
335 | scheme = "http", | ||
336 | host = "1080::8:800:200C:417A", | ||
337 | authority = "[1080::8:800:200C:417A]", | ||
338 | path = "/foo" | ||
339 | } | ||
340 | |||
341 | check_parse_url{ | ||
342 | url = "http://[::192.9.5.5]/ipng", | ||
343 | scheme = "http", | ||
344 | host = "::192.9.5.5", | ||
345 | authority = "[::192.9.5.5]", | ||
346 | path = "/ipng" | ||
347 | } | ||
348 | |||
349 | check_parse_url{ | ||
350 | url = "http://[::FFFF:129.144.52.38]:80/index.html", | ||
351 | scheme = "http", | ||
352 | host = "::FFFF:129.144.52.38", | ||
353 | port = "80", | ||
354 | authority = "[::FFFF:129.144.52.38]:80", | ||
355 | path = "/index.html" | ||
356 | } | ||
357 | |||
358 | check_parse_url{ | ||
359 | url = "http://[2010:836B:4179::836B:4179]", | ||
360 | scheme = "http", | ||
361 | host = "2010:836B:4179::836B:4179", | ||
362 | authority = "[2010:836B:4179::836B:4179]", | ||
363 | } | ||
364 | |||
365 | check_parse_url{ | ||
366 | url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", | ||
367 | authority = "userinfo@[::FFFF:129.144.52.38]:port", | ||
368 | host = "::FFFF:129.144.52.38", | ||
369 | port = "port", | ||
370 | userinfo = "userinfo", | ||
371 | user = "userinfo", | ||
372 | path = "/path", | ||
373 | params = "params", | ||
374 | query = "query", | ||
375 | fragment = "fragment" | ||
376 | } | ||
377 | |||
378 | check_parse_url{ | ||
379 | url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", | ||
380 | scheme = "scheme", | ||
381 | authority = "user:password@[::192.9.5.5]:port", | ||
382 | host = "::192.9.5.5", | ||
383 | port = "port", | ||
384 | userinfo = "user:password", | ||
385 | user = "user", | ||
386 | password = "password", | ||
387 | path = "/path", | ||
388 | params = "params", | ||
389 | query = "query", | ||
390 | fragment = "fragment" | ||
391 | } | ||
392 | |||
307 | print("testing URL building") | 393 | print("testing URL building") |
308 | check_build_url { | 394 | check_build_url { |
309 | url = "scheme://user:password@host:port/path;params?query#fragment", | 395 | url = "scheme://user:password@host:port/path;params?query#fragment", |
@@ -318,6 +404,30 @@ check_build_url { | |||
318 | fragment = "fragment" | 404 | fragment = "fragment" |
319 | } | 405 | } |
320 | 406 | ||
407 | check_build_url{ | ||
408 | url = "//userinfo@[::FFFF:129.144.52.38]:port/path;params?query#fragment", | ||
409 | host = "::FFFF:129.144.52.38", | ||
410 | port = "port", | ||
411 | user = "userinfo", | ||
412 | path = "/path", | ||
413 | params = "params", | ||
414 | query = "query", | ||
415 | fragment = "fragment" | ||
416 | } | ||
417 | |||
418 | check_build_url{ | ||
419 | url = "scheme://user:password@[::192.9.5.5]:port/path;params?query#fragment", | ||
420 | scheme = "scheme", | ||
421 | host = "::192.9.5.5", | ||
422 | port = "port", | ||
423 | user = "user", | ||
424 | password = "password", | ||
425 | path = "/path", | ||
426 | params = "params", | ||
427 | query = "query", | ||
428 | fragment = "fragment" | ||
429 | } | ||
430 | |||
321 | check_build_url { | 431 | check_build_url { |
322 | url = "scheme://user:password@host/path;params?query#fragment", | 432 | url = "scheme://user:password@host/path;params?query#fragment", |
323 | scheme = "scheme", | 433 | scheme = "scheme", |
@@ -520,5 +630,6 @@ check_invert("/b/c/d;param#fragment") | |||
520 | check_invert("/b/c/d;param?query#fragment") | 630 | check_invert("/b/c/d;param?query#fragment") |
521 | check_invert("/b/c/d?query") | 631 | check_invert("/b/c/d?query") |
522 | check_invert("/b/c/d;param?query") | 632 | check_invert("/b/c/d;param?query") |
633 | check_invert("http://he:man@[::192.168.1.1]/a/b/c/i.html;type=moo?this=that#mark") | ||
523 | 634 | ||
524 | print("the library passed all tests") | 635 | print("the library passed all tests") |