• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ocaml / odoc / 2168

10 Jul 2024 02:38PM UTC coverage: 71.437% (-0.4%) from 71.864%
2168

Pull #1142

github

web-flow
Merge 9bc2c3b35 into de54ed266
Pull Request #1142: Parsing of path-references to pages and modules

68 of 127 new or added lines in 6 files covered. (53.54%)

700 existing lines in 17 files now uncovered.

9794 of 13710 relevant lines covered (71.44%)

3534.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.19
/src/html/utils.ml
1
(* Shared utility functions *)
2

3
(* = Option.fold *)
UNCOV
4
let fold_option ~none ~some = function Some x -> some x | None -> none
×
5

6
let rec list_concat_map ?sep ~f = function
7
  | [] -> []
44✔
8
  | [ x ] -> f x
80,711✔
9
  | x :: xs -> (
66,109✔
10
      let hd = f x in
11
      let tl = list_concat_map ?sep ~f xs in
66,109✔
12
      match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))
615✔
13

14
let optional_elt f ?a = function [] -> [] | l -> [ f ?a l ]
107✔
15

16
module Json = struct
17
  type json =
18
    [ `Null
19
    | `Bool of bool
20
    | `Float of float
21
    | `String of string
22
    | `Array of json list
23
    | `Object of (string * json) list ]
24

25
  let rec buffer_add_json b = function
26
    | `Null -> Buffer.add_string b "null"
7✔
UNCOV
27
    | `Bool bool -> Buffer.add_string b (if bool then "true" else "false")
×
UNCOV
28
    | `Float f -> Buffer.add_string b (Printf.sprintf "%.16g" f)
×
29
    | `String s -> buffer_add_json_string b s
626✔
30
    | `Array els -> (
89✔
31
        match els with
32
        | [] -> Buffer.add_string b "[]"
12✔
33
        | el :: els ->
77✔
34
            let add_sep_el b e =
35
              Buffer.add_char b ',';
62✔
36
              buffer_add_json b e
62✔
37
            in
38
            Buffer.add_char b '[';
39
            buffer_add_json b el;
77✔
40
            List.iter (add_sep_el b) els;
77✔
41
            Buffer.add_char b ']')
77✔
42
    | `Object mems -> (
339✔
43
        match mems with
UNCOV
44
        | [] -> Buffer.add_string b "{}"
×
45
        | mem :: mems ->
339✔
46
            let add_mem b (k, v) =
47
              buffer_add_json_string b k;
859✔
48
              Buffer.add_char b ':';
859✔
49
              buffer_add_json b v
859✔
50
            in
51
            let add_sep_mem b mem =
52
              Buffer.add_char b ',';
520✔
53
              add_mem b mem
520✔
54
            in
55
            Buffer.add_char b '{';
56
            add_mem b mem;
339✔
57
            List.iter (add_sep_mem b) mems;
339✔
58
            Buffer.add_char b '}')
339✔
59

60
  and buffer_add_json_string b s =
61
    let is_control = function
1,485✔
UNCOV
62
      | '\x00' .. '\x1F' | '\x7F' -> true
×
63
      | _ -> false
22,541✔
64
    in
65
    let len = String.length s in
66
    let max_idx = len - 1 in
1,485✔
67
    let flush b start i =
68
      if start < len then Buffer.add_substring b s start (i - start)
2,289✔
69
    in
70
    let rec loop start i =
71
      match i > max_idx with
24,865✔
72
      | true -> flush b start i
1,485✔
73
      | false -> (
23,380✔
74
          let next = i + 1 in
75
          match String.get s i with
76
          | '"' ->
822✔
77
              flush b start i;
78
              Buffer.add_string b "\\\"";
822✔
79
              loop next next
822✔
UNCOV
80
          | '\\' ->
×
81
              flush b start i;
UNCOV
82
              Buffer.add_string b "\\\\";
×
UNCOV
83
              loop next next
×
84
          | c when is_control c ->
22,558✔
85
              flush b start i;
17✔
86
              Buffer.add_string b (Printf.sprintf "\\u%04X" (Char.code c));
17✔
87
              loop next next
17✔
88
          | _c -> loop start next)
22,541✔
89
    in
90
    Buffer.add_char b '"';
91
    loop 0 0;
1,485✔
92
    Buffer.add_char b '"'
1,485✔
93

94
  let to_string json =
95
    let b = Buffer.create 1024 in
74✔
96
    buffer_add_json b json;
74✔
97
    Buffer.contents b
74✔
98
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc