Skip to content

Commit 02f60b8

Browse files
committed
add docstrings tests
1 parent 6424d66 commit 02f60b8

File tree

8 files changed

+748
-5
lines changed

8 files changed

+748
-5
lines changed

runtime/Belt_Array.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ arr == [0, 1, 9, 9, 4]
362362
Belt.Array.fill(arr, ~offset=7, ~len=2, 8)
363363
364364
arr == [0, 1, 9, 9, 4]
365+
```
365366
*/
366367
let fill: (t<'a>, ~offset: int, ~len: int, 'a) => unit
367368

runtime/Exn.resi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ a value passed to a Promise.catch callback)
5252
## Examples
5353
5454
```rescript
55-
switch (Js.Exn.unsafeAnyToExn("test")) {
55+
switch (Js.Exn.anyToExnInternal("test")) {
5656
| Js.Exn.Error(v) =>
5757
switch(Js.Exn.message(v)) {
58-
| Some(str) => Js.log("We won't end up here")
58+
| Some(_) => Js.log("We won't end up here")
5959
| None => Js.log2("We will land here: ", v)
6060
}
61+
| _ => assert(false)
6162
}
6263
```
6364
*/

runtime/Js_dict.resi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type key = string
5353
## Examples
5454
5555
```rescript
56+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
5657
Js.Dict.get(ages, "Vinh") == Some(22)
5758
Js.Dict.get(ages, "Paul") == None
5859
```
@@ -66,6 +67,7 @@ let get: (t<'a>, key) => option<'a>
6667
## Examples
6768
6869
```rescript
70+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
6971
Js.Dict.unsafeGet(ages, "Fred") == 49
7072
Js.Dict.unsafeGet(ages, "Paul") // returns undefined
7173
```
@@ -82,6 +84,7 @@ the key does not exist, and entry will be created for it.
8284
## Examples
8385
8486
```rescript
87+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
8588
Js.Dict.set(ages, "Maria", 31)
8689
Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49)}))
8790
@@ -98,6 +101,7 @@ Returns all the keys in the dictionary `dict`.
98101
## Examples
99102
100103
```rescript
104+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
101105
Js.Dict.keys(ages) == ["Maria", "Vinh", "Fred"]
102106
```
103107
*/
@@ -115,6 +119,7 @@ Returns an array of key/value pairs in the given dictionary (ES2017).
115119
## Examples
116120
117121
```rescript
122+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
118123
Js.Dict.entries(ages) == [("Maria", 30), ("Vinh", 22), ("Fred", 49)]
119124
```
120125
*/
@@ -126,6 +131,7 @@ Returns the values in the given dictionary (ES2017).
126131
## Examples
127132
128133
```rescript
134+
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
129135
Js.Dict.values(ages) == [30, 22, 49]
130136
```
131137
*/

runtime/Js_types.resi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ This is useful for doing runtime reflection on any given value.
5555
## Examples
5656
5757
```rescript
58-
test("test", String) == true
59-
test(() => true, Function) == true
60-
test("test", Boolean) == false
58+
Js.Types.test("test", String) == true
59+
Js.Types.test(() => true, Function) == true
60+
Js.Types.test("test", Boolean) == false
6161
```
6262
*/
6363
let test: ('a, t<'b>) => bool

scripts/test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let ounitTest = false;
1212
let mochaTest = false;
1313
let bsbTest = false;
1414
let formatTest = false;
15+
let runtimeDocstrings = false;
1516

1617
if (process.argv.includes("-ounit")) {
1718
ounitTest = true;
@@ -29,11 +30,16 @@ if (process.argv.includes("-format")) {
2930
formatTest = true;
3031
}
3132

33+
if (process.argv.includes("-docstrings")) {
34+
runtimeDocstrings = true;
35+
}
36+
3237
if (process.argv.includes("-all")) {
3338
ounitTest = true;
3439
mochaTest = true;
3540
bsbTest = true;
3641
formatTest = true;
42+
runtimeDocstrings = true;
3743
}
3844

3945
async function runTests() {
@@ -120,6 +126,18 @@ async function runTests() {
120126
process.exit(1);
121127
}
122128
}
129+
130+
if (runtimeDocstrings) {
131+
console.log("Running runtime docstrings tests");
132+
cp.execSync(`${rescript_exe} build`, {
133+
cwd: path.join(__dirname, "..", "tests/docstrings_examples"),
134+
stdio: [0, 1, 2],
135+
});
136+
cp.execSync("node tests/docstrings_examples/DocTest.res.mjs", {
137+
cwd: path.join(__dirname, ".."),
138+
stdio: [0, 1, 2],
139+
});
140+
}
123141
}
124142

125143
runTests();

0 commit comments

Comments
 (0)