forked from
anil.recoil.org/ocaml-requests
A batteries included HTTP/1.1 client in OCaml
1(*---------------------------------------------------------------------------
2 Copyright (c) 2025 Anil Madhavapeddy <anil@recoil.org>. All rights reserved.
3 SPDX-License-Identifier: ISC
4 ---------------------------------------------------------------------------*)
5
6(** Tests for Version module - library version and User-Agent *)
7
8module Version = Version
9
10(** {1 Version String} *)
11
12let test_version_non_empty () =
13 Alcotest.(check bool) "version is non-empty" true (String.length Version.v > 0)
14
15(** {1 Name} *)
16
17let test_name () = Alcotest.(check string) "name" "ocaml-requests" Version.name
18
19(** {1 User-Agent} *)
20
21let test_user_agent_contains_name () =
22 Alcotest.(check bool)
23 "user_agent contains name" true
24 (let ua = String.lowercase_ascii Version.user_agent in
25 let name = String.lowercase_ascii Version.name in
26 try
27 let rec find i =
28 if i + String.length name > String.length ua then raise Not_found
29 else if String.sub ua i (String.length name) = name then true
30 else find (i + 1)
31 in
32 find 0
33 with Not_found -> false)
34
35let test_user_agent_contains_version () =
36 Alcotest.(check bool)
37 "user_agent contains version" true
38 (let ua = Version.user_agent in
39 let ver = Version.v in
40 try
41 let rec find i =
42 if i + String.length ver > String.length ua then raise Not_found
43 else if String.sub ua i (String.length ver) = ver then true
44 else find (i + 1)
45 in
46 find 0
47 with Not_found -> false)
48
49let test_user_agent_non_empty () =
50 Alcotest.(check bool)
51 "user_agent is non-empty" true
52 (String.length Version.user_agent > 0)
53
54(** {1 Test Suite} *)
55
56let suite =
57 ( "version",
58 [
59 Alcotest.test_case "non-empty version" `Quick test_version_non_empty;
60 Alcotest.test_case "name is ocaml-requests" `Quick test_name;
61 Alcotest.test_case "contains name" `Quick test_user_agent_contains_name;
62 Alcotest.test_case "contains version" `Quick
63 test_user_agent_contains_version;
64 Alcotest.test_case "non-empty" `Quick test_user_agent_non_empty;
65 ] )