PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Rose-URI/t/basic.t

http://rose.googlecode.com/
Perl | 94 lines | 61 code | 31 blank | 2 comment | 2 complexity | f276517e2f92138772fe6fe2a75f7160 MD5 | raw file
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use Test::More tests => 28;
  4. BEGIN
  5. {
  6. use_ok('Rose::URI');
  7. }
  8. my $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  9. ok(ref $uri eq 'Rose::URI' && $uri eq 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'parse full URI (&)');
  10. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1;a=2;b=3#blah');
  11. ok(ref $uri eq 'Rose::URI' && $uri eq 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'parse full URI (;)');
  12. is($uri->scheme, 'http', 'scheme()');
  13. is($uri->username, 'un', 'username()');
  14. is($uri->password, 'pw', 'password()');
  15. is($uri->host, 'ob.com', 'host()');
  16. is($uri->port, '81', 'port()');
  17. is($uri->path, '/bar/baz', 'path()');
  18. is($uri->query, 'a=1&a=2&b=3', 'query()');
  19. is($uri->fragment, 'blah', 'fragment()');
  20. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  21. is($uri->abs, 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'abs() (simple)');
  22. $uri = Rose::URI->new('/bar/baz?a=1&a=2&b=3#blah');
  23. is($uri->abs('http://ob.com:81/'), 'http://ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'abs() (with base 1)');
  24. $uri = Rose::URI->new('/bar/baz?a=1&a=2&b=3#blah');
  25. is($uri->abs('http://ob.com:81'), 'http://ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'abs() (with base 2)');
  26. $uri = Rose::URI->new('bar/baz?a=1&a=2&b=3#blah');
  27. is($uri->abs('http://ob.com:81'), 'http://ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'abs() (with base 3)');
  28. $uri = Rose::URI->new('bar/baz?a=1&a=2&b=3#blah');
  29. is($uri->abs('http://ob.com:81/'), 'http://ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'abs() (with base 4)');
  30. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  31. is($uri->rel, 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'rel (no base)');
  32. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  33. is($uri->rel('http://un:pw@ob.com:81/'), 'bar/baz?a=1&a=2&b=3#blah', 'rel (good base 1)');
  34. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  35. is($uri->rel('http://un:pw@ob.com:81'), 'bar/baz?a=1&a=2&b=3#blah', 'rel (good base 2)');
  36. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  37. is($uri->rel('http://ob.com:81'), 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'rel (bad base 1)');
  38. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  39. is($uri->rel('http://un:pw@ob.com/'), 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'rel (bad base 2)');
  40. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  41. is($uri->rel('http://un:pw@ob.com:82/'), 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah', 'rel (bad base 3)');
  42. $uri->query_param(c => '1 + 1 = 2');
  43. is($uri, 'http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3&c=1%20%2B%201%20%3D%202#blah', 'escape 1');
  44. $uri->path('/Foo Bar/Baz');
  45. $uri->username('u/n&');
  46. $uri->query_param(c => '?5/1 + 1-3 = 2_()');
  47. # URI::Escape 3.30 escapes () but older versions do not
  48. ok($uri eq 'http://u%2Fn%26:pw@ob.com:81/Foo%20Bar/Baz?a=1&a=2&b=3&c=%3F5%2F1%20%2B%201-3%20%3D%202_()#blah' ||
  49. $uri eq 'http://u%2Fn%26:pw@ob.com:81/Foo%20Bar/Baz?a=1&a=2&b=3&c=%3F5%2F1%20%2B%201-3%20%3D%202_%28%29#blah', 'escape 2');
  50. my @values = (1, 2);
  51. my %query = (a => \@values, b => 3);
  52. $uri->query(\%query);
  53. my $original_uri = $uri->as_string;
  54. $values[0] = 8;
  55. $query{'b'} = 9;
  56. is($uri->as_string, $original_uri, 'deep copy 1');
  57. my $uri2 = $uri->clone;
  58. is($uri2->as_string, $original_uri, 'clone 1');
  59. $values[0] = 7;
  60. is($uri2->as_string, $original_uri, 'clone 2');
  61. Rose::URI->default_query_param_separator(';');
  62. $uri = Rose::URI->new('http://un:pw@ob.com:81/bar/baz?a=1&a=2&b=3#blah');
  63. is($uri, 'http://un:pw@ob.com:81/bar/baz?a=1;a=2;b=3#blah', 'default query param separator (;)');