diff options
Diffstat (limited to 't/heuristic.t')
-rw-r--r-- | t/heuristic.t | 86 |
1 files changed, 30 insertions, 56 deletions
diff --git a/t/heuristic.t b/t/heuristic.t index e64c338..037497b 100644 --- a/t/heuristic.t +++ b/t/heuristic.t @@ -13,7 +13,7 @@ BEGIN { }; } -print "1..26\n"; +use Test::More tests => 26; use URI::Heuristic qw(uf_url uf_urlstr); if (shift) { @@ -21,33 +21,28 @@ if (shift) { open(STDERR, ">&STDOUT"); # redirect STDERR } -print "not " unless uf_urlstr("http://www.sn.no/") eq "http://www.sn.no/"; -print "ok 1\n"; +is(uf_urlstr("http://www.sn.no/"), "http://www.sn.no/"); if ($^O eq "MacOS") { - print "not " unless uf_urlstr("etc:passwd") eq "file:/etc/passwd"; + is(uf_urlstr("etc:passwd"), "file:/etc/passwd"); } else { -print "not " unless uf_urlstr("/etc/passwd") eq "file:/etc/passwd"; + is(uf_urlstr("/etc/passwd"), "file:/etc/passwd"); } -print "ok 2\n"; if ($^O eq "MacOS") { - print "not " unless uf_urlstr(":foo.txt") eq "file:./foo.txt"; + is(uf_urlstr(":foo.txt"), "file:./foo.txt"); } else { -print "not " unless uf_urlstr("./foo.txt") eq "file:./foo.txt"; + is(uf_urlstr("./foo.txt"), "file:./foo.txt"); } -print "ok 3\n"; -print "not " unless uf_urlstr("ftp.aas.no/lwp.tar.gz") eq "ftp://ftp.aas.no/lwp.tar.gz"; -print "ok 4\n"; +is(uf_urlstr("ftp.aas.no/lwp.tar.gz"), "ftp://ftp.aas.no/lwp.tar.gz"); if($^O eq "MacOS") { # its a weird, but valid, MacOS path, so it can't be left alone - print "not " unless uf_urlstr("C:\\CONFIG.SYS") eq "file:/C/%5CCONFIG.SYS"; + is(uf_urlstr("C:\\CONFIG.SYS"), "file:/C/%5CCONFIG.SYS"); } else { -print "not " unless uf_urlstr("C:\\CONFIG.SYS") eq "file:C:\\CONFIG.SYS"; + is(uf_urlstr("C:\\CONFIG.SYS"), "file:C:\\CONFIG.SYS"); } -print "ok 5\n"; { local $ENV{LC_ALL} = ""; @@ -56,83 +51,62 @@ print "ok 5\n"; $ENV{LC_ALL} = "en_GB.UTF-8"; undef $URI::Heuristic::MY_COUNTRY; - print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.(org|co)\.uk/camel\.gif$,; - print "ok 6\n"; + like(uf_urlstr("perl/camel.gif"), qr,^http://www\.perl\.(org|co)\.uk/camel\.gif$,); use Net::Domain (); $ENV{LC_ALL} = "C"; { no warnings; *Net::Domain::hostfqdn = sub { return 'vasya.su' } } undef $URI::Heuristic::MY_COUNTRY; - print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.su/camel\.gif$,; - print "ok 7\n"; + is(uf_urlstr("perl/camel.gif"), "http://www.perl.su/camel.gif"); $ENV{LC_ALL} = "C"; { no warnings; *Net::Domain::hostfqdn = sub { return '' } } undef $URI::Heuristic::MY_COUNTRY; - print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.(com|org)/camel\.gif$,; - print "ok 8\n"; + like(uf_urlstr("perl/camel.gif"), qr,^http://www\.perl\.(com|org)/camel\.gif$,); $ENV{HTTP_ACCEPT_LANGUAGE} = "en-ca"; undef $URI::Heuristic::MY_COUNTRY; - print "not " unless uf_urlstr("perl/camel.gif") eq "http://www.perl.ca/camel.gif"; - print "ok 9\n"; + is(uf_urlstr("perl/camel.gif"), "http://www.perl.ca/camel.gif"); } $URI::Heuristic::MY_COUNTRY = "bv"; -print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.(com|org)/camel\.gif$,; -print "ok 10\n"; +like(uf_urlstr("perl/camel.gif"), qr,^http://www\.perl\.(com|org)/camel\.gif$,); # Backwards compatibility; uk != United Kingdom in ISO 3166 $URI::Heuristic::MY_COUNTRY = "uk"; -print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.(org|co)\.uk/camel\.gif$,; -print "ok 11\n"; +like(uf_urlstr("perl/camel.gif"), qr,^http://www\.perl\.(org|co)\.uk/camel\.gif$,); $URI::Heuristic::MY_COUNTRY = "gb"; -print "not " unless uf_urlstr("perl/camel.gif") =~ m,^http://www\.perl\.(org|co)\.uk/camel\.gif$,; -print "ok 12\n"; +like(uf_urlstr("perl/camel.gif"), qr,^http://www\.perl\.(org|co)\.uk/camel\.gif$,); $ENV{URL_GUESS_PATTERN} = "www.ACME.org www.ACME.com"; -print "not " unless uf_urlstr("perl") eq "http://www.perl.org"; -print "ok 13\n"; +is(uf_urlstr("perl"), "http://www.perl.org"); { local $ENV{URL_GUESS_PATTERN} = ""; - print "not " unless uf_urlstr("perl") eq "http://perl"; - print "ok 14\n"; + is(uf_urlstr("perl"), "http://perl"); - print "not " unless uf_urlstr("http:80") eq "http:80"; - print "ok 15\n"; + is(uf_urlstr("http:80"), "http:80"); - print "not " unless uf_urlstr("mailto:gisle\@aas.no") eq "mailto:gisle\@aas.no"; - print "ok 16\n"; + is(uf_urlstr("mailto:gisle\@aas.no"), "mailto:gisle\@aas.no"); - print "not " unless uf_urlstr("gisle\@aas.no") eq "mailto:gisle\@aas.no"; - print "ok 17\n"; + is(uf_urlstr("gisle\@aas.no"), "mailto:gisle\@aas.no"); - print "not " unless uf_urlstr("Gisle.Aas\@aas.perl.org") eq "mailto:Gisle.Aas\@aas.perl.org"; - print "ok 18\n"; + is(uf_urlstr("Gisle.Aas\@aas.perl.org"), "mailto:Gisle.Aas\@aas.perl.org"); - print "not " unless uf_url("gopher.sn.no")->scheme eq "gopher"; - print "ok 19\n"; + is(uf_url("gopher.sn.no")->scheme, "gopher"); - print "not " unless uf_urlstr("123.3.3.3:8080/foo") eq "http://123.3.3.3:8080/foo"; - print "ok 20\n"; + is(uf_urlstr("123.3.3.3:8080/foo"), "http://123.3.3.3:8080/foo"); - print "not " unless uf_urlstr("123.3.3.3:443/foo") eq "https://123.3.3.3:443/foo"; - print "ok 21\n"; + is(uf_urlstr("123.3.3.3:443/foo"), "https://123.3.3.3:443/foo"); - print "not " unless uf_urlstr("123.3.3.3:21/foo") eq "ftp://123.3.3.3:21/foo"; - print "ok 22\n"; + is(uf_urlstr("123.3.3.3:21/foo"), "ftp://123.3.3.3:21/foo"); - print "not " unless uf_url("FTP.example.com")->scheme eq "ftp"; - print "ok 23\n"; + is(uf_url("FTP.example.com")->scheme, "ftp"); - print "not " unless uf_url("ftp2.example.com")->scheme eq "ftp"; - print "ok 24\n"; + is(uf_url("ftp2.example.com")->scheme, "ftp"); - print "not " unless uf_url("ftp")->scheme eq "ftp"; - print "ok 25\n"; + is(uf_url("ftp")->scheme, "ftp"); - print "not " unless uf_url("https.example.com")->scheme eq "https"; - print "ok 26\n"; + is(uf_url("https.example.com")->scheme, "https"); } |