(*--------------------------------------------------------------------------- Copyright (c) 2025 Anil Madhavapeddy . All rights reserved. SPDX-License-Identifier: ISC ---------------------------------------------------------------------------*) (** Tests for Version module - library version and User-Agent *) module Version = Version (** {1 Version String} *) let test_version_non_empty () = Alcotest.(check bool) "version is non-empty" true (String.length Version.v > 0) (** {1 Name} *) let test_name () = Alcotest.(check string) "name" "ocaml-requests" Version.name (** {1 User-Agent} *) let test_user_agent_contains_name () = Alcotest.(check bool) "user_agent contains name" true (let ua = String.lowercase_ascii Version.user_agent in let name = String.lowercase_ascii Version.name in try let rec find i = if i + String.length name > String.length ua then raise Not_found else if String.sub ua i (String.length name) = name then true else find (i + 1) in find 0 with Not_found -> false) let test_user_agent_contains_version () = Alcotest.(check bool) "user_agent contains version" true (let ua = Version.user_agent in let ver = Version.v in try let rec find i = if i + String.length ver > String.length ua then raise Not_found else if String.sub ua i (String.length ver) = ver then true else find (i + 1) in find 0 with Not_found -> false) let test_user_agent_non_empty () = Alcotest.(check bool) "user_agent is non-empty" true (String.length Version.user_agent > 0) (** {1 Test Suite} *) let suite = ( "version", [ Alcotest.test_case "non-empty version" `Quick test_version_non_empty; Alcotest.test_case "name is ocaml-requests" `Quick test_name; Alcotest.test_case "contains name" `Quick test_user_agent_contains_name; Alcotest.test_case "contains version" `Quick test_user_agent_contains_version; Alcotest.test_case "non-empty" `Quick test_user_agent_non_empty; ] )