package ppx_expect

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file file.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
open Base

module Name : sig
  type t [@@deriving sexp, compare]

  val relative_to : dir:string -> t -> string

  include Identifiable.S with type t := t
end = struct
  include String

  let relative_to ~dir t =
    if not (Caml.Filename.is_relative t) then t else Caml.Filename.concat dir t
  ;;
end

let initial_dir =
  let dir_or_error =
    match Caml.Sys.getcwd () with
    | v -> `Ok v
    | exception exn -> `Exn exn
  in
  fun () ->
    match dir_or_error with
    | `Ok v -> v
    | `Exn exn -> raise exn
;;

module Location = struct
  module T = struct
    type t =
      { filename : Name.t
      ; line_number : int
      ; line_start : int
      ; start_pos : int
      ; end_pos : int
      }
    [@@deriving sexp, compare]

    let compare a b =
      if not ([%compare.equal: Name.t] a.filename b.filename)
      then invalid_arg "Expect_test_collector.File.Location.compare"
      else compare a b
    ;;
  end

  include T
  include Comparable.Make (T)

  let beginning_of_file filename =
    { filename; line_number = 1; line_start = 0; start_pos = 0; end_pos = 0 }
  ;;
end

module Digest : sig
  type t [@@deriving sexp_of, compare]

  val to_string : t -> string
  val of_string : string -> t
end = struct
  type t = string [@@deriving sexp_of, compare]

  let to_string t = t

  let of_string s =
    let expected_length = 32 in
    if String.length s <> expected_length
    then invalid_arg "Expect_test_collector.File.Digest.of_string, unexpected length";
    for i = 0 to expected_length - 1 do
      match s.[i] with
      | '0' .. '9' | 'a' .. 'f' -> ()
      | _ -> invalid_arg "Expect_test_collector.File.Digest.of_string"
    done;
    s
  ;;
end
OCaml

Innovation. Community. Security.