From afb87661b546f990adbb90aa03d1a8fd14b9c479 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 4 Jul 2024 04:12:47 +0900 Subject: [PATCH 01/37] cleanup TypeScript config --- .gitignore | 2 ++ jsconfig.json | 14 -------- package.json | 7 ++-- .../typescript-react-example/Makefile | 2 +- .../typescript-react-example/package.json | 4 +-- .../typescript-react-example/tsconfig.json | 2 -- .../tsconfig.prod.json | 3 -- .../tsconfig.test.json | 6 ---- tsconfig.json | 22 ++++++++++++ yarn.lock | 36 ++++++++++++++----- 10 files changed, 59 insertions(+), 39 deletions(-) delete mode 100644 jsconfig.json delete mode 100644 tests/gentype_tests/typescript-react-example/tsconfig.prod.json delete mode 100644 tests/gentype_tests/typescript-react-example/tsconfig.test.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index e50efa90c8..c88c6d8ba9 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,5 @@ tests/analysis_tests/**/*.bs.js !.yarn/releases !.yarn/sdks !.yarn/versions + +*.tsbuildinfo diff --git a/jsconfig.json b/jsconfig.json deleted file mode 100644 index 5ac7dffc06..0000000000 --- a/jsconfig.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "compilerOptions": { - "alwaysStrict": true, - "noImplicitAny": true, - // , "strictNullChecks": true - "target": "es2018", - // target need be set up - // otherwise some method is missing - "module": "nodenext", - // setup to understand commonjs module - - "moduleResolution": "nodenext" - } -} diff --git a/package.json b/package.json index 6ae357785a..0c35e07a49 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "format:all": "biome format --write .", "checkFormat": "biome format --changed --no-errors-on-unmatched .", "checkFormat:all": "biome format .", - "coverage": "nyc --timeout=3000 --reporter=html mocha tests/tests/src/*_test.js && open ./coverage/index.html" + "coverage": "nyc --timeout=3000 --reporter=html mocha tests/tests/src/*_test.js && open ./coverage/index.html", + "typecheck": "tsc" }, "files": [ "CHANGELOG.md", @@ -76,8 +77,10 @@ }, "devDependencies": { "@biomejs/biome": "1.8.3", + "@types/node": "^20.14.9", "mocha": "10.8.2", - "nyc": "15.0.0" + "nyc": "15.0.0", + "typescript": "5.5.3" }, "workspaces": [ "tests/dependencies/**", diff --git a/tests/gentype_tests/typescript-react-example/Makefile b/tests/gentype_tests/typescript-react-example/Makefile index 7a821b93a4..9bdd0e5013 100644 --- a/tests/gentype_tests/typescript-react-example/Makefile +++ b/tests/gentype_tests/typescript-react-example/Makefile @@ -3,7 +3,7 @@ SHELL = /bin/bash test: npm run lint npm run build - npm run tsc + npm run typecheck @git diff --quiet src/ \ || { echo; echo "Please review the Gentype outputs too!"; echo; false; } \ || exit 1 diff --git a/tests/gentype_tests/typescript-react-example/package.json b/tests/gentype_tests/typescript-react-example/package.json index 861e6c2c13..aab9789432 100644 --- a/tests/gentype_tests/typescript-react-example/package.json +++ b/tests/gentype_tests/typescript-react-example/package.json @@ -5,7 +5,7 @@ "start": "rescript build -w", "build": "rescript", "clean": "rescript clean", - "tsc": "tsc -p tsconfig.json", + "typecheck": "tsc", "lint": "biome check src" }, "dependencies": { @@ -19,6 +19,6 @@ "@types/node": "^18.15.12", "@types/react": "^18.3.19", "@types/react-dom": "^18.3.5", - "typescript": "^5.2.2" + "typescript": "5.5.3" } } diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.json b/tests/gentype_tests/typescript-react-example/tsconfig.json index ab864d616d..d78ab7798e 100644 --- a/tests/gentype_tests/typescript-react-example/tsconfig.json +++ b/tests/gentype_tests/typescript-react-example/tsconfig.json @@ -7,8 +7,6 @@ "strict": true, "skipLibCheck": true, "allowJs": true, - "jsx": "react-jsx", - "noEmit": true }, "include": ["src"] } diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.prod.json b/tests/gentype_tests/typescript-react-example/tsconfig.prod.json deleted file mode 100644 index fc8520e737..0000000000 --- a/tests/gentype_tests/typescript-react-example/tsconfig.prod.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "./tsconfig.json" -} diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.test.json b/tests/gentype_tests/typescript-react-example/tsconfig.test.json deleted file mode 100644 index 2c7b284162..0000000000 --- a/tests/gentype_tests/typescript-react-example/tsconfig.test.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "module": "commonjs" - } -} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..f83400749c --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "allowJs": true, + "resolveJsonModule": true, + "strict": true, + "strictNullChecks": true, + "noImplicitAny": true, + "noEmit": true, + "skipLibCheck": true, + "composite": true, + "incremental": true + }, + "include": ["./cli/*", "./scripts/*", "./package.json"], + "exclude": [ + "node_modules", + "./jscomp/test/**/*", + "./jscomp/gentype_tests/**/*" + ] +} diff --git a/yarn.lock b/yarn.lock index cdfccb6b60..25f255ed27 100644 --- a/yarn.lock +++ b/yarn.lock @@ -451,7 +451,7 @@ __metadata: react: "npm:^18.3.1" react-dom: "npm:^18.3.1" rescript: "workspace:^" - typescript: "npm:^5.2.2" + typescript: "npm:5.5.3" languageName: unknown linkType: soft @@ -498,6 +498,15 @@ __metadata: languageName: node linkType: hard +"@types/node@npm:^20.14.9": + version: 20.17.27 + resolution: "@types/node@npm:20.17.27" + dependencies: + undici-types: "npm:~6.19.2" + checksum: 10c0/09f30c65e5f2a082eddf26a7ffa859bf2b77e1123829309823e7691227fd5a691b30cd3ac413d65829aa25c1eebd2f717bed80f2f8a7f83aaa6c2c3a047b3504 + languageName: node + linkType: hard + "@types/prop-types@npm:*": version: 15.7.14 resolution: "@types/prop-types@npm:15.7.14" @@ -2122,8 +2131,10 @@ __metadata: resolution: "rescript@workspace:." dependencies: "@biomejs/biome": "npm:1.8.3" + "@types/node": "npm:^20.14.9" mocha: "npm:10.8.2" nyc: "npm:15.0.0" + typescript: "npm:5.5.3" bin: bsc: cli/bsc bstracing: lib/bstracing @@ -2450,23 +2461,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:^5.2.2": - version: 5.8.2 - resolution: "typescript@npm:5.8.2" +"typescript@npm:5.5.3": + version: 5.5.3 + resolution: "typescript@npm:5.5.3" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/5c4f6fbf1c6389b6928fe7b8fcd5dc73bb2d58cd4e3883f1d774ed5bd83b151cbac6b7ecf11723de56d4676daeba8713894b1e9af56174f2f9780ae7848ec3c6 + checksum: 10c0/f52c71ccbc7080b034b9d3b72051d563601a4815bf3e39ded188e6ce60813f75dbedf11ad15dd4d32a12996a9ed8c7155b46c93a9b9c9bad1049766fe614bbdd languageName: node linkType: hard -"typescript@patch:typescript@npm%3A^5.2.2#optional!builtin": - version: 5.8.2 - resolution: "typescript@patch:typescript@npm%3A5.8.2#optional!builtin::version=5.8.2&hash=5786d5" +"typescript@patch:typescript@npm%3A5.5.3#optional!builtin": + version: 5.5.3 + resolution: "typescript@patch:typescript@npm%3A5.5.3#optional!builtin::version=5.5.3&hash=379a07" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/5448a08e595cc558ab321e49d4cac64fb43d1fa106584f6ff9a8d8e592111b373a995a1d5c7f3046211c8a37201eb6d0f1566f15cdb7a62a5e3be01d087848e2 + checksum: 10c0/911c7811d61f57f07df79c4a35f56a0f426a65426a020e5fcd792f66559f399017205f5f10255329ab5a3d8c2d1f1d19530aeceffda70758a521fae1d469432e languageName: node linkType: hard @@ -2477,6 +2488,13 @@ __metadata: languageName: node linkType: hard +"undici-types@npm:~6.19.2": + version: 6.19.8 + resolution: "undici-types@npm:6.19.8" + checksum: 10c0/078afa5990fba110f6824823ace86073b4638f1d5112ee26e790155f481f2a868cc3e0615505b6f4282bdf74a3d8caad715fd809e870c2bb0704e3ea6082f344 + languageName: node + linkType: hard + "unique-filename@npm:^4.0.0": version: 4.0.0 resolution: "unique-filename@npm:4.0.0" From 6e2feea9c08428680407ff187f0b4ee91a89400e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 22 Jul 2024 02:48:31 +0900 Subject: [PATCH 02/37] enable lint for js --- .github/workflows/get_artifact_dir_name.js | 4 +- .github/workflows/prepare_package_upload.js | 4 +- analysis/examples/example-project/types.json | 4 +- .../examples/larger-project/.watchmanconfig | 0 biome.json | 47 +++--- cli/bin_path.js | 42 ++--- cli/bsc | 9 +- cli/rescript | 19 +-- cli/rescript-tools | 13 +- cli/rescript_arg.js | 69 ++++---- cli/rescript_bsb.js | 137 ++++++++-------- cli/rescript_dump.js | 20 +-- cli/rescript_format.js | 72 +++++---- cli/rewatch | 13 +- lib/bstracing | 52 +++---- lib/minisocket.js | 147 +++++++++--------- lib_dev/meta.js | 7 + lib_dev/paths.js | 104 +++++++++++++ package.json | 8 +- .../playground-bundling/rollup.config.cjs | 2 +- .../scripts/generate_cmijs.js | 50 +++--- packages/playground-bundling/tsconfig.json | 8 + playground/playground_test.js | 28 ++-- scripts/buildNinjaBinary.js | 10 +- scripts/copyExes.js | 36 +++-- scripts/dune.js | 12 -- scripts/prebuilt.js | 57 +++---- scripts/setVersion.js | 10 +- scripts/test.js | 58 +++---- .../tests-reanalyze/deadcode/.watchmanconfig | 0 .../termination/.watchmanconfig | 0 .../build_tests/build_warn_as_error/input.js | 24 +-- tests/build_tests/case/input.js | 16 +- tests/build_tests/case2/input.js | 16 +- tests/build_tests/case3/input.js | 12 +- tests/build_tests/cli_compile_status/input.js | 13 +- tests/build_tests/cli_help/input.js | 42 +++-- tests/build_tests/custom_namespace/input.js | 8 +- tests/build_tests/cycle/input.js | 16 +- tests/build_tests/cycle1/input.js | 14 +- .../deprecated-package-specs/input.js | 4 +- tests/build_tests/devonly/input.js | 4 +- .../duplicated_symlinked_packages/input.js | 14 +- tests/build_tests/exports/input.js | 4 +- tests/build_tests/gpr_978/rescript.json | 6 +- tests/build_tests/hyphen2/input.js | 4 +- tests/build_tests/in_source/input.js | 15 +- tests/build_tests/install/input.js | 20 +-- .../jsx_settings_inheritance/input.js | 4 +- .../jsx_settings_inheritance/rescript.json | 8 +- tests/build_tests/nested/input.js | 12 +- tests/build_tests/nnest/input.js | 12 +- tests/build_tests/ns/input.js | 4 +- tests/build_tests/post-build/input.js | 8 +- tests/build_tests/rerror/input.js | 19 ++- tests/build_tests/scoped_ppx/input.js | 19 ++- .../node_modules/@hongbo/ppx1/test.js | 15 +- tests/build_tests/super_errors/input.js | 27 ++-- .../a/rescript.json | 8 +- .../transitive_pinned_dependency1/input.js | 13 +- .../node_modules/b/bsconfig.json | 50 +++--- .../node_modules/c/bsconfig.json | 38 ++--- .../transitive_pinned_dependency2/input.js | 8 +- .../node_modules/b/bsconfig.json | 50 +++--- .../node_modules/c/bsconfig.json | 38 ++--- .../unboxed_bool_with_const/input.js | 10 +- tests/build_tests/uncurried-always/input.js | 4 +- tests/build_tests/unicode/input.js | 19 +-- tests/build_tests/utils.js | 4 +- tests/build_tests/warn_legacy_config/input.js | 4 +- tests/build_tests/weird_deps/input.js | 10 +- tests/build_tests/weird_devdeps/input.js | 10 +- tests/build_tests/weird_names/input.js | 18 +-- .../weird_names_not_found_bug/input.js | 8 +- tests/build_tests/x-y/input.js | 4 +- tests/build_tests/xpkg/input.js | 8 +- tests/build_tests/zerocycle/input.js | 10 +- .../typescript-react-example/biome.json | 10 +- .../typescript-react-example/package.json | 2 +- .../typescript-react-example/src/index.tsx | 8 +- tests/tests/rescript.json | 2 +- tsconfig.json | 18 ++- 82 files changed, 963 insertions(+), 793 deletions(-) delete mode 100644 analysis/examples/larger-project/.watchmanconfig create mode 100644 lib_dev/meta.js create mode 100644 lib_dev/paths.js create mode 100644 packages/playground-bundling/tsconfig.json delete mode 100644 scripts/dune.js delete mode 100644 tests/analysis_tests/tests-reanalyze/deadcode/.watchmanconfig delete mode 100644 tests/analysis_tests/tests-reanalyze/termination/.watchmanconfig diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index 28e245bb5c..7d15b8e8dc 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,5 +1,5 @@ -const fs = require("fs"); -const os = require("os"); +const fs = require("node:fs"); +const os = require("node:os"); const { dirName: artifactDirName } = require("../../cli/bin_path.js"); diff --git a/.github/workflows/prepare_package_upload.js b/.github/workflows/prepare_package_upload.js index b94e20153e..bbf4ef206c 100644 --- a/.github/workflows/prepare_package_upload.js +++ b/.github/workflows/prepare_package_upload.js @@ -1,5 +1,5 @@ -const fs = require("fs"); -const os = require("os"); +const fs = require("node:fs"); +const os = require("node:os"); const packageSpec = require("rescript/package.json"); const { version } = packageSpec; diff --git a/analysis/examples/example-project/types.json b/analysis/examples/example-project/types.json index 904cdf616e..00f8bce969 100644 --- a/analysis/examples/example-project/types.json +++ b/analysis/examples/example-project/types.json @@ -8,6 +8,6 @@ } ], "custom": [ - {"module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1} + { "module": "Belt_HashMapInt", "path": [], "name": "t", "args": 1 } ] -} \ No newline at end of file +} diff --git a/analysis/examples/larger-project/.watchmanconfig b/analysis/examples/larger-project/.watchmanconfig deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/biome.json b/biome.json index 0d166ac261..64460061c1 100644 --- a/biome.json +++ b/biome.json @@ -7,10 +7,13 @@ "useIgnoreFile": true }, "linter": { - "enabled": false + "enabled": true, + "rules": { + "recommended": true + } }, "organizeImports": { - "enabled": false + "enabled": true }, "formatter": { "enabled": true, @@ -19,24 +22,7 @@ "indentWidth": 2, "lineEnding": "lf", "lineWidth": 80, - "attributePosition": "auto", - "ignore": [ - ".yarn/**", - "tests/build_tests/**", - "tests/tests/**", - "tests/tools_tests/**", - "tests/analysis_tests/**", - "tests/docstring_tests/**", - "analysis/examples/**", - "analysis/reanalyze/examples/**", - "lib/**", - "ninja/**", - "playground/**", - "**/*.bs.js", - "**/*.res.js", - "**/*.gen.ts*", - "package.json" - ] + "attributePosition": "auto" }, "javascript": { "formatter": { @@ -50,5 +36,26 @@ "quoteStyle": "double", "attributePosition": "auto" } + }, + "files": { + "include": ["tests/build_tests/**/node_modules/**"], + "ignore": [ + ".yarn/**", + "tests/analysis_tests/**/src/**", + "tests/build_tests/**/src/**", + "tests/docstring_tests/**", + "tests/tests/**/src/**", + "tests/tools_tests/**/src/**", + "analysis/examples/**/src/**", + "lib/es6/**", + "lib/js/**", + "ninja/**", + "playground/packages/**", + "*.bs.js", + "*.res.js", + "*.res.mjs", + "*.gen.ts*", + "package.json" + ] } } diff --git a/cli/bin_path.js b/cli/bin_path.js index 727e233da0..a728d1d5a0 100644 --- a/cli/bin_path.js +++ b/cli/bin_path.js @@ -1,59 +1,61 @@ -//@ts-check +// @ts-check -const path = require("path"); +const path = require("node:path"); /** - * @type{string} - * * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. * So we'll have "darwin", "linux" and "win32" for x64 arch, * but "darwinarm64" and "linuxarm64" for arm64 arch. * Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM. * So omit the architecture for Windows, too. */ -const binDirName = +const platformName = process.arch === "x64" || process.platform === "win32" ? process.platform : process.platform + process.arch; /** - * - * @type{string} + * @type {string} */ -const binAbsolutePath = path.join(__dirname, "..", binDirName); +const platformDir = path.resolve(__dirname, "..", platformName); /** - * @type{string} + * @type {string} */ -const bsc_exe = path.join(binAbsolutePath, "bsc.exe"); +const bsc_exe = path.join(platformDir, "bsc.exe"); /** - * @type{string} + * @type {string} */ -const ninja_exe = path.join(binAbsolutePath, "ninja.exe"); +const ninja_exe = path.join(platformDir, "ninja.exe"); /** - * @type{string} + * @type {string} */ -const rescript_exe = path.join(binAbsolutePath, "rescript.exe"); +const rescript_exe = path.join(platformDir, "rescript.exe"); /** - * @type{string} + * @type {string} */ -const rescript_tools_exe = path.join(binAbsolutePath, "rescript-tools.exe"); +const rescript_tools_exe = path.join(platformDir, "rescript-tools.exe"); /** - * @type{string} + * @type {string} */ const rescript_editor_analysis_exe = path.join( - binAbsolutePath, + platformDir, "rescript-editor-analysis.exe", ); -exports.dirName = binDirName; -exports.absolutePath = binAbsolutePath; +/** + * @type {string} + */ +const rewatch_exe = path.join(platformDir, "rewatch.exe"); + +exports.platformDir = platformDir; exports.bsc_exe = bsc_exe; exports.ninja_exe = ninja_exe; exports.rescript_exe = rescript_exe; exports.rescript_tools_exe = rescript_tools_exe; exports.rescript_editor_analysis_exe = rescript_editor_analysis_exe; +exports.rewatch_exe = rewatch_exe; diff --git a/cli/bsc b/cli/bsc index 6294212188..556697d2df 100755 --- a/cli/bsc +++ b/cli/bsc @@ -1,10 +1,13 @@ #!/usr/bin/env node + +// @ts-check + "use strict"; -var child_process = require("child_process"); -var { bsc_exe } = require("./bin_path"); +const child_process = require("child_process"); +const { bsc_exe } = require("./bin_path.js"); -var delegate_args = process.argv.slice(2); +const delegate_args = process.argv.slice(2); try { child_process.execFileSync(bsc_exe, delegate_args, { stdio: "inherit" }); diff --git a/cli/rescript b/cli/rescript index 831b0c1207..b434d4c6e9 100755 --- a/cli/rescript +++ b/cli/rescript @@ -1,21 +1,22 @@ #!/usr/bin/env node + //@ts-check + "use strict"; -/** - * This script is supposed to be running in project root directory - * It matters since we need read .sourcedirs(location) - * and its content are file/directories with regard to project root - */ +// This script is supposed to be running in project root directory +// It matters since we need read .sourcedirs(location) +// and its content are file/directories with regard to project root -var { bsc_exe, rescript_exe } = require("./bin_path.js"); -var bsb = require("./rescript_bsb.js"); +const tty = require("node:tty"); +const { bsc_exe, rescript_exe } = require("./bin_path.js"); +const bsb = require("./rescript_bsb.js"); -var cwd = process.cwd(); +const cwd = process.cwd(); process.env.BSB_PROJECT_ROOT = cwd; if (process.env.FORCE_COLOR === undefined) { - if (require("tty").isatty(1)) { + if (tty.isatty(1)) { process.env.FORCE_COLOR = "1"; process.env.NINJA_ANSI_FORCED = "1"; } diff --git a/cli/rescript-tools b/cli/rescript-tools index a4d5ae21ae..0451351388 100755 --- a/cli/rescript-tools +++ b/cli/rescript-tools @@ -1,13 +1,12 @@ #!/usr/bin/env node -//@ts-check -"use strict"; -const path = require("path"); -const child_process = require("child_process"); +// @ts-check + +"use strict"; -const { absolutePath: binAbsolutePath } = require("./bin_path"); -const rewatchExe = path.join(binAbsolutePath, "rescript-tools.exe"); +const child_process = require("node:child_process"); +const { rescript_tools_exe } = require("./bin_path.js"); const args = process.argv.slice(2); -child_process.spawnSync(rewatchExe, args, { stdio: "inherit" }); +child_process.spawnSync(rescript_tools_exe, args, { stdio: "inherit" }); diff --git a/cli/rescript_arg.js b/cli/rescript_arg.js index 3bfdc1283e..806ff2b612 100644 --- a/cli/rescript_arg.js +++ b/cli/rescript_arg.js @@ -1,4 +1,5 @@ -//@ts-check +// @ts-check + class StringBuilder { constructor() { this.val = ""; @@ -13,10 +14,10 @@ class StringBuilder { return this; } } -class ArgError extends Error {} + +class ArgError extends Error { } /** - * * @param {string} s */ function bad_arg(s) { @@ -24,12 +25,21 @@ function bad_arg(s) { } /** - * @typedef {{val : string}} stringref - * @typedef {{val : boolean}} boolref - * @typedef {{kind:"Unit_call",data : ()=>void } | {kind : "Unit_set", data : boolref}} unit_action - * @typedef {{kind:"String_call",data:(s : string)=>void} | {kind : "String_set",data: stringref}} string_action - * @typedef {{kind:"Unit",data : unit_action } | {kind:"String", data: string_action}} action - * @typedef {Array<[string,action,string]>} specs + * @typedef {{ val: string }} stringref + * @typedef {{ val: boolean }} boolref + * @typedef {( + * | { kind: "Unit_call", data: () => void } + * | { kind: "Unit_set", data: boolref } + * )} unit_action + * @typedef {( + * | { kind: "String_call", data: (s: string) => void } + * | { kind: "String_set", data: stringref } + * )} string_action + * @typedef {( + * | { kind: "Unit", data: unit_action } + * | { kind: "String", data: string_action} + * )} action + * @typedef {Array<[string, action, string]>} specs * @param {StringBuilder} b * @param {string} usage * @param {specs} specs @@ -39,33 +49,32 @@ function usage_b(b, usage, specs) { if (specs.length === 0) { return; } - b.add(`\nOptions:\n`); - var max_col = 0; - for (let [key] of specs) { + b.add("\nOptions:\n"); + let max_col = 0; + for (const [key] of specs) { if (key.length > max_col) { max_col = key.length; } } for (let i = 0; i < specs.length; i++) { - let [key, _, doc] = specs[i]; + const [key, _, doc] = specs[i]; if (!doc.startsWith("*internal*")) { b.add(" ") .add(key) .add(" ".repeat(max_col - key.length + 2)); let cur = 0; - let doc_length = doc.length; + const doc_length = doc.length; while (cur < doc_length) { if (cur !== 0) { b.add("\n").add(" ".repeat(max_col + 4)); } - let i = doc.indexOf("\n", cur); + const i = doc.indexOf("\n", cur); if (i < 0) { b.add(doc.substring(cur)); break; - } else { - b.add(doc.substr(cur, i - cur)); - cur = i + 1; } + b.add(doc.substring(cur, i - cur)); + cur = i + 1; } b.add("\n"); } @@ -73,13 +82,16 @@ function usage_b(b, usage, specs) { } /** - * @typedef { {kind : "Unknown"; data:string} | {kind:"Missing";data:string}} error + * @typedef {( + * | { kind: "Unknown", data:string } + * | { kind: "Missing", data:string } + * )} error * @param {string} usage * @param {error} error * @param {specs} specs */ function stop_raise(usage, error, specs) { - var b = new StringBuilder(); + const b = new StringBuilder(); switch (error.kind) { case "Unknown": if (["-help", "--help", "-h"].includes(error.data)) { @@ -89,19 +101,20 @@ function stop_raise(usage, error, specs) { } else { b.add(`Unknown option "${error.data}".\n'`); } + break; case "Missing": b.add(`Option "${error.data}" needs an argument.\n'`); + break; } usage_b(b, usage, specs); bad_arg(b.val); } /** - * * @param {string} usage * @param {Array} argv * @param {specs} specs - * @param {(args:Array)=>void} annofun + * @param {(args: Array) => void} annofun * @param {number} start * @param {number} finish */ @@ -114,15 +127,15 @@ function parse_exn( // first 3 are [node, rescript, subcommand] finish = argv.length, ) { - var current = start; - var list = []; + let current = start; + const list = []; while (current < finish) { - let s = argv[current]; + const s = argv[current]; ++current; if (s !== "" && s[0] === "-") { - var out = specs.find(([flag]) => flag === s); + const out = specs.find(([flag]) => flag === s); if (out !== undefined) { - let [_, action] = out; + const [_, action] = out; switch (action.kind) { case "Unit": switch (action.data.kind) { @@ -139,7 +152,7 @@ function parse_exn( if (current >= finish) { stop_raise(usage, { kind: "Missing", data: s }, specs); } else { - let arg = argv[current]; + const arg = argv[current]; ++current; switch (action.data.kind) { case "String_call": diff --git a/cli/rescript_bsb.js b/cli/rescript_bsb.js index 294979ddd1..6065df1b69 100644 --- a/cli/rescript_bsb.js +++ b/cli/rescript_bsb.js @@ -1,10 +1,12 @@ -//@ts-check +// @ts-check -const fs = require("fs"); -const path = require("path"); -var os = require("os"); -const child_process = require("child_process"); -const { rescript_exe } = require("./bin_path"); +const fs = require("node:fs"); +const path = require("node:path"); +const os = require("node:os"); +const child_process = require("node:child_process"); +const { createServer } = require("node:http"); +const { MiniWebSocket: WebSocket } = require("#lib/minisocket"); +const { rescript_exe } = require("#cli/bin_path"); const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); @@ -30,7 +32,7 @@ function releaseBuild() { ownerProcess.kill("SIGHUP"); try { fs.rmSync(lockFileName); - } catch {} + } catch { } ownerProcess = null; } } @@ -45,24 +47,23 @@ function releaseBuild() { function acquireBuild(args, options) { if (ownerProcess) { return null; - } else { - try { - ownerProcess = child_process.spawn(rescript_exe, args, { - stdio: "inherit", - ...options, - }); - fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { - encoding: "utf8", - flag: "wx", - mode: 0o664, - }); - } catch (err) { - if (err.code === "EEXIST") { - console.warn(lockFileName, "already exists, try later"); - } else console.log(err); - } - return ownerProcess; } + try { + ownerProcess = child_process.spawn(rescript_exe, args, { + stdio: "inherit", + ...options, + }); + fs.writeFileSync(lockFileName, ownerProcess.pid.toString(), { + encoding: "utf8", + flag: "wx", + mode: 0o664, + }); + } catch (err) { + if (err.code === "EEXIST") { + console.warn(lockFileName, "already exists, try later"); + } else console.log(err); + } + return ownerProcess; } /** @@ -110,8 +111,9 @@ function clean(args) { delegate(["clean", ...args]); } -const shouldColorizeError = process.stderr.isTTY || process.env.FORCE_COLOR == "1"; -const shouldColorize = process.stdout.isTTY || process.env.FORCE_COLOR == "1"; +const shouldColorizeError = + process.stderr.isTTY || process.env.FORCE_COLOR === "1"; +const shouldColorize = process.stdout.isTTY || process.env.FORCE_COLOR === "1"; /** * @type {[number,number]} @@ -129,12 +131,12 @@ function updateFinishTime() { * @param {number} [code] */ function logFinishCompiling(code) { - let log = `>>>> Finish compiling`; + let log = ">>>> Finish compiling"; if (code) { - log = log + " (exit: " + code + ")"; + log = `${log} (exit: ${code})`; } if (shouldColorize) { - log = "\x1b[36m" + log + "\x1b[0m"; + log = `\x1b[36m${log}\x1b[0m`; } if (code) { console.log(log); @@ -147,7 +149,7 @@ function logStartCompiling() { updateStartTime(); let log = `>>>> Start compiling`; if (shouldColorize) { - log = "\x1b[36m" + log + "\x1b[0m"; + log = `\x1b[36m${log}\x1b[0m`; } console.log(log); } @@ -164,9 +166,8 @@ function exitProcess() { function getProjectFiles(file) { if (fs.existsSync(file)) { return JSON.parse(fs.readFileSync(file, "utf8")); - } else { - return { dirs: [], generated: [] }; } + return { dirs: [], generated: [] }; } /** @@ -189,7 +190,7 @@ function watch(args) { const sourcedirs = path.join("lib", "bs", ".sourcedirs.json"); - var LAST_SUCCESS_BUILD_STAMP = 0; + let LAST_SUCCESS_BUILD_STAMP = 0; let LAST_BUILD_START = 0; let LAST_FIRED_EVENT = 0; @@ -209,22 +210,22 @@ function watch(args) { let watchers = []; const verbose = args.includes("-verbose"); - const dlog = verbose ? console.log : () => {}; + const dlog = verbose ? console.log : () => { }; - var wsParamIndex = args.indexOf("-ws"); + const wsParamIndex = args.indexOf("-ws"); if (wsParamIndex > -1) { - var hostAndPortNumber = (args[wsParamIndex + 1] || "").split(":"); + const hostAndPortNumber = (args[wsParamIndex + 1] || "").split(":"); /** * @type {number} */ - var portNumber; + let portNumber; if (hostAndPortNumber.length === 1) { - portNumber = parseInt(hostAndPortNumber[0]); + portNumber = Number.parseInt(hostAndPortNumber[0]); } else { webSocketHost = hostAndPortNumber[0]; - portNumber = parseInt(hostAndPortNumber[1]); + portNumber = Number.parseInt(hostAndPortNumber[1]); } - if (!isNaN(portNumber)) { + if (!Number.isNaN(portNumber)) { webSocketPort = portNumber; } withWebSocket = true; @@ -237,12 +238,12 @@ function watch(args) { function notifyClients() { wsClients = wsClients.filter(x => !x.closed && !x.socket.destroyed); - var wsClientsLen = wsClients.length; + const wsClientsLen = wsClients.length; dlog(`Alive sockets number: ${wsClientsLen}`); - var data = '{"LAST_SUCCESS_BUILD_STAMP":' + LAST_SUCCESS_BUILD_STAMP + "}"; - for (var i = 0; i < wsClientsLen; ++i) { + const data = JSON.stringify({ LAST_SUCCESS_BUILD_STAMP }); + for (let i = 0; i < wsClientsLen; i++) { // in reverse order, the last pushed get notified earlier - var client = wsClients[wsClientsLen - i - 1]; + const client = wsClients[wsClientsLen - i - 1]; if (!client.closed) { client.sendText(data); } @@ -250,19 +251,17 @@ function watch(args) { } function setUpWebSocket() { - var WebSocket = require("../lib/minisocket.js").MiniWebSocket; - var id = setInterval(notifyClients, 3000); - require("http") - .createServer() - .on("upgrade", function (req, socket, upgradeHead) { + const _id = setInterval(notifyClients, 3000); + createServer() + .on("upgrade", function(req, socket, upgradeHead) { dlog("connection opened"); var ws = new WebSocket(req, socket, upgradeHead); - socket.on("error", function (err) { + socket.on("error", function(err) { dlog(`Socket Error ${err}`); }); wsClients.push(ws); }) - .on("error", function (err) { + .on("error", function(err) { // @ts-ignore if (err !== undefined && err.code === "EADDRINUSE") { var error = shouldColorize ? `\x1b[1;31mERROR:\x1b[0m` : `ERROR:`; @@ -280,31 +279,26 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); * @param {ProjectFiles} projectFiles */ function watchBuild(projectFiles) { - var watchFiles = projectFiles.dirs; + const watchFiles = projectFiles.dirs; watchGenerated = projectFiles.generated; // close and remove all unused watchers - watchers = watchers.filter(function (watcher) { + watchers = watchers.filter(watcher => { if (watcher.dir === resConfig) { return true; - } else if (watchFiles.indexOf(watcher.dir) < 0) { + } + if (watchFiles.indexOf(watcher.dir) < 0) { dlog(`${watcher.dir} is no longer watched`); watcher.watcher.close(); return false; - } else { - return true; } + return true; }); // adding new watchers - for (var i = 0; i < watchFiles.length; ++i) { - var dir = watchFiles[i]; - if ( - !watchers.find(function (watcher) { - return watcher.dir === dir; - }) - ) { + for (const dir of watchFiles) { + if (!watchers.find(watcher => watcher.dir === dir)) { dlog(`watching dir ${dir} now`); - var watcher = fs.watch(dir, onChange); + const watcher = fs.watch(dir, onChange); watchers.push({ dir: dir, watcher: watcher }); } else { // console.log(dir, 'already watched') @@ -360,7 +354,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); function outputError(error, highlight) { if (shouldColorizeError && highlight) { process.stderr.write( - error.replace(highlight, "\x1b[1;31m" + highlight + "\x1b[0m"), + error.replace(highlight, `\x1b[1;31m${highlight}\x1b[0m`), ); } else { process.stderr.write(error); @@ -379,9 +373,8 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); if (reasonsToRebuild.length === 0) { dlog("No need to rebuild"); return; - } else { - dlog(`Rebuilding since ${reasonsToRebuild}`); } + dlog(`Rebuilding since ${reasonsToRebuild}`); let p; if ( (p = acquireBuild(rescriptWatchBuildArgs, { @@ -389,7 +382,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); })) ) { logStartCompiling(); - p.on("data", function (s) { + p.on("data", s => { outputError(s, "ninja: error"); }) .once("exit", buildFinishedCallback) @@ -407,7 +400,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); dlog( `Acquire lock failed, do the build later ${depth} : ${reasonsToRebuild}`, ); - const waitTime = Math.pow(2, depth) * 40; + const waitTime = 2 ** depth * 40; setTimeout(() => { build(Math.min(depth + 1, 5)); }, waitTime); @@ -420,9 +413,9 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); * @param {string | null} reason */ function onChange(event, reason) { - var eventTime = Date.now(); - var timeDiff = eventTime - LAST_BUILD_START; - var eventDiff = eventTime - LAST_FIRED_EVENT; + const eventTime = Date.now(); + const timeDiff = eventTime - LAST_BUILD_START; + const eventDiff = eventTime - LAST_FIRED_EVENT; dlog(`Since last build: ${timeDiff} -- ${eventDiff}`); if (timeDiff < 5 || eventDiff < 5) { // for 5ms, we could think that the ninja not get diff --git a/cli/rescript_dump.js b/cli/rescript_dump.js index 0aa46d4b44..5bf717f175 100644 --- a/cli/rescript_dump.js +++ b/cli/rescript_dump.js @@ -1,14 +1,16 @@ -//@ts-check -var arg = require("./rescript_arg.js"); -var dump_usage = `Usage: rescript dump [target] +// @ts-check + +const arg = require("./rescript_arg.js"); +const dump_usage = `Usage: rescript dump [target] \`rescript dump\` dumps the information for the target `; -var child_process = require("child_process"); -var path = require("path"); +const child_process = require("node:child_process"); +const path = require("node:path"); + /** * @type {arg.specs} */ -var specs = []; +const specs = []; /** * @param {string[]} argv @@ -16,7 +18,7 @@ var specs = []; * @param {string} bsc_exe */ function main(argv, rescript_exe, bsc_exe) { - var target; + let target; arg.parse_exn(dump_usage, argv, specs, xs => { if (xs.length !== 1) { arg.bad_arg(`Expect only one target, ${xs.length} found`); @@ -24,13 +26,13 @@ function main(argv, rescript_exe, bsc_exe) { target = xs[0]; }); - var { ext } = path.parse(target); + const { ext } = path.parse(target); if (ext !== ".cmi") { console.error("Only .cmi target allowed"); process.exit(2); } - var output = child_process.spawnSync(rescript_exe, ["build", "--", target], { + let output = child_process.spawnSync(rescript_exe, ["build", "--", target], { encoding: "utf-8", }); if (output.status !== 0) { diff --git a/cli/rescript_format.js b/cli/rescript_format.js index 0873b95bbb..d84b81908d 100644 --- a/cli/rescript_format.js +++ b/cli/rescript_format.js @@ -1,36 +1,37 @@ //@ts-check -var os = require("os"); -var arg = require("./rescript_arg.js"); +const os = require("node:os"); +const arg = require("./rescript_arg.js"); -var format_usage = `Usage: rescript format [files] +const format_usage = `Usage: rescript format [files] \`rescript format\` formats the current directory `; -var child_process = require("child_process"); -var util = require("util"); -var asyncExecFile = util.promisify(child_process.execFile); -var path = require("path"); -var fs = require("fs"); -var asyncFs = fs.promises; +const child_process = require("node:child_process"); +const util = require("node:util"); +const asyncExecFile = util.promisify(child_process.execFile); +const path = require("node:path"); +const fs = require("node:fs"); +const asyncFs = fs.promises; + /** * @type {arg.stringref} */ -var stdin = { val: undefined }; +const stdin = { val: "" }; /** * @type {arg.boolref} */ -var format = { val: undefined }; +const format = { val: false }; /** * @type {arg.boolref} */ -var check = { val: undefined }; +const check = { val: false }; /** * @type{arg.specs} */ -var specs = [ +const specs = [ [ "-stdin", { kind: "String", data: { kind: "String_set", data: stdin } }, @@ -48,8 +49,8 @@ the formatted code to stdout in ReScript syntax`, "Check formatting for file or the whole project. Use `-all` to check the whole project", ], ]; -var formattedStdExtensions = [".res", ".resi"]; -var formattedFileExtensions = [".res", ".resi"]; +const formattedStdExtensions = [".res", ".resi"]; +const formattedFileExtensions = [".res", ".resi"]; /** * @@ -59,11 +60,11 @@ function hasExtension(extensions) { /** * @param {string} x */ - var pred = x => extensions.some(ext => x.endsWith(ext)); + const pred = x => extensions.some(ext => x.endsWith(ext)); return pred; } async function readStdin() { - var stream = process.stdin; + const stream = process.stdin; const chunks = []; for await (const chunk of stream) chunks.push(chunk); return Buffer.concat(chunks).toString("utf8"); @@ -112,7 +113,7 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { const { stdout } = await asyncExecFile(bsc_exe, flags); if (check.val) { const original = await asyncFs.readFile(file, "utf-8"); - if (original != stdout) { + if (original !== stdout) { console.error("[format check]", file); incorrectlyFormattedFiles++; } @@ -125,7 +126,7 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { process.exit(2); } if (incorrectlyFormattedFiles > 0) { - if (incorrectlyFormattedFiles == 1) { + if (incorrectlyFormattedFiles === 1) { console.error("The file listed above needs formatting"); } else { console.error( @@ -142,24 +143,24 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { * @param {string} bsc_exe */ async function main(argv, rescript_exe, bsc_exe) { - var isSupportedFile = hasExtension(formattedFileExtensions); - var isSupportedStd = hasExtension(formattedStdExtensions); + const isSupportedFile = hasExtension(formattedFileExtensions); + const isSupportedStd = hasExtension(formattedStdExtensions); try { /** * @type {string[]} */ - var files = []; + let files = []; arg.parse_exn(format_usage, argv, specs, xs => { files = xs; }); - var format_project = format.val; - var use_stdin = stdin.val; + const format_project = format.val; + const use_stdin = stdin.val; // Only -check arg // Require: -all or path to a file - if (check.val && !format_project && files.length == 0) { + if (check.val && !format_project && files.length === 0) { console.error( "format check require path to a file or use `-all` to check the whole project", ); @@ -173,7 +174,7 @@ async function main(argv, rescript_exe, bsc_exe) { } // -all // TODO: check the rest arguments - var output = child_process.spawnSync( + const output = child_process.spawnSync( rescript_exe, ["info", "-list-files"], { @@ -193,17 +194,15 @@ async function main(argv, rescript_exe, bsc_exe) { process.exit(2); } if (isSupportedStd(use_stdin)) { - var crypto = require("crypto"); - var os = require("os"); - var filename = path.join( + const crypto = require("node:crypto"); + const os = require("node:os"); + const filename = path.join( os.tmpdir(), - "rescript_" + - crypto.randomBytes(8).toString("hex") + - path.parse(use_stdin).base, + `rescript_${crypto.randomBytes(8).toString("hex")}${path.parse(use_stdin).base}`, ); - (async function () { - var content = await readStdin(); - var fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file + (async () => { + const content = await readStdin(); + const fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file fs.writeFileSync(fd, content, "utf8"); fs.closeSync(fd); process.addListener("exit", () => fs.unlinkSync(filename)); @@ -232,8 +231,7 @@ async function main(argv, rescript_exe, bsc_exe) { files = fs.readdirSync(process.cwd()).filter(isSupportedFile); } - for (let i = 0; i < files.length; ++i) { - let file = files[i]; + for (const file of files) { if (!isSupportedStd(file)) { console.error(`Don't know what do with ${file}`); console.error(`Supported extensions: ${formattedFileExtensions}`); diff --git a/cli/rewatch b/cli/rewatch index 269daac37f..b1a0817447 100755 --- a/cli/rewatch +++ b/cli/rewatch @@ -1,13 +1,12 @@ #!/usr/bin/env node -//@ts-check -"use strict"; -const path = require("path"); -const child_process = require("child_process"); +// @ts-check + +"use strict"; -const { absolutePath: binAbsolutePath } = require("./bin_path"); -const rewatchExe = path.join(binAbsolutePath, "rewatch.exe"); +const child_process = require("node:child_process"); +const { rewatch_exe } = require("./bin_path.js"); const args = process.argv.slice(2); -child_process.spawnSync(rewatchExe, args, { stdio: "inherit" }); +child_process.spawnSync(rewatch_exe, args, { stdio: "inherit" }); diff --git a/lib/bstracing b/lib/bstracing index 2a365a6052..55012b5aa6 100755 --- a/lib/bstracing +++ b/lib/bstracing @@ -1,10 +1,10 @@ #!/usr/bin/env node -"use strict"; -//@ts-check -const fs = require("fs"); -const readline = require("readline"); -const path = require("path"); +// @ts-check + +const fs = require("node:fs"); +const readline = require("node:readline"); +const path = require("node:path"); /** * @@ -13,8 +13,8 @@ const path = require("path"); * @param {()=>void} finish */ function processEntry(file, lineCb, finish) { - let input = fs.createReadStream(file); - input.on("error", function (error) { + const input = fs.createReadStream(file); + input.on("error", (error) => { console.error(error.message); console.error( "make sure you are running after bsb building and in the top directory" @@ -23,7 +23,7 @@ function processEntry(file, lineCb, finish) { }); const rl = readline.createInterface({ input: input, - crlfDelay: Infinity, + crlfDelay: Number.POSITIVE_INFINITY, }); rl.on("line", lineCb); @@ -121,7 +121,7 @@ const colors = [ "cq_build_attempt_failed", ]; -let allocated = new Map(); +const allocated = new Map(); function getColorName(obj, cat) { obj.cat = cat; @@ -139,9 +139,9 @@ function getColorName(obj, cat) { * @param {Interval} target */ function category(target, obj) { - let targets = target.targets; + const targets = target.targets; if (targets.length === 1) { - let curTar = targets[0]; + const curTar = targets[0]; if (curTar.endsWith(".d")) { getColorName(obj, "dep"); } else if (curTar.endsWith(".mlast") || curTar.endsWith(".mliast")) { @@ -174,13 +174,13 @@ function readIntervals(file, showAll, outputFile) { processEntry( file, (line) => { - let lineTrim = line.trim(); + const lineTrim = line.trim(); if (lineTrim.startsWith("#")) { return; } let [start, end, _, name, cmdHash] = lineTrim.split("\t"); - cmdHash += "/" + end; + cmdHash += `/${end}`; if (+end < lastEndSeen) { // This is a guess // it could be wrong, when there's multiple small compilation @@ -199,12 +199,12 @@ function readIntervals(file, showAll, outputFile) { ).targets.push(name); }, () => { - let sorted = [...targets.values()].sort((a, b) => { + const sorted = [...targets.values()].sort((a, b) => { return a.start - b.start; }); - let jsonArray = []; - let threads = new Threads(); - for (let target of sorted) { + const jsonArray = []; + const threads = new Threads(); + for (const target of sorted) { jsonArray.push( category(target, { ph: "X", @@ -221,38 +221,38 @@ function readIntervals(file, showAll, outputFile) { } ); } -let logName = ".ninja_log"; +const logName = ".ninja_log"; /** * @type {string} */ -var file; +let file; /** * * @param ps {string[]} */ function tryLocation(ps) { - for (let p of ps) { - let log = path.join(p, logName); + for (const p of ps) { + const log = path.join(p, logName); if (fs.existsSync(log)) { file = log; return; } } console.error( - `no .ninja_log found in specified paths, make sure you set bstracing to the proper directory` + "no .ninja_log found in specified paths, make sure you set bstracing to the proper directory" ); process.exit(2); } let showAll = false; -let curDate = new Date(); +const curDate = new Date(); let outputFile = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDate.getSeconds()}.json`; { - let index = process.argv.indexOf(`-C`); + let index = process.argv.indexOf("-C"); if (index >= 0) { - let p = process.argv[index + 1]; + const p = process.argv[index + 1]; tryLocation([p, path.join(p, "lib", "bs")]); } else { tryLocation([".", path.join("lib", "bs")]); @@ -260,7 +260,7 @@ let outputFile = `tracing_${curDate.getHours()}_${curDate.getMinutes()}_${curDat if (process.argv.includes("-all")) { showAll = true; } - index = process.argv.indexOf(`-o`); + index = process.argv.indexOf("-o"); if (index >= 0) { outputFile = process.argv[index + 1]; } diff --git a/lib/minisocket.js b/lib/minisocket.js index 780a53e0a0..6bcb965aa4 100644 --- a/lib/minisocket.js +++ b/lib/minisocket.js @@ -1,93 +1,92 @@ - -var crypto = require("crypto"); -var KEY_SUFFIX = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; +const crypto = require("node:crypto"); +const KEY_SUFFIX = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; function hashWebSocketKey(key) { - var sha1 = crypto.createHash("sha1"); - sha1.update(key + KEY_SUFFIX, "ascii"); - return sha1.digest("base64"); + const sha1 = crypto.createHash("sha1"); + sha1.update(key + KEY_SUFFIX, "ascii"); + return sha1.digest("base64"); } /** - * Limitations: the current implementation does not + * Limitations: the current implementation does not * care about what the client send: * - we don't know `ws.close` only know `socket.closed` which is later so it has a latency * - ping pong protocol */ // http://tools.ietf.org/html/rfc6455#section-5.2 -var opcodes = { - TEXT: 1, - BINARY: 2, - CLOSE: 8, - PING: 9, - PONG: 10 +const opcodes = { + TEXT: 1, + BINARY: 2, + CLOSE: 8, + PING: 9, + PONG: 10, }; /** - * - * @param {number} opcode - * @param {Buffer} payload + * + * @param {number} opcode + * @param {Buffer} payload */ function encodeMessage(opcode, payload) { - var buf; // Buffer type - var b1 = 0x80 | opcode; - // always send message as one frame (fin) + let buf; // Buffer type + const b1 = 0x80 | opcode; + // always send message as one frame (fin) - // second byte: maks and length part 1 - // followed by 0, 2, or 8 additional bytes of continued length - var b2 = 0; - // server does not mask frames - var length = payload.length; - if (length < 126) { - buf = Buffer.allocUnsafe(payload.length + 2 + 0); - // zero extra bytes - b2 |= length; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - payload.copy(buf, 2); - } else if (length < (1 << 16)) { - buf = Buffer.allocUnsafe(payload.length + 2 + 2); - // two bytes extra - b2 |= 126; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - // add two byte length - buf.writeUInt16BE(length, 2); - payload.copy(buf, 4); - } else { - buf = Buffer.allocUnsafe(payload.length + 2 + 8); - // eight bytes extra - b2 |= 127; - buf.writeUInt8(b1, 0); - buf.writeUInt8(b2, 1); - // add eight byte length - // note: this implementation cannot handle lengths greater than 2^32 - // the 32 bit length is prefixed with 0x0000 - buf.writeUInt32BE(0, 2); - buf.writeUInt32BE(length, 6); - payload.copy(buf, 10); - } - return buf; -}; + // second byte: maks and length part 1 + // followed by 0, 2, or 8 additional bytes of continued length + let b2 = 0; + // server does not mask frames + const length = payload.length; + if (length < 126) { + buf = Buffer.allocUnsafe(payload.length + 2 + 0); + // zero extra bytes + b2 |= length; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + payload.copy(buf, 2); + } else if (length < 1 << 16) { + buf = Buffer.allocUnsafe(payload.length + 2 + 2); + // two bytes extra + b2 |= 126; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + // add two byte length + buf.writeUInt16BE(length, 2); + payload.copy(buf, 4); + } else { + buf = Buffer.allocUnsafe(payload.length + 2 + 8); + // eight bytes extra + b2 |= 127; + buf.writeUInt8(b1, 0); + buf.writeUInt8(b2, 1); + // add eight byte length + // note: this implementation cannot handle lengths greater than 2^32 + // the 32 bit length is prefixed with 0x0000 + buf.writeUInt32BE(0, 2); + buf.writeUInt32BE(length, 6); + payload.copy(buf, 10); + } + return buf; +} -var upgradeHeader = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: ' -class MiniWebSocket { - constructor(req, socket, upgradeHead) { - this.socket = socket; - this.closed = false; - var self = this; - var key = hashWebSocketKey(req.headers["sec-websocket-key"]) +const upgradeHeader = + "HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: "; +class MiniWebSocket { + constructor(req, socket, upgradeHead) { + this.socket = socket; + this.closed = false; + const key = hashWebSocketKey(req.headers["sec-websocket-key"]); - // http://tools.ietf.org/html/rfc6455#section-4.2.2 - socket.write( upgradeHeader + key + '\r\n\r\n'); - socket.on("close", function (hadError) { - if (!self.closed) { - self.closed = true; - } - }); - }; - sendText(obj) { - this.socket.write(encodeMessage(opcodes.TEXT,Buffer.from(obj, "utf8"))) - }; + // http://tools.ietf.org/html/rfc6455#section-4.2.2 + socket.write(`${upgradeHeader + key}\r\n\r\n`); + socket.on("close", hadError => { + if (!this.closed) { + this.closed = true; + } + }); + } + sendText(obj) { + this.socket.write(encodeMessage(opcodes.TEXT, Buffer.from(obj, "utf8"))); + } } -exports.MiniWebSocket = MiniWebSocket \ No newline at end of file +exports.MiniWebSocket = MiniWebSocket; diff --git a/lib_dev/meta.js b/lib_dev/meta.js new file mode 100644 index 0000000000..a21af58dcf --- /dev/null +++ b/lib_dev/meta.js @@ -0,0 +1,7 @@ +// @ts-check + +const packageJson = require("rescript/package.json"); + +module.exports = { + packageJson, +}; diff --git a/lib_dev/paths.js b/lib_dev/paths.js new file mode 100644 index 0000000000..1807147978 --- /dev/null +++ b/lib_dev/paths.js @@ -0,0 +1,104 @@ +// @ts-check + +const path = require("node:path"); + +/** + * The project root path + */ +const projectDir = path.resolve(__dirname, ".."); + +/** + * path: `/compiler/` + */ +const compilerRootDir = path.resolve(projectDir, "compiler"); + +/** + * path: `/runtime/` + */ +const runtimeDir = path.resolve(projectDir, "runtime"); + +/** + * path: `/lib/js/` + */ +const runtimeCjsOutputDir = path.resolve(projectDir, "lib", "js"); + +/** + * path: `/lib/es6/` + */ +const runtimeEsmOutputDir = path.resolve(projectDir, "lib", "es6"); + +/** + * path: `/rewatch/` + */ +const rewatchDir = path.resolve(projectDir, "rewatch"); + +/** + * path: `/ninja/` + */ +const ninjaDir = path.resolve(projectDir, "ninja"); + +/** + * path: `/tests/` + */ +const testDir = path.resolve(projectDir, "tests"); + +/** + * path: `/tests/tests/` + */ +const compilerTestDir = path.resolve(testDir, "tests"); + +/** + * path: `/tests/build_tests/` + */ +const buildTestDir = path.resolve(testDir, "build_tests"); + +/** + * path: `/tests/docstring_tests/` + */ +const docstringTestDir = path.resolve(testDir, "docstring_tests"); + +/** + * path: `/compiler/common/bs_version.ml` + */ +const compilerVersionFile = path.resolve( + compilerRootDir, + "common", + "bs_version.ml", +); + +/** + * path: `/_build/install/default/bin/` + */ +const compilerBinDir = path.resolve( + projectDir, + "_build", + "install", + "default", + "bin", +); + +/** + * path: `/tests/gentype_tests/typescript-react-example/` + */ +const gentypeExampleDir = path.resolve( + testDir, + "gentype_tests", + "typescript-react-example", +); + +module.exports = { + projectDir, + compilerRootDir, + runtimeDir, + runtimeCjsOutputDir, + runtimeEsmOutputDir, + rewatchDir, + ninjaDir, + testDir, + compilerTestDir, + buildTestDir, + docstringTestDir, + compilerVersionFile, + compilerBinDir, + gentypeExampleDir, +}; diff --git a/package.json b/package.json index 0c35e07a49..4cc6665303 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,8 @@ "test": "node scripts/test.js -all", "test-bsb": "node scripts/test.js -bsb", "test-ocaml": "node scripts/test.js -ounit", + "lint": "biome check --changed --no-errors-on-unmatched .", + "lint:all": "biome check .", "format": "biome format --changed --no-errors-on-unmatched --write .", "format:all": "biome format --write .", "checkFormat": "biome format --changed --no-errors-on-unmatched .", @@ -73,13 +75,17 @@ "./package.json": "./package.json" }, "imports": { - "#cli/bin_path": "./cli/bin_path.js" + "#cli/bin_path": "./cli/bin_path.js", + "#lib/minisocket": "./lib/minisocket.js", + "#dev/*": "./lib_dev/*.js" }, "devDependencies": { "@biomejs/biome": "1.8.3", "@types/node": "^20.14.9", + "@types/semver": "^7.5.8", "mocha": "10.8.2", "nyc": "15.0.0", + "semver": "7.6.2", "typescript": "5.5.3" }, "workspaces": [ diff --git a/packages/playground-bundling/rollup.config.cjs b/packages/playground-bundling/rollup.config.cjs index f4bf6db3aa..73675ebdce 100644 --- a/packages/playground-bundling/rollup.config.cjs +++ b/packages/playground-bundling/rollup.config.cjs @@ -10,7 +10,7 @@ const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); const PACKAGES_DIR = path.join(PLAYGROUND_DIR, "packages"); const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins", "stdlib"); -module.exports = globSync(`${LIB_DIR}/es6/*.js`).map((entryPoint) => { +module.exports = globSync(`${LIB_DIR}/es6/*.js`).map(entryPoint => { return { input: entryPoint, output: { diff --git a/packages/playground-bundling/scripts/generate_cmijs.js b/packages/playground-bundling/scripts/generate_cmijs.js index 00c2f6273d..f2ee548cac 100644 --- a/packages/playground-bundling/scripts/generate_cmijs.js +++ b/packages/playground-bundling/scripts/generate_cmijs.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -"use strict"; +// @ts-check /* * Requires the version matching `rescript` binary to be `npm link`ed in this @@ -15,9 +15,9 @@ * playground bundle. */ -const child_process = require("child_process"); -const fs = require("fs"); -const path = require("path"); +const child_process = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); const resConfig = require("../rescript.json"); @@ -35,23 +35,23 @@ if (!fs.existsSync(PACKAGES_DIR)) { fs.mkdirSync(PACKAGES_DIR, { recursive: true }); } -const config = { - cwd: PROJECT_ROOT_DIR, - encoding: "utf8", - stdio: [0, 1, 2], - shell: true, -}; - +/** + * @param {string} cmd + */ function e(cmd) { console.log(`>>>>>> running command: ${cmd}`); - child_process.execSync(cmd, config); - console.log(`<<<<<<`); + child_process.execSync(cmd, { + cwd: PROJECT_ROOT_DIR, + encoding: "utf8", + stdio: [0, 1, 2], + }); + console.log("<<<<<<"); } -e(`npm install`); +e("npm install"); e(`npm link ${RESCRIPT_COMPILER_ROOT_DIR}`); -e(`npx rescript clean`); -e(`npx rescript`); +e("npx rescript clean"); +e("npx rescript"); const packages = resConfig["bs-dependencies"]; @@ -63,41 +63,41 @@ function buildCompilerCmij() { "node_modules", "rescript", "lib", - "ocaml" + "ocaml", ); const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins"); - const cmijFile = path.join(outputFolder, `cmij.js`); + const cmijFile = path.join(outputFolder, "cmij.js"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); } e( - `find ${rescriptLibOcamlFolder} -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${cmijFile} -I ${rescriptLibOcamlFolder}` + `find ${rescriptLibOcamlFolder} -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${cmijFile} -I ${rescriptLibOcamlFolder}`, ); } function buildThirdPartyCmijs() { - packages.forEach(function installLib(pkg) { + for (const pkg of packages) { const libOcamlFolder = path.join( PROJECT_ROOT_DIR, "node_modules", pkg, "lib", - "ocaml" + "ocaml", ); const libEs6Folder = path.join( PROJECT_ROOT_DIR, "node_modules", pkg, "lib", - "es6" + "es6", ); const outputFolder = path.join(PACKAGES_DIR, pkg); - const cmijFile = path.join(outputFolder, `cmij.js`); + const cmijFile = path.join(outputFolder, "cmij.js"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); @@ -105,9 +105,9 @@ function buildThirdPartyCmijs() { e(`find ${libEs6Folder} -name '*.js' -exec cp {} ${outputFolder} \\;`); e( - `find ${libOcamlFolder} -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${cmijFile} -I ${libOcamlFolder}` + `find ${libOcamlFolder} -name "*.cmi" -or -name "*.cmj" | xargs -n1 basename | xargs js_of_ocaml build-fs -o ${cmijFile} -I ${libOcamlFolder}`, ); - }); + } } function bundleStdlibJs() { diff --git a/packages/playground-bundling/tsconfig.json b/packages/playground-bundling/tsconfig.json new file mode 100644 index 0000000000..49d00ee978 --- /dev/null +++ b/packages/playground-bundling/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "resolveJsonModule": true + }, + "include": ["scripts", "rescript.json"], + "exclude": ["lib/**"] +} diff --git a/playground/playground_test.js b/playground/playground_test.js index be5cc1df71..43b25ee4e3 100644 --- a/playground/playground_test.js +++ b/playground/playground_test.js @@ -1,13 +1,13 @@ // Playground bundle is UMD module // It uses `module.exports` in current context, or fallback to `globalThis` -const { rescript_compiler } = require("./compiler.js") +const { rescript_compiler } = require("./compiler.js"); -require("./packages/compiler-builtins/cmij.js") -require("./packages/@rescript/react/cmij.js") +require("./packages/compiler-builtins/cmij.js"); +require("./packages/@rescript/react/cmij.js"); -let compiler = rescript_compiler.make() +const compiler = rescript_compiler.make(); -let result = compiler.rescript.compile(` +const result = compiler.rescript.compile(` @@jsxConfig({ version: 4, mode: "automatic" }) module A = { @@ -27,7 +27,7 @@ let result = compiler.rescript.compile(` } } - let sum = [1,2,3] + let sum = [1,2,3] ->Array.map(x => x * 2) ->Array.reduce(0, (acc, item) => acc + item) @@ -41,29 +41,29 @@ let result = compiler.rescript.compile(` let a = `); -if(result.js_code != "") { - console.log('-- Playground test output --'); +if (result.js_code !== "") { + console.log("-- Playground test output --"); console.log(`ReScript version: ${compiler.rescript.version}`); - console.log('----'); - if(result.type === "unexpected_error") { + console.log("----"); + if (result.type === "unexpected_error") { console.log("UNEXPECTED ERROR"); console.log(result); process.exit(1); } - if(result.errors && result.errors.length > 0) { + if (result.errors && result.errors.length > 0) { console.log("COMPILATION ERROR"); - for(let error of result.errors) { + for (const error of result.errors) { console.log(error.shortMsg); } process.exit(1); } - if(result.warnings.length === 0) { + if (result.warnings.length === 0) { console.log("TEST FAILED"); console.log("The code should have at least one warning."); process.exit(1); } console.log(result.js_code); - console.log('-- Playground test complete --'); + console.log("-- Playground test complete --"); } diff --git a/scripts/buildNinjaBinary.js b/scripts/buildNinjaBinary.js index 92e3411be2..af73d99056 100755 --- a/scripts/buildNinjaBinary.js +++ b/scripts/buildNinjaBinary.js @@ -1,7 +1,9 @@ #!/usr/bin/env node -const child_process = require("child_process"); -const path = require("path"); +// @ts-check + +const child_process = require("node:child_process"); +const path = require("node:path"); const platform = process.platform; const ninjaDir = path.join(__dirname, "..", "ninja"); @@ -12,8 +14,8 @@ if (platform === "win32") { child_process.execSync(buildCommand, { cwd: ninjaDir }); } else { if (process.platform === "darwin") { - process.env["CXXFLAGS"] = "-flto"; + process.env.CXXFLAGS = "-flto"; } child_process.execSync(buildCommand, { stdio: [0, 1, 2], cwd: ninjaDir }); - child_process.execSync(`strip ninja`, { stdio: [0, 1, 2], cwd: ninjaDir }); + child_process.execSync("strip ninja", { stdio: [0, 1, 2], cwd: ninjaDir }); } diff --git a/scripts/copyExes.js b/scripts/copyExes.js index b9ebe91cc3..14017b9bc7 100755 --- a/scripts/copyExes.js +++ b/scripts/copyExes.js @@ -1,23 +1,25 @@ #!/usr/bin/env node -// Copy exes built by dune to platform bin dir -const path = require("path"); -const fs = require("fs"); -const child_process = require("child_process"); -const { duneBinDir } = require("./dune"); -const { absolutePath: platformBinDir } = require("#cli/bin_path"); +// @ts-check + +// Copy exes built by dune to platform bin dir -const ninjaDir = path.join(__dirname, "..", "ninja"); -const rewatchDir = path.join(__dirname, "..", "rewatch"); +const path = require("node:path"); +const fs = require("node:fs"); +const child_process = require("node:child_process"); +const { platformDir } = require("#cli/bin_path"); +const { compilerBinDir, ninjaDir, rewatchDir } = require("#dev/paths"); -if (!fs.existsSync(platformBinDir)) { - fs.mkdirSync(platformBinDir); -} +fs.mkdirSync(platformDir, { recursive: true }); +/** + * @param {string} dir + * @param {string} exe + */ function copyExe(dir, exe) { const ext = process.platform === "win32" ? ".exe" : ""; const src = path.join(dir, exe + ext); - const dest = path.join(platformBinDir, exe + ".exe"); + const dest = path.join(platformDir, `${exe}.exe`); // For some reason, the copy operation fails in Windows CI if the file already exists. if (process.platform === "win32" && fs.existsSync(dest)) { @@ -41,11 +43,11 @@ function copyExe(dir, exe) { } if (process.argv.includes("-all") || process.argv.includes("-compiler")) { - copyExe(duneBinDir, "rescript"); - copyExe(duneBinDir, "rescript-editor-analysis"); - copyExe(duneBinDir, "rescript-tools"); - copyExe(duneBinDir, "bsc"); - copyExe(duneBinDir, "bsb_helper"); + copyExe(compilerBinDir, "rescript"); + copyExe(compilerBinDir, "rescript-editor-analysis"); + copyExe(compilerBinDir, "rescript-tools"); + copyExe(compilerBinDir, "bsc"); + copyExe(compilerBinDir, "bsb_helper"); } if (process.argv.includes("-all") || process.argv.includes("-ninja")) { diff --git a/scripts/dune.js b/scripts/dune.js deleted file mode 100644 index dd22149381..0000000000 --- a/scripts/dune.js +++ /dev/null @@ -1,12 +0,0 @@ -var path = require("path"); - -var duneBinDir = path.join( - __dirname, - "..", - "_build", - "install", - "default", - "bin", -); - -exports.duneBinDir = duneBinDir; diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index 3d5b80cc48..17f581249d 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -1,37 +1,38 @@ #!/usr/bin/env node -//@ts-check -const path = require("path"); -const fs = require("fs"); -const assert = require("assert"); +// @ts-check -const package_config = require(path.join(__dirname, "..", "package.json")); -const bsVersion = fs.readFileSync( - path.join(__dirname, "..", "compiler", "common", "bs_version.ml"), - "utf-8", -); +const fs = require("node:fs"); +const assert = require("node:assert"); +const semver = require("semver"); +const { compilerVersionFile } = require("#dev/paths"); +const { packageJson } = require("#dev/meta"); /** - * @param {string} bsVersion - * @param {string} version + * @param {semver.SemVer} bsVersion + * @param {semver.SemVer} version */ function verifyVersion(bsVersion, version) { - try { - let [major, minor] = bsVersion - .split("\n") - .find(x => x.startsWith("let version = ")) - .split("=")[1] - .trim() - .slice(1, -1) - .split("."); - let [specifiedMajor, specifiedMinor] = version.split("."); - console.log( - `Version check: package.json: ${specifiedMajor}.${specifiedMinor} vs ABI: ${major}.${minor}`, - ); - return major === specifiedMajor && minor === specifiedMinor; - } catch (e) { - return false; - } + const { major, minor } = bsVersion; + const { major: specifiedMajor, minor: specifiedMinor } = version; + console.log( + `Version check: package.json: ${specifiedMajor}.${specifiedMinor} vs ABI: ${major}.${minor}`, + ); + return major === specifiedMajor && minor === specifiedMinor; } -assert(verifyVersion(bsVersion, package_config.version)); +const bsVersionPattern = /let version = "(?.*)"/m; +const bsVersionFileContent = fs.readFileSync(compilerVersionFile, "utf-8"); +const bsVersionMatch = bsVersionFileContent.match(bsVersionPattern)?.groups; +assert.ok(bsVersionMatch, "Failed to parse the compiler version file"); + +const bsVersion = semver.parse(bsVersionMatch.version); +assert.ok(bsVersion, "Failed to parse the compiler version file"); + +const pakageVersion = semver.parse(packageJson.version); +assert.ok(pakageVersion, "Failed to parse the version of the package.json"); + +assert.ok( + verifyVersion(bsVersion, pakageVersion), + `Bump the compiler version in ${compilerVersionFile}`, +); diff --git a/scripts/setVersion.js b/scripts/setVersion.js index d82e25425f..f70a61726a 100644 --- a/scripts/setVersion.js +++ b/scripts/setVersion.js @@ -1,8 +1,8 @@ -//@ts-check -/** - * This file is used only in dev time, feel free to use es6 - */ -const fs = require("fs"); +#!/usr/bin/env node + +// @ts-check + +const fs = require("node:fs"); const packageSpec = JSON.parse(fs.readFileSync("./package.json", "utf8")); const { version, name } = packageSpec; diff --git a/scripts/test.js b/scripts/test.js index 010103b42e..a9d7b79516 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,11 +1,17 @@ -//@ts-check -const cp = require("child_process"); -const path = require("path"); -const fs = require("fs"); -const os = require("os"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const duneBinDir = require("./dune").duneBinDir; +const cp = require("node:child_process"); +const path = require("node:path"); +const fs = require("node:fs"); +const os = require("node:os"); +const { rescript_exe } = require("#cli/bin_path"); +const { + projectDir, + compilerBinDir, + compilerTestDir, + buildTestDir, + docstringTestDir, +} = require("#dev/paths"); const { exec } = require("../tests/build_tests/utils.js"); @@ -46,7 +52,7 @@ if (process.argv.includes("-all")) { async function runTests() { if (formatTest) { cp.execSync("bash scripts/format_check.sh", { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }); } @@ -55,7 +61,7 @@ async function runTests() { if (process.platform === "win32") { console.log("Skipping OUnit tests on Windows"); } else { - cp.execSync(path.join(duneBinDir, "ounit_tests"), { + cp.execSync(path.join(compilerBinDir, "ounit_tests"), { stdio: [0, 1, 2], }); } @@ -63,34 +69,33 @@ async function runTests() { if (mochaTest) { cp.execSync(`${rescript_exe} clean`, { - cwd: path.join(__dirname, "..", "tests/tests"), + cwd: compilerTestDir, stdio: [0, 1, 2], }); cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/tests"), + cwd: compilerTestDir, stdio: [0, 1, 2], }); cp.execSync("npx mocha -t 10000 tests/tests/**/*_test.mjs", { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }); cp.execSync("node tests/tests/src/core/Core_TestSuite.mjs", { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }); cp.execSync("node tests/tests/src/core/Core_TempTests.mjs", { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }); } if (bsbTest) { console.log("Doing build_tests"); - const buildTestDir = path.join(__dirname, "..", "tests", "build_tests"); const files = fs.readdirSync(buildTestDir); let hasError = false; @@ -106,7 +111,7 @@ async function runTests() { console.log(`testing ${file}`); // note existsSync test already ensure that it is a directory - const out = await exec(`node`, ["input.js"], { cwd: testDir }); + const out = await exec("node", ["input.js"], { cwd: testDir }); console.log(out.stdout); if (out.status === 0) { @@ -128,7 +133,7 @@ async function runTests() { console.log(`Skipping docstrings tests on ${process.platform}`); } else if (process.platform === "darwin" && os.release().startsWith("22")) { // Workaround for intermittent hangs in CI - console.log("Skipping docstrings tests on macOS 13") + console.log("Skipping docstrings tests on macOS 13"); } else { console.log("Running runtime docstrings tests"); @@ -145,29 +150,26 @@ async function runTests() { } cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstring_tests"), + cwd: docstringTestDir, stdio: [0, 1, 2], }); // Generate rescript file with all tests `generated_mocha_test.res` - cp.execSync( - `node ${path.join("tests", "docstring_tests", "DocTest.res.mjs")}`, - { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }, - ); + cp.execSync(`node ${path.join(docstringTestDir, "DocTest.res.mjs")}`, { + cwd: projectDir, + stdio: [0, 1, 2], + }); // Build again to check if generated_mocha_test.res has syntax or type erros cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstring_tests"), + cwd: docstringTestDir, stdio: [0, 1, 2], }); // Format generated_mocha_test.res console.log("Formatting generated_mocha_test.res"); cp.execSync(`./cli/rescript format ${generated_mocha_test_res}`, { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }); @@ -175,7 +177,7 @@ async function runTests() { cp.execSync( `npx mocha ${path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")}`, { - cwd: path.join(__dirname, ".."), + cwd: projectDir, stdio: [0, 1, 2], }, ); diff --git a/tests/analysis_tests/tests-reanalyze/deadcode/.watchmanconfig b/tests/analysis_tests/tests-reanalyze/deadcode/.watchmanconfig deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/analysis_tests/tests-reanalyze/termination/.watchmanconfig b/tests/analysis_tests/tests-reanalyze/termination/.watchmanconfig deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index 01e4c30179..9e771b3e80 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -1,31 +1,31 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var o1 = p.spawnSync(rescript_exe, ["build"], { +const o1 = p.spawnSync(rescript_exe, ["build"], { encoding: "utf8", cwd: __dirname, }); -var first_message = o1.stdout +const first_message = o1.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Warning number 110"); + .find(s => s === "Warning number 110"); if (!first_message) { assert.fail(o1.stdout); } // Second build using -warn-error +110 -var o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], { +const o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], { encoding: "utf8", cwd: __dirname, }); -var second_message = o2.stdout +const second_message = o2.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Warning number 110 (configured as error)"); + .find(s => s === "Warning number 110 (configured as error)"); if (!second_message) { assert.fail(o2.stdout); @@ -33,15 +33,15 @@ if (!second_message) { // Third build, without -warn-error +110 // The result should not be a warning as error -var o3 = p.spawnSync(rescript_exe, ["build"], { +const o3 = p.spawnSync(rescript_exe, ["build"], { encoding: "utf8", cwd: __dirname, }); -var third_message = o3.stdout +const third_message = o3.stdout .split("\n") .map(s => s.trim()) - .find(s => s == "Dependency Finished"); + .find(s => s === "Dependency Finished"); if (!third_message) { assert.fail(o3.stdout); diff --git a/tests/build_tests/case/input.js b/tests/build_tests/case/input.js index b3cbcc4d85..c58952240d 100644 --- a/tests/build_tests/case/input.js +++ b/tests/build_tests/case/input.js @@ -1,17 +1,17 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var { normalizeNewlines } = require("../utils.js"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const { normalizeNewlines } = require("../utils.js"); -var o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); if ( ![ - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/demo vs src/Demo\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/demo vs src/Demo\n", // Windows: path separator - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\demo vs src\\Demo\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\demo vs src\\Demo\n", // Linux: files are parsed in different order - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/Demo vs src/demo\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/Demo vs src/demo\n", ].includes(normalizeNewlines(o.stderr)) ) { assert.fail(o.stderr); diff --git a/tests/build_tests/case2/input.js b/tests/build_tests/case2/input.js index 421017507e..c184c7982f 100644 --- a/tests/build_tests/case2/input.js +++ b/tests/build_tests/case2/input.js @@ -1,17 +1,17 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var { normalizeNewlines } = require("../utils.js"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const { normalizeNewlines } = require("../utils.js"); -var o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); if ( ![ - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/X vs src/x\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/X vs src/x\n", // Windows: path separator - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\X vs src\\x\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\X vs src\\x\n", // Linux: files are parsed in different order - `Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/x vs src/X\n`, + "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/x vs src/X\n", ].includes(normalizeNewlines(o.stderr)) ) { assert.fail(o.stderr); diff --git a/tests/build_tests/case3/input.js b/tests/build_tests/case3/input.js index c33330667b..40dc2be6b6 100644 --- a/tests/build_tests/case3/input.js +++ b/tests/build_tests/case3/input.js @@ -1,14 +1,14 @@ //@ts-check -var p = require("child_process"); -var fs = require("fs"); -var path = require("path"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); p.spawnSync(`${rescript_exe} clean && ${rescript_exe} build`, { encoding: "utf8", cwd: __dirname, }); -var o = fs.readFileSync(path.join(__dirname, "src", "hello.bs.js"), "ascii"); +const o = fs.readFileSync(path.join(__dirname, "src", "hello.bs.js"), "ascii"); assert.ok(/HelloGen\.f/.test(o)); diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index e41e57b39a..f40ac99cea 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -1,11 +1,11 @@ // @ts-check -const assert = require("assert"); -const path = require("path"); -const child_process = require("child_process"); +const assert = require("node:assert"); +const path = require("node:path"); +const child_process = require("node:child_process"); const { normalizeNewlines } = require("../utils.js"); -const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript") +const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript"); // Shows compile time for `rescript build` command let out = child_process.spawnSync("node", [rescriptPath, "build"], { @@ -40,5 +40,8 @@ out = child_process.spawnSync("node", [rescriptPath, "build", "-verbose"], { cwd: __dirname, }); -assert.match(normalizeNewlines(out.stdout), /Package stack: test \nDependency Finished\n/); +assert.match( + normalizeNewlines(out.stdout), + /Package stack: test \nDependency Finished\n/, +); assert.match(normalizeNewlines(out.stdout), /ninja.exe"? -C lib[\\/]bs ?\n/); diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index 326f1b4f99..687dbf66d4 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -4,7 +4,7 @@ const assert = require("assert"); const path = require("path"); const { exec, normalizeNewlines } = require("../utils.js"); -const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript") +const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript"); const cliHelp = "Usage: rescript \n" + @@ -77,12 +77,20 @@ async function runTest(params, expected) { assert.equal(normalizeNewlines(out.stderr), expected.stderr); assert.equal(out.status, expected.status); } - + async function test() { - // Shows build help with --help arg - await runTest(["build", "--help"], { stdout: buildHelp, stderr: "", status: 0 }); + // Shows build help with --help arg + await runTest(["build", "--help"], { + stdout: buildHelp, + stderr: "", + status: 0, + }); - await runTest(["build", "-w", "--help"], { stdout: buildHelp, stderr: "", status: 0 }); + await runTest(["build", "-w", "--help"], { + stdout: buildHelp, + stderr: "", + status: 0, + }); await runTest(["-w", "--help"], { stdout: cliHelp, stderr: "", status: 0 }); @@ -123,7 +131,11 @@ async function test() { }); // Shows clean help with --help arg - await runTest(["clean", "--help"], { stdout: cleanHelp, stderr: "", status: 0 }); + await runTest(["clean", "--help"], { + stdout: cleanHelp, + stderr: "", + status: 0, + }); // Shows clean help with -h arg await runTest(["clean", "-h"], { stdout: cleanHelp, stderr: "", status: 0 }); @@ -136,13 +148,25 @@ async function test() { }); // Shows format help with --help arg - await runTest(["format", "--help"], { stdout: formatHelp, stderr: "", status: 0 }); + await runTest(["format", "--help"], { + stdout: formatHelp, + stderr: "", + status: 0, + }); // Shows format help with -h arg - await runTest(["format", "-h"], { stdout: formatHelp, stderr: "", status: 0 }); + await runTest(["format", "-h"], { + stdout: formatHelp, + stderr: "", + status: 0, + }); // Shows dump help with --help arg - await runTest(["dump", "--help"], { stdout: dumpHelp, stderr: "", status: 0 }); + await runTest(["dump", "--help"], { + stdout: dumpHelp, + stderr: "", + status: 0, + }); // Shows dump help with -h arg await runTest(["dump", "-h"], { stdout: dumpHelp, stderr: "", status: 0 }); diff --git a/tests/build_tests/custom_namespace/input.js b/tests/build_tests/custom_namespace/input.js index e4502cb0c4..6e113560da 100644 --- a/tests/build_tests/custom_namespace/input.js +++ b/tests/build_tests/custom_namespace/input.js @@ -1,10 +1,10 @@ -var child_process = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(`${rescript_exe} clean && ${rescript_exe} build`, { cwd: __dirname, }); -var x = require("./src/demo.bs.js"); +const x = require("./src/demo.bs.js"); assert.equal(x.v, 42); diff --git a/tests/build_tests/cycle/input.js b/tests/build_tests/cycle/input.js index d94a234e49..fc4f9892ee 100644 --- a/tests/build_tests/cycle/input.js +++ b/tests/build_tests/cycle/input.js @@ -1,14 +1,14 @@ //@ts-check -const cp = require("child_process"); -const assert = require("assert"); -const fs = require("fs"); -const path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); -var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); assert(/dependency cycle/.test(output.stdout)); -var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -var compilerLog = fs.readFileSync(compilerLogFile, "utf8"); +const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); +const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); assert(/dependency cycle/.test(compilerLog)); diff --git a/tests/build_tests/cycle1/input.js b/tests/build_tests/cycle1/input.js index 1894a6c1a8..b9123e7fa3 100644 --- a/tests/build_tests/cycle1/input.js +++ b/tests/build_tests/cycle1/input.js @@ -1,16 +1,16 @@ //@ts-check -const cp = require("child_process"); -const assert = require("assert"); -const fs = require("fs"); -const path = require("path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); const { rescript_exe } = require("#cli/bin_path"); cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); -var output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); assert(/is dangling/.test(output.stdout)); -var compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -var compilerLog = fs.readFileSync(compilerLogFile, "utf8"); +const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); +const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); assert(/is dangling/.test(compilerLog)); diff --git a/tests/build_tests/deprecated-package-specs/input.js b/tests/build_tests/deprecated-package-specs/input.js index 7a7769861d..d403bda1f6 100644 --- a/tests/build_tests/deprecated-package-specs/input.js +++ b/tests/build_tests/deprecated-package-specs/input.js @@ -1,5 +1,5 @@ -const child_process = require("child_process"); -const assert = require("assert"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); const { rescript_exe } = require("#cli/bin_path"); const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); diff --git a/tests/build_tests/devonly/input.js b/tests/build_tests/devonly/input.js index 2aec9809b2..c1304efb8e 100644 --- a/tests/build_tests/devonly/input.js +++ b/tests/build_tests/devonly/input.js @@ -1,5 +1,5 @@ //@ts-check -var cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); diff --git a/tests/build_tests/duplicated_symlinked_packages/input.js b/tests/build_tests/duplicated_symlinked_packages/input.js index a80c90d0d5..32e66f67be 100644 --- a/tests/build_tests/duplicated_symlinked_packages/input.js +++ b/tests/build_tests/duplicated_symlinked_packages/input.js @@ -1,16 +1,18 @@ -const fs = require("fs"); -const path = require("path"); -const child_process = require("child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const child_process = require("node:child_process"); const { rescript_exe } = require("#cli/bin_path"); const expectedFilePath = path.join(__dirname, "out.expected"); const updateTests = process.argv[2] === "update"; +/** + * @param {string} output + * @return {string} + */ function postProcessErrorOutput(output) { - output = output.trimRight(); - output = output.replace(new RegExp(__dirname, "gi"), "."); - return output; + return output.trimEnd().replace(new RegExp(__dirname, "gi"), "."); } if (process.platform === "win32") { diff --git a/tests/build_tests/exports/input.js b/tests/build_tests/exports/input.js index 76ead396b3..596c5522a0 100644 --- a/tests/build_tests/exports/input.js +++ b/tests/build_tests/exports/input.js @@ -1,5 +1,5 @@ -var child_process = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(rescript_exe, { cwd: __dirname, diff --git a/tests/build_tests/gpr_978/rescript.json b/tests/build_tests/gpr_978/rescript.json index 406397e559..f921adf5b8 100644 --- a/tests/build_tests/gpr_978/rescript.json +++ b/tests/build_tests/gpr_978/rescript.json @@ -1,8 +1,6 @@ { "name": "gpr_978", "version": "0.0.0", - "sources": [ - "src" - ], + "sources": ["src"], "bs-dependencies": [] -} \ No newline at end of file +} diff --git a/tests/build_tests/hyphen2/input.js b/tests/build_tests/hyphen2/input.js index 84c35bb893..4e568e556e 100644 --- a/tests/build_tests/hyphen2/input.js +++ b/tests/build_tests/hyphen2/input.js @@ -1,4 +1,4 @@ -var p = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js index 533a61a521..d25402fbe9 100644 --- a/tests/build_tests/in_source/input.js +++ b/tests/build_tests/in_source/input.js @@ -1,24 +1,19 @@ -var child_process = require("child_process"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); -var assert = require("assert"); - -var { rescript_exe } = require("#cli/bin_path"); +const { rescript_exe } = require("#cli/bin_path"); assert.throws( () => { - var output = child_process.execSync(`${rescript_exe} build -regen`, { + const output = child_process.execSync(`${rescript_exe} build -regen`, { cwd: __dirname, encoding: "utf8", }); }, - function (err) { + err => { if (err.message.match(/detected two module formats/)) { return true; } return false; }, ); - -// assert.throws(()=>{ -// throw new Error('Wrong value') -// }, /x/) diff --git a/tests/build_tests/install/input.js b/tests/build_tests/install/input.js index 407e1f9558..4d720c5892 100644 --- a/tests/build_tests/install/input.js +++ b/tests/build_tests/install/input.js @@ -1,26 +1,26 @@ -var p = require("child_process"); -var fs = require("fs"); -var path = require("path"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -p.spawnSync(rescript_exe, [`clean`], { +p.spawnSync(rescript_exe, ["clean"], { encoding: "utf8", cwd: __dirname, }); -p.spawnSync(rescript_exe, [`build`, `-install`], { +p.spawnSync(rescript_exe, ["build", "-install"], { encoding: "utf8", cwd: __dirname, }); -var fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); -assert.ok(fooExists == false); +let fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); +assert.ok(fooExists === false); p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname, }); -p.spawnSync(rescript_exe, [`build`, `-install`], { +p.spawnSync(rescript_exe, ["build", "-install"], { encoding: "utf8", cwd: __dirname, }); diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 96e9ab8353..8cfd468c7a 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -1,5 +1,5 @@ //@ts-check -var cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname }); diff --git a/tests/build_tests/jsx_settings_inheritance/rescript.json b/tests/build_tests/jsx_settings_inheritance/rescript.json index bedc0f0d67..2c83b7c9ac 100644 --- a/tests/build_tests/jsx_settings_inheritance/rescript.json +++ b/tests/build_tests/jsx_settings_inheritance/rescript.json @@ -16,9 +16,5 @@ ], "suffix": ".mjs", "namespace": true, - "bs-dependencies": [ - "@rescript/react", - "a", - "b" - ] -} \ No newline at end of file + "bs-dependencies": ["@rescript/react", "a", "b"] +} diff --git a/tests/build_tests/nested/input.js b/tests/build_tests/nested/input.js index a56e24f14e..0e7135a212 100644 --- a/tests/build_tests/nested/input.js +++ b/tests/build_tests/nested/input.js @@ -1,11 +1,11 @@ -var p = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); -var content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); +const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); assert.ok(content.match(/A00_a1_main/g).length === 3); assert.ok(content.match(/B00_b1_main/g).length === 3); diff --git a/tests/build_tests/nnest/input.js b/tests/build_tests/nnest/input.js index e3ad473862..d9de24ac45 100644 --- a/tests/build_tests/nnest/input.js +++ b/tests/build_tests/nnest/input.js @@ -1,13 +1,13 @@ // @ts-check -var p = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe, { cwd: __dirname }); -var content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); +const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); assert.ok(content.match(/A0_a1_main/g).length === 3); assert.ok(content.match(/B0_b1_main/g).length === 3); diff --git a/tests/build_tests/ns/input.js b/tests/build_tests/ns/input.js index 55e41645da..1c14e98e41 100755 --- a/tests/build_tests/ns/input.js +++ b/tests/build_tests/ns/input.js @@ -1,4 +1,4 @@ -var child_process = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); child_process.execSync(rescript_exe, { cwd: __dirname }); diff --git a/tests/build_tests/post-build/input.js b/tests/build_tests/post-build/input.js index 8a9b223f42..29b4fe685e 100644 --- a/tests/build_tests/post-build/input.js +++ b/tests/build_tests/post-build/input.js @@ -1,13 +1,13 @@ -var child_process = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -var out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.status !== 0) { assert.fail(out.stdout + out.stderr); diff --git a/tests/build_tests/rerror/input.js b/tests/build_tests/rerror/input.js index 6f452f1331..44ee1fc0f4 100644 --- a/tests/build_tests/rerror/input.js +++ b/tests/build_tests/rerror/input.js @@ -1,30 +1,29 @@ // @ts-check -var child_process = require("child_process"); -var assert = require("assert"); -var os = require("os"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); child_process.spawnSync(`${rescript_exe} clean`, { cwd: __dirname, encoding: "utf8", }); -var o = child_process.spawnSync(rescript_exe, { +const o = child_process.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", shell: true, }); // verify the output is in reason syntax -var u = o.stdout.match(/=>/g); +const u = o.stdout.match(/=>/g); -var lines = o.stdout +const lines = o.stdout .split(/\r?\n/) .map(x => x.trim()) .filter(Boolean); -var test = false; -for (var i = 0; i < lines.length; ++i) { +let test = false; +for (let i = 0; i < lines.length; i++) { if (lines[i] === "We've found a bug for you!") { console.log(`line ${i} found`); assert.ok(/src[\\/]demo.res:1:21-23/.test(lines[i + 1])); @@ -32,4 +31,4 @@ for (var i = 0; i < lines.length; ++i) { } } assert.ok(test); -assert.ok(u.length === 2); +assert.ok(u?.length === 2); diff --git a/tests/build_tests/scoped_ppx/input.js b/tests/build_tests/scoped_ppx/input.js index 9d75560d0d..4d294148fb 100644 --- a/tests/build_tests/scoped_ppx/input.js +++ b/tests/build_tests/scoped_ppx/input.js @@ -1,6 +1,6 @@ -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); if (process.platform === "win32") { console.log("Skipping test on Windows"); @@ -9,12 +9,15 @@ if (process.platform === "win32") { cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); -var output = cp.execSync(`${rescript_exe} build -- -t commands src/hello.ast`, { - cwd: __dirname, - encoding: "utf8", -}); +const output = cp.execSync( + `${rescript_exe} build -- -t commands src/hello.ast`, + { + cwd: __dirname, + encoding: "utf8", + }, +); -assert( +assert.ok( /-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test( output, ), diff --git a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js index 34ea82903f..92f21f0418 100755 --- a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js +++ b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js @@ -1,12 +1,11 @@ #!/usr/bin/env node + //@ts-check -var fs = require('fs') -// let [_node, _js, file_in, file_out] = process.argv -var file_in = process.argv[process.argv.length - 2] -var file_out = process.argv[process.argv.length - 1] -// console.log(process.argv) -// debugger; -fs.createReadStream(file_in) - .pipe(fs.createWriteStream(file_out)) +const fs = require('node:fs') +const file_in = process.argv[process.argv.length - 2] +const file_out = process.argv[process.argv.length - 1] + +fs.createReadStream(file_in) + .pipe(fs.createWriteStream(file_out)) diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index ffe4642523..9702ed74f0 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -1,6 +1,6 @@ -const fs = require("fs"); -const path = require("path"); -const child_process = require("child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const child_process = require("node:child_process"); const { bsc_exe: bsc } = require("#cli/bin_path"); const { normalizeNewlines } = require("../utils.js"); @@ -11,25 +11,28 @@ const fixtures = fs .readdirSync(path.join(__dirname, "fixtures")) .filter(fileName => path.extname(fileName) === ".res"); -// const runtime = path.join(__dirname, '..', '..', 'runtime') const prefix = `${bsc} -w +A -bs-jsx 4`; const updateTests = process.argv[2] === "update"; - +/** + * @param {string} output + * @return {string} + */ function postProcessErrorOutput(output) { - output = output.trimRight(); - output = output.replace( + let result = output; + result = result.trimEnd(); + result = result.replace( /(?:[A-Z]:)?[\\/][^ ]+?tests[\\/]build_tests[\\/]super_errors[\\/]([^:]+)/g, - (_match, path, _offset, _string) => "/.../" + path.replace("\\", "/"), + (_match, path, _offset, _string) => `/.../${path.replace("\\", "/")}`, ); - return normalizeNewlines(output); + return normalizeNewlines(result); } let doneTasksCount = 0; let atLeastOneTaskFailed = false; -fixtures.forEach(fileName => { +for (const fileName of fixtures) { const fullFilePath = path.join(__dirname, "fixtures", fileName); const command = `${prefix} -color always ${fullFilePath}`; child_process.exec(command, (err, stdout, stderr) => { @@ -39,7 +42,7 @@ fixtures.forEach(fileName => { // - accidentally succeeding tests (not likely in this context), // actual, correctly erroring test case const actualErrorOutput = postProcessErrorOutput(stderr.toString()); - const expectedFilePath = path.join(expectedDir, fileName + ".expected"); + const expectedFilePath = path.join(expectedDir, `${fileName}.expected`); if (updateTests) { fs.writeFileSync(expectedFilePath, actualErrorOutput); } else { @@ -62,4 +65,4 @@ fixtures.forEach(fileName => { } } }); -}); +} diff --git a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json index 065cbb35b8..b4ae5013b5 100644 --- a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json +++ b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json @@ -18,6 +18,10 @@ "error": true }, "suffix": ".mjs", - "bs-dependencies": ["b"], - "pinned-dependencies": ["b"] + "bs-dependencies": [ + "b" + ], + "pinned-dependencies": [ + "b" + ] } diff --git a/tests/build_tests/transitive_pinned_dependency1/input.js b/tests/build_tests/transitive_pinned_dependency1/input.js index 565410ca01..e4d678770b 100644 --- a/tests/build_tests/transitive_pinned_dependency1/input.js +++ b/tests/build_tests/transitive_pinned_dependency1/input.js @@ -1,14 +1,15 @@ -//@ts-check -var child_process = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var { rescript_exe } = require("#cli/bin_path"); +// @ts-check + +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const { rescript_exe } = require("#cli/bin_path"); console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), ); -assert( +assert.ok( fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'", ); diff --git a/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json b/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json index 1bbb63d9e1..2fdd222a49 100644 --- a/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json @@ -1,27 +1,27 @@ { - "name": "b", - "namespace": true, - "sources": [ - { - "dir": "src" - }, - { - "dir": "tests", - "type": "dev" - } - ], - "package-specs": { - "module": "commonjs", - "in-source": false + "name": "b", + "namespace": true, + "sources": [ + { + "dir": "src" }, - "warnings": { - "error": true - }, - "suffix": ".mjs", - "bs-dependencies": [ - "c" - ], - "pinned-dependencies": [ - "c" - ] -} \ No newline at end of file + { + "dir": "tests", + "type": "dev" + } + ], + "package-specs": { + "module": "commonjs", + "in-source": false + }, + "warnings": { + "error": true + }, + "suffix": ".mjs", + "bs-dependencies": [ + "c" + ], + "pinned-dependencies": [ + "c" + ] +} diff --git a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json index c481bde6ef..b63b43209c 100644 --- a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json @@ -1,21 +1,21 @@ { - "name": "c", - "namespace": true, - "sources": [ - { - "dir": "src" - }, - { - "dir": "tests", - "type": "dev" - } - ], - "package-specs": { - "module": "commonjs", - "in-source": false + "name": "c", + "namespace": true, + "sources": [ + { + "dir": "src" }, - "warnings": { - "error": true - }, - "suffix": ".mjs" -} \ No newline at end of file + { + "dir": "tests", + "type": "dev" + } + ], + "package-specs": { + "module": "commonjs", + "in-source": false + }, + "warnings": { + "error": true + }, + "suffix": ".mjs" +} diff --git a/tests/build_tests/transitive_pinned_dependency2/input.js b/tests/build_tests/transitive_pinned_dependency2/input.js index aa9c501afc..879e701f81 100644 --- a/tests/build_tests/transitive_pinned_dependency2/input.js +++ b/tests/build_tests/transitive_pinned_dependency2/input.js @@ -1,8 +1,8 @@ //@ts-check -var child_process = require("child_process"); -var assert = require("assert"); -var fs = require("fs"); -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const { rescript_exe } = require("#cli/bin_path"); console.log( child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), diff --git a/tests/build_tests/transitive_pinned_dependency2/node_modules/b/bsconfig.json b/tests/build_tests/transitive_pinned_dependency2/node_modules/b/bsconfig.json index 1bbb63d9e1..2fdd222a49 100644 --- a/tests/build_tests/transitive_pinned_dependency2/node_modules/b/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency2/node_modules/b/bsconfig.json @@ -1,27 +1,27 @@ { - "name": "b", - "namespace": true, - "sources": [ - { - "dir": "src" - }, - { - "dir": "tests", - "type": "dev" - } - ], - "package-specs": { - "module": "commonjs", - "in-source": false + "name": "b", + "namespace": true, + "sources": [ + { + "dir": "src" }, - "warnings": { - "error": true - }, - "suffix": ".mjs", - "bs-dependencies": [ - "c" - ], - "pinned-dependencies": [ - "c" - ] -} \ No newline at end of file + { + "dir": "tests", + "type": "dev" + } + ], + "package-specs": { + "module": "commonjs", + "in-source": false + }, + "warnings": { + "error": true + }, + "suffix": ".mjs", + "bs-dependencies": [ + "c" + ], + "pinned-dependencies": [ + "c" + ] +} diff --git a/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json b/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json index c481bde6ef..b63b43209c 100644 --- a/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json @@ -1,21 +1,21 @@ { - "name": "c", - "namespace": true, - "sources": [ - { - "dir": "src" - }, - { - "dir": "tests", - "type": "dev" - } - ], - "package-specs": { - "module": "commonjs", - "in-source": false + "name": "c", + "namespace": true, + "sources": [ + { + "dir": "src" }, - "warnings": { - "error": true - }, - "suffix": ".mjs" -} \ No newline at end of file + { + "dir": "tests", + "type": "dev" + } + ], + "package-specs": { + "module": "commonjs", + "in-source": false + }, + "warnings": { + "error": true + }, + "suffix": ".mjs" +} diff --git a/tests/build_tests/unboxed_bool_with_const/input.js b/tests/build_tests/unboxed_bool_with_const/input.js index 59b01f8273..3655efc803 100644 --- a/tests/build_tests/unboxed_bool_with_const/input.js +++ b/tests/build_tests/unboxed_bool_with_const/input.js @@ -1,11 +1,11 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var { normalizeNewlines } = require("../utils.js"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const { normalizeNewlines } = require("../utils.js"); -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/tests/build_tests/uncurried-always/input.js b/tests/build_tests/uncurried-always/input.js index a7370b0c2f..4d511dcd41 100644 --- a/tests/build_tests/uncurried-always/input.js +++ b/tests/build_tests/uncurried-always/input.js @@ -1,6 +1,6 @@ //@ts-check -const cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); cp.execSync(`${rescript_exe}`, { cwd: __dirname }); diff --git a/tests/build_tests/unicode/input.js b/tests/build_tests/unicode/input.js index 2e7443629b..585da6ae54 100644 --- a/tests/build_tests/unicode/input.js +++ b/tests/build_tests/unicode/input.js @@ -1,9 +1,10 @@ -//@ts-check -var child_process = require("child_process"); -var fs = require("fs"); -var path = require("path"); +// @ts-check -var { rescript_exe } = require("#cli/bin_path"); +const child_process = require("node:child_process"); +const fs = require("node:fs"); +const path = require("node:path"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); if (process.platform === "win32") { console.log("Skipping test on Windows"); @@ -12,9 +13,9 @@ if (process.platform === "win32") { console.log(child_process.execSync(rescript_exe, { encoding: "utf8" })); -var content = - "" + fs.readFileSync(path.join(__dirname, "lib", "bs", ".sourcedirs.json")); - -var assert = require("assert"); +const content = fs.readFileSync( + path.join(__dirname, "lib", "bs", ".sourcedirs.json"), + "utf-8", +); assert(JSON.parse(content).dirs.some(x => x.includes("📕annotation"))); diff --git a/tests/build_tests/utils.js b/tests/build_tests/utils.js index d0715e907f..06d0a49eef 100644 --- a/tests/build_tests/utils.js +++ b/tests/build_tests/utils.js @@ -1,4 +1,4 @@ -const child_process = require("child_process"); +const child_process = require("node:child_process"); const signals = { SIGINT: 2, @@ -53,7 +53,7 @@ async function exec(command, args, options) { * @param {string} s */ function normalizeNewlines(s) { - return s.replace(/\r\n/g, '\n'); + return s.replace(/\r\n/g, "\n"); } exports.exec = exec; diff --git a/tests/build_tests/warn_legacy_config/input.js b/tests/build_tests/warn_legacy_config/input.js index 6a273a047f..b37c60cc07 100644 --- a/tests/build_tests/warn_legacy_config/input.js +++ b/tests/build_tests/warn_legacy_config/input.js @@ -1,5 +1,5 @@ -const { spawnSync } = require("child_process"); -const assert = require("assert"); +const { spawnSync } = require("node:child_process"); +const assert = require("node:assert"); const { rescript_exe } = require("#cli/bin_path"); const output = spawnSync(rescript_exe, { encoding: "utf8" }); diff --git a/tests/build_tests/weird_deps/input.js b/tests/build_tests/weird_deps/input.js index d76198e96e..af2831c51a 100644 --- a/tests/build_tests/weird_deps/input.js +++ b/tests/build_tests/weird_deps/input.js @@ -1,11 +1,11 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var { normalizeNewlines } = require("../utils.js"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const { normalizeNewlines } = require("../utils.js"); -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/tests/build_tests/weird_devdeps/input.js b/tests/build_tests/weird_devdeps/input.js index 77d621f892..30c1639255 100644 --- a/tests/build_tests/weird_devdeps/input.js +++ b/tests/build_tests/weird_devdeps/input.js @@ -1,11 +1,11 @@ //@ts-check -var cp = require("child_process"); -var assert = require("assert"); -var os = require("os"); -var rescript_exe = require("#cli/bin_path").rescript_exe; +const cp = require("node:child_process"); +const assert = require("node:assert"); +const os = require("node:os"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { +const out = cp.spawnSync(rescript_exe, { cwd: __dirname, encoding: "utf8", }); diff --git a/tests/build_tests/weird_names/input.js b/tests/build_tests/weird_names/input.js index c8e27d5371..5e0d591d88 100644 --- a/tests/build_tests/weird_names/input.js +++ b/tests/build_tests/weird_names/input.js @@ -1,15 +1,15 @@ -var cp = require("child_process"); -var assert = require("assert"); -var path = require("path"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const path = require("node:path"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.stderr !== "") { assert.fail(out.stderr); } -let files = [ +const files = [ "_app.res", "[...params_max_3].res", "[...params].res", @@ -19,8 +19,8 @@ let files = [ "utils.test.res", ]; -for (let f of files) { - let { name } = path.parse(f); - let m = `./lib/js/src/${name}.js`; +for (const f of files) { + const { name } = path.parse(f); + const m = `./lib/js/src/${name}.js`; assert.deepEqual(require(m).a, 1); } diff --git a/tests/build_tests/weird_names_not_found_bug/input.js b/tests/build_tests/weird_names_not_found_bug/input.js index 3bb70620c5..8582cc0bde 100644 --- a/tests/build_tests/weird_names_not_found_bug/input.js +++ b/tests/build_tests/weird_names_not_found_bug/input.js @@ -1,8 +1,8 @@ -var cp = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); -var out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.stderr !== "") { assert.fail(out.stderr); } diff --git a/tests/build_tests/x-y/input.js b/tests/build_tests/x-y/input.js index 1b2ea568cb..6d8c53998c 100644 --- a/tests/build_tests/x-y/input.js +++ b/tests/build_tests/x-y/input.js @@ -1,4 +1,4 @@ -var p = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); p.execSync(rescript_exe); diff --git a/tests/build_tests/xpkg/input.js b/tests/build_tests/xpkg/input.js index d499746478..e68c3a87db 100644 --- a/tests/build_tests/xpkg/input.js +++ b/tests/build_tests/xpkg/input.js @@ -1,8 +1,8 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); try { - var output = p.spawnSync(`${rescript_exe} build -regen`, { + const output = p.spawnSync(`${rescript_exe} build -regen`, { shell: true, encoding: "utf8", }); diff --git a/tests/build_tests/zerocycle/input.js b/tests/build_tests/zerocycle/input.js index aa23bdbc08..cfa9e940d8 100644 --- a/tests/build_tests/zerocycle/input.js +++ b/tests/build_tests/zerocycle/input.js @@ -1,5 +1,5 @@ -var p = require("child_process"); -var assert = require("assert"); -var { rescript_exe } = require("#cli/bin_path"); -var out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); -assert(out.status == 0); +const p = require("node:child_process"); +const assert = require("node:assert"); +const { rescript_exe } = require("#cli/bin_path"); +const out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +assert(out.status === 0); diff --git a/tests/gentype_tests/typescript-react-example/biome.json b/tests/gentype_tests/typescript-react-example/biome.json index d9c8975046..0339ee3a61 100644 --- a/tests/gentype_tests/typescript-react-example/biome.json +++ b/tests/gentype_tests/typescript-react-example/biome.json @@ -2,10 +2,12 @@ "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", "extends": ["../../../biome.json"], "linter": { - "enabled": true, - "rules": { - "recommended": true - }, + "ignore": ["**/*.res.js", "**/*.gen.ts*"] + }, + "organizeImports": { + "ignore": ["**/*.res.js", "**/*.gen.ts*"] + }, + "formatter": { "ignore": ["**/*.res.js", "**/*.gen.ts*"] } } diff --git a/tests/gentype_tests/typescript-react-example/package.json b/tests/gentype_tests/typescript-react-example/package.json index aab9789432..d57e8313f9 100644 --- a/tests/gentype_tests/typescript-react-example/package.json +++ b/tests/gentype_tests/typescript-react-example/package.json @@ -6,7 +6,7 @@ "build": "rescript", "clean": "rescript clean", "typecheck": "tsc", - "lint": "biome check src" + "lint": "biome check --changed --no-errors-on-unmatched ." }, "dependencies": { "@rescript/react": "^0.13.1", diff --git a/tests/gentype_tests/typescript-react-example/src/index.tsx b/tests/gentype_tests/typescript-react-example/src/index.tsx index 1bdb73f6c2..a09c3e5ba5 100644 --- a/tests/gentype_tests/typescript-react-example/src/index.tsx +++ b/tests/gentype_tests/typescript-react-example/src/index.tsx @@ -4,13 +4,13 @@ import App from "./App"; import * as ImportJsValue from "./ImportJsValue.gen"; import * as Uncurried from "./Uncurried.gen"; import "./index.css"; +import * as DocStrings from "./Docstrings.gen"; +import Hooks from "./Hooks.gen"; import * as MyMath from "./MyMath"; -import * as Types from "./nested/Types.gen"; import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen"; import * as Records from "./Records.gen"; +import * as TestPromise from "./TestPromise.gen"; import * as Variants from "./Variants.gen"; -import Hooks from "./Hooks.gen"; -import * as DocStrings from "./Docstrings.gen"; import { printManyPayloads, printVariantWithPayload, @@ -19,7 +19,7 @@ import { testVariantWithPayloads, testWithPayload, } from "./VariantsWithPayload.gen"; -import * as TestPromise from "./TestPromise.gen"; +import * as Types from "./nested/Types.gen"; const consoleLog = console.log; diff --git a/tests/tests/rescript.json b/tests/tests/rescript.json index c7dfdd6f05..4a21d34945 100644 --- a/tests/tests/rescript.json +++ b/tests/tests/rescript.json @@ -15,4 +15,4 @@ "-w -3-6-26-27-29-30-32..40-44-45-52-60-9-106+104", "-warn-error A" ] -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index f83400749c..a592f20158 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,14 +9,18 @@ "strictNullChecks": true, "noImplicitAny": true, "noEmit": true, - "skipLibCheck": true, - "composite": true, - "incremental": true + "skipLibCheck": true }, - "include": ["./cli/*", "./scripts/*", "./package.json"], + "include": [ + "cli/*", + "lib/*", + "lib_dev/*", + "scripts/*", + "tests/**/input.js", + "package.json" + ], "exclude": [ - "node_modules", - "./jscomp/test/**/*", - "./jscomp/gentype_tests/**/*" + "*.res.js", + "*.res.mjs", ] } From 1026096bfdbeef0b9df4139a279f353896183c6e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 06:42:36 +0900 Subject: [PATCH 03/37] upgrade Biome --- biome.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/biome.json b/biome.json index 64460061c1..5a01540645 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "vcs": { "enabled": true, "clientKind": "git", diff --git a/package.json b/package.json index 4cc6665303..98189c91a4 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "#dev/*": "./lib_dev/*.js" }, "devDependencies": { - "@biomejs/biome": "1.8.3", + "@biomejs/biome": "1.9.4", "@types/node": "^20.14.9", "@types/semver": "^7.5.8", "mocha": "10.8.2", From 1f5941828ecbe954d49e93a2dcd14fdb5893f9f1 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 06:49:09 +0900 Subject: [PATCH 04/37] add lint rules --- biome.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/biome.json b/biome.json index 5a01540645..3d7f98a395 100644 --- a/biome.json +++ b/biome.json @@ -9,7 +9,13 @@ "linter": { "enabled": true, "rules": { - "recommended": true + "recommended": true, + "correctness": { + "useImportExtensions": "error", + "noUndeclaredDependencies": "error", + "noUnusedImports": "error", + "noUnusedVariables": "warn" + } } }, "organizeImports": { From 433dc2089af85a1a928df326627bc5ba9e4177a1 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 06:52:30 +0900 Subject: [PATCH 05/37] fix artifact action --- .github/workflows/get_artifact_dir_name.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index 7d15b8e8dc..2b64276c37 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,10 +1,10 @@ const fs = require("node:fs"); const os = require("node:os"); -const { dirName: artifactDirName } = require("../../cli/bin_path.js"); +const { platformDir } = require("#cli/bin_path"); // Pass artifactDirName to subsequent GitHub actions fs.appendFileSync( process.env.GITHUB_ENV, - `artifact_dir_name=${artifactDirName}${os.EOL}`, + `artifact_dir_name=${platformDir}${os.EOL}`, ); From b978b2a887576a512f2db1f6c16696c0a1e0f6b5 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 06:57:53 +0900 Subject: [PATCH 06/37] fix lint files --- biome.json | 1 - 1 file changed, 1 deletion(-) diff --git a/biome.json b/biome.json index 3d7f98a395..4d189a5b11 100644 --- a/biome.json +++ b/biome.json @@ -44,7 +44,6 @@ } }, "files": { - "include": ["tests/build_tests/**/node_modules/**"], "ignore": [ ".yarn/**", "tests/analysis_tests/**/src/**", From 2b4c0dad628e9fec557c4b67d16318e7725c2f08 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 07:00:50 +0900 Subject: [PATCH 07/37] auto-fix by Biome --- cli/rescript_arg.js | 2 +- cli/rescript_bsb.js | 16 ++++---- cli/rescript_format.js | 2 +- lib/minisocket.js | 4 +- .../playground-bundling/rollup.config.cjs | 2 +- scripts/cppo.js | 2 +- scripts/npmPack.js | 12 +++--- .../build_tests/build_warn_as_error/input.js | 2 +- tests/build_tests/cli_compile_status/input.js | 10 ++--- tests/build_tests/cli_help/input.js | 12 +++--- .../duplicated_symlinked_packages/input.js | 38 ++++++++++--------- tests/build_tests/gpr_978/input.js | 8 ++-- tests/build_tests/in_source/input.js | 2 +- tests/build_tests/react_ppx/input.js | 4 +- tests/build_tests/super_errors/input.js | 2 +- .../a/rescript.json | 8 +--- .../typescript-react-example/src/App.css | 8 +++- .../typescript-react-example/src/MyMath.ts | 2 +- .../typescript-react-example/src/index.tsx | 6 +-- tsconfig.json | 5 +-- 20 files changed, 72 insertions(+), 75 deletions(-) diff --git a/cli/rescript_arg.js b/cli/rescript_arg.js index 806ff2b612..c5d77185cb 100644 --- a/cli/rescript_arg.js +++ b/cli/rescript_arg.js @@ -15,7 +15,7 @@ class StringBuilder { } } -class ArgError extends Error { } +class ArgError extends Error {} /** * @param {string} s diff --git a/cli/rescript_bsb.js b/cli/rescript_bsb.js index 6065df1b69..2a8bfd8c93 100644 --- a/cli/rescript_bsb.js +++ b/cli/rescript_bsb.js @@ -32,7 +32,7 @@ function releaseBuild() { ownerProcess.kill("SIGHUP"); try { fs.rmSync(lockFileName); - } catch { } + } catch {} ownerProcess = null; } } @@ -147,7 +147,7 @@ function logFinishCompiling(code) { function logStartCompiling() { updateStartTime(); - let log = `>>>> Start compiling`; + let log = ">>>> Start compiling"; if (shouldColorize) { log = `\x1b[36m${log}\x1b[0m`; } @@ -210,7 +210,7 @@ function watch(args) { let watchers = []; const verbose = args.includes("-verbose"); - const dlog = verbose ? console.log : () => { }; + const dlog = verbose ? console.log : () => {}; const wsParamIndex = args.indexOf("-ws"); if (wsParamIndex > -1) { @@ -253,18 +253,18 @@ function watch(args) { function setUpWebSocket() { const _id = setInterval(notifyClients, 3000); createServer() - .on("upgrade", function(req, socket, upgradeHead) { + .on("upgrade", (req, socket, upgradeHead) => { dlog("connection opened"); - var ws = new WebSocket(req, socket, upgradeHead); - socket.on("error", function(err) { + const ws = new WebSocket(req, socket, upgradeHead); + socket.on("error", err => { dlog(`Socket Error ${err}`); }); wsClients.push(ws); }) - .on("error", function(err) { + .on("error", err => { // @ts-ignore if (err !== undefined && err.code === "EADDRINUSE") { - var error = shouldColorize ? `\x1b[1;31mERROR:\x1b[0m` : `ERROR:`; + const error = shouldColorize ? "\x1b[1;31mERROR:\x1b[0m" : "ERROR:"; console.error(`${error} The websocket port number ${webSocketPort} is in use. Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); } else { diff --git a/cli/rescript_format.js b/cli/rescript_format.js index d84b81908d..ebba253205 100644 --- a/cli/rescript_format.js +++ b/cli/rescript_format.js @@ -70,7 +70,7 @@ async function readStdin() { return Buffer.concat(chunks).toString("utf8"); } -const numThreads = os.cpus().length; +const _numThreads = os.cpus().length; /** * Splits an array into smaller chunks of a specified size. diff --git a/lib/minisocket.js b/lib/minisocket.js index 6bcb965aa4..af1cbe4759 100644 --- a/lib/minisocket.js +++ b/lib/minisocket.js @@ -72,14 +72,14 @@ function encodeMessage(opcode, payload) { const upgradeHeader = "HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: "; class MiniWebSocket { - constructor(req, socket, upgradeHead) { + constructor(req, socket, _upgradeHead) { this.socket = socket; this.closed = false; const key = hashWebSocketKey(req.headers["sec-websocket-key"]); // http://tools.ietf.org/html/rfc6455#section-4.2.2 socket.write(`${upgradeHeader + key}\r\n\r\n`); - socket.on("close", hadError => { + socket.on("close", _hadError => { if (!this.closed) { this.closed = true; } diff --git a/packages/playground-bundling/rollup.config.cjs b/packages/playground-bundling/rollup.config.cjs index 73675ebdce..5c7fd2ca02 100644 --- a/packages/playground-bundling/rollup.config.cjs +++ b/packages/playground-bundling/rollup.config.cjs @@ -1,7 +1,7 @@ const resolve = require("@rollup/plugin-node-resolve"); const { globSync } = require("glob"); -const path = require("path"); +const path = require("node:path"); const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", ".."); const LIB_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "lib"); diff --git a/scripts/cppo.js b/scripts/cppo.js index 2394e01538..ee93d79d57 100644 --- a/scripts/cppo.js +++ b/scripts/cppo.js @@ -1,6 +1,6 @@ // @ts-check -const { execFileSync } = require("child_process"); +const { execFileSync } = require("node:child_process"); [ ["belt_HashSetString.res", "hashset.res.cppo", "TYPE_STRING"], diff --git a/scripts/npmPack.js b/scripts/npmPack.js index 656c0c6514..ce33e06118 100755 --- a/scripts/npmPack.js +++ b/scripts/npmPack.js @@ -28,9 +28,9 @@ * @typedef {[PackOutputEntry]} PackOutput */ -const { spawnSync, execSync } = require("child_process"); -const path = require("path"); -const fs = require("fs"); +const { spawnSync, execSync } = require("node:child_process"); +const path = require("node:path"); +const fs = require("node:fs"); const mode = process.argv.includes("-updateArtifactList") ? "updateArtifactList" @@ -40,7 +40,7 @@ const rootPath = path.join(__dirname, ".."); const fileListPath = path.join(rootPath, "packages", "artifacts.txt"); const output = spawnSync( - "npm pack --json" + (mode === "updateArtifactList" ? " --dry-run" : ""), + `npm pack --json${mode === "updateArtifactList" ? " --dry-run" : ""}`, { cwd: rootPath, encoding: "utf8", @@ -77,8 +77,8 @@ function getFilesAddedByCI() { const files = ["ninja.COPYING"]; - for (let platform of platforms) { - for (let exe of exes) { + for (const platform of platforms) { + for (const exe of exes) { files.push(`${platform}/${exe}`); } } diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index 9e771b3e80..e4f551c2cc 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -47,7 +47,7 @@ if (!third_message) { assert.fail(o3.stdout); } -var cleanup = p.spawnSync(rescript_exe, ["clean"], { +const _cleanup = p.spawnSync(rescript_exe, ["clean"], { encoding: "utf8", cwd: __dirname, }); diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index f40ac99cea..29ff3f42ad 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -14,9 +14,7 @@ let out = child_process.spawnSync("node", [rescriptPath, "build"], { }); assert.match( normalizeNewlines(out.stdout), - new RegExp(`>>>> Start compiling -Dependency Finished ->>>> Finish compiling \\d+ mseconds`), + />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Shows compile time for `rescript` command @@ -26,9 +24,7 @@ out = child_process.spawnSync("node", [rescriptPath], { }); assert.match( normalizeNewlines(out.stdout), - new RegExp(`>>>> Start compiling -Dependency Finished ->>>> Finish compiling \\d+ mseconds`), + />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Doesn't show compile time for `rescript build -verbose` command @@ -42,6 +38,6 @@ out = child_process.spawnSync("node", [rescriptPath, "build", "-verbose"], { assert.match( normalizeNewlines(out.stdout), - /Package stack: test \nDependency Finished\n/, + /Package stack: test {2}\nDependency Finished\n/, ); assert.match(normalizeNewlines(out.stdout), /ninja.exe"? -C lib[\\/]bs ?\n/); diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index 687dbf66d4..e17322a71b 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -1,7 +1,7 @@ // @ts-check -const assert = require("assert"); -const path = require("path"); +const assert = require("node:assert"); +const path = require("node:path"); const { exec, normalizeNewlines } = require("../utils.js"); const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript"); @@ -103,7 +103,7 @@ async function test() { // Exits with build help with unknown arg await runTest(["build", "-foo"], { stdout: "", - stderr: 'Error: Unknown option "-foo".\n' + buildHelp, + stderr: `Error: Unknown option "-foo".\n${buildHelp}`, status: 2, }); @@ -119,14 +119,14 @@ async function test() { // Exits with cli help with unknown command await runTest(["built"], { stdout: "", - stderr: `Error: Unknown command "built".\n` + cliHelp, + stderr: `Error: Unknown command "built".\n${cliHelp}`, status: 2, }); // Exits with build help with unknown args await runTest(["-foo"], { stdout: "", - stderr: 'Error: Unknown option "-foo".\n' + buildHelp, + stderr: `Error: Unknown option "-foo".\n${buildHelp}`, status: 2, }); @@ -143,7 +143,7 @@ async function test() { // Exits with clean help with unknown arg await runTest(["clean", "-foo"], { stdout: "", - stderr: 'Error: Unknown option "-foo".\n' + cleanHelp, + stderr: `Error: Unknown option "-foo".\n${cleanHelp}`, status: 2, }); diff --git a/tests/build_tests/duplicated_symlinked_packages/input.js b/tests/build_tests/duplicated_symlinked_packages/input.js index 32e66f67be..aa3540f6b9 100644 --- a/tests/build_tests/duplicated_symlinked_packages/input.js +++ b/tests/build_tests/duplicated_symlinked_packages/input.js @@ -22,21 +22,25 @@ if (process.platform === "win32") { child_process.execSync(`${rescript_exe} clean`, { cwd: __dirname }); -child_process.exec(rescript_exe, { cwd: __dirname }, (err, stdout, stderr) => { - const actualErrorOutput = postProcessErrorOutput(stderr.toString()); - if (updateTests) { - fs.writeFileSync(expectedFilePath, actualErrorOutput); - } else { - const expectedErrorOutput = postProcessErrorOutput( - fs.readFileSync(expectedFilePath, { encoding: "utf-8" }), - ); - if (expectedErrorOutput !== actualErrorOutput) { - console.error(`The old and new error output aren't the same`); - console.error("\n=== Old:"); - console.error(expectedErrorOutput); - console.error("\n=== New:"); - console.error(actualErrorOutput); - process.exit(1); +child_process.exec( + rescript_exe, + { cwd: __dirname }, + (_err, _stdout, stderr) => { + const actualErrorOutput = postProcessErrorOutput(stderr.toString()); + if (updateTests) { + fs.writeFileSync(expectedFilePath, actualErrorOutput); + } else { + const expectedErrorOutput = postProcessErrorOutput( + fs.readFileSync(expectedFilePath, { encoding: "utf-8" }), + ); + if (expectedErrorOutput !== actualErrorOutput) { + console.error(`The old and new error output aren't the same`); + console.error("\n=== Old:"); + console.error(expectedErrorOutput); + console.error("\n=== New:"); + console.error(actualErrorOutput); + process.exit(1); + } } - } -}); + }, +); diff --git a/tests/build_tests/gpr_978/input.js b/tests/build_tests/gpr_978/input.js index 70c0949700..d2722f4200 100644 --- a/tests/build_tests/gpr_978/input.js +++ b/tests/build_tests/gpr_978/input.js @@ -1,8 +1,8 @@ //@ts-check -const cp = require("child_process"); -const assert = require("assert"); -const fs = require("fs"); -const path = require("path"); +const cp = require("node:child_process"); +const assert = require("node:assert"); +const fs = require("node:fs"); +const path = require("node:path"); const { rescript_exe } = require("#cli/bin_path"); const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js index d25402fbe9..4bb7090f3c 100644 --- a/tests/build_tests/in_source/input.js +++ b/tests/build_tests/in_source/input.js @@ -5,7 +5,7 @@ const { rescript_exe } = require("#cli/bin_path"); assert.throws( () => { - const output = child_process.execSync(`${rescript_exe} build -regen`, { + const _output = child_process.execSync(`${rescript_exe} build -regen`, { cwd: __dirname, encoding: "utf8", }); diff --git a/tests/build_tests/react_ppx/input.js b/tests/build_tests/react_ppx/input.js index 96e9ab8353..8cfd468c7a 100644 --- a/tests/build_tests/react_ppx/input.js +++ b/tests/build_tests/react_ppx/input.js @@ -1,5 +1,5 @@ //@ts-check -var cp = require("child_process"); -var { rescript_exe } = require("#cli/bin_path"); +const cp = require("node:child_process"); +const { rescript_exe } = require("#cli/bin_path"); cp.execSync(rescript_exe, { cwd: __dirname }); diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index 9702ed74f0..308cf43d77 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -35,7 +35,7 @@ let atLeastOneTaskFailed = false; for (const fileName of fixtures) { const fullFilePath = path.join(__dirname, "fixtures", fileName); const command = `${prefix} -color always ${fullFilePath}`; - child_process.exec(command, (err, stdout, stderr) => { + child_process.exec(command, (_err, _stdout, stderr) => { doneTasksCount++; // careful of: // - warning test that actually succeeded in compiling (warning's still in stderr, so the code path is shared here) diff --git a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json index b4ae5013b5..065cbb35b8 100644 --- a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json +++ b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json @@ -18,10 +18,6 @@ "error": true }, "suffix": ".mjs", - "bs-dependencies": [ - "b" - ], - "pinned-dependencies": [ - "b" - ] + "bs-dependencies": ["b"], + "pinned-dependencies": ["b"] } diff --git a/tests/gentype_tests/typescript-react-example/src/App.css b/tests/gentype_tests/typescript-react-example/src/App.css index c5c6e8a68a..31be39dcc4 100644 --- a/tests/gentype_tests/typescript-react-example/src/App.css +++ b/tests/gentype_tests/typescript-react-example/src/App.css @@ -23,6 +23,10 @@ } @keyframes App-logo-spin { - from { transform: rotate(0deg); } - to { transform: rotate(360deg); } + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } } diff --git a/tests/gentype_tests/typescript-react-example/src/MyMath.ts b/tests/gentype_tests/typescript-react-example/src/MyMath.ts index 8727646f29..9c4db39420 100644 --- a/tests/gentype_tests/typescript-react-example/src/MyMath.ts +++ b/tests/gentype_tests/typescript-react-example/src/MyMath.ts @@ -21,7 +21,7 @@ export class AbsoluteValue { export type stringFunction = (_: string) => string; -export const useColor = (x: "tomato" | "gray"): number => 0; +export const useColor = (_x: "tomato" | "gray"): number => 0; export const higherOrder = (foo: (_1: number, _2: number) => number) => foo(3, 4); diff --git a/tests/gentype_tests/typescript-react-example/src/index.tsx b/tests/gentype_tests/typescript-react-example/src/index.tsx index a09c3e5ba5..4b8e8bcfdb 100644 --- a/tests/gentype_tests/typescript-react-example/src/index.tsx +++ b/tests/gentype_tests/typescript-react-example/src/index.tsx @@ -1,12 +1,12 @@ import type * as React from "react"; import * as ReactDOM from "react-dom"; -import App from "./App"; +import App from "./App.tsx"; import * as ImportJsValue from "./ImportJsValue.gen"; import * as Uncurried from "./Uncurried.gen"; import "./index.css"; import * as DocStrings from "./Docstrings.gen"; import Hooks from "./Hooks.gen"; -import * as MyMath from "./MyMath"; +import * as MyMath from "./MyMath.tsx"; import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen"; import * as Records from "./Records.gen"; import * as TestPromise from "./TestPromise.gen"; @@ -126,7 +126,7 @@ type Props = { readonly method?: "push" | "replace"; }; -export const make: React.FC = (x: Props) => { +export const make: React.FC = (_x: Props) => { return
; }; diff --git a/tsconfig.json b/tsconfig.json index a592f20158..aa4d2adb17 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,8 +19,5 @@ "tests/**/input.js", "package.json" ], - "exclude": [ - "*.res.js", - "*.res.mjs", - ] + "exclude": ["*.res.js", "*.res.mjs"] } From 9b170f2eac855b9e25e098e85375a6ab561ecf5d Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 07:02:30 +0900 Subject: [PATCH 08/37] biome upgrade for gentype example --- .../typescript-react-example/biome.json | 2 +- .../typescript-react-example/package.json | 7 +- yarn.lock | 127 +++++++++--------- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/tests/gentype_tests/typescript-react-example/biome.json b/tests/gentype_tests/typescript-react-example/biome.json index 0339ee3a61..f89a93677e 100644 --- a/tests/gentype_tests/typescript-react-example/biome.json +++ b/tests/gentype_tests/typescript-react-example/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", "extends": ["../../../biome.json"], "linter": { "ignore": ["**/*.res.js", "**/*.gen.ts*"] diff --git a/tests/gentype_tests/typescript-react-example/package.json b/tests/gentype_tests/typescript-react-example/package.json index d57e8313f9..13a9cc3ad4 100644 --- a/tests/gentype_tests/typescript-react-example/package.json +++ b/tests/gentype_tests/typescript-react-example/package.json @@ -15,10 +15,9 @@ "rescript": "workspace:^" }, "devDependencies": { - "@biomejs/biome": "1.8.3", - "@types/node": "^18.15.12", - "@types/react": "^18.3.19", - "@types/react-dom": "^18.3.5", + "@biomejs/biome": "1.9.4", + "@types/react": "^18.3.3", + "@types/react-dom": "^18.3.0", "typescript": "5.5.3" } } diff --git a/yarn.lock b/yarn.lock index 25f255ed27..45581b1398 100644 --- a/yarn.lock +++ b/yarn.lock @@ -183,18 +183,18 @@ __metadata: languageName: node linkType: hard -"@biomejs/biome@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/biome@npm:1.8.3" - dependencies: - "@biomejs/cli-darwin-arm64": "npm:1.8.3" - "@biomejs/cli-darwin-x64": "npm:1.8.3" - "@biomejs/cli-linux-arm64": "npm:1.8.3" - "@biomejs/cli-linux-arm64-musl": "npm:1.8.3" - "@biomejs/cli-linux-x64": "npm:1.8.3" - "@biomejs/cli-linux-x64-musl": "npm:1.8.3" - "@biomejs/cli-win32-arm64": "npm:1.8.3" - "@biomejs/cli-win32-x64": "npm:1.8.3" +"@biomejs/biome@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/biome@npm:1.9.4" + dependencies: + "@biomejs/cli-darwin-arm64": "npm:1.9.4" + "@biomejs/cli-darwin-x64": "npm:1.9.4" + "@biomejs/cli-linux-arm64": "npm:1.9.4" + "@biomejs/cli-linux-arm64-musl": "npm:1.9.4" + "@biomejs/cli-linux-x64": "npm:1.9.4" + "@biomejs/cli-linux-x64-musl": "npm:1.9.4" + "@biomejs/cli-win32-arm64": "npm:1.9.4" + "@biomejs/cli-win32-x64": "npm:1.9.4" dependenciesMeta: "@biomejs/cli-darwin-arm64": optional: true @@ -214,62 +214,62 @@ __metadata: optional: true bin: biome: bin/biome - checksum: 10c0/95fe99ce82cd8242f1be51cbf3ac26043b253f5a369d3dc24df09bdb32ec04dba679b1d4fa8b9d602b1bf2c30ecd80af14aa8f5c92d6e0cd6214a99a1099a65b + checksum: 10c0/b5655c5aed9a6fffe24f7d04f15ba4444389d0e891c9ed9106fab7388ac9b4be63185852cc2a937b22940dac3e550b71032a4afd306925cfea436c33e5646b3e languageName: node linkType: hard -"@biomejs/cli-darwin-arm64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-darwin-arm64@npm:1.8.3" +"@biomejs/cli-darwin-arm64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-darwin-arm64@npm:1.9.4" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-darwin-x64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-darwin-x64@npm:1.8.3" +"@biomejs/cli-darwin-x64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-darwin-x64@npm:1.9.4" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@biomejs/cli-linux-arm64-musl@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-linux-arm64-musl@npm:1.8.3" +"@biomejs/cli-linux-arm64-musl@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-linux-arm64-musl@npm:1.9.4" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@biomejs/cli-linux-arm64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-linux-arm64@npm:1.8.3" +"@biomejs/cli-linux-arm64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-linux-arm64@npm:1.9.4" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@biomejs/cli-linux-x64-musl@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-linux-x64-musl@npm:1.8.3" +"@biomejs/cli-linux-x64-musl@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-linux-x64-musl@npm:1.9.4" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@biomejs/cli-linux-x64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-linux-x64@npm:1.8.3" +"@biomejs/cli-linux-x64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-linux-x64@npm:1.9.4" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@biomejs/cli-win32-arm64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-win32-arm64@npm:1.8.3" +"@biomejs/cli-win32-arm64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-win32-arm64@npm:1.9.4" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@biomejs/cli-win32-x64@npm:1.8.3": - version: 1.8.3 - resolution: "@biomejs/cli-win32-x64@npm:1.8.3" +"@biomejs/cli-win32-x64@npm:1.9.4": + version: 1.9.4 + resolution: "@biomejs/cli-win32-x64@npm:1.9.4" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -443,11 +443,10 @@ __metadata: version: 0.0.0-use.local resolution: "@tests/gentype-react-example@workspace:tests/gentype_tests/typescript-react-example" dependencies: - "@biomejs/biome": "npm:1.8.3" + "@biomejs/biome": "npm:1.9.4" "@rescript/react": "npm:^0.13.1" - "@types/node": "npm:^18.15.12" - "@types/react": "npm:^18.3.19" - "@types/react-dom": "npm:^18.3.5" + "@types/react": "npm:^18.3.3" + "@types/react-dom": "npm:^18.3.0" react: "npm:^18.3.1" react-dom: "npm:^18.3.1" rescript: "workspace:^" @@ -489,15 +488,6 @@ __metadata: languageName: unknown linkType: soft -"@types/node@npm:^18.15.12": - version: 18.19.81 - resolution: "@types/node@npm:18.19.81" - dependencies: - undici-types: "npm:~5.26.4" - checksum: 10c0/fb1ae8a741b1b902c9fb6640075704e64c0e47aff2920eab502186c2d0b6ee65204c3ec8dd8a45260702c5a8d1b5dba33e6552aa6128d3787c70b0475c7f808d - languageName: node - linkType: hard - "@types/node@npm:^20.14.9": version: 20.17.27 resolution: "@types/node@npm:20.17.27" @@ -514,7 +504,7 @@ __metadata: languageName: node linkType: hard -"@types/react-dom@npm:^18.3.5": +"@types/react-dom@npm:^18.3.0": version: 18.3.5 resolution: "@types/react-dom@npm:18.3.5" peerDependencies: @@ -523,13 +513,20 @@ __metadata: languageName: node linkType: hard -"@types/react@npm:^18.3.19": - version: 18.3.19 - resolution: "@types/react@npm:18.3.19" +"@types/react@npm:^18.3.3": + version: 18.3.20 + resolution: "@types/react@npm:18.3.20" dependencies: "@types/prop-types": "npm:*" csstype: "npm:^3.0.2" - checksum: 10c0/236bfe0c4748ada1a640f13573eca3e0fc7c9d847b442947adb352b0718d6d285357fd84c33336c8ffb8cbfabc0d58a43a647c7fd79857fecd61fb58ab6f7918 + checksum: 10c0/65fa867c91357e4c4c646945c8b99044360f8973cb7f928ec4de115fe3207827985d45be236e6fd6c092b09f631c2126ce835c137be30718419e143d73300d8f + languageName: node + linkType: hard + +"@types/semver@npm:^7.5.8": + version: 7.5.8 + resolution: "@types/semver@npm:7.5.8" + checksum: 10c0/8663ff927234d1c5fcc04b33062cb2b9fcfbe0f5f351ed26c4d1e1581657deebd506b41ff7fdf89e787e3d33ce05854bc01686379b89e9c49b564c4cfa988efa languageName: node linkType: hard @@ -2130,10 +2127,12 @@ __metadata: version: 0.0.0-use.local resolution: "rescript@workspace:." dependencies: - "@biomejs/biome": "npm:1.8.3" + "@biomejs/biome": "npm:1.9.4" "@types/node": "npm:^20.14.9" + "@types/semver": "npm:^7.5.8" mocha: "npm:10.8.2" nyc: "npm:15.0.0" + semver: "npm:7.6.2" typescript: "npm:5.5.3" bin: bsc: cli/bsc @@ -2203,6 +2202,15 @@ __metadata: languageName: node linkType: hard +"semver@npm:7.6.2": + version: 7.6.2 + resolution: "semver@npm:7.6.2" + bin: + semver: bin/semver.js + checksum: 10c0/97d3441e97ace8be4b1976433d1c32658f6afaff09f143e52c593bae7eef33de19e3e369c88bd985ce1042c6f441c80c6803078d1de2a9988080b66684cbb30c + languageName: node + linkType: hard + "semver@npm:^6.0.0, semver@npm:^6.3.0, semver@npm:^6.3.1": version: 6.3.1 resolution: "semver@npm:6.3.1" @@ -2481,13 +2489,6 @@ __metadata: languageName: node linkType: hard -"undici-types@npm:~5.26.4": - version: 5.26.5 - resolution: "undici-types@npm:5.26.5" - checksum: 10c0/bb673d7876c2d411b6eb6c560e0c571eef4a01c1c19925175d16e3a30c4c428181fb8d7ae802a261f283e4166a0ac435e2f505743aa9e45d893f9a3df017b501 - languageName: node - linkType: hard - "undici-types@npm:~6.19.2": version: 6.19.8 resolution: "undici-types@npm:6.19.8" From 3c883bd7017b587d4c7a2529216731995f042ed8 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 07:09:31 +0900 Subject: [PATCH 09/37] fix gentype test --- .../typescript-react-example/src/index.tsx | 20 +++++++++---------- .../typescript-react-example/tsconfig.json | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/gentype_tests/typescript-react-example/src/index.tsx b/tests/gentype_tests/typescript-react-example/src/index.tsx index 4b8e8bcfdb..1fdcd83b2c 100644 --- a/tests/gentype_tests/typescript-react-example/src/index.tsx +++ b/tests/gentype_tests/typescript-react-example/src/index.tsx @@ -1,16 +1,16 @@ import type * as React from "react"; import * as ReactDOM from "react-dom"; import App from "./App.tsx"; -import * as ImportJsValue from "./ImportJsValue.gen"; -import * as Uncurried from "./Uncurried.gen"; +import * as ImportJsValue from "./ImportJsValue.gen.tsx"; +import * as Uncurried from "./Uncurried.gen.tsx"; import "./index.css"; -import * as DocStrings from "./Docstrings.gen"; -import Hooks from "./Hooks.gen"; +import * as DocStrings from "./Docstrings.gen.tsx"; +import Hooks from "./Hooks.gen.tsx"; import * as MyMath from "./MyMath.tsx"; -import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen"; -import * as Records from "./Records.gen"; -import * as TestPromise from "./TestPromise.gen"; -import * as Variants from "./Variants.gen"; +import { Universe_Nested2_Nested3_nested3Value } from "./NestedModules.gen.tsx"; +import * as Records from "./Records.gen.tsx"; +import * as TestPromise from "./TestPromise.gen.tsx"; +import * as Variants from "./Variants.gen.tsx"; import { printManyPayloads, printVariantWithPayload, @@ -18,8 +18,8 @@ import { testManyPayloads, testVariantWithPayloads, testWithPayload, -} from "./VariantsWithPayload.gen"; -import * as Types from "./nested/Types.gen"; +} from "./VariantsWithPayload.gen.tsx"; +import * as Types from "./nested/Types.gen.tsx"; const consoleLog = console.log; diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.json b/tests/gentype_tests/typescript-react-example/tsconfig.json index d78ab7798e..fd40382a73 100644 --- a/tests/gentype_tests/typescript-react-example/tsconfig.json +++ b/tests/gentype_tests/typescript-react-example/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "target": "esnext", - "module": "esnext", - "moduleResolution": "node", - "lib": ["dom", "dom.iterable", "esnext"], + "module": "ESNext", + "moduleResolution": "Node", + "lib": ["DOM", "DOM.Iterable", "ESNext"], + "jsx": "react-jsx", "strict": true, "skipLibCheck": true, "allowJs": true, From faa6ee8a55a06b232c30f7e9739ff5dbf0a482f9 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 19 Mar 2025 07:15:14 +0900 Subject: [PATCH 10/37] fix artifact action --- .github/workflows/get_artifact_dir_name.js | 4 ++-- cli/bin_path.js | 1 + tsconfig.json | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index 2b64276c37..94274941e6 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,10 +1,10 @@ const fs = require("node:fs"); const os = require("node:os"); -const { platformDir } = require("#cli/bin_path"); +const { platformName } = require("#cli/bin_path"); // Pass artifactDirName to subsequent GitHub actions fs.appendFileSync( process.env.GITHUB_ENV, - `artifact_dir_name=${platformDir}${os.EOL}`, + `artifact_dir_name=${platformName}${os.EOL}`, ); diff --git a/cli/bin_path.js b/cli/bin_path.js index a728d1d5a0..e5d2e846bf 100644 --- a/cli/bin_path.js +++ b/cli/bin_path.js @@ -52,6 +52,7 @@ const rescript_editor_analysis_exe = path.join( */ const rewatch_exe = path.join(platformDir, "rewatch.exe"); +exports.platformName = platformName; exports.platformDir = platformDir; exports.bsc_exe = bsc_exe; exports.ninja_exe = ninja_exe; diff --git a/tsconfig.json b/tsconfig.json index aa4d2adb17..3778657f66 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,7 @@ "lib_dev/*", "scripts/*", "tests/**/input.js", + ".github/workflows/*.js", "package.json" ], "exclude": ["*.res.js", "*.res.mjs"] From 67339c30690bc68d9f63a9f9d714b82e7a51c8a0 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 14:42:08 +0900 Subject: [PATCH 11/37] Convert to ESM, with refactoring codebase --- .github/workflows/get_artifact_dir_name.js | 6 +- .github/workflows/prepare_package_upload.js | 7 +- Makefile | 2 +- biome.json | 4 + cli/{rescript_arg.js => _args.js} | 9 +- cli/{rescript_bsb.js => _bsb.js} | 28 +- cli/_paths.js | 37 +++ cli/bin_path.js | 62 ----- cli/{bsc => bsc.js} | 7 +- cli/{rescript-tools => rescript-tools.js} | 5 +- cli/{rescript => rescript.js} | 46 ++-- cli/rescript_dump.js | 53 ---- cli/rescript_format.js | 252 ----------------- cli/{rewatch => rewatch.js} | 6 +- lib/bstracing | 6 +- lib/es6/RescriptTools.js | 6 +- lib/js/RescriptTools.js | 6 +- lib/minisocket.js | 7 +- lib_dev/meta.js | 7 - lib_dev/paths.js | 55 ++-- lib_dev/process.js | 166 ++++++++++++ lib_dev/utils.js | 16 ++ package.json | 21 +- packages/playground-bundling/package.json | 1 + .../playground-bundling/rollup.config.cjs | 22 -- .../playground-bundling/rollup.config.mjs | 23 ++ .../scripts/generate_cmijs.js | 11 +- playground/playground_test.js | 7 +- runtime/RescriptTools.res | 2 +- scripts/buildNinjaBinary.js | 11 +- scripts/buildRuntime.sh | 4 +- scripts/copyExes.js | 10 +- scripts/cppo.js | 10 +- scripts/format.sh | 2 +- scripts/format_check.sh | 4 +- scripts/npmPack.js | 13 +- scripts/prebuilt.js | 10 +- scripts/setVersion.js | 6 +- scripts/test.js | 255 +++++++++--------- .../build_tests/build_warn_as_error/input.js | 27 +- tests/build_tests/case/input.js | 15 +- tests/build_tests/case2/input.js | 17 +- tests/build_tests/case3/input.js | 25 +- tests/build_tests/case3/rescript.json | 4 +- .../case3/src/{B01.bs.js => B01.res.js} | 0 .../case3/src/{B02.bs.js => B02.res.js} | 0 .../case3/src/{B03.bs.js => B03.res.js} | 0 .../case3/src/{B04.bs.js => B04.res.js} | 0 .../case3/src/{B05.bs.js => B05.res.js} | 0 .../case3/src/{a01.bs.js => a01.res.js} | 0 .../case3/src/{a02.bs.js => a02.res.js} | 0 .../case3/src/{a03.bs.js => a03.res.js} | 0 .../case3/src/{a04.bs.js => a04.res.js} | 0 .../case3/src/{a05.bs.js => a05.res.js} | 0 .../case3/src/{hello.bs.js => hello.res.js} | 7 +- tests/build_tests/cli_compile_status/input.js | 24 +- tests/build_tests/cli_help/input.js | 200 +++++++------- tests/build_tests/custom_namespace/input.js | 14 +- .../custom_namespace/rescript.json | 5 +- .../src/{demo.bs.js => demo.res.js} | 6 +- tests/build_tests/cycle/input.js | 24 +- tests/build_tests/cycle1/input.js | 25 +- .../deprecated-package-specs/input.js | 11 +- tests/build_tests/devonly/input.js | 10 +- .../a/node_modules/z/package.json | 16 +- .../z/{bsconfig.json => rescript.json} | 10 +- .../a/package.json | 13 +- .../a/{bsconfig.json => rescript.json} | 4 +- .../b/package.json | 13 +- .../b/{bsconfig.json => rescript.json} | 4 +- .../c/package.json | 18 +- .../c/{bsconfig.json => rescript.json} | 5 +- .../duplicated_symlinked_packages/input.js | 58 ++-- .../node_modules/z/package.json | 16 +- .../z/{bsconfig.json => rescript.json} | 7 +- tests/build_tests/exports/input.js | 12 +- tests/build_tests/gpr_978/input.js | 28 +- tests/build_tests/hyphen2/input.js | 9 +- tests/build_tests/in_source/input.js | 24 +- tests/build_tests/install/input.js | 39 ++- .../jsx_settings_inheritance/input.js | 10 +- tests/build_tests/nested/input.js | 33 ++- tests/build_tests/nested/rescript.json | 2 +- tests/build_tests/nnest/input.js | 37 +-- tests/build_tests/nnest/rescript.json | 2 +- tests/build_tests/ns/input.js | 9 +- tests/build_tests/post-build/input.js | 11 +- tests/build_tests/react_ppx/input.js | 10 +- tests/build_tests/rerror/input.js | 26 +- tests/build_tests/scoped_ppx/input.js | 27 +- .../node_modules/@hongbo/ppx1/package.json | 3 + .../node_modules/@hongbo/ppx1/test.js | 2 +- tests/build_tests/super_errors/input.js | 77 +++--- .../transitive_pinned_dependency1/input.js | 16 +- .../transitive_pinned_dependency2/input.js | 23 +- .../unboxed_bool_with_const/input.js | 16 +- tests/build_tests/uncurried-always/input.js | 12 +- tests/build_tests/unicode/input.js | 20 +- tests/build_tests/utils.js | 60 ----- tests/build_tests/warn_legacy_config/input.js | 18 +- tests/build_tests/weird_deps/input.js | 15 +- tests/build_tests/weird_deps/rescript.json | 4 +- tests/build_tests/weird_devdeps/input.js | 15 +- tests/build_tests/weird_devdeps/rescript.json | 4 +- tests/build_tests/weird_names/input.js | 17 +- tests/build_tests/weird_names/rescript.json | 3 + .../weird_names_not_found_bug/input.js | 10 +- .../weird_names_not_found_bug/rescript.json | 3 + tests/build_tests/x-y/input.js | 9 +- tests/build_tests/xpkg/input.js | 19 +- tests/build_tests/zerocycle/input.js | 13 +- tests/docstring_tests/DocTest.res | 2 +- tests/docstring_tests/DocTest.res.mjs | 20 +- tests/docstring_tests/Node.res | 12 +- tests/docstring_tests/SpawnAsync.res.mjs | 6 +- .../typescript-react-example/Makefile | 2 +- .../typescript-react-example/package.json | 2 +- tests/tests/src/tagged_template_lib.js | 4 +- tests/tools_tests/rescript.json | 2 +- .../src/expected/TestPpx.res.jsout | 117 -------- tools/rescript.json | 4 +- 121 files changed, 1079 insertions(+), 1513 deletions(-) rename cli/{rescript_arg.js => _args.js} (96%) rename cli/{rescript_bsb.js => _bsb.js} (96%) create mode 100644 cli/_paths.js delete mode 100644 cli/bin_path.js rename cli/{bsc => bsc.js} (50%) rename cli/{rescript-tools => rescript-tools.js} (54%) rename cli/{rescript => rescript.js} (74%) delete mode 100644 cli/rescript_dump.js delete mode 100644 cli/rescript_format.js rename cli/{rewatch => rewatch.js} (54%) delete mode 100644 lib_dev/meta.js create mode 100644 lib_dev/process.js create mode 100644 lib_dev/utils.js delete mode 100644 packages/playground-bundling/rollup.config.cjs create mode 100644 packages/playground-bundling/rollup.config.mjs rename tests/build_tests/case3/src/{B01.bs.js => B01.res.js} (100%) rename tests/build_tests/case3/src/{B02.bs.js => B02.res.js} (100%) rename tests/build_tests/case3/src/{B03.bs.js => B03.res.js} (100%) rename tests/build_tests/case3/src/{B04.bs.js => B04.res.js} (100%) rename tests/build_tests/case3/src/{B05.bs.js => B05.res.js} (100%) rename tests/build_tests/case3/src/{a01.bs.js => a01.res.js} (100%) rename tests/build_tests/case3/src/{a02.bs.js => a02.res.js} (100%) rename tests/build_tests/case3/src/{a03.bs.js => a03.res.js} (100%) rename tests/build_tests/case3/src/{a04.bs.js => a04.res.js} (100%) rename tests/build_tests/case3/src/{a05.bs.js => a05.res.js} (100%) rename tests/build_tests/case3/src/{hello.bs.js => hello.res.js} (66%) rename tests/build_tests/custom_namespace/src/{demo.bs.js => demo.res.js} (55%) rename tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/{bsconfig.json => rescript.json} (63%) rename tests/build_tests/duplicated_symlinked_packages/a/{bsconfig.json => rescript.json} (82%) rename tests/build_tests/duplicated_symlinked_packages/b/{bsconfig.json => rescript.json} (82%) rename tests/build_tests/duplicated_symlinked_packages/c/{bsconfig.json => rescript.json} (73%) rename tests/build_tests/duplicated_symlinked_packages/node_modules/z/{bsconfig.json => rescript.json} (74%) create mode 100644 tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json delete mode 100644 tests/build_tests/utils.js diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index 94274941e6..fc2348f311 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,7 +1,7 @@ -const fs = require("node:fs"); -const os = require("node:os"); +import * as fs from "node:fs"; +import * as os from "node:os"; -const { platformName } = require("#cli/bin_path"); +import { platformName } from "#cli/paths"; // Pass artifactDirName to subsequent GitHub actions fs.appendFileSync( diff --git a/.github/workflows/prepare_package_upload.js b/.github/workflows/prepare_package_upload.js index bbf4ef206c..2dc41b7e1f 100644 --- a/.github/workflows/prepare_package_upload.js +++ b/.github/workflows/prepare_package_upload.js @@ -1,8 +1,7 @@ -const fs = require("node:fs"); -const os = require("node:os"); +import * as fs from "node:fs"; +import * as os from "node:os"; -const packageSpec = require("rescript/package.json"); -const { version } = packageSpec; +import { version } from "rescript/package.json" with { type: "json" }; const commitHash = process.argv[2] || process.env.GITHUB_SHA; const commitHashShort = commitHash.substring(0, 7); diff --git a/Makefile b/Makefile index 0b54c0bfb8..67446c81d8 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ clean-rewatch: cargo clean --manifest-path rewatch/Cargo.toml && rm -f rewatch/rewatch clean: - (cd runtime && ../cli/rescript clean) + (cd runtime && ../cli/rescript.js clean) dune clean clean-all: clean clean-gentype clean-rewatch diff --git a/biome.json b/biome.json index 4d189a5b11..29c14d9d4c 100644 --- a/biome.json +++ b/biome.json @@ -10,6 +10,9 @@ "enabled": true, "rules": { "recommended": true, + "nursery": { + "noCommonJs": "error" + }, "correctness": { "useImportExtensions": "error", "noUndeclaredDependencies": "error", @@ -49,6 +52,7 @@ "tests/analysis_tests/**/src/**", "tests/build_tests/**/src/**", "tests/docstring_tests/**", + "tests/gentype_tests/**", "tests/tests/**/src/**", "tests/tools_tests/**/src/**", "analysis/examples/**/src/**", diff --git a/cli/rescript_arg.js b/cli/_args.js similarity index 96% rename from cli/rescript_arg.js rename to cli/_args.js index c5d77185cb..471a6430d5 100644 --- a/cli/rescript_arg.js +++ b/cli/_args.js @@ -15,12 +15,12 @@ class StringBuilder { } } -class ArgError extends Error {} +export class ArgError extends Error {} /** * @param {string} s */ -function bad_arg(s) { +export function bad_arg(s) { throw new ArgError(s); } @@ -118,7 +118,7 @@ function stop_raise(usage, error, specs) { * @param {number} start * @param {number} finish */ -function parse_exn( +export function parse_exn( usage, argv, specs, @@ -174,6 +174,3 @@ function parse_exn( } annofun(list); } -exports.bad_arg = bad_arg; -exports.parse_exn = parse_exn; -exports.ArgError = ArgError; diff --git a/cli/rescript_bsb.js b/cli/_bsb.js similarity index 96% rename from cli/rescript_bsb.js rename to cli/_bsb.js index 2a8bfd8c93..9b378e6ba3 100644 --- a/cli/rescript_bsb.js +++ b/cli/_bsb.js @@ -1,12 +1,13 @@ // @ts-check -const fs = require("node:fs"); -const path = require("node:path"); -const os = require("node:os"); -const child_process = require("node:child_process"); -const { createServer } = require("node:http"); -const { MiniWebSocket: WebSocket } = require("#lib/minisocket"); -const { rescript_exe } = require("#cli/bin_path"); +import * as child_process from "node:child_process"; +import * as fs from "node:fs"; +import { createServer } from "node:http"; +import * as os from "node:os"; +import * as path from "node:path"; +import { WebSocket } from "#lib/minisocket"; + +import { rescript_exe } from "./_paths.js"; const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); @@ -27,7 +28,7 @@ const lockFileName = path.join(cwd, ".bsb.lock"); * @type {child_process.ChildProcess | null} */ let ownerProcess = null; -function releaseBuild() { +export function releaseBuild() { if (ownerProcess) { ownerProcess.kill("SIGHUP"); try { @@ -100,14 +101,14 @@ function delegate(args, maybeOnClose) { /** * @param {Array} args */ -function info(args) { +export function info(args) { delegate(["info", ...args]); } /** * @param {Array} args */ -function clean(args) { +export function clean(args) { delegate(["clean", ...args]); } @@ -475,7 +476,7 @@ Please pick a different one using the \`-ws [host:]port\` flag from bsb.`); /** * @param {Array} args */ -function build(args) { +export function build(args) { // We want to show the compile time for build // But bsb might show a help message when --help or invalid arguments are passed // We don't want to show the compile time in that case @@ -499,8 +500,3 @@ function build(args) { } delegate(["build", ...args]); } - -exports.releaseBuild = releaseBuild; -exports.info = info; -exports.clean = clean; -exports.build = build; diff --git a/cli/_paths.js b/cli/_paths.js new file mode 100644 index 0000000000..4e7d2b2640 --- /dev/null +++ b/cli/_paths.js @@ -0,0 +1,37 @@ +// @ts-check + +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +export const cliPath = path.join(__dirname, "rescript.js"); + +/** + * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. + * So we'll have "darwin", "linux" and "win32" for x64 arch, + * but "darwinarm64" and "linuxarm64" for arm64 arch. + * Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM. + * So omit the architecture for Windows, too. + */ +export const platformName = + process.arch === "x64" || process.platform === "win32" + ? process.platform + : process.platform + process.arch; + +export const platformDir = path.resolve(__dirname, "..", platformName); + +export const bsc_exe = path.join(platformDir, "bsc.exe"); + +export const ninja_exe = path.join(platformDir, "ninja.exe"); + +export const rescript_exe = path.join(platformDir, "rescript.exe"); + +export const rescript_tools_exe = path.join(platformDir, "rescript-tools.exe"); + +export const rescript_editor_analysis_exe = path.join( + platformDir, + "rescript-editor-analysis.exe", +); + +export const rewatch_exe = path.join(platformDir, "rewatch.exe"); diff --git a/cli/bin_path.js b/cli/bin_path.js deleted file mode 100644 index e5d2e846bf..0000000000 --- a/cli/bin_path.js +++ /dev/null @@ -1,62 +0,0 @@ -// @ts-check - -const path = require("node:path"); - -/** - * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. - * So we'll have "darwin", "linux" and "win32" for x64 arch, - * but "darwinarm64" and "linuxarm64" for arm64 arch. - * Also, we do not have Windows ARM binaries yet. But the x64 binaries do work on Windows 11 ARM. - * So omit the architecture for Windows, too. - */ -const platformName = - process.arch === "x64" || process.platform === "win32" - ? process.platform - : process.platform + process.arch; - -/** - * @type {string} - */ -const platformDir = path.resolve(__dirname, "..", platformName); - -/** - * @type {string} - */ -const bsc_exe = path.join(platformDir, "bsc.exe"); - -/** - * @type {string} - */ -const ninja_exe = path.join(platformDir, "ninja.exe"); - -/** - * @type {string} - */ -const rescript_exe = path.join(platformDir, "rescript.exe"); - -/** - * @type {string} - */ -const rescript_tools_exe = path.join(platformDir, "rescript-tools.exe"); - -/** - * @type {string} - */ -const rescript_editor_analysis_exe = path.join( - platformDir, - "rescript-editor-analysis.exe", -); - -/** - * @type {string} - */ -const rewatch_exe = path.join(platformDir, "rewatch.exe"); - -exports.platformName = platformName; -exports.platformDir = platformDir; -exports.bsc_exe = bsc_exe; -exports.ninja_exe = ninja_exe; -exports.rescript_exe = rescript_exe; -exports.rescript_tools_exe = rescript_tools_exe; -exports.rescript_editor_analysis_exe = rescript_editor_analysis_exe; -exports.rewatch_exe = rewatch_exe; diff --git a/cli/bsc b/cli/bsc.js similarity index 50% rename from cli/bsc rename to cli/bsc.js index 556697d2df..144fae71c7 100755 --- a/cli/bsc +++ b/cli/bsc.js @@ -2,15 +2,14 @@ // @ts-check -"use strict"; +import { execFileSync } from "node:child_process"; -const child_process = require("child_process"); -const { bsc_exe } = require("./bin_path.js"); +import { bsc_exe } from "./_paths.js"; const delegate_args = process.argv.slice(2); try { - child_process.execFileSync(bsc_exe, delegate_args, { stdio: "inherit" }); + execFileSync(bsc_exe, delegate_args, { stdio: "inherit" }); } catch (e) { if (e.code === "ENOENT") { console.error(String(e)); diff --git a/cli/rescript-tools b/cli/rescript-tools.js similarity index 54% rename from cli/rescript-tools rename to cli/rescript-tools.js index 0451351388..dd605df610 100755 --- a/cli/rescript-tools +++ b/cli/rescript-tools.js @@ -2,10 +2,9 @@ // @ts-check -"use strict"; +import * as child_process from "node:child_process"; -const child_process = require("node:child_process"); -const { rescript_tools_exe } = require("./bin_path.js"); +import { rescript_tools_exe } from "./_paths.js"; const args = process.argv.slice(2); diff --git a/cli/rescript b/cli/rescript.js similarity index 74% rename from cli/rescript rename to cli/rescript.js index b434d4c6e9..54ae2278dc 100755 --- a/cli/rescript +++ b/cli/rescript.js @@ -2,15 +2,15 @@ //@ts-check -"use strict"; - // This script is supposed to be running in project root directory // It matters since we need read .sourcedirs(location) // and its content are file/directories with regard to project root -const tty = require("node:tty"); -const { bsc_exe, rescript_exe } = require("./bin_path.js"); -const bsb = require("./rescript_bsb.js"); +import * as tty from "node:tty"; +import packageJson from "rescript/package.json" with { type: "json" }; + +import * as bsb from "./_bsb.js"; +import { bsc_exe, rescript_exe } from "./_paths.js"; const cwd = process.cwd(); process.env.BSB_PROJECT_ROOT = cwd; @@ -21,7 +21,10 @@ if (process.env.FORCE_COLOR === undefined) { process.env.NINJA_ANSI_FORCED = "1"; } } else { - if (process.env.FORCE_COLOR === "1" && process.env.NINJA_ANSI_FORCED === undefined) { + if ( + process.env.FORCE_COLOR === "1" && + process.env.NINJA_ANSI_FORCED === undefined + ) { process.env.NINJA_ANSI_FORCED = "1"; } if (process.argv.includes("-verbose")) { @@ -77,19 +80,20 @@ try { const args = process.argv.slice(2); const argPatterns = { - help: ['help', '-h', '-help', '--help'], - version: ['version', '-v', '-version', '--version'], + help: ["help", "-h", "-help", "--help"], + version: ["version", "-v", "-version", "--version"], }; const helpArgIndex = args.findIndex(arg => argPatterns.help.includes(arg)); const firstPositionalArgIndex = args.findIndex(arg => !arg.startsWith("-")); -if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex)) { +if ( + helpArgIndex !== -1 && + (firstPositionalArgIndex === -1 || helpArgIndex <= firstPositionalArgIndex) +) { console.log(helpMessage); - } else if (argPatterns.version.includes(args[0])) { - console.log(require("../package.json").version); - + console.log(packageJson.version); } else if (firstPositionalArgIndex !== -1) { const subcmd = args[firstPositionalArgIndex]; const subcmdArgs = args.slice(firstPositionalArgIndex + 1); @@ -108,25 +112,17 @@ if (helpArgIndex !== -1 && (firstPositionalArgIndex === -1 || helpArgIndex <= fi break; } case "format": { - require("./rescript_format.js").main( - subcmdArgs, - rescript_exe, - bsc_exe - ); + const mod = await import("./rescript/rescript_format.js"); + await mod.main(subcmdArgs, rescript_exe, bsc_exe); break; } case "dump": { - require("./rescript_dump.js").main( - subcmdArgs, - rescript_exe, - bsc_exe - ); + const mod = await import("./rescript/rescript_dump.js"); + mod.main(subcmdArgs, rescript_exe, bsc_exe); break; } default: { - console.error( - `Error: Unknown command "${subcmd}".\n${helpMessage}` - ); + console.error(`Error: Unknown command "${subcmd}".\n${helpMessage}`); process.exit(2); } } diff --git a/cli/rescript_dump.js b/cli/rescript_dump.js deleted file mode 100644 index 5bf717f175..0000000000 --- a/cli/rescript_dump.js +++ /dev/null @@ -1,53 +0,0 @@ -// @ts-check - -const arg = require("./rescript_arg.js"); -const dump_usage = `Usage: rescript dump [target] -\`rescript dump\` dumps the information for the target -`; -const child_process = require("node:child_process"); -const path = require("node:path"); - -/** - * @type {arg.specs} - */ -const specs = []; - -/** - * @param {string[]} argv - * @param {string} rescript_exe - * @param {string} bsc_exe - */ -function main(argv, rescript_exe, bsc_exe) { - let target; - arg.parse_exn(dump_usage, argv, specs, xs => { - if (xs.length !== 1) { - arg.bad_arg(`Expect only one target, ${xs.length} found`); - } - target = xs[0]; - }); - - const { ext } = path.parse(target); - if (ext !== ".cmi") { - console.error("Only .cmi target allowed"); - process.exit(2); - } - - let output = child_process.spawnSync(rescript_exe, ["build", "--", target], { - encoding: "utf-8", - }); - if (output.status !== 0) { - console.log(output.stdout); - console.error(output.stderr); - process.exit(2); - } - output = child_process.spawnSync(bsc_exe, [path.join("lib", "bs", target)], { - encoding: "utf-8", - }); - console.log(output.stdout.trimEnd()); - if (output.status !== 0) { - console.error(output.stderr); - process.exit(2); - } -} - -exports.main = main; diff --git a/cli/rescript_format.js b/cli/rescript_format.js deleted file mode 100644 index ebba253205..0000000000 --- a/cli/rescript_format.js +++ /dev/null @@ -1,252 +0,0 @@ -//@ts-check -const os = require("node:os"); -const arg = require("./rescript_arg.js"); - -const format_usage = `Usage: rescript format [files] - -\`rescript format\` formats the current directory -`; -const child_process = require("node:child_process"); -const util = require("node:util"); -const asyncExecFile = util.promisify(child_process.execFile); -const path = require("node:path"); -const fs = require("node:fs"); -const asyncFs = fs.promises; - -/** - * @type {arg.stringref} - */ -const stdin = { val: "" }; - -/** - * @type {arg.boolref} - */ -const format = { val: false }; - -/** - * @type {arg.boolref} - */ -const check = { val: false }; - -/** - * @type{arg.specs} - */ -const specs = [ - [ - "-stdin", - { kind: "String", data: { kind: "String_set", data: stdin } }, - `[.res|.resi] Read the code from stdin and print -the formatted code to stdout in ReScript syntax`, - ], - [ - "-all", - { kind: "Unit", data: { kind: "Unit_set", data: format } }, - "Format the whole project ", - ], - [ - "-check", - { kind: "Unit", data: { kind: "Unit_set", data: check } }, - "Check formatting for file or the whole project. Use `-all` to check the whole project", - ], -]; -const formattedStdExtensions = [".res", ".resi"]; -const formattedFileExtensions = [".res", ".resi"]; - -/** - * - * @param {string[]} extensions - */ -function hasExtension(extensions) { - /** - * @param {string} x - */ - const pred = x => extensions.some(ext => x.endsWith(ext)); - return pred; -} -async function readStdin() { - const stream = process.stdin; - const chunks = []; - for await (const chunk of stream) chunks.push(chunk); - return Buffer.concat(chunks).toString("utf8"); -} - -const _numThreads = os.cpus().length; - -/** - * Splits an array into smaller chunks of a specified size. - * - * @template T - * @param {T[]} array - The array to split into chunks. - * @param {number} chunkSize - The size of each chunk. - * @returns {T[][]} - An array of chunks, where each chunk is an array of type T. - */ -function chunkArray(array, chunkSize) { - /** @type {T[][]} */ - const result = []; - - for (let i = 0; i < array.length; i += chunkSize) { - result.push(array.slice(i, i + chunkSize)); - } - - return result; -} - -/** - * @param {string[]} files - * @param {string} bsc_exe - * @param {(x: string) => boolean} isSupportedFile - * @param {boolean} checkFormatting - */ -async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { - const supportedFiles = files.filter(isSupportedFile); - const batchSize = 4 * os.cpus().length; - const batches = chunkArray(supportedFiles, batchSize); - - let incorrectlyFormattedFiles = 0; - try { - for (const batch of batches) { - await Promise.all( - batch.map(async file => { - const flags = checkFormatting - ? ["-format", file] - : ["-o", file, "-format", file]; - const { stdout } = await asyncExecFile(bsc_exe, flags); - if (check.val) { - const original = await asyncFs.readFile(file, "utf-8"); - if (original !== stdout) { - console.error("[format check]", file); - incorrectlyFormattedFiles++; - } - } - }), - ); - } - } catch (err) { - console.error(err); - process.exit(2); - } - if (incorrectlyFormattedFiles > 0) { - if (incorrectlyFormattedFiles === 1) { - console.error("The file listed above needs formatting"); - } else { - console.error( - `The ${incorrectlyFormattedFiles} files listed above need formatting`, - ); - } - process.exit(3); - } -} - -/** - * @param {string[]} argv - * @param {string} rescript_exe - * @param {string} bsc_exe - */ -async function main(argv, rescript_exe, bsc_exe) { - const isSupportedFile = hasExtension(formattedFileExtensions); - const isSupportedStd = hasExtension(formattedStdExtensions); - - try { - /** - * @type {string[]} - */ - let files = []; - arg.parse_exn(format_usage, argv, specs, xs => { - files = xs; - }); - - const format_project = format.val; - const use_stdin = stdin.val; - - // Only -check arg - // Require: -all or path to a file - if (check.val && !format_project && files.length === 0) { - console.error( - "format check require path to a file or use `-all` to check the whole project", - ); - process.exit(2); - } - - if (format_project) { - if (use_stdin || files.length !== 0) { - console.error("format -all can not be in use with other flags"); - process.exit(2); - } - // -all - // TODO: check the rest arguments - const output = child_process.spawnSync( - rescript_exe, - ["info", "-list-files"], - { - encoding: "utf-8", - }, - ); - if (output.status !== 0) { - console.error(output.stdout); - console.error(output.stderr); - process.exit(2); - } - files = output.stdout.split("\n").map(x => x.trim()); - await formatFiles(files, bsc_exe, isSupportedFile, check.val); - } else if (use_stdin) { - if (check.val) { - console.error("format -stdin cannot be used with -check flag"); - process.exit(2); - } - if (isSupportedStd(use_stdin)) { - const crypto = require("node:crypto"); - const os = require("node:os"); - const filename = path.join( - os.tmpdir(), - `rescript_${crypto.randomBytes(8).toString("hex")}${path.parse(use_stdin).base}`, - ); - (async () => { - const content = await readStdin(); - const fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file - fs.writeFileSync(fd, content, "utf8"); - fs.closeSync(fd); - process.addListener("exit", () => fs.unlinkSync(filename)); - child_process.execFile( - bsc_exe, - ["-format", filename], - (error, stdout, stderr) => { - if (error === null) { - process.stdout.write(stdout); - } else { - console.error(stderr); - process.exit(2); - } - }, - ); - })(); - } else { - console.error(`Unsupported extension ${use_stdin}`); - console.error(`Supported extensions: ${formattedStdExtensions} `); - process.exit(2); - } - } else { - if (files.length === 0) { - // none of argumets set - // format the current directory - files = fs.readdirSync(process.cwd()).filter(isSupportedFile); - } - - for (const file of files) { - if (!isSupportedStd(file)) { - console.error(`Don't know what do with ${file}`); - console.error(`Supported extensions: ${formattedFileExtensions}`); - process.exit(2); - } - } - await formatFiles(files, bsc_exe, isSupportedFile, check.val); - } - } catch (e) { - if (e instanceof arg.ArgError) { - console.error(e.message); - process.exit(2); - } else { - throw e; - } - } -} -exports.main = main; diff --git a/cli/rewatch b/cli/rewatch.js similarity index 54% rename from cli/rewatch rename to cli/rewatch.js index b1a0817447..12d87fe662 100755 --- a/cli/rewatch +++ b/cli/rewatch.js @@ -2,10 +2,8 @@ // @ts-check -"use strict"; - -const child_process = require("node:child_process"); -const { rewatch_exe } = require("./bin_path.js"); +import * as child_process from "node:child_process"; +import { rewatch_exe } from "./bin_path.js"; const args = process.argv.slice(2); diff --git a/lib/bstracing b/lib/bstracing index 55012b5aa6..ad45f72c11 100755 --- a/lib/bstracing +++ b/lib/bstracing @@ -2,9 +2,9 @@ // @ts-check -const fs = require("node:fs"); -const readline = require("node:readline"); -const path = require("node:path"); +import * as fs from "node:fs"; +import * as readline from "node:readline"; +import * as path from "node:path"; /** * diff --git a/lib/es6/RescriptTools.js b/lib/es6/RescriptTools.js index 68a040855e..84f6ade54b 100644 --- a/lib/es6/RescriptTools.js +++ b/lib/es6/RescriptTools.js @@ -1,13 +1,9 @@ -import * as Bin_pathJs from "../../cli/bin_path.js"; - -let binaryPath = Bin_pathJs.rescript_tools_exe; let Docgen; export { Docgen, - binaryPath, } -/* binaryPath Not a pure module */ +/* No side effect */ diff --git a/lib/js/RescriptTools.js b/lib/js/RescriptTools.js index cefe75eb6f..064bdaddf4 100644 --- a/lib/js/RescriptTools.js +++ b/lib/js/RescriptTools.js @@ -1,11 +1,7 @@ 'use strict'; -let Bin_pathJs = require("../../cli/bin_path.js"); - -let binaryPath = Bin_pathJs.rescript_tools_exe; let Docgen; exports.Docgen = Docgen; -exports.binaryPath = binaryPath; -/* binaryPath Not a pure module */ +/* No side effect */ diff --git a/lib/minisocket.js b/lib/minisocket.js index af1cbe4759..45c9ca0676 100644 --- a/lib/minisocket.js +++ b/lib/minisocket.js @@ -1,4 +1,5 @@ -const crypto = require("node:crypto"); +import * as crypto from "node:crypto"; + const KEY_SUFFIX = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; function hashWebSocketKey(key) { @@ -71,7 +72,8 @@ function encodeMessage(opcode, payload) { const upgradeHeader = "HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nsec-websocket-accept: "; -class MiniWebSocket { + +export class WebSocket { constructor(req, socket, _upgradeHead) { this.socket = socket; this.closed = false; @@ -89,4 +91,3 @@ class MiniWebSocket { this.socket.write(encodeMessage(opcodes.TEXT, Buffer.from(obj, "utf8"))); } } -exports.MiniWebSocket = MiniWebSocket; diff --git a/lib_dev/meta.js b/lib_dev/meta.js deleted file mode 100644 index a21af58dcf..0000000000 --- a/lib_dev/meta.js +++ /dev/null @@ -1,7 +0,0 @@ -// @ts-check - -const packageJson = require("rescript/package.json"); - -module.exports = { - packageJson, -}; diff --git a/lib_dev/paths.js b/lib_dev/paths.js index 1807147978..dafc2a2e0a 100644 --- a/lib_dev/paths.js +++ b/lib_dev/paths.js @@ -1,66 +1,69 @@ // @ts-check -const path = require("node:path"); +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * The project root path */ -const projectDir = path.resolve(__dirname, ".."); +export const projectDir = path.resolve(__dirname, ".."); /** * path: `/compiler/` */ -const compilerRootDir = path.resolve(projectDir, "compiler"); +export const compilerRootDir = path.resolve(projectDir, "compiler"); /** * path: `/runtime/` */ -const runtimeDir = path.resolve(projectDir, "runtime"); +export const runtimeDir = path.resolve(projectDir, "runtime"); /** * path: `/lib/js/` */ -const runtimeCjsOutputDir = path.resolve(projectDir, "lib", "js"); +export const runtimeCjsOutputDir = path.resolve(projectDir, "lib", "js"); /** * path: `/lib/es6/` */ -const runtimeEsmOutputDir = path.resolve(projectDir, "lib", "es6"); +export const runtimeEsmOutputDir = path.resolve(projectDir, "lib", "es6"); /** * path: `/rewatch/` */ -const rewatchDir = path.resolve(projectDir, "rewatch"); +export const rewatchDir = path.resolve(projectDir, "rewatch"); /** * path: `/ninja/` */ -const ninjaDir = path.resolve(projectDir, "ninja"); +export const ninjaDir = path.resolve(projectDir, "ninja"); /** * path: `/tests/` */ -const testDir = path.resolve(projectDir, "tests"); +export const testDir = path.resolve(projectDir, "tests"); /** * path: `/tests/tests/` */ -const compilerTestDir = path.resolve(testDir, "tests"); +export const compilerTestDir = path.resolve(testDir, "tests"); /** * path: `/tests/build_tests/` */ -const buildTestDir = path.resolve(testDir, "build_tests"); +export const buildTestDir = path.resolve(testDir, "build_tests"); /** * path: `/tests/docstring_tests/` */ -const docstringTestDir = path.resolve(testDir, "docstring_tests"); +export const docstringTestDir = path.resolve(testDir, "docstring_tests"); /** * path: `/compiler/common/bs_version.ml` */ -const compilerVersionFile = path.resolve( +export const compilerVersionFile = path.resolve( compilerRootDir, "common", "bs_version.ml", @@ -69,7 +72,7 @@ const compilerVersionFile = path.resolve( /** * path: `/_build/install/default/bin/` */ -const compilerBinDir = path.resolve( +export const compilerBinDir = path.resolve( projectDir, "_build", "install", @@ -77,28 +80,16 @@ const compilerBinDir = path.resolve( "bin", ); +/** + * path: `/_build/install/default/bin/ounit_tests` + */ +export const ounitTestBin = path.join(compilerBinDir, "ounit_tests"); + /** * path: `/tests/gentype_tests/typescript-react-example/` */ -const gentypeExampleDir = path.resolve( +export const gentypeExampleDir = path.resolve( testDir, "gentype_tests", "typescript-react-example", ); - -module.exports = { - projectDir, - compilerRootDir, - runtimeDir, - runtimeCjsOutputDir, - runtimeEsmOutputDir, - rewatchDir, - ninjaDir, - testDir, - compilerTestDir, - buildTestDir, - docstringTestDir, - compilerVersionFile, - compilerBinDir, - gentypeExampleDir, -}; diff --git a/lib_dev/process.js b/lib_dev/process.js new file mode 100644 index 0000000000..f98aa6afec --- /dev/null +++ b/lib_dev/process.js @@ -0,0 +1,166 @@ +import * as child_process from "node:child_process"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import { bsc_exe, cliPath, rescript_exe } from "#cli/paths"; + +/** + * @typedef {{ + * status: number, + * stdout: string, + * stderr: string, + * }} ExecResult + */ + +const signals = { + SIGINT: 2, + SIGQUIT: 3, + SIGKILL: 9, + SIGTERM: 15, +}; + +export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } = + setup(); + +/** + * @param {string} url + */ +export function setupWithUrl(url) { + return setup(path.dirname(fileURLToPath(url))); +} + +/** + * @param {string} [cwd] + */ +export function setup(cwd = process.cwd()) { + /** + * @param {string} command + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + async function exec(command, args = [], options = {}) { + const stdoutChunks = []; + const stderrChunks = []; + + const subprocess = child_process.spawn(command, args, { + cwd, + stdio: ["ignore", "pipe", "pipe"], + ...options, + }); + + subprocess.stdout?.on("data", chunk => { + stdoutChunks.push(chunk); + }); + + subprocess.stderr?.on("data", chunk => { + stderrChunks.push(chunk); + }); + + return await new Promise((resolve, reject) => { + subprocess.once("error", err => { + reject(err); + }); + + subprocess.once("close", (exitCode, signal) => { + const stdout = Buffer.concat(stdoutChunks).toString("utf8"); + const stderr = Buffer.concat(stderrChunks).toString("utf8"); + + let code = exitCode ?? 1; + if (signals[signal]) { + // + 128 is standard POSIX practice, see also https://nodejs.org/api/process.html#exit-codes + code = signals[signal] + 128; + } + + resolve({ status: code, stdout, stderr }); + }); + }); + } + + return { + exec, + + /** + * `node` CLI + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + node(args = [], options = {}) { + return exec("node", args, options); + }, + + /** + * `npx` CLI + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + npx(args = [], options = {}) { + return exec("npx", args, options); + }, + + /** + * Mocha CLI + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + mocha(args = [], options = {}) { + return exec("npx", ["mocha", ...args], options); + }, + + /** + * `rescript` CLI + * + * @param {( + * | "build" + * | "clean" + * | "format" + * | "dump" + * | (string & {}) + * )} command + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + rescript(command, args = [], options = {}) { + return exec(cliPath, [command, ...args].filter(Boolean), options); + }, + + /** + * `bsc` CLI + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + bsc(args = [], options = {}) { + return exec(bsc_exe, args, options); + }, + + /** + * Execute ReScript `build` command directly + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + execBuild(args = [], options = {}) { + return exec(rescript_exe, ["build", ...args], options); + }, + + /** + * Execute ReScript `clean` command directly + * + * @param {string[]} [args] + * @param {child_process.SpawnOptions} [options] + * @return {Promise} + */ + execClean(args = [], options = {}) { + return exec(rescript_exe, ["clean", ...args], options); + }, + }; +} diff --git a/lib_dev/utils.js b/lib_dev/utils.js new file mode 100644 index 0000000000..36ff8f53a3 --- /dev/null +++ b/lib_dev/utils.js @@ -0,0 +1,16 @@ +/** + * `import.meta.dirname` alternative. It is available since Node.js v20.11.0 + * + * @param {string} url `import.meta.url` + * @return {string} + */ +export function getDirname(url) { + return path.dirname(fileURLToPath(url)); +} + +/** + * @param {string} s + */ +export function normalizeNewlines(s) { + return s.replace(/\r\n/g, "\n"); +} diff --git a/package.json b/package.json index 98189c91a4..d2ed451148 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "rescript", "version": "12.0.0-alpha.11", "description": "ReScript toolchain", + "type": "module", "keywords": [ "ReScript", "Compiler", @@ -37,22 +38,18 @@ "node": ">=20.11.0" }, "bin": { - "bsc": "cli/bsc", - "bstracing": "lib/bstracing", - "rescript": "cli/rescript", - "rescript-tools": "cli/rescript-tools", - "rewatch": "cli/rewatch" + "bsc": "cli/bsc.js", + "bstracing": "lib/bstracing.js", + "rescript": "cli/rescript.js", + "rescript-tools": "cli/rescript-tools.js", + "rewatch": "cli/rewatch.js" }, "scripts": { "test": "node scripts/test.js -all", "test-bsb": "node scripts/test.js -bsb", "test-ocaml": "node scripts/test.js -ounit", - "lint": "biome check --changed --no-errors-on-unmatched .", - "lint:all": "biome check .", - "format": "biome format --changed --no-errors-on-unmatched --write .", - "format:all": "biome format --write .", - "checkFormat": "biome format --changed --no-errors-on-unmatched .", - "checkFormat:all": "biome format .", + "check": "biome check --changed --no-errors-on-unmatched .", + "check:all": "biome check .", "coverage": "nyc --timeout=3000 --reporter=html mocha tests/tests/src/*_test.js && open ./coverage/index.html", "typecheck": "tsc" }, @@ -75,7 +72,7 @@ "./package.json": "./package.json" }, "imports": { - "#cli/bin_path": "./cli/bin_path.js", + "#cli/paths": "./cli/_paths.js", "#lib/minisocket": "./lib/minisocket.js", "#dev/*": "./lib_dev/*.js" }, diff --git a/packages/playground-bundling/package.json b/packages/playground-bundling/package.json index d7dbd99c89..2f7b0ca1ce 100644 --- a/packages/playground-bundling/package.json +++ b/packages/playground-bundling/package.json @@ -2,6 +2,7 @@ "name": "proj", "version": "1.0.0", "description": "", + "type": "module", "main": "index.js", "scripts": { "build": "rescript clean && rescript build && node ./scripts/generate_cmijs.js", diff --git a/packages/playground-bundling/rollup.config.cjs b/packages/playground-bundling/rollup.config.cjs deleted file mode 100644 index 5c7fd2ca02..0000000000 --- a/packages/playground-bundling/rollup.config.cjs +++ /dev/null @@ -1,22 +0,0 @@ -const resolve = require("@rollup/plugin-node-resolve"); - -const { globSync } = require("glob"); -const path = require("node:path"); - -const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", ".."); -const LIB_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "lib"); -const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); -// Final target output directory where all the cmijs will be stored -const PACKAGES_DIR = path.join(PLAYGROUND_DIR, "packages"); -const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins", "stdlib"); - -module.exports = globSync(`${LIB_DIR}/es6/*.js`).map(entryPoint => { - return { - input: entryPoint, - output: { - dir: outputFolder, - format: "esm", - }, - plugins: [resolve({ browser: true })], - }; -}); diff --git a/packages/playground-bundling/rollup.config.mjs b/packages/playground-bundling/rollup.config.mjs new file mode 100644 index 0000000000..4768a6071f --- /dev/null +++ b/packages/playground-bundling/rollup.config.mjs @@ -0,0 +1,23 @@ +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import nodeResolve from "@rollup/plugin-node-resolve"; +import { glob } from "glob"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", ".."); +const LIB_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "lib"); +const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); +// Final target output directory where all the cmijs will be stored +const PACKAGES_DIR = path.join(PLAYGROUND_DIR, "packages"); +const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins", "stdlib"); + +const entryPoint = await glob(`${LIB_DIR}/es6/*.js`); +export default { + input: entryPoint, + output: { + dir: outputFolder, + format: "esm", + }, + plugins: [nodeResolve({ browser: true })], +}; diff --git a/packages/playground-bundling/scripts/generate_cmijs.js b/packages/playground-bundling/scripts/generate_cmijs.js index f2ee548cac..9ce2004647 100644 --- a/packages/playground-bundling/scripts/generate_cmijs.js +++ b/packages/playground-bundling/scripts/generate_cmijs.js @@ -15,11 +15,14 @@ * playground bundle. */ -const child_process = require("node:child_process"); -const fs = require("node:fs"); -const path = require("node:path"); +import * as child_process from "node:child_process"; +import * as fs from "node:fs"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; -const resConfig = require("../rescript.json"); +import resConfig from "../rescript.json" with { type: "json" }; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", "..", ".."); const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); diff --git a/playground/playground_test.js b/playground/playground_test.js index 43b25ee4e3..134d518de8 100644 --- a/playground/playground_test.js +++ b/playground/playground_test.js @@ -1,9 +1,8 @@ // Playground bundle is UMD module // It uses `module.exports` in current context, or fallback to `globalThis` -const { rescript_compiler } = require("./compiler.js"); - -require("./packages/compiler-builtins/cmij.js"); -require("./packages/@rescript/react/cmij.js"); +import "./compiler.js"; +import "./packages/compiler-builtins/cmij.js"; +import "./packages/@rescript/react/cmij.js"; const compiler = rescript_compiler.make(); diff --git a/runtime/RescriptTools.res b/runtime/RescriptTools.res index 6ad891d51b..35b6426e0e 100644 --- a/runtime/RescriptTools.res +++ b/runtime/RescriptTools.res @@ -11,5 +11,5 @@ You can use this when you're already running a JS process and want to avoid the let stringifiedJson = ChildProcess.execFileSync(RescriptTools.binaryPath, ["-v"]) ``` */ -@module("../../cli/bin_path.js") +@module("#cli/paths") external binaryPath: string = "rescript_tools_exe" diff --git a/scripts/buildNinjaBinary.js b/scripts/buildNinjaBinary.js index af73d99056..0bfc6f8dfe 100755 --- a/scripts/buildNinjaBinary.js +++ b/scripts/buildNinjaBinary.js @@ -2,20 +2,19 @@ // @ts-check -const child_process = require("node:child_process"); -const path = require("node:path"); +import { execSync } from "node:child_process"; +import { ninjaDir } from "#dev/paths"; const platform = process.platform; -const ninjaDir = path.join(__dirname, "..", "ninja"); const buildCommand = "python configure.py --bootstrap --verbose"; if (platform === "win32") { // On Windows, the build uses the MSVC compiler which needs to be on the path. - child_process.execSync(buildCommand, { cwd: ninjaDir }); + execSync(buildCommand, { cwd: ninjaDir }); } else { if (process.platform === "darwin") { process.env.CXXFLAGS = "-flto"; } - child_process.execSync(buildCommand, { stdio: [0, 1, 2], cwd: ninjaDir }); - child_process.execSync("strip ninja", { stdio: [0, 1, 2], cwd: ninjaDir }); + execSync(buildCommand, { stdio: [0, 1, 2], cwd: ninjaDir }); + execSync("strip ninja", { stdio: [0, 1, 2], cwd: ninjaDir }); } diff --git a/scripts/buildRuntime.sh b/scripts/buildRuntime.sh index 8cf8ad5e92..5d794a7321 100755 --- a/scripts/buildRuntime.sh +++ b/scripts/buildRuntime.sh @@ -2,13 +2,13 @@ set -e shopt -s extglob -(cd runtime && ../cli/rescript clean) +(cd runtime && ../cli/rescript.js clean) rm -f lib/es6/*.js lib/js/*.js lib/ocaml/* mkdir -p lib/es6 lib/js lib/ocaml mkdir -p runtime/lib/es6 runtime/lib/js -(cd runtime && ../cli/rescript build) +(cd runtime && ../cli/rescript.js build) cp runtime/lib/es6/!(Pervasives_mini).js lib/es6 cp runtime/lib/js/!(Pervasives_mini).js lib/js diff --git a/scripts/copyExes.js b/scripts/copyExes.js index 14017b9bc7..dd8fce5563 100755 --- a/scripts/copyExes.js +++ b/scripts/copyExes.js @@ -4,11 +4,11 @@ // Copy exes built by dune to platform bin dir -const path = require("node:path"); -const fs = require("node:fs"); -const child_process = require("node:child_process"); -const { platformDir } = require("#cli/bin_path"); -const { compilerBinDir, ninjaDir, rewatchDir } = require("#dev/paths"); +import * as child_process from "node:child_process"; +import * as fs from "node:fs"; +import * as path from "node:path"; +import { platformDir } from "#cli/paths"; +import { compilerBinDir, ninjaDir, rewatchDir } from "#dev/paths"; fs.mkdirSync(platformDir, { recursive: true }); diff --git a/scripts/cppo.js b/scripts/cppo.js index ee93d79d57..6bd9b43144 100644 --- a/scripts/cppo.js +++ b/scripts/cppo.js @@ -1,8 +1,8 @@ // @ts-check -const { execFileSync } = require("node:child_process"); +import { execFileSync } from "node:child_process"; -[ +const targets = [ ["belt_HashSetString.res", "hashset.res.cppo", "TYPE_STRING"], ["belt_HashSetString.resi", "hashset.resi.cppo", "TYPE_STRING"], ["belt_HashSetInt.res", "hashset.res.cppo", "TYPE_INT"], @@ -35,10 +35,12 @@ const { execFileSync } = require("node:child_process"); ["belt_internalMapInt.res", "internal_map.res.cppo", "TYPE_INT"], ["belt_internalSetString.res", "internal_set.res.cppo", "TYPE_STRING"], ["belt_internalSetInt.res", "internal_set.res.cppo", "TYPE_INT"], -].forEach(([output, input, type]) => { +]; + +for (const [output, input, type] of targets) { execFileSync( "cppo", ["-n", "-D", type, `runtime/cppo/${input}`, "-o", `runtime/${output}`], { stdio: "inherit" }, ); -}); +} diff --git a/scripts/format.sh b/scripts/format.sh index 11c1fa299a..b9b8f0fed7 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -5,6 +5,6 @@ shopt -s extglob dune build @fmt --auto-promote files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*") -./cli/rescript format $files +./cli/rescript.js format $files yarn format diff --git a/scripts/format_check.sh b/scripts/format_check.sh index 9489a75008..656f86a732 100755 --- a/scripts/format_check.sh +++ b/scripts/format_check.sh @@ -18,7 +18,7 @@ case "$(uname -s)" in echo "Checking ReScript code formatting..." files=$(find runtime tests -type f \( -name "*.res" -o -name "*.resi" \) ! -name "syntaxErrors*" ! -name "generated_mocha_test.res" ! -path "tests/syntax_*" ! -path "tests/analysis_tests/tests*" ! -path "*/node_modules/*") - if ./cli/rescript format -check $files; then + if ./cli/rescript.js format -check $files; then printf "${successGreen}✅ ReScript code formatting ok.${reset}\n" else printf "${warningYellow}⚠️ ReScript code formatting issues found.${reset}\n" @@ -31,4 +31,4 @@ case "$(uname -s)" in esac echo "Biome format check" -yarn checkFormat +yarn check diff --git a/scripts/npmPack.js b/scripts/npmPack.js index ce33e06118..967803c827 100755 --- a/scripts/npmPack.js +++ b/scripts/npmPack.js @@ -1,4 +1,5 @@ #!/usr/bin/env node + // @ts-check // TODO: Use `yarn pack --json` instead. @@ -28,21 +29,21 @@ * @typedef {[PackOutputEntry]} PackOutput */ -const { spawnSync, execSync } = require("node:child_process"); -const path = require("node:path"); -const fs = require("node:fs"); +import { execSync, spawnSync } from "node:child_process"; +import fs from "node:fs"; +import path from "node:path"; +import { projectDir } from "#dev/paths"; const mode = process.argv.includes("-updateArtifactList") ? "updateArtifactList" : "package"; -const rootPath = path.join(__dirname, ".."); -const fileListPath = path.join(rootPath, "packages", "artifacts.txt"); +const fileListPath = path.join(projectDir, "packages", "artifacts.txt"); const output = spawnSync( `npm pack --json${mode === "updateArtifactList" ? " --dry-run" : ""}`, { - cwd: rootPath, + cwd: projectDir, encoding: "utf8", shell: true, }, diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index 17f581249d..c1c12b3ce3 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -2,11 +2,11 @@ // @ts-check -const fs = require("node:fs"); -const assert = require("node:assert"); -const semver = require("semver"); -const { compilerVersionFile } = require("#dev/paths"); -const { packageJson } = require("#dev/meta"); +import assert from "node:assert"; +import fs from "node:fs"; +import packageJson from "rescript/package.json" with { type: "json" }; +import semver from "semver"; +import { compilerVersionFile } from "#dev/paths"; /** * @param {semver.SemVer} bsVersion diff --git a/scripts/setVersion.js b/scripts/setVersion.js index f70a61726a..f2d30339bb 100644 --- a/scripts/setVersion.js +++ b/scripts/setVersion.js @@ -2,10 +2,8 @@ // @ts-check -const fs = require("node:fs"); - -const packageSpec = JSON.parse(fs.readFileSync("./package.json", "utf8")); -const { version, name } = packageSpec; +import fs from "node:fs"; +import { name, version } from "rescript/package.json" with { type: "json" }; const stdlibPackageSpec = JSON.parse( fs.readFileSync("./packages/std/package.json", "utf8"), diff --git a/scripts/test.js b/scripts/test.js index a9d7b79516..cbda6d6fb8 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,19 +1,24 @@ // @ts-check -const cp = require("node:child_process"); -const path = require("node:path"); -const fs = require("node:fs"); -const os = require("node:os"); -const { rescript_exe } = require("#cli/bin_path"); -const { - projectDir, - compilerBinDir, - compilerTestDir, +import * as fs from "node:fs"; +import * as os from "node:os"; +import * as path from "node:path"; +import { buildTestDir, + compilerTestDir, docstringTestDir, -} = require("#dev/paths"); + ounitTestBin, + projectDir, +} from "#dev/paths"; -const { exec } = require("../tests/build_tests/utils.js"); +import { + exec, + execBuild, + execClean, + mocha, + node, + rescript, +} from "#dev/process"; let ounitTest = false; let mochaTest = false; @@ -49,140 +54,136 @@ if (process.argv.includes("-all")) { runtimeDocstrings = true; } -async function runTests() { - if (formatTest) { - cp.execSync("bash scripts/format_check.sh", { - cwd: projectDir, - stdio: [0, 1, 2], +if (formatTest) { + await exec("bash", ["scripts/format_check.sh"], { + cwd: projectDir, + stdio: "inherit", + }); +} + +if (ounitTest) { + if (process.platform === "win32") { + console.log("Skipping OUnit tests on Windows"); + } else { + await exec(ounitTestBin, [], { + stdio: "inherit", }); } +} + +if (mochaTest) { + await execClean([], { + cwd: compilerTestDir, + stdio: "inherit", + }); + + await execBuild([], { + cwd: compilerTestDir, + stdio: "inherit", + }); + + await mocha(["-t", "10000", "tests/tests/**/*_test.mjs"], { + cwd: projectDir, + stdio: "inherit", + }); + + await node(["tests/tests/src/core/Core_TestSuite.mjs"], { + cwd: projectDir, + stdio: "inherit", + }); + + await node(["tests/tests/src/core/Core_TempTests.mjs"], { + cwd: projectDir, + stdio: "inherit", + }); +} + +if (bsbTest) { + console.log("Doing build_tests"); + const files = fs.readdirSync(buildTestDir); - if (ounitTest) { - if (process.platform === "win32") { - console.log("Skipping OUnit tests on Windows"); + let hasError = false; + + for (const file of files) { + const testDir = path.join(buildTestDir, file); + if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) { + continue; + } + if (!fs.existsSync(path.join(testDir, "input.js"))) { + console.warn(`input.js does not exist in ${testDir}`); } else { - cp.execSync(path.join(compilerBinDir, "ounit_tests"), { - stdio: [0, 1, 2], - }); + console.log(`testing ${file}`); + + // note existsSync test already ensure that it is a directory + const out = await exec("node", ["input.js"], { cwd: testDir }); + console.log(out.stdout); + + if (out.status === 0) { + console.log("✅ success in", file); + } else { + console.log(`❌ error in ${file} with stderr:\n`, out.stderr); + hasError = true; + } } } - if (mochaTest) { - cp.execSync(`${rescript_exe} clean`, { - cwd: compilerTestDir, - stdio: [0, 1, 2], - }); + if (hasError) { + process.exit(1); + } +} - cp.execSync(`${rescript_exe} build`, { - cwd: compilerTestDir, - stdio: [0, 1, 2], +if (runtimeDocstrings) { + if (process.platform === "win32") { + console.log(`Skipping docstrings tests on ${process.platform}`); + } else if (process.platform === "darwin" && os.release().startsWith("22")) { + // Workaround for intermittent hangs in CI + console.log("Skipping docstrings tests on macOS 13"); + } else { + console.log("Running runtime docstrings tests"); + + const generated_mocha_test_res = path.join( + "tests", + "docstring_tests", + "generated_mocha_test.res", + ); + + // Remove `generated_mocha_test.res` if file exists + if (fs.existsSync(generated_mocha_test_res)) { + console.log(`Removing ${generated_mocha_test_res}`); + fs.unlinkSync(generated_mocha_test_res); + } + + await execBuild([], { + cwd: docstringTestDir, + stdio: "inherit", }); - cp.execSync("npx mocha -t 10000 tests/tests/**/*_test.mjs", { + // Generate rescript file with all tests `generated_mocha_test.res` + await node([path.join(docstringTestDir, "DocTest.res.mjs")], { cwd: projectDir, - stdio: [0, 1, 2], + stdio: "inherit", }); - cp.execSync("node tests/tests/src/core/Core_TestSuite.mjs", { - cwd: projectDir, - stdio: [0, 1, 2], + // Build again to check if generated_mocha_test.res has syntax or type erros + await execBuild([], { + cwd: docstringTestDir, + stdio: "inherit", }); - cp.execSync("node tests/tests/src/core/Core_TempTests.mjs", { + // Format generated_mocha_test.res + console.log("Formatting generated_mocha_test.res"); + await rescript("format", [generated_mocha_test_res], { cwd: projectDir, - stdio: [0, 1, 2], + stdio: "inherit", }); - } - - if (bsbTest) { - console.log("Doing build_tests"); - const files = fs.readdirSync(buildTestDir); - - let hasError = false; - - for (const file of files) { - const testDir = path.join(buildTestDir, file); - if (file === "node_modules" || !fs.lstatSync(testDir).isDirectory()) { - continue; - } - if (!fs.existsSync(path.join(testDir, "input.js"))) { - console.warn(`input.js does not exist in ${testDir}`); - } else { - console.log(`testing ${file}`); - - // note existsSync test already ensure that it is a directory - const out = await exec("node", ["input.js"], { cwd: testDir }); - console.log(out.stdout); - - if (out.status === 0) { - console.log("✅ success in", file); - } else { - console.log(`❌ error in ${file} with stderr:\n`, out.stderr); - hasError = true; - } - } - } - if (hasError) { - process.exit(1); - } - } - - if (runtimeDocstrings) { - if (process.platform === "win32") { - console.log(`Skipping docstrings tests on ${process.platform}`); - } else if (process.platform === "darwin" && os.release().startsWith("22")) { - // Workaround for intermittent hangs in CI - console.log("Skipping docstrings tests on macOS 13"); - } else { - console.log("Running runtime docstrings tests"); - - const generated_mocha_test_res = path.join( - "tests", - "docstring_tests", - "generated_mocha_test.res", - ); - - // Remove `generated_mocha_test.res` if file exists - if (fs.existsSync(generated_mocha_test_res)) { - console.log(`Removing ${generated_mocha_test_res}`); - fs.unlinkSync(generated_mocha_test_res); - } - - cp.execSync(`${rescript_exe} build`, { - cwd: docstringTestDir, - stdio: [0, 1, 2], - }); - - // Generate rescript file with all tests `generated_mocha_test.res` - cp.execSync(`node ${path.join(docstringTestDir, "DocTest.res.mjs")}`, { - cwd: projectDir, - stdio: [0, 1, 2], - }); - - // Build again to check if generated_mocha_test.res has syntax or type erros - cp.execSync(`${rescript_exe} build`, { - cwd: docstringTestDir, - stdio: [0, 1, 2], - }); - - // Format generated_mocha_test.res - console.log("Formatting generated_mocha_test.res"); - cp.execSync(`./cli/rescript format ${generated_mocha_test_res}`, { + console.log("Run mocha test"); + await mocha( + [path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")], + { cwd: projectDir, - stdio: [0, 1, 2], - }); - - console.log("Run mocha test"); - cp.execSync( - `npx mocha ${path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")}`, - { - cwd: projectDir, - stdio: [0, 1, 2], - }, - ); - } + stdio: "inherit", + }, + ); } } - -runTests(); diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index e4f551c2cc..5ebaf29085 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -1,11 +1,9 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; -const o1 = p.spawnSync(rescript_exe, ["build"], { - encoding: "utf8", - cwd: __dirname, -}); +const { execBuild, execClean } = setupWithUrl(import.meta.url); + +const o1 = await execBuild(); const first_message = o1.stdout .split("\n") @@ -17,10 +15,7 @@ if (!first_message) { } // Second build using -warn-error +110 -const o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], { - encoding: "utf8", - cwd: __dirname, -}); +const o2 = await execBuild(["-warn-error", "+110"]); const second_message = o2.stdout .split("\n") @@ -33,10 +28,7 @@ if (!second_message) { // Third build, without -warn-error +110 // The result should not be a warning as error -const o3 = p.spawnSync(rescript_exe, ["build"], { - encoding: "utf8", - cwd: __dirname, -}); +const o3 = await execBuild(); const third_message = o3.stdout .split("\n") @@ -47,7 +39,4 @@ if (!third_message) { assert.fail(o3.stdout); } -const _cleanup = p.spawnSync(rescript_exe, ["clean"], { - encoding: "utf8", - cwd: __dirname, -}); +await execClean(); diff --git a/tests/build_tests/case/input.js b/tests/build_tests/case/input.js index c58952240d..004fbcc6a8 100644 --- a/tests/build_tests/case/input.js +++ b/tests/build_tests/case/input.js @@ -1,9 +1,10 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -const { normalizeNewlines } = require("../utils.js"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; -const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +const { execBuild } = setupWithUrl(import.meta.url); + +const { stderr } = await execBuild(); if ( ![ @@ -12,7 +13,7 @@ if ( "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\demo vs src\\Demo\n", // Linux: files are parsed in different order "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/Demo vs src/demo\n", - ].includes(normalizeNewlines(o.stderr)) + ].includes(normalizeNewlines(stderr)) ) { - assert.fail(o.stderr); + assert.fail(stderr); } diff --git a/tests/build_tests/case2/input.js b/tests/build_tests/case2/input.js index c184c7982f..364a2e3fe3 100644 --- a/tests/build_tests/case2/input.js +++ b/tests/build_tests/case2/input.js @@ -1,9 +1,12 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -const { normalizeNewlines } = require("../utils.js"); +// @ts-check -const o = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; + +const { execBuild } = setupWithUrl(import.meta.url); + +const { stderr } = await execBuild(); if ( ![ @@ -12,7 +15,7 @@ if ( "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src\\X vs src\\x\n", // Linux: files are parsed in different order "Error: Invalid bsconfig.json implementation and interface have different path names or different cases src/x vs src/X\n", - ].includes(normalizeNewlines(o.stderr)) + ].includes(normalizeNewlines(stderr)) ) { - assert.fail(o.stderr); + assert.fail(stderr); } diff --git a/tests/build_tests/case3/input.js b/tests/build_tests/case3/input.js index 40dc2be6b6..a761ec1c30 100644 --- a/tests/build_tests/case3/input.js +++ b/tests/build_tests/case3/input.js @@ -1,14 +1,13 @@ -//@ts-check - -const p = require("node:child_process"); -const fs = require("node:fs"); -const path = require("node:path"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -p.spawnSync(`${rescript_exe} clean && ${rescript_exe} build`, { - encoding: "utf8", - cwd: __dirname, -}); - -const o = fs.readFileSync(path.join(__dirname, "src", "hello.bs.js"), "ascii"); +// @ts-check + +import assert from "node:assert"; +import fs from "node:fs/promises"; +import path from "node:path"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); + +const o = await fs.readFile(path.join("src", "hello.res.js"), "ascii"); assert.ok(/HelloGen\.f/.test(o)); diff --git a/tests/build_tests/case3/rescript.json b/tests/build_tests/case3/rescript.json index 267c827078..a543e5788c 100644 --- a/tests/build_tests/case3/rescript.json +++ b/tests/build_tests/case3/rescript.json @@ -6,10 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": [], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/case3/src/B01.bs.js b/tests/build_tests/case3/src/B01.res.js similarity index 100% rename from tests/build_tests/case3/src/B01.bs.js rename to tests/build_tests/case3/src/B01.res.js diff --git a/tests/build_tests/case3/src/B02.bs.js b/tests/build_tests/case3/src/B02.res.js similarity index 100% rename from tests/build_tests/case3/src/B02.bs.js rename to tests/build_tests/case3/src/B02.res.js diff --git a/tests/build_tests/case3/src/B03.bs.js b/tests/build_tests/case3/src/B03.res.js similarity index 100% rename from tests/build_tests/case3/src/B03.bs.js rename to tests/build_tests/case3/src/B03.res.js diff --git a/tests/build_tests/case3/src/B04.bs.js b/tests/build_tests/case3/src/B04.res.js similarity index 100% rename from tests/build_tests/case3/src/B04.bs.js rename to tests/build_tests/case3/src/B04.res.js diff --git a/tests/build_tests/case3/src/B05.bs.js b/tests/build_tests/case3/src/B05.res.js similarity index 100% rename from tests/build_tests/case3/src/B05.bs.js rename to tests/build_tests/case3/src/B05.res.js diff --git a/tests/build_tests/case3/src/a01.bs.js b/tests/build_tests/case3/src/a01.res.js similarity index 100% rename from tests/build_tests/case3/src/a01.bs.js rename to tests/build_tests/case3/src/a01.res.js diff --git a/tests/build_tests/case3/src/a02.bs.js b/tests/build_tests/case3/src/a02.res.js similarity index 100% rename from tests/build_tests/case3/src/a02.bs.js rename to tests/build_tests/case3/src/a02.res.js diff --git a/tests/build_tests/case3/src/a03.bs.js b/tests/build_tests/case3/src/a03.res.js similarity index 100% rename from tests/build_tests/case3/src/a03.bs.js rename to tests/build_tests/case3/src/a03.res.js diff --git a/tests/build_tests/case3/src/a04.bs.js b/tests/build_tests/case3/src/a04.res.js similarity index 100% rename from tests/build_tests/case3/src/a04.bs.js rename to tests/build_tests/case3/src/a04.res.js diff --git a/tests/build_tests/case3/src/a05.bs.js b/tests/build_tests/case3/src/a05.res.js similarity index 100% rename from tests/build_tests/case3/src/a05.bs.js rename to tests/build_tests/case3/src/a05.res.js diff --git a/tests/build_tests/case3/src/hello.bs.js b/tests/build_tests/case3/src/hello.res.js similarity index 66% rename from tests/build_tests/case3/src/hello.bs.js rename to tests/build_tests/case3/src/hello.res.js index 08c02c69b7..2e8c61cbdd 100644 --- a/tests/build_tests/case3/src/hello.bs.js +++ b/tests/build_tests/case3/src/hello.res.js @@ -1,11 +1,12 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -var HelloGen = require("./hello.gen"); +import * as HelloGen from "./hello.gen"; function f(prim) { return HelloGen.f(prim); } -exports.f = f; +export { + f, +} /* ./hello.gen Not a pure module */ diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index 29ff3f42ad..f91271267e 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -1,27 +1,20 @@ // @ts-check -const assert = require("node:assert"); -const path = require("node:path"); -const child_process = require("node:child_process"); -const { normalizeNewlines } = require("../utils.js"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; -const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript"); +const { rescript } = setupWithUrl(import.meta.url); // Shows compile time for `rescript build` command -let out = child_process.spawnSync("node", [rescriptPath, "build"], { - encoding: "utf8", - cwd: __dirname, -}); +let out = await rescript("build"); assert.match( normalizeNewlines(out.stdout), />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, ); // Shows compile time for `rescript` command -out = child_process.spawnSync("node", [rescriptPath], { - encoding: "utf8", - cwd: __dirname, -}); +out = await rescript("build"); assert.match( normalizeNewlines(out.stdout), />>>> Start compiling\nDependency Finished\n>>>> Finish compiling \d+ mseconds/, @@ -31,10 +24,7 @@ assert.match( // Because we can't be sure that -verbose is a valid argument // And bsb won't fail with a usage message. // It works this way not only for -verbose, but any other arg, including -h/--help/-help -out = child_process.spawnSync("node", [rescriptPath, "build", "-verbose"], { - encoding: "utf8", - cwd: __dirname, -}); +out = await rescript("build", ["-verbose"]); assert.match( normalizeNewlines(out.stdout), diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index e17322a71b..7b18ed8985 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -1,10 +1,10 @@ // @ts-check -const assert = require("node:assert"); -const path = require("node:path"); -const { exec, normalizeNewlines } = require("../utils.js"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; -const rescriptPath = path.join(__dirname, "..", "..", "..", "cli", "rescript"); +const { rescript } = setupWithUrl(import.meta.url); const cliHelp = "Usage: rescript \n" + @@ -68,108 +68,102 @@ const dumpHelp = * @param {string[]} params * @param {{ stdout: string; stderr: string; status: number; }} expected */ -async function runTest(params, expected) { - const out = await exec("node", [rescriptPath, ...params], { - cwd: __dirname, - }); +async function test(params, expected) { + const out = await rescript("", params); assert.equal(normalizeNewlines(out.stdout), expected.stdout); assert.equal(normalizeNewlines(out.stderr), expected.stderr); assert.equal(out.status, expected.status); } -async function test() { - // Shows build help with --help arg - await runTest(["build", "--help"], { - stdout: buildHelp, - stderr: "", - status: 0, - }); - - await runTest(["build", "-w", "--help"], { - stdout: buildHelp, - stderr: "", - status: 0, - }); - - await runTest(["-w", "--help"], { stdout: cliHelp, stderr: "", status: 0 }); - - // Shows cli help with --help arg even if there are invalid arguments after it - await runTest(["--help", "-w"], { stdout: cliHelp, stderr: "", status: 0 }); - - // Shows build help with -h arg - await runTest(["build", "-h"], { stdout: buildHelp, stderr: "", status: 0 }); - - // Exits with build help with unknown arg - await runTest(["build", "-foo"], { - stdout: "", - stderr: `Error: Unknown option "-foo".\n${buildHelp}`, - status: 2, - }); - - // Shows cli help with --help arg - await runTest(["--help"], { stdout: cliHelp, stderr: "", status: 0 }); - - // Shows cli help with -h arg - await runTest(["-h"], { stdout: cliHelp, stderr: "", status: 0 }); - - // Shows cli help with -h arg - await runTest(["help"], { stdout: cliHelp, stderr: "", status: 0 }); - - // Exits with cli help with unknown command - await runTest(["built"], { - stdout: "", - stderr: `Error: Unknown command "built".\n${cliHelp}`, - status: 2, - }); - - // Exits with build help with unknown args - await runTest(["-foo"], { - stdout: "", - stderr: `Error: Unknown option "-foo".\n${buildHelp}`, - status: 2, - }); - - // Shows clean help with --help arg - await runTest(["clean", "--help"], { - stdout: cleanHelp, - stderr: "", - status: 0, - }); - - // Shows clean help with -h arg - await runTest(["clean", "-h"], { stdout: cleanHelp, stderr: "", status: 0 }); - - // Exits with clean help with unknown arg - await runTest(["clean", "-foo"], { - stdout: "", - stderr: `Error: Unknown option "-foo".\n${cleanHelp}`, - status: 2, - }); - - // Shows format help with --help arg - await runTest(["format", "--help"], { - stdout: formatHelp, - stderr: "", - status: 0, - }); - - // Shows format help with -h arg - await runTest(["format", "-h"], { - stdout: formatHelp, - stderr: "", - status: 0, - }); - - // Shows dump help with --help arg - await runTest(["dump", "--help"], { - stdout: dumpHelp, - stderr: "", - status: 0, - }); - - // Shows dump help with -h arg - await runTest(["dump", "-h"], { stdout: dumpHelp, stderr: "", status: 0 }); -} - -void test(); +// Shows build help with --help arg +await test(["build", "--help"], { + stdout: buildHelp, + stderr: "", + status: 0, +}); + +await test(["build", "-w", "--help"], { + stdout: buildHelp, + stderr: "", + status: 0, +}); + +await test(["-w", "--help"], { stdout: cliHelp, stderr: "", status: 0 }); + +// Shows cli help with --help arg even if there are invalid arguments after it +await test(["--help", "-w"], { stdout: cliHelp, stderr: "", status: 0 }); + +// Shows build help with -h arg +await test(["build", "-h"], { stdout: buildHelp, stderr: "", status: 0 }); + +// Exits with build help with unknown arg +await test(["build", "-foo"], { + stdout: "", + stderr: `Error: Unknown option "-foo".\n${buildHelp}`, + status: 2, +}); + +// Shows cli help with --help arg +await test(["--help"], { stdout: cliHelp, stderr: "", status: 0 }); + +// Shows cli help with -h arg +await test(["-h"], { stdout: cliHelp, stderr: "", status: 0 }); + +// Shows cli help with -h arg +await test(["help"], { stdout: cliHelp, stderr: "", status: 0 }); + +// Exits with cli help with unknown command +await test(["built"], { + stdout: "", + stderr: `Error: Unknown command "built".\n${cliHelp}`, + status: 2, +}); + +// Exits with build help with unknown args +await test(["-foo"], { + stdout: "", + stderr: `Error: Unknown option "-foo".\n${buildHelp}`, + status: 2, +}); + +// Shows clean help with --help arg +await test(["clean", "--help"], { + stdout: cleanHelp, + stderr: "", + status: 0, +}); + +// Shows clean help with -h arg +await test(["clean", "-h"], { stdout: cleanHelp, stderr: "", status: 0 }); + +// Exits with clean help with unknown arg +await test(["clean", "-foo"], { + stdout: "", + stderr: `Error: Unknown option "-foo".\n${cleanHelp}`, + status: 2, +}); + +// Shows format help with --help arg +await test(["format", "--help"], { + stdout: formatHelp, + stderr: "", + status: 0, +}); + +// Shows format help with -h arg +await test(["format", "-h"], { + stdout: formatHelp, + stderr: "", + status: 0, +}); + +// Shows dump help with --help arg +await test(["dump", "--help"], { + stdout: dumpHelp, + stderr: "", + status: 0, +}); + +// Shows dump help with -h arg +await test(["dump", "-h"], { stdout: dumpHelp, stderr: "", status: 0 }); diff --git a/tests/build_tests/custom_namespace/input.js b/tests/build_tests/custom_namespace/input.js index 6e113560da..feaf4ba8ec 100644 --- a/tests/build_tests/custom_namespace/input.js +++ b/tests/build_tests/custom_namespace/input.js @@ -1,10 +1,10 @@ -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; -child_process.execSync(`${rescript_exe} clean && ${rescript_exe} build`, { - cwd: __dirname, -}); +const { execClean, execBuild } = setupWithUrl(import.meta.url); -const x = require("./src/demo.bs.js"); +await execClean(); +await execBuild(); + +const x = await import("./src/demo.res.js"); assert.equal(x.v, 42); diff --git a/tests/build_tests/custom_namespace/rescript.json b/tests/build_tests/custom_namespace/rescript.json index 9677227f12..089f4e6858 100644 --- a/tests/build_tests/custom_namespace/rescript.json +++ b/tests/build_tests/custom_namespace/rescript.json @@ -7,14 +7,13 @@ }, "namespace": "Foo_bar", "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, "bsc-flags": ["-bs-no-version-header"], - "bs-dependencies": [], "warnings": { "number": "-40+6+7", "error": true }, - "suffix": ".bs.js" + "suffix": ".res.js" } diff --git a/tests/build_tests/custom_namespace/src/demo.bs.js b/tests/build_tests/custom_namespace/src/demo.res.js similarity index 55% rename from tests/build_tests/custom_namespace/src/demo.bs.js rename to tests/build_tests/custom_namespace/src/demo.res.js index 160a8f1d2b..4237b506f2 100644 --- a/tests/build_tests/custom_namespace/src/demo.bs.js +++ b/tests/build_tests/custom_namespace/src/demo.res.js @@ -1,7 +1,9 @@ -'use strict'; + let v = 42; -exports.v = v; +export { + v, +} /* No side effect */ diff --git a/tests/build_tests/cycle/input.js b/tests/build_tests/cycle/input.js index fc4f9892ee..fd9ccf5d65 100644 --- a/tests/build_tests/cycle/input.js +++ b/tests/build_tests/cycle/input.js @@ -1,14 +1,16 @@ -//@ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; -assert(/dependency cycle/.test(output.stdout)); +const { execBuild } = setupWithUrl(import.meta.url); -const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); -assert(/dependency cycle/.test(compilerLog)); +const output = await execBuild(); + +assert.match(output.stdout, /dependency cycle/); + +const compilerLogFile = path.join("lib", "bs", ".compiler.log"); +const compilerLog = await fs.readFile(compilerLogFile, "utf8"); +assert.match(compilerLog, /dependency cycle/); diff --git a/tests/build_tests/cycle1/input.js b/tests/build_tests/cycle1/input.js index b9123e7fa3..500caf5bd0 100644 --- a/tests/build_tests/cycle1/input.js +++ b/tests/build_tests/cycle1/input.js @@ -1,16 +1,17 @@ -//@ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; -const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); +const { execBuild, execClean } = setupWithUrl(import.meta.url); -assert(/is dangling/.test(output.stdout)); +await execClean(); +const output = await execBuild(); -const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); -assert(/is dangling/.test(compilerLog)); +assert.match(output.stdout, /is dangling/); + +const compilerLogFile = path.join("lib", "bs", ".compiler.log"); +const compilerLog = await fs.readFile(compilerLogFile, "utf8"); +assert.match(compilerLog, /is dangling/); diff --git a/tests/build_tests/deprecated-package-specs/input.js b/tests/build_tests/deprecated-package-specs/input.js index d403bda1f6..467f4fd689 100644 --- a/tests/build_tests/deprecated-package-specs/input.js +++ b/tests/build_tests/deprecated-package-specs/input.js @@ -1,8 +1,11 @@ -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); +import assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +const out = await execBuild(); assert.match( out.stderr, /deprecated: Option "es6-global" is deprecated\. Use "esmodule" instead\./, diff --git a/tests/build_tests/devonly/input.js b/tests/build_tests/devonly/input.js index c1304efb8e..31848da96f 100644 --- a/tests/build_tests/devonly/input.js +++ b/tests/build_tests/devonly/input.js @@ -1,5 +1,7 @@ -//@ts-check -const cp = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/package.json b/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/package.json index 92b37ba7fb..6b9eef9a35 100644 --- a/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/package.json +++ b/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/package.json @@ -1,18 +1,4 @@ { "name": "z", - "version": "0.1.0", - "scripts": { - "build": "bsb -make-world", - "start": "bsb -make-world -w", - "clean": "bsb -clean-world" - }, - "keywords": [ - "BuckleScript" - ], - "author": "", - "license": "MIT", - "devDependencies": { - "bs-platform": "^7.0.1", - "gentype": "^3.7.1" - } + "version": "0.1.0" } diff --git a/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json b/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/rescript.json similarity index 63% rename from tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json rename to tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/rescript.json index c99d72b2b4..9ea351dd4d 100644 --- a/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json +++ b/tests/build_tests/duplicated_symlinked_packages/a/node_modules/z/rescript.json @@ -6,16 +6,12 @@ "subdirs" : true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", - "bs-dependencies": [ - - ], + "suffix": ".res.js", "warnings": { "error" : "+101" }, - "namespace": true, - "refmt": 3 + "namespace": true } diff --git a/tests/build_tests/duplicated_symlinked_packages/a/package.json b/tests/build_tests/duplicated_symlinked_packages/a/package.json index f0cb45e231..7d9dd31f9e 100644 --- a/tests/build_tests/duplicated_symlinked_packages/a/package.json +++ b/tests/build_tests/duplicated_symlinked_packages/a/package.json @@ -1,15 +1,4 @@ { "name": "a", - "version": "0.1.0", - "scripts": { - "build": "rescript build", - "start": "rescript build -w", - "clean": "rescript clean" - }, - "keywords": [ - "ReScript" - ], - "author": "", - "license": "MIT", - "devDependencies": {} + "version": "0.1.0" } diff --git a/tests/build_tests/duplicated_symlinked_packages/a/bsconfig.json b/tests/build_tests/duplicated_symlinked_packages/a/rescript.json similarity index 82% rename from tests/build_tests/duplicated_symlinked_packages/a/bsconfig.json rename to tests/build_tests/duplicated_symlinked_packages/a/rescript.json index e59898305e..47d3c647ed 100644 --- a/tests/build_tests/duplicated_symlinked_packages/a/bsconfig.json +++ b/tests/build_tests/duplicated_symlinked_packages/a/rescript.json @@ -6,10 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": ["c", "z"], "warnings": { "error": "+101" }, "namespace": true diff --git a/tests/build_tests/duplicated_symlinked_packages/b/package.json b/tests/build_tests/duplicated_symlinked_packages/b/package.json index 6cba4e4ddc..17346b27df 100644 --- a/tests/build_tests/duplicated_symlinked_packages/b/package.json +++ b/tests/build_tests/duplicated_symlinked_packages/b/package.json @@ -1,15 +1,4 @@ { "name": "b", - "version": "0.1.0", - "scripts": { - "build": "rescript build", - "start": "rescript build -w", - "clean": "rescript clean" - }, - "keywords": [ - "ReScript" - ], - "author": "", - "license": "MIT", - "devDependencies": {} + "version": "0.1.0" } diff --git a/tests/build_tests/duplicated_symlinked_packages/b/bsconfig.json b/tests/build_tests/duplicated_symlinked_packages/b/rescript.json similarity index 82% rename from tests/build_tests/duplicated_symlinked_packages/b/bsconfig.json rename to tests/build_tests/duplicated_symlinked_packages/b/rescript.json index 29d031fd4b..4d85b1366a 100644 --- a/tests/build_tests/duplicated_symlinked_packages/b/bsconfig.json +++ b/tests/build_tests/duplicated_symlinked_packages/b/rescript.json @@ -6,10 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": ["c"], "warnings": { "error": "+101" }, "namespace": true diff --git a/tests/build_tests/duplicated_symlinked_packages/c/package.json b/tests/build_tests/duplicated_symlinked_packages/c/package.json index 907967c8be..f8623644bc 100644 --- a/tests/build_tests/duplicated_symlinked_packages/c/package.json +++ b/tests/build_tests/duplicated_symlinked_packages/c/package.json @@ -1,18 +1,4 @@ { - "name": "z", - "version": "0.1.0", - "scripts": { - "build": "rescript build", - "start": "rescript build -w", - "clean": "rescript clean" - }, - "keywords": [ - "ReScript" - ], - "author": "", - "license": "MIT", - "devDependencies": { - "bs-platform": "^7.0.1", - "gentype": "^3.7.1" - } + "name": "c", + "version": "0.1.0" } diff --git a/tests/build_tests/duplicated_symlinked_packages/c/bsconfig.json b/tests/build_tests/duplicated_symlinked_packages/c/rescript.json similarity index 73% rename from tests/build_tests/duplicated_symlinked_packages/c/bsconfig.json rename to tests/build_tests/duplicated_symlinked_packages/c/rescript.json index 24cc6980db..487a3cbac4 100644 --- a/tests/build_tests/duplicated_symlinked_packages/c/bsconfig.json +++ b/tests/build_tests/duplicated_symlinked_packages/c/rescript.json @@ -6,11 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", - "bs-dependencies": [], + "suffix": ".res.js", "warnings": { "error": "+101" }, "namespace": true } diff --git a/tests/build_tests/duplicated_symlinked_packages/input.js b/tests/build_tests/duplicated_symlinked_packages/input.js index aa3540f6b9..49a171a9b3 100644 --- a/tests/build_tests/duplicated_symlinked_packages/input.js +++ b/tests/build_tests/duplicated_symlinked_packages/input.js @@ -1,9 +1,14 @@ -const fs = require("node:fs"); -const path = require("node:path"); -const child_process = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const expectedFilePath = path.join(__dirname, "out.expected"); +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import { setupWithUrl } from "#dev/process"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const { execBuild, execClean } = setupWithUrl(import.meta.url); + +const expectedFilePath = "./out.expected"; const updateTests = process.argv[2] === "update"; @@ -20,27 +25,22 @@ if (process.platform === "win32") { process.exit(0); } -child_process.execSync(`${rescript_exe} clean`, { cwd: __dirname }); - -child_process.exec( - rescript_exe, - { cwd: __dirname }, - (_err, _stdout, stderr) => { - const actualErrorOutput = postProcessErrorOutput(stderr.toString()); - if (updateTests) { - fs.writeFileSync(expectedFilePath, actualErrorOutput); - } else { - const expectedErrorOutput = postProcessErrorOutput( - fs.readFileSync(expectedFilePath, { encoding: "utf-8" }), - ); - if (expectedErrorOutput !== actualErrorOutput) { - console.error(`The old and new error output aren't the same`); - console.error("\n=== Old:"); - console.error(expectedErrorOutput); - console.error("\n=== New:"); - console.error(actualErrorOutput); - process.exit(1); - } - } - }, -); +await execClean(); +const { stderr } = await execBuild(); + +const actualErrorOutput = postProcessErrorOutput(stderr.toString()); +if (updateTests) { + await fs.writeFile(expectedFilePath, actualErrorOutput); +} else { + const expectedErrorOutput = postProcessErrorOutput( + await fs.readFile(expectedFilePath, { encoding: "utf-8" }), + ); + if (expectedErrorOutput !== actualErrorOutput) { + console.error(`The old and new error output aren't the same`); + console.error("\n=== Old:"); + console.error(expectedErrorOutput); + console.error("\n=== New:"); + console.error(actualErrorOutput); + process.exit(1); + } +} diff --git a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/package.json b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/package.json index 92b37ba7fb..6b9eef9a35 100644 --- a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/package.json +++ b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/package.json @@ -1,18 +1,4 @@ { "name": "z", - "version": "0.1.0", - "scripts": { - "build": "bsb -make-world", - "start": "bsb -make-world -w", - "clean": "bsb -clean-world" - }, - "keywords": [ - "BuckleScript" - ], - "author": "", - "license": "MIT", - "devDependencies": { - "bs-platform": "^7.0.1", - "gentype": "^3.7.1" - } + "version": "0.1.0" } diff --git a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json similarity index 74% rename from tests/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json rename to tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json index c99d72b2b4..5ebf01cc2f 100644 --- a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/bsconfig.json +++ b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json @@ -6,13 +6,10 @@ "subdirs" : true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", - "bs-dependencies": [ - - ], + "suffix": ".res.js", "warnings": { "error" : "+101" }, diff --git a/tests/build_tests/exports/input.js b/tests/build_tests/exports/input.js index 596c5522a0..31848da96f 100644 --- a/tests/build_tests/exports/input.js +++ b/tests/build_tests/exports/input.js @@ -1,7 +1,7 @@ -const child_process = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -child_process.execSync(rescript_exe, { - cwd: __dirname, - encoding: "utf8", -}); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/gpr_978/input.js b/tests/build_tests/gpr_978/input.js index d2722f4200..4215a9e349 100644 --- a/tests/build_tests/gpr_978/input.js +++ b/tests/build_tests/gpr_978/input.js @@ -1,13 +1,15 @@ -//@ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); - -const output = cp.spawnSync(rescript_exe, { encoding: "utf8", shell: true }); -assert(/M is exported twice/.test(output.stdout)); - -const compilerLogFile = path.join(__dirname, "lib", "bs", ".compiler.log"); -const compilerLog = fs.readFileSync(compilerLogFile, "utf8"); -assert(/M is exported twice/.test(compilerLog)); +// @ts-check + +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +const output = await execBuild(); +assert.match(output.stdout, /M is exported twice/); + +const compilerLogFile = path.join("lib", "bs", ".compiler.log"); +const compilerLog = await fs.readFile(compilerLogFile, "utf8"); +assert.match(compilerLog, /M is exported twice/); diff --git a/tests/build_tests/hyphen2/input.js b/tests/build_tests/hyphen2/input.js index 4e568e556e..31848da96f 100644 --- a/tests/build_tests/hyphen2/input.js +++ b/tests/build_tests/hyphen2/input.js @@ -1,4 +1,7 @@ -const p = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -p.execSync(rescript_exe, { cwd: __dirname }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js index 4bb7090f3c..bf4e02b81e 100644 --- a/tests/build_tests/in_source/input.js +++ b/tests/build_tests/in_source/input.js @@ -1,19 +1,9 @@ -const child_process = require("node:child_process"); -const assert = require("node:assert"); +// @ts-check -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; -assert.throws( - () => { - const _output = child_process.execSync(`${rescript_exe} build -regen`, { - cwd: __dirname, - encoding: "utf8", - }); - }, - err => { - if (err.message.match(/detected two module formats/)) { - return true; - } - return false; - }, -); +const { execBuild } = setupWithUrl(import.meta.url); + +const output = await execBuild(["-regen"]); +assert.match(output.stderr, /detected two module formats/); diff --git a/tests/build_tests/install/input.js b/tests/build_tests/install/input.js index 4d720c5892..1233c731cd 100644 --- a/tests/build_tests/install/input.js +++ b/tests/build_tests/install/input.js @@ -1,29 +1,20 @@ -const p = require("node:child_process"); -const fs = require("node:fs"); -const path = require("node:path"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -p.spawnSync(rescript_exe, ["clean"], { - encoding: "utf8", - cwd: __dirname, -}); -p.spawnSync(rescript_exe, ["build", "-install"], { - encoding: "utf8", - cwd: __dirname, -}); +import * as assert from "node:assert"; +import { existsSync } from "node:fs"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; -let fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); -assert.ok(fooExists === false); +const { execBuild, execClean } = setupWithUrl(import.meta.url); -p.spawnSync(rescript_exe, { - encoding: "utf8", - cwd: __dirname, -}); -p.spawnSync(rescript_exe, ["build", "-install"], { - encoding: "utf8", - cwd: __dirname, -}); +await execClean(); +await execBuild(["-install"]); -fooExists = fs.existsSync(path.join(__dirname, "lib", "ocaml", "Foo.cmi")); +let fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); +assert.ok(!fooExists); + +await execBuild(); +await execBuild(["-install"]); + +fooExists = existsSync(path.join("lib", "ocaml", "Foo.cmi")); assert.ok(fooExists); diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 8cfd468c7a..31848da96f 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -1,5 +1,7 @@ -//@ts-check -const cp = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -cp.execSync(rescript_exe, { cwd: __dirname }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/nested/input.js b/tests/build_tests/nested/input.js index 0e7135a212..2b2300f8a0 100644 --- a/tests/build_tests/nested/input.js +++ b/tests/build_tests/nested/input.js @@ -1,17 +1,22 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); -p.execSync(rescript_exe, { cwd: __dirname }); +// @ts-check -const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; -assert.ok(content.match(/A00_a1_main/g).length === 3); -assert.ok(content.match(/B00_b1_main/g).length === 3); -assert.ok(content.match(/A0_main/g).length === 2); -assert.ok(content.match(/a0_main/g).length === 1); -assert.ok(content.match(/B0_main/g).length === 2); -assert.ok(content.match(/b0_main/g).length === 1); +const { execBuild } = setupWithUrl(import.meta.url); -assert.ok(require("./src/demo.js").v === 4, "nested"); +await execBuild(); + +const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); + +assert.equal(content.match(/A00_a1_main/g)?.length, 3); +assert.equal(content.match(/B00_b1_main/g)?.length, 3); +assert.equal(content.match(/A0_main/g)?.length, 2); +assert.equal(content.match(/a0_main/g)?.length, 1); +assert.equal(content.match(/B0_main/g)?.length, 2); +assert.equal(content.match(/b0_main/g)?.length, 1); + +const mod = await import("./src/demo.js"); +assert.equal(mod.v, 4, "nested"); diff --git a/tests/build_tests/nested/rescript.json b/tests/build_tests/nested/rescript.json index 745772f871..d796e4f378 100644 --- a/tests/build_tests/nested/rescript.json +++ b/tests/build_tests/nested/rescript.json @@ -6,7 +6,7 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, "warnings": { "error": true } diff --git a/tests/build_tests/nnest/input.js b/tests/build_tests/nnest/input.js index d9de24ac45..8749f7886e 100644 --- a/tests/build_tests/nnest/input.js +++ b/tests/build_tests/nnest/input.js @@ -1,22 +1,25 @@ // @ts-check -const p = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); -p.execSync(rescript_exe, { cwd: __dirname }); - -const content = fs.readFileSync(path.join(__dirname, "src", "demo.js"), "utf8"); - -assert.ok(content.match(/A0_a1_main/g).length === 3); -assert.ok(content.match(/B0_b1_main/g).length === 3); -assert.ok(content.match(/A0_main/g).length === 2); -assert.ok(content.match(/a0_main/g).length === 1); -assert.ok(content.match(/B0_main/g).length === 2); -assert.ok(content.match(/b0_main/g).length === 1); - -assert.ok(require("./src/demo.js").v === 4, "nested"); +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); + +const content = await fs.readFile(path.join("src", "demo.js"), "utf8"); + +assert.equal(content.match(/A0_a1_main/g)?.length, 3); +assert.equal(content.match(/B0_b1_main/g)?.length, 3); +assert.equal(content.match(/A0_main/g)?.length, 2); +assert.equal(content.match(/a0_main/g)?.length, 1); +assert.equal(content.match(/B0_main/g)?.length, 2); +assert.equal(content.match(/b0_main/g)?.length, 1); + +const mod = await import("./src/demo.js"); +assert.equal(mod.v, 4, "nested"); // var testWarnError = /warnings\s*=\s*[^\r\n]*-warn-error/; diff --git a/tests/build_tests/nnest/rescript.json b/tests/build_tests/nnest/rescript.json index e1e67b2128..dcbfeefd72 100644 --- a/tests/build_tests/nnest/rescript.json +++ b/tests/build_tests/nnest/rescript.json @@ -6,7 +6,7 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, "namespace": true, diff --git a/tests/build_tests/ns/input.js b/tests/build_tests/ns/input.js index 1c14e98e41..31848da96f 100755 --- a/tests/build_tests/ns/input.js +++ b/tests/build_tests/ns/input.js @@ -1,4 +1,7 @@ -const child_process = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -child_process.execSync(rescript_exe, { cwd: __dirname }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/post-build/input.js b/tests/build_tests/post-build/input.js index 29b4fe685e..46d223ffc0 100644 --- a/tests/build_tests/post-build/input.js +++ b/tests/build_tests/post-build/input.js @@ -1,13 +1,16 @@ -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check + +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -const out = child_process.spawnSync(rescript_exe, { encoding: "utf8" }); +const out = await execBuild(); if (out.status !== 0) { assert.fail(out.stdout + out.stderr); diff --git a/tests/build_tests/react_ppx/input.js b/tests/build_tests/react_ppx/input.js index 8cfd468c7a..31848da96f 100644 --- a/tests/build_tests/react_ppx/input.js +++ b/tests/build_tests/react_ppx/input.js @@ -1,5 +1,7 @@ -//@ts-check -const cp = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -cp.execSync(rescript_exe, { cwd: __dirname }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/rerror/input.js b/tests/build_tests/rerror/input.js index 44ee1fc0f4..c47003a81e 100644 --- a/tests/build_tests/rerror/input.js +++ b/tests/build_tests/rerror/input.js @@ -1,23 +1,17 @@ // @ts-check -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -child_process.spawnSync(`${rescript_exe} clean`, { - cwd: __dirname, - encoding: "utf8", -}); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; -const o = child_process.spawnSync(rescript_exe, { - cwd: __dirname, - encoding: "utf8", - shell: true, -}); +const { execBuild, execClean } = setupWithUrl(import.meta.url); + +await execClean(); +const output = await execBuild([]); // verify the output is in reason syntax -const u = o.stdout.match(/=>/g); +const u = output.stdout.match(/=>/g); -const lines = o.stdout +const lines = output.stdout .split(/\r?\n/) .map(x => x.trim()) .filter(Boolean); @@ -26,9 +20,9 @@ let test = false; for (let i = 0; i < lines.length; i++) { if (lines[i] === "We've found a bug for you!") { console.log(`line ${i} found`); - assert.ok(/src[\\/]demo.res:1:21-23/.test(lines[i + 1])); + assert.match(lines[i + 1], /src[\\/]demo.res:1:21-23/); test = true; } } assert.ok(test); -assert.ok(u?.length === 2); +assert.equal(u?.length, 2); diff --git a/tests/build_tests/scoped_ppx/input.js b/tests/build_tests/scoped_ppx/input.js index 4d294148fb..4144cb4446 100644 --- a/tests/build_tests/scoped_ppx/input.js +++ b/tests/build_tests/scoped_ppx/input.js @@ -1,24 +1,19 @@ -const cp = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check + +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -cp.execSync(rescript_exe, { cwd: __dirname, encoding: "utf8" }); - -const output = cp.execSync( - `${rescript_exe} build -- -t commands src/hello.ast`, - { - cwd: __dirname, - encoding: "utf8", - }, -); +await execBuild(); +const output = await execBuild(["--", "-t", "commands", "src/hello.ast"]); -assert.ok( - /-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/.test( - output, - ), +assert.match( + output.stdout, + /-ppx '.*\/test\.js -hello' -ppx '.*\/test\.js -heyy' -ppx .*test\.js/, ); diff --git a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json new file mode 100644 index 0000000000..5bbefffbab --- /dev/null +++ b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js index 92f21f0418..e0ec31c3e2 100755 --- a/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js +++ b/tests/build_tests/scoped_ppx/node_modules/@hongbo/ppx1/test.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -//@ts-check +// @ts-check const fs = require('node:fs') diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index 308cf43d77..f45ded172f 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -1,17 +1,22 @@ -const fs = require("node:fs"); -const path = require("node:path"); -const child_process = require("node:child_process"); +// @ts-check -const { bsc_exe: bsc } = require("#cli/bin_path"); -const { normalizeNewlines } = require("../utils.js"); +import { readdirSync } from "node:fs"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const { bsc } = setupWithUrl(import.meta.url); const expectedDir = path.join(__dirname, "expected"); -const fixtures = fs - .readdirSync(path.join(__dirname, "fixtures")) - .filter(fileName => path.extname(fileName) === ".res"); +const fixtures = readdirSync("fixtures").filter( + fileName => path.extname(fileName) === ".res", +); -const prefix = `${bsc} -w +A -bs-jsx 4`; +const prefix = ["-w", "+A", "-bs-jsx", "4"]; const updateTests = process.argv[2] === "update"; @@ -34,35 +39,33 @@ let atLeastOneTaskFailed = false; for (const fileName of fixtures) { const fullFilePath = path.join(__dirname, "fixtures", fileName); - const command = `${prefix} -color always ${fullFilePath}`; - child_process.exec(command, (_err, _stdout, stderr) => { - doneTasksCount++; - // careful of: - // - warning test that actually succeeded in compiling (warning's still in stderr, so the code path is shared here) - // - accidentally succeeding tests (not likely in this context), - // actual, correctly erroring test case - const actualErrorOutput = postProcessErrorOutput(stderr.toString()); - const expectedFilePath = path.join(expectedDir, `${fileName}.expected`); - if (updateTests) { - fs.writeFileSync(expectedFilePath, actualErrorOutput); - } else { - const expectedErrorOutput = postProcessErrorOutput( - fs.readFileSync(expectedFilePath, { encoding: "utf-8" }), + const { stderr } = await bsc([...prefix, "-color", "always", fullFilePath]); + doneTasksCount++; + // careful of: + // - warning test that actually succeeded in compiling (warning's still in stderr, so the code path is shared here) + // - accidentally succeeding tests (not likely in this context), + // actual, correctly erroring test case + const actualErrorOutput = postProcessErrorOutput(stderr.toString()); + const expectedFilePath = path.join(expectedDir, `${fileName}.expected`); + if (updateTests) { + await fs.writeFile(expectedFilePath, actualErrorOutput); + } else { + const expectedErrorOutput = postProcessErrorOutput( + await fs.readFile(expectedFilePath, "utf-8"), + ); + if (expectedErrorOutput !== actualErrorOutput) { + console.error( + `The old and new error output for the test ${fullFilePath} aren't the same`, ); - if (expectedErrorOutput !== actualErrorOutput) { - console.error( - `The old and new error output for the test ${fullFilePath} aren't the same`, - ); - console.error("\n=== Old:"); - console.error(expectedErrorOutput); - console.error("\n=== New:"); - console.error(actualErrorOutput); - atLeastOneTaskFailed = true; - } + console.error("\n=== Old:"); + console.error(expectedErrorOutput); + console.error("\n=== New:"); + console.error(actualErrorOutput); + atLeastOneTaskFailed = true; + } - if (doneTasksCount === fixtures.length && atLeastOneTaskFailed) { - process.exit(1); - } + if (doneTasksCount === fixtures.length && atLeastOneTaskFailed) { + process.exit(1); } - }); + } } diff --git a/tests/build_tests/transitive_pinned_dependency1/input.js b/tests/build_tests/transitive_pinned_dependency1/input.js index e4d678770b..c04f3991e4 100644 --- a/tests/build_tests/transitive_pinned_dependency1/input.js +++ b/tests/build_tests/transitive_pinned_dependency1/input.js @@ -1,15 +1,15 @@ // @ts-check -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import { existsSync } from "node:fs"; +import { setup } from "#dev/process"; -console.log( - child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), -); +const { execBuild } = setup("./a"); + +const output = await execBuild(); +console.log(output); assert.ok( - fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), + existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'", ); diff --git a/tests/build_tests/transitive_pinned_dependency2/input.js b/tests/build_tests/transitive_pinned_dependency2/input.js index 879e701f81..ef3ca3c461 100644 --- a/tests/build_tests/transitive_pinned_dependency2/input.js +++ b/tests/build_tests/transitive_pinned_dependency2/input.js @@ -1,14 +1,15 @@ -//@ts-check -const child_process = require("node:child_process"); -const assert = require("node:assert"); -const fs = require("node:fs"); -const { rescript_exe } = require("#cli/bin_path"); - -console.log( - child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }), -); +// @ts-check + +import * as assert from "node:assert"; +import { existsSync } from "node:fs"; +import { setup } from "#dev/process"; + +const { execBuild } = setup("./a"); + +const output = await execBuild(); +console.log(output); -assert( - !fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), +assert.ok( + !existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'", ); diff --git a/tests/build_tests/unboxed_bool_with_const/input.js b/tests/build_tests/unboxed_bool_with_const/input.js index 3655efc803..42c1a98a04 100644 --- a/tests/build_tests/unboxed_bool_with_const/input.js +++ b/tests/build_tests/unboxed_bool_with_const/input.js @@ -1,14 +1,12 @@ -//@ts-check +// @ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -const { normalizeNewlines } = require("../utils.js"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; -const out = cp.spawnSync(rescript_exe, { - cwd: __dirname, - encoding: "utf8", -}); +const { execBuild } = setupWithUrl(import.meta.url); + +const out = await execBuild(); assert.equal( normalizeNewlines(out.stdout.slice(out.stdout.indexOf("Main.res:3:3-14"))), diff --git a/tests/build_tests/uncurried-always/input.js b/tests/build_tests/uncurried-always/input.js index 4d511dcd41..abca212e29 100644 --- a/tests/build_tests/uncurried-always/input.js +++ b/tests/build_tests/uncurried-always/input.js @@ -1,6 +1,8 @@ -//@ts-check -const cp = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -cp.execSync(`${rescript_exe} clean`, { cwd: __dirname }); -cp.execSync(`${rescript_exe}`, { cwd: __dirname }); +import { setupWithUrl } from "#dev/process"; + +const { execBuild, execClean } = setupWithUrl(import.meta.url); + +await execClean(); +await execBuild(); diff --git a/tests/build_tests/unicode/input.js b/tests/build_tests/unicode/input.js index 585da6ae54..e4385bac6c 100644 --- a/tests/build_tests/unicode/input.js +++ b/tests/build_tests/unicode/input.js @@ -1,21 +1,21 @@ // @ts-check -const child_process = require("node:child_process"); -const fs = require("node:fs"); -const path = require("node:path"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import * as fs from "node:fs/promises"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); if (process.platform === "win32") { console.log("Skipping test on Windows"); process.exit(0); } -console.log(child_process.execSync(rescript_exe, { encoding: "utf8" })); - -const content = fs.readFileSync( - path.join(__dirname, "lib", "bs", ".sourcedirs.json"), +await execBuild(); +const content = await fs.readFile( + path.join("lib", "bs", ".sourcedirs.json"), "utf-8", ); -assert(JSON.parse(content).dirs.some(x => x.includes("📕annotation"))); +assert.ok(JSON.parse(content).dirs.some(x => x.includes("📕annotation"))); diff --git a/tests/build_tests/utils.js b/tests/build_tests/utils.js deleted file mode 100644 index 06d0a49eef..0000000000 --- a/tests/build_tests/utils.js +++ /dev/null @@ -1,60 +0,0 @@ -const child_process = require("node:child_process"); - -const signals = { - SIGINT: 2, - SIGQUIT: 3, - SIGKILL: 9, - SIGTERM: 15, -}; - -/** - * @param {string} command - * @param {Array} args - * @param {child_process.SpawnOptions} [options] - */ -async function exec(command, args, options) { - const stdoutChunks = []; - const stderrChunks = []; - - const subprocess = child_process.spawn(command, args, { - stdio: ["ignore", "pipe", "pipe"], - ...options, - }); - - subprocess.stdout.on("data", chunk => { - stdoutChunks.push(chunk); - }); - - subprocess.stderr.on("data", chunk => { - stderrChunks.push(chunk); - }); - - return await new Promise((resolve, reject) => { - subprocess.once("error", err => { - reject(err); - }); - - subprocess.once("close", (exitCode, signal) => { - const stdout = Buffer.concat(stdoutChunks).toString("utf8"); - const stderr = Buffer.concat(stderrChunks).toString("utf8"); - - let code = exitCode ?? 1; - if (signals[signal]) { - // + 128 is standard POSIX practice, see also https://nodejs.org/api/process.html#exit-codes - code = signals[signal] + 128; - } - - resolve({ status: code, stdout, stderr }); - }); - }); -} - -/** - * @param {string} s - */ -function normalizeNewlines(s) { - return s.replace(/\r\n/g, "\n"); -} - -exports.exec = exec; -exports.normalizeNewlines = normalizeNewlines; diff --git a/tests/build_tests/warn_legacy_config/input.js b/tests/build_tests/warn_legacy_config/input.js index b37c60cc07..433b55f9b9 100644 --- a/tests/build_tests/warn_legacy_config/input.js +++ b/tests/build_tests/warn_legacy_config/input.js @@ -1,10 +1,12 @@ -const { spawnSync } = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const output = spawnSync(rescript_exe, { encoding: "utf8" }); -assert( - /^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/.test( - output.stdout, - ), +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +const output = await execBuild(); +assert.match( + output.stdout, + /^Warning: bsconfig.json is deprecated. Migrate it to rescript.json/, ); diff --git a/tests/build_tests/weird_deps/input.js b/tests/build_tests/weird_deps/input.js index af2831c51a..1153a7c2c0 100644 --- a/tests/build_tests/weird_deps/input.js +++ b/tests/build_tests/weird_deps/input.js @@ -1,15 +1,12 @@ -//@ts-check +// @ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -const { normalizeNewlines } = require("../utils.js"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; +import { normalizeNewlines } from "#dev/utils"; -const out = cp.spawnSync(rescript_exe, { - cwd: __dirname, - encoding: "utf8", -}); +const { execBuild } = setupWithUrl(import.meta.url); +const out = await execBuild(); if (out.stdout !== "") { assert.fail(out.stdout); } else { diff --git a/tests/build_tests/weird_deps/rescript.json b/tests/build_tests/weird_deps/rescript.json index 4dc59a53e5..9a1511c654 100644 --- a/tests/build_tests/weird_deps/rescript.json +++ b/tests/build_tests/weird_deps/rescript.json @@ -12,10 +12,10 @@ } ], "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": ["weird"], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/weird_devdeps/input.js b/tests/build_tests/weird_devdeps/input.js index 30c1639255..5a09c80b73 100644 --- a/tests/build_tests/weird_devdeps/input.js +++ b/tests/build_tests/weird_devdeps/input.js @@ -1,15 +1,12 @@ -//@ts-check +// @ts-check -const cp = require("node:child_process"); -const assert = require("node:assert"); -const os = require("node:os"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import * as os from "node:os"; +import { setupWithUrl } from "#dev/process"; -const out = cp.spawnSync(rescript_exe, { - cwd: __dirname, - encoding: "utf8", -}); +const { execBuild } = setupWithUrl(import.meta.url); +const out = await execBuild(); if (out.stdout !== "") { assert.fail(out.stdout); } else { diff --git a/tests/build_tests/weird_devdeps/rescript.json b/tests/build_tests/weird_devdeps/rescript.json index 91696bc454..0e3911d9ad 100644 --- a/tests/build_tests/weird_devdeps/rescript.json +++ b/tests/build_tests/weird_devdeps/rescript.json @@ -12,10 +12,10 @@ } ], "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": [], "bs-dev-dependencies": ["weird"], "warnings": { "error": "+101" } diff --git a/tests/build_tests/weird_names/input.js b/tests/build_tests/weird_names/input.js index 5e0d591d88..9396a7d728 100644 --- a/tests/build_tests/weird_names/input.js +++ b/tests/build_tests/weird_names/input.js @@ -1,9 +1,12 @@ -const cp = require("node:child_process"); -const assert = require("node:assert"); -const path = require("node:path"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); +import * as assert from "node:assert"; +import * as path from "node:path"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +const out = await execBuild(); if (out.stderr !== "") { assert.fail(out.stderr); @@ -21,6 +24,6 @@ const files = [ for (const f of files) { const { name } = path.parse(f); - const m = `./lib/js/src/${name}.js`; - assert.deepEqual(require(m).a, 1); + const mod = await import(`./lib/es6/src/${name}.js`); + assert.deepEqual(mod.a, 1); } diff --git a/tests/build_tests/weird_names/rescript.json b/tests/build_tests/weird_names/rescript.json index 305524ed2c..357d524c49 100644 --- a/tests/build_tests/weird_names/rescript.json +++ b/tests/build_tests/weird_names/rescript.json @@ -4,5 +4,8 @@ "sources": { "dir": "src", "subdirs": true + }, + "package-specs": { + "module": "esmodule" } } diff --git a/tests/build_tests/weird_names_not_found_bug/input.js b/tests/build_tests/weird_names_not_found_bug/input.js index 8582cc0bde..b2427bcee3 100644 --- a/tests/build_tests/weird_names_not_found_bug/input.js +++ b/tests/build_tests/weird_names_not_found_bug/input.js @@ -1,8 +1,10 @@ -const cp = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = await setupWithUrl(import.meta.url); + +const out = await execBuild(); -const out = cp.spawnSync(rescript_exe, { encoding: "utf8" }); if (out.stderr !== "") { assert.fail(out.stderr); } diff --git a/tests/build_tests/weird_names_not_found_bug/rescript.json b/tests/build_tests/weird_names_not_found_bug/rescript.json index 305524ed2c..357d524c49 100644 --- a/tests/build_tests/weird_names_not_found_bug/rescript.json +++ b/tests/build_tests/weird_names_not_found_bug/rescript.json @@ -4,5 +4,8 @@ "sources": { "dir": "src", "subdirs": true + }, + "package-specs": { + "module": "esmodule" } } diff --git a/tests/build_tests/x-y/input.js b/tests/build_tests/x-y/input.js index 6d8c53998c..31848da96f 100644 --- a/tests/build_tests/x-y/input.js +++ b/tests/build_tests/x-y/input.js @@ -1,4 +1,7 @@ -const p = require("node:child_process"); -const { rescript_exe } = require("#cli/bin_path"); +// @ts-check -p.execSync(rescript_exe); +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); + +await execBuild(); diff --git a/tests/build_tests/xpkg/input.js b/tests/build_tests/xpkg/input.js index e68c3a87db..beece0fe1c 100644 --- a/tests/build_tests/xpkg/input.js +++ b/tests/build_tests/xpkg/input.js @@ -1,12 +1,9 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -try { - const output = p.spawnSync(`${rescript_exe} build -regen`, { - shell: true, - encoding: "utf8", - }); +// @ts-check - assert.ok(output.stderr.match(/reserved package name/)); -} finally { -} +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = await setupWithUrl(import.meta.url); + +const output = await execBuild(["-regen"]); +assert.match(output.stderr, /reserved package name/); diff --git a/tests/build_tests/zerocycle/input.js b/tests/build_tests/zerocycle/input.js index cfa9e940d8..1b0290a27d 100644 --- a/tests/build_tests/zerocycle/input.js +++ b/tests/build_tests/zerocycle/input.js @@ -1,5 +1,8 @@ -const p = require("node:child_process"); -const assert = require("node:assert"); -const { rescript_exe } = require("#cli/bin_path"); -const out = p.spawnSync(rescript_exe, { encoding: "utf8", cwd: __dirname }); -assert(out.status === 0); +// @ts-check + +import * as assert from "node:assert"; +import { setupWithUrl } from "#dev/process"; + +const { execBuild } = setupWithUrl(import.meta.url); +const output = await execBuild(); +assert.ok(output.status === 0); diff --git a/tests/docstring_tests/DocTest.res b/tests/docstring_tests/DocTest.res index bcb0bcba5f..f974435984 100644 --- a/tests/docstring_tests/DocTest.res +++ b/tests/docstring_tests/DocTest.res @@ -47,7 +47,7 @@ let getOutput = buffer => ->Array.join("") let extractDocFromFile = async file => { - let toolsBin = Path.join([Process.cwd(), "cli", "rescript-tools"]) + let toolsBin = Path.join([Process.cwd(), "cli", "rescript-tools.js"]) let {stdout} = await SpawnAsync.run(~command=toolsBin, ~args=["doc", file]) diff --git a/tests/docstring_tests/DocTest.res.mjs b/tests/docstring_tests/DocTest.res.mjs index 8ce01923db..a71ec94e3a 100644 --- a/tests/docstring_tests/DocTest.res.mjs +++ b/tests/docstring_tests/DocTest.res.mjs @@ -1,11 +1,11 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Fs from "fs"; -import * as Os from "os"; -import * as Url from "url"; -import * as Path from "path"; import * as Stdlib from "rescript/lib/es6/Stdlib.js"; +import * as Nodefs from "node:fs"; +import * as Nodeos from "node:os"; +import * as Nodeurl from "node:url"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; +import * as Nodepath from "node:path"; import * as ArrayUtils from "./ArrayUtils.res.mjs"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; import * as SpawnAsync from "./SpawnAsync.res.mjs"; @@ -51,7 +51,7 @@ function getOutput(buffer) { } async function extractDocFromFile(file) { - let toolsBin = Path.join(process.cwd(), "cli", "rescript-tools"); + let toolsBin = Nodepath.join(process.cwd(), "cli", "rescript-tools.js"); let match = await SpawnAsync.run(toolsBin, [ "doc", file @@ -204,10 +204,10 @@ function getCodeBlocks(example) { return Belt_Array.reverse(Stdlib_List.toArray(loop(Stdlib_List.fromArray(Stdlib_Array.reduce(example.docstrings, [], (acc, docstring) => acc.concat(docstring.split("\n")))), /* [] */0))).join("\n\n"); } -let batchSize = Os.cpus().length; +let batchSize = Nodeos.cpus().length; async function extractExamples() { - let files = Fs.readdirSync("runtime"); + let files = Nodefs.readdirSync("runtime"); let docFiles = files.filter(f => { if (f.startsWith("Js") || f.startsWith("RescriptTools") || f.startsWith("Stdlib_")) { return false; @@ -222,7 +222,7 @@ async function extractExamples() { console.log("Extracting examples from " + docFiles.length.toString() + " runtime files..."); let examples = []; await ArrayUtils.forEachAsyncInBatches(docFiles, batchSize, async f => { - let doc = await extractDocFromFile(Path.join("runtime", f)); + let doc = await extractDocFromFile(Nodepath.join("runtime", f)); examples.push(...getExamples(doc)); }); examples.sort((a, b) => Primitive_string.compare(a.id, b.id)); @@ -267,8 +267,8 @@ async function main() { let content = "describe(\"" + key + "\", () => {\n" + codeExamples.join("\n") + "\n })"; output.push(content); }); - let dirname = Path.dirname(Url.fileURLToPath(import.meta.url)); - let filepath = Path.join(dirname, "generated_mocha_test.res"); + let dirname = Nodepath.dirname(Nodeurl.fileURLToPath(import.meta.url)); + let filepath = Nodepath.join(dirname, "generated_mocha_test.res"); let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + output.join("\n"); return await Promises.writeFile(filepath, fileContent); } diff --git a/tests/docstring_tests/Node.res b/tests/docstring_tests/Node.res index 2182b31703..95eb4241bc 100644 --- a/tests/docstring_tests/Node.res +++ b/tests/docstring_tests/Node.res @@ -1,6 +1,6 @@ module Path = { - @module("path") @variadic external join: array => string = "join" - @module("path") external dirname: string => string = "dirname" + @module("node:path") @variadic external join: array => string = "join" + @module("node:path") external dirname: string => string = "dirname" } module Process = { @@ -9,7 +9,7 @@ module Process = { } module Fs = { - @module("fs") external readdirSync: string => array = "readdirSync" + @module("node:fs") external readdirSync: string => array = "readdirSync" @module("node:fs/promises") external writeFile: (string, string) => promise = "writeFile" } @@ -22,7 +22,7 @@ module ChildProcess = { type readable type spawnReturns = {stderr: readable, stdout: readable} type options = {cwd?: string, env?: Dict.t, timeout?: int} - @module("child_process") + @module("node:child_process") external spawn: (string, array, ~options: options=?) => spawnReturns = "spawn" @send external on: (readable, string, Buffer.t => unit) => unit = "on" @@ -32,12 +32,12 @@ module ChildProcess = { } module OS = { - @module("os") + @module("node:os") external cpus: unit => array<{.}> = "cpus" } module URL = { - @module("url") external fileURLToPath: string => string = "fileURLToPath" + @module("node:url") external fileURLToPath: string => string = "fileURLToPath" } @val @scope(("import", "meta")) external url: string = "url" diff --git a/tests/docstring_tests/SpawnAsync.res.mjs b/tests/docstring_tests/SpawnAsync.res.mjs index 22c6d33dae..0f56176257 100644 --- a/tests/docstring_tests/SpawnAsync.res.mjs +++ b/tests/docstring_tests/SpawnAsync.res.mjs @@ -1,10 +1,10 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Child_process from "child_process"; import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; +import * as Nodechild_process from "node:child_process"; async function run(command, args, options) { - let spawn = Child_process.spawn(command, args, options !== undefined ? Primitive_option.valFromOption(options) : undefined); + let spawn = Nodechild_process.spawn(command, args, options !== undefined ? Primitive_option.valFromOption(options) : undefined); let stdout = []; let stderr = []; spawn.stdout.on("data", data => { @@ -30,4 +30,4 @@ async function run(command, args, options) { export { run, } -/* child_process Not a pure module */ +/* node:child_process Not a pure module */ diff --git a/tests/gentype_tests/typescript-react-example/Makefile b/tests/gentype_tests/typescript-react-example/Makefile index 9bdd0e5013..5062da0431 100644 --- a/tests/gentype_tests/typescript-react-example/Makefile +++ b/tests/gentype_tests/typescript-react-example/Makefile @@ -1,7 +1,7 @@ SHELL = /bin/bash test: - npm run lint + npm run check npm run build npm run typecheck @git diff --quiet src/ \ diff --git a/tests/gentype_tests/typescript-react-example/package.json b/tests/gentype_tests/typescript-react-example/package.json index 13a9cc3ad4..8f5f0297de 100644 --- a/tests/gentype_tests/typescript-react-example/package.json +++ b/tests/gentype_tests/typescript-react-example/package.json @@ -6,7 +6,7 @@ "build": "rescript", "clean": "rescript clean", "typecheck": "tsc", - "lint": "biome check --changed --no-errors-on-unmatched ." + "check": "biome check --changed --no-errors-on-unmatched ." }, "dependencies": { "@rescript/react": "^0.13.1", diff --git a/tests/tests/src/tagged_template_lib.js b/tests/tests/src/tagged_template_lib.js index 5b4a6ed8af..beaacb5b0a 100644 --- a/tests/tests/src/tagged_template_lib.js +++ b/tests/tests/src/tagged_template_lib.js @@ -1,4 +1,4 @@ -exports.sql = (strings, ...values) => { +export const sql = (strings, ...values) => { let result = ""; for (let i = 0; i < values.length; i++) { result += strings[i] + "'" + values[i] + "'"; @@ -7,6 +7,6 @@ exports.sql = (strings, ...values) => { return result; }; -exports.length = (strings, ...values) => +export const length = (strings, ...values) => strings.reduce((acc, curr) => acc + curr.length, 0) + values.reduce((acc, curr) => acc + curr, 0); diff --git a/tests/tools_tests/rescript.json b/tests/tools_tests/rescript.json index c7968f1bf4..d901f81336 100644 --- a/tests/tools_tests/rescript.json +++ b/tests/tools_tests/rescript.json @@ -5,7 +5,7 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, "suffix": ".res.js", diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index 87ea7737ee..e69de29bb2 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -1,117 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - -let React = require("react"); - -console.log("ppx test"); - -console.log("ppx test"); - -let M = { - v: 10 -}; - -let OptionalFields = { - r: { - y: 1.0 - } -}; - -function one(x) { - return x; -} - -function two(x, y) { - return x + y | 0; -} - -let n = 6; - -let Arity = { - one: one, - two: two, - n: n -}; - -React.useState(() => 0); - -async function fpromise(promise, _x) { - return await promise; -} - -let Uncurried = {}; - -async function async_succ(x) { - return x + 1 | 0; -} - -async function async_foo(x, y) { - let a = async_succ(x); - let b = async_succ(y); - return await a + await b | 0; -} - -function add(x, y) { - return x + y | 0; -} - -function partial_add(extra) { - return 3 + extra | 0; -} - -function plus(x, y) { - return x + y | 0; -} - -let z = 3; - -let Pipe = { - plus: plus, - z: z -}; - -let concat = "ab"; - -async function test() { - return 12; -} - -async function f() { - return await test() + 1 | 0; -} - -let a = "A"; - -let b = "B"; - -let vv = 10; - -let neq = false; - -let neq2 = false; - -let eq = true; - -let eq2 = true; - -exports.a = a; -exports.b = b; -exports.M = M; -exports.vv = vv; -exports.OptionalFields = OptionalFields; -exports.Arity = Arity; -exports.fpromise = fpromise; -exports.Uncurried = Uncurried; -exports.async_succ = async_succ; -exports.async_foo = async_foo; -exports.add = add; -exports.partial_add = partial_add; -exports.Pipe = Pipe; -exports.concat = concat; -exports.neq = neq; -exports.neq2 = neq2; -exports.eq = eq; -exports.eq2 = eq2; -exports.test = test; -exports.f = f; -/* Not a pure module */ diff --git a/tools/rescript.json b/tools/rescript.json index 26ece932ef..1fa23c615a 100644 --- a/tools/rescript.json +++ b/tools/rescript.json @@ -6,9 +6,9 @@ "dir": "npm" } ], - "suffix": ".bs.js", + "suffix": ".res.js", "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": false } } From 5b04b25c3498d061abb609504ddb2d5e13ef601b Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 15:09:56 +0900 Subject: [PATCH 12/37] Use CommonJS on the playground test, due to the limit of JSOO --- .github/workflows/ci.yml | 4 +- .gitignore | 2 +- CONTRIBUTING.md | 4 +- Makefile | 4 +- cli/rescript/rescript_dump.js | 53 ++++ cli/rescript/rescript_format.js | 253 ++++++++++++++++++ lib_dev/process.js | 2 + .../scripts/generate_cmijs.js | 4 +- ...playground_test.js => playground_test.cjs} | 7 +- 9 files changed, 321 insertions(+), 12 deletions(-) create mode 100644 cli/rescript/rescript_dump.js create mode 100644 cli/rescript/rescript_format.js rename playground/{playground_test.js => playground_test.cjs} (90%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98a432c13d..f49af3f48f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -401,11 +401,11 @@ jobs: run: | opam exec -- node packages/playground-bundling/scripts/generate_cmijs.js opam exec -- dune build --profile browser - cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js + cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs - name: Test playground compiler if: matrix.build_playground - run: node playground/playground_test.js + run: node playground/playground_test.cjs - name: Upload playground compiler to CDN if: ${{ matrix.build_playground && startsWith(github.ref, 'refs/tags/v') }} diff --git a/.gitignore b/.gitignore index c88c6d8ba9..f672ecca61 100644 --- a/.gitignore +++ b/.gitignore @@ -72,7 +72,7 @@ playground/stdlib/ playground/*.cmj playground/*.cmi playground/.netrc -playground/compiler.js +playground/compiler.*js rewatch/target/ rewatch/rewatch diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0fcea01340..c94e799ddc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -263,7 +263,7 @@ $ node ### Testing the Playground bundle -Run `node playground/playground_test.js` for a quick sanity check to see if all the build artifacts are working together correctly. When releasing the playground bundle, the test will always be executed before publishing to catch regressions. +Run `node playground/playground_test.cjs` for a quick sanity check to see if all the build artifacts are working together correctly. When releasing the playground bundle, the test will always be executed before publishing to catch regressions. ### Working on the Playground JS API @@ -273,7 +273,7 @@ Whenever you are modifying any files in the ReScript compiler, or in the `jsoo_p make playground # optionally run your test / arbitrary node script to verify your changes -node playground/playground_test.js +node playground/playground_test.cjs ``` ### Publishing the Playground Bundle on our KeyCDN diff --git a/Makefile b/Makefile index 67446c81d8..5f6677fc31 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ artifacts: lib # Builds the core playground bundle (without the relevant cmijs files for the runtime) playground: dune build --profile browser - cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.js + cp ./_build/default/compiler/jsoo/jsoo_playground_main.bc.js playground/compiler.cjs # Creates all the relevant core and third party cmij files to side-load together with the playground bundle playground-cmijs: artifacts @@ -70,7 +70,7 @@ playground-cmijs: artifacts # Builds the playground, runs some e2e tests and releases the playground to the # CDN (requires KEYCDN_USER and KEYCDN_PASSWORD set in the env variables) playground-release: playground playground-cmijs - node playground/playground_test.js + node playground/playground_test.cjs sh playground/upload_bundle.sh format: diff --git a/cli/rescript/rescript_dump.js b/cli/rescript/rescript_dump.js new file mode 100644 index 0000000000..9475956777 --- /dev/null +++ b/cli/rescript/rescript_dump.js @@ -0,0 +1,53 @@ +// @ts-check + +import * as child_process from "node:child_process"; +import * as path from "node:path"; + +import * as arg from "../_args.js"; + +const dump_usage = `Usage: rescript dump [target] +\`rescript dump\` dumps the information for the target +`; + +/** + * @type {arg.specs} + */ +const specs = []; + +/** + * @param {string[]} argv + * @param {string} rescript_exe + * @param {string} bsc_exe + */ +export function main(argv, rescript_exe, bsc_exe) { + let target; + arg.parse_exn(dump_usage, argv, specs, xs => { + if (xs.length !== 1) { + arg.bad_arg(`Expect only one target, ${xs.length} found`); + } + target = xs[0]; + }); + + const { ext } = path.parse(target); + if (ext !== ".cmi") { + console.error("Only .cmi target allowed"); + process.exit(2); + } + + let output = child_process.spawnSync(rescript_exe, ["build", "--", target], { + encoding: "utf-8", + }); + if (output.status !== 0) { + console.log(output.stdout); + console.error(output.stderr); + process.exit(2); + } + output = child_process.spawnSync(bsc_exe, [path.join("lib", "bs", target)], { + encoding: "utf-8", + }); + console.log(output.stdout.trimEnd()); + if (output.status !== 0) { + console.error(output.stderr); + process.exit(2); + } +} diff --git a/cli/rescript/rescript_format.js b/cli/rescript/rescript_format.js new file mode 100644 index 0000000000..747282cf9a --- /dev/null +++ b/cli/rescript/rescript_format.js @@ -0,0 +1,253 @@ +// @ts-check + +import * as child_process from "node:child_process"; +import * as crypto from "node:crypto"; +import * as fs from "node:fs"; +import * as asyncFs from "node:fs/promises"; +import * as os from "node:os"; +import * as path from "node:path"; +import { promisify } from "node:util"; + +import * as arg from "../_args.js"; + +const asyncExecFile = promisify(child_process.execFile); + +const format_usage = `Usage: rescript format [files] + +\`rescript format\` formats the current directory +`; + +/** + * @type {arg.stringref} + */ +const stdin = { val: "" }; + +/** + * @type {arg.boolref} + */ +const format = { val: false }; + +/** + * @type {arg.boolref} + */ +const check = { val: false }; + +/** + * @type{arg.specs} + */ +const specs = [ + [ + "-stdin", + { kind: "String", data: { kind: "String_set", data: stdin } }, + `[.res|.resi] Read the code from stdin and print +the formatted code to stdout in ReScript syntax`, + ], + [ + "-all", + { kind: "Unit", data: { kind: "Unit_set", data: format } }, + "Format the whole project ", + ], + [ + "-check", + { kind: "Unit", data: { kind: "Unit_set", data: check } }, + "Check formatting for file or the whole project. Use `-all` to check the whole project", + ], +]; +const formattedStdExtensions = [".res", ".resi"]; +const formattedFileExtensions = [".res", ".resi"]; + +/** + * + * @param {string[]} extensions + */ +function hasExtension(extensions) { + /** + * @param {string} x + */ + const pred = x => extensions.some(ext => x.endsWith(ext)); + return pred; +} +async function readStdin() { + const stream = process.stdin; + const chunks = []; + for await (const chunk of stream) chunks.push(chunk); + return Buffer.concat(chunks).toString("utf8"); +} + +const _numThreads = os.cpus().length; + +/** + * Splits an array into smaller chunks of a specified size. + * + * @template T + * @param {T[]} array - The array to split into chunks. + * @param {number} chunkSize - The size of each chunk. + * @returns {T[][]} - An array of chunks, where each chunk is an array of type T. + */ +function chunkArray(array, chunkSize) { + /** @type {T[][]} */ + const result = []; + + for (let i = 0; i < array.length; i += chunkSize) { + result.push(array.slice(i, i + chunkSize)); + } + + return result; +} + +/** + * @param {string[]} files + * @param {string} bsc_exe + * @param {(x: string) => boolean} isSupportedFile + * @param {boolean} checkFormatting + */ +async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) { + const supportedFiles = files.filter(isSupportedFile); + const batchSize = 4 * os.cpus().length; + const batches = chunkArray(supportedFiles, batchSize); + + let incorrectlyFormattedFiles = 0; + try { + for (const batch of batches) { + await Promise.all( + batch.map(async file => { + const flags = checkFormatting + ? ["-format", file] + : ["-o", file, "-format", file]; + const { stdout } = await asyncExecFile(bsc_exe, flags); + if (check.val) { + const original = await asyncFs.readFile(file, "utf-8"); + if (original !== stdout) { + console.error("[format check]", file); + incorrectlyFormattedFiles++; + } + } + }), + ); + } + } catch (err) { + console.error(err); + process.exit(2); + } + if (incorrectlyFormattedFiles > 0) { + if (incorrectlyFormattedFiles === 1) { + console.error("The file listed above needs formatting"); + } else { + console.error( + `The ${incorrectlyFormattedFiles} files listed above need formatting`, + ); + } + process.exit(3); + } +} + +/** + * @param {string[]} argv + * @param {string} rescript_exe + * @param {string} bsc_exe + */ +export async function main(argv, rescript_exe, bsc_exe) { + const isSupportedFile = hasExtension(formattedFileExtensions); + const isSupportedStd = hasExtension(formattedStdExtensions); + + try { + /** + * @type {string[]} + */ + let files = []; + arg.parse_exn(format_usage, argv, specs, xs => { + files = xs; + }); + + const format_project = format.val; + const use_stdin = stdin.val; + + // Only -check arg + // Require: -all or path to a file + if (check.val && !format_project && files.length === 0) { + console.error( + "format check require path to a file or use `-all` to check the whole project", + ); + process.exit(2); + } + + if (format_project) { + if (use_stdin || files.length !== 0) { + console.error("format -all can not be in use with other flags"); + process.exit(2); + } + // -all + // TODO: check the rest arguments + const output = child_process.spawnSync( + rescript_exe, + ["info", "-list-files"], + { + encoding: "utf-8", + }, + ); + if (output.status !== 0) { + console.error(output.stdout); + console.error(output.stderr); + process.exit(2); + } + files = output.stdout.split("\n").map(x => x.trim()); + await formatFiles(files, bsc_exe, isSupportedFile, check.val); + } else if (use_stdin) { + if (check.val) { + console.error("format -stdin cannot be used with -check flag"); + process.exit(2); + } + if (isSupportedStd(use_stdin)) { + const filename = path.join( + os.tmpdir(), + `rescript_${crypto.randomBytes(8).toString("hex")}${path.parse(use_stdin).base}`, + ); + (async () => { + const content = await readStdin(); + const fd = fs.openSync(filename, "wx", 0o600); // Avoid overwriting existing file + fs.writeFileSync(fd, content, "utf8"); + fs.closeSync(fd); + process.addListener("exit", () => fs.unlinkSync(filename)); + child_process.execFile( + bsc_exe, + ["-format", filename], + (error, stdout, stderr) => { + if (error === null) { + process.stdout.write(stdout); + } else { + console.error(stderr); + process.exit(2); + } + }, + ); + })(); + } else { + console.error(`Unsupported extension ${use_stdin}`); + console.error(`Supported extensions: ${formattedStdExtensions} `); + process.exit(2); + } + } else { + if (files.length === 0) { + // none of argumets set + // format the current directory + files = fs.readdirSync(process.cwd()).filter(isSupportedFile); + } + + for (const file of files) { + if (!isSupportedStd(file)) { + console.error(`Don't know what do with ${file}`); + console.error(`Supported extensions: ${formattedFileExtensions}`); + process.exit(2); + } + } + await formatFiles(files, bsc_exe, isSupportedFile, check.val); + } + } catch (e) { + if (e instanceof arg.ArgError) { + console.error(e.message); + process.exit(2); + } else { + throw e; + } + } +} diff --git a/lib_dev/process.js b/lib_dev/process.js index f98aa6afec..b6e0d1c019 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -44,6 +44,8 @@ export function setup(cwd = process.cwd()) { const subprocess = child_process.spawn(command, args, { cwd, + // Enable shell mode only in Windows for performance + shell: process.platform === 'win32', stdio: ["ignore", "pipe", "pipe"], ...options, }); diff --git a/packages/playground-bundling/scripts/generate_cmijs.js b/packages/playground-bundling/scripts/generate_cmijs.js index 9ce2004647..e47e7ff5a1 100644 --- a/packages/playground-bundling/scripts/generate_cmijs.js +++ b/packages/playground-bundling/scripts/generate_cmijs.js @@ -71,7 +71,7 @@ function buildCompilerCmij() { const outputFolder = path.join(PACKAGES_DIR, "compiler-builtins"); - const cmijFile = path.join(outputFolder, "cmij.js"); + const cmijFile = path.join(outputFolder, "cmij.cjs"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); @@ -100,7 +100,7 @@ function buildThirdPartyCmijs() { ); const outputFolder = path.join(PACKAGES_DIR, pkg); - const cmijFile = path.join(outputFolder, "cmij.js"); + const cmijFile = path.join(outputFolder, "cmij.cjs"); if (!fs.existsSync(outputFolder)) { fs.mkdirSync(outputFolder, { recursive: true }); diff --git a/playground/playground_test.js b/playground/playground_test.cjs similarity index 90% rename from playground/playground_test.js rename to playground/playground_test.cjs index 134d518de8..763aebb094 100644 --- a/playground/playground_test.js +++ b/playground/playground_test.cjs @@ -1,8 +1,9 @@ // Playground bundle is UMD module // It uses `module.exports` in current context, or fallback to `globalThis` -import "./compiler.js"; -import "./packages/compiler-builtins/cmij.js"; -import "./packages/@rescript/react/cmij.js"; +const { rescript_compiler } = require("./compiler.js"); + +require("./packages/compiler-builtins/cmij.cjs"); +require("./packages/@rescript/react/cmij.cjs"); const compiler = rescript_compiler.make(); From 55b59e2819bcbca10fe679378b312f0f43928791 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 16:35:30 +0900 Subject: [PATCH 13/37] format --- lib_dev/process.js | 4 ++-- package.json | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index b6e0d1c019..bba3838f75 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -32,6 +32,7 @@ export function setupWithUrl(url) { * @param {string} [cwd] */ export function setup(cwd = process.cwd()) { + /** * @param {string} command * @param {string[]} [args] @@ -44,8 +45,7 @@ export function setup(cwd = process.cwd()) { const subprocess = child_process.spawn(command, args, { cwd, - // Enable shell mode only in Windows for performance - shell: process.platform === 'win32', + shell: process.platform === "win32", stdio: ["ignore", "pipe", "pipe"], ...options, }); diff --git a/package.json b/package.json index d2ed451148..9ae938378c 100644 --- a/package.json +++ b/package.json @@ -50,6 +50,7 @@ "test-ocaml": "node scripts/test.js -ounit", "check": "biome check --changed --no-errors-on-unmatched .", "check:all": "biome check .", + "format": "biome check --changed --no-errors-on-unmatched . --fix", "coverage": "nyc --timeout=3000 --reporter=html mocha tests/tests/src/*_test.js && open ./coverage/index.html", "typecheck": "tsc" }, From 72492fe68b66218183ddee941d0c94b5bee15c69 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 17:02:36 +0900 Subject: [PATCH 14/37] windows... so painful --- cli/rescript.js | 2 +- lib_dev/process.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/rescript.js b/cli/rescript.js index 54ae2278dc..b28ca4c5db 100755 --- a/cli/rescript.js +++ b/cli/rescript.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -//@ts-check +// @ts-check // This script is supposed to be running in project root directory // It matters since we need read .sourcedirs(location) diff --git a/lib_dev/process.js b/lib_dev/process.js index bba3838f75..680520be60 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -129,7 +129,7 @@ export function setup(cwd = process.cwd()) { * @return {Promise} */ rescript(command, args = [], options = {}) { - return exec(cliPath, [command, ...args].filter(Boolean), options); + return exec("node", [cliPath, command, ...args].filter(Boolean), options); }, /** From 798ed6e454a48b766d84c00ce653759138c92f9c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 17:12:45 +0900 Subject: [PATCH 15/37] update artifacts --- packages/artifacts.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/artifacts.txt b/packages/artifacts.txt index 66f14ed9f9..cad23c4ab0 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -4,15 +4,15 @@ COPYING.LESSER CREDITS.md LICENSE README.md -cli/bin_path.js -cli/bsc -cli/rescript -cli/rescript-tools -cli/rescript_arg.js -cli/rescript_bsb.js -cli/rescript_dump.js -cli/rescript_format.js -cli/rewatch +cli/_args.js +cli/_bsb.js +cli/_paths.js +cli/bsc.js +cli/rescript-tools.js +cli/rescript.js +cli/rescript/rescript_dump.js +cli/rescript/rescript_format.js +cli/rewatch.js darwin/bsb_helper.exe darwin/bsc.exe darwin/ninja.exe From 8f71a3c4a1733b7d0c263656c7b9f45d65738def Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 17:29:04 +0900 Subject: [PATCH 16/37] fix json imports --- .github/workflows/prepare_package_upload.js | 4 +++- scripts/setVersion.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/prepare_package_upload.js b/.github/workflows/prepare_package_upload.js index 2dc41b7e1f..680b58b7ae 100644 --- a/.github/workflows/prepare_package_upload.js +++ b/.github/workflows/prepare_package_upload.js @@ -1,7 +1,9 @@ import * as fs from "node:fs"; import * as os from "node:os"; -import { version } from "rescript/package.json" with { type: "json" }; +import packageSpec from "rescript/package.json" with { type: "json" }; + +const { version } = packageSpec; const commitHash = process.argv[2] || process.env.GITHUB_SHA; const commitHashShort = commitHash.substring(0, 7); diff --git a/scripts/setVersion.js b/scripts/setVersion.js index f2d30339bb..24d39f7ccd 100644 --- a/scripts/setVersion.js +++ b/scripts/setVersion.js @@ -3,7 +3,9 @@ // @ts-check import fs from "node:fs"; -import { name, version } from "rescript/package.json" with { type: "json" }; +import packageSpec from "rescript/package.json" with { type: "json" }; + +const { name, version } = packageSpec; const stdlibPackageSpec = JSON.parse( fs.readFileSync("./packages/std/package.json", "utf8"), From 77572e0f8613d95cde130f69274772f9aa3adb82 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 23:17:45 +0900 Subject: [PATCH 17/37] use `import.meta.dirname` --- cli/_paths.js | 11 ++++++----- lib_dev/paths.js | 5 +---- lib_dev/process.js | 10 ---------- lib_dev/utils.js | 10 ---------- packages/playground-bundling/rollup.config.mjs | 5 +---- .../playground-bundling/scripts/generate_cmijs.js | 12 +++++++----- tests/build_tests/build_warn_as_error/input.js | 4 ++-- tests/build_tests/case/input.js | 4 ++-- tests/build_tests/case2/input.js | 4 ++-- tests/build_tests/case3/input.js | 4 ++-- tests/build_tests/cli_compile_status/input.js | 4 ++-- tests/build_tests/cli_help/input.js | 4 ++-- tests/build_tests/custom_namespace/input.js | 4 ++-- tests/build_tests/cycle/input.js | 4 ++-- tests/build_tests/cycle1/input.js | 4 ++-- tests/build_tests/deprecated-package-specs/input.js | 4 ++-- tests/build_tests/devonly/input.js | 4 ++-- .../duplicated_symlinked_packages/input.js | 9 +++------ tests/build_tests/exports/input.js | 4 ++-- tests/build_tests/gpr_978/input.js | 4 ++-- tests/build_tests/hyphen2/input.js | 4 ++-- tests/build_tests/in_source/input.js | 4 ++-- tests/build_tests/install/input.js | 4 ++-- tests/build_tests/jsx_settings_inheritance/input.js | 4 ++-- tests/build_tests/nested/input.js | 4 ++-- tests/build_tests/nnest/input.js | 13 ++----------- tests/build_tests/ns/input.js | 4 ++-- tests/build_tests/post-build/input.js | 4 ++-- tests/build_tests/react_ppx/input.js | 4 ++-- tests/build_tests/rerror/input.js | 4 ++-- tests/build_tests/scoped_ppx/input.js | 4 ++-- tests/build_tests/super_errors/input.js | 10 ++++------ tests/build_tests/unboxed_bool_with_const/input.js | 4 ++-- tests/build_tests/uncurried-always/input.js | 4 ++-- tests/build_tests/unicode/input.js | 4 ++-- tests/build_tests/warn_legacy_config/input.js | 4 ++-- tests/build_tests/weird_deps/input.js | 4 ++-- tests/build_tests/weird_devdeps/input.js | 4 ++-- tests/build_tests/weird_names/input.js | 4 ++-- .../build_tests/weird_names_not_found_bug/input.js | 4 ++-- tests/build_tests/x-y/input.js | 4 ++-- tests/build_tests/xpkg/input.js | 4 ++-- tests/build_tests/zerocycle/input.js | 4 ++-- 43 files changed, 92 insertions(+), 129 deletions(-) diff --git a/cli/_paths.js b/cli/_paths.js index 4e7d2b2640..a4666766a9 100644 --- a/cli/_paths.js +++ b/cli/_paths.js @@ -1,11 +1,8 @@ // @ts-check import * as path from "node:path"; -import { fileURLToPath } from "node:url"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -export const cliPath = path.join(__dirname, "rescript.js"); +export const cliPath = path.join(import.meta.dirname, "rescript.js"); /** * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. @@ -19,7 +16,11 @@ export const platformName = ? process.platform : process.platform + process.arch; -export const platformDir = path.resolve(__dirname, "..", platformName); +export const platformDir = path.resolve( + import.meta.dirname, + "..", + platformName, +); export const bsc_exe = path.join(platformDir, "bsc.exe"); diff --git a/lib_dev/paths.js b/lib_dev/paths.js index dafc2a2e0a..35da5c5593 100644 --- a/lib_dev/paths.js +++ b/lib_dev/paths.js @@ -1,14 +1,11 @@ // @ts-check import * as path from "node:path"; -import { fileURLToPath } from "node:url"; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); /** * The project root path */ -export const projectDir = path.resolve(__dirname, ".."); +export const projectDir = path.resolve(import.meta.dirname, ".."); /** * path: `/compiler/` diff --git a/lib_dev/process.js b/lib_dev/process.js index 680520be60..23aeb5efb0 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -1,6 +1,4 @@ import * as child_process from "node:child_process"; -import * as path from "node:path"; -import { fileURLToPath } from "node:url"; import { bsc_exe, cliPath, rescript_exe } from "#cli/paths"; /** @@ -21,18 +19,10 @@ const signals = { export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } = setup(); -/** - * @param {string} url - */ -export function setupWithUrl(url) { - return setup(path.dirname(fileURLToPath(url))); -} - /** * @param {string} [cwd] */ export function setup(cwd = process.cwd()) { - /** * @param {string} command * @param {string[]} [args] diff --git a/lib_dev/utils.js b/lib_dev/utils.js index 36ff8f53a3..642811bdf9 100644 --- a/lib_dev/utils.js +++ b/lib_dev/utils.js @@ -1,13 +1,3 @@ -/** - * `import.meta.dirname` alternative. It is available since Node.js v20.11.0 - * - * @param {string} url `import.meta.url` - * @return {string} - */ -export function getDirname(url) { - return path.dirname(fileURLToPath(url)); -} - /** * @param {string} s */ diff --git a/packages/playground-bundling/rollup.config.mjs b/packages/playground-bundling/rollup.config.mjs index 4768a6071f..21f6260b44 100644 --- a/packages/playground-bundling/rollup.config.mjs +++ b/packages/playground-bundling/rollup.config.mjs @@ -1,11 +1,8 @@ import * as path from "node:path"; -import { fileURLToPath } from "node:url"; import nodeResolve from "@rollup/plugin-node-resolve"; import { glob } from "glob"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", ".."); +const RESCRIPT_COMPILER_ROOT_DIR = path.join(import.meta.dirname, "..", ".."); const LIB_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "lib"); const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); // Final target output directory where all the cmijs will be stored diff --git a/packages/playground-bundling/scripts/generate_cmijs.js b/packages/playground-bundling/scripts/generate_cmijs.js index e47e7ff5a1..7d0df1e877 100644 --- a/packages/playground-bundling/scripts/generate_cmijs.js +++ b/packages/playground-bundling/scripts/generate_cmijs.js @@ -18,17 +18,19 @@ import * as child_process from "node:child_process"; import * as fs from "node:fs"; import * as path from "node:path"; -import { fileURLToPath } from "node:url"; import resConfig from "../rescript.json" with { type: "json" }; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const RESCRIPT_COMPILER_ROOT_DIR = path.join(__dirname, "..", "..", ".."); +const RESCRIPT_COMPILER_ROOT_DIR = path.join( + import.meta.dirname, + "..", + "..", + "..", +); const PLAYGROUND_DIR = path.join(RESCRIPT_COMPILER_ROOT_DIR, "playground"); // The playground-bundling root dir -const PROJECT_ROOT_DIR = path.join(__dirname, ".."); +const PROJECT_ROOT_DIR = path.join(import.meta.dirname, ".."); // Final target output directory where all the cmijs will be stored const PACKAGES_DIR = path.join(PLAYGROUND_DIR, "packages"); diff --git a/tests/build_tests/build_warn_as_error/input.js b/tests/build_tests/build_warn_as_error/input.js index 5ebaf29085..17a0bdd42b 100644 --- a/tests/build_tests/build_warn_as_error/input.js +++ b/tests/build_tests/build_warn_as_error/input.js @@ -1,7 +1,7 @@ import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); const o1 = await execBuild(); diff --git a/tests/build_tests/case/input.js b/tests/build_tests/case/input.js index 004fbcc6a8..f91b89964c 100644 --- a/tests/build_tests/case/input.js +++ b/tests/build_tests/case/input.js @@ -1,8 +1,8 @@ import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const { stderr } = await execBuild(); diff --git a/tests/build_tests/case2/input.js b/tests/build_tests/case2/input.js index 364a2e3fe3..2b5299779f 100644 --- a/tests/build_tests/case2/input.js +++ b/tests/build_tests/case2/input.js @@ -1,10 +1,10 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const { stderr } = await execBuild(); diff --git a/tests/build_tests/case3/input.js b/tests/build_tests/case3/input.js index a761ec1c30..45d78e684a 100644 --- a/tests/build_tests/case3/input.js +++ b/tests/build_tests/case3/input.js @@ -3,9 +3,9 @@ import assert from "node:assert"; import fs from "node:fs/promises"; import path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/cli_compile_status/input.js b/tests/build_tests/cli_compile_status/input.js index f91271267e..c26e567862 100755 --- a/tests/build_tests/cli_compile_status/input.js +++ b/tests/build_tests/cli_compile_status/input.js @@ -1,10 +1,10 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescript } = setupWithUrl(import.meta.url); +const { rescript } = setup(import.meta.dirname); // Shows compile time for `rescript build` command let out = await rescript("build"); diff --git a/tests/build_tests/cli_help/input.js b/tests/build_tests/cli_help/input.js index 7b18ed8985..facfbecf2b 100755 --- a/tests/build_tests/cli_help/input.js +++ b/tests/build_tests/cli_help/input.js @@ -1,10 +1,10 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { rescript } = setupWithUrl(import.meta.url); +const { rescript } = setup(import.meta.dirname); const cliHelp = "Usage: rescript \n" + diff --git a/tests/build_tests/custom_namespace/input.js b/tests/build_tests/custom_namespace/input.js index feaf4ba8ec..718d172356 100644 --- a/tests/build_tests/custom_namespace/input.js +++ b/tests/build_tests/custom_namespace/input.js @@ -1,7 +1,7 @@ import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execClean, execBuild } = setupWithUrl(import.meta.url); +const { execClean, execBuild } = setup(import.meta.dirname); await execClean(); await execBuild(); diff --git a/tests/build_tests/cycle/input.js b/tests/build_tests/cycle/input.js index fd9ccf5d65..a35f908978 100644 --- a/tests/build_tests/cycle/input.js +++ b/tests/build_tests/cycle/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const output = await execBuild(); diff --git a/tests/build_tests/cycle1/input.js b/tests/build_tests/cycle1/input.js index 500caf5bd0..83e04e104e 100644 --- a/tests/build_tests/cycle1/input.js +++ b/tests/build_tests/cycle1/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); await execClean(); const output = await execBuild(); diff --git a/tests/build_tests/deprecated-package-specs/input.js b/tests/build_tests/deprecated-package-specs/input.js index 467f4fd689..a4a4ed69d1 100644 --- a/tests/build_tests/deprecated-package-specs/input.js +++ b/tests/build_tests/deprecated-package-specs/input.js @@ -1,9 +1,9 @@ // @ts-check import assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const out = await execBuild(); assert.match( diff --git a/tests/build_tests/devonly/input.js b/tests/build_tests/devonly/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/devonly/input.js +++ b/tests/build_tests/devonly/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/duplicated_symlinked_packages/input.js b/tests/build_tests/duplicated_symlinked_packages/input.js index 49a171a9b3..f15c2adcb9 100644 --- a/tests/build_tests/duplicated_symlinked_packages/input.js +++ b/tests/build_tests/duplicated_symlinked_packages/input.js @@ -1,12 +1,9 @@ // @ts-check import * as fs from "node:fs/promises"; -import * as path from "node:path"; -import { fileURLToPath } from "node:url"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); const expectedFilePath = "./out.expected"; @@ -17,7 +14,7 @@ const updateTests = process.argv[2] === "update"; * @return {string} */ function postProcessErrorOutput(output) { - return output.trimEnd().replace(new RegExp(__dirname, "gi"), "."); + return output.trimEnd().replace(new RegExp(import.meta.dirname, "gi"), "."); } if (process.platform === "win32") { diff --git a/tests/build_tests/exports/input.js b/tests/build_tests/exports/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/exports/input.js +++ b/tests/build_tests/exports/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/gpr_978/input.js b/tests/build_tests/gpr_978/input.js index 4215a9e349..384a36e77a 100644 --- a/tests/build_tests/gpr_978/input.js +++ b/tests/build_tests/gpr_978/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const output = await execBuild(); assert.match(output.stdout, /M is exported twice/); diff --git a/tests/build_tests/hyphen2/input.js b/tests/build_tests/hyphen2/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/hyphen2/input.js +++ b/tests/build_tests/hyphen2/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/in_source/input.js b/tests/build_tests/in_source/input.js index bf4e02b81e..f29b5a2e37 100644 --- a/tests/build_tests/in_source/input.js +++ b/tests/build_tests/in_source/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const output = await execBuild(["-regen"]); assert.match(output.stderr, /detected two module formats/); diff --git a/tests/build_tests/install/input.js b/tests/build_tests/install/input.js index 1233c731cd..4c7df0215d 100644 --- a/tests/build_tests/install/input.js +++ b/tests/build_tests/install/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import { existsSync } from "node:fs"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); await execClean(); await execBuild(["-install"]); diff --git a/tests/build_tests/jsx_settings_inheritance/input.js b/tests/build_tests/jsx_settings_inheritance/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/jsx_settings_inheritance/input.js +++ b/tests/build_tests/jsx_settings_inheritance/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/nested/input.js b/tests/build_tests/nested/input.js index 2b2300f8a0..68b05999ce 100644 --- a/tests/build_tests/nested/input.js +++ b/tests/build_tests/nested/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/nnest/input.js b/tests/build_tests/nnest/input.js index 8749f7886e..98da456f4d 100644 --- a/tests/build_tests/nnest/input.js +++ b/tests/build_tests/nnest/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); @@ -20,12 +20,3 @@ assert.equal(content.match(/b0_main/g)?.length, 1); const mod = await import("./src/demo.js"); assert.equal(mod.v, 4, "nested"); - -// var testWarnError = /warnings\s*=\s*[^\r\n]*-warn-error/; - -// function hasWarnError(file) { -// var content = fs.readFileSync(file, "utf8"); -// return testWarnError.test(content); -// } - -// assert.ok(hasWarnError(path.join(__dirname,'lib','bs','build.ninja'))) diff --git a/tests/build_tests/ns/input.js b/tests/build_tests/ns/input.js index 31848da96f..50a4ceabd1 100755 --- a/tests/build_tests/ns/input.js +++ b/tests/build_tests/ns/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/post-build/input.js b/tests/build_tests/post-build/input.js index 46d223ffc0..83fd43098f 100644 --- a/tests/build_tests/post-build/input.js +++ b/tests/build_tests/post-build/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); diff --git a/tests/build_tests/react_ppx/input.js b/tests/build_tests/react_ppx/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/react_ppx/input.js +++ b/tests/build_tests/react_ppx/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/rerror/input.js b/tests/build_tests/rerror/input.js index c47003a81e..70a81c8dba 100644 --- a/tests/build_tests/rerror/input.js +++ b/tests/build_tests/rerror/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); await execClean(); const output = await execBuild([]); diff --git a/tests/build_tests/scoped_ppx/input.js b/tests/build_tests/scoped_ppx/input.js index 4144cb4446..d3e3f06ee7 100644 --- a/tests/build_tests/scoped_ppx/input.js +++ b/tests/build_tests/scoped_ppx/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index f45ded172f..5f3eb8db68 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -3,14 +3,12 @@ import { readdirSync } from "node:fs"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { fileURLToPath } from "node:url"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const { bsc } = setupWithUrl(import.meta.url); +const { bsc } = setup(import.meta.dirname); -const expectedDir = path.join(__dirname, "expected"); +const expectedDir = path.join(import.meta.dirname, "expected"); const fixtures = readdirSync("fixtures").filter( fileName => path.extname(fileName) === ".res", @@ -38,7 +36,7 @@ let doneTasksCount = 0; let atLeastOneTaskFailed = false; for (const fileName of fixtures) { - const fullFilePath = path.join(__dirname, "fixtures", fileName); + const fullFilePath = path.join(import.meta.dirname, "fixtures", fileName); const { stderr } = await bsc([...prefix, "-color", "always", fullFilePath]); doneTasksCount++; // careful of: diff --git a/tests/build_tests/unboxed_bool_with_const/input.js b/tests/build_tests/unboxed_bool_with_const/input.js index 42c1a98a04..dd2470e600 100644 --- a/tests/build_tests/unboxed_bool_with_const/input.js +++ b/tests/build_tests/unboxed_bool_with_const/input.js @@ -1,10 +1,10 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const out = await execBuild(); diff --git a/tests/build_tests/uncurried-always/input.js b/tests/build_tests/uncurried-always/input.js index abca212e29..6d8beddd22 100644 --- a/tests/build_tests/uncurried-always/input.js +++ b/tests/build_tests/uncurried-always/input.js @@ -1,8 +1,8 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild, execClean } = setupWithUrl(import.meta.url); +const { execBuild, execClean } = setup(import.meta.dirname); await execClean(); await execBuild(); diff --git a/tests/build_tests/unicode/input.js b/tests/build_tests/unicode/input.js index e4385bac6c..4723a8f55c 100644 --- a/tests/build_tests/unicode/input.js +++ b/tests/build_tests/unicode/input.js @@ -3,9 +3,9 @@ import * as assert from "node:assert"; import * as fs from "node:fs/promises"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); if (process.platform === "win32") { console.log("Skipping test on Windows"); diff --git a/tests/build_tests/warn_legacy_config/input.js b/tests/build_tests/warn_legacy_config/input.js index 433b55f9b9..e079332080 100644 --- a/tests/build_tests/warn_legacy_config/input.js +++ b/tests/build_tests/warn_legacy_config/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const output = await execBuild(); assert.match( diff --git a/tests/build_tests/weird_deps/input.js b/tests/build_tests/weird_deps/input.js index 1153a7c2c0..b5d4af7317 100644 --- a/tests/build_tests/weird_deps/input.js +++ b/tests/build_tests/weird_deps/input.js @@ -1,10 +1,10 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; import { normalizeNewlines } from "#dev/utils"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const out = await execBuild(); if (out.stdout !== "") { diff --git a/tests/build_tests/weird_devdeps/input.js b/tests/build_tests/weird_devdeps/input.js index 5a09c80b73..fa9afcce6c 100644 --- a/tests/build_tests/weird_devdeps/input.js +++ b/tests/build_tests/weird_devdeps/input.js @@ -2,9 +2,9 @@ import * as assert from "node:assert"; import * as os from "node:os"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const out = await execBuild(); if (out.stdout !== "") { diff --git a/tests/build_tests/weird_names/input.js b/tests/build_tests/weird_names/input.js index 9396a7d728..56347603ae 100644 --- a/tests/build_tests/weird_names/input.js +++ b/tests/build_tests/weird_names/input.js @@ -2,9 +2,9 @@ import * as assert from "node:assert"; import * as path from "node:path"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const out = await execBuild(); diff --git a/tests/build_tests/weird_names_not_found_bug/input.js b/tests/build_tests/weird_names_not_found_bug/input.js index b2427bcee3..078fb29aed 100644 --- a/tests/build_tests/weird_names_not_found_bug/input.js +++ b/tests/build_tests/weird_names_not_found_bug/input.js @@ -1,7 +1,7 @@ import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = await setupWithUrl(import.meta.url); +const { execBuild } = await setup(import.meta.dirname); const out = await execBuild(); diff --git a/tests/build_tests/x-y/input.js b/tests/build_tests/x-y/input.js index 31848da96f..50a4ceabd1 100644 --- a/tests/build_tests/x-y/input.js +++ b/tests/build_tests/x-y/input.js @@ -1,7 +1,7 @@ // @ts-check -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); await execBuild(); diff --git a/tests/build_tests/xpkg/input.js b/tests/build_tests/xpkg/input.js index beece0fe1c..664cb16cd1 100644 --- a/tests/build_tests/xpkg/input.js +++ b/tests/build_tests/xpkg/input.js @@ -1,9 +1,9 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = await setupWithUrl(import.meta.url); +const { execBuild } = await setup(import.meta.dirname); const output = await execBuild(["-regen"]); assert.match(output.stderr, /reserved package name/); diff --git a/tests/build_tests/zerocycle/input.js b/tests/build_tests/zerocycle/input.js index 1b0290a27d..c81430b7c7 100644 --- a/tests/build_tests/zerocycle/input.js +++ b/tests/build_tests/zerocycle/input.js @@ -1,8 +1,8 @@ // @ts-check import * as assert from "node:assert"; -import { setupWithUrl } from "#dev/process"; +import { setup } from "#dev/process"; -const { execBuild } = setupWithUrl(import.meta.url); +const { execBuild } = setup(import.meta.dirname); const output = await execBuild(); assert.ok(output.status === 0); From f11159acb7a3b668a9951cc915407f7340961f86 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sun, 23 Mar 2025 23:31:16 +0900 Subject: [PATCH 18/37] specify node version --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f49af3f48f..32e436b8f1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,11 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + - name: Restore build cache id: build-cache uses: actions/cache@v4 From 9de8d73f173c99eb6f7f8f1759acda8865d27965 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Mon, 24 Mar 2025 01:36:18 +0900 Subject: [PATCH 19/37] Update scripts/prebuilt.js Co-authored-by: Christoph Knittel --- scripts/prebuilt.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/prebuilt.js b/scripts/prebuilt.js index c1c12b3ce3..6f3f2c43fd 100755 --- a/scripts/prebuilt.js +++ b/scripts/prebuilt.js @@ -29,10 +29,10 @@ assert.ok(bsVersionMatch, "Failed to parse the compiler version file"); const bsVersion = semver.parse(bsVersionMatch.version); assert.ok(bsVersion, "Failed to parse the compiler version file"); -const pakageVersion = semver.parse(packageJson.version); -assert.ok(pakageVersion, "Failed to parse the version of the package.json"); +const packageVersion = semver.parse(packageJson.version); +assert.ok(packageVersion, "Failed to parse the version of the package.json"); assert.ok( - verifyVersion(bsVersion, pakageVersion), + verifyVersion(bsVersion, packageVersion), `Bump the compiler version in ${compilerVersionFile}`, ); From d0906c05932d97faf001c2c30447207f005924b8 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 02:41:09 +0900 Subject: [PATCH 20/37] udpate lockfile --- yarn.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yarn.lock b/yarn.lock index 45581b1398..1c16e6ea60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2135,11 +2135,11 @@ __metadata: semver: "npm:7.6.2" typescript: "npm:5.5.3" bin: - bsc: cli/bsc - bstracing: lib/bstracing - rescript: cli/rescript - rescript-tools: cli/rescript-tools - rewatch: cli/rewatch + bsc: cli/bsc.js + bstracing: lib/bstracing.js + rescript: cli/rescript.js + rescript-tools: cli/rescript-tools.js + rewatch: cli/rewatch.js languageName: unknown linkType: soft From bf00f116da7c76a714a089c8251228bff2c51399 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 03:06:17 +0900 Subject: [PATCH 21/37] ts noEmit --- cli/bsc.js | 2 +- cli/{_args.js => common/args.js} | 0 cli/{_bsb.js => common/bsb.js} | 2 +- cli/{_paths.js => common/paths.js} | 2 +- cli/rescript-tools.js | 2 +- cli/rescript.js | 8 ++++---- cli/rescript/{rescript_dump.js => dump.js} | 2 +- cli/rescript/{rescript_format.js => format.js} | 2 +- cli/rewatch.js | 2 +- package.json | 6 +++--- .../gentype_tests/typescript-react-example/tsconfig.json | 1 + 11 files changed, 15 insertions(+), 14 deletions(-) rename cli/{_args.js => common/args.js} (100%) rename cli/{_bsb.js => common/bsb.js} (99%) rename cli/{_paths.js => common/paths.js} (93%) rename cli/rescript/{rescript_dump.js => dump.js} (97%) rename cli/rescript/{rescript_format.js => format.js} (99%) diff --git a/cli/bsc.js b/cli/bsc.js index 144fae71c7..b434c6b734 100755 --- a/cli/bsc.js +++ b/cli/bsc.js @@ -4,7 +4,7 @@ import { execFileSync } from "node:child_process"; -import { bsc_exe } from "./_paths.js"; +import { bsc_exe } from "#cli/paths"; const delegate_args = process.argv.slice(2); diff --git a/cli/_args.js b/cli/common/args.js similarity index 100% rename from cli/_args.js rename to cli/common/args.js diff --git a/cli/_bsb.js b/cli/common/bsb.js similarity index 99% rename from cli/_bsb.js rename to cli/common/bsb.js index 9b378e6ba3..a5b9c49c5e 100644 --- a/cli/_bsb.js +++ b/cli/common/bsb.js @@ -7,7 +7,7 @@ import * as os from "node:os"; import * as path from "node:path"; import { WebSocket } from "#lib/minisocket"; -import { rescript_exe } from "./_paths.js"; +import { rescript_exe } from "./paths.js"; const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); diff --git a/cli/_paths.js b/cli/common/paths.js similarity index 93% rename from cli/_paths.js rename to cli/common/paths.js index a4666766a9..5d2d1ca7d3 100644 --- a/cli/_paths.js +++ b/cli/common/paths.js @@ -2,7 +2,7 @@ import * as path from "node:path"; -export const cliPath = path.join(import.meta.dirname, "rescript.js"); +export const cliPath = path.join(import.meta.dirname, "../rescript.js"); /** * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. diff --git a/cli/rescript-tools.js b/cli/rescript-tools.js index dd605df610..9d4d54ae00 100755 --- a/cli/rescript-tools.js +++ b/cli/rescript-tools.js @@ -4,7 +4,7 @@ import * as child_process from "node:child_process"; -import { rescript_tools_exe } from "./_paths.js"; +import { rescript_tools_exe } from "#cli/paths"; const args = process.argv.slice(2); diff --git a/cli/rescript.js b/cli/rescript.js index b28ca4c5db..77d6242072 100755 --- a/cli/rescript.js +++ b/cli/rescript.js @@ -9,8 +9,8 @@ import * as tty from "node:tty"; import packageJson from "rescript/package.json" with { type: "json" }; -import * as bsb from "./_bsb.js"; -import { bsc_exe, rescript_exe } from "./_paths.js"; +import * as bsb from "#cli/bsb"; +import { bsc_exe, rescript_exe } from "#cli/paths"; const cwd = process.cwd(); process.env.BSB_PROJECT_ROOT = cwd; @@ -112,12 +112,12 @@ if ( break; } case "format": { - const mod = await import("./rescript/rescript_format.js"); + const mod = await import("./rescript/format.js"); await mod.main(subcmdArgs, rescript_exe, bsc_exe); break; } case "dump": { - const mod = await import("./rescript/rescript_dump.js"); + const mod = await import("./rescript/dump.js"); mod.main(subcmdArgs, rescript_exe, bsc_exe); break; } diff --git a/cli/rescript/rescript_dump.js b/cli/rescript/dump.js similarity index 97% rename from cli/rescript/rescript_dump.js rename to cli/rescript/dump.js index 9475956777..bd1201e354 100644 --- a/cli/rescript/rescript_dump.js +++ b/cli/rescript/dump.js @@ -3,7 +3,7 @@ import * as child_process from "node:child_process"; import * as path from "node:path"; -import * as arg from "../_args.js"; +import * as arg from "#cli/args"; const dump_usage = `Usage: rescript dump [target] \`rescript dump\` dumps the information for the target diff --git a/cli/rescript/rescript_format.js b/cli/rescript/format.js similarity index 99% rename from cli/rescript/rescript_format.js rename to cli/rescript/format.js index 747282cf9a..1d9a8029a2 100644 --- a/cli/rescript/rescript_format.js +++ b/cli/rescript/format.js @@ -8,7 +8,7 @@ import * as os from "node:os"; import * as path from "node:path"; import { promisify } from "node:util"; -import * as arg from "../_args.js"; +import * as arg from "#cli/args"; const asyncExecFile = promisify(child_process.execFile); diff --git a/cli/rewatch.js b/cli/rewatch.js index 12d87fe662..b2c1eea758 100755 --- a/cli/rewatch.js +++ b/cli/rewatch.js @@ -3,7 +3,7 @@ // @ts-check import * as child_process from "node:child_process"; -import { rewatch_exe } from "./bin_path.js"; +import { rewatch_exe } from "#cli/paths"; const args = process.argv.slice(2); diff --git a/package.json b/package.json index 9ae938378c..a4eab970fd 100644 --- a/package.json +++ b/package.json @@ -73,9 +73,9 @@ "./package.json": "./package.json" }, "imports": { - "#cli/paths": "./cli/_paths.js", - "#lib/minisocket": "./lib/minisocket.js", - "#dev/*": "./lib_dev/*.js" + "#cli/*": "./cli/common/*.js", + "#dev/*": "./lib_dev/*.js", + "#lib/minisocket": "./lib/minisocket.js" }, "devDependencies": { "@biomejs/biome": "1.9.4", diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.json b/tests/gentype_tests/typescript-react-example/tsconfig.json index fd40382a73..9835ab7a74 100644 --- a/tests/gentype_tests/typescript-react-example/tsconfig.json +++ b/tests/gentype_tests/typescript-react-example/tsconfig.json @@ -7,6 +7,7 @@ "strict": true, "skipLibCheck": true, "allowJs": true, + "noEmit": true }, "include": ["src"] } From 9b50125a17b562227f7ec7a1cf981b5edcc73bc3 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 03:23:26 +0900 Subject: [PATCH 22/37] update artifacts --- packages/artifacts.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/artifacts.txt b/packages/artifacts.txt index cad23c4ab0..c6e6369cef 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -4,14 +4,21 @@ COPYING.LESSER CREDITS.md LICENSE README.md -cli/_args.js -cli/_bsb.js -cli/_paths.js cli/bsc.js +cli/common/args.js +cli/common/bsb.js +cli/common/paths.js +cli/linux/bsb_helper.exe +cli/linux/bsc.exe +cli/linux/ninja.exe +cli/linux/rescript-editor-analysis.exe +cli/linux/rescript-tools.exe +cli/linux/rescript.exe +cli/linux/rewatch.exe cli/rescript-tools.js cli/rescript.js -cli/rescript/rescript_dump.js -cli/rescript/rescript_format.js +cli/rescript/dump.js +cli/rescript/format.js cli/rewatch.js darwin/bsb_helper.exe darwin/bsc.exe From 345c93c3ed5258a546a2a96f5b7e2930e9a39c3a Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 03:47:07 +0900 Subject: [PATCH 23/37] make it fail early --- biome.json | 6 +++++- lib_dev/process.js | 24 ++++++++++++++++++++---- tests/build_tests/install/src/Foo.bs.js | 10 ---------- 3 files changed, 25 insertions(+), 15 deletions(-) delete mode 100644 tests/build_tests/install/src/Foo.bs.js diff --git a/biome.json b/biome.json index 29c14d9d4c..cea5d0afee 100644 --- a/biome.json +++ b/biome.json @@ -13,6 +13,9 @@ "nursery": { "noCommonJs": "error" }, + "suspicious": { + "noAssignInExpressions": "warn" + }, "correctness": { "useImportExtensions": "error", "noUndeclaredDependencies": "error", @@ -59,7 +62,8 @@ "lib/es6/**", "lib/js/**", "ninja/**", - "playground/packages/**", + "packages/**", + "playground/**", "*.bs.js", "*.res.js", "*.res.mjs", diff --git a/lib_dev/process.js b/lib_dev/process.js index 23aeb5efb0..2d85b51bca 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -19,6 +19,12 @@ const signals = { export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } = setup(); +/** + * @typedef {{ + * throwOnExit?: boolean, + * }} ExecOptions + */ + /** * @param {string} [cwd] */ @@ -26,10 +32,12 @@ export function setup(cwd = process.cwd()) { /** * @param {string} command * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {child_process.SpawnOptions & ExecOptions} [options] * @return {Promise} */ async function exec(command, args = [], options = {}) { + const { throwOnExit = true } = options; + const stdoutChunks = []; const stderrChunks = []; @@ -54,8 +62,12 @@ export function setup(cwd = process.cwd()) { }); subprocess.once("close", (exitCode, signal) => { - const stdout = Buffer.concat(stdoutChunks).toString("utf8"); - const stderr = Buffer.concat(stderrChunks).toString("utf8"); + const stdout = stdoutChunks.length + ? Buffer.concat(stdoutChunks).toString("utf8") + : null; + const stderr = stdoutChunks.length + ? Buffer.concat(stderrChunks).toString("utf8") + : null; let code = exitCode ?? 1; if (signals[signal]) { @@ -63,7 +75,11 @@ export function setup(cwd = process.cwd()) { code = signals[signal] + 128; } - resolve({ status: code, stdout, stderr }); + if (throwOnExit && code !== 0) { + reject({ status: code, stdout, stderr }); + } else { + resolve({ status: code, stdout, stderr }); + } }); }); } diff --git a/tests/build_tests/install/src/Foo.bs.js b/tests/build_tests/install/src/Foo.bs.js deleted file mode 100644 index cf2ea83c43..0000000000 --- a/tests/build_tests/install/src/Foo.bs.js +++ /dev/null @@ -1,10 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; - - -function main() { - console.log("hello"); -} - -exports.main = main; -/* No side effect */ From bcd94bd28755003935d4dfd0d3e642281715d0c3 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 04:15:01 +0900 Subject: [PATCH 24/37] fix bin path --- cli/bsc.js | 2 +- cli/common/{paths.js => bins.js} | 3 +-- cli/common/bsb.js | 2 +- cli/rescript-tools.js | 2 +- cli/rescript.js | 4 ++-- cli/rewatch.js | 2 +- lib_dev/process.js | 4 +++- package.json | 2 +- runtime/RescriptTools.res | 2 +- scripts/copyExes.js | 2 +- 10 files changed, 13 insertions(+), 12 deletions(-) rename cli/common/{paths.js => bins.js} (93%) diff --git a/cli/bsc.js b/cli/bsc.js index b434c6b734..711ccc17dd 100755 --- a/cli/bsc.js +++ b/cli/bsc.js @@ -4,7 +4,7 @@ import { execFileSync } from "node:child_process"; -import { bsc_exe } from "#cli/paths"; +import { bsc_exe } from "./common/bins.js"; const delegate_args = process.argv.slice(2); diff --git a/cli/common/paths.js b/cli/common/bins.js similarity index 93% rename from cli/common/paths.js rename to cli/common/bins.js index 5d2d1ca7d3..7472466062 100644 --- a/cli/common/paths.js +++ b/cli/common/bins.js @@ -2,8 +2,6 @@ import * as path from "node:path"; -export const cliPath = path.join(import.meta.dirname, "../rescript.js"); - /** * For compatibility reasons, if the architecture is x64, omit it from the bin directory name. * So we'll have "darwin", "linux" and "win32" for x64 arch, @@ -19,6 +17,7 @@ export const platformName = export const platformDir = path.resolve( import.meta.dirname, "..", + "..", platformName, ); diff --git a/cli/common/bsb.js b/cli/common/bsb.js index a5b9c49c5e..8f229f1aa7 100644 --- a/cli/common/bsb.js +++ b/cli/common/bsb.js @@ -7,7 +7,7 @@ import * as os from "node:os"; import * as path from "node:path"; import { WebSocket } from "#lib/minisocket"; -import { rescript_exe } from "./paths.js"; +import { rescript_exe } from "./bins.js"; const cwd = process.cwd(); const lockFileName = path.join(cwd, ".bsb.lock"); diff --git a/cli/rescript-tools.js b/cli/rescript-tools.js index 9d4d54ae00..a5f8e6f0eb 100755 --- a/cli/rescript-tools.js +++ b/cli/rescript-tools.js @@ -4,7 +4,7 @@ import * as child_process from "node:child_process"; -import { rescript_tools_exe } from "#cli/paths"; +import { rescript_tools_exe } from "./common/bins.js"; const args = process.argv.slice(2); diff --git a/cli/rescript.js b/cli/rescript.js index 77d6242072..83bcfef05d 100755 --- a/cli/rescript.js +++ b/cli/rescript.js @@ -9,8 +9,8 @@ import * as tty from "node:tty"; import packageJson from "rescript/package.json" with { type: "json" }; -import * as bsb from "#cli/bsb"; -import { bsc_exe, rescript_exe } from "#cli/paths"; +import { bsc_exe, rescript_exe } from "./common/bins.js"; +import * as bsb from "./common/bsb.js"; const cwd = process.cwd(); process.env.BSB_PROJECT_ROOT = cwd; diff --git a/cli/rewatch.js b/cli/rewatch.js index b2c1eea758..41377a387f 100755 --- a/cli/rewatch.js +++ b/cli/rewatch.js @@ -3,7 +3,7 @@ // @ts-check import * as child_process from "node:child_process"; -import { rewatch_exe } from "#cli/paths"; +import { rewatch_exe } from "./common/bins.js"; const args = process.argv.slice(2); diff --git a/lib_dev/process.js b/lib_dev/process.js index 2d85b51bca..383ffada5a 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -1,5 +1,6 @@ import * as child_process from "node:child_process"; -import { bsc_exe, cliPath, rescript_exe } from "#cli/paths"; +import * as path from "node:path"; +import { bsc_exe, rescript_exe } from "#cli/bins"; /** * @typedef {{ @@ -135,6 +136,7 @@ export function setup(cwd = process.cwd()) { * @return {Promise} */ rescript(command, args = [], options = {}) { + const cliPath = path.join(import.meta.dirname, "../cli/rescript.js"); return exec("node", [cliPath, command, ...args].filter(Boolean), options); }, diff --git a/package.json b/package.json index a4eab970fd..de6bdf250c 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "./package.json": "./package.json" }, "imports": { - "#cli/*": "./cli/common/*.js", + "#cli/bins": "./cli/common/bins.js", "#dev/*": "./lib_dev/*.js", "#lib/minisocket": "./lib/minisocket.js" }, diff --git a/runtime/RescriptTools.res b/runtime/RescriptTools.res index 35b6426e0e..ea41dd74eb 100644 --- a/runtime/RescriptTools.res +++ b/runtime/RescriptTools.res @@ -11,5 +11,5 @@ You can use this when you're already running a JS process and want to avoid the let stringifiedJson = ChildProcess.execFileSync(RescriptTools.binaryPath, ["-v"]) ``` */ -@module("#cli/paths") +@module("#cli/bins") external binaryPath: string = "rescript_tools_exe" diff --git a/scripts/copyExes.js b/scripts/copyExes.js index dd8fce5563..e7c443fd19 100755 --- a/scripts/copyExes.js +++ b/scripts/copyExes.js @@ -7,7 +7,7 @@ import * as child_process from "node:child_process"; import * as fs from "node:fs"; import * as path from "node:path"; -import { platformDir } from "#cli/paths"; +import { platformDir } from "#cli/bins"; import { compilerBinDir, ninjaDir, rewatchDir } from "#dev/paths"; fs.mkdirSync(platformDir, { recursive: true }); From fd5d56e5382e91fbfcaf4da348033d8890397255 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 04:47:37 +0900 Subject: [PATCH 25/37] fix tests --- lib_dev/process.js | 38 ++++++++++++++++---------------------- package.json | 2 +- scripts/test.js | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index 383ffada5a..bae21ce2d0 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -3,6 +3,10 @@ import * as path from "node:path"; import { bsc_exe, rescript_exe } from "#cli/bins"; /** + * @typedef {{ + * throwOnFail?: boolean, + * } & child_process.SpawnOptions} ExecOptions + * * @typedef {{ * status: number, * stdout: string, @@ -20,12 +24,6 @@ const signals = { export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } = setup(); -/** - * @typedef {{ - * throwOnExit?: boolean, - * }} ExecOptions - */ - /** * @param {string} [cwd] */ @@ -33,11 +31,11 @@ export function setup(cwd = process.cwd()) { /** * @param {string} command * @param {string[]} [args] - * @param {child_process.SpawnOptions & ExecOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ async function exec(command, args = [], options = {}) { - const { throwOnExit = true } = options; + const { throwOnFail = options.stdio === "inherit" } = options; const stdoutChunks = []; const stderrChunks = []; @@ -63,12 +61,8 @@ export function setup(cwd = process.cwd()) { }); subprocess.once("close", (exitCode, signal) => { - const stdout = stdoutChunks.length - ? Buffer.concat(stdoutChunks).toString("utf8") - : null; - const stderr = stdoutChunks.length - ? Buffer.concat(stderrChunks).toString("utf8") - : null; + const stdout = Buffer.concat(stdoutChunks).toString("utf8"); + const stderr = Buffer.concat(stderrChunks).toString("utf8"); let code = exitCode ?? 1; if (signals[signal]) { @@ -76,7 +70,7 @@ export function setup(cwd = process.cwd()) { code = signals[signal] + 128; } - if (throwOnExit && code !== 0) { + if (throwOnFail && code !== 0) { reject({ status: code, stdout, stderr }); } else { resolve({ status: code, stdout, stderr }); @@ -92,7 +86,7 @@ export function setup(cwd = process.cwd()) { * `node` CLI * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ node(args = [], options = {}) { @@ -103,7 +97,7 @@ export function setup(cwd = process.cwd()) { * `npx` CLI * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ npx(args = [], options = {}) { @@ -114,7 +108,7 @@ export function setup(cwd = process.cwd()) { * Mocha CLI * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ mocha(args = [], options = {}) { @@ -132,7 +126,7 @@ export function setup(cwd = process.cwd()) { * | (string & {}) * )} command * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ rescript(command, args = [], options = {}) { @@ -144,7 +138,7 @@ export function setup(cwd = process.cwd()) { * `bsc` CLI * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ bsc(args = [], options = {}) { @@ -155,7 +149,7 @@ export function setup(cwd = process.cwd()) { * Execute ReScript `build` command directly * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ execBuild(args = [], options = {}) { @@ -166,7 +160,7 @@ export function setup(cwd = process.cwd()) { * Execute ReScript `clean` command directly * * @param {string[]} [args] - * @param {child_process.SpawnOptions} [options] + * @param {ExecOptions} [options] * @return {Promise} */ execClean(args = [], options = {}) { diff --git a/package.json b/package.json index de6bdf250c..a4eab970fd 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "./package.json": "./package.json" }, "imports": { - "#cli/bins": "./cli/common/bins.js", + "#cli/*": "./cli/common/*.js", "#dev/*": "./lib_dev/*.js", "#lib/minisocket": "./lib/minisocket.js" }, diff --git a/scripts/test.js b/scripts/test.js index cbda6d6fb8..2717bbd28b 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -55,7 +55,7 @@ if (process.argv.includes("-all")) { } if (formatTest) { - await exec("bash", ["scripts/format_check.sh"], { + await exec("./scripts/format_check.sh", [], { cwd: projectDir, stdio: "inherit", }); From d22fafd0843bff57e3125d50df49bb4d31c2cec2 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 05:05:25 +0900 Subject: [PATCH 26/37] cleanup test rescript configs --- scripts/test.js | 4 +- .../custom_namespace/rescript.json | 6 +- tests/build_tests/cycle/rescript.json | 6 +- tests/build_tests/cycle1/rescript.json | 6 +- tests/build_tests/devonly/rescript.json | 7 +- .../devonly/src/{demo.bs.js => demo.res.js} | 3 +- .../src/{depdemo.bs.js => depdemo.res.js} | 5 +- .../src2/{hello.bs.js => hello.res.js} | 5 +- .../src2/{hellodep.bs.js => hellodep.res.js} | 3 +- .../a/rescript.json | 4 +- .../b/rescript.json | 4 +- .../c/rescript.json | 1 - .../node_modules/z/rescript.json | 1 - tests/build_tests/exports/rescript.json | 3 +- tests/build_tests/gpr_978/rescript.json | 3 +- tests/build_tests/install/rescript.json | 6 +- tests/build_tests/install/src/Foo.res.js | 11 + .../@rescript/react/rescript.json | 6 +- .../react/src/{React.mjs => React.res.js} | 21 +- .../src/{ReactDOM.mjs => ReactDOM.res.js} | 9 +- .../node_modules/a/package.json | 6 +- .../node_modules/a/rescript.json | 14 +- .../node_modules/a/src/{A.mjs => A.res.js} | 7 +- .../node_modules/b/rescript.json | 14 +- .../node_modules/b/src/{B.mjs => B.res.js} | 7 +- .../jsx_settings_inheritance/rescript.json | 12 +- .../src/{C.mjs => C.res.js} | 11 +- tests/build_tests/react_ppx/rescript.json | 12 +- .../a/rescript.json | 6 +- .../node_modules/b/bsconfig.json | 6 +- .../node_modules/c/bsconfig.json | 6 +- .../a/rescript.json | 6 +- .../{bsconfig.json => rescript.json} | 8 +- tests/build_tests/weird_deps/rescript.json | 4 +- tests/build_tests/weird_devdeps/rescript.json | 4 +- tests/build_tests/zerocycle/rescript.json | 4 +- .../{ArrayUtils.res.mjs => ArrayUtils.res.js} | 0 .../{DocTest.res.mjs => DocTest.res.js} | 4 +- .../{Mocha.res.mjs => Mocha.res.js} | 0 .../{Node.res.mjs => Node.res.js} | 0 .../{SpawnAsync.res.mjs => SpawnAsync.res.js} | 0 .../generated_mocha_test.res.js | 19339 ++++++++++++++++ tests/docstring_tests/rescript.json | 2 +- 43 files changed, 19464 insertions(+), 122 deletions(-) rename tests/build_tests/devonly/src/{demo.bs.js => demo.res.js} (64%) rename tests/build_tests/devonly/src/{depdemo.bs.js => depdemo.res.js} (74%) rename tests/build_tests/devonly/src2/{hello.bs.js => hello.res.js} (74%) rename tests/build_tests/devonly/src2/{hellodep.bs.js => hellodep.res.js} (65%) create mode 100644 tests/build_tests/install/src/Foo.res.js rename tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/{React.mjs => React.res.js} (54%) rename tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/{ReactDOM.mjs => ReactDOM.res.js} (65%) rename tests/build_tests/jsx_settings_inheritance/node_modules/a/src/{A.mjs => A.res.js} (70%) rename tests/build_tests/jsx_settings_inheritance/node_modules/b/src/{B.mjs => B.res.js} (70%) rename tests/build_tests/jsx_settings_inheritance/src/{C.mjs => C.res.js} (63%) rename tests/build_tests/unboxed_bool_with_const/{bsconfig.json => rescript.json} (67%) rename tests/docstring_tests/{ArrayUtils.res.mjs => ArrayUtils.res.js} (100%) rename tests/docstring_tests/{DocTest.res.mjs => DocTest.res.js} (98%) rename tests/docstring_tests/{Mocha.res.mjs => Mocha.res.js} (100%) rename tests/docstring_tests/{Node.res.mjs => Node.res.js} (100%) rename tests/docstring_tests/{SpawnAsync.res.mjs => SpawnAsync.res.js} (100%) create mode 100644 tests/docstring_tests/generated_mocha_test.res.js diff --git a/scripts/test.js b/scripts/test.js index 2717bbd28b..58ce655852 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -159,7 +159,7 @@ if (runtimeDocstrings) { }); // Generate rescript file with all tests `generated_mocha_test.res` - await node([path.join(docstringTestDir, "DocTest.res.mjs")], { + await node([path.join(docstringTestDir, "DocTest.res.js")], { cwd: projectDir, stdio: "inherit", }); @@ -179,7 +179,7 @@ if (runtimeDocstrings) { console.log("Run mocha test"); await mocha( - [path.join("tests", "docstring_tests", "generated_mocha_test.res.mjs")], + [path.join("tests", "docstring_tests", "generated_mocha_test.res.js")], { cwd: projectDir, stdio: "inherit", diff --git a/tests/build_tests/custom_namespace/rescript.json b/tests/build_tests/custom_namespace/rescript.json index 089f4e6858..2d0bb7284b 100644 --- a/tests/build_tests/custom_namespace/rescript.json +++ b/tests/build_tests/custom_namespace/rescript.json @@ -8,12 +8,12 @@ "namespace": "Foo_bar", "package-specs": { "module": "esmodule", - "in-source": true + "in-source": true, + "suffix": ".res.js" }, "bsc-flags": ["-bs-no-version-header"], "warnings": { "number": "-40+6+7", "error": true - }, - "suffix": ".res.js" + } } diff --git a/tests/build_tests/cycle/rescript.json b/tests/build_tests/cycle/rescript.json index f43ea2c7c0..397c6c585b 100644 --- a/tests/build_tests/cycle/rescript.json +++ b/tests/build_tests/cycle/rescript.json @@ -6,10 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", - "in-source": true + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/cycle1/rescript.json b/tests/build_tests/cycle1/rescript.json index fdbf975812..21bff92f92 100644 --- a/tests/build_tests/cycle1/rescript.json +++ b/tests/build_tests/cycle1/rescript.json @@ -8,7 +8,7 @@ }, "package-specs": { "module": "esmodule", - "in-source": true - }, - "suffix": ".bs.js" + "in-source": true, + "suffix": ".res.js" + } } diff --git a/tests/build_tests/devonly/rescript.json b/tests/build_tests/devonly/rescript.json index e68f677194..5af3898abc 100644 --- a/tests/build_tests/devonly/rescript.json +++ b/tests/build_tests/devonly/rescript.json @@ -13,10 +13,9 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": true + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".bs.js", - "bs-dependencies": [], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/devonly/src/demo.bs.js b/tests/build_tests/devonly/src/demo.res.js similarity index 64% rename from tests/build_tests/devonly/src/demo.bs.js rename to tests/build_tests/devonly/src/demo.res.js index 1b69c81d7f..b4786279d6 100644 --- a/tests/build_tests/devonly/src/demo.bs.js +++ b/tests/build_tests/devonly/src/demo.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let Depdemo = require("./depdemo.bs.js"); +import * as Depdemo from "./depdemo.res.js"; console.log(Depdemo.a); diff --git a/tests/build_tests/devonly/src/depdemo.bs.js b/tests/build_tests/devonly/src/depdemo.res.js similarity index 74% rename from tests/build_tests/devonly/src/depdemo.bs.js rename to tests/build_tests/devonly/src/depdemo.res.js index 7a46d38e23..a81ebd8f92 100644 --- a/tests/build_tests/devonly/src/depdemo.bs.js +++ b/tests/build_tests/devonly/src/depdemo.res.js @@ -1,8 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; let a = 3; -exports.a = a; +export { + a, +} /* No side effect */ diff --git a/tests/build_tests/devonly/src2/hello.bs.js b/tests/build_tests/devonly/src2/hello.res.js similarity index 74% rename from tests/build_tests/devonly/src2/hello.bs.js rename to tests/build_tests/devonly/src2/hello.res.js index e49a9a2be3..cf0b79fe71 100644 --- a/tests/build_tests/devonly/src2/hello.bs.js +++ b/tests/build_tests/devonly/src2/hello.res.js @@ -1,8 +1,9 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; let v = 3; -exports.v = v; +export { + v, +} /* No side effect */ diff --git a/tests/build_tests/devonly/src2/hellodep.bs.js b/tests/build_tests/devonly/src2/hellodep.res.js similarity index 65% rename from tests/build_tests/devonly/src2/hellodep.bs.js rename to tests/build_tests/devonly/src2/hellodep.res.js index 0f6e84ce17..6c488f5087 100644 --- a/tests/build_tests/devonly/src2/hellodep.bs.js +++ b/tests/build_tests/devonly/src2/hellodep.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let Hello = require("./hello.bs.js"); +import * as Hello from "./hello.res.js"; console.log(Hello.v); diff --git a/tests/build_tests/duplicated_symlinked_packages/a/rescript.json b/tests/build_tests/duplicated_symlinked_packages/a/rescript.json index 47d3c647ed..43650453d1 100644 --- a/tests/build_tests/duplicated_symlinked_packages/a/rescript.json +++ b/tests/build_tests/duplicated_symlinked_packages/a/rescript.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "esmodule", - "in-source": true + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".res.js", "bs-dependencies": ["c", "z"], "warnings": { "error": "+101" }, "namespace": true diff --git a/tests/build_tests/duplicated_symlinked_packages/b/rescript.json b/tests/build_tests/duplicated_symlinked_packages/b/rescript.json index 4d85b1366a..46f7424882 100644 --- a/tests/build_tests/duplicated_symlinked_packages/b/rescript.json +++ b/tests/build_tests/duplicated_symlinked_packages/b/rescript.json @@ -7,9 +7,9 @@ }, "package-specs": { "module": "esmodule", - "in-source": true + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".res.js", "bs-dependencies": ["c"], "warnings": { "error": "+101" }, "namespace": true diff --git a/tests/build_tests/duplicated_symlinked_packages/c/rescript.json b/tests/build_tests/duplicated_symlinked_packages/c/rescript.json index 487a3cbac4..2941524ae2 100644 --- a/tests/build_tests/duplicated_symlinked_packages/c/rescript.json +++ b/tests/build_tests/duplicated_symlinked_packages/c/rescript.json @@ -9,7 +9,6 @@ "module": "esmodule", "in-source": true }, - "suffix": ".res.js", "warnings": { "error": "+101" }, "namespace": true } diff --git a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json index 5ebf01cc2f..025a177cc4 100644 --- a/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json +++ b/tests/build_tests/duplicated_symlinked_packages/node_modules/z/rescript.json @@ -9,7 +9,6 @@ "module": "esmodule", "in-source": true }, - "suffix": ".res.js", "warnings": { "error" : "+101" }, diff --git a/tests/build_tests/exports/rescript.json b/tests/build_tests/exports/rescript.json index 341475886f..1abffa2047 100644 --- a/tests/build_tests/exports/rescript.json +++ b/tests/build_tests/exports/rescript.json @@ -1,6 +1,5 @@ { "name": "exports", "version": "0.1.0", - "sources": ["src"], - "bs-dependencies": [] + "sources": ["src"] } diff --git a/tests/build_tests/gpr_978/rescript.json b/tests/build_tests/gpr_978/rescript.json index f921adf5b8..d5acde0ade 100644 --- a/tests/build_tests/gpr_978/rescript.json +++ b/tests/build_tests/gpr_978/rescript.json @@ -1,6 +1,5 @@ { "name": "gpr_978", "version": "0.0.0", - "sources": ["src"], - "bs-dependencies": [] + "sources": ["src"] } diff --git a/tests/build_tests/install/rescript.json b/tests/build_tests/install/rescript.json index c5e0d91b0e..b073ff2022 100644 --- a/tests/build_tests/install/rescript.json +++ b/tests/build_tests/install/rescript.json @@ -6,10 +6,10 @@ "subdirs": true }, "package-specs": { - "module": "commonjs", - "in-source": true + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".bs.js", "bs-dependencies": [], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/install/src/Foo.res.js b/tests/build_tests/install/src/Foo.res.js new file mode 100644 index 0000000000..6078c7d3cf --- /dev/null +++ b/tests/build_tests/install/src/Foo.res.js @@ -0,0 +1,11 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function main() { + console.log("hello"); +} + +export { + main, +} +/* No side effect */ diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/rescript.json b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/rescript.json index e948391f26..c2ed78b174 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/rescript.json +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/rescript.json @@ -5,9 +5,9 @@ "mode": "classic" }, "sources": [{ "dir": "src", "subdirs": true }], - "package-specs": [{ "module": "commonjs", "in-source": true }], - "suffix": ".bs.js", + "package-specs": { "module": "esmodule", "in-source": true }, + "suffix": ".res.js", "bs-dev-dependencies": [], "bsc-flags": [], "uncurried": false -} \ No newline at end of file +} diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.mjs b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.res.js similarity index 54% rename from tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.mjs rename to tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.res.js index abd3ce43c9..b9440275de 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.mjs +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/React.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let React = require("react"); +import * as React from "react"; let Ref = {}; @@ -23,12 +22,14 @@ function lazy_(load) { let Uncurried = {}; -exports.Ref = Ref; -exports.Children = Children; -exports.Context = Context; -exports.Fragment = Fragment; -exports.StrictMode = StrictMode; -exports.Suspense = Suspense; -exports.lazy_ = lazy_; -exports.Uncurried = Uncurried; +export { + Ref, + Children, + Context, + Fragment, + StrictMode, + Suspense, + lazy_, + Uncurried, +} /* react Not a pure module */ diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.mjs b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.res.js similarity index 65% rename from tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.mjs rename to tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.res.js index 531f41295f..0827b13dea 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.mjs +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/@rescript/react/src/ReactDOM.res.js @@ -1,5 +1,4 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; let Root = {}; @@ -12,7 +11,9 @@ let Ref = {}; let Props = {}; -exports.Client = Client; -exports.Ref = Ref; -exports.Props = Props; +export { + Client, + Ref, + Props, +} /* No side effect */ diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/a/package.json b/tests/build_tests/jsx_settings_inheritance/node_modules/a/package.json index db9848a748..f9244b8b0f 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/a/package.json +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/a/package.json @@ -1,4 +1,4 @@ { - "name": "a", - "version": "0.0.0" -} \ No newline at end of file + "name": "a", + "version": "0.0.0" +} diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/a/rescript.json b/tests/build_tests/jsx_settings_inheritance/node_modules/a/rescript.json index a9aad4cff9..266065ca7b 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/a/rescript.json +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/a/rescript.json @@ -8,15 +8,13 @@ "dir": "src", "subdirs": true }, - "package-specs": [ - { - "module": "commonjs", - "in-source": true - } - ], - "suffix": ".mjs", + "package-specs": { + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" + }, "namespace": true, "bs-dependencies": [ "@rescript/react" ] -} \ No newline at end of file +} diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.mjs b/tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.res.js similarity index 70% rename from tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.mjs rename to tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.res.js index cdd60ab268..6b95c9bba3 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.mjs +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/a/src/A.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let JsxRuntime = require("react/jsx-runtime"); +import * as JsxRuntime from "react/jsx-runtime"; function A(props) { return JsxRuntime.jsx("div", { @@ -11,5 +10,7 @@ function A(props) { let make = A; -exports.make = make; +export { + make, +} /* react/jsx-runtime Not a pure module */ diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/b/rescript.json b/tests/build_tests/jsx_settings_inheritance/node_modules/b/rescript.json index da3c68d2cd..b3b346ec46 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/b/rescript.json +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/b/rescript.json @@ -4,15 +4,13 @@ "dir": "src", "subdirs": true }, - "package-specs": [ - { - "module": "commonjs", - "in-source": true - } - ], - "suffix": ".mjs", + "package-specs": { + "module": "esmodule", + "in-source": true, + "suffix": ".mjs" + }, "namespace": true, "bs-dependencies": [ "@rescript/react" ] -} \ No newline at end of file +} diff --git a/tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.mjs b/tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.res.js similarity index 70% rename from tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.mjs rename to tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.res.js index 85e5b19562..757e5af351 100644 --- a/tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.mjs +++ b/tests/build_tests/jsx_settings_inheritance/node_modules/b/src/B.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let JsxRuntime = require("react/jsx-runtime"); +import * as JsxRuntime from "react/jsx-runtime"; function B(props) { return JsxRuntime.jsx("div", { @@ -11,5 +10,7 @@ function B(props) { let make = B; -exports.make = make; +export { + make, +} /* react/jsx-runtime Not a pure module */ diff --git a/tests/build_tests/jsx_settings_inheritance/rescript.json b/tests/build_tests/jsx_settings_inheritance/rescript.json index 2c83b7c9ac..3036b57b61 100644 --- a/tests/build_tests/jsx_settings_inheritance/rescript.json +++ b/tests/build_tests/jsx_settings_inheritance/rescript.json @@ -8,13 +8,11 @@ "dir": "src", "subdirs": true }, - "package-specs": [ - { - "module": "commonjs", - "in-source": true - } - ], - "suffix": ".mjs", + "package-specs": { + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" + }, "namespace": true, "bs-dependencies": ["@rescript/react", "a", "b"] } diff --git a/tests/build_tests/jsx_settings_inheritance/src/C.mjs b/tests/build_tests/jsx_settings_inheritance/src/C.res.js similarity index 63% rename from tests/build_tests/jsx_settings_inheritance/src/C.mjs rename to tests/build_tests/jsx_settings_inheritance/src/C.res.js index 8904c9bed0..f341b1a58a 100644 --- a/tests/build_tests/jsx_settings_inheritance/src/C.mjs +++ b/tests/build_tests/jsx_settings_inheritance/src/C.res.js @@ -1,9 +1,8 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let A$A = require("a/src/A.mjs"); -let B$B = require("b/src/B.mjs"); -let JsxRuntime = require("react/jsx-runtime"); +import * as A$A from "a/src/A.res.js"; +import * as B$B from "b/src/B.res.js"; +import * as JsxRuntime from "react/jsx-runtime"; function C(props) { return JsxRuntime.jsxs(JsxRuntime.Fragment, { @@ -16,5 +15,7 @@ function C(props) { let make = C; -exports.make = make; +export { + make, +} /* A-A Not a pure module */ diff --git a/tests/build_tests/react_ppx/rescript.json b/tests/build_tests/react_ppx/rescript.json index 62d4a8e2fb..0ed0b3be50 100644 --- a/tests/build_tests/react_ppx/rescript.json +++ b/tests/build_tests/react_ppx/rescript.json @@ -7,12 +7,10 @@ "dir": "src", "subdirs": true }, - "package-specs": [ - { - "module": "commonjs", - "in-source": true - } - ], - "suffix": ".bs.js", + "package-specs": { + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" + }, "namespace": true } diff --git a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json index 065cbb35b8..9ab943fa18 100644 --- a/tests/build_tests/transitive_pinned_dependency1/a/rescript.json +++ b/tests/build_tests/transitive_pinned_dependency1/a/rescript.json @@ -11,13 +11,13 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": false + "module": "esmodule", + "in-source": false, + "suffix": ".res.js" }, "warnings": { "error": true }, - "suffix": ".mjs", "bs-dependencies": ["b"], "pinned-dependencies": ["b"] } diff --git a/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json b/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json index 2fdd222a49..47680b2c98 100644 --- a/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency1/node_modules/b/bsconfig.json @@ -11,13 +11,13 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": false + "module": "esmodule", + "in-source": false, + "suffix": ".res.js" }, "warnings": { "error": true }, - "suffix": ".mjs", "bs-dependencies": [ "c" ], diff --git a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json index b63b43209c..08bfc2bd3c 100644 --- a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json @@ -11,11 +11,11 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": false + "module": "esmodule", + "in-source": false, + "suffix": ".res.js" }, "warnings": { "error": true }, - "suffix": ".mjs" } diff --git a/tests/build_tests/transitive_pinned_dependency2/a/rescript.json b/tests/build_tests/transitive_pinned_dependency2/a/rescript.json index 40bd9a1a7d..42e66a06c4 100644 --- a/tests/build_tests/transitive_pinned_dependency2/a/rescript.json +++ b/tests/build_tests/transitive_pinned_dependency2/a/rescript.json @@ -11,12 +11,12 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": false + "module": "esmodule", + "in-source": false, + "suffix": ".res.js" }, "warnings": { "error": true }, - "suffix": ".mjs", "bs-dependencies": ["b"] } diff --git a/tests/build_tests/unboxed_bool_with_const/bsconfig.json b/tests/build_tests/unboxed_bool_with_const/rescript.json similarity index 67% rename from tests/build_tests/unboxed_bool_with_const/bsconfig.json rename to tests/build_tests/unboxed_bool_with_const/rescript.json index 1cbcace50a..186e6f201b 100644 --- a/tests/build_tests/unboxed_bool_with_const/bsconfig.json +++ b/tests/build_tests/unboxed_bool_with_const/rescript.json @@ -8,8 +8,8 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": true - }, - "suffix": ".bs.js" + "module": "esmodule", + "in-source": true, + "suffix": ".res.js" + } } diff --git a/tests/build_tests/weird_deps/rescript.json b/tests/build_tests/weird_deps/rescript.json index 9a1511c654..30c2891d34 100644 --- a/tests/build_tests/weird_deps/rescript.json +++ b/tests/build_tests/weird_deps/rescript.json @@ -13,9 +13,9 @@ ], "package-specs": { "module": "esmodule", - "in-source": true + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".res.js", "bs-dependencies": ["weird"], "warnings": { "error": "+101" } } diff --git a/tests/build_tests/weird_devdeps/rescript.json b/tests/build_tests/weird_devdeps/rescript.json index 0e3911d9ad..85174f02e8 100644 --- a/tests/build_tests/weird_devdeps/rescript.json +++ b/tests/build_tests/weird_devdeps/rescript.json @@ -13,9 +13,9 @@ ], "package-specs": { "module": "esmodule", - "in-source": true + "in-source": true, + "suffix": ".res.js" }, - "suffix": ".res.js", "bs-dependencies": [], "bs-dev-dependencies": ["weird"], "warnings": { "error": "+101" } diff --git a/tests/build_tests/zerocycle/rescript.json b/tests/build_tests/zerocycle/rescript.json index 4210d87b96..1c3fa9736f 100644 --- a/tests/build_tests/zerocycle/rescript.json +++ b/tests/build_tests/zerocycle/rescript.json @@ -3,9 +3,9 @@ "version": "0.1.0", "sources": ["src"], "package-specs": { - "module": "commonjs", + "module": "esmodule", "in-source": true }, - "suffix": ".bs.js", + "suffix": ".res.js", "bs-dependencies": [] } diff --git a/tests/docstring_tests/ArrayUtils.res.mjs b/tests/docstring_tests/ArrayUtils.res.js similarity index 100% rename from tests/docstring_tests/ArrayUtils.res.mjs rename to tests/docstring_tests/ArrayUtils.res.js diff --git a/tests/docstring_tests/DocTest.res.mjs b/tests/docstring_tests/DocTest.res.js similarity index 98% rename from tests/docstring_tests/DocTest.res.mjs rename to tests/docstring_tests/DocTest.res.js index a71ec94e3a..2c75b3a9ad 100644 --- a/tests/docstring_tests/DocTest.res.mjs +++ b/tests/docstring_tests/DocTest.res.js @@ -6,9 +6,9 @@ import * as Nodeos from "node:os"; import * as Nodeurl from "node:url"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as Nodepath from "node:path"; -import * as ArrayUtils from "./ArrayUtils.res.mjs"; +import * as ArrayUtils from "./ArrayUtils.res.js"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; -import * as SpawnAsync from "./SpawnAsync.res.mjs"; +import * as SpawnAsync from "./SpawnAsync.res.js"; import * as Stdlib_Exn from "rescript/lib/es6/Stdlib_Exn.js"; import * as Stdlib_Int from "rescript/lib/es6/Stdlib_Int.js"; import * as Stdlib_Dict from "rescript/lib/es6/Stdlib_Dict.js"; diff --git a/tests/docstring_tests/Mocha.res.mjs b/tests/docstring_tests/Mocha.res.js similarity index 100% rename from tests/docstring_tests/Mocha.res.mjs rename to tests/docstring_tests/Mocha.res.js diff --git a/tests/docstring_tests/Node.res.mjs b/tests/docstring_tests/Node.res.js similarity index 100% rename from tests/docstring_tests/Node.res.mjs rename to tests/docstring_tests/Node.res.js diff --git a/tests/docstring_tests/SpawnAsync.res.mjs b/tests/docstring_tests/SpawnAsync.res.js similarity index 100% rename from tests/docstring_tests/SpawnAsync.res.mjs rename to tests/docstring_tests/SpawnAsync.res.js diff --git a/tests/docstring_tests/generated_mocha_test.res.js b/tests/docstring_tests/generated_mocha_test.res.js new file mode 100644 index 0000000000..4611517b45 --- /dev/null +++ b/tests/docstring_tests/generated_mocha_test.res.js @@ -0,0 +1,19339 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Mocha from "mocha"; +import * as Stdlib from "rescript/lib/es6/Stdlib.js"; +import * as Belt_Id from "rescript/lib/es6/Belt_Id.js"; +import * as Belt_Int from "rescript/lib/es6/Belt_Int.js"; +import * as Belt_Map from "rescript/lib/es6/Belt_Map.js"; +import * as Belt_Set from "rescript/lib/es6/Belt_Set.js"; +import * as Belt_List from "rescript/lib/es6/Belt_List.js"; +import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; +import * as Belt_Float from "rescript/lib/es6/Belt_Float.js"; +import * as Belt_Range from "rescript/lib/es6/Belt_Range.js"; +import * as Pervasives from "rescript/lib/es6/Pervasives.js"; +import * as Stdlib_Exn from "rescript/lib/es6/Stdlib_Exn.js"; +import * as Stdlib_Int from "rescript/lib/es6/Stdlib_Int.js"; +import * as Belt_MapInt from "rescript/lib/es6/Belt_MapInt.js"; +import * as Belt_Option from "rescript/lib/es6/Belt_Option.js"; +import * as Belt_Result from "rescript/lib/es6/Belt_Result.js"; +import * as Stdlib_Bool from "rescript/lib/es6/Stdlib_Bool.js"; +import * as Stdlib_Char from "rescript/lib/es6/Stdlib_Char.js"; +import * as Stdlib_Dict from "rescript/lib/es6/Stdlib_Dict.js"; +import * as Stdlib_JSON from "rescript/lib/es6/Stdlib_JSON.js"; +import * as Stdlib_List from "rescript/lib/es6/Stdlib_List.js"; +import * as Stdlib_Math from "rescript/lib/es6/Stdlib_Math.js"; +import * as Stdlib_Null from "rescript/lib/es6/Stdlib_Null.js"; +import * as Stdlib_Type from "rescript/lib/es6/Stdlib_Type.js"; +import * as Belt_HashMap from "rescript/lib/es6/Belt_HashMap.js"; +import * as Belt_HashSet from "rescript/lib/es6/Belt_HashSet.js"; +import * as Belt_MapDict from "rescript/lib/es6/Belt_MapDict.js"; +import * as Belt_SetDict from "rescript/lib/es6/Belt_SetDict.js"; +import * as Stdlib_Array from "rescript/lib/es6/Stdlib_Array.js"; +import * as Stdlib_Error from "rescript/lib/es6/Stdlib_Error.js"; +import * as Stdlib_Float from "rescript/lib/es6/Stdlib_Float.js"; +import * as Primitive_int from "rescript/lib/es6/Primitive_int.js"; +import * as Stdlib_Option from "rescript/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Result from "rescript/lib/es6/Stdlib_Result.js"; +import * as Stdlib_String from "rescript/lib/es6/Stdlib_String.js"; +import * as Belt_MapString from "rescript/lib/es6/Belt_MapString.js"; +import * as Belt_SortArray from "rescript/lib/es6/Belt_SortArray.js"; +import * as Stdlib_Promise from "rescript/lib/es6/Stdlib_Promise.js"; +import * as Belt_MutableSet from "rescript/lib/es6/Belt_MutableSet.js"; +import * as Stdlib_Iterator from "rescript/lib/es6/Stdlib_Iterator.js"; +import * as Stdlib_Nullable from "rescript/lib/es6/Stdlib_Nullable.js"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; +import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; +import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js"; + +Mocha.describe("Belt", () => { + Mocha.test("HashMap", () => { + let I0 = Belt_Id.hashable(param => 65535, (a, b) => a === b); + let s0 = Belt_HashMap.make(40, I0); + let I1 = Belt_Id.hashable(param => 255, (a, b) => a === b); + let s1 = Belt_HashMap.make(40, I1); + Belt_HashMap.set(s0, 0, 3); + Belt_HashMap.set(s1, 1, "3"); + }); + Mocha.test("HashSet", () => { + let I0 = Belt_Id.hashable(a => a & 65535, (a, b) => a === b); + Belt_HashSet.make(40, I0); + let I1 = Belt_Id.hashable(a => a & 255, (a, b) => a === b); + let s1 = Belt_HashSet.make(40, I1); + Belt_HashSet.add(s1, 0); + Belt_HashSet.add(s1, 1); + }); + Mocha.test("MutableSet", () => { + let cmp = (param, param$1) => { + let c = Primitive_object.compare(param[0], param$1[0]); + if (c !== 0) { + return c; + } else { + return Primitive_object.compare(param[1], param$1[1]); + } + }; + let PairComparator = Belt_Id.MakeComparable({ + cmp: cmp + }); + let mySet = Belt_MutableSet.make(PairComparator); + Belt_MutableSet.add(mySet, [ + 1, + 2 + ]); + }); + Mocha.test("Option", () => {}); + Mocha.test("Set", () => { + let cmp = (param, param$1) => { + let c = Primitive_object.compare(param[0], param$1[0]); + if (c !== 0) { + return c; + } else { + return Primitive_object.compare(param[1], param$1[1]); + } + }; + let PairComparator = Belt_Id.MakeComparable({ + cmp: cmp + }); + let mySet = Belt_Set.make(PairComparator); + Belt_Set.add(mySet, [ + 1, + 2 + ]); + let cmp$1 = Primitive_object.compare; + Belt_Id.MakeComparable({ + cmp: cmp$1 + }); + }); +}); + +Mocha.describe("Belt.Array", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt.Float", () => { + Mocha.test("*", () => { + Stdlib.assertEqual(2.0 * 2.0, 4.0); + }); + Mocha.test("+", () => { + Stdlib.assertEqual(2.0 + 2.0, 4.0); + }); + Mocha.test("-", () => { + Stdlib.assertEqual(2.0 - 1.0, 1.0); + }); + Mocha.test("/", () => { + Stdlib.assertEqual(4.0 / 2.0, 2.0); + }); + Mocha.test("fromInt", () => { + console.log(1 === 1.0); + }); + Mocha.test("fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); + }); + Mocha.test("toInt", () => { + console.log(true); + }); + Mocha.test("toString", () => { + console.log(String(1.0) === "1.0"); + }); +}); + +Mocha.describe("Belt.HashMap", () => { + Mocha.test("clear", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.fromArray([[ + 1, + "1" + ]], IntHash); + Belt_HashMap.clear(hMap); + Belt_HashMap.isEmpty(hMap) === true; + }); + Mocha.test("copy", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntHash); + let s1 = Belt_HashMap.copy(s0); + Belt_HashMap.set(s0, 2, "3"); + Primitive_object.notequal(Belt_HashMap.get(s0, 2), Belt_HashMap.get(s1, 2)); + }); + Mocha.test("forEach", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.forEach(s0, (key, value) => { + console.log(key, value); + }); + }); + Mocha.test("fromArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ], IntHash); + Primitive_object.equal(Belt_HashMap.toArray(s0), [ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ]); + }); + Mocha.test("get", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Primitive_object.equal(Belt_HashMap.get(s0, 1), "value1"); + Belt_HashMap.get(s0, 2) === undefined; + }); + Mocha.test("getBucketHistogram", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 1, "1"); + Belt_HashMap.getBucketHistogram(hMap); + }); + Mocha.test("has", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.has(s0, 1) === true; + Belt_HashMap.has(s0, 2) === false; + }); + Mocha.test("isEmpty", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + Belt_HashMap.isEmpty(Belt_HashMap.fromArray([[ + 1, + "1" + ]], IntHash)) === false; + }); + Mocha.test("keepMapInPlace", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Belt_HashMap.keepMapInPlace(s0, (key, value) => { + if (key === 1) { + return; + } else { + return value; + } + }); + }); + Mocha.test("keysToArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.keysToArray(s0), [ + 1, + 2 + ]); + }); + Mocha.test("logStats", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 1, "1"); + Belt_HashMap.logStats(hMap); + }); + Mocha.test("make", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 0, "a"); + }); + Mocha.test("mergeMany", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.mergeMany(hMap, [ + [ + 1, + "1" + ], + [ + 2, + "2" + ] + ]); + }); + Mocha.test("reduce", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Stdlib.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); + }); + Mocha.test("remove", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.remove(s0, 1); + Belt_HashMap.has(s0, 1) === false; + }); + Mocha.test("set", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntHash); + Belt_HashMap.set(s0, 2, "3"); + Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ + "1", + "3", + "3" + ]); + }); + Mocha.test("size", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Belt_HashMap.size(s0) === 2; + }); + Mocha.test("toArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.toArray(s0), [ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ]); + }); + Mocha.test("valuesToArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ + "value1", + "value2" + ]); + }); +}); + +Mocha.describe("Belt.Int", () => { + Mocha.test("*", () => { + Stdlib.assertEqual(4, 4); + }); + Mocha.test("+", () => { + Stdlib.assertEqual(4, 4); + }); + Mocha.test("-", () => { + Stdlib.assertEqual(1, 1); + }); + Mocha.test("/", () => { + Stdlib.assertEqual(2, 2); + }); + Mocha.test("fromFloat", () => { + Stdlib.assertEqual(1, 1); + }); + Mocha.test("fromString", () => { + Stdlib.assertEqual(Belt_Int.fromString("1"), 1); + }); + Mocha.test("toFloat", () => { + Stdlib.assertEqual(1, 1.0); + }); + Mocha.test("toString", () => { + Stdlib.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt.List", () => { + Mocha.test("add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); + Mocha.test("cmp", () => { + Belt_List.cmp({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 4, + tl: { + hd: 2, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + }); + Mocha.test("cmpByLength", () => { + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + }); + }); + Mocha.test("concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); + Mocha.test("concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); + Mocha.test("drop", () => { + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 3); + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("eq", () => { + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("every", () => { + let isBelow10 = value => value < 10; + Belt_List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + Belt_List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + }); + Mocha.test("every2", () => { + Belt_List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Belt_List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("filter", () => { + let isEven = x => x % 2 === 0; + Belt_List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + Belt_List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Belt_Option.isSome); + }); + Mocha.test("filterWithIndex", () => { + Belt_List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); + Mocha.test("flatten", () => { + Belt_List.flatten({ + hd: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + tl: { + hd: /* [] */0, + tl: { + hd: { + hd: 3, + tl: /* [] */0 + }, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); + Mocha.test("forEach2", () => { + Belt_List.forEach2({ + hd: "Z", + tl: { + hd: "Y", + tl: /* [] */0 + } + }, { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }, (x, y) => { + console.log(x, y); + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); + }); + Mocha.test("fromArray", () => { + Belt_List.fromArray([ + 1, + 2, + 3 + ]); + }); + Mocha.test("get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); + Mocha.test("getAssoc", () => { + Belt_List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + Belt_List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); + }); + Mocha.test("getBy", () => { + Belt_List.getBy({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 3); + Belt_List.getBy({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); + Mocha.test("getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Stdlib.assertEqual(Belt_List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = Belt_List.getExn(abc, 4); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1046, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("has", () => { + Belt_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2, (a, b) => a === b); + Belt_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + Belt_List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("hasAssoc", () => { + Belt_List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Belt_List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); + }); + Mocha.test("head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("headExn", () => { + Stdlib.assertEqual(Belt_List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = Belt_List.headExn(/* [] */0); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1083, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("keep", () => { + let isEven = x => x % 2 === 0; + Belt_List.keep({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + Belt_List.keep({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Belt_Option.isSome); + }); + Mocha.test("keepMap", () => { + let isEven = x => x % 2 === 0; + Belt_List.keepMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => { + if (isEven(x)) { + return x; + } + + }); + Belt_List.keepMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); + }); + Mocha.test("keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); + Mocha.test("length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("make", () => { + Belt_List.make(3, 1); + }); + Mocha.test("makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => i * i | 0); + }); + Mocha.test("map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); + Mocha.test("mapReverse", () => { + Stdlib.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => x * x | 0), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("mapReverse2", () => { + Belt_List.mapReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a + b | 0); + }); + Mocha.test("mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); + }); + Mocha.test("partition", () => { + Stdlib.assertEqual(Belt_List.partition({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => x > 2), [ + { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }, + { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + } + ]); + }); + Mocha.test("reduce", () => { + Belt_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Belt_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); + }); + Mocha.test("reduce2", () => { + Belt_List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceReverse", () => { + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, Belt_List.add); + }); + Mocha.test("reduceReverse2", () => { + Belt_List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceWithIndex", () => { + Belt_List.reduceWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item, index) => (acc + item | 0) + index | 0); + }); + Mocha.test("removeAssoc", () => { + Belt_List.removeAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Belt_List.removeAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); + }); + Mocha.test("reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); + Mocha.test("setAssoc", () => { + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + Belt_List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); + Mocha.test("shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("some", () => { + let isAbove100 = value => value > 100; + Belt_List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + Belt_List.some({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isAbove100); + }); + Mocha.test("some2", () => { + Belt_List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Belt_List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("sort", () => { + Belt_List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } + } + }, (a, b) => a - b | 0); + }); + Mocha.test("splitAt", () => { + Belt_List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + Belt_List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); + }); + Mocha.test("tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Belt_List.tail(/* [] */0); + }); + Mocha.test("tailExn", () => { + Stdlib.assertEqual(Belt_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }); + let exit = 0; + let val; + try { + val = Belt_List.tailExn(/* [] */0); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1306, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("take", () => { + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("unzip", () => { + Belt_List.unzip({ + hd: [ + 1, + 2 + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + Belt_List.unzip({ + hd: [ + "H", + "W" + ], + tl: { + hd: [ + "e", + "o" + ], + tl: { + hd: [ + "l", + "r" + ], + tl: { + hd: [ + "l", + "l" + ], + tl: { + hd: [ + "o", + "d" + ], + tl: { + hd: [ + " ", + "!" + ], + tl: /* [] */0 + } + } + } + } + } + }); + }); + Mocha.test("zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("zipBy", () => { + Belt_List.zipBy({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, (a, b) => (a << 1) + b | 0); + }); +}); + +Mocha.describe("Belt.Map", () => { + Mocha.test("Int", () => {}); + Mocha.test("findFirstBy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] + ], IntCmp); + Stdlib.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_Map.forEach(s0, (k, v) => { + acc.contents = { + hd: [ + k, + v + ], + tl: acc.contents + }; + }); + Primitive_object.equal(acc.contents, { + hd: [ + 4, + "4" + ], + tl: { + hd: [ + 3, + "3" + ], + tl: { + hd: [ + 2, + "2" + ], + tl: { + hd: [ + 1, + "1" + ], + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ]); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp), 2), "2"); + Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp), 2) === undefined; + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.has(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp), 1) === true; + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; + }); + Mocha.test("keysToArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + 1, + 2, + 3 + ]); + }); + Mocha.test("make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let m = Belt_Map.make(IntCmp); + Belt_Map.set(m, 0, "a"); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp); + Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ + hd: [ + k, + v + ], + tl: acc + })); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp); + let s1 = Belt_Map.remove(s0, 1); + Belt_Map.remove(s1, 1); + Primitive_object.equal(Belt_Map.keysToArray(s1), [ + 2, + 3 + ]); + }); + Mocha.test("set", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp); + let s1 = Belt_Map.set(s0, 2, "3"); + Primitive_object.equal(Belt_Map.valuesToArray(s1), [ + "1", + "3", + "3" + ]); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ]); + }); + Mocha.test("valuesToArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.valuesToArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + "1", + "2", + "3" + ]); + }); +}); + +Mocha.describe("Belt.Map.Dict", () => { + Mocha.test("findFirstBy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MapDict.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp.cmp); + Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt.Map.Int", () => { + Mocha.test("findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt.Map.String", () => { + Mocha.test("findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt.MutableSet", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + Belt_MutableSet.add(s0, 1); + Belt_MutableSet.add(s0, 2); + Belt_MutableSet.add(s0, 2); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("copy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + let copied = Belt_MutableSet.copy(s0); + Belt_MutableSet.toArray(copied); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); + Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); + }); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 5 + ], IntCmp); + Belt_MutableSet.eq(s0, s1); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_MutableSet.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.every(s0, isEven); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_MutableSet.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Belt_MutableSet.get(s0, 3); + Belt_MutableSet.get(s0, 20); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Belt_MutableSet.has(set, 3); + Belt_MutableSet.has(set, 1); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let intersect = Belt_MutableSet.intersect(s0, s1); + Belt_MutableSet.toArray(intersect); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_MutableSet.fromArray([], IntCmp); + let notEmpty = Belt_MutableSet.fromArray([1], IntCmp); + Belt_MutableSet.isEmpty(empty); + Belt_MutableSet.isEmpty(notEmpty); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_MutableSet.keep(s0, isEven); + Belt_MutableSet.toArray(s1); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.maxUndefined(s0); + Belt_MutableSet.maxUndefined(s1); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.maximum(s0); + Belt_MutableSet.maximum(s1); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.make(IntCmp); + Belt_MutableSet.mergeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Belt_MutableSet.toArray(set); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.minUndefined(s0); + Belt_MutableSet.minUndefined(s1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.minimum(s0); + Belt_MutableSet.minimum(s1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_MutableSet.partition(s0, isOdd); + Belt_MutableSet.toArray(match[0]); + Belt_MutableSet.toArray(match[1]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp); + Belt_MutableSet.remove(s0, 1); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Belt_MutableSet.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Belt_MutableSet.toArray(set); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Belt_MutableSet.size(s0); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.some(s0, isOdd); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_MutableSet.split(s0, 3); + let match$1 = match[0]; + Belt_MutableSet.toArray(match$1[0]); + Belt_MutableSet.toArray(match$1[1]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let s2 = Belt_MutableSet.intersect(s0, s1); + Belt_MutableSet.subset(s2, s0); + Belt_MutableSet.subset(s2, s1); + Belt_MutableSet.subset(s1, s0); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.toList(s0); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let union = Belt_MutableSet.union(s0, s1); + Belt_MutableSet.toArray(union); + }); +}); + +Mocha.describe("Belt.Option", () => { + Mocha.test("cmp", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Belt_Option.cmp(3, 15, clockCompare); + Belt_Option.cmp(3, 14, clockCompare); + Belt_Option.cmp(2, 15, clockCompare); + Belt_Option.cmp(undefined, 15, clockCompare); + Belt_Option.cmp(14, undefined, clockCompare); + Belt_Option.cmp(undefined, undefined, clockCompare); + }); + Mocha.test("eq", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Belt_Option.eq(3, 15, clockEqual); + Belt_Option.eq(3, undefined, clockEqual); + Belt_Option.eq(undefined, 3, clockEqual); + Belt_Option.eq(undefined, undefined, clockEqual); + }); + Mocha.test("flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + + }; + Belt_Option.flatMap(2, addIfAboveOne); + Belt_Option.flatMap(-4, addIfAboveOne); + Belt_Option.flatMap(undefined, addIfAboveOne); + }); + Mocha.test("forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Belt_Option.getExn(3), 3); + let exit = 0; + let val; + try { + val = Belt_Option.getExn(undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 2073, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getWithDefault", () => { + Belt_Option.getWithDefault(undefined, "Banana"); + Belt_Option.getWithDefault("Apple", "Banana"); + let greet = firstName => "Greetings " + Belt_Option.getWithDefault(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); + }); + Mocha.test("isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); + }); + Mocha.test("isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); + }); + Mocha.test("keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); + }); + Mocha.test("map", () => { + Belt_Option.map(3, x => x * x | 0); + Belt_Option.map(undefined, x => x * x | 0); + }); + Mocha.test("mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); + }); + Mocha.test("orElse", () => { + Primitive_object.equal(Belt_Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Belt_Option.orElse(undefined, 1066), 1066); + Belt_Option.orElse(undefined, undefined) === undefined; + }); +}); + +Mocha.describe("Belt.Range", () => { + Mocha.test("every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); + Mocha.test("everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); + Mocha.test("forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); + Mocha.test("some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); + Mocha.test("someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt.Result", () => { + Mocha.test("cmp", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Belt_Result.cmp({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Belt_Result.cmp({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Belt_Result.cmp({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Belt_Result.cmp({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Belt_Result.cmp({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; + }); + Mocha.test("eq", () => { + let good1 = { + TAG: "Ok", + _0: 42 + }; + let good2 = { + TAG: "Ok", + _0: 32 + }; + let bad1 = { + TAG: "Error", + _0: "invalid" + }; + let bad2 = { + TAG: "Error", + _0: "really invalid" + }; + let mod10equal = (a, b) => a % 10 === b % 10; + Belt_Result.eq(good1, good2, mod10equal) === true; + Belt_Result.eq(good1, bad1, mod10equal) === false; + Belt_Result.eq(bad2, good2, mod10equal) === false; + Belt_Result.eq(bad1, bad2, mod10equal) === true; + }); + Mocha.test("flatMap", () => { + let recip = x => { + if (x !== 0.0) { + return { + TAG: "Ok", + _0: 1.0 / x + }; + } else { + return { + TAG: "Error", + _0: "Divide by zero" + }; + } + }; + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 + }); + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" + }); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Belt_Result.getExn({ + TAG: "Ok", + _0: 42 + }), 42); + let exit = 0; + let val; + try { + val = Belt_Result.getExn({ + TAG: "Error", + _0: "Invalid data" + }); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 2263, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); + Mocha.test("map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Belt_Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Belt_Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); + }); + Mocha.test("mapWithDefault", () => { + Belt_Result.mapWithDefault({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Belt_Result.mapWithDefault({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; + }); +}); + +Mocha.describe("Belt.Set", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.add(s0, 1); + let s2 = Belt_Set.add(s1, 2); + let s3 = Belt_Set.add(s2, 2); + Stdlib.assertEqual(Belt_Set.toArray(s0), []); + Stdlib.assertEqual(Belt_Set.toArray(s1), [1]); + Stdlib.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Stdlib.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Stdlib.assertEqual(s2, s3); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); + }); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.eq(s0, s1), true); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_Set.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.every(s0, isEven), true); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_Set.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + Stdlib.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 4 + ]); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.get(s0, 3), 3); + Stdlib.assertEqual(Belt_Set.get(s0, 20), undefined); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.has(set, 3), false); + Stdlib.assertEqual(Belt_Set.has(set, 1), true); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let intersect = Belt_Set.intersect(s0, s1); + Stdlib.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Stdlib.assertEqual(Belt_Set.isEmpty(empty), true); + Stdlib.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_Set.keep(s0, isEven); + Stdlib.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); + }); + Mocha.test("make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Stdlib.assertEqual(Belt_Set.isEmpty(set), true); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.maximum(s0), undefined); + Stdlib.assertEqual(Belt_Set.maximum(s1), 5); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + let newSet = Belt_Set.mergeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Stdlib.assertEqual(Belt_Set.toArray(newSet), [ + 1, + 2, + 3, + 4, + 5 + ]); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.minimum(s0), undefined); + Stdlib.assertEqual(Belt_Set.minimum(s1), 1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Stdlib.assertEqual(Belt_Set.toArray(match[0]), [ + 1, + 3, + 5 + ]); + Stdlib.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 + ]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp); + let s1 = Belt_Set.remove(s0, 1); + let s2 = Belt_Set.remove(s1, 3); + let s3 = Belt_Set.remove(s2, 3); + Stdlib.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Stdlib.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Stdlib.assertEqual(s2, s3); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + let newSet = Belt_Set.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Stdlib.assertEqual(Belt_Set.toArray(newSet), []); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.size(s0), 4); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.some(s0, isOdd), true); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.split(s0, 3); + let match$1 = match[0]; + Stdlib.assertEqual(match[1], true); + Stdlib.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Stdlib.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let s2 = Belt_Set.intersect(s0, s1); + Stdlib.assertEqual(Belt_Set.subset(s2, s0), true); + Stdlib.assertEqual(Belt_Set.subset(s2, s1), true); + Stdlib.assertEqual(Belt_Set.subset(s1, s0), false); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let union = Belt_Set.union(s0, s1); + Stdlib.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); + }); +}); + +Mocha.describe("Belt.Set.Dict", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); + let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); + let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); + Belt_SetDict.toArray(undefined); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Belt_SetDict.toArray(s3); + Primitive_object.equal(s2, s3); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); + let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); + Belt_SetDict.toArray(diff1); + Belt_SetDict.toArray(diff2); + }); + Mocha.test("empty", () => {}); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.eq(s0, s1, IntCmp.cmp); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let acc = { + contents: /* [] */0 + }; + Belt_SetDict.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.has(set, 3, IntCmp.cmp); + Belt_SetDict.has(set, 1, IntCmp.cmp); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(intersect); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_SetDict.fromArray([], IntCmp.cmp); + let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); + Belt_SetDict.isEmpty(empty); + Belt_SetDict.isEmpty(notEmpty); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maxUndefined(undefined); + Belt_SetDict.maxUndefined(s1); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maximum(undefined); + Belt_SetDict.maximum(s1); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let newSet = Belt_SetDict.mergeMany(undefined, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); + let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); + let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Primitive_object.equal(s2, s3); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + let newSet = Belt_SetDict.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + Belt_SetDict.size(s0); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); + let match$1 = match[0]; + Belt_SetDict.toArray(match$1[0]); + Belt_SetDict.toArray(match$1[1]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.subset(s2, s0, IntCmp.cmp); + Belt_SetDict.subset(s2, s1, IntCmp.cmp); + Belt_SetDict.subset(s1, s0, IntCmp.cmp); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toList(s0); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(union); + }); +}); + +Mocha.describe("Belt.SortArray", () => { + Mocha.test("binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, + 2, + 3, + 4, + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 1, + 3, + 5, + 7 + ], 4, Primitive_int.compare)) === 2; + }); + Mocha.test("strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ + 1, + 2, + 3, + 4, + 3 + ], (x, y) => x < y) === 4; + Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; + Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; + Belt_SortArray.strictlySortedLength([ + 4, + 3, + 2, + 1 + ], (x, y) => x < y) === -4; + }); +}); + +Mocha.describe("Belt_Array", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_Float", () => { + Mocha.test("*", () => { + Stdlib.assertEqual(2.0 * 2.0, 4.0); + }); + Mocha.test("+", () => { + Stdlib.assertEqual(2.0 + 2.0, 4.0); + }); + Mocha.test("-", () => { + Stdlib.assertEqual(2.0 - 1.0, 1.0); + }); + Mocha.test("/", () => { + Stdlib.assertEqual(4.0 / 2.0, 2.0); + }); + Mocha.test("fromInt", () => { + console.log(1 === 1.0); + }); + Mocha.test("fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); + }); + Mocha.test("toInt", () => { + console.log(true); + }); + Mocha.test("toString", () => { + console.log(String(1.0) === "1.0"); + }); +}); + +Mocha.describe("Belt_HashMap", () => { + Mocha.test("clear", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.fromArray([[ + 1, + "1" + ]], IntHash); + Belt_HashMap.clear(hMap); + Belt_HashMap.isEmpty(hMap) === true; + }); + Mocha.test("copy", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntHash); + let s1 = Belt_HashMap.copy(s0); + Belt_HashMap.set(s0, 2, "3"); + Primitive_object.notequal(Belt_HashMap.get(s0, 2), Belt_HashMap.get(s1, 2)); + }); + Mocha.test("forEach", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.forEach(s0, (key, value) => { + console.log(key, value); + }); + }); + Mocha.test("fromArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ], IntHash); + Primitive_object.equal(Belt_HashMap.toArray(s0), [ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ]); + }); + Mocha.test("get", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Primitive_object.equal(Belt_HashMap.get(s0, 1), "value1"); + Belt_HashMap.get(s0, 2) === undefined; + }); + Mocha.test("getBucketHistogram", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 1, "1"); + Belt_HashMap.getBucketHistogram(hMap); + }); + Mocha.test("has", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.has(s0, 1) === true; + Belt_HashMap.has(s0, 2) === false; + }); + Mocha.test("isEmpty", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + Belt_HashMap.isEmpty(Belt_HashMap.fromArray([[ + 1, + "1" + ]], IntHash)) === false; + }); + Mocha.test("keepMapInPlace", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Belt_HashMap.keepMapInPlace(s0, (key, value) => { + if (key === 1) { + return; + } else { + return value; + } + }); + }); + Mocha.test("keysToArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.keysToArray(s0), [ + 1, + 2 + ]); + }); + Mocha.test("logStats", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 1, "1"); + Belt_HashMap.logStats(hMap); + }); + Mocha.test("make", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 0, "a"); + }); + Mocha.test("mergeMany", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.mergeMany(hMap, [ + [ + 1, + "1" + ], + [ + 2, + "2" + ] + ]); + }); + Mocha.test("reduce", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Stdlib.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); + }); + Mocha.test("remove", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.remove(s0, 1); + Belt_HashMap.has(s0, 1) === false; + }); + Mocha.test("set", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntHash); + Belt_HashMap.set(s0, 2, "3"); + Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ + "1", + "3", + "3" + ]); + }); + Mocha.test("size", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Belt_HashMap.size(s0) === 2; + }); + Mocha.test("toArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.toArray(s0), [ + [ + 1, + "value1" + ], + [ + 2, + "value2" + ] + ]); + }); + Mocha.test("valuesToArray", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq + }); + let s0 = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(s0, 1, "value1"); + Belt_HashMap.set(s0, 2, "value2"); + Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ + "value1", + "value2" + ]); + }); +}); + +Mocha.describe("Belt_Int", () => { + Mocha.test("*", () => { + Stdlib.assertEqual(4, 4); + }); + Mocha.test("+", () => { + Stdlib.assertEqual(4, 4); + }); + Mocha.test("-", () => { + Stdlib.assertEqual(1, 1); + }); + Mocha.test("/", () => { + Stdlib.assertEqual(2, 2); + }); + Mocha.test("fromFloat", () => { + Stdlib.assertEqual(1, 1); + }); + Mocha.test("fromString", () => { + Stdlib.assertEqual(Belt_Int.fromString("1"), 1); + }); + Mocha.test("toFloat", () => { + Stdlib.assertEqual(1, 1.0); + }); + Mocha.test("toString", () => { + Stdlib.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt_List", () => { + Mocha.test("add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); + Mocha.test("cmp", () => { + Belt_List.cmp({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 4, + tl: { + hd: 2, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Belt_List.cmp({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + }); + Mocha.test("cmpByLength", () => { + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + }); + }); + Mocha.test("concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); + Mocha.test("concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); + Mocha.test("drop", () => { + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 3); + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("eq", () => { + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Belt_List.eq({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("every", () => { + let isBelow10 = value => value < 10; + Belt_List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + Belt_List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + }); + Mocha.test("every2", () => { + Belt_List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Belt_List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("filter", () => { + let isEven = x => x % 2 === 0; + Belt_List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + Belt_List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Belt_Option.isSome); + }); + Mocha.test("filterWithIndex", () => { + Belt_List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); + Mocha.test("flatten", () => { + Belt_List.flatten({ + hd: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + tl: { + hd: /* [] */0, + tl: { + hd: { + hd: 3, + tl: /* [] */0 + }, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); + Mocha.test("forEach2", () => { + Belt_List.forEach2({ + hd: "Z", + tl: { + hd: "Y", + tl: /* [] */0 + } + }, { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }, (x, y) => { + console.log(x, y); + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); + }); + Mocha.test("fromArray", () => { + Belt_List.fromArray([ + 1, + 2, + 3 + ]); + }); + Mocha.test("get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); + Mocha.test("getAssoc", () => { + Belt_List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + Belt_List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); + }); + Mocha.test("getBy", () => { + Belt_List.getBy({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 3); + Belt_List.getBy({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); + Mocha.test("getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Stdlib.assertEqual(Belt_List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = Belt_List.getExn(abc, 4); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 4127, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("has", () => { + Belt_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2, (a, b) => a === b); + Belt_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + Belt_List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("hasAssoc", () => { + Belt_List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Belt_List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); + }); + Mocha.test("head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("headExn", () => { + Stdlib.assertEqual(Belt_List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = Belt_List.headExn(/* [] */0); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 4164, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("keep", () => { + let isEven = x => x % 2 === 0; + Belt_List.keep({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + Belt_List.keep({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Belt_Option.isSome); + }); + Mocha.test("keepMap", () => { + let isEven = x => x % 2 === 0; + Belt_List.keepMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => { + if (isEven(x)) { + return x; + } + + }); + Belt_List.keepMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); + }); + Mocha.test("keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); + Mocha.test("length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("make", () => { + Belt_List.make(3, 1); + }); + Mocha.test("makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => i * i | 0); + }); + Mocha.test("map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); + Mocha.test("mapReverse", () => { + Stdlib.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => x * x | 0), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("mapReverse2", () => { + Belt_List.mapReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a + b | 0); + }); + Mocha.test("mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); + }); + Mocha.test("partition", () => { + Stdlib.assertEqual(Belt_List.partition({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => x > 2), [ + { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }, + { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + } + ]); + }); + Mocha.test("reduce", () => { + Belt_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Belt_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); + }); + Mocha.test("reduce2", () => { + Belt_List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceReverse", () => { + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, Belt_List.add); + }); + Mocha.test("reduceReverse2", () => { + Belt_List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceWithIndex", () => { + Belt_List.reduceWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item, index) => (acc + item | 0) + index | 0); + }); + Mocha.test("removeAssoc", () => { + Belt_List.removeAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Belt_List.removeAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); + }); + Mocha.test("reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); + Mocha.test("setAssoc", () => { + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + Belt_List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); + Mocha.test("shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("some", () => { + let isAbove100 = value => value > 100; + Belt_List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + Belt_List.some({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isAbove100); + }); + Mocha.test("some2", () => { + Belt_List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Belt_List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("sort", () => { + Belt_List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } + } + }, (a, b) => a - b | 0); + }); + Mocha.test("splitAt", () => { + Belt_List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + Belt_List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); + }); + Mocha.test("tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Belt_List.tail(/* [] */0); + }); + Mocha.test("tailExn", () => { + Stdlib.assertEqual(Belt_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }); + let exit = 0; + let val; + try { + val = Belt_List.tailExn(/* [] */0); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 4387, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("take", () => { + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Belt_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("unzip", () => { + Belt_List.unzip({ + hd: [ + 1, + 2 + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + Belt_List.unzip({ + hd: [ + "H", + "W" + ], + tl: { + hd: [ + "e", + "o" + ], + tl: { + hd: [ + "l", + "r" + ], + tl: { + hd: [ + "l", + "l" + ], + tl: { + hd: [ + "o", + "d" + ], + tl: { + hd: [ + " ", + "!" + ], + tl: /* [] */0 + } + } + } + } + } + }); + }); + Mocha.test("zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("zipBy", () => { + Belt_List.zipBy({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, (a, b) => (a << 1) + b | 0); + }); +}); + +Mocha.describe("Belt_Map", () => { + Mocha.test("Int", () => {}); + Mocha.test("findFirstBy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] + ], IntCmp); + Stdlib.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_Map.forEach(s0, (k, v) => { + acc.contents = { + hd: [ + k, + v + ], + tl: acc.contents + }; + }); + Primitive_object.equal(acc.contents, { + hd: [ + 4, + "4" + ], + tl: { + hd: [ + 3, + "3" + ], + tl: { + hd: [ + 2, + "2" + ], + tl: { + hd: [ + 1, + "1" + ], + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ]); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp), 2), "2"); + Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp), 2) === undefined; + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.has(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp), 1) === true; + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; + }); + Mocha.test("keysToArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + 1, + 2, + 3 + ]); + }); + Mocha.test("make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let m = Belt_Map.make(IntCmp); + Belt_Map.set(m, 0, "a"); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp); + Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ + hd: [ + k, + v + ], + tl: acc + })); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp); + let s1 = Belt_Map.remove(s0, 1); + Belt_Map.remove(s1, 1); + Primitive_object.equal(Belt_Map.keysToArray(s1), [ + 2, + 3 + ]); + }); + Mocha.test("set", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp); + let s1 = Belt_Map.set(s0, 2, "3"); + Primitive_object.equal(Belt_Map.valuesToArray(s1), [ + "1", + "3", + "3" + ]); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ]); + }); + Mocha.test("valuesToArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.valuesToArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + "1", + "2", + "3" + ]); + }); +}); + +Mocha.describe("Belt_Map.Dict", () => { + Mocha.test("findFirstBy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MapDict.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp.cmp); + Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt_Map.Int", () => { + Mocha.test("findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt_Map.String", () => { + Mocha.test("findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt_MapDict", () => { + Mocha.test("findFirstBy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MapDict.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp.cmp); + Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt_MapInt", () => { + Mocha.test("findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt_MapString", () => { + Mocha.test("findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt_MutableSet", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + Belt_MutableSet.add(s0, 1); + Belt_MutableSet.add(s0, 2); + Belt_MutableSet.add(s0, 2); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("copy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + let copied = Belt_MutableSet.copy(s0); + Belt_MutableSet.toArray(copied); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); + Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); + }); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 5 + ], IntCmp); + Belt_MutableSet.eq(s0, s1); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_MutableSet.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.every(s0, isEven); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_MutableSet.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Belt_MutableSet.get(s0, 3); + Belt_MutableSet.get(s0, 20); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Belt_MutableSet.has(set, 3); + Belt_MutableSet.has(set, 1); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let intersect = Belt_MutableSet.intersect(s0, s1); + Belt_MutableSet.toArray(intersect); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_MutableSet.fromArray([], IntCmp); + let notEmpty = Belt_MutableSet.fromArray([1], IntCmp); + Belt_MutableSet.isEmpty(empty); + Belt_MutableSet.isEmpty(notEmpty); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_MutableSet.keep(s0, isEven); + Belt_MutableSet.toArray(s1); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.maxUndefined(s0); + Belt_MutableSet.maxUndefined(s1); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.maximum(s0); + Belt_MutableSet.maximum(s1); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.make(IntCmp); + Belt_MutableSet.mergeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Belt_MutableSet.toArray(set); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.minUndefined(s0); + Belt_MutableSet.minUndefined(s1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.make(IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.minimum(s0); + Belt_MutableSet.minimum(s1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_MutableSet.partition(s0, isOdd); + Belt_MutableSet.toArray(match[0]); + Belt_MutableSet.toArray(match[1]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp); + Belt_MutableSet.remove(s0, 1); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Belt_MutableSet.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Belt_MutableSet.toArray(set); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Belt_MutableSet.size(s0); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.some(s0, isOdd); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_MutableSet.split(s0, 3); + let match$1 = match[0]; + Belt_MutableSet.toArray(match$1[0]); + Belt_MutableSet.toArray(match$1[1]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let s2 = Belt_MutableSet.intersect(s0, s1); + Belt_MutableSet.subset(s2, s0); + Belt_MutableSet.subset(s2, s1); + Belt_MutableSet.subset(s1, s0); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.toArray(s0); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.toList(s0); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let union = Belt_MutableSet.union(s0, s1); + Belt_MutableSet.toArray(union); + }); +}); + +Mocha.describe("Belt_Option", () => { + Mocha.test("cmp", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Belt_Option.cmp(3, 15, clockCompare); + Belt_Option.cmp(3, 14, clockCompare); + Belt_Option.cmp(2, 15, clockCompare); + Belt_Option.cmp(undefined, 15, clockCompare); + Belt_Option.cmp(14, undefined, clockCompare); + Belt_Option.cmp(undefined, undefined, clockCompare); + }); + Mocha.test("eq", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Belt_Option.eq(3, 15, clockEqual); + Belt_Option.eq(3, undefined, clockEqual); + Belt_Option.eq(undefined, 3, clockEqual); + Belt_Option.eq(undefined, undefined, clockEqual); + }); + Mocha.test("flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + + }; + Belt_Option.flatMap(2, addIfAboveOne); + Belt_Option.flatMap(-4, addIfAboveOne); + Belt_Option.flatMap(undefined, addIfAboveOne); + }); + Mocha.test("forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Belt_Option.getExn(3), 3); + let exit = 0; + let val; + try { + val = Belt_Option.getExn(undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 5193, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getWithDefault", () => { + Belt_Option.getWithDefault(undefined, "Banana"); + Belt_Option.getWithDefault("Apple", "Banana"); + let greet = firstName => "Greetings " + Belt_Option.getWithDefault(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); + }); + Mocha.test("isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); + }); + Mocha.test("isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); + }); + Mocha.test("keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); + }); + Mocha.test("map", () => { + Belt_Option.map(3, x => x * x | 0); + Belt_Option.map(undefined, x => x * x | 0); + }); + Mocha.test("mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); + }); + Mocha.test("orElse", () => { + Primitive_object.equal(Belt_Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Belt_Option.orElse(undefined, 1066), 1066); + Belt_Option.orElse(undefined, undefined) === undefined; + }); +}); + +Mocha.describe("Belt_Range", () => { + Mocha.test("every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); + Mocha.test("everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); + Mocha.test("forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); + Mocha.test("some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); + Mocha.test("someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt_Result", () => { + Mocha.test("cmp", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Belt_Result.cmp({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Belt_Result.cmp({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Belt_Result.cmp({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Belt_Result.cmp({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Belt_Result.cmp({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; + }); + Mocha.test("eq", () => { + let good1 = { + TAG: "Ok", + _0: 42 + }; + let good2 = { + TAG: "Ok", + _0: 32 + }; + let bad1 = { + TAG: "Error", + _0: "invalid" + }; + let bad2 = { + TAG: "Error", + _0: "really invalid" + }; + let mod10equal = (a, b) => a % 10 === b % 10; + Belt_Result.eq(good1, good2, mod10equal) === true; + Belt_Result.eq(good1, bad1, mod10equal) === false; + Belt_Result.eq(bad2, good2, mod10equal) === false; + Belt_Result.eq(bad1, bad2, mod10equal) === true; + }); + Mocha.test("flatMap", () => { + let recip = x => { + if (x !== 0.0) { + return { + TAG: "Ok", + _0: 1.0 / x + }; + } else { + return { + TAG: "Error", + _0: "Divide by zero" + }; + } + }; + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 + }); + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Belt_Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" + }); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Belt_Result.getExn({ + TAG: "Ok", + _0: 42 + }), 42); + let exit = 0; + let val; + try { + val = Belt_Result.getExn({ + TAG: "Error", + _0: "Invalid data" + }); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 5383, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); + Mocha.test("map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Belt_Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Belt_Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); + }); + Mocha.test("mapWithDefault", () => { + Belt_Result.mapWithDefault({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Belt_Result.mapWithDefault({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; + }); +}); + +Mocha.describe("Belt_Set", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.add(s0, 1); + let s2 = Belt_Set.add(s1, 2); + let s3 = Belt_Set.add(s2, 2); + Stdlib.assertEqual(Belt_Set.toArray(s0), []); + Stdlib.assertEqual(Belt_Set.toArray(s1), [1]); + Stdlib.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Stdlib.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Stdlib.assertEqual(s2, s3); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); + }); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.eq(s0, s1), true); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_Set.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.every(s0, isEven), true); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_Set.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + Stdlib.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 4 + ]); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.get(s0, 3), 3); + Stdlib.assertEqual(Belt_Set.get(s0, 20), undefined); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.has(set, 3), false); + Stdlib.assertEqual(Belt_Set.has(set, 1), true); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let intersect = Belt_Set.intersect(s0, s1); + Stdlib.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Stdlib.assertEqual(Belt_Set.isEmpty(empty), true); + Stdlib.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_Set.keep(s0, isEven); + Stdlib.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); + }); + Mocha.test("make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Stdlib.assertEqual(Belt_Set.isEmpty(set), true); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.maximum(s0), undefined); + Stdlib.assertEqual(Belt_Set.maximum(s1), 5); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + let newSet = Belt_Set.mergeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Stdlib.assertEqual(Belt_Set.toArray(newSet), [ + 1, + 2, + 3, + 4, + 5 + ]); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.minimum(s0), undefined); + Stdlib.assertEqual(Belt_Set.minimum(s1), 1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Stdlib.assertEqual(Belt_Set.toArray(match[0]), [ + 1, + 3, + 5 + ]); + Stdlib.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 + ]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp); + let s1 = Belt_Set.remove(s0, 1); + let s2 = Belt_Set.remove(s1, 3); + let s3 = Belt_Set.remove(s2, 3); + Stdlib.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Stdlib.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Stdlib.assertEqual(s2, s3); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + let newSet = Belt_Set.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Stdlib.assertEqual(Belt_Set.toArray(newSet), []); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.size(s0), 4); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.some(s0, isOdd), true); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.split(s0, 3); + let match$1 = match[0]; + Stdlib.assertEqual(match[1], true); + Stdlib.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Stdlib.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let s2 = Belt_Set.intersect(s0, s1); + Stdlib.assertEqual(Belt_Set.subset(s2, s0), true); + Stdlib.assertEqual(Belt_Set.subset(s2, s1), true); + Stdlib.assertEqual(Belt_Set.subset(s1, s0), false); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Stdlib.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp); + let union = Belt_Set.union(s0, s1); + Stdlib.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); + }); +}); + +Mocha.describe("Belt_Set.Dict", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); + let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); + let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); + Belt_SetDict.toArray(undefined); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Belt_SetDict.toArray(s3); + Primitive_object.equal(s2, s3); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); + let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); + Belt_SetDict.toArray(diff1); + Belt_SetDict.toArray(diff2); + }); + Mocha.test("empty", () => {}); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.eq(s0, s1, IntCmp.cmp); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let acc = { + contents: /* [] */0 + }; + Belt_SetDict.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.has(set, 3, IntCmp.cmp); + Belt_SetDict.has(set, 1, IntCmp.cmp); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(intersect); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_SetDict.fromArray([], IntCmp.cmp); + let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); + Belt_SetDict.isEmpty(empty); + Belt_SetDict.isEmpty(notEmpty); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maxUndefined(undefined); + Belt_SetDict.maxUndefined(s1); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maximum(undefined); + Belt_SetDict.maximum(s1); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let newSet = Belt_SetDict.mergeMany(undefined, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); + let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); + let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Primitive_object.equal(s2, s3); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + let newSet = Belt_SetDict.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + Belt_SetDict.size(s0); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); + let match$1 = match[0]; + Belt_SetDict.toArray(match$1[0]); + Belt_SetDict.toArray(match$1[1]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.subset(s2, s0, IntCmp.cmp); + Belt_SetDict.subset(s2, s1, IntCmp.cmp); + Belt_SetDict.subset(s1, s0, IntCmp.cmp); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toList(s0); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(union); + }); +}); + +Mocha.describe("Belt_SetDict", () => { + Mocha.test("add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); + let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); + let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); + Belt_SetDict.toArray(undefined); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Belt_SetDict.toArray(s3); + Primitive_object.equal(s2, s3); + }); + Mocha.test("diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); + let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); + Belt_SetDict.toArray(diff1); + Belt_SetDict.toArray(diff2); + }); + Mocha.test("empty", () => {}); + Mocha.test("eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.eq(s0, s1, IntCmp.cmp); + }); + Mocha.test("every", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); + }); + Mocha.test("forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let acc = { + contents: /* [] */0 + }; + Belt_SetDict.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); + Mocha.test("fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); + }); + Mocha.test("has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.has(set, 3, IntCmp.cmp); + Belt_SetDict.has(set, 1, IntCmp.cmp); + }); + Mocha.test("intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(intersect); + }); + Mocha.test("isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let empty = Belt_SetDict.fromArray([], IntCmp.cmp); + let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); + Belt_SetDict.isEmpty(empty); + Belt_SetDict.isEmpty(notEmpty); + }); + Mocha.test("keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isEven = x => x % 2 === 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); + }); + Mocha.test("maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maxUndefined(undefined); + Belt_SetDict.maxUndefined(s1); + }); + Mocha.test("maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maximum(undefined); + Belt_SetDict.maximum(s1); + }); + Mocha.test("mergeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let newSet = Belt_SetDict.mergeMany(undefined, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); + }); + Mocha.test("minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); + }); + Mocha.test("partition", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); + }); + Mocha.test("reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); + }); + Mocha.test("remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 2, + 3, + 1, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); + let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); + let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); + Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(s2); + Primitive_object.equal(s2, s3); + }); + Mocha.test("removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + let newSet = Belt_SetDict.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); + }); + Mocha.test("size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp.cmp); + Belt_SetDict.size(s0); + }); + Mocha.test("some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); + }); + Mocha.test("split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp.cmp); + let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); + let match$1 = match[0]; + Belt_SetDict.toArray(match$1[0]); + Belt_SetDict.toArray(match$1[1]); + }); + Mocha.test("subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.subset(s2, s0, IntCmp.cmp); + Belt_SetDict.subset(s2, s1, IntCmp.cmp); + Belt_SetDict.subset(s1, s0, IntCmp.cmp); + }); + Mocha.test("toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); + }); + Mocha.test("toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toList(s0); + }); + Mocha.test("union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, + 3, + 1, + 5, + 4 + ], IntCmp.cmp); + let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(union); + }); +}); + +Mocha.describe("Belt_SortArray", () => { + Mocha.test("binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, + 2, + 3, + 4, + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 1, + 3, + 5, + 7 + ], 4, Primitive_int.compare)) === 2; + }); + Mocha.test("strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ + 1, + 2, + 3, + 4, + 3 + ], (x, y) => x < y) === 4; + Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; + Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; + Belt_SortArray.strictlySortedLength([ + 4, + 3, + 2, + 1 + ], (x, y) => x < y) === -4; + }); +}); + +Mocha.describe("Belt_internalMapInt.A", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.S", () => { + Mocha.test("binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, + 2, + 3, + 4, + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 1, + 3, + 5, + 7 + ], 4, Primitive_int.compare)) === 2; + }); + Mocha.test("strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ + 1, + 2, + 3, + 4, + 3 + ], (x, y) => x < y) === 4; + Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; + Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; + Belt_SortArray.strictlySortedLength([ + 4, + 3, + 2, + 1 + ], (x, y) => x < y) === -4; + }); +}); + +Mocha.describe("Belt_internalMapString.A", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.S", () => { + Mocha.test("binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, + 2, + 3, + 4, + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 1, + 3, + 5, + 7 + ], 4, Primitive_int.compare)) === 2; + }); + Mocha.test("strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ + 1, + 2, + 3, + 4, + 3 + ], (x, y) => x < y) === 4; + Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; + Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; + Belt_SortArray.strictlySortedLength([ + 4, + 3, + 2, + 1 + ], (x, y) => x < y) === -4; + }); +}); + +Mocha.describe("Belt_internalSetInt.A", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A", () => { + Mocha.test("blit", () => { + let v1 = [ + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17 + ]; + let v2 = [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27 + ]; + Belt_Array.blit(v1, 4, v2, 2, 3); + Primitive_object.equal(v2, [ + 20, + 21, + 14, + 15, + 16, + 25, + 26, + 27 + ]); + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 + ]); + }); + Mocha.test("cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; + }); + Mocha.test("concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); + }); + Mocha.test("concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); + Mocha.test("eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); + Mocha.test("every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); + Mocha.test("every2", () => { + Belt_Array.every2([ + 1, + 2, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 2, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ + 5, + 0 + ], (x, y) => x > y) === false; + }); + Mocha.test("fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); + Mocha.test("forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); + }); + Mocha.test("forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); + Mocha.test("get", () => { + Primitive_object.equal(Belt_Array.get([ + "a", + "b", + "c" + ], 0), "a"); + Belt_Array.get([ + "a", + "b", + "c" + ], 3) === undefined; + Belt_Array.get([ + "a", + "b", + "c" + ], -1) === undefined; + }); + Mocha.test("getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ + 1, + 4, + 3, + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); + Mocha.test("joinWith", () => { + Belt_Array.joinWith([ + 0, + 1 + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); + Mocha.test("keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); + Mocha.test("keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); + Mocha.test("length", () => {}); + Mocha.test("makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); + Mocha.test("makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); + Mocha.test("makeUninitializedUnsafe", () => { + let arr = new Array(5); + console.log(Belt_Array.getExn(arr, 0)); + Belt_Array.setExn(arr, 0, "example"); + console.log(Belt_Array.getExn(arr, 0) === "example"); + }); + Mocha.test("map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); + Mocha.test("mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); + Mocha.test("partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); + }); + Mocha.test("rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, + 3, + 6, + 9 + ]); + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, + 6, + 9, + 12 + ]); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); + Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); + Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); + }); + Mocha.test("reduce", () => { + Belt_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; + }); + Mocha.test("reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); + Mocha.test("reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); + Mocha.test("reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); + Mocha.test("reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); + Mocha.test("slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4, 3), [ + 13, + 14, + 15 + ]); + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 + ]); + }); + Mocha.test("sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 + ]); + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 + ]); + }); + Mocha.test("some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); + Mocha.test("some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ + 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ + 2, + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; + }); + Mocha.test("truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); + Mocha.test("unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); + Mocha.test("zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); + Mocha.test("zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Pervasives", () => { + Mocha.test("throw", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); + }); +}); + +Mocha.describe("Stdlib", () => { + Mocha.test("Option", () => {}); + Mocha.test("assertEqual", () => { + Stdlib.assertEqual(Stdlib_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }), { + hd: 2, + tl: /* [] */0 + }); + }); + Mocha.test("clearInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints in 100 ms"); + }, 100); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); + Mocha.test("clearTimeout", () => { + let timeoutId = setTimeout(() => { + console.log("This prints in 2 seconds."); + }, 2000); + clearTimeout(timeoutId); + }); + Mocha.test("decodeURI", () => { + console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); + }); + Mocha.test("decodeURIComponent", () => { + console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); + }); + Mocha.test("encodeURI", () => { + console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); + }); + Mocha.test("encodeURIComponent", () => { + console.log(encodeURIComponent("array=[someValue]")); + }); + Mocha.test("import", () => {}); + Mocha.test("setInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms."); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); + Mocha.test("setIntervalFloat", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms"); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500.0); + }); + Mocha.test("setTimeout", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); + Mocha.test("setTimeoutFloat", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); +}); + +Mocha.describe("Stdlib.Array", () => { + Mocha.test("at", () => { + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(0), "a"); + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(2), "c"); + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(3), undefined); + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(-1), "c"); + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(-3), "a"); + Stdlib.assertEqual([ + "a", + "b", + "c" + ].at(-4), undefined); + }); + Mocha.test("concat", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = [ + "yay", + "wehoo" + ]; + let someArray = array1.concat(array2); + Stdlib.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); + }); + Mocha.test("concatMany", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = ["yay"]; + let array3 = ["wehoo"]; + let someArray = array1.concat(array2, array3); + console.log(someArray); + }); + Mocha.test("copy", () => { + let myArray = [ + 1, + 2, + 3 + ]; + let copyOfMyArray = myArray.slice(); + Stdlib.assertEqual(copyOfMyArray, [ + 1, + 2, + 3 + ]); + Stdlib.assertEqual(myArray === copyOfMyArray, false); + }); + Mocha.test("every", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Stdlib.assertEqual(array.every(num => num <= 4), true); + Stdlib.assertEqual(array.every(num => num === 1), false); + }); + Mocha.test("everyWithIndex", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Stdlib.assertEqual(array.every((num, index) => { + if (index < 5) { + return num <= 4; + } else { + return false; + } + }), true); + Stdlib.assertEqual(array.every((num, index) => { + if (index < 2) { + return num >= 2; + } else { + return false; + } + }), false); + }); + Mocha.test("fill", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1, 3); + Stdlib.assertEqual(myArray, [ + 1, + 9, + 9, + 4 + ]); + }); + Mocha.test("fillAll", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9); + Stdlib.assertEqual(myArray, [ + 9, + 9, + 9, + 9 + ]); + }); + Mocha.test("fillToEnd", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1); + Stdlib.assertEqual(myArray, [ + 1, + 9, + 9, + 9 + ]); + }); + Mocha.test("filter", () => { + Stdlib.assertEqual([ + 1, + 2, + 3, + 4 + ].filter(num => num > 2), [ + 3, + 4 + ]); + }); + Mocha.test("filterMap", () => { + Stdlib.assertEqual(Stdlib_Array.filterMap([ + "Hello", + "Hi", + "Good bye" + ], item => { + if (item === "Hello") { + return item.length; + } + + }), [5]); + Stdlib.assertEqual(Stdlib_Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return n * n | 0; + } + + }), [ + 4, + 16, + 36 + ]); + Stdlib.assertEqual(Stdlib_Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), []); + Stdlib.assertEqual(Stdlib_Array.filterMap([], n => { + if (n % 2 === 0) { + return n * n | 0; + } + + }), []); + }); + Mocha.test("filterWithIndex", () => { + Stdlib.assertEqual([ + 1, + 2, + 3, + 4 + ].filter((num, index) => { + if (index === 0) { + return true; + } else { + return num === 2; + } + }), [ + 1, + 2 + ]); + }); + Mocha.test("find", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Stdlib.assertEqual(array.find(item => item === "ReScript"), "ReScript"); + }); + Mocha.test("findIndex", () => { + let array = [ + "ReScript", + "JavaScript" + ]; + Stdlib.assertEqual(array.findIndex(item => item === "ReScript"), 0); + Stdlib.assertEqual(array.findIndex(item => item === "TypeScript"), -1); + }); + Mocha.test("findIndexOpt", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Stdlib.assertEqual(Stdlib_Array.findIndexOpt(array, item => item === "ReScript"), 0); + }); + Mocha.test("findIndexWithIndex", () => { + let array = [ + "ReScript", + "JavaScript" + ]; + let isReScriptFirst = array.findIndex((item, index) => { + if (index === 0) { + return item === "ReScript"; + } else { + return false; + } + }); + let isTypeScriptFirst = array.findIndex((item, index) => { + if (index === 0) { + return item === "TypeScript"; + } else { + return false; + } + }); + Stdlib.assertEqual(isReScriptFirst, 0); + Stdlib.assertEqual(isTypeScriptFirst, -1); + }); + Mocha.test("findMap", () => { + Stdlib.assertEqual(Stdlib_Array.findMap([ + 1, + 2, + 3 + ], n => { + if (n % 2 === 0) { + return n - 2 | 0; + } + + }), 0); + Stdlib.assertEqual(Stdlib_Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return n - 8 | 0; + } + + }), -6); + Stdlib.assertEqual(Stdlib_Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), undefined); + Stdlib.assertEqual(Stdlib_Array.findMap([], n => { + if (n % 2 === 0) { + return n * n | 0; + } + + }), undefined); + }); + Mocha.test("findWithIndex", () => { + let array = [ + "TypeScript", + "JavaScript", + "ReScript" + ]; + Stdlib.assertEqual(array.find((item, index) => { + if (index > 1) { + return item === "ReScript"; + } else { + return false; + } + }), "ReScript"); + }); + Mocha.test("flat", () => { + Stdlib.assertEqual([ + [1], + [2], + [ + 3, + 4 + ] + ].flat(), [ + 1, + 2, + 3, + 4 + ]); + }); + Mocha.test("flatMap", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Stdlib.assertEqual(array.flatMap(item => { + switch (item) { + case "ReScript" : + return [ + 1, + 2, + 3 + ]; + case "TypeScript" : + return [ + 4, + 5, + 6 + ]; + case "JavaScript" : + return [ + 7, + 8, + 9 + ]; + } + }), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); + }); + Mocha.test("flatMapWithIndex", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Stdlib.assertEqual(array.flatMap((item, index) => { + switch (item) { + case "ReScript" : + return [index]; + case "TypeScript" : + return [ + index, + index + 1 | 0 + ]; + case "JavaScript" : + return [ + index, + index + 1 | 0, + index + 2 | 0 + ]; + } + }), [ + 0, + 1, + 2, + 2, + 3, + 4 + ]); + }); + Mocha.test("forEach", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach(item => { + console.log(item); + }); + }); + Mocha.test("forEachWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach((item, index) => { + console.log("At item " + index.toString() + ": " + item); + }); + }); + Mocha.test("fromInitializer", () => { + Stdlib.assertEqual(Stdlib_Array.fromInitializer(3, i => i + 3 | 0), [ + 3, + 4, + 5 + ]); + Stdlib.assertEqual(Stdlib_Array.fromInitializer(7, i => i + 3 | 0), [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); + }); + Mocha.test("fromIterator", () => { + Stdlib.assertEqual(Array.from(new Map([ + [ + "foo", + 1 + ], + [ + "bar", + 2 + ] + ]).values()), [ + 1, + 2 + ]); + }); + Mocha.test("get", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Stdlib.assertEqual(array[0], "Hello"); + Stdlib.assertEqual(array[3], undefined); + }); + Mocha.test("getUnsafe", () => { + let array = [ + 1, + 2, + 3 + ]; + for (let index = 0, index_finish = array.length; index < index_finish; ++index) { + let value = array[index]; + console.log(value); + } + }); + Mocha.test("includes", () => { + Stdlib.assertEqual([ + 1, + 2 + ].includes(1), true); + Stdlib.assertEqual([ + 1, + 2 + ].includes(3), false); + Stdlib.assertEqual([{ + language: "ReScript" + }].includes({ + language: "ReScript" + }), false); + }); + Mocha.test("indexOf", () => { + Stdlib.assertEqual([ + 1, + 2 + ].indexOf(2), 1); + Stdlib.assertEqual([ + 1, + 2 + ].indexOf(3), -1); + Stdlib.assertEqual([{ + language: "ReScript" + }].indexOf({ + language: "ReScript" + }), -1); + }); + Mocha.test("indexOfOpt", () => { + Stdlib.assertEqual(Stdlib_Array.indexOfOpt([ + 1, + 2 + ], 2), 1); + Stdlib.assertEqual(Stdlib_Array.indexOfOpt([ + 1, + 2 + ], 3), undefined); + Stdlib.assertEqual(Stdlib_Array.indexOfOpt([{ + language: "ReScript" + }], { + language: "ReScript" + }), undefined); + }); + Mocha.test("join", () => { + Stdlib.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); + Mocha.test("joinUnsafe", () => { + Stdlib.assertEqual([ + 1, + 2, + 3 + ].join(" -- "), "1 -- 2 -- 3"); + }); + Mocha.test("joinWith", () => { + Stdlib.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); + Mocha.test("joinWithUnsafe", () => { + Stdlib.assertEqual([ + 1, + 2, + 3 + ].join(" -- "), "1 -- 2 -- 3"); + }); + Mocha.test("keepSome", () => { + Stdlib.assertEqual(Stdlib_Array.keepSome([ + 1, + undefined, + 3 + ]), [ + 1, + 3 + ]); + Stdlib.assertEqual(Stdlib_Array.keepSome([ + 1, + 2, + 3 + ]), [ + 1, + 2, + 3 + ]); + Stdlib.assertEqual(Stdlib_Array.keepSome([ + undefined, + undefined, + undefined + ]), []); + Stdlib.assertEqual(Stdlib_Array.keepSome([]), []); + }); + Mocha.test("last", () => { + Stdlib.assertEqual(Stdlib_Array.last([ + "Hello", + "Hi", + "Good bye" + ]), "Good bye"); + Stdlib.assertEqual(Stdlib_Array.last([]), undefined); + }); + Mocha.test("length", () => { + let someArray = [ + "hi", + "hello" + ]; + Stdlib.assertEqual(someArray.length, 2); + }); + Mocha.test("make", () => { + Stdlib.assertEqual(Stdlib_Array.make(3, "apple"), [ + "apple", + "apple", + "apple" + ]); + Stdlib.assertEqual(Stdlib_Array.make(6, 7), [ + 7, + 7, + 7, + 7, + 7, + 7 + ]); + }); + Mocha.test("map", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map(greeting => greeting + " to you"); + Stdlib.assertEqual(mappedArray, [ + "Hello to you", + "Hi to you", + "Good bye to you" + ]); + }); + Mocha.test("mapWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); + Stdlib.assertEqual(mappedArray, [ + "Hello at position 0", + "Hi at position 1", + "Good bye at position 2" + ]); + }); + Mocha.test("pop", () => { + let someArray = [ + "hi", + "hello" + ]; + Stdlib.assertEqual(someArray.pop(), "hello"); + Stdlib.assertEqual(someArray, ["hi"]); + }); + Mocha.test("push", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay"); + Stdlib.assertEqual(someArray, [ + "hi", + "hello", + "yay" + ]); + }); + Mocha.test("pushMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay", "wehoo"); + Stdlib.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); + }); + Mocha.test("reduce", () => { + Stdlib.assertEqual(Stdlib_Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0), 10); + Stdlib.assertEqual(Stdlib_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "abcd"); + Stdlib.assertEqual(Stdlib_Array.reduce([ + 1, + 2, + 3 + ], /* [] */0, Stdlib_List.add), { + hd: 3, + tl: { + hd: 2, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + Stdlib.assertEqual(Stdlib_Array.reduce([], /* [] */0, Stdlib_List.add), /* [] */0); + }); + Mocha.test("reduceRight", () => { + Stdlib.assertEqual(Stdlib_Array.reduceRight([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "dcba"); + Stdlib.assertEqual(Stdlib_Array.reduceRight([ + 1, + 2, + 3 + ], /* [] */0, Stdlib_List.add), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Stdlib.assertEqual(Stdlib_Array.reduceRight([], /* [] */0, Stdlib_List.add), /* [] */0); + }); + Mocha.test("reduceRightWithIndex", () => { + Stdlib.assertEqual(Stdlib_Array.reduceRightWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Stdlib.assertEqual(Stdlib_Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); + }); + Mocha.test("reduceWithIndex", () => { + Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([ + 1, + 2, + 3 + ], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); + }); + Mocha.test("removeInPlace", () => { + let array = []; + array.splice(0, 1); + Stdlib.assertEqual(array, []); + let array2 = [ + "Hello", + "Hi", + "Good bye" + ]; + array2.splice(1, 1); + Stdlib.assertEqual(array2, [ + "Hello", + "Good bye" + ]); + }); + Mocha.test("reverse", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.reverse(); + Stdlib.assertEqual(someArray, [ + "hello", + "hi" + ]); + }); + Mocha.test("set", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Stdlib.assertEqual(array[1], "Hello"); + }); + Mocha.test("setUnsafe", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Stdlib.assertEqual(array[1], "Hello"); + }); + Mocha.test("shift", () => { + let someArray = [ + "hi", + "hello" + ]; + Stdlib.assertEqual(someArray.shift(), "hi"); + Stdlib.assertEqual(someArray, ["hello"]); + }); + Mocha.test("shuffle", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Stdlib_Array.shuffle(array); + console.log(array); + let array2 = [ + 1, + 2, + 3 + ]; + Stdlib_Array.shuffle(array2); + Stdlib.assertEqual(array2.length, 3); + }); + Mocha.test("slice", () => { + Stdlib.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1, 3), [ + 2, + 3 + ]); + }); + Mocha.test("sliceToEnd", () => { + Stdlib.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1), [ + 2, + 3, + 4 + ]); + }); + Mocha.test("some", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Stdlib.assertEqual(array.some(greeting => greeting === "Hello"), true); + }); + Mocha.test("someWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Stdlib.assertEqual(array.some((greeting, index) => { + if (greeting === "Hello") { + return index === 0; + } else { + return false; + } + }), true); + }); + Mocha.test("sort", () => { + let array = [ + 3, + 2, + 1 + ]; + array.sort((a, b) => a - b | 0); + Stdlib.assertEqual(array, [ + 1, + 2, + 3 + ]); + }); + Mocha.test("toReversed", () => { + let someArray = [ + "hi", + "hello" + ]; + let reversed = someArray.toReversed(); + Stdlib.assertEqual(reversed, [ + "hello", + "hi" + ]); + Stdlib.assertEqual(someArray, [ + "hi", + "hello" + ]); + }); + Mocha.test("toShuffled", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let shuffledArray = Stdlib_Array.toShuffled(array); + console.log(shuffledArray); + Stdlib.assertEqual(Stdlib_Array.toShuffled([ + 1, + 2, + 3 + ]).length, 3); + }); + Mocha.test("toSorted", () => { + let someArray = [ + 3, + 2, + 1 + ]; + Stdlib.assertEqual(someArray.toSorted(Primitive_int.compare), [ + 1, + 2, + 3 + ]); + Stdlib.assertEqual(someArray, [ + 3, + 2, + 1 + ]); + }); + Mocha.test("toString", () => { + Stdlib.assertEqual([ + 1, + 2, + 3, + 4 + ].toString(), "1,2,3,4"); + }); + Mocha.test("unsafe_get", () => { + let array = [ + 1, + 2, + 3 + ]; + for (let index = 0, index_finish = array.length; index < index_finish; ++index) { + let value = array[index]; + console.log(value); + } + }); + Mocha.test("unshift", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay"); + Stdlib.assertEqual(someArray, [ + "yay", + "hi", + "hello" + ]); + }); + Mocha.test("unshiftMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay", "wehoo"); + Stdlib.assertEqual(someArray, [ + "yay", + "wehoo", + "hi", + "hello" + ]); + }); +}); + +Mocha.describe("Stdlib.AsyncIterator", () => { + Mocha.test("done", () => { + let context = { + contents: 0 + }; + Stdlib_AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return Stdlib_AsyncIterator.done(undefined); + } else { + return Stdlib_AsyncIterator.value(currentValue); + } + }); + }); + Mocha.test("forEach", () => { + let asyncIterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + let main = async () => await Stdlib_AsyncIterator.forEach(asyncIterator, v => { + if (v !== undefined && v[0] === "second") { + return Stdlib.assertEqual(v[1], "2"); + } + + }); + main(); + }); + Mocha.test("make", () => { + let context = { + contents: 0 + }; + let asyncIterator = Stdlib_AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + return { + done: currentValue >= 3, + value: currentValue + }; + }); + let main = async () => await Stdlib_AsyncIterator.forEach(asyncIterator, value => { + if (value !== undefined) { + console.log(value); + return; + } + + }); + main(); + }); + Mocha.test("next", () => { + let asyncIterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + let processMyAsyncIterator = async () => { + let $$break = false; + while (!$$break) { + let match = await asyncIterator.next(); + let done = match.done; + $$break = done; + if (done) { + Stdlib.assertEqual(Stdlib_Option.isNone(match.value), true); + } + + }; + }; + processMyAsyncIterator(); + }); + Mocha.test("value", () => { + let context = { + contents: 0 + }; + Stdlib_AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return Stdlib_AsyncIterator.done(undefined); + } else { + return Stdlib_AsyncIterator.value(currentValue); + } + }); + }); +}); + +Mocha.describe("Stdlib.BigInt", () => { + Mocha.test("fromStringExn", () => { + Stdlib.assertEqual(BigInt("123"), 123n); + Stdlib.assertEqual(BigInt(""), 0n); + Stdlib.assertEqual(BigInt("0x11"), 17n); + Stdlib.assertEqual(BigInt("0b11"), 3n); + Stdlib.assertEqual(BigInt("0o11"), 9n); + let exit = 0; + let _bigInt; + try { + _bigInt = BigInt("a"); + exit = 1; + } catch (raw__error) { + let _error = Primitive_exceptions.internalToException(raw__error); + if (_error.RE_EXN_ID !== Stdlib_Exn.$$Error) { + throw _error; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 9180, + 13 + ], + Error: new Error() + }; + } + + }); + Mocha.test("toLocaleString", () => { + Stdlib.assertEqual((123n).toString(), "123"); + }); + Mocha.test("toString", () => { + Stdlib.assertEqual((123n).toString(), "123"); + }); +}); + +Mocha.describe("Stdlib.Bool", () => { + Mocha.test("fromString", () => { + Stdlib.assertEqual(Stdlib_Bool.fromString("true"), true); + Stdlib.assertEqual(Stdlib_Bool.fromString("false"), false); + Stdlib.assertEqual(Stdlib_Bool.fromString("notAValidBoolean"), undefined); + }); + Mocha.test("fromStringExn", () => { + Stdlib.assertEqual(Stdlib_Bool.fromStringExn("true"), true); + Stdlib.assertEqual(Stdlib_Bool.fromStringExn("false"), false); + let exit = 0; + let val; + try { + val = Stdlib_Bool.fromStringExn("notAValidBoolean"); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== "Invalid_argument") { + throw exn; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 9213, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("toString", () => { + Stdlib.assertEqual(Stdlib_Bool.toString(true), "true"); + Stdlib.assertEqual(Stdlib_Bool.toString(false), "false"); + }); +}); + +Mocha.describe("Stdlib.Char", () => { + Mocha.test("toLowerCaseAscii", () => { + Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'A' */65), /* 'a' */97); + Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'Z' */90), /* 'z' */122); + Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'a' */97), /* 'a' */97); + }); + Mocha.test("toUpperCaseAscii", () => { + Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'a' */97), /* 'A' */65); + Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'z' */122), /* 'Z' */90); + Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'A' */65), /* 'A' */65); + }); +}); + +Mocha.describe("Stdlib.Console", () => { + Mocha.test("assert2", () => { + console.assert(false, "Hello", "World"); + console.assert(true, [ + 1, + 2, + 3 + ], /* '4' */52); + }); + Mocha.test("assert3", () => { + console.assert(false, "Hello", "World", "ReScript"); + console.assert(true, "One", 2, 3); + }); + Mocha.test("assert4", () => { + console.assert(false, "Hello", "World", "ReScript", "!!!"); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); + Mocha.test("assert5", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); + Mocha.test("assert6", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("assertMany", () => { + console.assert(false, "Hello", "World"); + console.assert(true, 1, 2, 3); + }); + Mocha.test("assert_", () => { + console.assert(false, "Hello World!"); + console.assert(true, "The answer"); + }); + Mocha.test("clear", () => { + console.clear(); + }); + Mocha.test("count", () => { + console.count("rescript"); + }); + Mocha.test("countReset", () => { + console.countReset("rescript"); + }); + Mocha.test("debug", () => { + console.debug("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.debug(obj); + }); + Mocha.test("debug2", () => { + console.debug("Hello", "World"); + console.debug([ + 1, + 2, + 3 + ], /* '4' */52); + }); + Mocha.test("debug3", () => { + console.debug("Hello", "World", "ReScript"); + console.debug("One", 2, 3); + }); + Mocha.test("debug4", () => { + console.debug("Hello", "World", "ReScript", "!!!"); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); + Mocha.test("debug5", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); + Mocha.test("debug6", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("debugMany", () => { + console.debug("Hello", "World"); + console.debug(1, 2, 3); + }); + Mocha.test("dir", () => { + console.dir({ + language: "rescript", + version: "10.1.2" + }); + }); + Mocha.test("error", () => { + console.error("error message"); + console.error([ + "error", + "invalid value" + ]); + }); + Mocha.test("error2", () => { + console.error("Error", "here"); + console.error([ + "log", + "error" + ], "message"); + }); + Mocha.test("error3", () => { + console.error("Hello", "World", "!!!"); + console.error("first", "second", "third"); + }); + Mocha.test("error4", () => { + console.error("Hello", "World", "ReScript", /* '!' */33); + console.error("first", "second", "third", "fourth"); + }); + Mocha.test("error5", () => { + console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); + console.error(1, "second", "third", "fourth", /* 'c' */99); + }); + Mocha.test("error6", () => { + console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.error([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("errorMany", () => { + console.error("Hello", "World"); + console.error(1, 2, 3); + }); + Mocha.test("group", () => { + console.group("first group"); + console.group("second group"); + console.log("a message on the second level"); + console.groupEnd(); + console.log("a message message on the first level"); + console.groupEnd(); + }); + Mocha.test("info", () => { + console.info("Information"); + console.info([ + "Hello", + "JS" + ]); + }); + Mocha.test("info2", () => { + console.info("Info", "failed to download"); + console.info("info", { + name: "ReScript" + }); + }); + Mocha.test("info3", () => { + console.info("Hello", "World", "ReScript"); + console.info([ + 1, + 2, + 3 + ], 4, 5); + }); + Mocha.test("info4", () => { + console.info("Hello", "World", "ReScript", /* '!' */33); + console.info([ + 1, + 2, + 3 + ], 4, 5, "lastinfo"); + }); + Mocha.test("info5", () => { + console.info("Hello", "World", "from", "JS", "!!!"); + console.info([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); + Mocha.test("info6", () => { + console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.info([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("infoMany", () => { + console.info("Hello", "World"); + console.info(1, 2, 3); + }); + Mocha.test("log", () => { + console.log("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.log(obj); + }); + Mocha.test("log2", () => { + console.log("Hello", "World"); + console.log([ + 1, + 2, + 3 + ], /* '4' */52); + }); + Mocha.test("log3", () => { + console.log("Hello", "World", "ReScript"); + console.log("One", 2, 3); + }); + Mocha.test("log4", () => { + console.log("Hello", "World", "ReScript", "!!!"); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); + Mocha.test("log5", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); + Mocha.test("log6", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("logMany", () => { + console.log("Hello", "World"); + console.log(1, 2, 3); + }); + Mocha.test("table", () => { + console.table({ + language: "rescript", + version: "10.1.2" + }); + }); + Mocha.test("time", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); + Mocha.test("timeEnd", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); + Mocha.test("timeLog", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); + Mocha.test("trace", () => { + console.trace(); + }); + Mocha.test("warn", () => { + console.warn("Warning"); + console.warn([ + "Warning", + "invalid number" + ]); + }); + Mocha.test("warn2", () => { + console.warn("Hello", "World"); + console.warn([ + 1, + 2, + 3 + ], 4); + }); + Mocha.test("warn3", () => { + console.warn("Hello", "World", "ReScript"); + console.warn([ + 1, + 2, + 3 + ], 4, 5); + }); + Mocha.test("warn4", () => { + console.warn("Hello", "World", "ReScript", "!!!"); + console.warn("first", "second", "third", "fourth"); + }); + Mocha.test("warn5", () => { + console.warn("Hello", "World", "from", "JS", "!!!"); + console.warn([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); + Mocha.test("warn6", () => { + console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.warn([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); + Mocha.test("warnMany", () => { + console.warn("Hello", "World"); + console.warn(1, 2, 3); + }); +}); + +Mocha.describe("Stdlib.Date.UTC", () => { + Mocha.test("makeWithYM", () => { + Date.UTC(2023, 0); + Date.UTC(2023, 11); + Date.UTC(2023, 12); + Date.UTC(2023, -1); + }); + Mocha.test("makeWithYMD", () => { + Date.UTC(2023, 1, 20); + Date.UTC(2023, 1, -1); + Date.UTC(2023, 1, 29); + }); + Mocha.test("makeWithYMDH", () => { + Date.UTC(2023, 1, 20, 16); + Date.UTC(2023, 1, 20, 24); + Date.UTC(2023, 1, 20, -1); + }); + Mocha.test("makeWithYMDHM", () => { + Date.UTC(2023, 1, 20, 16, 40); + Date.UTC(2023, 1, 20, 16, 60); + Date.UTC(2023, 1, 20, 16, -1); + }); + Mocha.test("makeWithYMDHMS", () => { + Date.UTC(2023, 1, 20, 16, 40, 0); + Date.UTC(2023, 1, 20, 16, 40, 60); + Date.UTC(2023, 1, 20, 16, 40, -1); + }); + Mocha.test("makeWithYMDHMSM", () => { + console.log(Date.UTC(2023, 1, 20, 16, 40, 0, 0)); + console.log(Date.UTC(2023, 1, 20, 16, 40, 0, 1000)); + console.log(Date.UTC(2023, 1, 20, 16, 40, 0, -1)); + }); +}); + +Mocha.describe("Stdlib.Date", () => { + Mocha.test("fromString", () => { + new Date("2023"); + new Date("2023-02-20"); + new Date("2023-02-20T16:40:00.00Z"); + new Date(""); + new Date("").getTime(); + }); + Mocha.test("fromTime", () => { + new Date(0.0); + new Date(-86400000.0); + new Date(86400000.0); + }); + Mocha.test("getDate", () => { + new Date("2023-02-20T16:40:00.00").getDate(); + }); + Mocha.test("getDay", () => { + new Date("2023-02-20T16:40:00.00").getDay(); + }); + Mocha.test("getFullYear", () => { + new Date("2023-02-20").getFullYear(); + }); + Mocha.test("getHours", () => { + new Date("2023-02-20T16:40:00.00").getHours(); + }); + Mocha.test("getMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").getMilliseconds(); + }); + Mocha.test("getMinutes", () => { + new Date("2023-02-20T16:40:00.00").getMinutes(); + }); + Mocha.test("getMonth", () => { + new Date("2023-01-01").getMonth(); + }); + Mocha.test("getSeconds", () => { + new Date("2023-02-20T16:40:00.00").getSeconds(); + }); + Mocha.test("getTime", () => { + new Date("2023-02-20").getTime(); + }); + Mocha.test("getTimezoneOffset", () => { + new Date("2023-01-01").getTimezoneOffset(); + new Date("2023-06-01").getTimezoneOffset(); + }); + Mocha.test("getUTCDate", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); + }); + Mocha.test("getUTCDay", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); + }); + Mocha.test("getUTCFullYear", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); + }); + Mocha.test("getUTCHours", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); + }); + Mocha.test("getUTCMilliseconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); + }); + Mocha.test("getUTCMinutes", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); + }); + Mocha.test("getUTCMonth", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); + }); + Mocha.test("getUTCSeconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); + }); + Mocha.test("make", () => { + new Date(); + }); + Mocha.test("makeWithYM", () => { + new Date(2023, 0); + new Date(2023, 11); + new Date(2023, 12); + new Date(2023, -1); + }); + Mocha.test("makeWithYMD", () => { + new Date(2023, 1, 20); + new Date(2023, 1, -1); + new Date(2023, 1, 29); + }); + Mocha.test("makeWithYMDH", () => { + new Date(2023, 1, 20, 16); + new Date(2023, 1, 20, 24); + new Date(2023, 1, 20, -1); + }); + Mocha.test("makeWithYMDHM", () => { + new Date(2023, 1, 20, 16, 40); + new Date(2023, 1, 20, 16, 60); + new Date(2023, 1, 20, 16, -1); + }); + Mocha.test("makeWithYMDHMS", () => { + new Date(2023, 1, 20, 16, 40, 0); + new Date(2023, 1, 20, 16, 40, 60); + new Date(2023, 1, 20, 16, 40, -1); + }); + Mocha.test("makeWithYMDHMSM", () => { + new Date(2023, 1, 20, 16, 40, 0, 0); + new Date(2023, 1, 20, 16, 40, 0, 1000); + new Date(2023, 1, 20, 16, 40, 0, -1); + }); + Mocha.test("setDate", () => { + new Date("2023-02-20T16:40:00.00").setDate(1); + }); + Mocha.test("setFullYear", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024); + }); + Mocha.test("setFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); + }); + Mocha.test("setFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); + }); + Mocha.test("setHours", () => { + new Date("2023-02-20T16:40:00.00").setHours(0); + }); + Mocha.test("setHoursM", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0); + }); + Mocha.test("setHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); + }); + Mocha.test("setHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); + }); + Mocha.test("setMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setMilliseconds(0); + }); + Mocha.test("setMinutes", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0); + }); + Mocha.test("setMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); + }); + Mocha.test("setMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); + }); + Mocha.test("setMonth", () => { + new Date("2023-02-20T16:40:00.00").setMonth(0); + }); + Mocha.test("setSeconds", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0); + }); + Mocha.test("setSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); + }); + Mocha.test("setUTCDate", () => { + new Date("2023-02-20T16:40:00.00").setUTCDate(1); + }); + Mocha.test("setUTCFullYear", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); + }); + Mocha.test("setUTCFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); + }); + Mocha.test("setUTCFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); + }); + Mocha.test("setUTCHours", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0); + }); + Mocha.test("setUTCHoursM", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); + }); + Mocha.test("setUTCHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); + }); + Mocha.test("setUTCHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); + }); + Mocha.test("setUTCMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); + }); + Mocha.test("setUTCMinutes", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); + }); + Mocha.test("setUTCMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); + }); + Mocha.test("setUTCMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); + }); + Mocha.test("setUTCMonth", () => { + new Date("2023-02-20T16:40:00.00").setUTCMonth(0); + }); + Mocha.test("setUTCSeconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); + }); + Mocha.test("setUTCSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); + }); + Mocha.test("toDateString", () => { + console.log(new Date("2023-01-01T00:00:00.00+01:00").toDateString()); + console.log(new Date("2023-01-01T00:00:00.00+08:00").toDateString()); + }); + Mocha.test("toISOString", () => { + console.log(new Date("2023-01-01T00:00:00.00+00:00").toISOString()); + console.log(new Date("2023-01-01T00:00:00.00+08:00").toISOString()); + }); + Mocha.test("toJSON", () => { + new Date("2023-01-01T00:00:00.00+00:00").toJSON(); + new Date("").toJSON(); + }); + Mocha.test("toLocaleDateString", () => { + console.log(new Date().toLocaleDateString()); + }); + Mocha.test("toLocaleDateStringWithLocale", () => { + console.log(new Date().toLocaleDateString("en-US")); + }); + Mocha.test("toLocaleDateStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleDateString("en-US", { + dateStyle: "long" + })); + console.log(new Date().toLocaleDateString("de", { + hour: "2-digit", + minute: "2-digit" + })); + console.log(new Date().toLocaleDateString("de", { + year: "numeric" + })); + }); + Mocha.test("toLocaleString", () => { + console.log(new Date().toLocaleString()); + }); + Mocha.test("toLocaleStringWithLocale", () => { + console.log(new Date().toLocaleString("en-US")); + }); + Mocha.test("toLocaleStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleString("en", { + dateStyle: "short", + timeStyle: "short" + })); + console.log(new Date().toLocaleString("en", { + era: "long", + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "numeric", + timeZoneName: "short" + })); + }); + Mocha.test("toLocaleTimeString", () => { + console.log(new Date().toLocaleTimeString()); + }); + Mocha.test("toLocaleTimeStringWithLocale", () => { + console.log(new Date().toLocaleTimeString("en-US")); + }); + Mocha.test("toLocaleTimeStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleTimeString("en-US", { + timeStyle: "long" + })); + console.log(new Date().toLocaleTimeString("de", { + hour: "2-digit", + minute: "2-digit" + })); + }); + Mocha.test("toString", () => { + console.log(new Date("2023-01-01T00:00:00.00+01:00").toString()); + console.log(new Date("2023-06-01T00:00:00.00+01:00").toString()); + }); + Mocha.test("toTimeString", () => { + console.log(new Date("2023-01-01T00:00:00.00+01:00").toTimeString()); + console.log(new Date("2023-01-01T00:00:00.00+08:00").toTimeString()); + }); + Mocha.test("toUTCString", () => { + console.log(new Date("2023-01-01T00:00:00.00+00:00").toUTCString()); + console.log(new Date("2023-01-01T00:00:00.00+08:00").toUTCString()); + }); +}); + +Mocha.describe("Stdlib.Dict", () => { + Mocha.test("assign", () => { + let dict1 = {}; + dict1["firstKey"] = 1; + console.log(Object.keys(dict1)); + let dict2 = {}; + dict2["someKey"] = 2; + dict2["someKey2"] = 3; + let dict1$1 = Object.assign(dict1, dict2); + console.log(Object.keys(dict1$1)); + }); + Mocha.test("copy", () => { + let dict = { + key1: "value1", + key2: "value2" + }; + let dict2 = Object.assign({}, dict); + console.log(Object.keys(dict), Object.keys(dict2)); + }); + Mocha.test("delete", () => { + let dict = { + someKey: "someValue" + }; + Stdlib_Dict.$$delete(dict, "someKey"); + }); + Mocha.test("forEach", () => { + let dict = { + key1: "value1", + key2: "value2" + }; + Stdlib_Dict.forEach(dict, value => { + console.log(value); + }); + }); + Mocha.test("forEachWithKey", () => { + let dict = { + key1: "value1", + key2: "value2" + }; + Stdlib_Dict.forEachWithKey(dict, (value, key) => { + console.log(value, key); + }); + }); + Mocha.test("fromArray", () => { + Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + }); + Mocha.test("fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Stdlib.assertEqual(Object.values(Object.fromEntries(iterator)), [ + 1, + 2 + ]); + }); + Mocha.test("get", () => { + let dict = { + someKey: "someValue" + }; + let value = dict["someKey"]; + if (value !== undefined) { + console.log(value); + } else { + console.log("Nope, didn't have the key."); + } + }); + Mocha.test("getUnsafe", () => { + let dict = { + key1: "value1", + key2: "value2" + }; + let value = dict["key1"]; + console.log(value); + }); + Mocha.test("has", () => { + let dict = { + key1: 1, + key2: undefined + }; + Stdlib_Dict.has(dict, "key1"); + Stdlib_Dict.has(dict, "key2"); + Stdlib_Dict.has(dict, "key3"); + }); + Mocha.test("keysToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let keys = Object.keys(dict); + console.log(keys); + }); + Mocha.test("make", () => { + let dict2 = {}; + dict2["someKey"] = 12; + }); + Mocha.test("mapValues", () => { + let dict = { + key1: 1, + key2: 2 + }; + Object.entries(Stdlib_Dict.mapValues(dict, v => v + 10 | 0)); + Object.entries(Stdlib_Dict.mapValues(dict, v => v.toString())); + }); + Mocha.test("set", () => { + let dict = {}; + dict["someKey"] = "someValue"; + }); + Mocha.test("toArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let asArray = Object.entries(dict); + console.log(asArray); + }); + Mocha.test("valuesToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let values = Object.values(dict); + console.log(values); + }); +}); + +Mocha.describe("Stdlib.Error", () => { + Mocha.test("make", () => { + let error = new Error("Some message here"); + console.log(error.message); + console.log(error.name); + }); + Mocha.test("message", () => { + let error = new SyntaxError("Some message here"); + console.log(error.message); + }); + Mocha.test("name", () => { + let error = new SyntaxError("Some message here"); + console.log(error.name); + }); + Mocha.test("panic", () => { + try { + Stdlib_Error.panic("Uh oh. This was unexpected!"); + } catch (raw_obj) { + let obj = Primitive_exceptions.internalToException(raw_obj); + if (obj.RE_EXN_ID === Stdlib_Exn.$$Error) { + let m = obj._1.message; + if (m !== undefined) { + if (m !== "Panic! Uh oh. This was unexpected!") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 10483, + 15 + ], + Error: new Error() + }; + } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 10484, + 12 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 10486, + 7 + ], + Error: new Error() + }; + } + } + }); + Mocha.test("raise", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); + }); + Mocha.test("stack", () => { + let error = new Error("error"); + console.log(error.stack); + }); + Mocha.test("throw", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); + }); + Mocha.test("toException", () => { + new Error("Something went wrong."); + }); +}); + +Mocha.describe("Stdlib.Float", () => { + Mocha.test("clamp", () => { + Stdlib_Float.clamp(undefined, undefined, 4.2) === 4.2; + Stdlib_Float.clamp(4.3, undefined, 4.2) === 4.3; + Stdlib_Float.clamp(undefined, 4.1, 4.2) === 4.1; + Stdlib_Float.clamp(4.3, 4.1, 4.2) === 4.3; + }); + Mocha.test("fromInt", () => {}); + Mocha.test("fromString", () => { + Primitive_object.equal(Stdlib_Float.fromString("0"), 0.0); + Stdlib_Float.fromString("NaN") === undefined; + Primitive_object.equal(Stdlib_Float.fromString("6"), 6.0); + }); + Mocha.test("isFinite", () => { + isFinite(1.0); + isFinite(NaN); + isFinite(Number.POSITIVE_INFINITY); + }); + Mocha.test("isNaN", () => { + isNaN(3.0); + isNaN(NaN); + }); + Mocha.test("mod", () => {}); + Mocha.test("parseFloat", () => { + parseFloat("1.0"); + parseFloat(" 3.14 "); + parseFloat("3.0"); + parseFloat("3.14some non-digit characters"); + isNaN(parseFloat("error")); + }); + Mocha.test("parseInt", () => { + parseInt("1.0"); + parseInt(" 3.14 "); + parseInt(3); + parseInt("3.14some non-digit characters"); + isNaN(parseInt("error")); + parseInt("10.0", 2); + parseInt("15 * 3", 10); + parseInt("12", 13); + isNaN(parseInt("17", 40)); + }); + Mocha.test("parseIntWithRadix", () => { + parseInt("10.0", 2); + parseInt("15 * 3", 10); + parseInt("12", 13); + isNaN(parseInt("17", 40)); + }); + Mocha.test("toExponential", () => { + (1000.0).toExponential(); + (-1000.0).toExponential(); + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); + Mocha.test("toExponentialWithPrecision", () => { + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); + Mocha.test("toFixed", () => { + (123456.0).toFixed(); + (10.0).toFixed(); + (300.0).toFixed(4); + (300.0).toFixed(1); + }); + Mocha.test("toFixedWithPrecision", () => { + (300.0).toFixed(4); + (300.0).toFixed(1); + }); + Mocha.test("toInt", () => {}); + Mocha.test("toLocaleString", () => { + (1000.0).toLocaleString(); + (1000.0).toLocaleString(); + }); + Mocha.test("toPrecision", () => { + (100.0).toPrecision(); + (1.0).toPrecision(); + (100.0).toPrecision(2); + (1.0).toPrecision(1); + }); + Mocha.test("toPrecisionWithPrecision", () => { + (100.0).toPrecision(2); + (1.0).toPrecision(1); + }); + Mocha.test("toString", () => { + (1000.0).toString(); + (-1000.0).toString(); + }); + Mocha.test("toStringWithRadix", () => { + (6.0).toString(2); + (3735928559.0).toString(16); + (123456.0).toString(36); + }); +}); + +Mocha.describe("Stdlib.Float.Constants", () => { + Mocha.test("epsilon", () => {}); + Mocha.test("maxValue", () => {}); + Mocha.test("minValue", () => {}); + Mocha.test("nan", () => {}); + Mocha.test("negativeInfinity", () => {}); + Mocha.test("positiveInfinity", () => {}); +}); + +Mocha.describe("Stdlib.Int.Constants", () => { + Mocha.test("maxValue", () => { + console.log(Stdlib_Int.Constants.maxValue); + }); + Mocha.test("minValue", () => { + console.log(Stdlib_Int.Constants.minValue); + }); +}); + +Mocha.describe("Stdlib.Int", () => { + Mocha.test("bitwiseAnd", () => {}); + Mocha.test("bitwiseNot", () => { + Stdlib_Int.bitwiseNot(2) === -3; + }); + Mocha.test("bitwiseOr", () => {}); + Mocha.test("bitwiseXor", () => {}); + Mocha.test("clamp", () => { + Stdlib_Int.clamp(undefined, undefined, 42) === 42; + Stdlib_Int.clamp(50, undefined, 42) === 50; + Stdlib_Int.clamp(undefined, 40, 42) === 40; + Stdlib_Int.clamp(50, 40, 42) === 50; + }); + Mocha.test("fromFloat", () => {}); + Mocha.test("fromString", () => { + Primitive_object.equal(Stdlib_Int.fromString("0", undefined), 0); + Stdlib_Int.fromString("NaN", undefined) === undefined; + Stdlib_Int.fromString("6", 2) === undefined; + }); + Mocha.test("mod", () => {}); + Mocha.test("range", () => { + Primitive_object.equal(Stdlib_Int.range(3, 6, undefined), [ + 3, + 4, + 5 + ]); + Primitive_object.equal(Stdlib_Int.range(-3, -1, undefined), [ + -3, + -2 + ]); + Primitive_object.equal(Stdlib_Int.range(3, 1, undefined), [ + 3, + 2 + ]); + Primitive_object.equal(Stdlib_Int.range(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Stdlib_Int.range(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Stdlib_Int.range(3, 6, { + step: -2 + }); + }); + Mocha.test("rangeWithOptions", () => { + Primitive_object.equal(Stdlib_Int.rangeWithOptions(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Stdlib_Int.rangeWithOptions(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Stdlib_Int.rangeWithOptions(3, 6, { + step: -2 + }); + }); + Mocha.test("shiftLeft", () => {}); + Mocha.test("shiftRight", () => {}); + Mocha.test("shiftRightUnsigned", () => {}); + Mocha.test("toExponential", () => { + (1000).toExponential(); + (-1000).toExponential(); + (77).toExponential(2); + (5678).toExponential(2); + }); + Mocha.test("toExponentialWithPrecision", () => { + (77).toExponential(2); + (5678).toExponential(2); + }); + Mocha.test("toFixed", () => { + (123456).toFixed(); + (10).toFixed(); + (300).toFixed(4); + (300).toFixed(1); + }); + Mocha.test("toFixedWithPrecision", () => { + (300).toFixed(4); + (300).toFixed(1); + }); + Mocha.test("toFloat", () => {}); + Mocha.test("toLocaleString", () => { + (1000).toLocaleString(); + (1000).toLocaleString(); + }); + Mocha.test("toPrecision", () => { + (100).toPrecision(); + (1).toPrecision(); + (100).toPrecision(2); + (1).toPrecision(2); + }); + Mocha.test("toPrecisionWithPrecision", () => { + (100).toPrecision(2); + (1).toPrecision(2); + }); + Mocha.test("toString", () => { + (1000).toString(); + (-1000).toString(); + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); + Mocha.test("toStringWithRadix", () => { + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); +}); + +Mocha.describe("Stdlib.Iterator", () => { + Mocha.test("forEach", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Stdlib_Iterator.forEach(iterator, v => { + if (v === undefined) { + return Stdlib.assertEqual(Stdlib_Option.isNone(v), true); + } + switch (v) { + case "a" : + case "b" : + case "c" : + return; + default: + return Stdlib.assertEqual(Stdlib_Option.isNone(v), true); + } + }); + }); + Mocha.test("next", () => { + let iterator = ((() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Stdlib.assertEqual(iterator.next().done, false); + Stdlib.assertEqual(iterator.next().done, true); + }); + Mocha.test("toArray", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + let mapKeysAsArray = Array.from(map.keys()); + console.log(mapKeysAsArray); + }); + Mocha.test("toArrayWithMapper", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + let mapKeysAsArray = Array.from(map.keys(), key => key.length); + console.log(mapKeysAsArray); + }); +}); + +Mocha.describe("Stdlib.JSON.Classify", () => { + Mocha.test("classify", () => { + Stdlib_JSON.Classify.classify("hello world"); + Stdlib_JSON.Classify.classify(42); + }); +}); + +Mocha.describe("Stdlib.JSON.Decode", () => { + Mocha.test("array", () => { + Stdlib_JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); + Stdlib_JSON.Decode.array(JSON.parse("\"hello world\"")); + }); + Mocha.test("bool", () => { + Stdlib_JSON.Decode.bool(JSON.parse("true")); + Stdlib_JSON.Decode.bool(JSON.parse("\"hello world\"")); + }); + Mocha.test("float", () => { + Stdlib_JSON.Decode.float(JSON.parse("42.0")); + Stdlib_JSON.Decode.float(JSON.parse("\"hello world\"")); + }); + Mocha.test("null", () => { + Stdlib_JSON.Decode.$$null(JSON.parse("null")); + Stdlib_JSON.Decode.$$null(JSON.parse("\"hello world\"")); + }); + Mocha.test("object", () => { + Stdlib_JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); + Stdlib_JSON.Decode.object(JSON.parse("\"hello world\"")); + }); + Mocha.test("string", () => { + Stdlib_JSON.Decode.string(JSON.parse("\"hello world\"")); + Stdlib_JSON.Decode.string(JSON.parse("42")); + }); +}); + +Mocha.describe("Stdlib.JSON.Encode", () => { + Mocha.test("array", () => {}); + Mocha.test("bool", () => {}); + Mocha.test("float", () => {}); + Mocha.test("int", () => {}); + Mocha.test("null", () => {}); + Mocha.test("object", () => { + Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ] + ]); + }); + Mocha.test("string", () => {}); +}); + +Mocha.describe("Stdlib.JSON", () => { + Mocha.test("parseExn", () => { + try { + JSON.parse("{\"foo\":\"bar\",\"hello\":\"world\"}"); + JSON.parse(""); + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID === Stdlib_Exn.$$Error) { + console.log("error"); + } else { + throw exn; + } + } + let reviver = (param, value) => { + switch (typeof value) { + case "string" : + return value.toUpperCase(); + case "number" : + return value * 2.0; + default: + return value; + } + }; + try { + console.log(JSON.parse("{\"hello\":\"world\",\"someNumber\":21}", reviver)); + console.log(JSON.parse("", reviver)); + } catch (raw_exn$1) { + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); + if (exn$1.RE_EXN_ID === Stdlib_Exn.$$Error) { + console.log("error"); + } else { + throw exn$1; + } + } + }); + Mocha.test("parseExnWithReviver", () => { + let reviver = (param, value) => { + switch (typeof value) { + case "string" : + return value.toUpperCase(); + case "number" : + return value * 2.0; + default: + return value; + } + }; + try { + console.log(JSON.parse("{\"hello\":\"world\",\"someNumber\":21}", reviver)); + console.log(JSON.parse("", reviver)); + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID === Stdlib_Exn.$$Error) { + console.log("error"); + } else { + throw exn; + } + } + }); + Mocha.test("stringify", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json); + JSON.stringify(json, undefined, 2); + JSON.stringify(json, [ + "foo", + "someNumber" + ]); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); + Mocha.test("stringifyAny", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Stdlib.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Stdlib.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11253, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyAnyWithFilter", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Stdlib.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11274, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyAnyWithFilterAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Stdlib.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Stdlib.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11310, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyAnyWithIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Stdlib.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11336, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyAnyWithReplacer", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11367, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyAnyWithReplacerAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11398, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("stringifyWithFilter", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ]); + }); + Mocha.test("stringifyWithFilterAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ], 2); + }); + Mocha.test("stringifyWithIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, null, 2); + }); + Mocha.test("stringifyWithReplacer", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); + Mocha.test("stringifyWithReplacerAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = Stdlib_JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer, 2); + }); +}); + +Mocha.describe("Stdlib.List", () => { + Mocha.test("add", () => { + Stdlib_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Stdlib_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); + Mocha.test("compare", () => { + Stdlib_List.compare({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + Stdlib_List.compare({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + Stdlib_List.compare({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 4, + tl: { + hd: 2, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Stdlib_List.compare({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + Stdlib_List.compare({ + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, Primitive_int.compare); + }); + Mocha.test("compareLength", () => { + Stdlib_List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + Stdlib_List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + Stdlib_List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + }); + }); + Mocha.test("concat", () => { + Stdlib.assertEqual(Stdlib_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + } + }); + }); + Mocha.test("concatMany", () => { + Stdlib_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); + Mocha.test("drop", () => { + Stdlib_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Stdlib_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 3); + Stdlib_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("equal", () => { + Stdlib_List.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Stdlib_List.equal({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + Stdlib_List.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("every", () => { + let isBelow10 = value => value < 10; + Stdlib_List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + Stdlib_List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + }); + Mocha.test("every2", () => { + Stdlib_List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Stdlib_List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Stdlib_List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Stdlib_List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("filter", () => { + let isEven = x => x % 2 === 0; + Stdlib_List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + Stdlib_List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Stdlib_Option.isSome); + }); + Mocha.test("filterMap", () => { + let isEven = x => x % 2 === 0; + Stdlib_List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => { + if (isEven(x)) { + return x; + } + + }); + Stdlib_List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); + }); + Mocha.test("filterWithIndex", () => { + Stdlib_List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); + Mocha.test("find", () => { + Stdlib_List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 3); + Stdlib_List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); + Mocha.test("flat", () => { + Stdlib_List.flat({ + hd: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + tl: { + hd: /* [] */0, + tl: { + hd: { + hd: 3, + tl: /* [] */0 + }, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("forEach", () => { + Stdlib_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); + Mocha.test("forEach2", () => { + Stdlib_List.forEach2({ + hd: "Z", + tl: { + hd: "Y", + tl: /* [] */0 + } + }, { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }, (x, y) => { + console.log(x, y); + }); + }); + Mocha.test("forEachWithIndex", () => { + Stdlib_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (x, index) => { + console.log("Item " + index.toString() + " is " + x); + }); + }); + Mocha.test("fromArray", () => { + Stdlib_List.fromArray([ + 1, + 2, + 3 + ]); + }); + Mocha.test("fromInitializer", () => { + Stdlib_List.fromInitializer(5, i => i); + Stdlib_List.fromInitializer(5, i => i * i | 0); + }); + Mocha.test("get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Stdlib_List.get(abc, 1); + Stdlib_List.get(abc, 4); + }); + Mocha.test("getAssoc", () => { + Stdlib_List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + Stdlib_List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); + }); + Mocha.test("getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Stdlib.assertEqual(Stdlib_List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = Stdlib_List.getExn(abc, 4); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== "Not_found") { + throw exn; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11717, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("has", () => { + Stdlib_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2, (a, b) => a === b); + Stdlib_List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + Stdlib_List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); + Mocha.test("hasAssoc", () => { + Stdlib_List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Stdlib_List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); + }); + Mocha.test("head", () => { + Stdlib_List.head(/* [] */0); + Stdlib_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("headExn", () => { + Stdlib.assertEqual(Stdlib_List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = Stdlib_List.headExn(/* [] */0); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== "Not_found") { + throw exn; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11754, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("length", () => { + Stdlib_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("make", () => { + Stdlib_List.make(3, 1); + }); + Mocha.test("map", () => { + Stdlib_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); + Mocha.test("mapReverse", () => { + let f = x => x * x | 0; + let l = { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }; + let withMap = Stdlib_List.reverse(Stdlib_List.map(l, f)); + let withMapReverse = Stdlib_List.mapReverse(l, f); + console.log(Primitive_object.equal(withMap, withMapReverse)); + }); + Mocha.test("mapReverse2", () => { + Stdlib_List.mapReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a + b | 0); + }); + Mocha.test("mapWithIndex", () => { + Stdlib_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (x, index) => index + x | 0); + }); + Mocha.test("partition", () => { + Stdlib_List.partition({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => x > 2); + }); + Mocha.test("reduce", () => { + Stdlib_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Stdlib_List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); + }); + Mocha.test("reduce2", () => { + Stdlib_List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceReverse", () => { + Stdlib_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + Stdlib_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + Stdlib_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, Stdlib_List.add); + }); + Mocha.test("reduceReverse2", () => { + Stdlib_List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); + }); + Mocha.test("reduceWithIndex", () => { + Stdlib_List.reduceWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item, index) => (acc + item | 0) + index | 0); + }); + Mocha.test("removeAssoc", () => { + Stdlib_List.removeAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Stdlib_List.removeAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); + }); + Mocha.test("reverse", () => { + Stdlib_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("reverseConcat", () => { + Stdlib_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); + Mocha.test("setAssoc", () => { + Stdlib_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + Stdlib_List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + Stdlib_List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); + Mocha.test("shuffle", () => { + Stdlib_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("size", () => { + Stdlib_List.size({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("some", () => { + let isAbove100 = value => value > 100; + Stdlib_List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + Stdlib_List.some({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isAbove100); + }); + Mocha.test("some2", () => { + Stdlib_List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + Stdlib_List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Stdlib_List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Stdlib_List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); + Mocha.test("sort", () => { + Stdlib_List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } + } + }, Primitive_int.compare); + }); + Mocha.test("splitAt", () => { + Stdlib_List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + Stdlib_List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); + }); + Mocha.test("tail", () => { + Stdlib_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Stdlib_List.tail(/* [] */0); + }); + Mocha.test("tailExn", () => { + Stdlib.assertEqual(Stdlib_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }); + let exit = 0; + let val; + try { + val = Stdlib_List.tailExn(/* [] */0); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== "Not_found") { + throw exn; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 11943, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("take", () => { + Stdlib_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + Stdlib_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + Stdlib_List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); + Mocha.test("toArray", () => { + Stdlib_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("toShuffled", () => { + Stdlib_List.toShuffled({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("unzip", () => { + Stdlib_List.unzip({ + hd: [ + 1, + 2 + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + Stdlib_List.unzip({ + hd: [ + "H", + "W" + ], + tl: { + hd: [ + "e", + "o" + ], + tl: { + hd: [ + "l", + "r" + ], + tl: { + hd: [ + "l", + "l" + ], + tl: { + hd: [ + "o", + "d" + ], + tl: { + hd: [ + " ", + "!" + ], + tl: /* [] */0 + } + } + } + } + } + }); + }); + Mocha.test("zip", () => { + Stdlib_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); + Mocha.test("zipBy", () => { + Stdlib_List.zipBy({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, (a, b) => (a << 1) + b | 0); + }); +}); + +Mocha.describe("Stdlib.Map", () => { + Mocha.test("clear", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.clear(); + }); + Mocha.test("delete", () => { + let map = new Map(); + map.set("someKey", "someValue"); + let didDeleteKey = map.delete("someKey"); + console.log(didDeleteKey); + let didDeleteKey$1 = map.delete("someNonExistantKey"); + console.log(didDeleteKey$1); + }); + Mocha.test("entries", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("anotherKey", "anotherValue"); + let entries = map.entries(); + console.log(entries.next().value); + console.log(Array.from(map.entries())); + }); + Mocha.test("forEach", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach(value => { + console.log(value); + }); + }); + Mocha.test("forEachWithKey", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach((value, key) => { + console.log(value, key); + }); + }); + Mocha.test("fromArray", () => { + let languageRank = [ + [ + "ReScript", + 1 + ], + [ + "JavaScript", + 2 + ], + [ + "TypeScript", + 3 + ] + ]; + let map = new Map(languageRank); + let match = map.get("ReScript"); + if (match === 1) { + console.log("Yay, ReScript is #1!"); + } else { + console.log("Uh-oh, something is _terribly_ wrong with this program... abort."); + } + }); + Mocha.test("fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Stdlib.assertEqual(new Map(iterator).size, 2); + }); + Mocha.test("get", () => { + let map = new Map(); + map.set("someKey", "someValue"); + let value = map.get("someKey"); + if (value !== undefined) { + console.log("Yay, had the value, and it's:", value); + } else { + console.log("Nope, didn't have it."); + } + }); + Mocha.test("has", () => { + let map = new Map(); + map.set("someKey", "someValue"); + if (map.has("someKey")) { + console.log("Yay, we have the value!"); + } else { + console.log("Nope, didn't have it."); + } + }); + Mocha.test("keys", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("anotherKey", "anotherValue"); + let keys = map.keys(); + console.log(keys.next().value); + console.log(Array.from(map.keys())); + }); + Mocha.test("make", () => { + new Map(); + let map = new Map(); + map.set("lang", "ReScript"); + }); + Mocha.test("set", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); + Mocha.test("size", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); + Mocha.test("values", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("anotherKey", "anotherValue"); + let values = map.values(); + console.log(values.next().value); + console.log(Array.from(map.values())); + }); +}); + +Mocha.describe("Stdlib.Math", () => { + Mocha.test("abs", () => { + Math.abs(-2.0); + Math.abs(3.0); + }); + Mocha.test("acos", () => { + Math.acos(-1.0); + isNaN(Math.acos(-3.0)); + }); + Mocha.test("acosh", () => { + Math.acosh(1.0); + isNaN(Math.acosh(0.5)); + }); + Mocha.test("asin", () => { + Math.asin(-1.0); + isNaN(Math.asin(-2.0)); + }); + Mocha.test("asinh", () => { + Math.asinh(-1.0); + Math.asinh(-0.0); + }); + Mocha.test("atan", () => { + Math.atan(-0.0); + Math.atan(0.0); + Math.atan(1.0); + }); + Mocha.test("atan2", () => { + Math.atan2(0.0, 10.0) === 0.0; + Math.atan2(5.0, 5.0) === Math.PI / 4.0; + Math.atan2(15.0, 90.0); + Math.atan2(90.0, 15.0); + }); + Mocha.test("atanh", () => { + isNaN(Math.atanh(-2.0)); + isFinite(Math.atanh(-1.0)); + Math.atanh(-0.0); + Math.atanh(0.0); + Math.atanh(0.5); + }); + Mocha.test("cbrt", () => { + Math.cbrt(-1.0); + Math.cbrt(-0.0); + Math.cbrt(0.0); + }); + Mocha.test("ceil", () => { + Math.ceil(3.1) === 4.0; + Math.ceil(3.0) === 3.0; + Math.ceil(-3.1) === -3.0; + Math.ceil(2150000000.3) === 2150000001.0; + }); + Mocha.test("cos", () => { + Math.cos(-0.0); + Math.cos(0.0); + Math.cos(1.0); + }); + Mocha.test("cosh", () => { + Math.cosh(-1.0); + Math.cosh(-0.0); + Math.cosh(0.0); + }); + Mocha.test("exp", () => { + Math.exp(-1.0); + Math.exp(0.0); + }); + Mocha.test("expm1", () => { + Math.expm1(-1.0); + Math.expm1(-0.0); + }); + Mocha.test("floor", () => { + Math.floor(-45.95); + Math.floor(-45.05); + Math.floor(-0.0); + }); + Mocha.test("fround", () => { + Math.fround(5.5) === 5.5; + Math.fround(5.05) === 5.050000190734863; + }); + Mocha.test("hypot", () => { + Math.hypot(3.0, 4.0); + Math.hypot(3.0, 5.0); + }); + Mocha.test("hypotMany", () => { + Math.hypot(3.0, 4.0, 5.0); + Math.hypot(); + }); + Mocha.test("log", () => { + isNaN(Math.log(-1.0)); + isFinite(Math.log(-0.0)); + isFinite(Math.log(0.0)); + Math.log(1.0); + }); + Mocha.test("log10", () => { + isNaN(Math.log10(-2.0)); + isFinite(Math.log10(-0.0)); + isFinite(Math.log10(0.0)); + Math.log10(1.0); + }); + Mocha.test("log1p", () => { + isNaN(Math.log1p(-2.0)); + isFinite(Math.log1p(-1.0)); + Math.log1p(-0.0); + }); + Mocha.test("log2", () => { + isNaN(Math.log2(-2.0)); + isFinite(Math.log2(-0.0)); + isFinite(Math.log2(0.0)); + Math.log2(1.0); + }); + Mocha.test("max", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + }); + Mocha.test("maxMany", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + isFinite(Math.max()); + }); + Mocha.test("min", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + }); + Mocha.test("minMany", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + isFinite(Math.min()); + }); + Mocha.test("pow", () => { + Math.pow(2.0, 4.0); + Math.pow(3.0, 4.0); + }); + Mocha.test("random", () => { + Math.random(); + }); + Mocha.test("round", () => { + Math.round(-20.5); + Math.round(-0.1); + Math.round(0.0); + Math.round(-0.0); + }); + Mocha.test("sign", () => { + Math.sign(3.0); + Math.sign(-3.0); + Math.sign(0.0); + }); + Mocha.test("sin", () => { + Math.sin(-0.0); + Math.sin(0.0); + Math.sin(1.0); + }); + Mocha.test("sinh", () => { + Math.sinh(-0.0); + Math.sinh(0.0); + Math.sinh(1.0); + }); + Mocha.test("sqrt", () => { + isNaN(Math.sqrt(-1.0)); + Math.sqrt(-0.0); + Math.sqrt(0.0); + Math.sqrt(1.0); + Math.sqrt(9.0); + }); + Mocha.test("tan", () => { + Math.tan(-0.0); + Math.tan(0.0); + Math.tan(1.0); + }); + Mocha.test("tanh", () => { + Math.tanh(-0.0); + Math.tanh(0.0); + Math.tanh(1.0); + }); + Mocha.test("trunc", () => { + Math.trunc(0.123); + Math.trunc(1.999); + Math.trunc(13.37); + Math.trunc(42.84); + }); +}); + +Mocha.describe("Stdlib.Math.Constants", () => { + Mocha.test("e", () => {}); + Mocha.test("ln10", () => {}); + Mocha.test("ln2", () => {}); + Mocha.test("log10e", () => {}); + Mocha.test("log2e", () => {}); + Mocha.test("pi", () => {}); + Mocha.test("sqrt1_2", () => {}); + Mocha.test("sqrt2", () => {}); +}); + +Mocha.describe("Stdlib.Math.Int", () => { + Mocha.test("abs", () => { + Math.abs(-2); + Math.abs(3); + }); + Mocha.test("ceil", () => { + Stdlib_Math.Int.ceil(3.7) === 4; + Stdlib_Math.Int.ceil(3.0) === 3; + Stdlib_Math.Int.ceil(-3.1) === -3; + }); + Mocha.test("clz32", () => { + Math.clz32(1); + Math.clz32(4); + }); + Mocha.test("floor", () => { + Stdlib_Math.Int.floor(3.7) === 3; + Stdlib_Math.Int.floor(3.0) === 3; + Stdlib_Math.Int.floor(-3.1) === -4; + }); + Mocha.test("imul", () => { + Math.imul(3, 4); + Math.imul(-5, 12); + }); + Mocha.test("max", () => { + Math.max(1, 2); + Math.max(-1, -2); + }); + Mocha.test("maxMany", () => { + Math.max(1, 2); + Math.max(-1, -2); + isFinite(Math.max()); + }); + Mocha.test("min", () => { + Math.min(1, 2); + Math.min(-1, -2); + }); + Mocha.test("minMany", () => { + Math.min(1, 2); + Math.min(-1, -2); + isFinite(Math.min()); + }); + Mocha.test("pow", () => { + Math.pow(2, 4); + Math.pow(3, 4); + }); + Mocha.test("random", () => { + Stdlib_Math.Int.random(2, 5) === 4; + Stdlib_Math.Int.random(505, 2000) === 1276; + Stdlib_Math.Int.random(-7, -2) === -4; + }); + Mocha.test("sign", () => { + Math.sign(3); + Math.sign(-3); + Math.sign(0); + }); +}); + +Mocha.describe("Stdlib.Null", () => { + Mocha.test("asNullable", () => {}); + Mocha.test("flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Stdlib_Null.flatMap(2, addIfAboveOne); + Stdlib_Null.flatMap(-4, addIfAboveOne); + Stdlib_Null.flatMap(null, addIfAboveOne); + }); + Mocha.test("forEach", () => { + Stdlib_Null.forEach("thing", x => { + console.log(x); + }); + Stdlib_Null.forEach(null, x => { + console.log(x); + }); + }); + Mocha.test("fromOption", () => { + let asNull = Stdlib_Null.fromOption(undefined); + console.log(asNull === null); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Stdlib_Null.getExn(3), 3); + let exit = 0; + let value; + try { + value = Stdlib_Null.getExn('ReScript'); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID === "Invalid_argument") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12655, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Stdlib.assertEqual(value, "ReScript"); + } + let exit$1 = 0; + let val; + try { + val = Stdlib_Null.getExn(null); + exit$1 = 1; + } catch (raw_exn$1) { + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); + if (exn$1.RE_EXN_ID !== "Invalid_argument") { + throw exn$1; + } + + } + if (exit$1 === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12661, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getOr", () => { + Stdlib_Null.getOr(null, "Banana"); + Stdlib_Null.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNull("Jane")); + greet(undefined); + }); + Mocha.test("getUnsafe", () => {}); + Mocha.test("make", () => {}); + Mocha.test("map", () => { + Stdlib_Null.map(3, x => x * x | 0); + Stdlib_Null.map(null, x => x * x | 0); + }); + Mocha.test("mapOr", () => { + Stdlib_Null.mapOr(3, 0, x => x + 5 | 0); + Stdlib_Null.mapOr(null, 0, x => x + 5 | 0); + }); + Mocha.test("null", () => { + console.log(null); + }); + Mocha.test("toOption", () => { + let nullStr = "Hello"; + if (nullStr !== null) { + console.log("Got string:", nullStr); + } else { + console.log("Didn't have a value."); + } + }); +}); + +Mocha.describe("Stdlib.Nullable", () => { + Mocha.test("flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Stdlib_Nullable.flatMap(2, addIfAboveOne); + Stdlib_Nullable.flatMap(-4, addIfAboveOne); + Stdlib_Nullable.flatMap(null, addIfAboveOne); + }); + Mocha.test("forEach", () => { + Stdlib_Nullable.forEach("thing", x => { + console.log(x); + }); + Stdlib_Nullable.forEach(null, x => { + console.log(x); + }); + Stdlib_Nullable.forEach(undefined, x => { + console.log(x); + }); + }); + Mocha.test("fromOption", () => { + Stdlib_Nullable.fromOption("Hello"); + }); + Mocha.test("getExn", () => { + let exit = 0; + let value; + try { + value = Stdlib_Nullable.getExn('Hello'); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID === "Invalid_argument") { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12762, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Stdlib.assertEqual(value, "Hello"); + } + let exit$1 = 0; + let val; + try { + val = Stdlib_Nullable.getExn(null); + exit$1 = 1; + } catch (raw_exn$1) { + let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); + if (exn$1.RE_EXN_ID !== "Invalid_argument") { + throw exn$1; + } + + } + if (exit$1 === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12768, + 7 + ], + Error: new Error() + }; + } + let exit$2 = 0; + let val$1; + try { + val$1 = Stdlib_Nullable.getExn(undefined); + exit$2 = 1; + } catch (raw_exn$2) { + let exn$2 = Primitive_exceptions.internalToException(raw_exn$2); + if (exn$2.RE_EXN_ID !== "Invalid_argument") { + throw exn$2; + } + + } + if (exit$2 === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12773, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getOr", () => { + Stdlib_Nullable.getOr(null, "Banana"); + Stdlib_Nullable.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNullable("Jane")); + greet(undefined); + }); + Mocha.test("getUnsafe", () => {}); + Mocha.test("isNullable", () => { + if ("Hello" == null) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12808, + 10 + ], + Error: new Error() + }; + } + + }); + Mocha.test("make", () => { + let myStr = "Hello"; + if ((myStr == null) || myStr !== myStr) { + console.log("Values did not match."); + } else { + console.log("Yay, values matched!"); + } + }); + Mocha.test("map", () => { + Stdlib_Nullable.map(3, x => x * x | 0); + Stdlib_Nullable.map(undefined, x => x * x | 0); + }); + Mocha.test("mapOr", () => { + Stdlib_Nullable.mapOr(3, 0, x => x + 5 | 0); + Stdlib_Nullable.mapOr(null, 0, x => x + 5 | 0); + }); + Mocha.test("null", () => { + console.log(null); + }); + Mocha.test("toOption", () => { + let nullableString = "Hello"; + if (nullableString == null) { + console.log("Didn't have a value."); + } else { + console.log("Got string:", nullableString); + } + }); + Mocha.test("undefined", () => { + console.log(undefined); + }); +}); + +Mocha.describe("Stdlib.Object", () => { + Mocha.test("assign", () => { + Object.assign({ + a: 1 + }, { + a: 2 + }); + Object.assign({ + a: 1, + b: 2 + }, { + a: 0 + }); + Object.assign({ + a: 1 + }, { + a: null + }); + }); + Mocha.test("create", () => { + let x = { + fruit: "banana" + }; + Object.create(x); + }); + Mocha.test("freeze", () => { + let obj = { + a: 1 + }; + obj["a"] = 2; + Object.freeze(obj); + try { + obj["a"] = 3; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12898, + 7 + ], + Error: new Error() + }; + } + + } + }); + Mocha.test("get", () => { + Stdlib_Option.isSome(({ + a: 1 + })["toString"]); + }); + Mocha.test("getSymbol", () => { + let fruit = Symbol("fruit"); + let x = {}; + x[fruit] = "banana"; + }); + Mocha.test("hasOwnProperty", () => { + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "a"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "b"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "toString"); + }); + Mocha.test("is", () => { + Object.is(25, 13); + Object.is("abc", "abc"); + Object.is(undefined, undefined); + Object.is(undefined, null); + Object.is(-0.0, 0.0); + Object.is({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }); + Object.is([ + 1, + 2, + 3 + ], [ + 1, + 2, + 3 + ]); + Primitive_object.equal([ + 1, + 2, + 3 + ], [ + 1, + 2, + 3 + ]); + let fruit = { + name: "Apple" + }; + Object.is(fruit, fruit); + Object.is(fruit, { + name: "Apple" + }); + Primitive_object.equal(fruit, { + name: "Apple" + }); + }); + Mocha.test("isExtensible", () => { + let obj = { + a: 1 + }; + Object.isExtensible(obj); + Object.preventExtensions(obj); + Object.isExtensible(obj); + }); + Mocha.test("isFrozen", () => { + let point = Object.freeze({ + x: 1, + y: 3 + }); + Object.isFrozen(point); + let fruit = { + name: "Apple" + }; + Object.isFrozen(fruit); + }); + Mocha.test("isSealed", () => { + let point = Object.seal({ + x: 1, + y: 3 + }); + Object.isSealed(point); + let fruit = { + name: "Apple" + }; + Object.isSealed(fruit); + }); + Mocha.test("keysToArray", () => { + Object.keys({ + a: 1, + b: 2 + }); + Object.keys({ + a: undefined + }); + Object.keys({}); + }); + Mocha.test("make", () => { + let x = {}; + Object.keys(x).length; + Stdlib_Option.isSome(x["toString"]); + }); + Mocha.test("preventExtensions", () => { + let obj = { + a: 1 + }; + obj["b"] = 2; + Object.preventExtensions(obj); + try { + obj["c"] = 3; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13004, + 7 + ], + Error: new Error() + }; + } + + } + }); + Mocha.test("seal", () => { + let point = { + x: 1, + y: 2 + }; + point["x"] = -7; + Object.seal(point); + try { + point["z"] = 9; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13019, + 7 + ], + Error: new Error() + }; + } + + } + point["x"] = 13; + }); + Mocha.test("set", () => { + ({ + a: 1 + })["a"] = 2; + ({ + a: 1 + })["a"] = undefined; + ({ + a: 1 + })["b"] = 2; + }); +}); + +Mocha.describe("Stdlib.Option", () => { + Mocha.test("all", () => { + Stdlib_Option.all([ + 1, + 2, + 3 + ]); + Stdlib_Option.all([ + 1, + undefined + ]); + }); + Mocha.test("compare", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Stdlib_Option.compare(3, 15, clockCompare); + Stdlib_Option.compare(3, 14, clockCompare); + Stdlib_Option.compare(2, 15, clockCompare); + Stdlib_Option.compare(undefined, 15, clockCompare); + Stdlib_Option.compare(14, undefined, clockCompare); + Stdlib_Option.compare(undefined, undefined, clockCompare); + }); + Mocha.test("equal", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Stdlib_Option.equal(3, 15, clockEqual); + Stdlib_Option.equal(3, undefined, clockEqual); + Stdlib_Option.equal(undefined, 3, clockEqual); + Stdlib_Option.equal(undefined, undefined, clockEqual); + }); + Mocha.test("filter", () => { + Stdlib_Option.filter(10, x => x > 5); + Stdlib_Option.filter(4, x => x > 5); + Stdlib_Option.filter(undefined, x => x > 5); + }); + Mocha.test("flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + + }; + Stdlib_Option.flatMap(2, addIfAboveOne); + Stdlib_Option.flatMap(-4, addIfAboveOne); + Stdlib_Option.flatMap(undefined, addIfAboveOne); + }); + Mocha.test("forEach", () => { + Stdlib_Option.forEach("thing", x => { + console.log(x); + }); + Stdlib_Option.forEach(undefined, x => { + console.log(x); + }); + }); + Mocha.test("getExn", () => { + Stdlib.assertEqual(Stdlib_Option.getExn(3, undefined), 3); + let exit = 0; + let val; + try { + val = Stdlib_Option.getExn(undefined, undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13105, + 7 + ], + Error: new Error() + }; + } + let exit$1 = 0; + let val$1; + try { + val$1 = Stdlib_Option.getExn(undefined, "was None!"); + exit$1 = 1; + } catch (exn$1) { + + } + if (exit$1 === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13110, + 7 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getOr", () => { + Stdlib_Option.getOr(undefined, "Banana"); + Stdlib_Option.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); + }); + Mocha.test("getUnsafe", () => {}); + Mocha.test("isNone", () => { + Stdlib_Option.isNone(undefined); + Stdlib_Option.isNone(1); + }); + Mocha.test("isSome", () => { + Stdlib_Option.isSome(undefined); + Stdlib_Option.isSome(1); + }); + Mocha.test("map", () => { + Stdlib_Option.map(3, x => x * x | 0); + Stdlib_Option.map(undefined, x => x * x | 0); + }); + Mocha.test("mapOr", () => { + Stdlib_Option.mapOr(3, 0, x => x + 5 | 0); + Stdlib_Option.mapOr(undefined, 0, x => x + 5 | 0); + }); + Mocha.test("orElse", () => { + Primitive_object.equal(Stdlib_Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Stdlib_Option.orElse(undefined, 1066), 1066); + Stdlib_Option.orElse(undefined, undefined) === undefined; + }); +}); + +Mocha.describe("Stdlib.Promise", () => { + Mocha.test("all", () => { + let promises = [ + Promise.resolve(1), + Promise.resolve(2), + Promise.resolve(3) + ]; + Promise.all(promises).then(results => { + results.forEach(num => { + console.log("Number: ", num); + }); + return Promise.resolve(); + }); + }); + Mocha.test("allSettled", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + let promises = [ + Promise.resolve(1), + Promise.resolve(2), + Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected promise" + }) + ]; + Promise.allSettled(promises).then(results => { + results.forEach(result => { + if (result.status === "fulfilled") { + console.log("Number: ", result.value); + return; + } + console.log(result.reason); + }); + return Promise.resolve(); + }); + }); + Mocha.test("any", () => { + let racer = (ms, name) => new Promise((resolve, param) => { + setTimeout(() => resolve(name), ms); + }); + let promises = [ + racer(1000, "Turtle"), + racer(500, "Hare"), + racer(100, "Eagle") + ]; + Promise.any(promises).then(winner => { + console.log("The winner is " + winner); + return Promise.resolve(); + }); + }); + Mocha.test("catch", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + Stdlib_Promise.$$catch(Promise.reject({ + RE_EXN_ID: SomeError, + _1: "this is an error" + }).then(param => Promise.resolve({ + TAG: "Ok", + _0: "This result will never be returned" + })), e => { + let msg; + if (e.RE_EXN_ID === SomeError) { + msg = "ReScript error occurred: " + e._1; + } else if (e.RE_EXN_ID === Stdlib_Exn.$$Error) { + let msg$1 = e._1.message; + msg = msg$1 !== undefined ? "JS exception occurred: " + msg$1 : "Some other JS value has been thrown"; + } else { + msg = "Unexpected error occurred"; + } + return Promise.resolve({ + TAG: "Error", + _0: msg + }); + }).then(result => { + let tmp; + if (result.TAG === "Ok") { + console.log("Operation successful: ", result._0); + tmp = undefined; + } else { + console.log("Operation failed: ", result._0); + tmp = undefined; + } + return Promise.resolve(tmp); + }); + }); + Mocha.test("finally", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + let isDone = { + contents: false + }; + Stdlib_Promise.$$catch(Promise.resolve(5).then(param => Promise.reject({ + RE_EXN_ID: SomeError, + _1: "test" + })).then(v => { + console.log("final result", v); + return Promise.resolve(); + }), param => { + console.log("Error handled"); + return Promise.resolve(); + }).finally(() => { + console.log("finally"); + isDone.contents = true; + }).then(() => { + console.log("isDone:", isDone.contents); + return Promise.resolve(); + }); + }); + Mocha.test("make", () => { + Stdlib_Promise.$$catch(new Promise((resolve, reject) => resolve("success")).then(str => Promise.resolve((console.log(str), undefined))), param => { + console.log("Error occurred"); + return Promise.resolve(); + }); + }); + Mocha.test("race", () => { + let racer = (ms, name) => new Promise((resolve, param) => { + setTimeout(() => resolve(name), ms); + }); + let promises = [ + racer(1000, "Turtle"), + racer(500, "Hare"), + racer(100, "Eagle") + ]; + Promise.race(promises).then(winner => { + console.log("The winner is " + winner); + return Promise.resolve(); + }); + }); + Mocha.test("reject", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + Stdlib_Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }), v => { + if (v.RE_EXN_ID === TestError) { + Stdlib.assertEqual(v._1, "some rejected value"); + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13354, + 9 + ], + Error: new Error() + }; + } + return Promise.resolve(); + }); + }); + Mocha.test("resolve", () => { + Promise.resolve(5); + }); + Mocha.test("then", () => { + Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { + console.log("Your lucky number is: ", num); + return Promise.resolve(); + }); + }); + Mocha.test("thenResolve", () => { + Promise.resolve("Anna").then(str => "Hello " + str).then(str => { + console.log(str); + }); + }); +}); + +Mocha.describe("Stdlib.RegExp.Result", () => { + Mocha.test("fullMatch", () => { + let regexp = new RegExp("(\\w+) (\\w+)"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + console.log(result[0]); + } + }); + Mocha.test("input", () => { + let regexp = new RegExp("(\\w+) (\\w+)"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + console.log(result.input); + } + }); + Mocha.test("matches", () => { + let regexp = new RegExp("(\\w+) (\\w+)"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + let match = result.slice(1); + if (match.length !== 2) { + console.log("Didn't find exactly two words..."); + } else { + let firstWord = match[0]; + let secondWord = match[1]; + console.log(firstWord, secondWord); + } + } + }); +}); + +Mocha.describe("Stdlib.RegExp", () => { + Mocha.test("exec", () => { + let regexp = new RegExp("\\w+"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + console.log(result[0]); + } + }); + Mocha.test("fromString", () => { + let regexp = new RegExp("\\w+"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + console.log(result[0]); + } + }); + Mocha.test("fromStringWithFlags", () => { + let regexp = new RegExp("\\w+", "g"); + let result = regexp.exec("ReScript is pretty cool, right?"); + if (result == null) { + console.log("Nope, no match..."); + } else { + console.log(result[0]); + } + }); + Mocha.test("global", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.global); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.global); + }); + Mocha.test("ignoreCase", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.ignoreCase); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.ignoreCase); + }); + Mocha.test("lastIndex", () => { + let regexp = new RegExp("\\w+"); + console.log(regexp.lastIndex); + regexp.exec("Many words here."); + console.log(regexp.lastIndex); + }); + Mocha.test("multiline", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.multiline); + let regexp2 = new RegExp("\\w+", "mi"); + console.log(regexp2.multiline); + }); + Mocha.test("setLastIndex", () => { + let regexp = new RegExp("\\w+"); + regexp.lastIndex = 4; + regexp.exec("Many words here."); + console.log(regexp.lastIndex); + }); + Mocha.test("source", () => { + let regexp = new RegExp("\\w+", "g"); + console.log(regexp.source); + }); + Mocha.test("sticky", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "my"); + console.log(regexp2.unicode); + }); + Mocha.test("test", () => { + let regexp = new RegExp("\\w+"); + if (regexp.test("ReScript is cool!")) { + console.log("Yay, there's a word in there."); + } + + }); + Mocha.test("unicode", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "mu"); + console.log(regexp2.unicode); + }); +}); + +Mocha.describe("Stdlib.Result", () => { + Mocha.test("all", () => { + Stdlib_Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Ok", + _0: 2 + }, + { + TAG: "Ok", + _0: 3 + } + ]); + Stdlib_Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Error", + _0: 1 + } + ]); + }); + Mocha.test("compare", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Stdlib_Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Stdlib_Result.compare({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Stdlib_Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Stdlib_Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Stdlib_Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; + }); + Mocha.test("equal", () => { + let good1 = { + TAG: "Ok", + _0: 42 + }; + let good2 = { + TAG: "Ok", + _0: 32 + }; + let bad1 = { + TAG: "Error", + _0: "invalid" + }; + let bad2 = { + TAG: "Error", + _0: "really invalid" + }; + let mod10equal = (a, b) => a % 10 === b % 10; + Stdlib_Result.equal(good1, good2, mod10equal) === true; + Stdlib_Result.equal(good1, bad1, mod10equal) === false; + Stdlib_Result.equal(bad2, good2, mod10equal) === false; + Stdlib_Result.equal(bad1, bad2, mod10equal) === true; + }); + Mocha.test("flatMap", () => { + let recip = x => { + if (x !== 0.0) { + return { + TAG: "Ok", + _0: 1.0 / x + }; + } else { + return { + TAG: "Error", + _0: "Divide by zero" + }; + } + }; + Primitive_object.equal(Stdlib_Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 + }); + Primitive_object.equal(Stdlib_Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Stdlib_Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" + }); + }); + Mocha.test("forEach", () => { + Stdlib_Result.forEach({ + TAG: "Ok", + _0: 3 + }, prim => { + console.log(prim); + }); + Stdlib_Result.forEach({ + TAG: "Error", + _0: "x" + }, prim => { + console.log(prim); + }); + }); + Mocha.test("getExn", () => { + Stdlib_Result.getExn({ + TAG: "Ok", + _0: 42 + }) === 42; + let exit = 0; + let val; + try { + val = Stdlib_Result.getExn({ + TAG: "Error", + _0: "Invalid data" + }); + exit = 1; + } catch (raw_exn) { + let exn = Primitive_exceptions.internalToException(raw_exn); + if (exn.RE_EXN_ID !== "Not_found") { + throw exn; + } + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 13658, + 9 + ], + Error: new Error() + }; + } + + }); + Mocha.test("getOr", () => { + Stdlib_Result.getOr({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Stdlib_Result.getOr({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); + Mocha.test("map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Stdlib_Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Stdlib_Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); + }); + Mocha.test("mapError", () => { + let format = n => "Error code: " + n.toString(); + Stdlib_Result.mapError({ + TAG: "Error", + _0: 14 + }, format); + Stdlib_Result.mapError({ + TAG: "Ok", + _0: "abc" + }, format); + }); + Mocha.test("mapOr", () => { + Stdlib_Result.mapOr({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Stdlib_Result.mapOr({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; + }); +}); + +Mocha.describe("Stdlib.Set", () => { + Mocha.test("add", () => { + let set = new Set(); + set.add("someValue"); + }); + Mocha.test("clear", () => { + let set = new Set(); + set.add("someKey"); + set.clear(); + }); + Mocha.test("delete", () => { + let set = new Set(); + set.add("someValue"); + let didDeleteValue = set.delete("someValue"); + console.log(didDeleteValue); + let didDeleteValue$1 = set.delete("someNonExistantKey"); + console.log(didDeleteValue$1); + }); + Mocha.test("forEach", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue2"); + set.forEach(value => { + console.log(value); + }); + }); + Mocha.test("fromArray", () => { + let languageRank = [ + "ReScript", + "JavaScript", + "TypeScript" + ]; + let set = new Set(languageRank); + if (set.has("ReScript")) { + console.log("Yay, ReScript is in there!"); + } else { + console.log("Uh-oh, something is _terribly_ wrong with this program... abort."); + } + }); + Mocha.test("fromIterator", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Stdlib.assertEqual(new Set(iterator).size, 3); + }); + Mocha.test("has", () => { + let set = new Set(); + set.add("someValue"); + if (set.has("someValue")) { + console.log("Yay, we have the value!"); + } else { + console.log("Nope, didn't have it."); + } + }); + Mocha.test("make", () => { + new Set(); + let set = new Set(); + set.add("Fine name"); + }); + Mocha.test("size", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue"); + set.add("someValue2"); + }); + Mocha.test("toArray", () => { + let set = new Set([ + "apple", + "orange", + "apple", + "banana" + ]); + Array.from(set); + }); + Mocha.test("values", () => { + let set = new Set(); + set.add("someValue"); + set.add("anotherValue"); + let values = set.values(); + console.log(values.next().value); + console.log(Array.from(set.values())); + }); +}); + +Mocha.describe("Stdlib.String", () => { + Mocha.test("charAt", () => { + "ReScript".charAt(0) === "R"; + "Hello".charAt(12) === ""; + "JS".charAt(5) === ""; + }); + Mocha.test("charCodeAt", () => { + "😺".charCodeAt(0) === 55357; + Primitive_object.equal("😺".codePointAt(0), 128570); + }); + Mocha.test("codePointAt", () => { + Primitive_object.equal("¿😺?".codePointAt(1), 128570); + "abc".codePointAt(5) === undefined; + }); + Mocha.test("concat", () => { + "cow".concat("bell") === "cowbell"; + "Re".concat("Script") === "ReScript"; + }); + Mocha.test("concatMany", () => { + "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; + }); + Mocha.test("endsWith", () => { + "BuckleScript".endsWith("Script") === true; + "BuckleShoes".endsWith("Script") === false; + }); + Mocha.test("endsWithFrom", () => { + "abcd".endsWith("cd", 4) === true; + "abcde".endsWith("cd", 3) === false; + "abcde".endsWith("cde", 99) === true; + "example.dat".endsWith("ple", 7) === true; + }); + Mocha.test("fromCharCode", () => { + String.fromCharCode(65) === "A"; + String.fromCharCode(968) === "ψ"; + String.fromCharCode(54620) === "한"; + String.fromCharCode(-64568) === "ψ"; + }); + Mocha.test("fromCharCodeMany", () => { + String.fromCharCode(189, 43, 190, 61) === "½+¾="; + String.fromCharCode(65, 66, 67) === "ABC"; + }); + Mocha.test("fromCodePoint", () => { + String.fromCodePoint(65) === "A"; + String.fromCodePoint(968) === "ψ"; + String.fromCodePoint(54620) === "한"; + String.fromCodePoint(128570) === "😺"; + }); + Mocha.test("fromCodePointMany", () => { + String.fromCodePoint(54620, 44544, 128570) === "한글😺"; + }); + Mocha.test("get", () => { + Primitive_object.equal("ReScript"[0], "R"); + Primitive_object.equal("Hello"[4], "o"); + }); + Mocha.test("getUnsafe", () => {}); + Mocha.test("includes", () => { + "programmer".includes("gram") === true; + "programmer".includes("er") === true; + "programmer".includes("pro") === true; + "programmer.dat".includes("xyz") === false; + }); + Mocha.test("includesFrom", () => { + "programmer".includes("gram", 1) === true; + "programmer".includes("gram", 4) === false; + "대한민국".includes("한", 1) === true; + }); + Mocha.test("indexOf", () => { + "bookseller".indexOf("ok") === 2; + "bookseller".indexOf("sell") === 4; + "beekeeper".indexOf("ee") === 1; + "bookseller".indexOf("xyz") === -1; + }); + Mocha.test("indexOfFrom", () => { + "bookseller".indexOf("ok", 1) === 2; + "bookseller".indexOf("sell", 2) === 4; + "bookseller".indexOf("sell", 5) === -1; + }); + Mocha.test("indexOfOpt", () => { + Primitive_object.equal(Stdlib_String.indexOfOpt("bookseller", "ok"), 2); + Stdlib_String.indexOfOpt("bookseller", "xyz") === undefined; + }); + Mocha.test("lastIndexOf", () => { + "bookseller".lastIndexOf("ok") === 2; + "beekeeper".lastIndexOf("ee") === 4; + "abcdefg".lastIndexOf("xyz") === -1; + }); + Mocha.test("lastIndexOfFrom", () => { + "bookseller".lastIndexOf("ok", 6) === 2; + "beekeeper".lastIndexOf("ee", 8) === 4; + "beekeeper".lastIndexOf("ee", 3) === 1; + "abcdefg".lastIndexOf("xyz", 4) === -1; + }); + Mocha.test("lastIndexOfOpt", () => { + Primitive_object.equal(Stdlib_String.lastIndexOfOpt("bookseller", "ok"), 2); + Primitive_object.equal(Stdlib_String.lastIndexOfOpt("beekeeper", "ee"), 4); + Stdlib_String.lastIndexOfOpt("abcdefg", "xyz") === undefined; + }); + Mocha.test("length", () => {}); + Mocha.test("localeCompare", () => { + "a".localeCompare("c") < 0.0 === true; + "a".localeCompare("a") === 0.0; + }); + Mocha.test("make", () => { + String(3.5) === "3.5"; + String([ + 1, + 2, + 3 + ]) === "1,2,3"; + }); + Mocha.test("match", () => { + Primitive_object.equal(Primitive_option.fromNullable("The better bats".match(/b[aeiou]t/)), ["bet"]); + Primitive_object.equal(Primitive_option.fromNullable("The better bats".match(/b[aeiou]t/g)), [ + "bet", + "bat" + ]); + Primitive_object.equal(Primitive_option.fromNullable("Today is 2018-04-05.".match(/(\d+)-(\d+)-(\d+)/)), [ + "2018-04-05", + "2018", + "04", + "05" + ]); + Primitive_object.equal(Primitive_option.fromNullable("The optional example".match(/(foo)?(example)/)), [ + "example", + undefined, + "example" + ]); + Primitive_option.fromNullable("The large container.".match(/b[aeiou]g/)) === undefined; + }); + Mocha.test("normalize", () => { + let string1 = "\u00F1"; + let string2 = "\u006E\u0303"; + if (string1 === string2) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 14036, + 0 + ], + Error: new Error() + }; + } + Stdlib.assertEqual(string1.normalize(), string2.normalize()); + }); + Mocha.test("normalizeForm", () => { + let string1 = "\uFB00"; + let string2 = "\u0066\u0066"; + console.log(string1 === string2); + let normalizeString1 = string1.normalize("NFKD"); + let normalizeString2 = string2.normalize("NFKD"); + console.log(normalizeString1 === normalizeString2); + }); + Mocha.test("padEnd", () => { + "Hello".padEnd(10, ".") === "Hello....."; + "abc".padEnd(1, "") === "abc"; + }); + Mocha.test("padStart", () => { + "abc".padStart(5, " ") === " abc"; + "abc".padStart(6, "123465") === "123abc"; + }); + Mocha.test("repeat", () => { + "ha".repeat(3) === "hahaha"; + "empty".repeat(0) === ""; + }); + Mocha.test("replace", () => { + "old string".replace("old", "new") === "new string"; + "the cat and the dog".replace("the", "this") === "this cat and the dog"; + }); + Mocha.test("replaceAll", () => { + "old old string".replaceAll("old", "new") === "new new string"; + "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; + }); + Mocha.test("replaceAllRegExp", () => { + "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; + }); + Mocha.test("replaceRegExp", () => { + "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; + }); + Mocha.test("replaceRegExpBy0Unsafe", () => { + let re = /[aeiou]/g; + let matchFn = (match, param, param$1) => match.toUpperCase(); + "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; + }); + Mocha.test("replaceRegExpBy1Unsafe", () => { + let re = /(Jony is )\d+/g; + let matchFn = (param, group1, param$1, param$2) => group1 + "41"; + "Jony is 40".replace(re, matchFn) === "Jony is 41"; + }); + Mocha.test("replaceRegExpBy2Unsafe", () => { + let re = /(\d+) times (\d+)/; + let matchFn = (param, group1, group2, param$1, param$2) => { + let match = Stdlib_Int.fromString(group1, undefined); + let match$1 = Stdlib_Int.fromString(group2, undefined); + if (match !== undefined && match$1 !== undefined) { + return (match * match$1 | 0).toString(); + } else { + return "???"; + } + }; + "7 times 6".replace(re, matchFn) === "42"; + }); + Mocha.test("search", () => { + "testing 1 2 3".search(/\d+/) === 8; + "no numbers".search(/\d+/) === -1; + }); + Mocha.test("searchOpt", () => { + Primitive_object.equal(Stdlib_String.searchOpt("testing 1 2 3", /\d+/), 8); + Stdlib_String.searchOpt("no numbers", /\d+/) === undefined; + }); + Mocha.test("slice", () => { + "abcdefg".slice(2, 5) === "cde"; + "abcdefg".slice(2, 9) === "cdefg"; + "abcdefg".slice(-4, -2) === "de"; + "abcdefg".slice(5, 1) === ""; + }); + Mocha.test("sliceToEnd", () => { + "abcdefg".slice(4) === "efg"; + "abcdefg".slice(-2) === "fg"; + "abcdefg".slice(7) === ""; + }); + Mocha.test("split", () => { + Primitive_object.equal("2018-01-02".split("-"), [ + "2018", + "01", + "02" + ]); + Primitive_object.equal("a,b,,c".split(","), [ + "a", + "b", + "", + "c" + ]); + Primitive_object.equal("good::bad as great::awful".split("::"), [ + "good", + "bad as great", + "awful" + ]); + Primitive_object.equal("has-no-delimiter".split(";"), ["has-no-delimiter"]); + }); + Mocha.test("splitAtMost", () => { + Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 3), [ + "ant", + "bee", + "cat" + ]); + Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 0), []); + Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 9), [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]); + }); + Mocha.test("splitByRegExp", () => { + Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ + "Jan", + "Feb", + "Mar" + ]); + }); + Mocha.test("splitByRegExpAtMost", () => { + Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ + "Hello", + "World.", + "How" + ]); + }); + Mocha.test("startsWith", () => { + "BuckleScript".startsWith("Buckle") === true; + "BuckleScript".startsWith("") === true; + "JavaScript".startsWith("Buckle") === false; + }); + Mocha.test("startsWithFrom", () => { + "BuckleScript".startsWith("kle", 3) === true; + "BuckleScript".startsWith("", 3) === true; + "JavaScript".startsWith("Buckle", 2) === false; + }); + Mocha.test("substring", () => { + "playground".substring(3, 6) === "ygr"; + "playground".substring(6, 3) === "ygr"; + "playground".substring(4, 12) === "ground"; + }); + Mocha.test("substringToEnd", () => { + "playground".substring(4) === "ground"; + "playground".substring(-3) === "playground"; + "playground".substring(12) === ""; + }); + Mocha.test("toLowerCase", () => { + "ABC".toLowerCase() === "abc"; + "ΣΠ".toLowerCase() === "σπ"; + "ΠΣ".toLowerCase() === "πς"; + }); + Mocha.test("toUpperCase", () => { + "abc".toUpperCase() === "ABC"; + "Straße".toUpperCase() === "STRASSE"; + "πς".toUpperCase() === "ΠΣ"; + }); + Mocha.test("trim", () => { + " abc def ".trim() === "abc def"; + "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; + }); + Mocha.test("trimEnd", () => { + " Hello world! ".trimEnd() === " Hello world!"; + " Hello world! ".trimEnd() === " Hello world!"; + }); + Mocha.test("trimStart", () => { + " Hello world! ".trimStart() === "Hello world! "; + " Hello world! ".trimStart() === "Hello world! "; + }); + Mocha.test("unsafeReplaceRegExpBy0", () => { + let re = /[aeiou]/g; + let matchFn = (match, param, param$1) => match.toUpperCase(); + "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; + }); + Mocha.test("unsafeReplaceRegExpBy1", () => { + let re = /(Jony is )\d+/g; + let matchFn = (param, group1, param$1, param$2) => group1 + "41"; + "Jony is 40".replace(re, matchFn) === "Jony is 41"; + }); + Mocha.test("unsafeReplaceRegExpBy2", () => { + let re = /(\d+) times (\d+)/; + let matchFn = (param, group1, group2, param$1, param$2) => { + let match = Stdlib_Int.fromString(group1, undefined); + let match$1 = Stdlib_Int.fromString(group2, undefined); + if (match !== undefined && match$1 !== undefined) { + return (match * match$1 | 0).toString(); + } else { + return "???"; + } + }; + "7 times 6".replace(re, matchFn) === "42"; + }); +}); + +Mocha.describe("Stdlib.Symbol", () => { + Mocha.test("description", () => { + let sym = Symbol("sym1"); + Stdlib.assertEqual(sym.description, "sym1"); + }); + Mocha.test("getFor", () => { + Stdlib.assertEqual(Symbol.for("sym1"), Symbol.for("sym1")); + }); + Mocha.test("keyFor", () => { + let globalSym = Symbol.for("sym1"); + Stdlib.assertEqual(Stdlib_Option.flatMap(globalSym, prim => prim.description), "sym1"); + }); + Mocha.test("make", () => { + Stdlib.assertEqual(Symbol("sym1").description, "sym1"); + }); + Mocha.test("toString", () => { + let sym = Symbol("sym1"); + Stdlib.assertEqual(sym.toString(), "Symbol(sym1)"); + }); +}); + +Mocha.describe("Stdlib.Type.Classify", () => { + Mocha.test("classify", () => { + let match = Stdlib_Type.Classify.classify(null); + if (typeof match !== "object" && match === "Null") { + console.log("Yup, that's null."); + } else { + console.log("This doesn't actually appear to be null..."); + } + }); +}); + +Mocha.describe("Stdlib.Type", () => { + Mocha.test("typeof", () => { + console.log("string"); + let match = "boolean"; + if (match === "boolean") { + console.log("This is a bool, yay!"); + } else { + console.log("Oh, not a bool sadly..."); + } + }); +}); + +/* Not a pure module */ diff --git a/tests/docstring_tests/rescript.json b/tests/docstring_tests/rescript.json index e987791ab6..d8b223e112 100644 --- a/tests/docstring_tests/rescript.json +++ b/tests/docstring_tests/rescript.json @@ -7,5 +7,5 @@ "module": "esmodule", "in-source": true }, - "suffix": ".res.mjs" + "suffix": ".res.js" } From ff710cde3168756f97be89ec4fd32194b14692cb Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 05:06:38 +0900 Subject: [PATCH 27/37] update artifacts --- .github/workflows/get_artifact_dir_name.js | 2 +- packages/artifacts.txt | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/get_artifact_dir_name.js b/.github/workflows/get_artifact_dir_name.js index fc2348f311..9ad465b6a4 100644 --- a/.github/workflows/get_artifact_dir_name.js +++ b/.github/workflows/get_artifact_dir_name.js @@ -1,7 +1,7 @@ import * as fs from "node:fs"; import * as os from "node:os"; -import { platformName } from "#cli/paths"; +import { platformName } from "#cli/bins"; // Pass artifactDirName to subsequent GitHub actions fs.appendFileSync( diff --git a/packages/artifacts.txt b/packages/artifacts.txt index c6e6369cef..7be00eae08 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -6,15 +6,8 @@ LICENSE README.md cli/bsc.js cli/common/args.js +cli/common/bins.js cli/common/bsb.js -cli/common/paths.js -cli/linux/bsb_helper.exe -cli/linux/bsc.exe -cli/linux/ninja.exe -cli/linux/rescript-editor-analysis.exe -cli/linux/rescript-tools.exe -cli/linux/rescript.exe -cli/linux/rewatch.exe cli/rescript-tools.js cli/rescript.js cli/rescript/dump.js From 3e69a83e359d10606f7b50687177fa2e5c1eed97 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 05:17:00 +0900 Subject: [PATCH 28/37] fix --- .../src/{React.bs.js => React.res.js} | 13 +++++++------ ...pr_3695_test.bs.js => gpr_3695_test.res.js} | 11 ++++++----- ...pr_3987_test.bs.js => gpr_3987_test.res.js} | 13 +++++++------ ...t.bs.js => recursive_component_test.res.js} | 5 +++-- .../transitive_pinned_dependency1/input.js | 2 +- .../node_modules/c/bsconfig.json | 2 +- .../transitive_pinned_dependency2/input.js | 2 +- .../node_modules/c/bsconfig.json | 8 ++++---- tests/build_tests/zerocycle/src/bar.res.js | 18 ++++++++++++++++++ tests/build_tests/zerocycle/src/demo.res.js | 9 +++++++++ tests/build_tests/zerocycle/src/demo2.res.js | 9 +++++++++ tests/build_tests/zerocycle/src/foo.res.js | 2 ++ tests/build_tests/zerocycle/src/foo2.res.js | 2 ++ 13 files changed, 70 insertions(+), 26 deletions(-) rename tests/build_tests/react_ppx/src/{React.bs.js => React.res.js} (52%) rename tests/build_tests/react_ppx/src/{gpr_3695_test.bs.js => gpr_3695_test.res.js} (59%) rename tests/build_tests/react_ppx/src/{gpr_3987_test.bs.js => gpr_3987_test.res.js} (83%) rename tests/build_tests/react_ppx/src/{recursive_component_test.bs.js => recursive_component_test.res.js} (87%) create mode 100644 tests/build_tests/zerocycle/src/bar.res.js create mode 100644 tests/build_tests/zerocycle/src/demo.res.js create mode 100644 tests/build_tests/zerocycle/src/demo2.res.js create mode 100644 tests/build_tests/zerocycle/src/foo.res.js create mode 100644 tests/build_tests/zerocycle/src/foo2.res.js diff --git a/tests/build_tests/react_ppx/src/React.bs.js b/tests/build_tests/react_ppx/src/React.res.js similarity index 52% rename from tests/build_tests/react_ppx/src/React.bs.js rename to tests/build_tests/react_ppx/src/React.res.js index 05c8865770..fb408bebf1 100644 --- a/tests/build_tests/react_ppx/src/React.bs.js +++ b/tests/build_tests/react_ppx/src/React.res.js @@ -1,5 +1,4 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; let Ref = {}; @@ -12,9 +11,11 @@ let Fragment = {}; let Suspense = {}; -exports.Ref = Ref; -exports.Children = Children; -exports.Context = Context; -exports.Fragment = Fragment; -exports.Suspense = Suspense; +export { + Ref, + Children, + Context, + Fragment, + Suspense, +} /* No side effect */ diff --git a/tests/build_tests/react_ppx/src/gpr_3695_test.bs.js b/tests/build_tests/react_ppx/src/gpr_3695_test.res.js similarity index 59% rename from tests/build_tests/react_ppx/src/gpr_3695_test.bs.js rename to tests/build_tests/react_ppx/src/gpr_3695_test.res.js index 42dcc0f6db..ebaf897020 100644 --- a/tests/build_tests/react_ppx/src/gpr_3695_test.bs.js +++ b/tests/build_tests/react_ppx/src/gpr_3695_test.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let Foo = require("Foo"); +import * as Foo from "Foo"; let React = {}; @@ -11,7 +10,9 @@ function test(className) { return Foo; } -exports.React = React; -exports.Test = Test; -exports.test = test; +export { + React, + Test, + test, +} /* Foo Not a pure module */ diff --git a/tests/build_tests/react_ppx/src/gpr_3987_test.bs.js b/tests/build_tests/react_ppx/src/gpr_3987_test.res.js similarity index 83% rename from tests/build_tests/react_ppx/src/gpr_3987_test.bs.js rename to tests/build_tests/react_ppx/src/gpr_3987_test.res.js index a8451b2174..378f9156ca 100644 --- a/tests/build_tests/react_ppx/src/gpr_3987_test.bs.js +++ b/tests/build_tests/react_ppx/src/gpr_3987_test.res.js @@ -1,7 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; -let JsxRuntime = require("react/jsx-runtime"); +import * as JsxRuntime from "react/jsx-runtime"; function makeContainer(text) { let container = document.createElement("div"); @@ -56,8 +55,10 @@ JsxRuntime.jsx(Gpr_3987_test$Gpr3987ReproError, { onChange: (param, param$1) => {} }); -exports.makeContainer = makeContainer; -exports.Gpr3987ReproOk = Gpr3987ReproOk; -exports.Gpr3987ReproOk2 = Gpr3987ReproOk2; -exports.Gpr3987ReproError = Gpr3987ReproError; +export { + makeContainer, + Gpr3987ReproOk, + Gpr3987ReproOk2, + Gpr3987ReproError, +} /* Not a pure module */ diff --git a/tests/build_tests/react_ppx/src/recursive_component_test.bs.js b/tests/build_tests/react_ppx/src/recursive_component_test.res.js similarity index 87% rename from tests/build_tests/react_ppx/src/recursive_component_test.bs.js rename to tests/build_tests/react_ppx/src/recursive_component_test.res.js index c24783b0fa..4e3fd9951f 100644 --- a/tests/build_tests/react_ppx/src/recursive_component_test.bs.js +++ b/tests/build_tests/react_ppx/src/recursive_component_test.res.js @@ -1,5 +1,4 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -'use strict'; function mm(x) { @@ -19,5 +18,7 @@ let Rec = { mm: mm }; -exports.Rec = Rec; +export { + Rec, +} /* No side effect */ diff --git a/tests/build_tests/transitive_pinned_dependency1/input.js b/tests/build_tests/transitive_pinned_dependency1/input.js index c04f3991e4..7ac7da56f3 100644 --- a/tests/build_tests/transitive_pinned_dependency1/input.js +++ b/tests/build_tests/transitive_pinned_dependency1/input.js @@ -10,6 +10,6 @@ const output = await execBuild(); console.log(output); assert.ok( - existsSync("./node_modules/c/lib/js/tests/test.mjs"), + existsSync("./node_modules/c/lib/es6/tests/test.res.js"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'", ); diff --git a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json index 08bfc2bd3c..aeb18883bb 100644 --- a/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency1/node_modules/c/bsconfig.json @@ -17,5 +17,5 @@ }, "warnings": { "error": true - }, + } } diff --git a/tests/build_tests/transitive_pinned_dependency2/input.js b/tests/build_tests/transitive_pinned_dependency2/input.js index ef3ca3c461..31f05eab92 100644 --- a/tests/build_tests/transitive_pinned_dependency2/input.js +++ b/tests/build_tests/transitive_pinned_dependency2/input.js @@ -10,6 +10,6 @@ const output = await execBuild(); console.log(output); assert.ok( - !existsSync("./node_modules/c/lib/js/tests/test.mjs"), + !existsSync("./node_modules/c/lib/es6/tests/test.res.js"), "dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'", ); diff --git a/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json b/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json index b63b43209c..aeb18883bb 100644 --- a/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json +++ b/tests/build_tests/transitive_pinned_dependency2/node_modules/c/bsconfig.json @@ -11,11 +11,11 @@ } ], "package-specs": { - "module": "commonjs", - "in-source": false + "module": "esmodule", + "in-source": false, + "suffix": ".res.js" }, "warnings": { "error": true - }, - "suffix": ".mjs" + } } diff --git a/tests/build_tests/zerocycle/src/bar.res.js b/tests/build_tests/zerocycle/src/bar.res.js new file mode 100644 index 0000000000..c1a2d01a74 --- /dev/null +++ b/tests/build_tests/zerocycle/src/bar.res.js @@ -0,0 +1,18 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +let Bar = {}; + +let Nested = { + Bar: Bar +}; + +let Bar$1 = { + t: 42 +}; + +export { + Nested, + Bar$1 as Bar, +} +/* No side effect */ diff --git a/tests/build_tests/zerocycle/src/demo.res.js b/tests/build_tests/zerocycle/src/demo.res.js new file mode 100644 index 0000000000..0e473e85e6 --- /dev/null +++ b/tests/build_tests/zerocycle/src/demo.res.js @@ -0,0 +1,9 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +let Foo = {}; + +export { + Foo, +} +/* No side effect */ diff --git a/tests/build_tests/zerocycle/src/demo2.res.js b/tests/build_tests/zerocycle/src/demo2.res.js new file mode 100644 index 0000000000..59cc76cd64 --- /dev/null +++ b/tests/build_tests/zerocycle/src/demo2.res.js @@ -0,0 +1,9 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +let Foo2 = {}; + +export { + Foo2, +} +/* No side effect */ diff --git a/tests/build_tests/zerocycle/src/foo.res.js b/tests/build_tests/zerocycle/src/foo.res.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/tests/build_tests/zerocycle/src/foo.res.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ diff --git a/tests/build_tests/zerocycle/src/foo2.res.js b/tests/build_tests/zerocycle/src/foo2.res.js new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/tests/build_tests/zerocycle/src/foo2.res.js @@ -0,0 +1,2 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE +/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ From 73b9765214844f355c753e11773169f95561ff4e Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 05:18:41 +0900 Subject: [PATCH 29/37] prefer yarn --- lib_dev/process.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index bae21ce2d0..8878c4ad6f 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -21,7 +21,7 @@ const signals = { SIGTERM: 15, }; -export const { exec, node, npx, mocha, bsc, rescript, execBuild, execClean } = +export const { exec, node, yarn, mocha, bsc, rescript, execBuild, execClean } = setup(); /** @@ -94,14 +94,14 @@ export function setup(cwd = process.cwd()) { }, /** - * `npx` CLI + * `yarn` CLI * * @param {string[]} [args] * @param {ExecOptions} [options] * @return {Promise} */ - npx(args = [], options = {}) { - return exec("npx", args, options); + yarn(args = [], options = {}) { + return exec("yarn", args, options); }, /** @@ -112,6 +112,8 @@ export function setup(cwd = process.cwd()) { * @return {Promise} */ mocha(args = [], options = {}) { + // `yarn mocha` works, but format output differently + // No more efforts here since we're plannig to drop Mocha return exec("npx", ["mocha", ...args], options); }, From f194ee4d6d609e5c362d91f5d3d2f2b35a591425 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 05:22:09 +0900 Subject: [PATCH 30/37] fix gentype test --- tests/gentype_tests/typescript-react-example/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/gentype_tests/typescript-react-example/tsconfig.json b/tests/gentype_tests/typescript-react-example/tsconfig.json index 9835ab7a74..589016b98d 100644 --- a/tests/gentype_tests/typescript-react-example/tsconfig.json +++ b/tests/gentype_tests/typescript-react-example/tsconfig.json @@ -7,6 +7,7 @@ "strict": true, "skipLibCheck": true, "allowJs": true, + "allowImportingTsExtensions": true, "noEmit": true }, "include": ["src"] From efad3d11f22a7b9d32e20d5971826dee809a426d Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 20:08:42 +0900 Subject: [PATCH 31/37] fix --- lib_dev/process.js | 60 +++++++++++++++++++++++++++++++++++++--------- scripts/test.js | 15 ++++++------ 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/lib_dev/process.js b/lib_dev/process.js index 8878c4ad6f..444d28019a 100644 --- a/lib_dev/process.js +++ b/lib_dev/process.js @@ -21,8 +21,17 @@ const signals = { SIGTERM: 15, }; -export const { exec, node, yarn, mocha, bsc, rescript, execBuild, execClean } = - setup(); +export const { + shell, + node, + yarn, + mocha, + bsc, + rescript, + execBin, + execBuild, + execClean, +} = setup(); /** * @param {string} [cwd] @@ -71,7 +80,11 @@ export function setup(cwd = process.cwd()) { } if (throwOnFail && code !== 0) { - reject({ status: code, stdout, stderr }); + reject( + new Error( + `Command ${command} exited with non-zero status: ${code}`, + ), + ); } else { resolve({ status: code, stdout, stderr }); } @@ -80,32 +93,44 @@ export function setup(cwd = process.cwd()) { } return { - exec, + /** + * bash shell script + * + * @param {string} script + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + shell(script, args = [], options = {}) { + return exec("bash", [script, ...args], options); + }, /** - * `node` CLI + * Execute JavaScript on Node.js * + * @param {string} script * @param {string[]} [args] * @param {ExecOptions} [options] * @return {Promise} */ - node(args = [], options = {}) { - return exec("node", args, options); + node(script, args = [], options = {}) { + return exec("node", [script, ...args], options); }, /** - * `yarn` CLI + * Execute Yarn command * + * @param {string} command * @param {string[]} [args] * @param {ExecOptions} [options] * @return {Promise} */ - yarn(args = [], options = {}) { - return exec("yarn", args, options); + yarn(command, args = [], options = {}) { + return exec("yarn", [...command.split(" "), ...args], options); }, /** - * Mocha CLI + * Execute Mocha CLI * * @param {string[]} [args] * @param {ExecOptions} [options] @@ -168,5 +193,18 @@ export function setup(cwd = process.cwd()) { execClean(args = [], options = {}) { return exec(rescript_exe, ["clean", ...args], options); }, + + /** + * Execute any binary or wrapper. + * It should support Windows as well + * + * @param {string} bin + * @param {string[]} [args] + * @param {ExecOptions} [options] + * @return {Promise} + */ + execBin(bin, args = [], options = {}) { + return exec(bin, args, options); + }, }; } diff --git a/scripts/test.js b/scripts/test.js index 58ce655852..1a975f1ef8 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -12,12 +12,13 @@ import { } from "#dev/paths"; import { - exec, + execBin, execBuild, execClean, mocha, node, rescript, + shell, } from "#dev/process"; let ounitTest = false; @@ -55,7 +56,7 @@ if (process.argv.includes("-all")) { } if (formatTest) { - await exec("./scripts/format_check.sh", [], { + await shell("./scripts/format_check.sh", [], { cwd: projectDir, stdio: "inherit", }); @@ -65,7 +66,7 @@ if (ounitTest) { if (process.platform === "win32") { console.log("Skipping OUnit tests on Windows"); } else { - await exec(ounitTestBin, [], { + await execBin(ounitTestBin, [], { stdio: "inherit", }); } @@ -87,12 +88,12 @@ if (mochaTest) { stdio: "inherit", }); - await node(["tests/tests/src/core/Core_TestSuite.mjs"], { + await node("tests/tests/src/core/Core_TestSuite.mjs", [], { cwd: projectDir, stdio: "inherit", }); - await node(["tests/tests/src/core/Core_TempTests.mjs"], { + await node("tests/tests/src/core/Core_TempTests.mjs", [], { cwd: projectDir, stdio: "inherit", }); @@ -115,7 +116,7 @@ if (bsbTest) { console.log(`testing ${file}`); // note existsSync test already ensure that it is a directory - const out = await exec("node", ["input.js"], { cwd: testDir }); + const out = await node("input.js", [], { cwd: testDir }); console.log(out.stdout); if (out.status === 0) { @@ -159,7 +160,7 @@ if (runtimeDocstrings) { }); // Generate rescript file with all tests `generated_mocha_test.res` - await node([path.join(docstringTestDir, "DocTest.res.js")], { + await node(path.join(docstringTestDir, "DocTest.res.js"), [], { cwd: projectDir, stdio: "inherit", }); From 8bb32bb868d83d4392dab59967aa6b5970394e71 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 20:43:06 +0900 Subject: [PATCH 32/37] disable useTemplate rule --- biome.json | 3 +++ cli/rescript/format.js | 4 +++- tests/build_tests/super_errors/input.js | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/biome.json b/biome.json index cea5d0afee..aef80be170 100644 --- a/biome.json +++ b/biome.json @@ -10,6 +10,9 @@ "enabled": true, "rules": { "recommended": true, + "style": { + "useTemplate": "off" + }, "nursery": { "noCommonJs": "error" }, diff --git a/cli/rescript/format.js b/cli/rescript/format.js index 1d9a8029a2..072d340d76 100644 --- a/cli/rescript/format.js +++ b/cli/rescript/format.js @@ -198,9 +198,11 @@ export async function main(argv, rescript_exe, bsc_exe) { process.exit(2); } if (isSupportedStd(use_stdin)) { + const randomHex = crypto.randomBytes(8).toString("hex"); + const basename = path.basename(use_stdin); const filename = path.join( os.tmpdir(), - `rescript_${crypto.randomBytes(8).toString("hex")}${path.parse(use_stdin).base}`, + `rescript_${randomHex}${basename}`, ); (async () => { const content = await readStdin(); diff --git a/tests/build_tests/super_errors/input.js b/tests/build_tests/super_errors/input.js index 5f3eb8db68..f31370b097 100644 --- a/tests/build_tests/super_errors/input.js +++ b/tests/build_tests/super_errors/input.js @@ -27,7 +27,7 @@ function postProcessErrorOutput(output) { result = result.trimEnd(); result = result.replace( /(?:[A-Z]:)?[\\/][^ ]+?tests[\\/]build_tests[\\/]super_errors[\\/]([^:]+)/g, - (_match, path, _offset, _string) => `/.../${path.replace("\\", "/")}`, + (_match, path, _offset, _string) => "/.../" + path.replace("\\", "/"), ); return normalizeNewlines(result); } From c72e0bb8289934bb92cce935d4ea77a7767fa2fa Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 23:23:29 +0900 Subject: [PATCH 33/37] fix rebase miss --- playground/playground_test.cjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/playground/playground_test.cjs b/playground/playground_test.cjs index 763aebb094..3e7a40e022 100644 --- a/playground/playground_test.cjs +++ b/playground/playground_test.cjs @@ -1,6 +1,6 @@ // Playground bundle is UMD module // It uses `module.exports` in current context, or fallback to `globalThis` -const { rescript_compiler } = require("./compiler.js"); +const { rescript_compiler } = require("./compiler.cjs"); require("./packages/compiler-builtins/cmij.cjs"); require("./packages/@rescript/react/cmij.cjs"); From 1d20225cfca8fe13b4c5fa7046836426115f010c Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 23:31:42 +0900 Subject: [PATCH 34/37] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d503c99bb6..070d0df456 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ #### :house: Internal - Remove `Stdlib_Char` module for now. https://github.com/rescript-lang/rescript/pull/7367 +- Convert internal JavaScript codebase into ESM, ReScript package itself is now ESM (`"type": "module"`). https://github.com/rescript-lang/rescript/pull/6899 # 12.0.0-alpha.10 From e2c6420d6d36d27f5b63bdb7fa897d47354e737b Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Thu, 27 Mar 2025 00:49:32 +0900 Subject: [PATCH 35/37] add README to lib_dev --- lib_dev/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib_dev/README.md diff --git a/lib_dev/README.md b/lib_dev/README.md new file mode 100644 index 0000000000..b742ebf514 --- /dev/null +++ b/lib_dev/README.md @@ -0,0 +1,19 @@ +# Libraries for development + +This is a place for development purposes libraries. + +You can use modules here by `#dev/*` + +e.g. in `scripts` or `tests`: + +```js +import { setup } from '#dev/process'; + +const { execBuild } = setup(import.meta.url); + +// Execute ReScript in the current file location. +await execBuild({ stdio: "inherit" }); +``` + +> [!IMPORTANT] +> DO NOT USE this modules in the compiler artifacts. From 6164bd238b1c0488b1ef26e01caa6fac1791e8aa Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sat, 29 Mar 2025 18:34:38 +0900 Subject: [PATCH 36/37] ignore docstring test artifact --- tests/docstring_tests/.gitignore | 3 +- .../generated_mocha_test.res.js | 19339 ---------------- 2 files changed, 1 insertion(+), 19341 deletions(-) delete mode 100644 tests/docstring_tests/generated_mocha_test.res.js diff --git a/tests/docstring_tests/.gitignore b/tests/docstring_tests/.gitignore index 448ac7b39c..57ede28ad4 100644 --- a/tests/docstring_tests/.gitignore +++ b/tests/docstring_tests/.gitignore @@ -1,2 +1 @@ -generated_mocha_test.res -generated_mocha_test.res.mjs +generated_mocha_test.res* diff --git a/tests/docstring_tests/generated_mocha_test.res.js b/tests/docstring_tests/generated_mocha_test.res.js deleted file mode 100644 index 4611517b45..0000000000 --- a/tests/docstring_tests/generated_mocha_test.res.js +++ /dev/null @@ -1,19339 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Mocha from "mocha"; -import * as Stdlib from "rescript/lib/es6/Stdlib.js"; -import * as Belt_Id from "rescript/lib/es6/Belt_Id.js"; -import * as Belt_Int from "rescript/lib/es6/Belt_Int.js"; -import * as Belt_Map from "rescript/lib/es6/Belt_Map.js"; -import * as Belt_Set from "rescript/lib/es6/Belt_Set.js"; -import * as Belt_List from "rescript/lib/es6/Belt_List.js"; -import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; -import * as Belt_Float from "rescript/lib/es6/Belt_Float.js"; -import * as Belt_Range from "rescript/lib/es6/Belt_Range.js"; -import * as Pervasives from "rescript/lib/es6/Pervasives.js"; -import * as Stdlib_Exn from "rescript/lib/es6/Stdlib_Exn.js"; -import * as Stdlib_Int from "rescript/lib/es6/Stdlib_Int.js"; -import * as Belt_MapInt from "rescript/lib/es6/Belt_MapInt.js"; -import * as Belt_Option from "rescript/lib/es6/Belt_Option.js"; -import * as Belt_Result from "rescript/lib/es6/Belt_Result.js"; -import * as Stdlib_Bool from "rescript/lib/es6/Stdlib_Bool.js"; -import * as Stdlib_Char from "rescript/lib/es6/Stdlib_Char.js"; -import * as Stdlib_Dict from "rescript/lib/es6/Stdlib_Dict.js"; -import * as Stdlib_JSON from "rescript/lib/es6/Stdlib_JSON.js"; -import * as Stdlib_List from "rescript/lib/es6/Stdlib_List.js"; -import * as Stdlib_Math from "rescript/lib/es6/Stdlib_Math.js"; -import * as Stdlib_Null from "rescript/lib/es6/Stdlib_Null.js"; -import * as Stdlib_Type from "rescript/lib/es6/Stdlib_Type.js"; -import * as Belt_HashMap from "rescript/lib/es6/Belt_HashMap.js"; -import * as Belt_HashSet from "rescript/lib/es6/Belt_HashSet.js"; -import * as Belt_MapDict from "rescript/lib/es6/Belt_MapDict.js"; -import * as Belt_SetDict from "rescript/lib/es6/Belt_SetDict.js"; -import * as Stdlib_Array from "rescript/lib/es6/Stdlib_Array.js"; -import * as Stdlib_Error from "rescript/lib/es6/Stdlib_Error.js"; -import * as Stdlib_Float from "rescript/lib/es6/Stdlib_Float.js"; -import * as Primitive_int from "rescript/lib/es6/Primitive_int.js"; -import * as Stdlib_Option from "rescript/lib/es6/Stdlib_Option.js"; -import * as Stdlib_Result from "rescript/lib/es6/Stdlib_Result.js"; -import * as Stdlib_String from "rescript/lib/es6/Stdlib_String.js"; -import * as Belt_MapString from "rescript/lib/es6/Belt_MapString.js"; -import * as Belt_SortArray from "rescript/lib/es6/Belt_SortArray.js"; -import * as Stdlib_Promise from "rescript/lib/es6/Stdlib_Promise.js"; -import * as Belt_MutableSet from "rescript/lib/es6/Belt_MutableSet.js"; -import * as Stdlib_Iterator from "rescript/lib/es6/Stdlib_Iterator.js"; -import * as Stdlib_Nullable from "rescript/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; -import * as Primitive_option from "rescript/lib/es6/Primitive_option.js"; -import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; -import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js"; - -Mocha.describe("Belt", () => { - Mocha.test("HashMap", () => { - let I0 = Belt_Id.hashable(param => 65535, (a, b) => a === b); - let s0 = Belt_HashMap.make(40, I0); - let I1 = Belt_Id.hashable(param => 255, (a, b) => a === b); - let s1 = Belt_HashMap.make(40, I1); - Belt_HashMap.set(s0, 0, 3); - Belt_HashMap.set(s1, 1, "3"); - }); - Mocha.test("HashSet", () => { - let I0 = Belt_Id.hashable(a => a & 65535, (a, b) => a === b); - Belt_HashSet.make(40, I0); - let I1 = Belt_Id.hashable(a => a & 255, (a, b) => a === b); - let s1 = Belt_HashSet.make(40, I1); - Belt_HashSet.add(s1, 0); - Belt_HashSet.add(s1, 1); - }); - Mocha.test("MutableSet", () => { - let cmp = (param, param$1) => { - let c = Primitive_object.compare(param[0], param$1[0]); - if (c !== 0) { - return c; - } else { - return Primitive_object.compare(param[1], param$1[1]); - } - }; - let PairComparator = Belt_Id.MakeComparable({ - cmp: cmp - }); - let mySet = Belt_MutableSet.make(PairComparator); - Belt_MutableSet.add(mySet, [ - 1, - 2 - ]); - }); - Mocha.test("Option", () => {}); - Mocha.test("Set", () => { - let cmp = (param, param$1) => { - let c = Primitive_object.compare(param[0], param$1[0]); - if (c !== 0) { - return c; - } else { - return Primitive_object.compare(param[1], param$1[1]); - } - }; - let PairComparator = Belt_Id.MakeComparable({ - cmp: cmp - }); - let mySet = Belt_Set.make(PairComparator); - Belt_Set.add(mySet, [ - 1, - 2 - ]); - let cmp$1 = Primitive_object.compare; - Belt_Id.MakeComparable({ - cmp: cmp$1 - }); - }); -}); - -Mocha.describe("Belt.Array", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt.Float", () => { - Mocha.test("*", () => { - Stdlib.assertEqual(2.0 * 2.0, 4.0); - }); - Mocha.test("+", () => { - Stdlib.assertEqual(2.0 + 2.0, 4.0); - }); - Mocha.test("-", () => { - Stdlib.assertEqual(2.0 - 1.0, 1.0); - }); - Mocha.test("/", () => { - Stdlib.assertEqual(4.0 / 2.0, 2.0); - }); - Mocha.test("fromInt", () => { - console.log(1 === 1.0); - }); - Mocha.test("fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); - }); - Mocha.test("toInt", () => { - console.log(true); - }); - Mocha.test("toString", () => { - console.log(String(1.0) === "1.0"); - }); -}); - -Mocha.describe("Belt.HashMap", () => { - Mocha.test("clear", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.fromArray([[ - 1, - "1" - ]], IntHash); - Belt_HashMap.clear(hMap); - Belt_HashMap.isEmpty(hMap) === true; - }); - Mocha.test("copy", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntHash); - let s1 = Belt_HashMap.copy(s0); - Belt_HashMap.set(s0, 2, "3"); - Primitive_object.notequal(Belt_HashMap.get(s0, 2), Belt_HashMap.get(s1, 2)); - }); - Mocha.test("forEach", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.forEach(s0, (key, value) => { - console.log(key, value); - }); - }); - Mocha.test("fromArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ], IntHash); - Primitive_object.equal(Belt_HashMap.toArray(s0), [ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ]); - }); - Mocha.test("get", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Primitive_object.equal(Belt_HashMap.get(s0, 1), "value1"); - Belt_HashMap.get(s0, 2) === undefined; - }); - Mocha.test("getBucketHistogram", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.getBucketHistogram(hMap); - }); - Mocha.test("has", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.has(s0, 1) === true; - Belt_HashMap.has(s0, 2) === false; - }); - Mocha.test("isEmpty", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - Belt_HashMap.isEmpty(Belt_HashMap.fromArray([[ - 1, - "1" - ]], IntHash)) === false; - }); - Mocha.test("keepMapInPlace", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Belt_HashMap.keepMapInPlace(s0, (key, value) => { - if (key === 1) { - return; - } else { - return value; - } - }); - }); - Mocha.test("keysToArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.keysToArray(s0), [ - 1, - 2 - ]); - }); - Mocha.test("logStats", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.logStats(hMap); - }); - Mocha.test("make", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 0, "a"); - }); - Mocha.test("mergeMany", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.mergeMany(hMap, [ - [ - 1, - "1" - ], - [ - 2, - "2" - ] - ]); - }); - Mocha.test("reduce", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Stdlib.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); - }); - Mocha.test("remove", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.remove(s0, 1); - Belt_HashMap.has(s0, 1) === false; - }); - Mocha.test("set", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntHash); - Belt_HashMap.set(s0, 2, "3"); - Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ - "1", - "3", - "3" - ]); - }); - Mocha.test("size", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Belt_HashMap.size(s0) === 2; - }); - Mocha.test("toArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.toArray(s0), [ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ]); - }); - Mocha.test("valuesToArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ - "value1", - "value2" - ]); - }); -}); - -Mocha.describe("Belt.Int", () => { - Mocha.test("*", () => { - Stdlib.assertEqual(4, 4); - }); - Mocha.test("+", () => { - Stdlib.assertEqual(4, 4); - }); - Mocha.test("-", () => { - Stdlib.assertEqual(1, 1); - }); - Mocha.test("/", () => { - Stdlib.assertEqual(2, 2); - }); - Mocha.test("fromFloat", () => { - Stdlib.assertEqual(1, 1); - }); - Mocha.test("fromString", () => { - Stdlib.assertEqual(Belt_Int.fromString("1"), 1); - }); - Mocha.test("toFloat", () => { - Stdlib.assertEqual(1, 1.0); - }); - Mocha.test("toString", () => { - Stdlib.assertEqual(String(1), "1"); - }); -}); - -Mocha.describe("Belt.List", () => { - Mocha.test("add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); - Mocha.test("cmp", () => { - Belt_List.cmp({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 5, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 4, - tl: { - hd: 2, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - }); - Mocha.test("cmpByLength", () => { - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); - }); - Mocha.test("concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); - }); - Mocha.test("concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); - Mocha.test("drop", () => { - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("eq", () => { - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("every", () => { - let isBelow10 = value => value < 10; - Belt_List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - Belt_List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - }); - Mocha.test("every2", () => { - Belt_List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Belt_List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("filter", () => { - let isEven = x => x % 2 === 0; - Belt_List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - Belt_List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Belt_Option.isSome); - }); - Mocha.test("filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); - Mocha.test("flatten", () => { - Belt_List.flatten({ - hd: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - tl: { - hd: /* [] */0, - tl: { - hd: { - hd: 3, - tl: /* [] */0 - }, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); - Mocha.test("forEach2", () => { - Belt_List.forEach2({ - hd: "Z", - tl: { - hd: "Y", - tl: /* [] */0 - } - }, { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }, (x, y) => { - console.log(x, y); - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); - }); - Mocha.test("fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 - ]); - }); - Mocha.test("get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); - }); - Mocha.test("getAssoc", () => { - Belt_List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - Belt_List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); - }); - Mocha.test("getBy", () => { - Belt_List.getBy({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - Belt_List.getBy({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); - }); - Mocha.test("getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Stdlib.assertEqual(Belt_List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = Belt_List.getExn(abc, 4); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1046, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("has", () => { - Belt_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - Belt_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4, (a, b) => a === b); - Belt_List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("hasAssoc", () => { - Belt_List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Belt_List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); - }); - Mocha.test("head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("headExn", () => { - Stdlib.assertEqual(Belt_List.headExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), 1); - let exit = 0; - let val; - try { - val = Belt_List.headExn(/* [] */0); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1083, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("keep", () => { - let isEven = x => x % 2 === 0; - Belt_List.keep({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - Belt_List.keep({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Belt_Option.isSome); - }); - Mocha.test("keepMap", () => { - let isEven = x => x % 2 === 0; - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => { - if (isEven(x)) { - return x; - } - - }); - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); - Mocha.test("keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); - Mocha.test("length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("make", () => { - Belt_List.make(3, 1); - }); - Mocha.test("makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => i * i | 0); - }); - Mocha.test("map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); - Mocha.test("mapReverse", () => { - Stdlib.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => x * x | 0), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("mapReverse2", () => { - Belt_List.mapReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a + b | 0); - }); - Mocha.test("mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); - }); - Mocha.test("partition", () => { - Stdlib.assertEqual(Belt_List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2), [ - { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }, - { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - } - ]); - }); - Mocha.test("reduce", () => { - Belt_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Belt_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item) => acc + item | 0); - }); - Mocha.test("reduce2", () => { - Belt_List.reduce2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceReverse", () => { - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 10, (a, b) => a - b | 0); - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, /* [] */0, Belt_List.add); - }); - Mocha.test("reduceReverse2", () => { - Belt_List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceWithIndex", () => { - Belt_List.reduceWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item, index) => (acc + item | 0) + index | 0); - }); - Mocha.test("removeAssoc", () => { - Belt_List.removeAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Belt_List.removeAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); - }); - Mocha.test("reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); - Mocha.test("setAssoc", () => { - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); - }); - Mocha.test("shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("some", () => { - let isAbove100 = value => value > 100; - Belt_List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - Belt_List.some({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isAbove100); - }); - Mocha.test("some2", () => { - Belt_List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Belt_List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("sort", () => { - Belt_List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, (a, b) => a - b | 0); - }); - Mocha.test("splitAt", () => { - Belt_List.splitAt({ - hd: "Hello", - tl: { - hd: "World", - tl: /* [] */0 - } - }, 1); - Belt_List.splitAt({ - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - }, 2); - }); - Mocha.test("tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); - }); - Mocha.test("tailExn", () => { - Stdlib.assertEqual(Belt_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }); - let exit = 0; - let val; - try { - val = Belt_List.tailExn(/* [] */0); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1306, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("take", () => { - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("unzip", () => { - Belt_List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - Belt_List.unzip({ - hd: [ - "H", - "W" - ], - tl: { - hd: [ - "e", - "o" - ], - tl: { - hd: [ - "l", - "r" - ], - tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } - } - } - } - }); - }); - Mocha.test("zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("zipBy", () => { - Belt_List.zipBy({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, (a, b) => (a << 1) + b | 0); - }); -}); - -Mocha.describe("Belt.Map", () => { - Mocha.test("Int", () => {}); - Mocha.test("findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "" - ] - ], IntCmp); - Stdlib.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "" - ] - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_Map.forEach(s0, (k, v) => { - acc.contents = { - hd: [ - k, - v - ], - tl: acc.contents - }; - }); - Primitive_object.equal(acc.contents, { - hd: [ - 4, - "4" - ], - tl: { - hd: [ - 3, - "3" - ], - tl: { - hd: [ - 2, - "2" - ], - tl: { - hd: [ - 1, - "1" - ], - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ]); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2), "2"); - Belt_Map.get(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2) === undefined; - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.has(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp), 1) === true; - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; - }); - Mocha.test("keysToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - 1, - 2, - 3 - ]); - }); - Mocha.test("make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let m = Belt_Map.make(IntCmp); - Belt_Map.set(m, 0, "a"); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp); - Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ - hd: [ - k, - v - ], - tl: acc - })); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.remove(s0, 1); - Belt_Map.remove(s1, 1); - Primitive_object.equal(Belt_Map.keysToArray(s1), [ - 2, - 3 - ]); - }); - Mocha.test("set", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" - ]); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.size(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 2, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)) === 2; - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ]); - }); - Mocha.test("valuesToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.valuesToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - "1", - "2", - "3" - ]); - }); -}); - -Mocha.describe("Belt.Map.Dict", () => { - Mocha.test("findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MapDict.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp.cmp); - Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt.Map.Int", () => { - Mocha.test("findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt.Map.String", () => { - Mocha.test("findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt.MutableSet", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - Belt_MutableSet.add(s0, 1); - Belt_MutableSet.add(s0, 2); - Belt_MutableSet.add(s0, 2); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("copy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - let copied = Belt_MutableSet.copy(s0); - Belt_MutableSet.toArray(copied); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); - }); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Belt_MutableSet.eq(s0, s1); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Belt_MutableSet.every(s0, isEven); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_MutableSet.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Belt_MutableSet.get(s0, 3); - Belt_MutableSet.get(s0, 20); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Belt_MutableSet.has(set, 3); - Belt_MutableSet.has(set, 1); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_MutableSet.intersect(s0, s1); - Belt_MutableSet.toArray(intersect); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_MutableSet.fromArray([], IntCmp); - let notEmpty = Belt_MutableSet.fromArray([1], IntCmp); - Belt_MutableSet.isEmpty(empty); - Belt_MutableSet.isEmpty(notEmpty); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_MutableSet.keep(s0, isEven); - Belt_MutableSet.toArray(s1); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.maxUndefined(s0); - Belt_MutableSet.maxUndefined(s1); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.maximum(s0); - Belt_MutableSet.maximum(s1); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.make(IntCmp); - Belt_MutableSet.mergeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.minUndefined(s0); - Belt_MutableSet.minUndefined(s1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.minimum(s0); - Belt_MutableSet.minimum(s1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_MutableSet.partition(s0, isOdd); - Belt_MutableSet.toArray(match[0]); - Belt_MutableSet.toArray(match[1]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp); - Belt_MutableSet.remove(s0, 1); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.size(s0); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp); - Belt_MutableSet.some(s0, isOdd); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_MutableSet.split(s0, 3); - let match$1 = match[0]; - Belt_MutableSet.toArray(match$1[0]); - Belt_MutableSet.toArray(match$1[1]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let s2 = Belt_MutableSet.intersect(s0, s1); - Belt_MutableSet.subset(s2, s0); - Belt_MutableSet.subset(s2, s1); - Belt_MutableSet.subset(s1, s0); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.toList(s0); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let union = Belt_MutableSet.union(s0, s1); - Belt_MutableSet.toArray(union); - }); -}); - -Mocha.describe("Belt.Option", () => { - Mocha.test("cmp", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Belt_Option.cmp(3, 15, clockCompare); - Belt_Option.cmp(3, 14, clockCompare); - Belt_Option.cmp(2, 15, clockCompare); - Belt_Option.cmp(undefined, 15, clockCompare); - Belt_Option.cmp(14, undefined, clockCompare); - Belt_Option.cmp(undefined, undefined, clockCompare); - }); - Mocha.test("eq", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Belt_Option.eq(3, 15, clockEqual); - Belt_Option.eq(3, undefined, clockEqual); - Belt_Option.eq(undefined, 3, clockEqual); - Belt_Option.eq(undefined, undefined, clockEqual); - }); - Mocha.test("flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Belt_Option.flatMap(2, addIfAboveOne); - Belt_Option.flatMap(-4, addIfAboveOne); - Belt_Option.flatMap(undefined, addIfAboveOne); - }); - Mocha.test("forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Belt_Option.getExn(3), 3); - let exit = 0; - let val; - try { - val = Belt_Option.getExn(undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 2073, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getWithDefault", () => { - Belt_Option.getWithDefault(undefined, "Banana"); - Belt_Option.getWithDefault("Apple", "Banana"); - let greet = firstName => "Greetings " + Belt_Option.getWithDefault(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); - }); - Mocha.test("isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); - }); - Mocha.test("isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); - }); - Mocha.test("keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); - }); - Mocha.test("map", () => { - Belt_Option.map(3, x => x * x | 0); - Belt_Option.map(undefined, x => x * x | 0); - }); - Mocha.test("mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); - }); - Mocha.test("orElse", () => { - Primitive_object.equal(Belt_Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Belt_Option.orElse(undefined, 1066), 1066); - Belt_Option.orElse(undefined, undefined) === undefined; - }); -}); - -Mocha.describe("Belt.Range", () => { - Mocha.test("every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); - Mocha.test("everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); - Mocha.test("forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); - Mocha.test("some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); - Mocha.test("someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt.Result", () => { - Mocha.test("cmp", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Belt_Result.cmp({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Belt_Result.cmp({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Belt_Result.cmp({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Belt_Result.cmp({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Belt_Result.cmp({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; - }); - Mocha.test("eq", () => { - let good1 = { - TAG: "Ok", - _0: 42 - }; - let good2 = { - TAG: "Ok", - _0: 32 - }; - let bad1 = { - TAG: "Error", - _0: "invalid" - }; - let bad2 = { - TAG: "Error", - _0: "really invalid" - }; - let mod10equal = (a, b) => a % 10 === b % 10; - Belt_Result.eq(good1, good2, mod10equal) === true; - Belt_Result.eq(good1, bad1, mod10equal) === false; - Belt_Result.eq(bad2, good2, mod10equal) === false; - Belt_Result.eq(bad1, bad2, mod10equal) === true; - }); - Mocha.test("flatMap", () => { - let recip = x => { - if (x !== 0.0) { - return { - TAG: "Ok", - _0: 1.0 / x - }; - } else { - return { - TAG: "Error", - _0: "Divide by zero" - }; - } - }; - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 - }); - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" - }); - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" - }); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Belt_Result.getExn({ - TAG: "Ok", - _0: 42 - }), 42); - let exit = 0; - let val; - try { - val = Belt_Result.getExn({ - TAG: "Error", - _0: "Invalid data" - }); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 2263, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); - Mocha.test("map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Belt_Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Belt_Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" - }); - }); - Mocha.test("mapWithDefault", () => { - Belt_Result.mapWithDefault({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Belt_Result.mapWithDefault({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; - }); -}); - -Mocha.describe("Belt.Set", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.add(s0, 1); - let s2 = Belt_Set.add(s1, 2); - let s3 = Belt_Set.add(s2, 2); - Stdlib.assertEqual(Belt_Set.toArray(s0), []); - Stdlib.assertEqual(Belt_Set.toArray(s1), [1]); - Stdlib.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Stdlib.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Stdlib.assertEqual(s2, s3); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); - }); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.eq(s0, s1), true); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.every(s0, isEven), true); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_Set.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - Stdlib.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.get(s0, 3), 3); - Stdlib.assertEqual(Belt_Set.get(s0, 20), undefined); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.has(set, 3), false); - Stdlib.assertEqual(Belt_Set.has(set, 1), true); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_Set.intersect(s0, s1); - Stdlib.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, - 5 - ]); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_Set.fromArray([], IntCmp); - let notEmpty = Belt_Set.fromArray([1], IntCmp); - Stdlib.assertEqual(Belt_Set.isEmpty(empty), true); - Stdlib.assertEqual(Belt_Set.isEmpty(notEmpty), false); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Stdlib.assertEqual(Belt_Set.toArray(s1), [ - 2, - 4 - ]); - }); - Mocha.test("make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Stdlib.assertEqual(Belt_Set.isEmpty(set), true); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.maximum(s0), undefined); - Stdlib.assertEqual(Belt_Set.maximum(s1), 5); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - let newSet = Belt_Set.mergeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Stdlib.assertEqual(Belt_Set.toArray(newSet), [ - 1, - 2, - 3, - 4, - 5 - ]); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.minimum(s0), undefined); - Stdlib.assertEqual(Belt_Set.minimum(s1), 1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.partition(s0, isOdd); - Stdlib.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Stdlib.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.remove(s0, 1); - let s2 = Belt_Set.remove(s1, 3); - let s3 = Belt_Set.remove(s2, 3); - Stdlib.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Stdlib.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Stdlib.assertEqual(s2, s3); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - let newSet = Belt_Set.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Stdlib.assertEqual(Belt_Set.toArray(newSet), []); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.size(s0), 4); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.some(s0, isOdd), true); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.split(s0, 3); - let match$1 = match[0]; - Stdlib.assertEqual(match[1], true); - Stdlib.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Stdlib.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let s2 = Belt_Set.intersect(s0, s1); - Stdlib.assertEqual(Belt_Set.subset(s2, s0), true); - Stdlib.assertEqual(Belt_Set.subset(s2, s1), true); - Stdlib.assertEqual(Belt_Set.subset(s1, s0), false); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 - ]); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let union = Belt_Set.union(s0, s1); - Stdlib.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, - 3, - 4, - 5, - 6 - ]); - }); -}); - -Mocha.describe("Belt.Set.Dict", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); - let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); - let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); - Belt_SetDict.toArray(undefined); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Belt_SetDict.toArray(s3); - Primitive_object.equal(s2, s3); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); - let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); - Belt_SetDict.toArray(diff1); - Belt_SetDict.toArray(diff2); - }); - Mocha.test("empty", () => {}); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.eq(s0, s1, IntCmp.cmp); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let acc = { - contents: /* [] */0 - }; - Belt_SetDict.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(intersect); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.keep(s0, isEven); - Belt_SetDict.toArray(s1); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maximum(undefined); - Belt_SetDict.maximum(s1); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let newSet = Belt_SetDict.mergeMany(undefined, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minimum(undefined); - Belt_SetDict.minimum(s1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.partition(s0, isOdd); - Belt_SetDict.toArray(match[0]); - Belt_SetDict.toArray(match[1]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); - let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); - let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Primitive_object.equal(s2, s3); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - let newSet = Belt_SetDict.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - Belt_SetDict.size(s0); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.some(s0, isOdd); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); - let match$1 = match[0]; - Belt_SetDict.toArray(match$1[0]); - Belt_SetDict.toArray(match$1[1]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.subset(s2, s0, IntCmp.cmp); - Belt_SetDict.subset(s2, s1, IntCmp.cmp); - Belt_SetDict.subset(s1, s0, IntCmp.cmp); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(union); - }); -}); - -Mocha.describe("Belt.SortArray", () => { - Mocha.test("binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ - 1, - 2, - 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ - 1, - 3, - 5, - 7 - ], 4, Primitive_int.compare)) === 2; - }); - Mocha.test("strictlySortedLength", () => { - Belt_SortArray.strictlySortedLength([ - 1, - 2, - 3, - 4, - 3 - ], (x, y) => x < y) === 4; - Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; - Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; - Belt_SortArray.strictlySortedLength([ - 4, - 3, - 2, - 1 - ], (x, y) => x < y) === -4; - }); -}); - -Mocha.describe("Belt_Array", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt_Float", () => { - Mocha.test("*", () => { - Stdlib.assertEqual(2.0 * 2.0, 4.0); - }); - Mocha.test("+", () => { - Stdlib.assertEqual(2.0 + 2.0, 4.0); - }); - Mocha.test("-", () => { - Stdlib.assertEqual(2.0 - 1.0, 1.0); - }); - Mocha.test("/", () => { - Stdlib.assertEqual(4.0 / 2.0, 2.0); - }); - Mocha.test("fromInt", () => { - console.log(1 === 1.0); - }); - Mocha.test("fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); - }); - Mocha.test("toInt", () => { - console.log(true); - }); - Mocha.test("toString", () => { - console.log(String(1.0) === "1.0"); - }); -}); - -Mocha.describe("Belt_HashMap", () => { - Mocha.test("clear", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.fromArray([[ - 1, - "1" - ]], IntHash); - Belt_HashMap.clear(hMap); - Belt_HashMap.isEmpty(hMap) === true; - }); - Mocha.test("copy", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntHash); - let s1 = Belt_HashMap.copy(s0); - Belt_HashMap.set(s0, 2, "3"); - Primitive_object.notequal(Belt_HashMap.get(s0, 2), Belt_HashMap.get(s1, 2)); - }); - Mocha.test("forEach", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.forEach(s0, (key, value) => { - console.log(key, value); - }); - }); - Mocha.test("fromArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ], IntHash); - Primitive_object.equal(Belt_HashMap.toArray(s0), [ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ]); - }); - Mocha.test("get", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Primitive_object.equal(Belt_HashMap.get(s0, 1), "value1"); - Belt_HashMap.get(s0, 2) === undefined; - }); - Mocha.test("getBucketHistogram", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.getBucketHistogram(hMap); - }); - Mocha.test("has", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.has(s0, 1) === true; - Belt_HashMap.has(s0, 2) === false; - }); - Mocha.test("isEmpty", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - Belt_HashMap.isEmpty(Belt_HashMap.fromArray([[ - 1, - "1" - ]], IntHash)) === false; - }); - Mocha.test("keepMapInPlace", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Belt_HashMap.keepMapInPlace(s0, (key, value) => { - if (key === 1) { - return; - } else { - return value; - } - }); - }); - Mocha.test("keysToArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.keysToArray(s0), [ - 1, - 2 - ]); - }); - Mocha.test("logStats", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.logStats(hMap); - }); - Mocha.test("make", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 0, "a"); - }); - Mocha.test("mergeMany", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.mergeMany(hMap, [ - [ - 1, - "1" - ], - [ - 2, - "2" - ] - ]); - }); - Mocha.test("reduce", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Stdlib.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); - }); - Mocha.test("remove", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.remove(s0, 1); - Belt_HashMap.has(s0, 1) === false; - }); - Mocha.test("set", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntHash); - Belt_HashMap.set(s0, 2, "3"); - Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ - "1", - "3", - "3" - ]); - }); - Mocha.test("size", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Belt_HashMap.size(s0) === 2; - }); - Mocha.test("toArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.toArray(s0), [ - [ - 1, - "value1" - ], - [ - 2, - "value2" - ] - ]); - }); - Mocha.test("valuesToArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq - }); - let s0 = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(s0, 1, "value1"); - Belt_HashMap.set(s0, 2, "value2"); - Primitive_object.equal(Belt_HashMap.valuesToArray(s0), [ - "value1", - "value2" - ]); - }); -}); - -Mocha.describe("Belt_Int", () => { - Mocha.test("*", () => { - Stdlib.assertEqual(4, 4); - }); - Mocha.test("+", () => { - Stdlib.assertEqual(4, 4); - }); - Mocha.test("-", () => { - Stdlib.assertEqual(1, 1); - }); - Mocha.test("/", () => { - Stdlib.assertEqual(2, 2); - }); - Mocha.test("fromFloat", () => { - Stdlib.assertEqual(1, 1); - }); - Mocha.test("fromString", () => { - Stdlib.assertEqual(Belt_Int.fromString("1"), 1); - }); - Mocha.test("toFloat", () => { - Stdlib.assertEqual(1, 1.0); - }); - Mocha.test("toString", () => { - Stdlib.assertEqual(String(1), "1"); - }); -}); - -Mocha.describe("Belt_List", () => { - Mocha.test("add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); - Mocha.test("cmp", () => { - Belt_List.cmp({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 5, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 4, - tl: { - hd: 2, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - }); - Mocha.test("cmpByLength", () => { - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - Belt_List.cmpByLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); - }); - Mocha.test("concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); - }); - Mocha.test("concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); - Mocha.test("drop", () => { - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("eq", () => { - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("every", () => { - let isBelow10 = value => value < 10; - Belt_List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - Belt_List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - }); - Mocha.test("every2", () => { - Belt_List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Belt_List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("filter", () => { - let isEven = x => x % 2 === 0; - Belt_List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - Belt_List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Belt_Option.isSome); - }); - Mocha.test("filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); - Mocha.test("flatten", () => { - Belt_List.flatten({ - hd: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - tl: { - hd: /* [] */0, - tl: { - hd: { - hd: 3, - tl: /* [] */0 - }, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); - Mocha.test("forEach2", () => { - Belt_List.forEach2({ - hd: "Z", - tl: { - hd: "Y", - tl: /* [] */0 - } - }, { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }, (x, y) => { - console.log(x, y); - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); - }); - Mocha.test("fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 - ]); - }); - Mocha.test("get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); - }); - Mocha.test("getAssoc", () => { - Belt_List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - Belt_List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); - }); - Mocha.test("getBy", () => { - Belt_List.getBy({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - Belt_List.getBy({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); - }); - Mocha.test("getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Stdlib.assertEqual(Belt_List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = Belt_List.getExn(abc, 4); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 4127, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("has", () => { - Belt_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - Belt_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4, (a, b) => a === b); - Belt_List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("hasAssoc", () => { - Belt_List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Belt_List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); - }); - Mocha.test("head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("headExn", () => { - Stdlib.assertEqual(Belt_List.headExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), 1); - let exit = 0; - let val; - try { - val = Belt_List.headExn(/* [] */0); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 4164, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("keep", () => { - let isEven = x => x % 2 === 0; - Belt_List.keep({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - Belt_List.keep({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Belt_Option.isSome); - }); - Mocha.test("keepMap", () => { - let isEven = x => x % 2 === 0; - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => { - if (isEven(x)) { - return x; - } - - }); - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); - Mocha.test("keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); - Mocha.test("length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("make", () => { - Belt_List.make(3, 1); - }); - Mocha.test("makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => i * i | 0); - }); - Mocha.test("map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); - Mocha.test("mapReverse", () => { - Stdlib.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => x * x | 0), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("mapReverse2", () => { - Belt_List.mapReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a + b | 0); - }); - Mocha.test("mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); - }); - Mocha.test("partition", () => { - Stdlib.assertEqual(Belt_List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2), [ - { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }, - { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - } - ]); - }); - Mocha.test("reduce", () => { - Belt_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Belt_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item) => acc + item | 0); - }); - Mocha.test("reduce2", () => { - Belt_List.reduce2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceReverse", () => { - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 10, (a, b) => a - b | 0); - Belt_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, /* [] */0, Belt_List.add); - }); - Mocha.test("reduceReverse2", () => { - Belt_List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceWithIndex", () => { - Belt_List.reduceWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item, index) => (acc + item | 0) + index | 0); - }); - Mocha.test("removeAssoc", () => { - Belt_List.removeAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Belt_List.removeAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); - }); - Mocha.test("reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); - Mocha.test("setAssoc", () => { - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); - }); - Mocha.test("shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("some", () => { - let isAbove100 = value => value > 100; - Belt_List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - Belt_List.some({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isAbove100); - }); - Mocha.test("some2", () => { - Belt_List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Belt_List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Belt_List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("sort", () => { - Belt_List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, (a, b) => a - b | 0); - }); - Mocha.test("splitAt", () => { - Belt_List.splitAt({ - hd: "Hello", - tl: { - hd: "World", - tl: /* [] */0 - } - }, 1); - Belt_List.splitAt({ - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - }, 2); - }); - Mocha.test("tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); - }); - Mocha.test("tailExn", () => { - Stdlib.assertEqual(Belt_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }); - let exit = 0; - let val; - try { - val = Belt_List.tailExn(/* [] */0); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 4387, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("take", () => { - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("unzip", () => { - Belt_List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - Belt_List.unzip({ - hd: [ - "H", - "W" - ], - tl: { - hd: [ - "e", - "o" - ], - tl: { - hd: [ - "l", - "r" - ], - tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } - } - } - } - }); - }); - Mocha.test("zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("zipBy", () => { - Belt_List.zipBy({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, (a, b) => (a << 1) + b | 0); - }); -}); - -Mocha.describe("Belt_Map", () => { - Mocha.test("Int", () => {}); - Mocha.test("findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "" - ] - ], IntCmp); - Stdlib.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "" - ] - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_Map.forEach(s0, (k, v) => { - acc.contents = { - hd: [ - k, - v - ], - tl: acc.contents - }; - }); - Primitive_object.equal(acc.contents, { - hd: [ - 4, - "4" - ], - tl: { - hd: [ - 3, - "3" - ], - tl: { - hd: [ - 2, - "2" - ], - tl: { - hd: [ - 1, - "1" - ], - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ]); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2), "2"); - Belt_Map.get(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2) === undefined; - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.has(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp), 1) === true; - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; - }); - Mocha.test("keysToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - 1, - 2, - 3 - ]); - }); - Mocha.test("make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let m = Belt_Map.make(IntCmp); - Belt_Map.set(m, 0, "a"); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp); - Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ - hd: [ - k, - v - ], - tl: acc - })); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.remove(s0, 1); - Belt_Map.remove(s1, 1); - Primitive_object.equal(Belt_Map.keysToArray(s1), [ - 2, - 3 - ]); - }); - Mocha.test("set", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" - ]); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.size(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 2, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)) === 2; - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ]); - }); - Mocha.test("valuesToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.valuesToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - "1", - "2", - "3" - ]); - }); -}); - -Mocha.describe("Belt_Map.Dict", () => { - Mocha.test("findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MapDict.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp.cmp); - Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt_Map.Int", () => { - Mocha.test("findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt_Map.String", () => { - Mocha.test("findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_MapDict", () => { - Mocha.test("findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MapDict.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp.cmp); - Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt_MapInt", () => { - Mocha.test("findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt_MapString", () => { - Mocha.test("findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Stdlib.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_MutableSet", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - Belt_MutableSet.add(s0, 1); - Belt_MutableSet.add(s0, 2); - Belt_MutableSet.add(s0, 2); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("copy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - let copied = Belt_MutableSet.copy(s0); - Belt_MutableSet.toArray(copied); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); - }); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Belt_MutableSet.eq(s0, s1); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Belt_MutableSet.every(s0, isEven); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_MutableSet.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Belt_MutableSet.get(s0, 3); - Belt_MutableSet.get(s0, 20); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Belt_MutableSet.has(set, 3); - Belt_MutableSet.has(set, 1); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_MutableSet.intersect(s0, s1); - Belt_MutableSet.toArray(intersect); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_MutableSet.fromArray([], IntCmp); - let notEmpty = Belt_MutableSet.fromArray([1], IntCmp); - Belt_MutableSet.isEmpty(empty); - Belt_MutableSet.isEmpty(notEmpty); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_MutableSet.keep(s0, isEven); - Belt_MutableSet.toArray(s1); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.maxUndefined(s0); - Belt_MutableSet.maxUndefined(s1); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.maximum(s0); - Belt_MutableSet.maximum(s1); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.make(IntCmp); - Belt_MutableSet.mergeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.minUndefined(s0); - Belt_MutableSet.minUndefined(s1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.minimum(s0); - Belt_MutableSet.minimum(s1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_MutableSet.partition(s0, isOdd); - Belt_MutableSet.toArray(match[0]); - Belt_MutableSet.toArray(match[1]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp); - Belt_MutableSet.remove(s0, 1); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.size(s0); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp); - Belt_MutableSet.some(s0, isOdd); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_MutableSet.split(s0, 3); - let match$1 = match[0]; - Belt_MutableSet.toArray(match$1[0]); - Belt_MutableSet.toArray(match$1[1]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let s2 = Belt_MutableSet.intersect(s0, s1); - Belt_MutableSet.subset(s2, s0); - Belt_MutableSet.subset(s2, s1); - Belt_MutableSet.subset(s1, s0); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.toArray(s0); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.toList(s0); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let union = Belt_MutableSet.union(s0, s1); - Belt_MutableSet.toArray(union); - }); -}); - -Mocha.describe("Belt_Option", () => { - Mocha.test("cmp", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Belt_Option.cmp(3, 15, clockCompare); - Belt_Option.cmp(3, 14, clockCompare); - Belt_Option.cmp(2, 15, clockCompare); - Belt_Option.cmp(undefined, 15, clockCompare); - Belt_Option.cmp(14, undefined, clockCompare); - Belt_Option.cmp(undefined, undefined, clockCompare); - }); - Mocha.test("eq", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Belt_Option.eq(3, 15, clockEqual); - Belt_Option.eq(3, undefined, clockEqual); - Belt_Option.eq(undefined, 3, clockEqual); - Belt_Option.eq(undefined, undefined, clockEqual); - }); - Mocha.test("flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Belt_Option.flatMap(2, addIfAboveOne); - Belt_Option.flatMap(-4, addIfAboveOne); - Belt_Option.flatMap(undefined, addIfAboveOne); - }); - Mocha.test("forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Belt_Option.getExn(3), 3); - let exit = 0; - let val; - try { - val = Belt_Option.getExn(undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 5193, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getWithDefault", () => { - Belt_Option.getWithDefault(undefined, "Banana"); - Belt_Option.getWithDefault("Apple", "Banana"); - let greet = firstName => "Greetings " + Belt_Option.getWithDefault(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); - }); - Mocha.test("isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); - }); - Mocha.test("isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); - }); - Mocha.test("keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); - }); - Mocha.test("map", () => { - Belt_Option.map(3, x => x * x | 0); - Belt_Option.map(undefined, x => x * x | 0); - }); - Mocha.test("mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); - }); - Mocha.test("orElse", () => { - Primitive_object.equal(Belt_Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Belt_Option.orElse(undefined, 1066), 1066); - Belt_Option.orElse(undefined, undefined) === undefined; - }); -}); - -Mocha.describe("Belt_Range", () => { - Mocha.test("every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); - Mocha.test("everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); - Mocha.test("forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); - Mocha.test("some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); - Mocha.test("someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Result", () => { - Mocha.test("cmp", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Belt_Result.cmp({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Belt_Result.cmp({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Belt_Result.cmp({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Belt_Result.cmp({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Belt_Result.cmp({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; - }); - Mocha.test("eq", () => { - let good1 = { - TAG: "Ok", - _0: 42 - }; - let good2 = { - TAG: "Ok", - _0: 32 - }; - let bad1 = { - TAG: "Error", - _0: "invalid" - }; - let bad2 = { - TAG: "Error", - _0: "really invalid" - }; - let mod10equal = (a, b) => a % 10 === b % 10; - Belt_Result.eq(good1, good2, mod10equal) === true; - Belt_Result.eq(good1, bad1, mod10equal) === false; - Belt_Result.eq(bad2, good2, mod10equal) === false; - Belt_Result.eq(bad1, bad2, mod10equal) === true; - }); - Mocha.test("flatMap", () => { - let recip = x => { - if (x !== 0.0) { - return { - TAG: "Ok", - _0: 1.0 / x - }; - } else { - return { - TAG: "Error", - _0: "Divide by zero" - }; - } - }; - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 - }); - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" - }); - Primitive_object.equal(Belt_Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" - }); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Belt_Result.getExn({ - TAG: "Ok", - _0: 42 - }), 42); - let exit = 0; - let val; - try { - val = Belt_Result.getExn({ - TAG: "Error", - _0: "Invalid data" - }); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 5383, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); - Mocha.test("map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Belt_Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Belt_Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" - }); - }); - Mocha.test("mapWithDefault", () => { - Belt_Result.mapWithDefault({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Belt_Result.mapWithDefault({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; - }); -}); - -Mocha.describe("Belt_Set", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.add(s0, 1); - let s2 = Belt_Set.add(s1, 2); - let s3 = Belt_Set.add(s2, 2); - Stdlib.assertEqual(Belt_Set.toArray(s0), []); - Stdlib.assertEqual(Belt_Set.toArray(s1), [1]); - Stdlib.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Stdlib.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Stdlib.assertEqual(s2, s3); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Stdlib.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); - }); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.eq(s0, s1), true); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.every(s0, isEven), true); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_Set.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - Stdlib.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.get(s0, 3), 3); - Stdlib.assertEqual(Belt_Set.get(s0, 20), undefined); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.has(set, 3), false); - Stdlib.assertEqual(Belt_Set.has(set, 1), true); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_Set.intersect(s0, s1); - Stdlib.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, - 5 - ]); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_Set.fromArray([], IntCmp); - let notEmpty = Belt_Set.fromArray([1], IntCmp); - Stdlib.assertEqual(Belt_Set.isEmpty(empty), true); - Stdlib.assertEqual(Belt_Set.isEmpty(notEmpty), false); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Stdlib.assertEqual(Belt_Set.toArray(s1), [ - 2, - 4 - ]); - }); - Mocha.test("make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Stdlib.assertEqual(Belt_Set.isEmpty(set), true); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.maximum(s0), undefined); - Stdlib.assertEqual(Belt_Set.maximum(s1), 5); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - let newSet = Belt_Set.mergeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Stdlib.assertEqual(Belt_Set.toArray(newSet), [ - 1, - 2, - 3, - 4, - 5 - ]); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Stdlib.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.minimum(s0), undefined); - Stdlib.assertEqual(Belt_Set.minimum(s1), 1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.partition(s0, isOdd); - Stdlib.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Stdlib.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.remove(s0, 1); - let s2 = Belt_Set.remove(s1, 3); - let s3 = Belt_Set.remove(s2, 3); - Stdlib.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Stdlib.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Stdlib.assertEqual(s2, s3); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - let newSet = Belt_Set.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Stdlib.assertEqual(Belt_Set.toArray(newSet), []); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.size(s0), 4); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.some(s0, isOdd), true); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.split(s0, 3); - let match$1 = match[0]; - Stdlib.assertEqual(match[1], true); - Stdlib.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Stdlib.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let s2 = Belt_Set.intersect(s0, s1); - Stdlib.assertEqual(Belt_Set.subset(s2, s0), true); - Stdlib.assertEqual(Belt_Set.subset(s2, s1), true); - Stdlib.assertEqual(Belt_Set.subset(s1, s0), false); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 - ]); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Stdlib.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - let union = Belt_Set.union(s0, s1); - Stdlib.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, - 3, - 4, - 5, - 6 - ]); - }); -}); - -Mocha.describe("Belt_Set.Dict", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); - let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); - let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); - Belt_SetDict.toArray(undefined); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Belt_SetDict.toArray(s3); - Primitive_object.equal(s2, s3); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); - let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); - Belt_SetDict.toArray(diff1); - Belt_SetDict.toArray(diff2); - }); - Mocha.test("empty", () => {}); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.eq(s0, s1, IntCmp.cmp); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let acc = { - contents: /* [] */0 - }; - Belt_SetDict.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(intersect); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.keep(s0, isEven); - Belt_SetDict.toArray(s1); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maximum(undefined); - Belt_SetDict.maximum(s1); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let newSet = Belt_SetDict.mergeMany(undefined, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minimum(undefined); - Belt_SetDict.minimum(s1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.partition(s0, isOdd); - Belt_SetDict.toArray(match[0]); - Belt_SetDict.toArray(match[1]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); - let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); - let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Primitive_object.equal(s2, s3); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - let newSet = Belt_SetDict.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - Belt_SetDict.size(s0); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.some(s0, isOdd); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); - let match$1 = match[0]; - Belt_SetDict.toArray(match$1[0]); - Belt_SetDict.toArray(match$1[1]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.subset(s2, s0, IntCmp.cmp); - Belt_SetDict.subset(s2, s1, IntCmp.cmp); - Belt_SetDict.subset(s1, s0, IntCmp.cmp); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(union); - }); -}); - -Mocha.describe("Belt_SetDict", () => { - Mocha.test("add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.add(undefined, 1, IntCmp.cmp); - let s2 = Belt_SetDict.add(s1, 2, IntCmp.cmp); - let s3 = Belt_SetDict.add(s2, 2, IntCmp.cmp); - Belt_SetDict.toArray(undefined); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Belt_SetDict.toArray(s3); - Primitive_object.equal(s2, s3); - }); - Mocha.test("diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let diff1 = Belt_SetDict.diff(s0, s1, IntCmp.cmp); - let diff2 = Belt_SetDict.diff(s1, s0, IntCmp.cmp); - Belt_SetDict.toArray(diff1); - Belt_SetDict.toArray(diff2); - }); - Mocha.test("empty", () => {}); - Mocha.test("eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.eq(s0, s1, IntCmp.cmp); - }); - Mocha.test("every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); - }); - Mocha.test("forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let acc = { - contents: /* [] */0 - }; - Belt_SetDict.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - }); - Mocha.test("fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); - }); - Mocha.test("has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); - }); - Mocha.test("intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(intersect); - }); - Mocha.test("isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); - }); - Mocha.test("keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.keep(s0, isEven); - Belt_SetDict.toArray(s1); - }); - Mocha.test("maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); - }); - Mocha.test("maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maximum(undefined); - Belt_SetDict.maximum(s1); - }); - Mocha.test("mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let newSet = Belt_SetDict.mergeMany(undefined, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); - }); - Mocha.test("minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minimum(undefined); - Belt_SetDict.minimum(s1); - }); - Mocha.test("partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.partition(s0, isOdd); - Belt_SetDict.toArray(match[0]); - Belt_SetDict.toArray(match[1]); - }); - Mocha.test("reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); - }); - Mocha.test("remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 2, - 3, - 1, - 4, - 5 - ], IntCmp.cmp); - let s1 = Belt_SetDict.remove(s0, 1, IntCmp.cmp); - let s2 = Belt_SetDict.remove(s1, 3, IntCmp.cmp); - let s3 = Belt_SetDict.remove(s2, 3, IntCmp.cmp); - Belt_SetDict.toArray(s1); - Belt_SetDict.toArray(s2); - Primitive_object.equal(s2, s3); - }); - Mocha.test("removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - let newSet = Belt_SetDict.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); - }); - Mocha.test("size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp.cmp); - Belt_SetDict.size(s0); - }); - Mocha.test("some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.some(s0, isOdd); - }); - Mocha.test("split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.split(s0, 3, IntCmp.cmp); - let match$1 = match[0]; - Belt_SetDict.toArray(match$1[0]); - Belt_SetDict.toArray(match$1[1]); - }); - Mocha.test("subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let s2 = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.subset(s2, s0, IntCmp.cmp); - Belt_SetDict.subset(s2, s1, IntCmp.cmp); - Belt_SetDict.subset(s1, s0, IntCmp.cmp); - }); - Mocha.test("toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); - }); - Mocha.test("toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); - }); - Mocha.test("union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp.cmp); - let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(union); - }); -}); - -Mocha.describe("Belt_SortArray", () => { - Mocha.test("binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ - 1, - 2, - 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ - 1, - 3, - 5, - 7 - ], 4, Primitive_int.compare)) === 2; - }); - Mocha.test("strictlySortedLength", () => { - Belt_SortArray.strictlySortedLength([ - 1, - 2, - 3, - 4, - 3 - ], (x, y) => x < y) === 4; - Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; - Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; - Belt_SortArray.strictlySortedLength([ - 4, - 3, - 2, - 1 - ], (x, y) => x < y) === -4; - }); -}); - -Mocha.describe("Belt_internalMapInt.A", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.S", () => { - Mocha.test("binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ - 1, - 2, - 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ - 1, - 3, - 5, - 7 - ], 4, Primitive_int.compare)) === 2; - }); - Mocha.test("strictlySortedLength", () => { - Belt_SortArray.strictlySortedLength([ - 1, - 2, - 3, - 4, - 3 - ], (x, y) => x < y) === 4; - Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; - Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; - Belt_SortArray.strictlySortedLength([ - 4, - 3, - 2, - 1 - ], (x, y) => x < y) === -4; - }); -}); - -Mocha.describe("Belt_internalMapString.A", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.S", () => { - Mocha.test("binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ - 1, - 2, - 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ - 1, - 3, - 5, - 7 - ], 4, Primitive_int.compare)) === 2; - }); - Mocha.test("strictlySortedLength", () => { - Belt_SortArray.strictlySortedLength([ - 1, - 2, - 3, - 4, - 3 - ], (x, y) => x < y) === 4; - Belt_SortArray.strictlySortedLength([], Primitive_object.lessthan) === 0; - Belt_SortArray.strictlySortedLength([1], (x, y) => x < y) === 1; - Belt_SortArray.strictlySortedLength([ - 4, - 3, - 2, - 1 - ], (x, y) => x < y) === -4; - }); -}); - -Mocha.describe("Belt_internalSetInt.A", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A", () => { - Mocha.test("blit", () => { - let v1 = [ - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17 - ]; - let v2 = [ - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27 - ]; - Belt_Array.blit(v1, 4, v2, 2, 3); - Primitive_object.equal(v2, [ - 20, - 21, - 14, - 15, - 16, - 25, - 26, - 27 - ]); - Belt_Array.blit(v1, 4, v1, 2, 3); - Primitive_object.equal(v1, [ - 10, - 11, - 14, - 15, - 16, - 15, - 16, - 17 - ]); - }); - Mocha.test("cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); - Mocha.test("concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); - }); - Mocha.test("concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); - Mocha.test("eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); - Mocha.test("every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); - Mocha.test("every2", () => { - Belt_Array.every2([ - 1, - 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); - Mocha.test("fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); - Mocha.test("forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); - Mocha.test("forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ - "a", - "b", - "c" - ], (i, x) => { - console.log("Item " + String(i) + " is " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEachWithIndex([ - 10, - 11, - 12, - 13 - ], (i, x) => { - total.contents = (total.contents + x | 0) + i | 0; - }); - }); - Mocha.test("get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ - "a", - "b", - "c" - ], -1) === undefined; - }); - Mocha.test("getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); - Mocha.test("joinWith", () => { - Belt_Array.joinWith([ - 0, - 1 - ], ", ", prim => prim.toString()) === "0, 1"; - Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; - Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; - }); - Mocha.test("keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); - Mocha.test("keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); - Mocha.test("length", () => {}); - Mocha.test("makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => i * i | 0), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); - Mocha.test("makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); - Mocha.test("makeUninitializedUnsafe", () => { - let arr = new Array(5); - console.log(Belt_Array.getExn(arr, 0)); - Belt_Array.setExn(arr, 0, "example"); - console.log(Belt_Array.getExn(arr, 0) === "example"); - }); - Mocha.test("map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); - Mocha.test("mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); - Mocha.test("partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, - 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); - Mocha.test("rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 - ]); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, 1), []); - Primitive_object.equal(Belt_Array.rangeBy(33, 0, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 12, -1), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 0), []); - Primitive_object.equal(Belt_Array.rangeBy(3, 3, 1), [3]); - }); - Mocha.test("reduce", () => { - Belt_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; - }); - Mocha.test("reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); - Mocha.test("reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); - Mocha.test("reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); - Mocha.test("reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); - Mocha.test("slice", () => { - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2, 3), [ - 12, - 13, - 14 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4, 3), [ - 13, - 14, - 15 - ]); - Primitive_object.equal(Belt_Array.slice([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 - ]); - }); - Mocha.test("sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 - ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 - ]); - }); - Mocha.test("some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); - Mocha.test("some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ - 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 - ], [ - 1, - 4 - ], (x, y) => x > y) === true; - }); - Mocha.test("truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); - Mocha.test("unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ] - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - Primitive_object.equal(Belt_Array.unzip([ - [ - 1, - 2 - ], - [ - 3, - 4 - ], - [ - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - [ - 1, - 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 - ] - ]); - }); - Mocha.test("zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); - Mocha.test("zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Pervasives", () => { - Mocha.test("throw", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); - }); -}); - -Mocha.describe("Stdlib", () => { - Mocha.test("Option", () => {}); - Mocha.test("assertEqual", () => { - Stdlib.assertEqual(Stdlib_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }), { - hd: 2, - tl: /* [] */0 - }); - }); - Mocha.test("clearInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints in 100 ms"); - }, 100); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); - Mocha.test("clearTimeout", () => { - let timeoutId = setTimeout(() => { - console.log("This prints in 2 seconds."); - }, 2000); - clearTimeout(timeoutId); - }); - Mocha.test("decodeURI", () => { - console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); - }); - Mocha.test("decodeURIComponent", () => { - console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); - }); - Mocha.test("encodeURI", () => { - console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); - }); - Mocha.test("encodeURIComponent", () => { - console.log(encodeURIComponent("array=[someValue]")); - }); - Mocha.test("import", () => {}); - Mocha.test("setInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms."); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); - Mocha.test("setIntervalFloat", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms"); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500.0); - }); - Mocha.test("setTimeout", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); - Mocha.test("setTimeoutFloat", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); -}); - -Mocha.describe("Stdlib.Array", () => { - Mocha.test("at", () => { - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(0), "a"); - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(2), "c"); - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(3), undefined); - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(-1), "c"); - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(-3), "a"); - Stdlib.assertEqual([ - "a", - "b", - "c" - ].at(-4), undefined); - }); - Mocha.test("concat", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = [ - "yay", - "wehoo" - ]; - let someArray = array1.concat(array2); - Stdlib.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" - ]); - }); - Mocha.test("concatMany", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = ["yay"]; - let array3 = ["wehoo"]; - let someArray = array1.concat(array2, array3); - console.log(someArray); - }); - Mocha.test("copy", () => { - let myArray = [ - 1, - 2, - 3 - ]; - let copyOfMyArray = myArray.slice(); - Stdlib.assertEqual(copyOfMyArray, [ - 1, - 2, - 3 - ]); - Stdlib.assertEqual(myArray === copyOfMyArray, false); - }); - Mocha.test("every", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Stdlib.assertEqual(array.every(num => num <= 4), true); - Stdlib.assertEqual(array.every(num => num === 1), false); - }); - Mocha.test("everyWithIndex", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Stdlib.assertEqual(array.every((num, index) => { - if (index < 5) { - return num <= 4; - } else { - return false; - } - }), true); - Stdlib.assertEqual(array.every((num, index) => { - if (index < 2) { - return num >= 2; - } else { - return false; - } - }), false); - }); - Mocha.test("fill", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1, 3); - Stdlib.assertEqual(myArray, [ - 1, - 9, - 9, - 4 - ]); - }); - Mocha.test("fillAll", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9); - Stdlib.assertEqual(myArray, [ - 9, - 9, - 9, - 9 - ]); - }); - Mocha.test("fillToEnd", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1); - Stdlib.assertEqual(myArray, [ - 1, - 9, - 9, - 9 - ]); - }); - Mocha.test("filter", () => { - Stdlib.assertEqual([ - 1, - 2, - 3, - 4 - ].filter(num => num > 2), [ - 3, - 4 - ]); - }); - Mocha.test("filterMap", () => { - Stdlib.assertEqual(Stdlib_Array.filterMap([ - "Hello", - "Hi", - "Good bye" - ], item => { - if (item === "Hello") { - return item.length; - } - - }), [5]); - Stdlib.assertEqual(Stdlib_Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return n * n | 0; - } - - }), [ - 4, - 16, - 36 - ]); - Stdlib.assertEqual(Stdlib_Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), []); - Stdlib.assertEqual(Stdlib_Array.filterMap([], n => { - if (n % 2 === 0) { - return n * n | 0; - } - - }), []); - }); - Mocha.test("filterWithIndex", () => { - Stdlib.assertEqual([ - 1, - 2, - 3, - 4 - ].filter((num, index) => { - if (index === 0) { - return true; - } else { - return num === 2; - } - }), [ - 1, - 2 - ]); - }); - Mocha.test("find", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Stdlib.assertEqual(array.find(item => item === "ReScript"), "ReScript"); - }); - Mocha.test("findIndex", () => { - let array = [ - "ReScript", - "JavaScript" - ]; - Stdlib.assertEqual(array.findIndex(item => item === "ReScript"), 0); - Stdlib.assertEqual(array.findIndex(item => item === "TypeScript"), -1); - }); - Mocha.test("findIndexOpt", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Stdlib.assertEqual(Stdlib_Array.findIndexOpt(array, item => item === "ReScript"), 0); - }); - Mocha.test("findIndexWithIndex", () => { - let array = [ - "ReScript", - "JavaScript" - ]; - let isReScriptFirst = array.findIndex((item, index) => { - if (index === 0) { - return item === "ReScript"; - } else { - return false; - } - }); - let isTypeScriptFirst = array.findIndex((item, index) => { - if (index === 0) { - return item === "TypeScript"; - } else { - return false; - } - }); - Stdlib.assertEqual(isReScriptFirst, 0); - Stdlib.assertEqual(isTypeScriptFirst, -1); - }); - Mocha.test("findMap", () => { - Stdlib.assertEqual(Stdlib_Array.findMap([ - 1, - 2, - 3 - ], n => { - if (n % 2 === 0) { - return n - 2 | 0; - } - - }), 0); - Stdlib.assertEqual(Stdlib_Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return n - 8 | 0; - } - - }), -6); - Stdlib.assertEqual(Stdlib_Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), undefined); - Stdlib.assertEqual(Stdlib_Array.findMap([], n => { - if (n % 2 === 0) { - return n * n | 0; - } - - }), undefined); - }); - Mocha.test("findWithIndex", () => { - let array = [ - "TypeScript", - "JavaScript", - "ReScript" - ]; - Stdlib.assertEqual(array.find((item, index) => { - if (index > 1) { - return item === "ReScript"; - } else { - return false; - } - }), "ReScript"); - }); - Mocha.test("flat", () => { - Stdlib.assertEqual([ - [1], - [2], - [ - 3, - 4 - ] - ].flat(), [ - 1, - 2, - 3, - 4 - ]); - }); - Mocha.test("flatMap", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Stdlib.assertEqual(array.flatMap(item => { - switch (item) { - case "ReScript" : - return [ - 1, - 2, - 3 - ]; - case "TypeScript" : - return [ - 4, - 5, - 6 - ]; - case "JavaScript" : - return [ - 7, - 8, - 9 - ]; - } - }), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); - }); - Mocha.test("flatMapWithIndex", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Stdlib.assertEqual(array.flatMap((item, index) => { - switch (item) { - case "ReScript" : - return [index]; - case "TypeScript" : - return [ - index, - index + 1 | 0 - ]; - case "JavaScript" : - return [ - index, - index + 1 | 0, - index + 2 | 0 - ]; - } - }), [ - 0, - 1, - 2, - 2, - 3, - 4 - ]); - }); - Mocha.test("forEach", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach(item => { - console.log(item); - }); - }); - Mocha.test("forEachWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach((item, index) => { - console.log("At item " + index.toString() + ": " + item); - }); - }); - Mocha.test("fromInitializer", () => { - Stdlib.assertEqual(Stdlib_Array.fromInitializer(3, i => i + 3 | 0), [ - 3, - 4, - 5 - ]); - Stdlib.assertEqual(Stdlib_Array.fromInitializer(7, i => i + 3 | 0), [ - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); - }); - Mocha.test("fromIterator", () => { - Stdlib.assertEqual(Array.from(new Map([ - [ - "foo", - 1 - ], - [ - "bar", - 2 - ] - ]).values()), [ - 1, - 2 - ]); - }); - Mocha.test("get", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Stdlib.assertEqual(array[0], "Hello"); - Stdlib.assertEqual(array[3], undefined); - }); - Mocha.test("getUnsafe", () => { - let array = [ - 1, - 2, - 3 - ]; - for (let index = 0, index_finish = array.length; index < index_finish; ++index) { - let value = array[index]; - console.log(value); - } - }); - Mocha.test("includes", () => { - Stdlib.assertEqual([ - 1, - 2 - ].includes(1), true); - Stdlib.assertEqual([ - 1, - 2 - ].includes(3), false); - Stdlib.assertEqual([{ - language: "ReScript" - }].includes({ - language: "ReScript" - }), false); - }); - Mocha.test("indexOf", () => { - Stdlib.assertEqual([ - 1, - 2 - ].indexOf(2), 1); - Stdlib.assertEqual([ - 1, - 2 - ].indexOf(3), -1); - Stdlib.assertEqual([{ - language: "ReScript" - }].indexOf({ - language: "ReScript" - }), -1); - }); - Mocha.test("indexOfOpt", () => { - Stdlib.assertEqual(Stdlib_Array.indexOfOpt([ - 1, - 2 - ], 2), 1); - Stdlib.assertEqual(Stdlib_Array.indexOfOpt([ - 1, - 2 - ], 3), undefined); - Stdlib.assertEqual(Stdlib_Array.indexOfOpt([{ - language: "ReScript" - }], { - language: "ReScript" - }), undefined); - }); - Mocha.test("join", () => { - Stdlib.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); - }); - Mocha.test("joinUnsafe", () => { - Stdlib.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); - Mocha.test("joinWith", () => { - Stdlib.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); - }); - Mocha.test("joinWithUnsafe", () => { - Stdlib.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); - Mocha.test("keepSome", () => { - Stdlib.assertEqual(Stdlib_Array.keepSome([ - 1, - undefined, - 3 - ]), [ - 1, - 3 - ]); - Stdlib.assertEqual(Stdlib_Array.keepSome([ - 1, - 2, - 3 - ]), [ - 1, - 2, - 3 - ]); - Stdlib.assertEqual(Stdlib_Array.keepSome([ - undefined, - undefined, - undefined - ]), []); - Stdlib.assertEqual(Stdlib_Array.keepSome([]), []); - }); - Mocha.test("last", () => { - Stdlib.assertEqual(Stdlib_Array.last([ - "Hello", - "Hi", - "Good bye" - ]), "Good bye"); - Stdlib.assertEqual(Stdlib_Array.last([]), undefined); - }); - Mocha.test("length", () => { - let someArray = [ - "hi", - "hello" - ]; - Stdlib.assertEqual(someArray.length, 2); - }); - Mocha.test("make", () => { - Stdlib.assertEqual(Stdlib_Array.make(3, "apple"), [ - "apple", - "apple", - "apple" - ]); - Stdlib.assertEqual(Stdlib_Array.make(6, 7), [ - 7, - 7, - 7, - 7, - 7, - 7 - ]); - }); - Mocha.test("map", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map(greeting => greeting + " to you"); - Stdlib.assertEqual(mappedArray, [ - "Hello to you", - "Hi to you", - "Good bye to you" - ]); - }); - Mocha.test("mapWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); - Stdlib.assertEqual(mappedArray, [ - "Hello at position 0", - "Hi at position 1", - "Good bye at position 2" - ]); - }); - Mocha.test("pop", () => { - let someArray = [ - "hi", - "hello" - ]; - Stdlib.assertEqual(someArray.pop(), "hello"); - Stdlib.assertEqual(someArray, ["hi"]); - }); - Mocha.test("push", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay"); - Stdlib.assertEqual(someArray, [ - "hi", - "hello", - "yay" - ]); - }); - Mocha.test("pushMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay", "wehoo"); - Stdlib.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" - ]); - }); - Mocha.test("reduce", () => { - Stdlib.assertEqual(Stdlib_Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0), 10); - Stdlib.assertEqual(Stdlib_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "abcd"); - Stdlib.assertEqual(Stdlib_Array.reduce([ - 1, - 2, - 3 - ], /* [] */0, Stdlib_List.add), { - hd: 3, - tl: { - hd: 2, - tl: { - hd: 1, - tl: /* [] */0 - } - } - }); - Stdlib.assertEqual(Stdlib_Array.reduce([], /* [] */0, Stdlib_List.add), /* [] */0); - }); - Mocha.test("reduceRight", () => { - Stdlib.assertEqual(Stdlib_Array.reduceRight([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "dcba"); - Stdlib.assertEqual(Stdlib_Array.reduceRight([ - 1, - 2, - 3 - ], /* [] */0, Stdlib_List.add), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Stdlib.assertEqual(Stdlib_Array.reduceRight([], /* [] */0, Stdlib_List.add), /* [] */0); - }); - Mocha.test("reduceRightWithIndex", () => { - Stdlib.assertEqual(Stdlib_Array.reduceRightWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Stdlib.assertEqual(Stdlib_Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); - Mocha.test("reduceWithIndex", () => { - Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([ - 1, - 2, - 3 - ], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 1, - tl: /* [] */0 - } - } - }); - Stdlib.assertEqual(Stdlib_Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); - Mocha.test("removeInPlace", () => { - let array = []; - array.splice(0, 1); - Stdlib.assertEqual(array, []); - let array2 = [ - "Hello", - "Hi", - "Good bye" - ]; - array2.splice(1, 1); - Stdlib.assertEqual(array2, [ - "Hello", - "Good bye" - ]); - }); - Mocha.test("reverse", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.reverse(); - Stdlib.assertEqual(someArray, [ - "hello", - "hi" - ]); - }); - Mocha.test("set", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Stdlib.assertEqual(array[1], "Hello"); - }); - Mocha.test("setUnsafe", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Stdlib.assertEqual(array[1], "Hello"); - }); - Mocha.test("shift", () => { - let someArray = [ - "hi", - "hello" - ]; - Stdlib.assertEqual(someArray.shift(), "hi"); - Stdlib.assertEqual(someArray, ["hello"]); - }); - Mocha.test("shuffle", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Stdlib_Array.shuffle(array); - console.log(array); - let array2 = [ - 1, - 2, - 3 - ]; - Stdlib_Array.shuffle(array2); - Stdlib.assertEqual(array2.length, 3); - }); - Mocha.test("slice", () => { - Stdlib.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1, 3), [ - 2, - 3 - ]); - }); - Mocha.test("sliceToEnd", () => { - Stdlib.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1), [ - 2, - 3, - 4 - ]); - }); - Mocha.test("some", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Stdlib.assertEqual(array.some(greeting => greeting === "Hello"), true); - }); - Mocha.test("someWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Stdlib.assertEqual(array.some((greeting, index) => { - if (greeting === "Hello") { - return index === 0; - } else { - return false; - } - }), true); - }); - Mocha.test("sort", () => { - let array = [ - 3, - 2, - 1 - ]; - array.sort((a, b) => a - b | 0); - Stdlib.assertEqual(array, [ - 1, - 2, - 3 - ]); - }); - Mocha.test("toReversed", () => { - let someArray = [ - "hi", - "hello" - ]; - let reversed = someArray.toReversed(); - Stdlib.assertEqual(reversed, [ - "hello", - "hi" - ]); - Stdlib.assertEqual(someArray, [ - "hi", - "hello" - ]); - }); - Mocha.test("toShuffled", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let shuffledArray = Stdlib_Array.toShuffled(array); - console.log(shuffledArray); - Stdlib.assertEqual(Stdlib_Array.toShuffled([ - 1, - 2, - 3 - ]).length, 3); - }); - Mocha.test("toSorted", () => { - let someArray = [ - 3, - 2, - 1 - ]; - Stdlib.assertEqual(someArray.toSorted(Primitive_int.compare), [ - 1, - 2, - 3 - ]); - Stdlib.assertEqual(someArray, [ - 3, - 2, - 1 - ]); - }); - Mocha.test("toString", () => { - Stdlib.assertEqual([ - 1, - 2, - 3, - 4 - ].toString(), "1,2,3,4"); - }); - Mocha.test("unsafe_get", () => { - let array = [ - 1, - 2, - 3 - ]; - for (let index = 0, index_finish = array.length; index < index_finish; ++index) { - let value = array[index]; - console.log(value); - } - }); - Mocha.test("unshift", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay"); - Stdlib.assertEqual(someArray, [ - "yay", - "hi", - "hello" - ]); - }); - Mocha.test("unshiftMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay", "wehoo"); - Stdlib.assertEqual(someArray, [ - "yay", - "wehoo", - "hi", - "hello" - ]); - }); -}); - -Mocha.describe("Stdlib.AsyncIterator", () => { - Mocha.test("done", () => { - let context = { - contents: 0 - }; - Stdlib_AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return Stdlib_AsyncIterator.done(undefined); - } else { - return Stdlib_AsyncIterator.value(currentValue); - } - }); - }); - Mocha.test("forEach", () => { - let asyncIterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - let main = async () => await Stdlib_AsyncIterator.forEach(asyncIterator, v => { - if (v !== undefined && v[0] === "second") { - return Stdlib.assertEqual(v[1], "2"); - } - - }); - main(); - }); - Mocha.test("make", () => { - let context = { - contents: 0 - }; - let asyncIterator = Stdlib_AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - return { - done: currentValue >= 3, - value: currentValue - }; - }); - let main = async () => await Stdlib_AsyncIterator.forEach(asyncIterator, value => { - if (value !== undefined) { - console.log(value); - return; - } - - }); - main(); - }); - Mocha.test("next", () => { - let asyncIterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - let processMyAsyncIterator = async () => { - let $$break = false; - while (!$$break) { - let match = await asyncIterator.next(); - let done = match.done; - $$break = done; - if (done) { - Stdlib.assertEqual(Stdlib_Option.isNone(match.value), true); - } - - }; - }; - processMyAsyncIterator(); - }); - Mocha.test("value", () => { - let context = { - contents: 0 - }; - Stdlib_AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return Stdlib_AsyncIterator.done(undefined); - } else { - return Stdlib_AsyncIterator.value(currentValue); - } - }); - }); -}); - -Mocha.describe("Stdlib.BigInt", () => { - Mocha.test("fromStringExn", () => { - Stdlib.assertEqual(BigInt("123"), 123n); - Stdlib.assertEqual(BigInt(""), 0n); - Stdlib.assertEqual(BigInt("0x11"), 17n); - Stdlib.assertEqual(BigInt("0b11"), 3n); - Stdlib.assertEqual(BigInt("0o11"), 9n); - let exit = 0; - let _bigInt; - try { - _bigInt = BigInt("a"); - exit = 1; - } catch (raw__error) { - let _error = Primitive_exceptions.internalToException(raw__error); - if (_error.RE_EXN_ID !== Stdlib_Exn.$$Error) { - throw _error; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 9180, - 13 - ], - Error: new Error() - }; - } - - }); - Mocha.test("toLocaleString", () => { - Stdlib.assertEqual((123n).toString(), "123"); - }); - Mocha.test("toString", () => { - Stdlib.assertEqual((123n).toString(), "123"); - }); -}); - -Mocha.describe("Stdlib.Bool", () => { - Mocha.test("fromString", () => { - Stdlib.assertEqual(Stdlib_Bool.fromString("true"), true); - Stdlib.assertEqual(Stdlib_Bool.fromString("false"), false); - Stdlib.assertEqual(Stdlib_Bool.fromString("notAValidBoolean"), undefined); - }); - Mocha.test("fromStringExn", () => { - Stdlib.assertEqual(Stdlib_Bool.fromStringExn("true"), true); - Stdlib.assertEqual(Stdlib_Bool.fromStringExn("false"), false); - let exit = 0; - let val; - try { - val = Stdlib_Bool.fromStringExn("notAValidBoolean"); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Invalid_argument") { - throw exn; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 9213, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("toString", () => { - Stdlib.assertEqual(Stdlib_Bool.toString(true), "true"); - Stdlib.assertEqual(Stdlib_Bool.toString(false), "false"); - }); -}); - -Mocha.describe("Stdlib.Char", () => { - Mocha.test("toLowerCaseAscii", () => { - Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'A' */65), /* 'a' */97); - Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'Z' */90), /* 'z' */122); - Stdlib.assertEqual(Stdlib_Char.toLowerCaseAscii(/* 'a' */97), /* 'a' */97); - }); - Mocha.test("toUpperCaseAscii", () => { - Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'a' */97), /* 'A' */65); - Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'z' */122), /* 'Z' */90); - Stdlib.assertEqual(Stdlib_Char.toUpperCaseAscii(/* 'A' */65), /* 'A' */65); - }); -}); - -Mocha.describe("Stdlib.Console", () => { - Mocha.test("assert2", () => { - console.assert(false, "Hello", "World"); - console.assert(true, [ - 1, - 2, - 3 - ], /* '4' */52); - }); - Mocha.test("assert3", () => { - console.assert(false, "Hello", "World", "ReScript"); - console.assert(true, "One", 2, 3); - }); - Mocha.test("assert4", () => { - console.assert(false, "Hello", "World", "ReScript", "!!!"); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); - Mocha.test("assert5", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); - Mocha.test("assert6", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("assertMany", () => { - console.assert(false, "Hello", "World"); - console.assert(true, 1, 2, 3); - }); - Mocha.test("assert_", () => { - console.assert(false, "Hello World!"); - console.assert(true, "The answer"); - }); - Mocha.test("clear", () => { - console.clear(); - }); - Mocha.test("count", () => { - console.count("rescript"); - }); - Mocha.test("countReset", () => { - console.countReset("rescript"); - }); - Mocha.test("debug", () => { - console.debug("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.debug(obj); - }); - Mocha.test("debug2", () => { - console.debug("Hello", "World"); - console.debug([ - 1, - 2, - 3 - ], /* '4' */52); - }); - Mocha.test("debug3", () => { - console.debug("Hello", "World", "ReScript"); - console.debug("One", 2, 3); - }); - Mocha.test("debug4", () => { - console.debug("Hello", "World", "ReScript", "!!!"); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); - Mocha.test("debug5", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); - Mocha.test("debug6", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("debugMany", () => { - console.debug("Hello", "World"); - console.debug(1, 2, 3); - }); - Mocha.test("dir", () => { - console.dir({ - language: "rescript", - version: "10.1.2" - }); - }); - Mocha.test("error", () => { - console.error("error message"); - console.error([ - "error", - "invalid value" - ]); - }); - Mocha.test("error2", () => { - console.error("Error", "here"); - console.error([ - "log", - "error" - ], "message"); - }); - Mocha.test("error3", () => { - console.error("Hello", "World", "!!!"); - console.error("first", "second", "third"); - }); - Mocha.test("error4", () => { - console.error("Hello", "World", "ReScript", /* '!' */33); - console.error("first", "second", "third", "fourth"); - }); - Mocha.test("error5", () => { - console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); - console.error(1, "second", "third", "fourth", /* 'c' */99); - }); - Mocha.test("error6", () => { - console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.error([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("errorMany", () => { - console.error("Hello", "World"); - console.error(1, 2, 3); - }); - Mocha.test("group", () => { - console.group("first group"); - console.group("second group"); - console.log("a message on the second level"); - console.groupEnd(); - console.log("a message message on the first level"); - console.groupEnd(); - }); - Mocha.test("info", () => { - console.info("Information"); - console.info([ - "Hello", - "JS" - ]); - }); - Mocha.test("info2", () => { - console.info("Info", "failed to download"); - console.info("info", { - name: "ReScript" - }); - }); - Mocha.test("info3", () => { - console.info("Hello", "World", "ReScript"); - console.info([ - 1, - 2, - 3 - ], 4, 5); - }); - Mocha.test("info4", () => { - console.info("Hello", "World", "ReScript", /* '!' */33); - console.info([ - 1, - 2, - 3 - ], 4, 5, "lastinfo"); - }); - Mocha.test("info5", () => { - console.info("Hello", "World", "from", "JS", "!!!"); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); - Mocha.test("info6", () => { - console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("infoMany", () => { - console.info("Hello", "World"); - console.info(1, 2, 3); - }); - Mocha.test("log", () => { - console.log("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.log(obj); - }); - Mocha.test("log2", () => { - console.log("Hello", "World"); - console.log([ - 1, - 2, - 3 - ], /* '4' */52); - }); - Mocha.test("log3", () => { - console.log("Hello", "World", "ReScript"); - console.log("One", 2, 3); - }); - Mocha.test("log4", () => { - console.log("Hello", "World", "ReScript", "!!!"); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); - Mocha.test("log5", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); - Mocha.test("log6", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("logMany", () => { - console.log("Hello", "World"); - console.log(1, 2, 3); - }); - Mocha.test("table", () => { - console.table({ - language: "rescript", - version: "10.1.2" - }); - }); - Mocha.test("time", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); - Mocha.test("timeEnd", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); - Mocha.test("timeLog", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); - Mocha.test("trace", () => { - console.trace(); - }); - Mocha.test("warn", () => { - console.warn("Warning"); - console.warn([ - "Warning", - "invalid number" - ]); - }); - Mocha.test("warn2", () => { - console.warn("Hello", "World"); - console.warn([ - 1, - 2, - 3 - ], 4); - }); - Mocha.test("warn3", () => { - console.warn("Hello", "World", "ReScript"); - console.warn([ - 1, - 2, - 3 - ], 4, 5); - }); - Mocha.test("warn4", () => { - console.warn("Hello", "World", "ReScript", "!!!"); - console.warn("first", "second", "third", "fourth"); - }); - Mocha.test("warn5", () => { - console.warn("Hello", "World", "from", "JS", "!!!"); - console.warn([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); - Mocha.test("warn6", () => { - console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.warn([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); - Mocha.test("warnMany", () => { - console.warn("Hello", "World"); - console.warn(1, 2, 3); - }); -}); - -Mocha.describe("Stdlib.Date.UTC", () => { - Mocha.test("makeWithYM", () => { - Date.UTC(2023, 0); - Date.UTC(2023, 11); - Date.UTC(2023, 12); - Date.UTC(2023, -1); - }); - Mocha.test("makeWithYMD", () => { - Date.UTC(2023, 1, 20); - Date.UTC(2023, 1, -1); - Date.UTC(2023, 1, 29); - }); - Mocha.test("makeWithYMDH", () => { - Date.UTC(2023, 1, 20, 16); - Date.UTC(2023, 1, 20, 24); - Date.UTC(2023, 1, 20, -1); - }); - Mocha.test("makeWithYMDHM", () => { - Date.UTC(2023, 1, 20, 16, 40); - Date.UTC(2023, 1, 20, 16, 60); - Date.UTC(2023, 1, 20, 16, -1); - }); - Mocha.test("makeWithYMDHMS", () => { - Date.UTC(2023, 1, 20, 16, 40, 0); - Date.UTC(2023, 1, 20, 16, 40, 60); - Date.UTC(2023, 1, 20, 16, 40, -1); - }); - Mocha.test("makeWithYMDHMSM", () => { - console.log(Date.UTC(2023, 1, 20, 16, 40, 0, 0)); - console.log(Date.UTC(2023, 1, 20, 16, 40, 0, 1000)); - console.log(Date.UTC(2023, 1, 20, 16, 40, 0, -1)); - }); -}); - -Mocha.describe("Stdlib.Date", () => { - Mocha.test("fromString", () => { - new Date("2023"); - new Date("2023-02-20"); - new Date("2023-02-20T16:40:00.00Z"); - new Date(""); - new Date("").getTime(); - }); - Mocha.test("fromTime", () => { - new Date(0.0); - new Date(-86400000.0); - new Date(86400000.0); - }); - Mocha.test("getDate", () => { - new Date("2023-02-20T16:40:00.00").getDate(); - }); - Mocha.test("getDay", () => { - new Date("2023-02-20T16:40:00.00").getDay(); - }); - Mocha.test("getFullYear", () => { - new Date("2023-02-20").getFullYear(); - }); - Mocha.test("getHours", () => { - new Date("2023-02-20T16:40:00.00").getHours(); - }); - Mocha.test("getMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").getMilliseconds(); - }); - Mocha.test("getMinutes", () => { - new Date("2023-02-20T16:40:00.00").getMinutes(); - }); - Mocha.test("getMonth", () => { - new Date("2023-01-01").getMonth(); - }); - Mocha.test("getSeconds", () => { - new Date("2023-02-20T16:40:00.00").getSeconds(); - }); - Mocha.test("getTime", () => { - new Date("2023-02-20").getTime(); - }); - Mocha.test("getTimezoneOffset", () => { - new Date("2023-01-01").getTimezoneOffset(); - new Date("2023-06-01").getTimezoneOffset(); - }); - Mocha.test("getUTCDate", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); - }); - Mocha.test("getUTCDay", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); - }); - Mocha.test("getUTCFullYear", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); - }); - Mocha.test("getUTCHours", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); - }); - Mocha.test("getUTCMilliseconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); - }); - Mocha.test("getUTCMinutes", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); - }); - Mocha.test("getUTCMonth", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); - }); - Mocha.test("getUTCSeconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); - }); - Mocha.test("make", () => { - new Date(); - }); - Mocha.test("makeWithYM", () => { - new Date(2023, 0); - new Date(2023, 11); - new Date(2023, 12); - new Date(2023, -1); - }); - Mocha.test("makeWithYMD", () => { - new Date(2023, 1, 20); - new Date(2023, 1, -1); - new Date(2023, 1, 29); - }); - Mocha.test("makeWithYMDH", () => { - new Date(2023, 1, 20, 16); - new Date(2023, 1, 20, 24); - new Date(2023, 1, 20, -1); - }); - Mocha.test("makeWithYMDHM", () => { - new Date(2023, 1, 20, 16, 40); - new Date(2023, 1, 20, 16, 60); - new Date(2023, 1, 20, 16, -1); - }); - Mocha.test("makeWithYMDHMS", () => { - new Date(2023, 1, 20, 16, 40, 0); - new Date(2023, 1, 20, 16, 40, 60); - new Date(2023, 1, 20, 16, 40, -1); - }); - Mocha.test("makeWithYMDHMSM", () => { - new Date(2023, 1, 20, 16, 40, 0, 0); - new Date(2023, 1, 20, 16, 40, 0, 1000); - new Date(2023, 1, 20, 16, 40, 0, -1); - }); - Mocha.test("setDate", () => { - new Date("2023-02-20T16:40:00.00").setDate(1); - }); - Mocha.test("setFullYear", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024); - }); - Mocha.test("setFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); - }); - Mocha.test("setFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); - }); - Mocha.test("setHours", () => { - new Date("2023-02-20T16:40:00.00").setHours(0); - }); - Mocha.test("setHoursM", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0); - }); - Mocha.test("setHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); - }); - Mocha.test("setHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); - }); - Mocha.test("setMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setMilliseconds(0); - }); - Mocha.test("setMinutes", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0); - }); - Mocha.test("setMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); - }); - Mocha.test("setMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); - }); - Mocha.test("setMonth", () => { - new Date("2023-02-20T16:40:00.00").setMonth(0); - }); - Mocha.test("setSeconds", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0); - }); - Mocha.test("setSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); - }); - Mocha.test("setUTCDate", () => { - new Date("2023-02-20T16:40:00.00").setUTCDate(1); - }); - Mocha.test("setUTCFullYear", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); - }); - Mocha.test("setUTCFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); - }); - Mocha.test("setUTCFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); - }); - Mocha.test("setUTCHours", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0); - }); - Mocha.test("setUTCHoursM", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); - }); - Mocha.test("setUTCHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); - }); - Mocha.test("setUTCHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); - }); - Mocha.test("setUTCMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); - }); - Mocha.test("setUTCMinutes", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); - }); - Mocha.test("setUTCMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); - }); - Mocha.test("setUTCMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); - }); - Mocha.test("setUTCMonth", () => { - new Date("2023-02-20T16:40:00.00").setUTCMonth(0); - }); - Mocha.test("setUTCSeconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); - }); - Mocha.test("setUTCSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); - }); - Mocha.test("toDateString", () => { - console.log(new Date("2023-01-01T00:00:00.00+01:00").toDateString()); - console.log(new Date("2023-01-01T00:00:00.00+08:00").toDateString()); - }); - Mocha.test("toISOString", () => { - console.log(new Date("2023-01-01T00:00:00.00+00:00").toISOString()); - console.log(new Date("2023-01-01T00:00:00.00+08:00").toISOString()); - }); - Mocha.test("toJSON", () => { - new Date("2023-01-01T00:00:00.00+00:00").toJSON(); - new Date("").toJSON(); - }); - Mocha.test("toLocaleDateString", () => { - console.log(new Date().toLocaleDateString()); - }); - Mocha.test("toLocaleDateStringWithLocale", () => { - console.log(new Date().toLocaleDateString("en-US")); - }); - Mocha.test("toLocaleDateStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleDateString("en-US", { - dateStyle: "long" - })); - console.log(new Date().toLocaleDateString("de", { - hour: "2-digit", - minute: "2-digit" - })); - console.log(new Date().toLocaleDateString("de", { - year: "numeric" - })); - }); - Mocha.test("toLocaleString", () => { - console.log(new Date().toLocaleString()); - }); - Mocha.test("toLocaleStringWithLocale", () => { - console.log(new Date().toLocaleString("en-US")); - }); - Mocha.test("toLocaleStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleString("en", { - dateStyle: "short", - timeStyle: "short" - })); - console.log(new Date().toLocaleString("en", { - era: "long", - year: "numeric", - month: "2-digit", - day: "2-digit", - hour: "numeric", - timeZoneName: "short" - })); - }); - Mocha.test("toLocaleTimeString", () => { - console.log(new Date().toLocaleTimeString()); - }); - Mocha.test("toLocaleTimeStringWithLocale", () => { - console.log(new Date().toLocaleTimeString("en-US")); - }); - Mocha.test("toLocaleTimeStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleTimeString("en-US", { - timeStyle: "long" - })); - console.log(new Date().toLocaleTimeString("de", { - hour: "2-digit", - minute: "2-digit" - })); - }); - Mocha.test("toString", () => { - console.log(new Date("2023-01-01T00:00:00.00+01:00").toString()); - console.log(new Date("2023-06-01T00:00:00.00+01:00").toString()); - }); - Mocha.test("toTimeString", () => { - console.log(new Date("2023-01-01T00:00:00.00+01:00").toTimeString()); - console.log(new Date("2023-01-01T00:00:00.00+08:00").toTimeString()); - }); - Mocha.test("toUTCString", () => { - console.log(new Date("2023-01-01T00:00:00.00+00:00").toUTCString()); - console.log(new Date("2023-01-01T00:00:00.00+08:00").toUTCString()); - }); -}); - -Mocha.describe("Stdlib.Dict", () => { - Mocha.test("assign", () => { - let dict1 = {}; - dict1["firstKey"] = 1; - console.log(Object.keys(dict1)); - let dict2 = {}; - dict2["someKey"] = 2; - dict2["someKey2"] = 3; - let dict1$1 = Object.assign(dict1, dict2); - console.log(Object.keys(dict1$1)); - }); - Mocha.test("copy", () => { - let dict = { - key1: "value1", - key2: "value2" - }; - let dict2 = Object.assign({}, dict); - console.log(Object.keys(dict), Object.keys(dict2)); - }); - Mocha.test("delete", () => { - let dict = { - someKey: "someValue" - }; - Stdlib_Dict.$$delete(dict, "someKey"); - }); - Mocha.test("forEach", () => { - let dict = { - key1: "value1", - key2: "value2" - }; - Stdlib_Dict.forEach(dict, value => { - console.log(value); - }); - }); - Mocha.test("forEachWithKey", () => { - let dict = { - key1: "value1", - key2: "value2" - }; - Stdlib_Dict.forEachWithKey(dict, (value, key) => { - console.log(value, key); - }); - }); - Mocha.test("fromArray", () => { - Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - }); - Mocha.test("fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Stdlib.assertEqual(Object.values(Object.fromEntries(iterator)), [ - 1, - 2 - ]); - }); - Mocha.test("get", () => { - let dict = { - someKey: "someValue" - }; - let value = dict["someKey"]; - if (value !== undefined) { - console.log(value); - } else { - console.log("Nope, didn't have the key."); - } - }); - Mocha.test("getUnsafe", () => { - let dict = { - key1: "value1", - key2: "value2" - }; - let value = dict["key1"]; - console.log(value); - }); - Mocha.test("has", () => { - let dict = { - key1: 1, - key2: undefined - }; - Stdlib_Dict.has(dict, "key1"); - Stdlib_Dict.has(dict, "key2"); - Stdlib_Dict.has(dict, "key3"); - }); - Mocha.test("keysToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let keys = Object.keys(dict); - console.log(keys); - }); - Mocha.test("make", () => { - let dict2 = {}; - dict2["someKey"] = 12; - }); - Mocha.test("mapValues", () => { - let dict = { - key1: 1, - key2: 2 - }; - Object.entries(Stdlib_Dict.mapValues(dict, v => v + 10 | 0)); - Object.entries(Stdlib_Dict.mapValues(dict, v => v.toString())); - }); - Mocha.test("set", () => { - let dict = {}; - dict["someKey"] = "someValue"; - }); - Mocha.test("toArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let asArray = Object.entries(dict); - console.log(asArray); - }); - Mocha.test("valuesToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let values = Object.values(dict); - console.log(values); - }); -}); - -Mocha.describe("Stdlib.Error", () => { - Mocha.test("make", () => { - let error = new Error("Some message here"); - console.log(error.message); - console.log(error.name); - }); - Mocha.test("message", () => { - let error = new SyntaxError("Some message here"); - console.log(error.message); - }); - Mocha.test("name", () => { - let error = new SyntaxError("Some message here"); - console.log(error.name); - }); - Mocha.test("panic", () => { - try { - Stdlib_Error.panic("Uh oh. This was unexpected!"); - } catch (raw_obj) { - let obj = Primitive_exceptions.internalToException(raw_obj); - if (obj.RE_EXN_ID === Stdlib_Exn.$$Error) { - let m = obj._1.message; - if (m !== undefined) { - if (m !== "Panic! Uh oh. This was unexpected!") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 10483, - 15 - ], - Error: new Error() - }; - } - - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 10484, - 12 - ], - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 10486, - 7 - ], - Error: new Error() - }; - } - } - }); - Mocha.test("raise", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); - }); - Mocha.test("stack", () => { - let error = new Error("error"); - console.log(error.stack); - }); - Mocha.test("throw", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); - }); - Mocha.test("toException", () => { - new Error("Something went wrong."); - }); -}); - -Mocha.describe("Stdlib.Float", () => { - Mocha.test("clamp", () => { - Stdlib_Float.clamp(undefined, undefined, 4.2) === 4.2; - Stdlib_Float.clamp(4.3, undefined, 4.2) === 4.3; - Stdlib_Float.clamp(undefined, 4.1, 4.2) === 4.1; - Stdlib_Float.clamp(4.3, 4.1, 4.2) === 4.3; - }); - Mocha.test("fromInt", () => {}); - Mocha.test("fromString", () => { - Primitive_object.equal(Stdlib_Float.fromString("0"), 0.0); - Stdlib_Float.fromString("NaN") === undefined; - Primitive_object.equal(Stdlib_Float.fromString("6"), 6.0); - }); - Mocha.test("isFinite", () => { - isFinite(1.0); - isFinite(NaN); - isFinite(Number.POSITIVE_INFINITY); - }); - Mocha.test("isNaN", () => { - isNaN(3.0); - isNaN(NaN); - }); - Mocha.test("mod", () => {}); - Mocha.test("parseFloat", () => { - parseFloat("1.0"); - parseFloat(" 3.14 "); - parseFloat("3.0"); - parseFloat("3.14some non-digit characters"); - isNaN(parseFloat("error")); - }); - Mocha.test("parseInt", () => { - parseInt("1.0"); - parseInt(" 3.14 "); - parseInt(3); - parseInt("3.14some non-digit characters"); - isNaN(parseInt("error")); - parseInt("10.0", 2); - parseInt("15 * 3", 10); - parseInt("12", 13); - isNaN(parseInt("17", 40)); - }); - Mocha.test("parseIntWithRadix", () => { - parseInt("10.0", 2); - parseInt("15 * 3", 10); - parseInt("12", 13); - isNaN(parseInt("17", 40)); - }); - Mocha.test("toExponential", () => { - (1000.0).toExponential(); - (-1000.0).toExponential(); - (77.0).toExponential(2); - (5678.0).toExponential(2); - }); - Mocha.test("toExponentialWithPrecision", () => { - (77.0).toExponential(2); - (5678.0).toExponential(2); - }); - Mocha.test("toFixed", () => { - (123456.0).toFixed(); - (10.0).toFixed(); - (300.0).toFixed(4); - (300.0).toFixed(1); - }); - Mocha.test("toFixedWithPrecision", () => { - (300.0).toFixed(4); - (300.0).toFixed(1); - }); - Mocha.test("toInt", () => {}); - Mocha.test("toLocaleString", () => { - (1000.0).toLocaleString(); - (1000.0).toLocaleString(); - }); - Mocha.test("toPrecision", () => { - (100.0).toPrecision(); - (1.0).toPrecision(); - (100.0).toPrecision(2); - (1.0).toPrecision(1); - }); - Mocha.test("toPrecisionWithPrecision", () => { - (100.0).toPrecision(2); - (1.0).toPrecision(1); - }); - Mocha.test("toString", () => { - (1000.0).toString(); - (-1000.0).toString(); - }); - Mocha.test("toStringWithRadix", () => { - (6.0).toString(2); - (3735928559.0).toString(16); - (123456.0).toString(36); - }); -}); - -Mocha.describe("Stdlib.Float.Constants", () => { - Mocha.test("epsilon", () => {}); - Mocha.test("maxValue", () => {}); - Mocha.test("minValue", () => {}); - Mocha.test("nan", () => {}); - Mocha.test("negativeInfinity", () => {}); - Mocha.test("positiveInfinity", () => {}); -}); - -Mocha.describe("Stdlib.Int.Constants", () => { - Mocha.test("maxValue", () => { - console.log(Stdlib_Int.Constants.maxValue); - }); - Mocha.test("minValue", () => { - console.log(Stdlib_Int.Constants.minValue); - }); -}); - -Mocha.describe("Stdlib.Int", () => { - Mocha.test("bitwiseAnd", () => {}); - Mocha.test("bitwiseNot", () => { - Stdlib_Int.bitwiseNot(2) === -3; - }); - Mocha.test("bitwiseOr", () => {}); - Mocha.test("bitwiseXor", () => {}); - Mocha.test("clamp", () => { - Stdlib_Int.clamp(undefined, undefined, 42) === 42; - Stdlib_Int.clamp(50, undefined, 42) === 50; - Stdlib_Int.clamp(undefined, 40, 42) === 40; - Stdlib_Int.clamp(50, 40, 42) === 50; - }); - Mocha.test("fromFloat", () => {}); - Mocha.test("fromString", () => { - Primitive_object.equal(Stdlib_Int.fromString("0", undefined), 0); - Stdlib_Int.fromString("NaN", undefined) === undefined; - Stdlib_Int.fromString("6", 2) === undefined; - }); - Mocha.test("mod", () => {}); - Mocha.test("range", () => { - Primitive_object.equal(Stdlib_Int.range(3, 6, undefined), [ - 3, - 4, - 5 - ]); - Primitive_object.equal(Stdlib_Int.range(-3, -1, undefined), [ - -3, - -2 - ]); - Primitive_object.equal(Stdlib_Int.range(3, 1, undefined), [ - 3, - 2 - ]); - Primitive_object.equal(Stdlib_Int.range(3, 7, { - step: 2 - }), [ - 3, - 5 - ]); - Primitive_object.equal(Stdlib_Int.range(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Stdlib_Int.range(3, 6, { - step: -2 - }); - }); - Mocha.test("rangeWithOptions", () => { - Primitive_object.equal(Stdlib_Int.rangeWithOptions(3, 7, { - step: 2 - }), [ - 3, - 5 - ]); - Primitive_object.equal(Stdlib_Int.rangeWithOptions(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Stdlib_Int.rangeWithOptions(3, 6, { - step: -2 - }); - }); - Mocha.test("shiftLeft", () => {}); - Mocha.test("shiftRight", () => {}); - Mocha.test("shiftRightUnsigned", () => {}); - Mocha.test("toExponential", () => { - (1000).toExponential(); - (-1000).toExponential(); - (77).toExponential(2); - (5678).toExponential(2); - }); - Mocha.test("toExponentialWithPrecision", () => { - (77).toExponential(2); - (5678).toExponential(2); - }); - Mocha.test("toFixed", () => { - (123456).toFixed(); - (10).toFixed(); - (300).toFixed(4); - (300).toFixed(1); - }); - Mocha.test("toFixedWithPrecision", () => { - (300).toFixed(4); - (300).toFixed(1); - }); - Mocha.test("toFloat", () => {}); - Mocha.test("toLocaleString", () => { - (1000).toLocaleString(); - (1000).toLocaleString(); - }); - Mocha.test("toPrecision", () => { - (100).toPrecision(); - (1).toPrecision(); - (100).toPrecision(2); - (1).toPrecision(2); - }); - Mocha.test("toPrecisionWithPrecision", () => { - (100).toPrecision(2); - (1).toPrecision(2); - }); - Mocha.test("toString", () => { - (1000).toString(); - (-1000).toString(); - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); - }); - Mocha.test("toStringWithRadix", () => { - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); - }); -}); - -Mocha.describe("Stdlib.Iterator", () => { - Mocha.test("forEach", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Stdlib_Iterator.forEach(iterator, v => { - if (v === undefined) { - return Stdlib.assertEqual(Stdlib_Option.isNone(v), true); - } - switch (v) { - case "a" : - case "b" : - case "c" : - return; - default: - return Stdlib.assertEqual(Stdlib_Option.isNone(v), true); - } - }); - }); - Mocha.test("next", () => { - let iterator = ((() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Stdlib.assertEqual(iterator.next().done, false); - Stdlib.assertEqual(iterator.next().done, true); - }); - Mocha.test("toArray", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - let mapKeysAsArray = Array.from(map.keys()); - console.log(mapKeysAsArray); - }); - Mocha.test("toArrayWithMapper", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - let mapKeysAsArray = Array.from(map.keys(), key => key.length); - console.log(mapKeysAsArray); - }); -}); - -Mocha.describe("Stdlib.JSON.Classify", () => { - Mocha.test("classify", () => { - Stdlib_JSON.Classify.classify("hello world"); - Stdlib_JSON.Classify.classify(42); - }); -}); - -Mocha.describe("Stdlib.JSON.Decode", () => { - Mocha.test("array", () => { - Stdlib_JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); - Stdlib_JSON.Decode.array(JSON.parse("\"hello world\"")); - }); - Mocha.test("bool", () => { - Stdlib_JSON.Decode.bool(JSON.parse("true")); - Stdlib_JSON.Decode.bool(JSON.parse("\"hello world\"")); - }); - Mocha.test("float", () => { - Stdlib_JSON.Decode.float(JSON.parse("42.0")); - Stdlib_JSON.Decode.float(JSON.parse("\"hello world\"")); - }); - Mocha.test("null", () => { - Stdlib_JSON.Decode.$$null(JSON.parse("null")); - Stdlib_JSON.Decode.$$null(JSON.parse("\"hello world\"")); - }); - Mocha.test("object", () => { - Stdlib_JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); - Stdlib_JSON.Decode.object(JSON.parse("\"hello world\"")); - }); - Mocha.test("string", () => { - Stdlib_JSON.Decode.string(JSON.parse("\"hello world\"")); - Stdlib_JSON.Decode.string(JSON.parse("42")); - }); -}); - -Mocha.describe("Stdlib.JSON.Encode", () => { - Mocha.test("array", () => {}); - Mocha.test("bool", () => {}); - Mocha.test("float", () => {}); - Mocha.test("int", () => {}); - Mocha.test("null", () => {}); - Mocha.test("object", () => { - Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ] - ]); - }); - Mocha.test("string", () => {}); -}); - -Mocha.describe("Stdlib.JSON", () => { - Mocha.test("parseExn", () => { - try { - JSON.parse("{\"foo\":\"bar\",\"hello\":\"world\"}"); - JSON.parse(""); - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === Stdlib_Exn.$$Error) { - console.log("error"); - } else { - throw exn; - } - } - let reviver = (param, value) => { - switch (typeof value) { - case "string" : - return value.toUpperCase(); - case "number" : - return value * 2.0; - default: - return value; - } - }; - try { - console.log(JSON.parse("{\"hello\":\"world\",\"someNumber\":21}", reviver)); - console.log(JSON.parse("", reviver)); - } catch (raw_exn$1) { - let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); - if (exn$1.RE_EXN_ID === Stdlib_Exn.$$Error) { - console.log("error"); - } else { - throw exn$1; - } - } - }); - Mocha.test("parseExnWithReviver", () => { - let reviver = (param, value) => { - switch (typeof value) { - case "string" : - return value.toUpperCase(); - case "number" : - return value * 2.0; - default: - return value; - } - }; - try { - console.log(JSON.parse("{\"hello\":\"world\",\"someNumber\":21}", reviver)); - console.log(JSON.parse("", reviver)); - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === Stdlib_Exn.$$Error) { - console.log("error"); - } else { - throw exn; - } - } - }); - Mocha.test("stringify", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json); - JSON.stringify(json, undefined, 2); - JSON.stringify(json, [ - "foo", - "someNumber" - ]); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); - Mocha.test("stringifyAny", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Stdlib.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Stdlib.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11253, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyAnyWithFilter", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Stdlib.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11274, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyAnyWithFilterAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Stdlib.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Stdlib.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11310, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyAnyWithIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Stdlib.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11336, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyAnyWithReplacer", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11367, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyAnyWithReplacerAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Stdlib.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Stdlib.assertEqual(JSON.stringify(() => "hello world"), undefined); - let exit = 0; - let val; - try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11398, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("stringifyWithFilter", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ]); - }); - Mocha.test("stringifyWithFilterAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ], 2); - }); - Mocha.test("stringifyWithIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, null, 2); - }); - Mocha.test("stringifyWithReplacer", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); - Mocha.test("stringifyWithReplacerAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = Stdlib_JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer, 2); - }); -}); - -Mocha.describe("Stdlib.List", () => { - Mocha.test("add", () => { - Stdlib_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Stdlib_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); - Mocha.test("compare", () => { - Stdlib_List.compare({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - }, Primitive_int.compare); - Stdlib_List.compare({ - hd: 5, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - Stdlib_List.compare({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 4, - tl: { - hd: 2, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Stdlib_List.compare({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - Stdlib_List.compare({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, Primitive_int.compare); - }); - Mocha.test("compareLength", () => { - Stdlib_List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - Stdlib_List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - Stdlib_List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); - }); - Mocha.test("concat", () => { - Stdlib.assertEqual(Stdlib_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - } - }); - }); - Mocha.test("concatMany", () => { - Stdlib_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); - Mocha.test("drop", () => { - Stdlib_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Stdlib_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - Stdlib_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("equal", () => { - Stdlib_List.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Stdlib_List.equal({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Stdlib_List.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("every", () => { - let isBelow10 = value => value < 10; - Stdlib_List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - Stdlib_List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - }); - Mocha.test("every2", () => { - Stdlib_List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Stdlib_List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Stdlib_List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Stdlib_List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("filter", () => { - let isEven = x => x % 2 === 0; - Stdlib_List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - Stdlib_List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Stdlib_Option.isSome); - }); - Mocha.test("filterMap", () => { - let isEven = x => x % 2 === 0; - Stdlib_List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => { - if (isEven(x)) { - return x; - } - - }); - Stdlib_List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); - Mocha.test("filterWithIndex", () => { - Stdlib_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); - Mocha.test("find", () => { - Stdlib_List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - Stdlib_List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); - }); - Mocha.test("flat", () => { - Stdlib_List.flat({ - hd: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - tl: { - hd: /* [] */0, - tl: { - hd: { - hd: 3, - tl: /* [] */0 - }, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("forEach", () => { - Stdlib_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); - Mocha.test("forEach2", () => { - Stdlib_List.forEach2({ - hd: "Z", - tl: { - hd: "Y", - tl: /* [] */0 - } - }, { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }, (x, y) => { - console.log(x, y); - }); - }); - Mocha.test("forEachWithIndex", () => { - Stdlib_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (x, index) => { - console.log("Item " + index.toString() + " is " + x); - }); - }); - Mocha.test("fromArray", () => { - Stdlib_List.fromArray([ - 1, - 2, - 3 - ]); - }); - Mocha.test("fromInitializer", () => { - Stdlib_List.fromInitializer(5, i => i); - Stdlib_List.fromInitializer(5, i => i * i | 0); - }); - Mocha.test("get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Stdlib_List.get(abc, 1); - Stdlib_List.get(abc, 4); - }); - Mocha.test("getAssoc", () => { - Stdlib_List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - Stdlib_List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); - }); - Mocha.test("getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Stdlib.assertEqual(Stdlib_List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = Stdlib_List.getExn(abc, 4); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Not_found") { - throw exn; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11717, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("has", () => { - Stdlib_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - Stdlib_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4, (a, b) => a === b); - Stdlib_List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); - Mocha.test("hasAssoc", () => { - Stdlib_List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Stdlib_List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); - }); - Mocha.test("head", () => { - Stdlib_List.head(/* [] */0); - Stdlib_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("headExn", () => { - Stdlib.assertEqual(Stdlib_List.headExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), 1); - let exit = 0; - let val; - try { - val = Stdlib_List.headExn(/* [] */0); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Not_found") { - throw exn; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11754, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("length", () => { - Stdlib_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("make", () => { - Stdlib_List.make(3, 1); - }); - Mocha.test("map", () => { - Stdlib_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); - Mocha.test("mapReverse", () => { - let f = x => x * x | 0; - let l = { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }; - let withMap = Stdlib_List.reverse(Stdlib_List.map(l, f)); - let withMapReverse = Stdlib_List.mapReverse(l, f); - console.log(Primitive_object.equal(withMap, withMapReverse)); - }); - Mocha.test("mapReverse2", () => { - Stdlib_List.mapReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a + b | 0); - }); - Mocha.test("mapWithIndex", () => { - Stdlib_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (x, index) => index + x | 0); - }); - Mocha.test("partition", () => { - Stdlib_List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2); - }); - Mocha.test("reduce", () => { - Stdlib_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Stdlib_List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item) => acc + item | 0); - }); - Mocha.test("reduce2", () => { - Stdlib_List.reduce2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceReverse", () => { - Stdlib_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - Stdlib_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 10, (a, b) => a - b | 0); - Stdlib_List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, /* [] */0, Stdlib_List.add); - }); - Mocha.test("reduceReverse2", () => { - Stdlib_List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + (x * x | 0) | 0) + y | 0); - }); - Mocha.test("reduceWithIndex", () => { - Stdlib_List.reduceWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item, index) => (acc + item | 0) + index | 0); - }); - Mocha.test("removeAssoc", () => { - Stdlib_List.removeAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Stdlib_List.removeAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); - }); - Mocha.test("reverse", () => { - Stdlib_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("reverseConcat", () => { - Stdlib_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); - Mocha.test("setAssoc", () => { - Stdlib_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - Stdlib_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - Stdlib_List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); - }); - Mocha.test("shuffle", () => { - Stdlib_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("size", () => { - Stdlib_List.size({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("some", () => { - let isAbove100 = value => value > 100; - Stdlib_List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - Stdlib_List.some({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isAbove100); - }); - Mocha.test("some2", () => { - Stdlib_List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - Stdlib_List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Stdlib_List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - Stdlib_List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); - Mocha.test("sort", () => { - Stdlib_List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, Primitive_int.compare); - }); - Mocha.test("splitAt", () => { - Stdlib_List.splitAt({ - hd: "Hello", - tl: { - hd: "World", - tl: /* [] */0 - } - }, 1); - Stdlib_List.splitAt({ - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - }, 2); - }); - Mocha.test("tail", () => { - Stdlib_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Stdlib_List.tail(/* [] */0); - }); - Mocha.test("tailExn", () => { - Stdlib.assertEqual(Stdlib_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }); - let exit = 0; - let val; - try { - val = Stdlib_List.tailExn(/* [] */0); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Not_found") { - throw exn; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 11943, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("take", () => { - Stdlib_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - Stdlib_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Stdlib_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); - Mocha.test("toArray", () => { - Stdlib_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("toShuffled", () => { - Stdlib_List.toShuffled({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("unzip", () => { - Stdlib_List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - Stdlib_List.unzip({ - hd: [ - "H", - "W" - ], - tl: { - hd: [ - "e", - "o" - ], - tl: { - hd: [ - "l", - "r" - ], - tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } - } - } - } - }); - }); - Mocha.test("zip", () => { - Stdlib_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); - Mocha.test("zipBy", () => { - Stdlib_List.zipBy({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, (a, b) => (a << 1) + b | 0); - }); -}); - -Mocha.describe("Stdlib.Map", () => { - Mocha.test("clear", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.clear(); - }); - Mocha.test("delete", () => { - let map = new Map(); - map.set("someKey", "someValue"); - let didDeleteKey = map.delete("someKey"); - console.log(didDeleteKey); - let didDeleteKey$1 = map.delete("someNonExistantKey"); - console.log(didDeleteKey$1); - }); - Mocha.test("entries", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("anotherKey", "anotherValue"); - let entries = map.entries(); - console.log(entries.next().value); - console.log(Array.from(map.entries())); - }); - Mocha.test("forEach", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach(value => { - console.log(value); - }); - }); - Mocha.test("forEachWithKey", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach((value, key) => { - console.log(value, key); - }); - }); - Mocha.test("fromArray", () => { - let languageRank = [ - [ - "ReScript", - 1 - ], - [ - "JavaScript", - 2 - ], - [ - "TypeScript", - 3 - ] - ]; - let map = new Map(languageRank); - let match = map.get("ReScript"); - if (match === 1) { - console.log("Yay, ReScript is #1!"); - } else { - console.log("Uh-oh, something is _terribly_ wrong with this program... abort."); - } - }); - Mocha.test("fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Stdlib.assertEqual(new Map(iterator).size, 2); - }); - Mocha.test("get", () => { - let map = new Map(); - map.set("someKey", "someValue"); - let value = map.get("someKey"); - if (value !== undefined) { - console.log("Yay, had the value, and it's:", value); - } else { - console.log("Nope, didn't have it."); - } - }); - Mocha.test("has", () => { - let map = new Map(); - map.set("someKey", "someValue"); - if (map.has("someKey")) { - console.log("Yay, we have the value!"); - } else { - console.log("Nope, didn't have it."); - } - }); - Mocha.test("keys", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("anotherKey", "anotherValue"); - let keys = map.keys(); - console.log(keys.next().value); - console.log(Array.from(map.keys())); - }); - Mocha.test("make", () => { - new Map(); - let map = new Map(); - map.set("lang", "ReScript"); - }); - Mocha.test("set", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); - Mocha.test("size", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); - Mocha.test("values", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("anotherKey", "anotherValue"); - let values = map.values(); - console.log(values.next().value); - console.log(Array.from(map.values())); - }); -}); - -Mocha.describe("Stdlib.Math", () => { - Mocha.test("abs", () => { - Math.abs(-2.0); - Math.abs(3.0); - }); - Mocha.test("acos", () => { - Math.acos(-1.0); - isNaN(Math.acos(-3.0)); - }); - Mocha.test("acosh", () => { - Math.acosh(1.0); - isNaN(Math.acosh(0.5)); - }); - Mocha.test("asin", () => { - Math.asin(-1.0); - isNaN(Math.asin(-2.0)); - }); - Mocha.test("asinh", () => { - Math.asinh(-1.0); - Math.asinh(-0.0); - }); - Mocha.test("atan", () => { - Math.atan(-0.0); - Math.atan(0.0); - Math.atan(1.0); - }); - Mocha.test("atan2", () => { - Math.atan2(0.0, 10.0) === 0.0; - Math.atan2(5.0, 5.0) === Math.PI / 4.0; - Math.atan2(15.0, 90.0); - Math.atan2(90.0, 15.0); - }); - Mocha.test("atanh", () => { - isNaN(Math.atanh(-2.0)); - isFinite(Math.atanh(-1.0)); - Math.atanh(-0.0); - Math.atanh(0.0); - Math.atanh(0.5); - }); - Mocha.test("cbrt", () => { - Math.cbrt(-1.0); - Math.cbrt(-0.0); - Math.cbrt(0.0); - }); - Mocha.test("ceil", () => { - Math.ceil(3.1) === 4.0; - Math.ceil(3.0) === 3.0; - Math.ceil(-3.1) === -3.0; - Math.ceil(2150000000.3) === 2150000001.0; - }); - Mocha.test("cos", () => { - Math.cos(-0.0); - Math.cos(0.0); - Math.cos(1.0); - }); - Mocha.test("cosh", () => { - Math.cosh(-1.0); - Math.cosh(-0.0); - Math.cosh(0.0); - }); - Mocha.test("exp", () => { - Math.exp(-1.0); - Math.exp(0.0); - }); - Mocha.test("expm1", () => { - Math.expm1(-1.0); - Math.expm1(-0.0); - }); - Mocha.test("floor", () => { - Math.floor(-45.95); - Math.floor(-45.05); - Math.floor(-0.0); - }); - Mocha.test("fround", () => { - Math.fround(5.5) === 5.5; - Math.fround(5.05) === 5.050000190734863; - }); - Mocha.test("hypot", () => { - Math.hypot(3.0, 4.0); - Math.hypot(3.0, 5.0); - }); - Mocha.test("hypotMany", () => { - Math.hypot(3.0, 4.0, 5.0); - Math.hypot(); - }); - Mocha.test("log", () => { - isNaN(Math.log(-1.0)); - isFinite(Math.log(-0.0)); - isFinite(Math.log(0.0)); - Math.log(1.0); - }); - Mocha.test("log10", () => { - isNaN(Math.log10(-2.0)); - isFinite(Math.log10(-0.0)); - isFinite(Math.log10(0.0)); - Math.log10(1.0); - }); - Mocha.test("log1p", () => { - isNaN(Math.log1p(-2.0)); - isFinite(Math.log1p(-1.0)); - Math.log1p(-0.0); - }); - Mocha.test("log2", () => { - isNaN(Math.log2(-2.0)); - isFinite(Math.log2(-0.0)); - isFinite(Math.log2(0.0)); - Math.log2(1.0); - }); - Mocha.test("max", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - }); - Mocha.test("maxMany", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - isFinite(Math.max()); - }); - Mocha.test("min", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - }); - Mocha.test("minMany", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - isFinite(Math.min()); - }); - Mocha.test("pow", () => { - Math.pow(2.0, 4.0); - Math.pow(3.0, 4.0); - }); - Mocha.test("random", () => { - Math.random(); - }); - Mocha.test("round", () => { - Math.round(-20.5); - Math.round(-0.1); - Math.round(0.0); - Math.round(-0.0); - }); - Mocha.test("sign", () => { - Math.sign(3.0); - Math.sign(-3.0); - Math.sign(0.0); - }); - Mocha.test("sin", () => { - Math.sin(-0.0); - Math.sin(0.0); - Math.sin(1.0); - }); - Mocha.test("sinh", () => { - Math.sinh(-0.0); - Math.sinh(0.0); - Math.sinh(1.0); - }); - Mocha.test("sqrt", () => { - isNaN(Math.sqrt(-1.0)); - Math.sqrt(-0.0); - Math.sqrt(0.0); - Math.sqrt(1.0); - Math.sqrt(9.0); - }); - Mocha.test("tan", () => { - Math.tan(-0.0); - Math.tan(0.0); - Math.tan(1.0); - }); - Mocha.test("tanh", () => { - Math.tanh(-0.0); - Math.tanh(0.0); - Math.tanh(1.0); - }); - Mocha.test("trunc", () => { - Math.trunc(0.123); - Math.trunc(1.999); - Math.trunc(13.37); - Math.trunc(42.84); - }); -}); - -Mocha.describe("Stdlib.Math.Constants", () => { - Mocha.test("e", () => {}); - Mocha.test("ln10", () => {}); - Mocha.test("ln2", () => {}); - Mocha.test("log10e", () => {}); - Mocha.test("log2e", () => {}); - Mocha.test("pi", () => {}); - Mocha.test("sqrt1_2", () => {}); - Mocha.test("sqrt2", () => {}); -}); - -Mocha.describe("Stdlib.Math.Int", () => { - Mocha.test("abs", () => { - Math.abs(-2); - Math.abs(3); - }); - Mocha.test("ceil", () => { - Stdlib_Math.Int.ceil(3.7) === 4; - Stdlib_Math.Int.ceil(3.0) === 3; - Stdlib_Math.Int.ceil(-3.1) === -3; - }); - Mocha.test("clz32", () => { - Math.clz32(1); - Math.clz32(4); - }); - Mocha.test("floor", () => { - Stdlib_Math.Int.floor(3.7) === 3; - Stdlib_Math.Int.floor(3.0) === 3; - Stdlib_Math.Int.floor(-3.1) === -4; - }); - Mocha.test("imul", () => { - Math.imul(3, 4); - Math.imul(-5, 12); - }); - Mocha.test("max", () => { - Math.max(1, 2); - Math.max(-1, -2); - }); - Mocha.test("maxMany", () => { - Math.max(1, 2); - Math.max(-1, -2); - isFinite(Math.max()); - }); - Mocha.test("min", () => { - Math.min(1, 2); - Math.min(-1, -2); - }); - Mocha.test("minMany", () => { - Math.min(1, 2); - Math.min(-1, -2); - isFinite(Math.min()); - }); - Mocha.test("pow", () => { - Math.pow(2, 4); - Math.pow(3, 4); - }); - Mocha.test("random", () => { - Stdlib_Math.Int.random(2, 5) === 4; - Stdlib_Math.Int.random(505, 2000) === 1276; - Stdlib_Math.Int.random(-7, -2) === -4; - }); - Mocha.test("sign", () => { - Math.sign(3); - Math.sign(-3); - Math.sign(0); - }); -}); - -Mocha.describe("Stdlib.Null", () => { - Mocha.test("asNullable", () => {}); - Mocha.test("flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; - } - }; - Stdlib_Null.flatMap(2, addIfAboveOne); - Stdlib_Null.flatMap(-4, addIfAboveOne); - Stdlib_Null.flatMap(null, addIfAboveOne); - }); - Mocha.test("forEach", () => { - Stdlib_Null.forEach("thing", x => { - console.log(x); - }); - Stdlib_Null.forEach(null, x => { - console.log(x); - }); - }); - Mocha.test("fromOption", () => { - let asNull = Stdlib_Null.fromOption(undefined); - console.log(asNull === null); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Stdlib_Null.getExn(3), 3); - let exit = 0; - let value; - try { - value = Stdlib_Null.getExn('ReScript'); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12655, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Stdlib.assertEqual(value, "ReScript"); - } - let exit$1 = 0; - let val; - try { - val = Stdlib_Null.getExn(null); - exit$1 = 1; - } catch (raw_exn$1) { - let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); - if (exn$1.RE_EXN_ID !== "Invalid_argument") { - throw exn$1; - } - - } - if (exit$1 === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12661, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getOr", () => { - Stdlib_Null.getOr(null, "Banana"); - Stdlib_Null.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNull("Jane")); - greet(undefined); - }); - Mocha.test("getUnsafe", () => {}); - Mocha.test("make", () => {}); - Mocha.test("map", () => { - Stdlib_Null.map(3, x => x * x | 0); - Stdlib_Null.map(null, x => x * x | 0); - }); - Mocha.test("mapOr", () => { - Stdlib_Null.mapOr(3, 0, x => x + 5 | 0); - Stdlib_Null.mapOr(null, 0, x => x + 5 | 0); - }); - Mocha.test("null", () => { - console.log(null); - }); - Mocha.test("toOption", () => { - let nullStr = "Hello"; - if (nullStr !== null) { - console.log("Got string:", nullStr); - } else { - console.log("Didn't have a value."); - } - }); -}); - -Mocha.describe("Stdlib.Nullable", () => { - Mocha.test("flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; - } - }; - Stdlib_Nullable.flatMap(2, addIfAboveOne); - Stdlib_Nullable.flatMap(-4, addIfAboveOne); - Stdlib_Nullable.flatMap(null, addIfAboveOne); - }); - Mocha.test("forEach", () => { - Stdlib_Nullable.forEach("thing", x => { - console.log(x); - }); - Stdlib_Nullable.forEach(null, x => { - console.log(x); - }); - Stdlib_Nullable.forEach(undefined, x => { - console.log(x); - }); - }); - Mocha.test("fromOption", () => { - Stdlib_Nullable.fromOption("Hello"); - }); - Mocha.test("getExn", () => { - let exit = 0; - let value; - try { - value = Stdlib_Nullable.getExn('Hello'); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === "Invalid_argument") { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12762, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Stdlib.assertEqual(value, "Hello"); - } - let exit$1 = 0; - let val; - try { - val = Stdlib_Nullable.getExn(null); - exit$1 = 1; - } catch (raw_exn$1) { - let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); - if (exn$1.RE_EXN_ID !== "Invalid_argument") { - throw exn$1; - } - - } - if (exit$1 === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12768, - 7 - ], - Error: new Error() - }; - } - let exit$2 = 0; - let val$1; - try { - val$1 = Stdlib_Nullable.getExn(undefined); - exit$2 = 1; - } catch (raw_exn$2) { - let exn$2 = Primitive_exceptions.internalToException(raw_exn$2); - if (exn$2.RE_EXN_ID !== "Invalid_argument") { - throw exn$2; - } - - } - if (exit$2 === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12773, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getOr", () => { - Stdlib_Nullable.getOr(null, "Banana"); - Stdlib_Nullable.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNullable("Jane")); - greet(undefined); - }); - Mocha.test("getUnsafe", () => {}); - Mocha.test("isNullable", () => { - if ("Hello" == null) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12808, - 10 - ], - Error: new Error() - }; - } - - }); - Mocha.test("make", () => { - let myStr = "Hello"; - if ((myStr == null) || myStr !== myStr) { - console.log("Values did not match."); - } else { - console.log("Yay, values matched!"); - } - }); - Mocha.test("map", () => { - Stdlib_Nullable.map(3, x => x * x | 0); - Stdlib_Nullable.map(undefined, x => x * x | 0); - }); - Mocha.test("mapOr", () => { - Stdlib_Nullable.mapOr(3, 0, x => x + 5 | 0); - Stdlib_Nullable.mapOr(null, 0, x => x + 5 | 0); - }); - Mocha.test("null", () => { - console.log(null); - }); - Mocha.test("toOption", () => { - let nullableString = "Hello"; - if (nullableString == null) { - console.log("Didn't have a value."); - } else { - console.log("Got string:", nullableString); - } - }); - Mocha.test("undefined", () => { - console.log(undefined); - }); -}); - -Mocha.describe("Stdlib.Object", () => { - Mocha.test("assign", () => { - Object.assign({ - a: 1 - }, { - a: 2 - }); - Object.assign({ - a: 1, - b: 2 - }, { - a: 0 - }); - Object.assign({ - a: 1 - }, { - a: null - }); - }); - Mocha.test("create", () => { - let x = { - fruit: "banana" - }; - Object.create(x); - }); - Mocha.test("freeze", () => { - let obj = { - a: 1 - }; - obj["a"] = 2; - Object.freeze(obj); - try { - obj["a"] = 3; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12898, - 7 - ], - Error: new Error() - }; - } - - } - }); - Mocha.test("get", () => { - Stdlib_Option.isSome(({ - a: 1 - })["toString"]); - }); - Mocha.test("getSymbol", () => { - let fruit = Symbol("fruit"); - let x = {}; - x[fruit] = "banana"; - }); - Mocha.test("hasOwnProperty", () => { - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "a"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "b"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "toString"); - }); - Mocha.test("is", () => { - Object.is(25, 13); - Object.is("abc", "abc"); - Object.is(undefined, undefined); - Object.is(undefined, null); - Object.is(-0.0, 0.0); - Object.is({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }); - Object.is([ - 1, - 2, - 3 - ], [ - 1, - 2, - 3 - ]); - Primitive_object.equal([ - 1, - 2, - 3 - ], [ - 1, - 2, - 3 - ]); - let fruit = { - name: "Apple" - }; - Object.is(fruit, fruit); - Object.is(fruit, { - name: "Apple" - }); - Primitive_object.equal(fruit, { - name: "Apple" - }); - }); - Mocha.test("isExtensible", () => { - let obj = { - a: 1 - }; - Object.isExtensible(obj); - Object.preventExtensions(obj); - Object.isExtensible(obj); - }); - Mocha.test("isFrozen", () => { - let point = Object.freeze({ - x: 1, - y: 3 - }); - Object.isFrozen(point); - let fruit = { - name: "Apple" - }; - Object.isFrozen(fruit); - }); - Mocha.test("isSealed", () => { - let point = Object.seal({ - x: 1, - y: 3 - }); - Object.isSealed(point); - let fruit = { - name: "Apple" - }; - Object.isSealed(fruit); - }); - Mocha.test("keysToArray", () => { - Object.keys({ - a: 1, - b: 2 - }); - Object.keys({ - a: undefined - }); - Object.keys({}); - }); - Mocha.test("make", () => { - let x = {}; - Object.keys(x).length; - Stdlib_Option.isSome(x["toString"]); - }); - Mocha.test("preventExtensions", () => { - let obj = { - a: 1 - }; - obj["b"] = 2; - Object.preventExtensions(obj); - try { - obj["c"] = 3; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13004, - 7 - ], - Error: new Error() - }; - } - - } - }); - Mocha.test("seal", () => { - let point = { - x: 1, - y: 2 - }; - point["x"] = -7; - Object.seal(point); - try { - point["z"] = 9; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== Stdlib_Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13019, - 7 - ], - Error: new Error() - }; - } - - } - point["x"] = 13; - }); - Mocha.test("set", () => { - ({ - a: 1 - })["a"] = 2; - ({ - a: 1 - })["a"] = undefined; - ({ - a: 1 - })["b"] = 2; - }); -}); - -Mocha.describe("Stdlib.Option", () => { - Mocha.test("all", () => { - Stdlib_Option.all([ - 1, - 2, - 3 - ]); - Stdlib_Option.all([ - 1, - undefined - ]); - }); - Mocha.test("compare", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Stdlib_Option.compare(3, 15, clockCompare); - Stdlib_Option.compare(3, 14, clockCompare); - Stdlib_Option.compare(2, 15, clockCompare); - Stdlib_Option.compare(undefined, 15, clockCompare); - Stdlib_Option.compare(14, undefined, clockCompare); - Stdlib_Option.compare(undefined, undefined, clockCompare); - }); - Mocha.test("equal", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Stdlib_Option.equal(3, 15, clockEqual); - Stdlib_Option.equal(3, undefined, clockEqual); - Stdlib_Option.equal(undefined, 3, clockEqual); - Stdlib_Option.equal(undefined, undefined, clockEqual); - }); - Mocha.test("filter", () => { - Stdlib_Option.filter(10, x => x > 5); - Stdlib_Option.filter(4, x => x > 5); - Stdlib_Option.filter(undefined, x => x > 5); - }); - Mocha.test("flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Stdlib_Option.flatMap(2, addIfAboveOne); - Stdlib_Option.flatMap(-4, addIfAboveOne); - Stdlib_Option.flatMap(undefined, addIfAboveOne); - }); - Mocha.test("forEach", () => { - Stdlib_Option.forEach("thing", x => { - console.log(x); - }); - Stdlib_Option.forEach(undefined, x => { - console.log(x); - }); - }); - Mocha.test("getExn", () => { - Stdlib.assertEqual(Stdlib_Option.getExn(3, undefined), 3); - let exit = 0; - let val; - try { - val = Stdlib_Option.getExn(undefined, undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13105, - 7 - ], - Error: new Error() - }; - } - let exit$1 = 0; - let val$1; - try { - val$1 = Stdlib_Option.getExn(undefined, "was None!"); - exit$1 = 1; - } catch (exn$1) { - - } - if (exit$1 === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13110, - 7 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getOr", () => { - Stdlib_Option.getOr(undefined, "Banana"); - Stdlib_Option.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Stdlib_Option.getOr(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); - }); - Mocha.test("getUnsafe", () => {}); - Mocha.test("isNone", () => { - Stdlib_Option.isNone(undefined); - Stdlib_Option.isNone(1); - }); - Mocha.test("isSome", () => { - Stdlib_Option.isSome(undefined); - Stdlib_Option.isSome(1); - }); - Mocha.test("map", () => { - Stdlib_Option.map(3, x => x * x | 0); - Stdlib_Option.map(undefined, x => x * x | 0); - }); - Mocha.test("mapOr", () => { - Stdlib_Option.mapOr(3, 0, x => x + 5 | 0); - Stdlib_Option.mapOr(undefined, 0, x => x + 5 | 0); - }); - Mocha.test("orElse", () => { - Primitive_object.equal(Stdlib_Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Stdlib_Option.orElse(undefined, 1066), 1066); - Stdlib_Option.orElse(undefined, undefined) === undefined; - }); -}); - -Mocha.describe("Stdlib.Promise", () => { - Mocha.test("all", () => { - let promises = [ - Promise.resolve(1), - Promise.resolve(2), - Promise.resolve(3) - ]; - Promise.all(promises).then(results => { - results.forEach(num => { - console.log("Number: ", num); - }); - return Promise.resolve(); - }); - }); - Mocha.test("allSettled", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - let promises = [ - Promise.resolve(1), - Promise.resolve(2), - Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected promise" - }) - ]; - Promise.allSettled(promises).then(results => { - results.forEach(result => { - if (result.status === "fulfilled") { - console.log("Number: ", result.value); - return; - } - console.log(result.reason); - }); - return Promise.resolve(); - }); - }); - Mocha.test("any", () => { - let racer = (ms, name) => new Promise((resolve, param) => { - setTimeout(() => resolve(name), ms); - }); - let promises = [ - racer(1000, "Turtle"), - racer(500, "Hare"), - racer(100, "Eagle") - ]; - Promise.any(promises).then(winner => { - console.log("The winner is " + winner); - return Promise.resolve(); - }); - }); - Mocha.test("catch", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - Stdlib_Promise.$$catch(Promise.reject({ - RE_EXN_ID: SomeError, - _1: "this is an error" - }).then(param => Promise.resolve({ - TAG: "Ok", - _0: "This result will never be returned" - })), e => { - let msg; - if (e.RE_EXN_ID === SomeError) { - msg = "ReScript error occurred: " + e._1; - } else if (e.RE_EXN_ID === Stdlib_Exn.$$Error) { - let msg$1 = e._1.message; - msg = msg$1 !== undefined ? "JS exception occurred: " + msg$1 : "Some other JS value has been thrown"; - } else { - msg = "Unexpected error occurred"; - } - return Promise.resolve({ - TAG: "Error", - _0: msg - }); - }).then(result => { - let tmp; - if (result.TAG === "Ok") { - console.log("Operation successful: ", result._0); - tmp = undefined; - } else { - console.log("Operation failed: ", result._0); - tmp = undefined; - } - return Promise.resolve(tmp); - }); - }); - Mocha.test("finally", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - let isDone = { - contents: false - }; - Stdlib_Promise.$$catch(Promise.resolve(5).then(param => Promise.reject({ - RE_EXN_ID: SomeError, - _1: "test" - })).then(v => { - console.log("final result", v); - return Promise.resolve(); - }), param => { - console.log("Error handled"); - return Promise.resolve(); - }).finally(() => { - console.log("finally"); - isDone.contents = true; - }).then(() => { - console.log("isDone:", isDone.contents); - return Promise.resolve(); - }); - }); - Mocha.test("make", () => { - Stdlib_Promise.$$catch(new Promise((resolve, reject) => resolve("success")).then(str => Promise.resolve((console.log(str), undefined))), param => { - console.log("Error occurred"); - return Promise.resolve(); - }); - }); - Mocha.test("race", () => { - let racer = (ms, name) => new Promise((resolve, param) => { - setTimeout(() => resolve(name), ms); - }); - let promises = [ - racer(1000, "Turtle"), - racer(500, "Hare"), - racer(100, "Eagle") - ]; - Promise.race(promises).then(winner => { - console.log("The winner is " + winner); - return Promise.resolve(); - }); - }); - Mocha.test("reject", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - Stdlib_Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }), v => { - if (v.RE_EXN_ID === TestError) { - Stdlib.assertEqual(v._1, "some rejected value"); - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13354, - 9 - ], - Error: new Error() - }; - } - return Promise.resolve(); - }); - }); - Mocha.test("resolve", () => { - Promise.resolve(5); - }); - Mocha.test("then", () => { - Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { - console.log("Your lucky number is: ", num); - return Promise.resolve(); - }); - }); - Mocha.test("thenResolve", () => { - Promise.resolve("Anna").then(str => "Hello " + str).then(str => { - console.log(str); - }); - }); -}); - -Mocha.describe("Stdlib.RegExp.Result", () => { - Mocha.test("fullMatch", () => { - let regexp = new RegExp("(\\w+) (\\w+)"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - console.log(result[0]); - } - }); - Mocha.test("input", () => { - let regexp = new RegExp("(\\w+) (\\w+)"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - console.log(result.input); - } - }); - Mocha.test("matches", () => { - let regexp = new RegExp("(\\w+) (\\w+)"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - let match = result.slice(1); - if (match.length !== 2) { - console.log("Didn't find exactly two words..."); - } else { - let firstWord = match[0]; - let secondWord = match[1]; - console.log(firstWord, secondWord); - } - } - }); -}); - -Mocha.describe("Stdlib.RegExp", () => { - Mocha.test("exec", () => { - let regexp = new RegExp("\\w+"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - console.log(result[0]); - } - }); - Mocha.test("fromString", () => { - let regexp = new RegExp("\\w+"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - console.log(result[0]); - } - }); - Mocha.test("fromStringWithFlags", () => { - let regexp = new RegExp("\\w+", "g"); - let result = regexp.exec("ReScript is pretty cool, right?"); - if (result == null) { - console.log("Nope, no match..."); - } else { - console.log(result[0]); - } - }); - Mocha.test("global", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.global); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.global); - }); - Mocha.test("ignoreCase", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.ignoreCase); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.ignoreCase); - }); - Mocha.test("lastIndex", () => { - let regexp = new RegExp("\\w+"); - console.log(regexp.lastIndex); - regexp.exec("Many words here."); - console.log(regexp.lastIndex); - }); - Mocha.test("multiline", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.multiline); - let regexp2 = new RegExp("\\w+", "mi"); - console.log(regexp2.multiline); - }); - Mocha.test("setLastIndex", () => { - let regexp = new RegExp("\\w+"); - regexp.lastIndex = 4; - regexp.exec("Many words here."); - console.log(regexp.lastIndex); - }); - Mocha.test("source", () => { - let regexp = new RegExp("\\w+", "g"); - console.log(regexp.source); - }); - Mocha.test("sticky", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "my"); - console.log(regexp2.unicode); - }); - Mocha.test("test", () => { - let regexp = new RegExp("\\w+"); - if (regexp.test("ReScript is cool!")) { - console.log("Yay, there's a word in there."); - } - - }); - Mocha.test("unicode", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "mu"); - console.log(regexp2.unicode); - }); -}); - -Mocha.describe("Stdlib.Result", () => { - Mocha.test("all", () => { - Stdlib_Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Ok", - _0: 2 - }, - { - TAG: "Ok", - _0: 3 - } - ]); - Stdlib_Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Error", - _0: 1 - } - ]); - }); - Mocha.test("compare", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Stdlib_Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Stdlib_Result.compare({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Stdlib_Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Stdlib_Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Stdlib_Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; - }); - Mocha.test("equal", () => { - let good1 = { - TAG: "Ok", - _0: 42 - }; - let good2 = { - TAG: "Ok", - _0: 32 - }; - let bad1 = { - TAG: "Error", - _0: "invalid" - }; - let bad2 = { - TAG: "Error", - _0: "really invalid" - }; - let mod10equal = (a, b) => a % 10 === b % 10; - Stdlib_Result.equal(good1, good2, mod10equal) === true; - Stdlib_Result.equal(good1, bad1, mod10equal) === false; - Stdlib_Result.equal(bad2, good2, mod10equal) === false; - Stdlib_Result.equal(bad1, bad2, mod10equal) === true; - }); - Mocha.test("flatMap", () => { - let recip = x => { - if (x !== 0.0) { - return { - TAG: "Ok", - _0: 1.0 / x - }; - } else { - return { - TAG: "Error", - _0: "Divide by zero" - }; - } - }; - Primitive_object.equal(Stdlib_Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 - }); - Primitive_object.equal(Stdlib_Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" - }); - Primitive_object.equal(Stdlib_Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" - }); - }); - Mocha.test("forEach", () => { - Stdlib_Result.forEach({ - TAG: "Ok", - _0: 3 - }, prim => { - console.log(prim); - }); - Stdlib_Result.forEach({ - TAG: "Error", - _0: "x" - }, prim => { - console.log(prim); - }); - }); - Mocha.test("getExn", () => { - Stdlib_Result.getExn({ - TAG: "Ok", - _0: 42 - }) === 42; - let exit = 0; - let val; - try { - val = Stdlib_Result.getExn({ - TAG: "Error", - _0: "Invalid data" - }); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Not_found") { - throw exn; - } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 13658, - 9 - ], - Error: new Error() - }; - } - - }); - Mocha.test("getOr", () => { - Stdlib_Result.getOr({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Stdlib_Result.getOr({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); - Mocha.test("map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Stdlib_Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Stdlib_Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" - }); - }); - Mocha.test("mapError", () => { - let format = n => "Error code: " + n.toString(); - Stdlib_Result.mapError({ - TAG: "Error", - _0: 14 - }, format); - Stdlib_Result.mapError({ - TAG: "Ok", - _0: "abc" - }, format); - }); - Mocha.test("mapOr", () => { - Stdlib_Result.mapOr({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Stdlib_Result.mapOr({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; - }); -}); - -Mocha.describe("Stdlib.Set", () => { - Mocha.test("add", () => { - let set = new Set(); - set.add("someValue"); - }); - Mocha.test("clear", () => { - let set = new Set(); - set.add("someKey"); - set.clear(); - }); - Mocha.test("delete", () => { - let set = new Set(); - set.add("someValue"); - let didDeleteValue = set.delete("someValue"); - console.log(didDeleteValue); - let didDeleteValue$1 = set.delete("someNonExistantKey"); - console.log(didDeleteValue$1); - }); - Mocha.test("forEach", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue2"); - set.forEach(value => { - console.log(value); - }); - }); - Mocha.test("fromArray", () => { - let languageRank = [ - "ReScript", - "JavaScript", - "TypeScript" - ]; - let set = new Set(languageRank); - if (set.has("ReScript")) { - console.log("Yay, ReScript is in there!"); - } else { - console.log("Uh-oh, something is _terribly_ wrong with this program... abort."); - } - }); - Mocha.test("fromIterator", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Stdlib.assertEqual(new Set(iterator).size, 3); - }); - Mocha.test("has", () => { - let set = new Set(); - set.add("someValue"); - if (set.has("someValue")) { - console.log("Yay, we have the value!"); - } else { - console.log("Nope, didn't have it."); - } - }); - Mocha.test("make", () => { - new Set(); - let set = new Set(); - set.add("Fine name"); - }); - Mocha.test("size", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue"); - set.add("someValue2"); - }); - Mocha.test("toArray", () => { - let set = new Set([ - "apple", - "orange", - "apple", - "banana" - ]); - Array.from(set); - }); - Mocha.test("values", () => { - let set = new Set(); - set.add("someValue"); - set.add("anotherValue"); - let values = set.values(); - console.log(values.next().value); - console.log(Array.from(set.values())); - }); -}); - -Mocha.describe("Stdlib.String", () => { - Mocha.test("charAt", () => { - "ReScript".charAt(0) === "R"; - "Hello".charAt(12) === ""; - "JS".charAt(5) === ""; - }); - Mocha.test("charCodeAt", () => { - "😺".charCodeAt(0) === 55357; - Primitive_object.equal("😺".codePointAt(0), 128570); - }); - Mocha.test("codePointAt", () => { - Primitive_object.equal("¿😺?".codePointAt(1), 128570); - "abc".codePointAt(5) === undefined; - }); - Mocha.test("concat", () => { - "cow".concat("bell") === "cowbell"; - "Re".concat("Script") === "ReScript"; - }); - Mocha.test("concatMany", () => { - "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; - }); - Mocha.test("endsWith", () => { - "BuckleScript".endsWith("Script") === true; - "BuckleShoes".endsWith("Script") === false; - }); - Mocha.test("endsWithFrom", () => { - "abcd".endsWith("cd", 4) === true; - "abcde".endsWith("cd", 3) === false; - "abcde".endsWith("cde", 99) === true; - "example.dat".endsWith("ple", 7) === true; - }); - Mocha.test("fromCharCode", () => { - String.fromCharCode(65) === "A"; - String.fromCharCode(968) === "ψ"; - String.fromCharCode(54620) === "한"; - String.fromCharCode(-64568) === "ψ"; - }); - Mocha.test("fromCharCodeMany", () => { - String.fromCharCode(189, 43, 190, 61) === "½+¾="; - String.fromCharCode(65, 66, 67) === "ABC"; - }); - Mocha.test("fromCodePoint", () => { - String.fromCodePoint(65) === "A"; - String.fromCodePoint(968) === "ψ"; - String.fromCodePoint(54620) === "한"; - String.fromCodePoint(128570) === "😺"; - }); - Mocha.test("fromCodePointMany", () => { - String.fromCodePoint(54620, 44544, 128570) === "한글😺"; - }); - Mocha.test("get", () => { - Primitive_object.equal("ReScript"[0], "R"); - Primitive_object.equal("Hello"[4], "o"); - }); - Mocha.test("getUnsafe", () => {}); - Mocha.test("includes", () => { - "programmer".includes("gram") === true; - "programmer".includes("er") === true; - "programmer".includes("pro") === true; - "programmer.dat".includes("xyz") === false; - }); - Mocha.test("includesFrom", () => { - "programmer".includes("gram", 1) === true; - "programmer".includes("gram", 4) === false; - "대한민국".includes("한", 1) === true; - }); - Mocha.test("indexOf", () => { - "bookseller".indexOf("ok") === 2; - "bookseller".indexOf("sell") === 4; - "beekeeper".indexOf("ee") === 1; - "bookseller".indexOf("xyz") === -1; - }); - Mocha.test("indexOfFrom", () => { - "bookseller".indexOf("ok", 1) === 2; - "bookseller".indexOf("sell", 2) === 4; - "bookseller".indexOf("sell", 5) === -1; - }); - Mocha.test("indexOfOpt", () => { - Primitive_object.equal(Stdlib_String.indexOfOpt("bookseller", "ok"), 2); - Stdlib_String.indexOfOpt("bookseller", "xyz") === undefined; - }); - Mocha.test("lastIndexOf", () => { - "bookseller".lastIndexOf("ok") === 2; - "beekeeper".lastIndexOf("ee") === 4; - "abcdefg".lastIndexOf("xyz") === -1; - }); - Mocha.test("lastIndexOfFrom", () => { - "bookseller".lastIndexOf("ok", 6) === 2; - "beekeeper".lastIndexOf("ee", 8) === 4; - "beekeeper".lastIndexOf("ee", 3) === 1; - "abcdefg".lastIndexOf("xyz", 4) === -1; - }); - Mocha.test("lastIndexOfOpt", () => { - Primitive_object.equal(Stdlib_String.lastIndexOfOpt("bookseller", "ok"), 2); - Primitive_object.equal(Stdlib_String.lastIndexOfOpt("beekeeper", "ee"), 4); - Stdlib_String.lastIndexOfOpt("abcdefg", "xyz") === undefined; - }); - Mocha.test("length", () => {}); - Mocha.test("localeCompare", () => { - "a".localeCompare("c") < 0.0 === true; - "a".localeCompare("a") === 0.0; - }); - Mocha.test("make", () => { - String(3.5) === "3.5"; - String([ - 1, - 2, - 3 - ]) === "1,2,3"; - }); - Mocha.test("match", () => { - Primitive_object.equal(Primitive_option.fromNullable("The better bats".match(/b[aeiou]t/)), ["bet"]); - Primitive_object.equal(Primitive_option.fromNullable("The better bats".match(/b[aeiou]t/g)), [ - "bet", - "bat" - ]); - Primitive_object.equal(Primitive_option.fromNullable("Today is 2018-04-05.".match(/(\d+)-(\d+)-(\d+)/)), [ - "2018-04-05", - "2018", - "04", - "05" - ]); - Primitive_object.equal(Primitive_option.fromNullable("The optional example".match(/(foo)?(example)/)), [ - "example", - undefined, - "example" - ]); - Primitive_option.fromNullable("The large container.".match(/b[aeiou]g/)) === undefined; - }); - Mocha.test("normalize", () => { - let string1 = "\u00F1"; - let string2 = "\u006E\u0303"; - if (string1 === string2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 14036, - 0 - ], - Error: new Error() - }; - } - Stdlib.assertEqual(string1.normalize(), string2.normalize()); - }); - Mocha.test("normalizeForm", () => { - let string1 = "\uFB00"; - let string2 = "\u0066\u0066"; - console.log(string1 === string2); - let normalizeString1 = string1.normalize("NFKD"); - let normalizeString2 = string2.normalize("NFKD"); - console.log(normalizeString1 === normalizeString2); - }); - Mocha.test("padEnd", () => { - "Hello".padEnd(10, ".") === "Hello....."; - "abc".padEnd(1, "") === "abc"; - }); - Mocha.test("padStart", () => { - "abc".padStart(5, " ") === " abc"; - "abc".padStart(6, "123465") === "123abc"; - }); - Mocha.test("repeat", () => { - "ha".repeat(3) === "hahaha"; - "empty".repeat(0) === ""; - }); - Mocha.test("replace", () => { - "old string".replace("old", "new") === "new string"; - "the cat and the dog".replace("the", "this") === "this cat and the dog"; - }); - Mocha.test("replaceAll", () => { - "old old string".replaceAll("old", "new") === "new new string"; - "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; - }); - Mocha.test("replaceAllRegExp", () => { - "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; - }); - Mocha.test("replaceRegExp", () => { - "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; - }); - Mocha.test("replaceRegExpBy0Unsafe", () => { - let re = /[aeiou]/g; - let matchFn = (match, param, param$1) => match.toUpperCase(); - "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; - }); - Mocha.test("replaceRegExpBy1Unsafe", () => { - let re = /(Jony is )\d+/g; - let matchFn = (param, group1, param$1, param$2) => group1 + "41"; - "Jony is 40".replace(re, matchFn) === "Jony is 41"; - }); - Mocha.test("replaceRegExpBy2Unsafe", () => { - let re = /(\d+) times (\d+)/; - let matchFn = (param, group1, group2, param$1, param$2) => { - let match = Stdlib_Int.fromString(group1, undefined); - let match$1 = Stdlib_Int.fromString(group2, undefined); - if (match !== undefined && match$1 !== undefined) { - return (match * match$1 | 0).toString(); - } else { - return "???"; - } - }; - "7 times 6".replace(re, matchFn) === "42"; - }); - Mocha.test("search", () => { - "testing 1 2 3".search(/\d+/) === 8; - "no numbers".search(/\d+/) === -1; - }); - Mocha.test("searchOpt", () => { - Primitive_object.equal(Stdlib_String.searchOpt("testing 1 2 3", /\d+/), 8); - Stdlib_String.searchOpt("no numbers", /\d+/) === undefined; - }); - Mocha.test("slice", () => { - "abcdefg".slice(2, 5) === "cde"; - "abcdefg".slice(2, 9) === "cdefg"; - "abcdefg".slice(-4, -2) === "de"; - "abcdefg".slice(5, 1) === ""; - }); - Mocha.test("sliceToEnd", () => { - "abcdefg".slice(4) === "efg"; - "abcdefg".slice(-2) === "fg"; - "abcdefg".slice(7) === ""; - }); - Mocha.test("split", () => { - Primitive_object.equal("2018-01-02".split("-"), [ - "2018", - "01", - "02" - ]); - Primitive_object.equal("a,b,,c".split(","), [ - "a", - "b", - "", - "c" - ]); - Primitive_object.equal("good::bad as great::awful".split("::"), [ - "good", - "bad as great", - "awful" - ]); - Primitive_object.equal("has-no-delimiter".split(";"), ["has-no-delimiter"]); - }); - Mocha.test("splitAtMost", () => { - Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 3), [ - "ant", - "bee", - "cat" - ]); - Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 0), []); - Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 9), [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]); - }); - Mocha.test("splitByRegExp", () => { - Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ - "Jan", - "Feb", - "Mar" - ]); - }); - Mocha.test("splitByRegExpAtMost", () => { - Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ - "Hello", - "World.", - "How" - ]); - }); - Mocha.test("startsWith", () => { - "BuckleScript".startsWith("Buckle") === true; - "BuckleScript".startsWith("") === true; - "JavaScript".startsWith("Buckle") === false; - }); - Mocha.test("startsWithFrom", () => { - "BuckleScript".startsWith("kle", 3) === true; - "BuckleScript".startsWith("", 3) === true; - "JavaScript".startsWith("Buckle", 2) === false; - }); - Mocha.test("substring", () => { - "playground".substring(3, 6) === "ygr"; - "playground".substring(6, 3) === "ygr"; - "playground".substring(4, 12) === "ground"; - }); - Mocha.test("substringToEnd", () => { - "playground".substring(4) === "ground"; - "playground".substring(-3) === "playground"; - "playground".substring(12) === ""; - }); - Mocha.test("toLowerCase", () => { - "ABC".toLowerCase() === "abc"; - "ΣΠ".toLowerCase() === "σπ"; - "ΠΣ".toLowerCase() === "πς"; - }); - Mocha.test("toUpperCase", () => { - "abc".toUpperCase() === "ABC"; - "Straße".toUpperCase() === "STRASSE"; - "πς".toUpperCase() === "ΠΣ"; - }); - Mocha.test("trim", () => { - " abc def ".trim() === "abc def"; - "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; - }); - Mocha.test("trimEnd", () => { - " Hello world! ".trimEnd() === " Hello world!"; - " Hello world! ".trimEnd() === " Hello world!"; - }); - Mocha.test("trimStart", () => { - " Hello world! ".trimStart() === "Hello world! "; - " Hello world! ".trimStart() === "Hello world! "; - }); - Mocha.test("unsafeReplaceRegExpBy0", () => { - let re = /[aeiou]/g; - let matchFn = (match, param, param$1) => match.toUpperCase(); - "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; - }); - Mocha.test("unsafeReplaceRegExpBy1", () => { - let re = /(Jony is )\d+/g; - let matchFn = (param, group1, param$1, param$2) => group1 + "41"; - "Jony is 40".replace(re, matchFn) === "Jony is 41"; - }); - Mocha.test("unsafeReplaceRegExpBy2", () => { - let re = /(\d+) times (\d+)/; - let matchFn = (param, group1, group2, param$1, param$2) => { - let match = Stdlib_Int.fromString(group1, undefined); - let match$1 = Stdlib_Int.fromString(group2, undefined); - if (match !== undefined && match$1 !== undefined) { - return (match * match$1 | 0).toString(); - } else { - return "???"; - } - }; - "7 times 6".replace(re, matchFn) === "42"; - }); -}); - -Mocha.describe("Stdlib.Symbol", () => { - Mocha.test("description", () => { - let sym = Symbol("sym1"); - Stdlib.assertEqual(sym.description, "sym1"); - }); - Mocha.test("getFor", () => { - Stdlib.assertEqual(Symbol.for("sym1"), Symbol.for("sym1")); - }); - Mocha.test("keyFor", () => { - let globalSym = Symbol.for("sym1"); - Stdlib.assertEqual(Stdlib_Option.flatMap(globalSym, prim => prim.description), "sym1"); - }); - Mocha.test("make", () => { - Stdlib.assertEqual(Symbol("sym1").description, "sym1"); - }); - Mocha.test("toString", () => { - let sym = Symbol("sym1"); - Stdlib.assertEqual(sym.toString(), "Symbol(sym1)"); - }); -}); - -Mocha.describe("Stdlib.Type.Classify", () => { - Mocha.test("classify", () => { - let match = Stdlib_Type.Classify.classify(null); - if (typeof match !== "object" && match === "Null") { - console.log("Yup, that's null."); - } else { - console.log("This doesn't actually appear to be null..."); - } - }); -}); - -Mocha.describe("Stdlib.Type", () => { - Mocha.test("typeof", () => { - console.log("string"); - let match = "boolean"; - if (match === "boolean") { - console.log("This is a bool, yay!"); - } else { - console.log("Oh, not a bool sadly..."); - } - }); -}); - -/* Not a pure module */ From 69c184b176b5ddd5597733bc8e435de0694a31c1 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Sat, 29 Mar 2025 22:40:49 +0900 Subject: [PATCH 37/37] yarn up typescript --- .yarnrc.yml | 2 ++ package.json | 2 +- .../typescript-react-example/package.json | 2 +- yarn.lock | 20 +++++++++---------- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/.yarnrc.yml b/.yarnrc.yml index aa89ff6467..5a86a6195d 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -3,3 +3,5 @@ yarnPath: .yarn/releases/yarn-4.7.0.cjs nodeLinker: node-modules nmMode: hardlinks-global + +defaultSemverRangePrefix: "" diff --git a/package.json b/package.json index a4eab970fd..1c152114eb 100644 --- a/package.json +++ b/package.json @@ -84,7 +84,7 @@ "mocha": "10.8.2", "nyc": "15.0.0", "semver": "7.6.2", - "typescript": "5.5.3" + "typescript": "5.8.2" }, "workspaces": [ "tests/dependencies/**", diff --git a/tests/gentype_tests/typescript-react-example/package.json b/tests/gentype_tests/typescript-react-example/package.json index 8f5f0297de..721b4bf4ba 100644 --- a/tests/gentype_tests/typescript-react-example/package.json +++ b/tests/gentype_tests/typescript-react-example/package.json @@ -18,6 +18,6 @@ "@biomejs/biome": "1.9.4", "@types/react": "^18.3.3", "@types/react-dom": "^18.3.0", - "typescript": "5.5.3" + "typescript": "5.8.2" } } diff --git a/yarn.lock b/yarn.lock index 1c16e6ea60..521187df7b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -450,7 +450,7 @@ __metadata: react: "npm:^18.3.1" react-dom: "npm:^18.3.1" rescript: "workspace:^" - typescript: "npm:5.5.3" + typescript: "npm:5.8.2" languageName: unknown linkType: soft @@ -2133,7 +2133,7 @@ __metadata: mocha: "npm:10.8.2" nyc: "npm:15.0.0" semver: "npm:7.6.2" - typescript: "npm:5.5.3" + typescript: "npm:5.8.2" bin: bsc: cli/bsc.js bstracing: lib/bstracing.js @@ -2469,23 +2469,23 @@ __metadata: languageName: node linkType: hard -"typescript@npm:5.5.3": - version: 5.5.3 - resolution: "typescript@npm:5.5.3" +"typescript@npm:5.8.2": + version: 5.8.2 + resolution: "typescript@npm:5.8.2" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/f52c71ccbc7080b034b9d3b72051d563601a4815bf3e39ded188e6ce60813f75dbedf11ad15dd4d32a12996a9ed8c7155b46c93a9b9c9bad1049766fe614bbdd + checksum: 10c0/5c4f6fbf1c6389b6928fe7b8fcd5dc73bb2d58cd4e3883f1d774ed5bd83b151cbac6b7ecf11723de56d4676daeba8713894b1e9af56174f2f9780ae7848ec3c6 languageName: node linkType: hard -"typescript@patch:typescript@npm%3A5.5.3#optional!builtin": - version: 5.5.3 - resolution: "typescript@patch:typescript@npm%3A5.5.3#optional!builtin::version=5.5.3&hash=379a07" +"typescript@patch:typescript@npm%3A5.8.2#optional!builtin": + version: 5.8.2 + resolution: "typescript@patch:typescript@npm%3A5.8.2#optional!builtin::version=5.8.2&hash=5786d5" bin: tsc: bin/tsc tsserver: bin/tsserver - checksum: 10c0/911c7811d61f57f07df79c4a35f56a0f426a65426a020e5fcd792f66559f399017205f5f10255329ab5a3d8c2d1f1d19530aeceffda70758a521fae1d469432e + checksum: 10c0/5448a08e595cc558ab321e49d4cac64fb43d1fa106584f6ff9a8d8e592111b373a995a1d5c7f3046211c8a37201eb6d0f1566f15cdb7a62a5e3be01d087848e2 languageName: node linkType: hard