| 1 |
-- with Ada.Text_IO; use Ada.Text_IO; |
| 2 |
|
| 3 |
procedure URI.Test is |
| 4 |
T_1 : constant String := |
| 5 |
"http://anon:[email protected]/highway/to/?sure&really#hell"; |
| 6 |
T_2 : constant String := "urn:example:animal:ferret:nose"; |
| 7 |
begin |
| 8 |
|
| 9 |
-- Individual parts |
| 10 |
|
| 11 |
pragma Assert (Extract ("", Scheme) = ""); |
| 12 |
pragma Assert (Extract ("file:", Scheme) = "file"); |
| 13 |
pragma Assert (Extract (" file:", Scheme) = "file"); -- leading whitespace |
| 14 |
pragma Assert (Extract ("#space ", Fragment) = "space"); -- lagging whitespace |
| 15 |
pragma Assert (Extract ("#space", Path) = ""); -- Empty path |
| 16 |
|
| 17 |
pragma Assert (Extract (T_1, Scheme) = "http"); |
| 18 |
pragma Assert (Extract (T_1, Authority) = "anon:[email protected]"); |
| 19 |
pragma Assert (Extract (T_1, Path) = "/highway/to/"); |
| 20 |
pragma Assert (Extract (T_1, Query) = "sure&really"); |
| 21 |
pragma Assert (Extract (T_1, Fragment) = "hell"); |
| 22 |
|
| 23 |
pragma Assert (Extract (T_2, Scheme) = "urn"); |
| 24 |
pragma Assert (Extract (T_2, Authority) = ""); |
| 25 |
pragma Assert (Extract (T_2, Path) = "example:animal:ferret:nose"); |
| 26 |
pragma Assert (Extract (T_2, Query) = ""); |
| 27 |
pragma Assert (Extract (T_2, Fragment) = ""); |
| 28 |
|
| 29 |
-- Bizarre individual parts |
| 30 |
|
| 31 |
pragma Assert (Extract ("git+http:", Scheme) = "git+http"); |
| 32 |
pragma Assert (Extract ("http::nowhere", Scheme) = "http"); |
| 33 |
pragma Assert (Extract ("http::nowhere", Path) = ":nowhere"); |
| 34 |
|
| 35 |
pragma Assert (Extract ("///auth", Authority) = ""); |
| 36 |
pragma Assert (Extract ("///auth", Path) = "/auth"); |
| 37 |
|
| 38 |
pragma Assert (Extract ("//+auth", Authority) = "+auth"); |
| 39 |
pragma Assert (Extract ("//?auth", Authority) = ""); |
| 40 |
pragma Assert (Extract ("//#auth", Authority) = ""); |
| 41 |
pragma Assert (Extract ("//../uh/oh", Authority) = ".."); |
| 42 |
|
| 43 |
pragma Assert (Extract ("//?", Path) = ""); |
| 44 |
pragma Assert (Extract ("///+asdf?", Path) = "/+asdf"); |
| 45 |
pragma Assert (Extract ("//../uh/oh", Path) = "/uh/oh"); |
| 46 |
|
| 47 |
pragma Assert (Extract ("??", Query) = "?"); |
| 48 |
pragma Assert (Extract ("?#", Query) = ""); |
| 49 |
pragma Assert (Extract ("??&#?", Query) = "?&"); |
| 50 |
pragma Assert (Extract ("?&#?", Query) = "&"); |
| 51 |
|
| 52 |
pragma Assert (Extract ("??&#?", Fragment) = "?"); |
| 53 |
pragma Assert (Extract ("#", Fragment) = ""); |
| 54 |
pragma Assert (Extract ("##", Fragment) = "#"); |
| 55 |
|
| 56 |
-- Counterintuitive Authority/Path combos |
| 57 |
|
| 58 |
pragma Assert (Extract ("file://hello.txt", Authority) = "hello.txt"); |
| 59 |
pragma Assert (Extract ("file://hello.txt", Path) = ""); |
| 60 |
pragma Assert (Permissive_Path ("file://hello.txt") = "hello.txt"); |
| 61 |
|
| 62 |
pragma Assert (Extract ("file:///hello.txt", Authority) = ""); |
| 63 |
pragma Assert (Extract ("file:///hello.txt", Path) = "/hello.txt"); |
| 64 |
pragma Assert (Permissive_Path ("file:///hello.txt") = "/hello.txt"); |
| 65 |
|
| 66 |
pragma Assert (Extract ("file:../hello.txt", Authority) = ""); |
| 67 |
pragma Assert (Extract ("file:../hello.txt", Path) = "../hello.txt"); |
| 68 |
pragma Assert (Permissive_Path ("file:../hello.txt") = "../hello.txt"); |
| 69 |
|
| 70 |
pragma Assert (Extract ("file://../hello.txt", Authority) = ".."); |
| 71 |
pragma Assert (Extract ("file://../hello.txt", Path) = "/hello.txt"); |
| 72 |
pragma Assert (Permissive_Path ("file://../hello.txt") = "../hello.txt"); |
| 73 |
|
| 74 |
pragma Assert (Extract ("file:/hello.txt", Authority) = ""); |
| 75 |
pragma Assert (Extract ("file:/hello.txt", Path) = "/hello.txt"); |
| 76 |
pragma Assert (Permissive_Path ("file:/hello.txt") = "/hello.txt"); |
| 77 |
|
| 78 |
-- Slices |
| 79 |
|
| 80 |
pragma Assert (Extract ("file:///path/to", Scheme, Path) = "file:/path/to"); |
| 81 |
pragma Assert (Extract ("file:///path/to", Authority, Authority) = ""); |
| 82 |
|
| 83 |
pragma Assert (Extract (T_1, Scheme, Fragment) = T_1); |
| 84 |
pragma Assert (Extract (T_1, Authority, Query) = "anon:[email protected]/highway/to/?sure&really"); |
| 85 |
pragma Assert (Extract (T_1, Path, Query) = "/highway/to/?sure&really"); |
| 86 |
pragma Assert (Extract (T_1, Scheme, Authority) = "http://anon:[email protected]"); |
| 87 |
pragma Assert (Extract (T_1, Authority, Path) = "anon:[email protected]/highway/to/"); |
| 88 |
|
| 89 |
pragma Assert (Extract (T_2, Scheme, Fragment) = T_2); |
| 90 |
pragma Assert (Extract (T_2, Authority, Query) = "example:animal:ferret:nose"); |
| 91 |
pragma Assert (Extract (T_2, Path, Query) = "example:animal:ferret:nose"); |
| 92 |
pragma Assert (Extract (T_2, Scheme, Authority) = "urn"); |
| 93 |
pragma Assert (Extract (T_2, Scheme, Path) = T_2); |
| 94 |
pragma Assert (Extract (T_2, Authority, Path) = "example:animal:ferret:nose"); |
| 95 |
|
| 96 |
end URI.Test; |