Add the original source packages to maemo, source lenny
[dh-make-perl] / dev / i386 / liburi-perl / liburi-perl-1.35.dfsg.1 / t / abs.t
1 #!perl -w
2
3 print "1..45\n";
4
5 # This test the resolution of abs path for all examples given
6 # in the "Uniform Resource Identifiers (URI): Generic Syntax" document.
7
8 use URI;
9 $base = "http://a/b/c/d;p?q";
10 $testno = 1;
11
12 while (<DATA>) {
13    #next if 1 .. /^C\.\s+/;
14    #last if /^D\.\s+/;
15    next unless /\s+(\S+)\s*=\s*(.*)/;
16    my $uref = $1;
17    my $expect = $2;
18    $expect =~ s/\(current document\)/$base/;
19    #print "$uref => $expect\n";
20
21    my $bad;
22    my $u = URI->new($uref, $base);
23    if ($u->abs($base)->as_string ne $expect) {
24        $bad++;
25        my $abs = $u->abs($base)->as_string;
26        print qq(URI->new("$uref")->abs("$base") ==> "$abs"\n);
27    }
28
29    # Let's test another version of the same thing
30    $u = URI->new($uref);
31    my $b = URI->new($base);
32    if ($u->abs($b,1) ne $expect && $uref !~ /^http:/) {
33        $bad++;
34        print qq(URI->new("$uref")->abs(URI->new("$base"), 1)\n);
35    }
36
37    # Let's try the other way
38    $u = URI->new($expect)->rel($base)->as_string;
39    if ($u ne $uref) {
40        push(@rel_fail, qq($testno: URI->new("$expect", "$base")->rel ==> "$u" (not "$uref")\n));
41    }
42
43    print "not " if $bad;
44    print "ok ", $testno++, "\n";
45 }
46
47 if (@rel_fail) {
48     print "\n\nIn the following cases we did not get back to where we started with rel()\n";
49     print @rel_fail;
50 }
51
52
53
54 __END__
55
56 Network Working Group                            T. Berners-Lee, MIT/LCS
57 INTERNET-DRAFT                                 R. Fielding,  U.C. Irvine
58 draft-fielding-uri-syntax-02              L. Masinter, Xerox Corporation
59 Expires six months after publication date                  March 4, 1998
60
61
62           Uniform Resource Identifiers (URI): Generic Syntax
63
64 [...]
65
66 C. Examples of Resolving Relative URI References
67
68    Within an object with a well-defined base URI of
69
70       http://a/b/c/d;p?q
71
72    the relative URIs would be resolved as follows:
73
74 C.1.  Normal Examples
75
76       g:h           =  g:h
77       g             =  http://a/b/c/g
78       ./g           =  http://a/b/c/g
79       g/            =  http://a/b/c/g/
80       /g            =  http://a/g
81       //g           =  http://g
82       ?y            =  http://a/b/c/d;p?y
83       g?y           =  http://a/b/c/g?y
84       #s            =  (current document)#s
85       g#s           =  http://a/b/c/g#s
86       g?y#s         =  http://a/b/c/g?y#s
87       ;x            =  http://a/b/c/;x
88       g;x           =  http://a/b/c/g;x
89       g;x?y#s       =  http://a/b/c/g;x?y#s
90       .             =  http://a/b/c/
91       ./            =  http://a/b/c/
92       ..            =  http://a/b/
93       ../           =  http://a/b/
94       ../g          =  http://a/b/g
95       ../..         =  http://a/
96       ../../        =  http://a/
97       ../../g       =  http://a/g
98
99 C.2.  Abnormal Examples
100
101    Although the following abnormal examples are unlikely to occur in
102    normal practice, all URI parsers should be capable of resolving them
103    consistently.  Each example uses the same base as above.
104
105    An empty reference refers to the start of the current document.
106
107       <>            =  (current document)
108
109    Parsers must be careful in handling the case where there are more
110    relative path ".." segments than there are hierarchical levels in
111    the base URI's path.  Note that the ".." syntax cannot be used to
112    change the authority component of a URI.
113
114       ../../../g    =  http://a/../g
115       ../../../../g =  http://a/../../g
116
117    In practice, some implementations strip leading relative symbolic
118    elements (".", "..") after applying a relative URI calculation, based
119    on the theory that compensating for obvious author errors is better
120    than allowing the request to fail.  Thus, the above two references
121    will be interpreted as "http://a/g" by some implementations.
122
123    Similarly, parsers must avoid treating "." and ".." as special when
124    they are not complete components of a relative path.
125
126       /./g          =  http://a/./g
127       /../g         =  http://a/../g
128       g.            =  http://a/b/c/g.
129       .g            =  http://a/b/c/.g
130       g..           =  http://a/b/c/g..
131       ..g           =  http://a/b/c/..g
132
133    Less likely are cases where the relative URI uses unnecessary or
134    nonsensical forms of the "." and ".." complete path segments.
135
136       ./../g        =  http://a/b/g
137       ./g/.         =  http://a/b/c/g/
138       g/./h         =  http://a/b/c/g/h
139       g/../h        =  http://a/b/c/h
140       g;x=1/./y     =  http://a/b/c/g;x=1/y
141       g;x=1/../y    =  http://a/b/c/y
142
143    All client applications remove the query component from the base URI
144    before resolving relative URIs.  However, some applications fail to
145    separate the reference's query and/or fragment components from a
146    relative path before merging it with the base path.  This error is
147    rarely noticed, since typical usage of a fragment never includes the
148    hierarchy ("/") character, and the query component is not normally
149    used within relative references.
150
151       g?y/./x       =  http://a/b/c/g?y/./x
152       g?y/../x      =  http://a/b/c/g?y/../x
153       g#s/./x       =  http://a/b/c/g#s/./x
154       g#s/../x      =  http://a/b/c/g#s/../x
155
156    Some parsers allow the scheme name to be present in a relative URI
157    if it is the same as the base URI scheme.  This is considered to be
158    a loophole in prior specifications of partial URIs [RFC1630]. Its
159    use should be avoided.
160
161       http:g        =  http:g
162       http:         =  http:
163
164
165 ==========================================================================
166
167 Some extra tests for good measure...
168
169       #foo?        = (current document)#foo?
170       ?#foo        = http://a/b/c/d;p?#foo
171