Skip to content

Commit

Permalink
Convert test to use Test::More
Browse files Browse the repository at this point in the history
  • Loading branch information
gisle committed Jan 22, 2011
1 parent fec082d commit 493e6f2
Showing 1 changed file with 25 additions and 55 deletions.
80 changes: 25 additions & 55 deletions t/query.t
Original file line number Diff line number Diff line change
@@ -1,111 +1,81 @@
#!perl -w

print "1..23\n";

use strict;
use Test::More tests => 23;

use URI ();
my $u = URI->new("", "http");
my @q;

$u->query_form(a => 3, b => 4);

print "not " unless $u eq "?a=3&b=4";
print "ok 1\n";
is $u, "?a=3&b=4";

$u->query_form(a => undef);
print "not " unless $u eq "?a=";
print "ok 2\n";
is $u, "?a=";

$u->query_form("a[=&+#] " => " [=&+#]");
print "not " unless $u eq "?a%5B%3D%26%2B%23%5D+=+%5B%3D%26%2B%23%5D";
print "ok 3\n";
is $u, "?a%5B%3D%26%2B%23%5D+=+%5B%3D%26%2B%23%5D";

@q = $u->query_form;
print "not " unless join(":", @q) eq "a[=&+#] : [=&+#]";
print "ok 4\n";
is join(":", @q), "a[=&+#] : [=&+#]";

@q = $u->query_keywords;
print "not " if @q;
print "ok 5\n";
ok !@q;

$u->query_keywords("a", "b");
print "not " unless $u eq "?a+b";
print "ok 6\n";
is $u, "?a+b";

$u->query_keywords(" ", "+", "=", "[", "]");
print "not " unless $u eq "?%20+%2B+%3D+%5B+%5D";
print "ok 7\n";
is $u, "?%20+%2B+%3D+%5B+%5D";

@q = $u->query_keywords;
print "not " unless join(":", @q) eq " :+:=:[:]";
print "ok 8\n";
is join(":", @q), " :+:=:[:]";

@q = $u->query_form;
print "not " if @q;
print "ok 9\n";
ok !@q;

$u->query(" +?=#");
print "not " unless $u eq "?%20+?=%23";
print "ok 10\n";
is $u, "?%20+?=%23";

$u->query_keywords([qw(a b)]);
print "not " unless $u eq "?a+b";
print "ok 11\n";
is $u, "?a+b";

$u->query_keywords([]);
print "not " unless $u eq "";
print "ok 12\n";
is $u, "";

$u->query_form({ a => 1, b => 2 });
print "not " unless $u eq "?a=1&b=2" || $u eq "?b=2&a=1";
print "ok 13\n";
ok $u eq "?a=1&b=2" || $u eq "?b=2&a=1";

$u->query_form([ a => 1, b => 2 ]);
print "not " unless $u eq "?a=1&b=2";
print "ok 14\n";
is $u, "?a=1&b=2";

$u->query_form({});
print "not " unless $u eq "";
print "ok 15\n";
is $u, "";

$u->query_form([a => [1..4]]);
print "not " unless $u eq "?a=1&a=2&a=3&a=4";
print "ok 16\n";
is $u, "?a=1&a=2&a=3&a=4";

$u->query_form([]);
print "not " unless $u eq "";
print "ok 17\n";
is $u, "";

$u->query_form(a => { foo => 1 });
print "not " unless "$u" =~ /^\?a=HASH\(/;
print "ok 18\n";
ok "$u" =~ /^\?a=HASH\(/;

$u->query_form(a => 1, b => 2, ';');
print "not " unless $u eq "?a=1;b=2";
print "ok 19\n";
is $u, "?a=1;b=2";

$u->query_form(a => 1, c => 2);
print "not " unless $u eq "?a=1;c=2";
print "ok 20\n";
is $u, "?a=1;c=2";

$u->query_form(a => 1, c => 2, '&');
print "not " unless $u eq "?a=1&c=2";
print "ok 21\n";
is $u, "?a=1&c=2";

$u->query_form([a => 1, b => 2], ';');
print "not " unless $u eq "?a=1;b=2";
print "ok 22\n";
is $u, "?a=1;b=2";

$u->query_form([]);
{
local $URI::DEFAULT_QUERY_FORM_DELIMITER = ';';
$u->query_form(a => 1, b => 2);
}
print "not " unless $u eq "?a=1;b=2";
print "ok 23\n";

__END__
# Some debugging while writing new tests
print "\@q='", join(":", @q), "'\n";
print "\$u='$u'\n";
is $u, "?a=1;b=2";

0 comments on commit 493e6f2

Please sign in to comment.