forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoUnitUtils.ml
121 lines (101 loc) · 2.46 KB
/
oUnitUtils.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
(**
* Utilities for OUnit
*
* @author Sylvain Le Gall
*)
open OUnitTypes
let is_success =
function
| RSuccess _ -> true
| RFailure _ | RError _ | RSkip _ | RTodo _ -> false
let is_failure =
function
| RFailure _ -> true
| RSuccess _ | RError _ | RSkip _ | RTodo _ -> false
let is_error =
function
| RError _ -> true
| RSuccess _ | RFailure _ | RSkip _ | RTodo _ -> false
let is_skip =
function
| RSkip _ -> true
| RSuccess _ | RFailure _ | RError _ | RTodo _ -> false
let is_todo =
function
| RTodo _ -> true
| RSuccess _ | RFailure _ | RError _ | RSkip _ -> false
let result_flavour =
function
| RError _ -> "Error"
| RFailure _ -> "Failure"
| RSuccess _ -> "Success"
| RSkip _ -> "Skip"
| RTodo _ -> "Todo"
let result_path =
function
| RSuccess path
| RError (path, _)
| RFailure (path, _)
| RSkip (path, _)
| RTodo (path, _) -> path
let result_msg =
function
| RSuccess _ -> "Success"
| RError (_, msg)
| RFailure (_, msg)
| RSkip (_, msg)
| RTodo (_, msg) -> msg
(* Returns true if the result list contains successes only. *)
let rec was_successful =
function
| [] -> true
| RSuccess _::t
| RSkip _::t ->
was_successful t
| RFailure _::_
| RError _::_
| RTodo _::_ ->
false
let string_of_node =
function
| ListItem n ->
string_of_int n
| Label s ->
s
(* Return the number of available tests *)
let rec test_case_count =
function
| TestCase _ -> 1
| TestLabel (_, t) -> test_case_count t
| TestList l ->
List.fold_left
(fun c t -> c + test_case_count t)
0 l
let string_of_path path =
String.concat ":" (List.rev_map string_of_node path)
let buff_format_printf f =
let buff = Buffer.create 13 in
let fmt = Format.formatter_of_buffer buff in
f fmt;
Format.pp_print_flush fmt ();
Buffer.contents buff
(* Applies function f in turn to each element in list. Function f takes
one element, and integer indicating its location in the list *)
let mapi f l =
let rec rmapi cnt l =
match l with
| [] ->
[]
| h :: t ->
(f h cnt) :: (rmapi (cnt + 1) t)
in
rmapi 0 l
let fold_lefti f accu l =
let rec rfold_lefti cnt accup l =
match l with
| [] ->
accup
| h::t ->
rfold_lefti (cnt + 1) (f accup h cnt) t
in
rfold_lefti 0 accu l