Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docstrings compiler tests #7184

Draft
wants to merge 28 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"tests/tests/**",
"tests/tools_tests/**",
"tests/analysis_tests/**",
"tests/docstrings_examples/**",
"analysis/examples/**",
"analysis/reanalyze/examples/**",
"lib/**",
Expand Down
1 change: 1 addition & 0 deletions runtime/Belt_Array.resi
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ arr == [0, 1, 9, 9, 4]
Belt.Array.fill(arr, ~offset=7, ~len=2, 8)

arr == [0, 1, 9, 9, 4]
```
*/
let fill: (t<'a>, ~offset: int, ~len: int, 'a) => unit

Expand Down
5 changes: 3 additions & 2 deletions runtime/Exn.resi
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ a value passed to a Promise.catch callback)
## Examples

```rescript
switch (Js.Exn.unsafeAnyToExn("test")) {
switch (Js.Exn.anyToExnInternal("test")) {
| Js.Exn.Error(v) =>
switch(Js.Exn.message(v)) {
| Some(str) => Js.log("We won't end up here")
| Some(_) => Js.log("We won't end up here")
| None => Js.log2("We will land here: ", v)
}
| _ => assert(false)
}
```
*/
Expand Down
6 changes: 6 additions & 0 deletions runtime/Js_dict.resi
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type key = string
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.get(ages, "Vinh") == Some(22)
Js.Dict.get(ages, "Paul") == None
```
Expand All @@ -66,6 +67,7 @@ let get: (t<'a>, key) => option<'a>
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.unsafeGet(ages, "Fred") == 49
Js.Dict.unsafeGet(ages, "Paul") // returns undefined
```
Expand All @@ -82,6 +84,7 @@ the key does not exist, and entry will be created for it.
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.set(ages, "Maria", 31)
Js.log(ages == Js.Dict.fromList(list{("Maria", 31), ("Vinh", 22), ("Fred", 49)}))

Expand All @@ -98,6 +101,7 @@ Returns all the keys in the dictionary `dict`.
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.keys(ages) == ["Maria", "Vinh", "Fred"]
```
*/
Expand All @@ -115,6 +119,7 @@ Returns an array of key/value pairs in the given dictionary (ES2017).
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.entries(ages) == [("Maria", 30), ("Vinh", 22), ("Fred", 49)]
```
*/
Expand All @@ -126,6 +131,7 @@ Returns the values in the given dictionary (ES2017).
## Examples

```rescript
let ages = dict{"Maria": 30, "Vinh": 22, "Fred": 49}
Js.Dict.values(ages) == [30, 22, 49]
```
*/
Expand Down
6 changes: 3 additions & 3 deletions runtime/Js_types.resi
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ This is useful for doing runtime reflection on any given value.
## Examples

```rescript
test("test", String) == true
test(() => true, Function) == true
test("test", Boolean) == false
Js.Types.test("test", String) == true
Js.Types.test(() => true, Function) == true
Js.Types.test("test", Boolean) == false
```
*/
let test: ('a, t<'b>) => bool
Expand Down
18 changes: 18 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let ounitTest = false;
let mochaTest = false;
let bsbTest = false;
let formatTest = false;
let runtimeDocstrings = false;

if (process.argv.includes("-ounit")) {
ounitTest = true;
Expand All @@ -29,11 +30,16 @@ if (process.argv.includes("-format")) {
formatTest = true;
}

if (process.argv.includes("-docstrings")) {
runtimeDocstrings = true;
}

if (process.argv.includes("-all")) {
ounitTest = true;
mochaTest = true;
bsbTest = true;
formatTest = true;
runtimeDocstrings = true;
}

async function runTests() {
Expand Down Expand Up @@ -120,6 +126,18 @@ async function runTests() {
process.exit(1);
}
}

if (runtimeDocstrings) {
console.log("Running runtime docstrings tests");
cp.execSync(`${rescript_exe} build`, {
cwd: path.join(__dirname, "..", "tests/docstrings_examples"),
stdio: [0, 1, 2],
});
cp.execSync("node tests/docstrings_examples/DocTest.res.mjs", {
cwd: path.join(__dirname, ".."),
stdio: [0, 1, 2],
});
}
}

runTests();
3 changes: 2 additions & 1 deletion tests/analysis_tests/tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/analysis_tests/tests/src/expected/Completion.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ Path Js.Dict.u
"kind": 12,
"tags": [],
"detail": "(t<'a>, key) => 'a",
"documentation": {"kind": "markdown", "value": "\n`Js.Dict.unsafeGet(key)` returns the value if the key exists, otherwise an `undefined` value is returned. Use this only when you are sure the key exists (i.e. when having used the `keys()` function to check that the key is valid).\n\n## Examples\n\n```rescript\nJs.Dict.unsafeGet(ages, \"Fred\") == 49\nJs.Dict.unsafeGet(ages, \"Paul\") // returns undefined\n```\n"}
"documentation": {"kind": "markdown", "value": "\n`Js.Dict.unsafeGet(key)` returns the value if the key exists, otherwise an `undefined` value is returned. Use this only when you are sure the key exists (i.e. when having used the `keys()` function to check that the key is valid).\n\n## Examples\n\n```rescript\nlet ages = dict{\"Maria\": 30, \"Vinh\": 22, \"Fred\": 49}\nJs.Dict.unsafeGet(ages, \"Fred\") == 49\nJs.Dict.unsafeGet(ages, \"Paul\") // returns undefined\n```\n"}
}, {
"label": "unsafeDeleteKey",
"kind": 12,
Expand Down
Loading
Loading