1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#!perl -w
use URI::file;
@tests = (
[ "file", "unix", "win32", "mac" ],
#---------------- ------------ --------------- --------------
[ "file://localhost/foo/bar",
"!/foo/bar", "!\\foo\\bar", "!foo:bar", ],
[ "file:///foo/bar",
"/foo/bar", "\\foo\\bar", "!foo:bar", ],
[ "file:/foo/bar", "!/foo/bar", "!\\foo\\bar", "foo:bar", ],
[ "foo/bar", "foo/bar", "foo\\bar", ":foo:bar",],
[ "file://foo/bar","!//foo/bar", "!\\\\foo\\bar", "!foo:bar"],
[ "file://a:/", "!//a:/", "!A:\\", undef],
[ "file:///A:/", "/A:/", "A:\\", undef],
[ "file:///", "/", "\\", undef],
[ ".", ".", ".", ":"],
[ "..", "..", "..", "::"],
[ "%2E", "!.", "!.", ":."],
[ "../%2E%2E", "!../..", "!..\\..", "::.."],
);
@os = @{shift @tests};
shift @os; # file
my $num = @tests;
print "1..$num\n";
$testno = 1;
for $t (@tests) {
my @t = @$t;
my $file = shift @t;
my $err;
my $u = URI->new($file, "file");
my $i = 0;
for $os (@os) {
my $f = $u->file($os);
my $expect = $t[$i];
$f = "<undef>" unless defined $f;
$expect = "<undef>" unless defined $expect;
my $loose;
$loose++ if $expect =~ s/^!//;
if ($expect ne $f) {
print "URI->new('$file', 'file')->file('$os') ne $expect, but $f\n";
$err++;
}
if (defined($t[$i]) && !$loose) {
$u2 = URI::file->new($t[$i], $os);
unless ($u2->as_string eq $file) {
print "URI::file->new('$t[$i]', '$os') ne $file, but $u2\n";
$err++;
}
}
$i++;
}
print "not " if $err;
print "ok $testno\n";
$testno++;
}
|