summaryrefslogtreecommitdiff
path: root/t/file.t
diff options
context:
space:
mode:
Diffstat (limited to 't/file.t')
-rw-r--r--t/file.t65
1 files changed, 65 insertions, 0 deletions
diff --git a/t/file.t b/t/file.t
new file mode 100644
index 0000000..26e0119
--- /dev/null
+++ b/t/file.t
@@ -0,0 +1,65 @@
+#!perl -T
+
+use strict;
+use warnings;
+
+use URI::file;
+
+my @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://foo3445x/bar","!//foo3445x/bar", "!\\\\foo3445x\\bar", "!foo3445x:bar"],
+[ "file://a:/", "!//a:/", "!A:\\", undef],
+[ "file:///A:/", "/A:/", "A:\\", undef],
+[ "file:///", "/", "\\", undef],
+[ ".", ".", ".", ":"],
+[ "..", "..", "..", "::"],
+[ "%2E", "!.", "!.", ":."],
+[ "../%2E%2E", "!../..", "!..\\..", "::.."],
+);
+
+my @os = @{shift @tests};
+shift @os; # file
+
+my $num = @tests;
+print "1..$num\n";
+
+my $testno = 1;
+
+for my $t (@tests) {
+ my @t = @$t;
+ my $file = shift @t;
+ my $err;
+
+ my $u = URI->new($file, "file");
+ my $i = 0;
+ for my $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) {
+ my $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++;
+}