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

ocaml / odoc / 2072

10 Jun 2024 10:09AM UTC coverage: 71.986% (+0.2%) from 71.774%
2072

Pull #1145

github

web-flow
Merge 1b7b0910b into 1ced6f23f
Pull Request #1145: "Global" Sidebar

195 of 220 new or added lines in 12 files covered. (88.64%)

630 existing lines in 13 files now uncovered.

9834 of 13661 relevant lines covered (71.99%)

3561.61 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 *)
4
let fold_option ~none ~some = function Some x -> some x | None -> none
×
5

6
let rec list_concat_map ?sep ~f = function
7
  | [] -> []
64✔
8
  | [ x ] -> f x
80,620✔
9
  | x :: xs -> (
66,071✔
10
      let hd = f x in
11
      let tl = list_concat_map ?sep ~f xs in
66,071✔
12
      match sep with None -> hd @ tl | Some sep -> hd @ (sep :: tl))
620✔
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"
11✔
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
1,307✔
30
    | `Array els -> (
178✔
31
        match els with
32
        | [] -> Buffer.add_string b "[]"
18✔
33
        | el :: els ->
160✔
34
            let add_sep_el b e =
35
              Buffer.add_char b ',';
130✔
36
              buffer_add_json b e
130✔
37
            in
38
            Buffer.add_char b '[';
39
            buffer_add_json b el;
160✔
40
            List.iter (add_sep_el b) els;
160✔
41
            Buffer.add_char b ']')
160✔
42
    | `Object mems -> (
723✔
43
        match mems with
UNCOV
44
        | [] -> Buffer.add_string b "{}"
×
45
        | mem :: mems ->
723✔
46
            let add_mem b (k, v) =
47
              buffer_add_json_string b k;
1,793✔
48
              Buffer.add_char b ':';
1,793✔
49
              buffer_add_json b v
1,793✔
50
            in
51
            let add_sep_mem b mem =
52
              Buffer.add_char b ',';
1,070✔
53
              add_mem b mem
1,070✔
54
            in
55
            Buffer.add_char b '{';
56
            add_mem b mem;
723✔
57
            List.iter (add_sep_mem b) mems;
723✔
58
            Buffer.add_char b '}')
723✔
59

60
  and buffer_add_json_string b s =
61
    let is_control = function
3,100✔
UNCOV
62
      | '\x00' .. '\x1F' | '\x7F' -> true
×
63
      | _ -> false
47,062✔
64
    in
65
    let len = String.length s in
66
    let max_idx = len - 1 in
3,100✔
67
    let flush b start i =
68
      if start < len then Buffer.add_substring b s start (i - start)
4,710✔
69
    in
70
    let rec loop start i =
71
      match i > max_idx with
51,827✔
72
      | true -> flush b start i
3,100✔
73
      | false -> (
48,727✔
74
          let next = i + 1 in
75
          match String.get s i with
76
          | '"' ->
1,646✔
77
              flush b start i;
78
              Buffer.add_string b "\\\"";
1,646✔
79
              loop next next
1,646✔
UNCOV
80
          | '\\' ->
×
81
              flush b start i;
UNCOV
82
              Buffer.add_string b "\\\\";
×
UNCOV
83
              loop next next
×
84
          | c when is_control c ->
47,081✔
85
              flush b start i;
19✔
86
              Buffer.add_string b (Printf.sprintf "\\u%04X" (Char.code c));
19✔
87
              loop next next
19✔
88
          | _c -> loop start next)
47,062✔
89
    in
90
    Buffer.add_char b '"';
91
    loop 0 0;
3,100✔
92
    Buffer.add_char b '"'
3,100✔
93

94
  let to_string json =
95
    let b = Buffer.create 1024 in
153✔
96
    buffer_add_json b json;
153✔
97
    Buffer.contents b
153✔
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