Source file CodeptUnitSansCodeId.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
(** A [CodeptUnitSansCodeId] uniquely identifies a {!Unit.t}
    while ignoring the {!Unit.code} field. *)

type unit_precision = Unit.precision = Exact | Approx

let compare_unit_precision t1 t2 =
  match (t1, t2) with
  | Exact, Approx -> -1
  | Exact, Exact -> 0
  | Approx, Approx -> 0
  | Approx, Exact -> 1

type m2l_kind = M2l.kind = Structure | Signature

let compare_m2l_kind t1 t2 =
  match (t1, t2) with
  | Structure, Signature -> -1
  | Structure, Structure -> 0
  | Signature, Signature -> 0
  | Signature, Structure -> 1

type t = {
  path : Namespaced.t;
  src : Pkg.t;
  kind : m2l_kind;
  precision : unit_precision;
}

let compare { path = a1; src = b1; kind = c1; precision = d1 }
    { path = a2; src = b2; kind = c2; precision = d2 } =
  match Namespaced.compare a1 a2 with
  | 0 -> (
      match DerivPkg.compare b1 b2 with
      | 0 -> (
          match compare_m2l_kind c1 c2 with
          | 0 -> compare_unit_precision d1 d2
          | c -> c)
      | c -> c)
  | c -> c

let of_unit (unit : _ Unit.t) =
  {
    path = unit.path;
    src = unit.src;
    kind = unit.kind;
    precision = unit.precision;
  }