1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 module tanya.net.tests.uri;
5 
6 import tanya.net.uri;
7 import tanya.test.assertion;
8 
9 @nogc pure @system unittest
10 {
11     const u = URL("127.0.0.1");
12     assert(u.path == "127.0.0.1");
13 }
14 
15 @nogc pure @system unittest
16 {
17     const u = URL("http://127.0.0.1");
18     assert(u.scheme == "http");
19     assert(u.host == "127.0.0.1");
20 }
21 
22 @nogc pure @system unittest
23 {
24     const u = URL("http://127.0.0.1:9000");
25     assert(u.scheme == "http");
26     assert(u.host == "127.0.0.1");
27     assert(u.port == 9000);
28 }
29 
30 @nogc pure @system unittest
31 {
32     const u = URL("127.0.0.1:80");
33     assert(u.host == "127.0.0.1");
34     assert(u.port == 80);
35     assert(u.path is null);
36 }
37 
38 @nogc pure @system unittest
39 {
40     const u = URL("//example.net");
41     assert(u.host == "example.net");
42     assert(u.scheme is null);
43 }
44 
45 @nogc pure @system unittest
46 {
47     const u = URL("//example.net?q=before:after");
48     assert(u.host == "example.net");
49     assert(u.query == "q=before:after");
50 }
51 
52 @nogc pure @system unittest
53 {
54     const u = URL("localhost:8080");
55     assert(u.host == "localhost");
56     assert(u.port == 8080);
57     assert(u.path is null);
58 }
59 
60 @nogc pure @system unittest
61 {
62     const u = URL("ftp:");
63     assert(u.scheme == "ftp");
64 }
65 
66 @nogc pure @system unittest
67 {
68     const u = URL("file:///C:\\Users");
69     assert(u.scheme == "file");
70     assert(u.path == "C:\\Users");
71 }
72 
73 @nogc pure @system unittest
74 {
75     const u = URL("localhost:66000");
76     assert(u.scheme == "localhost");
77     assert(u.path == "66000");
78 }
79 
80 @nogc pure @system unittest
81 {
82     const u = URL("file:///home/");
83     assert(u.scheme == "file");
84     assert(u.path == "/home/");
85 }
86 
87 @nogc pure @system unittest
88 {
89     const u = URL("file:///home/?q=asdf");
90     assert(u.scheme == "file");
91     assert(u.path == "/home/");
92     assert(u.query == "q=asdf");
93 }
94 
95 @nogc pure @system unittest
96 {
97     const u = URL("http://secret@example.org");
98     assert(u.scheme == "http");
99     assert(u.host == "example.org");
100     assert(u.user == "secret");
101 }
102 
103 @nogc pure @system unittest
104 {
105     const u = URL("h_tp://:80");
106     assert(u.path == "h_tp://:80");
107     assert(u.port == 0);
108 }
109 
110 @nogc pure @system unittest
111 {
112     const u = URL("zlib:/home/user/file.gz");
113     assert(u.scheme == "zlib");
114     assert(u.path == "/home/user/file.gz");
115 }
116 
117 @nogc pure @system unittest
118 {
119     const u = URL("h_tp:asdf");
120     assert(u.path == "h_tp:asdf");
121 }
122 
123 @nogc pure @system unittest
124 {
125     assertThrown!URIException(() => URL("http://:80"));
126     assertThrown!URIException(() => URL(":80"));
127     assertThrown!URIException(() => URL("http://u1:p1@u2:p2@example.org"));
128     assertThrown!URIException(() => URL("http://blah.com:port"));
129     assertThrown!URIException(() => URL("http://blah.com:66000"));
130 }
131 
132 @nogc pure @system unittest
133 {
134     const u = URL("ftp://");
135     assert(u.scheme == "ftp");
136 }