3 * _| || |_/ ___| ___ _ __ _ __ ___ | |
4 * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
5 * |_ _|___) | __/ |_) | |_) | (_) |_|
6 * |_||_| |____/ \___| .__/| .__/ \___/(_)
13 * Copyright (C) The #Seppo contributors. All rights reserved.
15 * This program is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 let a = Uri.of_string
"https://example.xom/a/a.a/?a#a"
33 and b
= Uri.of_string
"./b?b#b" in
36 |> Assrt.equals_string __LOC__
"https://example.xom/a/a.a/b?b#b";
37 let b = Uri.of_string
"http://example.com/c?c#c" in
40 |> Assrt.equals_string __LOC__
"http://example.com/c?c#c"
43 let sub ?
(pos
= 0) ?
(len
= -1) s
=
46 else (String.length s
) - pos
in
55 |> Assrt.equals_string __LOC__
"fo%40%20o@example.com"
58 Logr.info
(fun m
-> m
"uri_test.test_0" );
59 let ends_with ~suffix s
=
60 let l = s
|> String.length
61 and l'
= suffix
|> String.length
in
63 (* Logr.info (fun m -> m "uri_test.test_0 f %d %d" i' i); *)
67 || (suffix
.[i'
] = s
.[i]
73 assert (ends_with ~suffix
:"" "");
74 assert (ends_with ~suffix
:"s" "s");
75 assert (ends_with ~suffix
:"/seppo.cgi" "uhu/seppo.cgi");
76 assert (ends_with ~suffix
:"🐫" "s🐫");
77 assert (not
(ends_with ~suffix
:"s" ""));
78 assert (not
(ends_with ~suffix
:"s" "su"));
79 assert (not
(ends_with ~suffix
:"s" "su"));
84 Logr.info
(fun m
-> m
"uri_test.test_1" );
85 let u = "https://uid@example.com/dir/seppo.cgi"
88 u |> Uri.user
|> Option.get
|> Assrt.equals_string __LOC__
"uid" ;
89 u |> Uri.host
|> Option.get
|> Assrt.equals_string __LOC__
"example.com" ;
90 u |> Uri.path
|> Assrt.equals_string __LOC__
"/dir/seppo.cgi" ;
91 let u = u |> Uri.with_uri ~userinfo
:(Some
"ufo") in
92 u |> Uri.user
|> Option.get
|> Assrt.equals_string __LOC__
"ufo" ;