package alcotest

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

Install

Dune Dependency

Authors

Maintainers

Sources

alcotest-1.9.0.tbz
sha256=e2387136ca854df2b4152139dd4d4b3953a646e804948073dedfe0a232f08a15
sha512=ba38fe4a9061b001d274e5d41fb06c10c84120570fc00dc57dc5a06ba05176c2413295680d839f465ba91469ea99d7e172a324e26f005d6e8c4d98fca7657241

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.