package alcotest

  1. Overview
  2. Docs
Alcotest is a lightweight and colourful test framework

Install

Dune Dependency

Authors

Maintainers

Sources

alcotest-1.8.0.tbz
sha256=cba1bd01707c8c55b4764bb0df8c9c732be321e1f1c1a96a406e56d8dbca1d0e
sha512=eebb034c990abd253f526e848a99881686d7bd3c7d1b1d373953d568d062e3d5aaa79b6b4807455aaa9a98710eca4ada30e816a0134717a380619a597575564d

doc/src/alcotest.engine/safe_string.ml.html

Source file safe_string.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
open! Import

let escape str =
  let add_codepoint buf uchar =
    Uchar.to_int uchar |> Fmt.str "U+%04X" |> Buffer.add_string buf
  in
  let buf = Buffer.create (String.length str * 2) in
  let get_normalized_char _ _ u =
    match u with
    | `Uchar u ->
        if Uchar.is_char u then
          match Uchar.to_char u with
          | ('A' .. 'Z' | 'a' .. 'z' | '0' .. '9' | '_' | '-' | ' ' | '.') as c
            ->
              Buffer.add_char buf c
          | '/' | '\\' -> Buffer.add_char buf '-'
          | _ -> add_codepoint buf u
        else add_codepoint buf u
    | `Malformed _ -> Uutf.Buffer.add_utf_8 buf Uutf.u_rep
  in
  Uutf.String.fold_utf_8 get_normalized_char () str;
  Buffer.contents buf

type t = { raw : string; escaped : string }

let v raw = { raw; escaped = escape raw }
let to_string { escaped; _ } = escaped
let to_unescaped_string { raw; _ } = raw
let pp = Fmt.using (fun { raw; _ } -> raw) Fmt.string
let length { raw; _ } = String.length_utf8 raw
let equal t t' = String.equal t.escaped t'.escaped
let compare t t' = String.compare t.escaped t'.escaped
OCaml

Innovation. Community. Security.