forked from rescript-lang/rescript-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResultTests.mjs
96 lines (87 loc) · 1.87 KB
/
ResultTests.mjs
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
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Test from "./Test.mjs";
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
import * as Core__Result from "../src/Core__Result.mjs";
var eq = Caml_obj.equal;
function forEachIfOkCallFunction(param) {
var called = {
contents: []
};
Core__Result.forEach({
TAG: /* Ok */0,
_0: 3
}, (function (i) {
called.contents.push(i);
}));
Test.run([
[
"ResultTests.res",
12,
22,
72
],
"forEach: if ok, call function with ok value once"
], called.contents, eq, [3]);
}
forEachIfOkCallFunction(undefined);
function forEachIfErrorDoNotCallFunction(param) {
var called = {
contents: []
};
Core__Result.forEach({
TAG: /* Error */1,
_0: 3
}, (function (i) {
called.contents.push(i);
}));
Test.run([
[
"ResultTests.res",
19,
22,
63
],
"forEach: if error, do not call function"
], called.contents, eq, []);
}
forEachIfErrorDoNotCallFunction(undefined);
Test.run([
[
"ResultTests.res",
27,
20,
48
],
"mapError: if ok, return it"
], Core__Result.mapError({
TAG: /* Ok */0,
_0: 5
}, (function (i) {
return Math.imul(i, 3);
})), eq, {
TAG: /* Ok */0,
_0: 5
});
Test.run([
[
"ResultTests.res",
30,
13,
42
],
"mapError: if error, apply f"
], Core__Result.mapError({
TAG: /* Error */1,
_0: 5
}, (function (i) {
return Math.imul(i, 3);
})), eq, {
TAG: /* Error */1,
_0: 15
});
export {
eq ,
forEachIfOkCallFunction ,
forEachIfErrorDoNotCallFunction ,
}
/* Not a pure module */