From 123d2b9cf03ad78e9aa46f472ce8245791029577 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 21:58:16 -0300 Subject: [PATCH 01/13] run tests with mocha --- .github/workflows/ci.yml | 3 +- scripts/test.js | 19 +- tests/docstrings_examples/DocTest.res | 195 +- tests/docstrings_examples/DocTest.res.mjs | 210 +- tests/docstrings_examples/Mocha.res | 5 + tests/docstrings_examples/Mocha.res.mjs | 2 + tests/docstrings_examples/Node.res | 7 + tests/docstrings_examples/Node.res.mjs | 3 + tests/docstrings_examples/mocha_full_test.res | 18311 +++++++++++++ .../mocha_full_test.res.mjs | 22839 ++++++++++++++++ 10 files changed, 41252 insertions(+), 342 deletions(-) create mode 100644 tests/docstrings_examples/Mocha.res create mode 100644 tests/docstrings_examples/Mocha.res.mjs create mode 100644 tests/docstrings_examples/mocha_full_test.res create mode 100644 tests/docstrings_examples/mocha_full_test.res.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9376937ac4..b097e3265f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -315,8 +315,7 @@ jobs: - name: Docstrings tests if: matrix.docstring_tests - # Ignore functions that are not available on Node 18 - run: node tests/docstrings_examples/DocTest.res.mjs --ignore-runtime-tests "Array.toReversed, Array.toSorted, Promise.withResolvers, Set.union, Set.isSupersetOf, Set.isSubsetOf, Set.isDisjointFrom, Set.intersection, Set.symmetricDifference, Set.difference" + run: node scripts/test.js -docstrings - name: Check for diffs in tests folder run: git diff --ignore-cr-at-eol --exit-code tests diff --git a/scripts/test.js b/scripts/test.js index 3b5c8ca39e..c9a008a8bb 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -34,12 +34,12 @@ if (process.argv.includes("-docstrings")) { runtimeDocstrings = true; } +// -all dont include runtimeDocstrings if (process.argv.includes("-all")) { ounitTest = true; mochaTest = true; bsbTest = true; formatTest = true; - runtimeDocstrings = true; } async function runTests() { @@ -136,14 +136,15 @@ async function runTests() { cwd: path.join(__dirname, "..", "tests/docstrings_examples"), stdio: [0, 1, 2], }); - // Ignore some tests not supported by node v18 - // cp.execSync( - // `node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")} --ignore-runtime-tests "Array.toReversed, Array.toSorted, Promise.withResolvers, Set.union, Set.isSupersetOf, Set.isSubsetOf, Set.isDisjointFrom, Set.intersection, Set.symmetricDifference, Set.difference"`, - // { - // cwd: path.join(__dirname, ".."), - // stdio: [0, 1, 2], - // }, - // ); + // Format file + cp.execSync("./cli/rescript format tests/docstrings_examples/mocha_full_test.res", { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }) + cp.execSync(`npx mocha tests/docstrings_examples/mocha_full_test.res.mjs`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); } } } diff --git a/tests/docstrings_examples/DocTest.res b/tests/docstrings_examples/DocTest.res index fa61eb599c..b059e0d6aa 100644 --- a/tests/docstrings_examples/DocTest.res +++ b/tests/docstrings_examples/DocTest.res @@ -9,24 +9,19 @@ type example = { docstrings: array, } -type error = - | ReScriptError(string) - | RuntimeError({rescript: string, js: string, error: string}) - -let bscBin = Path.join(["cli", "bsc"]) - -let parsed = Util.parseArgs({ - args: Process.argv->Array.sliceToEnd(~start=2), - options: dict{"ignore-runtime-tests": {Util.type_: "string"}}, -}) - -let ignoreRuntimeTests = switch parsed.values->Dict.get("ignore-runtime-tests") { -| Some(v) => - v - ->String.split(",") - ->Array.map(s => s->String.trim) -| None => [] -} +// Ignore some tests not supported by node v18 +let ignoreRuntimeTests = [ + "Array.toReversed", + "Array.toSorted", + "Promise.withResolvers", + "Set.union", + "Set.isSupersetOf", + "Set.isSubsetOf", + "Set.isDisjointFrom", + "Set.intersection", + "Set.symmetricDifference", + "Set.difference", +] let getOutput = buffer => buffer @@ -158,142 +153,42 @@ let extractExamples = async () => { examples } -let compileTest = async (~code) => { - // NOTE: warnings argument (-w) should be before eval (-e) argument - let args = ["-w", "-3-109-44", "-e", code] - let {stderr, stdout} = await SpawnAsync.run(~command=bscBin, ~args) - - stderr->Array.length > 0 ? Error(stderr->getOutput) : Ok(stdout->getOutput) -} - -let compileExamples = async examples => { - Console.log(`Compiling ${examples->Array.length->Int.toString} examples from docstrings...`) - - let compiled = [] - let compilationErrors = [] - - await examples->ArrayUtils.forEachAsyncInBatches(~batchSize, async example => { - // let id = example.id->String.replaceAll(".", "__") - let rescriptCode = example->getCodeBlocks - - switch await compileTest(~code=rescriptCode) { - | Ok(jsCode) => compiled->Array.push((example, rescriptCode, jsCode)) - | Error(err) => compilationErrors->Array.push((example, ReScriptError(err))) - } - }) - - (compiled, compilationErrors) -} - -let runTest = async code => { - let {stdout, stderr, code: exitCode} = await SpawnAsync.run( - ~command="node", - ~args=["-e", code, "--input-type", "commonjs"], - ~options={cwd: Process.cwd(), timeout: 2000}, - ) - - // Some expressions, like `console.error("error")` are printed to stderr, - // but exit code is 0 - let std = switch exitCode->Null.toOption { - | Some(exitCode) if exitCode == 0.0 && Array.length(stderr) > 0 => stderr->Ok - | Some(exitCode) if exitCode == 0.0 => stdout->Ok - | None | Some(_) => Error(Array.length(stderr) > 0 ? stderr : stdout) - } - - switch std { - | Ok(buf) => Ok(buf->getOutput) - | Error(buf) => Error(buf->getOutput) - } -} - -let runExamples = async compiled => { - Console.log(`Running ${compiled->Array.length->Int.toString} compiled examples...`) - - let tests = compiled->Array.filter((({id}, _, _)) => !(ignoreRuntimeTests->Array.includes(id))) - - let runtimeErrors = [] - await tests->ArrayUtils.forEachAsyncInBatches(~batchSize, async compiled => { - let (example, rescriptCode, jsCode) = compiled - - switch await runTest(jsCode) { - | Ok(_) => () - | Error(error) => - let runtimeError = RuntimeError({rescript: rescriptCode, js: jsCode, error}) - runtimeErrors->Array.push((example, runtimeError)) - } - }) - - runtimeErrors -} - -let indentOutputCode = code => { - let indent = String.repeat(" ", 2) - - code - ->String.split("\n") - ->Array.map(s => `${indent}${s}`) - ->Array.join("\n") -} - -let printErrors = errors => { - errors->Array.forEach(((example, errors)) => { - let red = s => `\x1B[1;31m${s}\x1B[0m` - let cyan = s => `\x1b[36m${s}\x1b[0m` - let kind = switch example.kind { - | "moduleAlias" => "module alias" - | other => other - } - - let a = switch errors { - | ReScriptError(error) => - let err = - error - ->String.split("\n") - // Drop line of filename - ->Array.filterWithIndex((_, i) => i !== 2) - ->Array.join("\n") - - `${"error"->red}: failed to compile examples from ${kind} ${example.id->cyan} -${err}` - | RuntimeError({rescript, js, error}) => - let indent = String.repeat(" ", 2) - - `${"runtime error"->red}: failed to run examples from ${kind} ${example.id->cyan} - -${indent}${"ReScript"->cyan} - -${rescript->indentOutputCode} - -${indent}${"Compiled Js"->cyan} - -${js->indentOutputCode} - -${indent}${"stacktrace"->red} - -${error->indentOutputCode} -` +let main = async () => { + let examples = await extractExamples() + let testsContent = + examples + ->Array.filterMap(example => { + let codeExamples = getCodeBlocks(example) + + let ignore = Array.includes(ignoreRuntimeTests, example.id) + + switch String.length(codeExamples) == 0 { + | true => None + | false => + ignore + ? None + : Some( + `describe("${example.id}", () => { + test("${example.id}", () => { + module Test = { + ${codeExamples} } - - Process.stderrWrite(a) + () }) -} +})`, + ) + } + }) + ->Array.join("\n\n") -let main = async () => { - let examples = await extractExamples() - let (compiled, compilationErrors) = await compileExamples(examples) - let runtimeErrors = await runExamples(compiled) + let dirname = url->URL.fileURLToPath->Path.dirname + let filepath = Path.join([dirname, "mocha_full_test.res"]) + let fileContent = `open Mocha +@@warning("-32-34-60-37-109-3-44") - let allErrors = Array.concat(runtimeErrors, compilationErrors) +${testsContent}` - if allErrors->Array.length > 0 { - printErrors(allErrors) - 1 - } else { - Console.log("All examples passed successfully") - 0 - } + await Fs.writeFile(filepath, fileContent) } -let exitCode = await main() - -Process.exit(exitCode) +let () = await main() diff --git a/tests/docstrings_examples/DocTest.res.mjs b/tests/docstrings_examples/DocTest.res.mjs index 5a09cd10b3..fc5cfecc12 100644 --- a/tests/docstrings_examples/DocTest.res.mjs +++ b/tests/docstrings_examples/DocTest.res.mjs @@ -3,33 +3,32 @@ import * as Fs from "fs"; import * as Os from "os"; import * as Exn from "rescript/lib/es6/Exn.js"; +import * as Url from "url"; import * as List from "rescript/lib/es6/List.js"; import * as Path from "path"; import * as $$Array from "rescript/lib/es6/Array.js"; import * as $$Error from "rescript/lib/es6/Error.js"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; -import * as Nodeutil from "node:util"; import * as ArrayUtils from "./ArrayUtils.res.mjs"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; import * as SpawnAsync from "./SpawnAsync.res.mjs"; +import * as Promises from "node:fs/promises"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js"; -let bscBin = Path.join("cli", "bsc"); - -let parsed = Nodeutil.parseArgs({ - args: process.argv.slice(2), - options: { - "ignore-runtime-tests": { - type: "string" - } - } -}); - -let v = parsed.values["ignore-runtime-tests"]; - -let ignoreRuntimeTests = v !== undefined ? v.split(",").map(s => s.trim()) : []; +let ignoreRuntimeTests = [ + "Array.toReversed", + "Array.toSorted", + "Promise.withResolvers", + "Set.union", + "Set.isSupersetOf", + "Set.isSubsetOf", + "Set.isDisjointFrom", + "Set.intersection", + "Set.symmetricDifference", + "Set.difference" +]; function getOutput(buffer) { return buffer.map(e => e.toString()).join(""); @@ -52,7 +51,7 @@ async function extractDocFromFile(file) { RE_EXN_ID: "Assert_failure", _1: [ "DocTest.res", - 48, + 43, 9 ], Error: new Error() @@ -213,174 +212,23 @@ async function extractExamples() { return examples; } -async function compileTest(code) { - let args = [ - "-w", - "-3-109-44", - "-e", - code - ]; - let match = await SpawnAsync.run(bscBin, args, undefined); - let stderr = match.stderr; - if (stderr.length > 0) { - return { - TAG: "Error", - _0: getOutput(stderr) - }; - } else { - return { - TAG: "Ok", - _0: getOutput(match.stdout) - }; - } -} - -async function compileExamples(examples) { - console.log("Compiling " + examples.length.toString() + " examples from docstrings..."); - let compiled = []; - let compilationErrors = []; - await ArrayUtils.forEachAsyncInBatches(examples, batchSize, async example => { - let rescriptCode = getCodeBlocks(example); - let jsCode = await compileTest(rescriptCode); - if (jsCode.TAG === "Ok") { - compiled.push([ - example, - rescriptCode, - jsCode._0 - ]); - return; - } - compilationErrors.push([ - example, - { - TAG: "ReScriptError", - _0: jsCode._0 - } - ]); - }); - return [ - compiled, - compilationErrors - ]; -} - -async function runTest(code) { - let match = await SpawnAsync.run("node", [ - "-e", - code, - "--input-type", - "commonjs" - ], { - cwd: process.cwd(), - timeout: 2000 - }); - let exitCode = match.code; - let stderr = match.stderr; - let stdout = match.stdout; - let std; - let exit = 0; - if (exitCode !== null) { - if (exitCode === 0.0 && stderr.length > 0) { - std = { - TAG: "Ok", - _0: stderr - }; - } else if (exitCode === 0.0) { - std = { - TAG: "Ok", - _0: stdout - }; - } else { - exit = 1; - } - } else { - exit = 1; - } - if (exit === 1) { - std = { - TAG: "Error", - _0: stderr.length > 0 ? stderr : stdout - }; - } - if (std.TAG === "Ok") { - return { - TAG: "Ok", - _0: getOutput(std._0) - }; - } else { - return { - TAG: "Error", - _0: getOutput(std._0) - }; - } -} - -async function runExamples(compiled) { - console.log("Running " + compiled.length.toString() + " compiled examples..."); - let tests = compiled.filter(param => !ignoreRuntimeTests.includes(param[0].id)); - let runtimeErrors = []; - await ArrayUtils.forEachAsyncInBatches(tests, batchSize, async compiled => { - let jsCode = compiled[2]; - let error = await runTest(jsCode); - if (error.TAG === "Ok") { +async function main() { + let examples = await extractExamples(); + let testsContent = $$Array.filterMap(examples, example => { + let codeExamples = getCodeBlocks(example); + let ignore = ignoreRuntimeTests.includes(example.id); + if (codeExamples.length === 0 || ignore) { return; - } - let runtimeError_0 = compiled[1]; - let runtimeError_2 = error._0; - let runtimeError = { - TAG: "RuntimeError", - rescript: runtimeError_0, - js: jsCode, - error: runtimeError_2 - }; - runtimeErrors.push([ - compiled[0], - runtimeError - ]); - }); - return runtimeErrors; -} - -function indentOutputCode(code) { - let indent = " ".repeat(2); - return code.split("\n").map(s => indent + s).join("\n"); -} - -function printErrors(errors) { - errors.forEach(param => { - let errors = param[1]; - let example = param[0]; - let cyan = s => "\x1b[36m" + s + "\x1b[0m"; - let other = example.kind; - let kind = other === "moduleAlias" ? "module alias" : other; - let a; - if (errors.TAG === "ReScriptError") { - let err = errors._0.split("\n").filter((param, i) => i !== 2).join("\n"); - a = "\x1B[1;31merror\x1B[0m: failed to compile examples from " + kind + " " + cyan(example.id) + "\n" + err; } else { - let indent = " ".repeat(2); - a = "\x1B[1;31mruntime error\x1B[0m: failed to run examples from " + kind + " " + cyan(example.id) + "\n\n" + indent + "\x1b[36mReScript\x1b[0m\n\n" + indentOutputCode(errors.rescript) + "\n\n" + indent + "\x1b[36mCompiled Js\x1b[0m\n\n" + indentOutputCode(errors.js) + "\n\n" + indent + "\x1B[1;31mstacktrace\x1B[0m\n\n" + indentOutputCode(errors.error) + "\n"; + return "describe(\"" + example.id + "\", () => {\n test(\"" + example.id + "\", () => {\n module Test = {\n " + codeExamples + "\n }\n ()\n })\n})"; } - process.stderr.write(a); - }); + }).join("\n\n"); + let dirname = Path.dirname(Url.fileURLToPath(import.meta.url)); + let filepath = Path.join(dirname, "mocha_full_test.res"); + let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + testsContent; + return await Promises.writeFile(filepath, fileContent); } -async function main() { - let examples = await extractExamples(); - let match = await compileExamples(examples); - let runtimeErrors = await runExamples(match[0]); - let allErrors = runtimeErrors.concat(match[1]); - if (allErrors.length > 0) { - printErrors(allErrors); - return 1; - } else { - console.log("All examples passed successfully"); - return 0; - } -} - -let exitCode = await main(); - -process.exit(exitCode); +await main(); -/* bscBin Not a pure module */ +/* batchSize Not a pure module */ diff --git a/tests/docstrings_examples/Mocha.res b/tests/docstrings_examples/Mocha.res new file mode 100644 index 0000000000..a7fc8c9ed3 --- /dev/null +++ b/tests/docstrings_examples/Mocha.res @@ -0,0 +1,5 @@ +@module("mocha") +external test: (string, unit => unit) => unit = "test" + +@module("mocha") +external describe: (string, unit => unit) => unit = "describe" diff --git a/tests/docstrings_examples/Mocha.res.mjs b/tests/docstrings_examples/Mocha.res.mjs new file mode 100644 index 0000000000..d856702bfe --- /dev/null +++ b/tests/docstrings_examples/Mocha.res.mjs @@ -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/docstrings_examples/Node.res b/tests/docstrings_examples/Node.res index a7f804b3aa..34b155ac4e 100644 --- a/tests/docstrings_examples/Node.res +++ b/tests/docstrings_examples/Node.res @@ -1,6 +1,7 @@ module Path = { @module("path") external join2: (string, string) => string = "join" @module("path") @variadic external join: array => string = "join" + @module("path") external dirname: string => string = "dirname" } module Process = { @@ -63,3 +64,9 @@ module Util = { } @module("node:util") external parseArgs: config => parsed = "parseArgs" } + +module URL = { + @module("url") external fileURLToPath: string => string = "fileURLToPath" +} + +@val @scope(("import", "meta")) external url: string = "url" diff --git a/tests/docstrings_examples/Node.res.mjs b/tests/docstrings_examples/Node.res.mjs index 46cc52f763..106c4672a2 100644 --- a/tests/docstrings_examples/Node.res.mjs +++ b/tests/docstrings_examples/Node.res.mjs @@ -15,6 +15,8 @@ let OS = {}; let Util = {}; +let URL = {}; + export { Path, Process, @@ -23,5 +25,6 @@ export { ChildProcess, OS, Util, + URL, } /* No side effect */ diff --git a/tests/docstrings_examples/mocha_full_test.res b/tests/docstrings_examples/mocha_full_test.res new file mode 100644 index 0000000000..2e0befc698 --- /dev/null +++ b/tests/docstrings_examples/mocha_full_test.res @@ -0,0 +1,18311 @@ +open Mocha +@@warning("-32-34-60-37-109-3-44") + +describe("AsyncIterator.forEach", () => { + test("AsyncIterator.forEach", () => { + module Test = { + // Let's pretend we get an async iterator returning ints from somewhere. + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + let main = async () => + await asyncIterator->AsyncIterator.forEach( + v => { + switch v { + | Some(("second", value)) => assertEqual(value, "2") + | _ => () + } + }, + ) + + main()->ignore + } + () + }) +}) + +describe("AsyncIterator.next", () => { + test("AsyncIterator.next", () => { + module Test = { + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + let processMyAsyncIterator = async () => { + // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. + let break = ref(false) + + while !break.contents { + // Await the next iterator value + let {value, done} = await asyncIterator->AsyncIterator.next + + // Exit the while loop if the iterator says it's done + break := done + + if done { + value + ->Option.isNone + ->assertEqual(true) + } + } + } + + processMyAsyncIterator()->ignore + } + () + }) +}) + +describe("AsyncIterator.done", () => { + test("AsyncIterator.done", () => { + module Test = { + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) + } + () + }) +}) + +describe("AsyncIterator.value", () => { + test("AsyncIterator.value", () => { + module Test = { + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) + } + () + }) +}) + +describe("AsyncIterator.make", () => { + test("AsyncIterator.make", () => { + module Test = { + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + { + AsyncIterator.value: Some(currentValue), + done: currentValue >= 3, + } + }, + ) + + // This will log 1, 2, 3 + let main = async () => + await asyncIterator->AsyncIterator.forEach( + value => + switch value { + | Some(value) => Console.log(value) + | None => () + }, + ) + + main()->ignore + } + () + }) +}) + +describe("Array.last", () => { + test("Array.last", () => { + module Test = { + ["Hello", "Hi", "Good bye"] + ->Array.last + ->assertEqual(Some("Good bye")) + + [] + ->Array.last + ->assertEqual(None) + } + () + }) +}) + +describe("Array.at", () => { + test("Array.at", () => { + module Test = { + ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(3)->assertEqual(None) + ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(-4)->assertEqual(None) + } + () + }) +}) + +describe("Array.findMap", () => { + test("Array.findMap", () => { + module Test = { + Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) + + Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( + Some(-6), + ) + + Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) + + Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) + } + () + }) +}) + +describe("Array.flatMapWithIndex", () => { + test("Array.flatMapWithIndex", () => { + module Test = { + type language = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.flatMapWithIndex( + (item, index) => + switch item { + | ReScript => [index] + | TypeScript => [index, index + 1] + | JavaScript => [index, index + 1, index + 2] + }, + ) + ->assertEqual([0, 1, 2, 2, 3, 4]) + } + () + }) +}) + +describe("Array.flatMap", () => { + test("Array.flatMap", () => { + module Test = { + type language = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.flatMap( + item => + switch item { + | ReScript => [1, 2, 3] + | TypeScript => [4, 5, 6] + | JavaScript => [7, 8, 9] + }, + ) + ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) + } + () + }) +}) + +describe("Array.shuffle", () => { + test("Array.shuffle", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + array->Array.shuffle + Console.log(array) + + let array2 = [1, 2, 3] + array2->Array.shuffle + + array2 + ->Array.length + ->assertEqual(3) + } + () + }) +}) + +describe("Array.toShuffled", () => { + test("Array.toShuffled", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + let shuffledArray = array->Array.toShuffled + Console.log(shuffledArray) + + Array.toShuffled([1, 2, 3]) + ->Array.length + ->assertEqual(3) + } + () + }) +}) + +describe("Array.keepSome", () => { + test("Array.keepSome", () => { + module Test = { + Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) + + Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) + + Array.keepSome([None, None, None])->assertEqual([]) + + Array.keepSome([])->assertEqual([]) + } + () + }) +}) + +describe("Array.filterMap", () => { + test("Array.filterMap", () => { + module Test = { + ["Hello", "Hi", "Good bye"] + ->Array.filterMap( + item => + switch item { + | "Hello" => Some(item->String.length) + | _ => None + }, + ) + ->assertEqual([5]) + + [1, 2, 3, 4, 5, 6] + ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) + ->assertEqual([4, 16, 36]) + + Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) + + Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) + } + () + }) +}) + +describe("Array.findIndexOpt", () => { + test("Array.findIndexOpt", () => { + module Test = { + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.findIndexOpt(item => item == ReScript) + ->assertEqual(Some(0)) + } + () + }) +}) + +describe("Array.setUnsafe", () => { + test("Array.setUnsafe", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + array->Array.setUnsafe(1, "Hello") + + assertEqual(array[1], Some("Hello")) + } + () + }) +}) + +describe("Array.unsafe_get", () => { + test("Array.unsafe_get", () => { + module Test = { + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.unsafe_get(index) + Console.log(value) + } + } + () + }) +}) + +describe("Array.getUnsafe", () => { + test("Array.getUnsafe", () => { + module Test = { + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.getUnsafe(index) + Console.log(value) + } + } + () + }) +}) + +describe("Array.set", () => { + test("Array.set", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + array->Array.set(1, "Hello") + + array[1]->assertEqual(Some("Hello")) + } + () + }) +}) + +describe("Array.get", () => { + test("Array.get", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + + array + ->Array.get(0) + ->assertEqual(Some("Hello")) + + array + ->Array.get(3) + ->assertEqual(None) + } + () + }) +}) + +describe("Array.someWithIndex", () => { + test("Array.someWithIndex", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + + array + ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) + ->assertEqual(true) + } + () + }) +}) + +describe("Array.some", () => { + test("Array.some", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + + array + ->Array.some(greeting => greeting === "Hello") + ->assertEqual(true) + } + () + }) +}) + +describe("Array.reduceRightWithIndex", () => { + test("Array.reduceRightWithIndex", () => { + module Test = { + Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceRightWithIndex( + [], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{}) + } + () + }) +}) + +describe("Array.reduceRight", () => { + test("Array.reduceRight", () => { + module Test = { + Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") + + Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) + + Array.reduceRight([], list{}, List.add)->assertEqual(list{}) + } + () + }) +}) + +describe("Array.reduceWithIndex", () => { + test("Array.reduceWithIndex", () => { + module Test = { + Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceWithIndex( + [1, 2, 3], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{5, 3, 1}) + + Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) + } + () + }) +}) + +describe("Array.reduce", () => { + test("Array.reduce", () => { + module Test = { + Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) + + Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") + + [1, 2, 3] + ->Array.reduce(list{}, List.add) + ->assertEqual(list{3, 2, 1}) + + Array.reduce([], list{}, List.add)->assertEqual(list{}) + } + () + }) +}) + +describe("Array.mapWithIndex", () => { + test("Array.mapWithIndex", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = + array->Array.mapWithIndex( + (greeting, index) => greeting ++ " at position " ++ Int.toString(index), + ) + + assertEqual( + mappedArray, + ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], + ) + } + () + }) +}) + +describe("Array.map", () => { + test("Array.map", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = array->Array.map(greeting => greeting ++ " to you") + + assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) + } + () + }) +}) + +describe("Array.forEachWithIndex", () => { + test("Array.forEachWithIndex", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + + array->Array.forEachWithIndex( + (item, index) => { + Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) + }, + ) + } + () + }) +}) + +describe("Array.forEach", () => { + test("Array.forEach", () => { + module Test = { + let array = ["Hello", "Hi", "Good bye"] + + array->Array.forEach( + item => { + Console.log(item) + }, + ) + } + () + }) +}) + +describe("Array.findIndexWithIndex", () => { + test("Array.findIndexWithIndex", () => { + module Test = { + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, JavaScript] + + let isReScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) + let isTypeScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) + + assertEqual(isReScriptFirst, 0) + assertEqual(isTypeScriptFirst, -1) + } + () + }) +}) + +describe("Array.findIndex", () => { + test("Array.findIndex", () => { + module Test = { + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, JavaScript] + + array + ->Array.findIndex(item => item == ReScript) + ->assertEqual(0) + + array + ->Array.findIndex(item => item == TypeScript) + ->assertEqual(-1) + } + () + }) +}) + +describe("Array.findWithIndex", () => { + test("Array.findWithIndex", () => { + module Test = { + type languages = ReScript | TypeScript | JavaScript + + let array = [TypeScript, JavaScript, ReScript] + + array + ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) + ->assertEqual(Some(ReScript)) + } + () + }) +}) + +describe("Array.find", () => { + test("Array.find", () => { + module Test = { + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.find(item => item == ReScript) + ->assertEqual(Some(ReScript)) + } + () + }) +}) + +describe("Array.filterWithIndex", () => { + test("Array.filterWithIndex", () => { + module Test = { + [1, 2, 3, 4] + ->Array.filterWithIndex((num, index) => index === 0 || num === 2) + ->assertEqual([1, 2]) + } + () + }) +}) + +describe("Array.filter", () => { + test("Array.filter", () => { + module Test = { + [1, 2, 3, 4] + ->Array.filter(num => num > 2) + ->assertEqual([3, 4]) + } + () + }) +}) + +describe("Array.everyWithIndex", () => { + test("Array.everyWithIndex", () => { + module Test = { + let array = [1, 2, 3, 4] + + array + ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) + ->assertEqual(true) + + array + ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) + ->assertEqual(false) + } + () + }) +}) + +describe("Array.every", () => { + test("Array.every", () => { + module Test = { + let array = [1, 2, 3, 4] + + array + ->Array.every(num => num <= 4) + ->assertEqual(true) + + array + ->Array.every(num => num === 1) + ->assertEqual(false) + } + () + }) +}) + +describe("Array.toString", () => { + test("Array.toString", () => { + module Test = { + [1, 2, 3, 4] + ->Array.toString + ->assertEqual("1,2,3,4") + } + () + }) +}) + +describe("Array.copy", () => { + test("Array.copy", () => { + module Test = { + let myArray = [1, 2, 3] + let copyOfMyArray = myArray->Array.copy + + copyOfMyArray->assertEqual([1, 2, 3]) + assertEqual(myArray === copyOfMyArray, false) + } + () + }) +}) + +describe("Array.sliceToEnd", () => { + test("Array.sliceToEnd", () => { + module Test = { + [1, 2, 3, 4] + ->Array.sliceToEnd(~start=1) + ->assertEqual([2, 3, 4]) + } + () + }) +}) + +describe("Array.slice", () => { + test("Array.slice", () => { + module Test = { + [1, 2, 3, 4] + ->Array.slice(~start=1, ~end=3) + ->assertEqual([2, 3]) + } + () + }) +}) + +describe("Array.joinWithUnsafe", () => { + test("Array.joinWithUnsafe", () => { + module Test = { + [1, 2, 3] + ->Array.joinWithUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") + } + () + }) +}) + +describe("Array.joinUnsafe", () => { + test("Array.joinUnsafe", () => { + module Test = { + [1, 2, 3] + ->Array.joinUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") + } + () + }) +}) + +describe("Array.joinWith", () => { + test("Array.joinWith", () => { + module Test = { + ["One", "Two", "Three"] + ->Array.joinWith(" -- ") + ->assertEqual("One -- Two -- Three") + } + () + }) +}) + +describe("Array.join", () => { + test("Array.join", () => { + module Test = { + ["One", "Two", "Three"] + ->Array.join(" -- ") + ->assertEqual("One -- Two -- Three") + } + () + }) +}) + +describe("Array.indexOfOpt", () => { + test("Array.indexOfOpt", () => { + module Test = { + [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) + [1, 2]->Array.indexOfOpt(3)->assertEqual(None) + [{"language": "ReScript"}] + ->Array.indexOfOpt({"language": "ReScript"}) + ->assertEqual(None) // None, because of strict equality + } + () + }) +}) + +describe("Array.indexOf", () => { + test("Array.indexOf", () => { + module Test = { + [1, 2]->Array.indexOf(2)->assertEqual(1) + [1, 2]->Array.indexOf(3)->assertEqual(-1) + + [{"language": "ReScript"}] + ->Array.indexOf({"language": "ReScript"}) + ->assertEqual(-1) // -1, because of strict equality + } + () + }) +}) + +describe("Array.includes", () => { + test("Array.includes", () => { + module Test = { + [1, 2]->Array.includes(1)->assertEqual(true) + [1, 2]->Array.includes(3)->assertEqual(false) + + [{"language": "ReScript"}] + ->Array.includes({"language": "ReScript"}) + ->assertEqual(false) // false, because of strict equality + } + () + }) +}) + +describe("Array.flat", () => { + test("Array.flat", () => { + module Test = { + [[1], [2], [3, 4]] + ->Array.flat + ->assertEqual([1, 2, 3, 4]) + } + () + }) +}) + +describe("Array.concatMany", () => { + test("Array.concatMany", () => { + module Test = { + let array1 = ["hi", "hello"] + let array2 = ["yay"] + let array3 = ["wehoo"] + + let someArray = array1->Array.concatMany([array2, array3]) + + Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] + } + () + }) +}) + +describe("Array.concat", () => { + test("Array.concat", () => { + module Test = { + let array1 = ["hi", "hello"] + let array2 = ["yay", "wehoo"] + + let someArray = array1->Array.concat(array2) + + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) + } + () + }) +}) + +describe("Array.unshiftMany", () => { + test("Array.unshiftMany", () => { + module Test = { + let someArray = ["hi", "hello"] + someArray->Array.unshiftMany(["yay", "wehoo"]) + someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) + } + () + }) +}) + +describe("Array.unshift", () => { + test("Array.unshift", () => { + module Test = { + let someArray = ["hi", "hello"] + someArray->Array.unshift("yay") + someArray->assertEqual(["yay", "hi", "hello"]) + } + () + }) +}) + +describe("Array.sort", () => { + test("Array.sort", () => { + module Test = { + let array = [3, 2, 1] + array->Array.sort((a, b) => float(a - b)) + array->assertEqual([1, 2, 3]) + } + () + }) +}) + +describe("Array.shift", () => { + test("Array.shift", () => { + module Test = { + let someArray = ["hi", "hello"] + + someArray + ->Array.shift + ->assertEqual(Some("hi")) + + someArray->assertEqual(["hello"]) // Notice first item is gone. + } + () + }) +}) + +describe("Array.reverse", () => { + test("Array.reverse", () => { + module Test = { + let someArray = ["hi", "hello"] + someArray->Array.reverse + + someArray->assertEqual(["hello", "hi"]) + } + () + }) +}) + +describe("Array.pushMany", () => { + test("Array.pushMany", () => { + module Test = { + let someArray = ["hi", "hello"] + + someArray->Array.pushMany(["yay", "wehoo"]) + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) + } + () + }) +}) + +describe("Array.push", () => { + test("Array.push", () => { + module Test = { + let someArray = ["hi", "hello"] + + someArray->Array.push("yay") + + someArray->assertEqual(["hi", "hello", "yay"]) + } + () + }) +}) + +describe("Array.pop", () => { + test("Array.pop", () => { + module Test = { + let someArray = ["hi", "hello"] + + someArray + ->Array.pop + ->assertEqual(Some("hello")) + + someArray->assertEqual(["hi"]) // Notice last item is gone. + } + () + }) +}) + +describe("Array.fill", () => { + test("Array.fill", () => { + module Test = { + let myArray = [1, 2, 3, 4] + + myArray->Array.fill(9, ~start=1, ~end=3) + + myArray->assertEqual([1, 9, 9, 4]) + } + () + }) +}) + +describe("Array.fillToEnd", () => { + test("Array.fillToEnd", () => { + module Test = { + let myArray = [1, 2, 3, 4] + myArray->Array.fillToEnd(9, ~start=1) + myArray->assertEqual([1, 9, 9, 9]) + } + () + }) +}) + +describe("Array.fillAll", () => { + test("Array.fillAll", () => { + module Test = { + let myArray = [1, 2, 3, 4] + myArray->Array.fillAll(9) + myArray->assertEqual([9, 9, 9, 9]) + } + () + }) +}) + +describe("Array.length", () => { + test("Array.length", () => { + module Test = { + let someArray = ["hi", "hello"] + + someArray + ->Array.length + ->assertEqual(2) + } + () + }) +}) + +describe("Array.fromInitializer", () => { + test("Array.fromInitializer", () => { + module Test = { + Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) + + Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) + } + () + }) +}) + +describe("Array.make", () => { + test("Array.make", () => { + module Test = { + Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) + Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) + } + () + }) +}) + +describe("Array.fromIterator", () => { + test("Array.fromIterator", () => { + module Test = { + Map.fromArray([("foo", 1), ("bar", 2)]) + ->Map.values + ->Array.fromIterator + ->assertEqual([1, 2]) + } + () + }) +}) + +describe("Belt_Float./", () => { + test("Belt_Float./", () => { + module Test = { + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) + } + () + }) +}) + +describe("Belt_Float.*", () => { + test("Belt_Float.*", () => { + module Test = { + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) + } + () + }) +}) + +describe("Belt_Float.-", () => { + test("Belt_Float.-", () => { + module Test = { + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) + } + () + }) +}) + +describe("Belt_Float.+", () => { + test("Belt_Float.+", () => { + module Test = { + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) + } + () + }) +}) + +describe("Belt_Float.toString", () => { + test("Belt_Float.toString", () => { + module Test = { + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ + } + () + }) +}) + +describe("Belt_Float.fromString", () => { + test("Belt_Float.fromString", () => { + module Test = { + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + } + () + }) +}) + +describe("Belt_Float.fromInt", () => { + test("Belt_Float.fromInt", () => { + module Test = { + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + } + () + }) +}) + +describe("Belt_Float.toInt", () => { + test("Belt_Float.toInt", () => { + module Test = { + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + } + () + }) +}) + +describe("Belt_Array.truncateToLengthUnsafe", () => { + test("Belt_Array.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt_Array.eq", () => { + test("Belt_Array.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt_Array.cmp", () => { + test("Belt_Array.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt_Array.some2", () => { + test("Belt_Array.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_Array.every2", () => { + test("Belt_Array.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_Array.every", () => { + test("Belt_Array.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_Array.some", () => { + test("Belt_Array.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_Array.joinWith", () => { + test("Belt_Array.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt_Array.reduceWithIndex", () => { + test("Belt_Array.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt_Array.reduceReverse2", () => { + test("Belt_Array.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt_Array.reduceReverse", () => { + test("Belt_Array.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt_Array.reduce", () => { + test("Belt_Array.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt_Array.partition", () => { + test("Belt_Array.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt_Array.mapWithIndex", () => { + test("Belt_Array.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt_Array.forEachWithIndex", () => { + test("Belt_Array.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt_Array.keepMap", () => { + test("Belt_Array.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt_Array.keepWithIndex", () => { + test("Belt_Array.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt_Array.getIndexBy", () => { + test("Belt_Array.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_Array.getBy", () => { + test("Belt_Array.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_Array.flatMap", () => { + test("Belt_Array.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt_Array.map", () => { + test("Belt_Array.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt_Array.forEach", () => { + test("Belt_Array.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt_Array.blit", () => { + test("Belt_Array.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt_Array.fill", () => { + test("Belt_Array.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt_Array.sliceToEnd", () => { + test("Belt_Array.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt_Array.slice", () => { + test("Belt_Array.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt_Array.concatMany", () => { + test("Belt_Array.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt_Array.concat", () => { + test("Belt_Array.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt_Array.unzip", () => { + test("Belt_Array.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt_Array.zipBy", () => { + test("Belt_Array.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt_Array.zip", () => { + test("Belt_Array.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt_Array.makeBy", () => { + test("Belt_Array.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt_Array.rangeBy", () => { + test("Belt_Array.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt_Array.range", () => { + test("Belt_Array.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt_Array.makeUninitializedUnsafe", () => { + test("Belt_Array.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt_Array.makeUninitialized", () => { + test("Belt_Array.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt_Array.reverse", () => { + test("Belt_Array.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_Array.reverseInPlace", () => { + test("Belt_Array.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_Array.get", () => { + test("Belt_Array.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt_Array.length", () => { + test("Belt_Array.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Belt_HashMap.logStats", () => { + test("Belt_HashMap.logStats", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.logStats(hMap) + } + () + }) +}) + +describe("Belt_HashMap.getBucketHistogram", () => { + test("Belt_HashMap.getBucketHistogram", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.getBucketHistogram(hMap) + } + () + }) +}) + +describe("Belt_HashMap.mergeMany", () => { + test("Belt_HashMap.mergeMany", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + } + () + }) +}) + +describe("Belt_HashMap.fromArray", () => { + test("Belt_HashMap.fromArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + } + () + }) +}) + +describe("Belt_HashMap.valuesToArray", () => { + test("Belt_HashMap.valuesToArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + } + () + }) +}) + +describe("Belt_HashMap.keysToArray", () => { + test("Belt_HashMap.keysToArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keysToArray(s0) == [1, 2] + } + () + }) +}) + +describe("Belt_HashMap.toArray", () => { + test("Belt_HashMap.toArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + } + () + }) +}) + +describe("Belt_HashMap.size", () => { + test("Belt_HashMap.size", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.size(s0) == 2 + } + () + }) +}) + +describe("Belt_HashMap.keepMapInPlace", () => { + test("Belt_HashMap.keepMapInPlace", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + } + () + }) +}) + +describe("Belt_HashMap.reduce", () => { + test("Belt_HashMap.reduce", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") + } + () + }) +}) + +describe("Belt_HashMap.forEach", () => { + test("Belt_HashMap.forEach", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") + } + () + }) +}) + +describe("Belt_HashMap.remove", () => { + test("Belt_HashMap.remove", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false + } + () + }) +}) + +describe("Belt_HashMap.has", () => { + test("Belt_HashMap.has", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false + } + () + }) +}) + +describe("Belt_HashMap.get", () => { + test("Belt_HashMap.get", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None + } + () + }) +}) + +describe("Belt_HashMap.copy", () => { + test("Belt_HashMap.copy", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + } + () + }) +}) + +describe("Belt_HashMap.set", () => { + test("Belt_HashMap.set", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + } + () + }) +}) + +describe("Belt_HashMap.isEmpty", () => { + test("Belt_HashMap.isEmpty", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + } + () + }) +}) + +describe("Belt_HashMap.clear", () => { + test("Belt_HashMap.clear", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true + } + () + }) +}) + +describe("Belt_HashMap.make", () => { + test("Belt_HashMap.make", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(hMap, 0, "a") + } + () + }) +}) + +describe("Belt.Map.Dict.findFirstBy", () => { + test("Belt.Map.Dict.findFirstBy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + } + () + }) +}) + +describe("Belt.Map.String.findFirstBy", () => { + test("Belt.Map.String.findFirstBy", () => { + module Test = { + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) + } + () + }) +}) + +describe("Belt.Map.Int.findFirstBy", () => { + test("Belt.Map.Int.findFirstBy", () => { + module Test = { + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) + } + () + }) +}) + +describe("Belt.Set.Dict.split", () => { + test("Belt.Set.Dict.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ + } + () + }) +}) + +describe("Belt.Set.Dict.get", () => { + test("Belt.Set.Dict.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + } + () + }) +}) + +describe("Belt.Set.Dict.maxUndefined", () => { + test("Belt.Set.Dict.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ + } + () + }) +}) + +describe("Belt.Set.Dict.maximum", () => { + test("Belt.Set.Dict.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ + } + () + }) +}) + +describe("Belt.Set.Dict.minUndefined", () => { + test("Belt.Set.Dict.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ + } + () + }) +}) + +describe("Belt.Set.Dict.minimum", () => { + test("Belt.Set.Dict.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ + } + () + }) +}) + +describe("Belt.Set.Dict.toArray", () => { + test("Belt.Set.Dict.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt.Set.Dict.toList", () => { + test("Belt.Set.Dict.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt.Set.Dict.size", () => { + test("Belt.Set.Dict.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ + } + () + }) +}) + +describe("Belt.Set.Dict.partition", () => { + test("Belt.Set.Dict.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt.Set.Dict.keep", () => { + test("Belt.Set.Dict.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt.Set.Dict.some", () => { + test("Belt.Set.Dict.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.every", () => { + test("Belt.Set.Dict.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.reduce", () => { + test("Belt.Set.Dict.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt.Set.Dict.forEach", () => { + test("Belt.Set.Dict.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt.Set.Dict.eq", () => { + test("Belt.Set.Dict.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.subset", () => { + test("Belt.Set.Dict.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + } + () + }) +}) + +describe("Belt.Set.Dict.diff", () => { + test("Belt.Set.Dict.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ + } + () + }) +}) + +describe("Belt.Set.Dict.intersect", () => { + test("Belt.Set.Dict.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + } + () + }) +}) + +describe("Belt.Set.Dict.union", () => { + test("Belt.Set.Dict.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + } + () + }) +}) + +describe("Belt.Set.Dict.removeMany", () => { + test("Belt.Set.Dict.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ + } + () + }) +}) + +describe("Belt.Set.Dict.remove", () => { + test("Belt.Set.Dict.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.mergeMany", () => { + test("Belt.Set.Dict.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + } + () + }) +}) + +describe("Belt.Set.Dict.add", () => { + test("Belt.Set.Dict.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.has", () => { + test("Belt.Set.Dict.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt.Set.Dict.isEmpty", () => { + test("Belt.Set.Dict.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ + } + () + }) +}) + +describe("Belt.Set.Dict.fromArray", () => { + test("Belt.Set.Dict.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt.Set.Dict.empty", () => { + test("Belt.Set.Dict.empty", () => { + module Test = { + let s0 = Belt.Set.Dict.empty + } + () + }) +}) + +describe("Belt.Float./", () => { + test("Belt.Float./", () => { + module Test = { + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) + } + () + }) +}) + +describe("Belt.Float.*", () => { + test("Belt.Float.*", () => { + module Test = { + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) + } + () + }) +}) + +describe("Belt.Float.-", () => { + test("Belt.Float.-", () => { + module Test = { + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) + } + () + }) +}) + +describe("Belt.Float.+", () => { + test("Belt.Float.+", () => { + module Test = { + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) + } + () + }) +}) + +describe("Belt.Float.toString", () => { + test("Belt.Float.toString", () => { + module Test = { + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ + } + () + }) +}) + +describe("Belt.Float.fromString", () => { + test("Belt.Float.fromString", () => { + module Test = { + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + } + () + }) +}) + +describe("Belt.Float.fromInt", () => { + test("Belt.Float.fromInt", () => { + module Test = { + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + } + () + }) +}) + +describe("Belt.Float.toInt", () => { + test("Belt.Float.toInt", () => { + module Test = { + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + } + () + }) +}) + +describe("Belt.Int./", () => { + test("Belt.Int./", () => { + module Test = { + open Belt.Int + assertEqual(4 / 2, 2) + } + () + }) +}) + +describe("Belt.Int.*", () => { + test("Belt.Int.*", () => { + module Test = { + open Belt.Int + assertEqual(2 * 2, 4) + } + () + }) +}) + +describe("Belt.Int.-", () => { + test("Belt.Int.-", () => { + module Test = { + open Belt.Int + assertEqual(2 - 1, 1) + } + () + }) +}) + +describe("Belt.Int.+", () => { + test("Belt.Int.+", () => { + module Test = { + open Belt.Int + assertEqual(2 + 2, 4) + } + () + }) +}) + +describe("Belt.Int.toString", () => { + test("Belt.Int.toString", () => { + module Test = { + Belt.Int.toString(1)->assertEqual("1") + } + () + }) +}) + +describe("Belt.Int.fromString", () => { + test("Belt.Int.fromString", () => { + module Test = { + Belt.Int.fromString("1")->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt.Int.fromFloat", () => { + test("Belt.Int.fromFloat", () => { + module Test = { + Belt.Int.fromFloat(1.0)->assertEqual(1) + } + () + }) +}) + +describe("Belt.Int.toFloat", () => { + test("Belt.Int.toFloat", () => { + module Test = { + Belt.Int.toFloat(1)->assertEqual(1.0) + } + () + }) +}) + +describe("Belt.Result.cmp", () => { + test("Belt.Result.cmp", () => { + module Test = { + let good1 = Belt.Result.Ok(59) + + let good2 = Belt.Result.Ok(37) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + } + () + }) +}) + +describe("Belt.Result.eq", () => { + test("Belt.Result.eq", () => { + module Test = { + let good1 = Belt.Result.Ok(42) + + let good2 = Belt.Result.Ok(32) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 + } + () + }) +}) + +describe("Belt.Result.getWithDefault", () => { + test("Belt.Result.getWithDefault", () => { + module Test = { + Belt.Result.getWithDefault(Ok(42), 0) == 42 + + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + } + () + }) +}) + +describe("Belt.Result.flatMap", () => { + test("Belt.Result.flatMap", () => { + module Test = { + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + } + () + }) +}) + +describe("Belt.Result.map", () => { + test("Belt.Result.map", () => { + module Test = { + let f = x => sqrt(Belt.Int.toFloat(x)) + + Belt.Result.map(Ok(64), f) == Ok(8.0) + + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + } + () + }) +}) + +describe("Belt.Result.mapWithDefault", () => { + test("Belt.Result.mapWithDefault", () => { + module Test = { + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + } + () + }) +}) + +describe("Belt.Result.getExn", () => { + test("Belt.Result.getExn", () => { + module Test = { + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) + + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt.Option.cmp", () => { + test("Belt.Option.cmp", () => { + module Test = { + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) + + open Belt.Option + + cmp(Some(3), Some(15), clockCompare) /* 0 */ + + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ + } + () + }) +}) + +describe("Belt.Option.eq", () => { + test("Belt.Option.eq", () => { + module Test = { + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Belt.Option + + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ + } + () + }) +}) + +describe("Belt.Option.isNone", () => { + test("Belt.Option.isNone", () => { + module Test = { + Belt.Option.isNone(None) /* true */ + + Belt.Option.isNone(Some(1)) /* false */ + } + () + }) +}) + +describe("Belt.Option.isSome", () => { + test("Belt.Option.isSome", () => { + module Test = { + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ + } + () + }) +}) + +describe("Belt.Option.orElse", () => { + test("Belt.Option.orElse", () => { + module Test = { + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None + } + () + }) +}) + +describe("Belt.Option.getWithDefault", () => { + test("Belt.Option.getWithDefault", () => { + module Test = { + Belt.Option.getWithDefault(None, "Banana") /* Banana */ + + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ + + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ + } + () + }) +}) + +describe("Belt.Option.flatMap", () => { + test("Belt.Option.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ + + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ + } + () + }) +}) + +describe("Belt.Option.map", () => { + test("Belt.Option.map", () => { + module Test = { + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + + Belt.Option.map(None, x => x * x) /* None */ + } + () + }) +}) + +describe("Belt.Option.mapWithDefault", () => { + test("Belt.Option.mapWithDefault", () => { + module Test = { + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ + + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + } + () + }) +}) + +describe("Belt.Option.getExn", () => { + test("Belt.Option.getExn", () => { + module Test = { + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) + + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt.Option.forEach", () => { + test("Belt.Option.forEach", () => { + module Test = { + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + } + () + }) +}) + +describe("Belt.Option.keep", () => { + test("Belt.Option.keep", () => { + module Test = { + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ + } + () + }) +}) + +describe("Belt.HashMap.logStats", () => { + test("Belt.HashMap.logStats", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.logStats(hMap) + } + () + }) +}) + +describe("Belt.HashMap.getBucketHistogram", () => { + test("Belt.HashMap.getBucketHistogram", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.getBucketHistogram(hMap) + } + () + }) +}) + +describe("Belt.HashMap.mergeMany", () => { + test("Belt.HashMap.mergeMany", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + } + () + }) +}) + +describe("Belt.HashMap.fromArray", () => { + test("Belt.HashMap.fromArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + } + () + }) +}) + +describe("Belt.HashMap.valuesToArray", () => { + test("Belt.HashMap.valuesToArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + } + () + }) +}) + +describe("Belt.HashMap.keysToArray", () => { + test("Belt.HashMap.keysToArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keysToArray(s0) == [1, 2] + } + () + }) +}) + +describe("Belt.HashMap.toArray", () => { + test("Belt.HashMap.toArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + } + () + }) +}) + +describe("Belt.HashMap.size", () => { + test("Belt.HashMap.size", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.size(s0) == 2 + } + () + }) +}) + +describe("Belt.HashMap.keepMapInPlace", () => { + test("Belt.HashMap.keepMapInPlace", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + } + () + }) +}) + +describe("Belt.HashMap.reduce", () => { + test("Belt.HashMap.reduce", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") + } + () + }) +}) + +describe("Belt.HashMap.forEach", () => { + test("Belt.HashMap.forEach", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") + } + () + }) +}) + +describe("Belt.HashMap.remove", () => { + test("Belt.HashMap.remove", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false + } + () + }) +}) + +describe("Belt.HashMap.has", () => { + test("Belt.HashMap.has", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false + } + () + }) +}) + +describe("Belt.HashMap.get", () => { + test("Belt.HashMap.get", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None + } + () + }) +}) + +describe("Belt.HashMap.copy", () => { + test("Belt.HashMap.copy", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + } + () + }) +}) + +describe("Belt.HashMap.set", () => { + test("Belt.HashMap.set", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + } + () + }) +}) + +describe("Belt.HashMap.isEmpty", () => { + test("Belt.HashMap.isEmpty", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + } + () + }) +}) + +describe("Belt.HashMap.clear", () => { + test("Belt.HashMap.clear", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true + } + () + }) +}) + +describe("Belt.HashMap.make", () => { + test("Belt.HashMap.make", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(hMap, 0, "a") + } + () + }) +}) + +describe("Belt.MutableSet.split", () => { + test("Belt.MutableSet.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ + } + () + }) +}) + +describe("Belt.MutableSet.get", () => { + test("Belt.MutableSet.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ + } + () + }) +}) + +describe("Belt.MutableSet.maxUndefined", () => { + test("Belt.MutableSet.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ + } + () + }) +}) + +describe("Belt.MutableSet.maximum", () => { + test("Belt.MutableSet.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ + } + () + }) +}) + +describe("Belt.MutableSet.minUndefined", () => { + test("Belt.MutableSet.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ + } + () + }) +}) + +describe("Belt.MutableSet.minimum", () => { + test("Belt.MutableSet.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ + } + () + }) +}) + +describe("Belt.MutableSet.toArray", () => { + test("Belt.MutableSet.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt.MutableSet.toList", () => { + test("Belt.MutableSet.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt.MutableSet.size", () => { + test("Belt.MutableSet.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.size /* 4 */ + } + () + }) +}) + +describe("Belt.MutableSet.partition", () => { + test("Belt.MutableSet.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt.MutableSet.keep", () => { + test("Belt.MutableSet.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ + } + () + }) +}) + +describe("Belt.MutableSet.some", () => { + test("Belt.MutableSet.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ + } + () + }) +}) + +describe("Belt.MutableSet.every", () => { + test("Belt.MutableSet.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ + } + () + }) +}) + +describe("Belt.MutableSet.reduce", () => { + test("Belt.MutableSet.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt.MutableSet.forEach", () => { + test("Belt.MutableSet.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt.MutableSet.eq", () => { + test("Belt.MutableSet.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.MutableSet.eq(s0, s1) /* true */ + } + () + }) +}) + +describe("Belt.MutableSet.subset", () => { + test("Belt.MutableSet.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ + } + () + }) +}) + +describe("Belt.MutableSet.diff", () => { + test("Belt.MutableSet.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + } + () + }) +}) + +describe("Belt.MutableSet.intersect", () => { + test("Belt.MutableSet.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ + } + () + }) +}) + +describe("Belt.MutableSet.union", () => { + test("Belt.MutableSet.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + } + () + }) +}) + +describe("Belt.MutableSet.removeMany", () => { + test("Belt.MutableSet.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ + } + () + }) +}) + +describe("Belt.MutableSet.remove", () => { + test("Belt.MutableSet.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ + } + () + }) +}) + +describe("Belt.MutableSet.mergeMany", () => { + test("Belt.MutableSet.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + } + () + }) +}) + +describe("Belt.MutableSet.add", () => { + test("Belt.MutableSet.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) + + s0->Belt.MutableSet.toArray /* [1, 2] */ + } + () + }) +}) + +describe("Belt.MutableSet.has", () => { + test("Belt.MutableSet.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ + } + () + }) +}) + +describe("Belt.MutableSet.isEmpty", () => { + test("Belt.MutableSet.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ + } + () + }) +}) + +describe("Belt.MutableSet.copy", () => { + test("Belt.MutableSet.copy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt.MutableSet.fromArray", () => { + test("Belt.MutableSet.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt.Map.set", () => { + test("Belt.Map.set", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.set(s0, 2, "3") + + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + } + () + }) +}) + +describe("Belt.Map.remove", () => { + test("Belt.Map.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] + } + () + }) +}) + +describe("Belt.Map.get", () => { + test("Belt.Map.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") + + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None + } + () + }) +}) + +describe("Belt.Map.valuesToArray", () => { + test("Belt.Map.valuesToArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] + } + () + }) +}) + +describe("Belt.Map.keysToArray", () => { + test("Belt.Map.keysToArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] + } + () + }) +}) + +describe("Belt.Map.fromArray", () => { + test("Belt.Map.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] + } + () + }) +}) + +describe("Belt.Map.toArray", () => { + test("Belt.Map.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] + } + () + }) +}) + +describe("Belt.Map.size", () => { + test("Belt.Map.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 + } + () + }) +}) + +describe("Belt.Map.reduce", () => { + test("Belt.Map.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + } + () + }) +}) + +describe("Belt.Map.forEach", () => { + test("Belt.Map.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + let acc = ref(list{}) + + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + } + () + }) +}) + +describe("Belt.Map.findFirstBy", () => { + test("Belt.Map.findFirstBy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) + } + () + }) +}) + +describe("Belt.Map.has", () => { + test("Belt.Map.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + } + () + }) +}) + +describe("Belt.Map.isEmpty", () => { + test("Belt.Map.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + } + () + }) +}) + +describe("Belt.Map.make", () => { + test("Belt.Map.make", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let m = Belt.Map.make(~id=module(IntCmp)) + + Belt.Map.set(m, 0, "a") + } + () + }) +}) + +describe("Belt.Map.Int", () => { + test("Belt.Map.Int", () => { + module Test = { + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + } + () + }) +}) + +describe("Belt.Set.split", () => { + test("Belt.Set.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.Set.split(3) + + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) + } + () + }) +}) + +describe("Belt.Set.get", () => { + test("Belt.Set.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) + } + () + }) +}) + +describe("Belt.Set.maxUndefined", () => { + test("Belt.Set.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) + } + () + }) +}) + +describe("Belt.Set.maximum", () => { + test("Belt.Set.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.maximum->assertEqual(None) + s1->Belt.Set.maximum->assertEqual(Some(5)) + } + () + }) +}) + +describe("Belt.Set.minUndefined", () => { + test("Belt.Set.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt.Set.minimum", () => { + test("Belt.Set.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt.Set.toList", () => { + test("Belt.Set.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + } + () + }) +}) + +describe("Belt.Set.toArray", () => { + test("Belt.Set.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + } + () + }) +}) + +describe("Belt.Set.size", () => { + test("Belt.Set.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.Set.size->assertEqual(4) + } + () + }) +}) + +describe("Belt.Set.partition", () => { + test("Belt.Set.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) + + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) + } + () + }) +}) + +describe("Belt.Set.keep", () => { + test("Belt.Set.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.keep(isEven) + + s1->Belt.Set.toArray->assertEqual([2, 4]) + } + () + }) +}) + +describe("Belt.Set.some", () => { + test("Belt.Set.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) + } + () + }) +}) + +describe("Belt.Set.every", () => { + test("Belt.Set.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) + } + () + }) +}) + +describe("Belt.Set.reduce", () => { + test("Belt.Set.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) + } + () + }) +}) + +describe("Belt.Set.forEach", () => { + test("Belt.Set.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + + let acc = ref(list{}) + + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) + } + () + }) +}) + +describe("Belt.Set.eq", () => { + test("Belt.Set.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.Set.eq(s0, s1)->assertEqual(true) + } + () + }) +}) + +describe("Belt.Set.subset", () => { + test("Belt.Set.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) + + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) + } + () + }) +}) + +describe("Belt.Set.diff", () => { + test("Belt.Set.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + Belt.Set.diff(s0, s1) + ->Belt.Set.toArray + ->assertEqual([6]) + + Belt.Set.diff(s1, s0) + ->Belt.Set.toArray + ->assertEqual([1, 4]) + } + () + }) +}) + +describe("Belt.Set.intersect", () => { + test("Belt.Set.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + let intersect = Belt.Set.intersect(s0, s1) + + intersect + ->Belt.Set.toArray + ->assertEqual([2, 3, 5]) + } + () + }) +}) + +describe("Belt.Set.union", () => { + test("Belt.Set.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) + + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) + } + () + }) +}) + +describe("Belt.Set.removeMany", () => { + test("Belt.Set.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) + } + () + }) +}) + +describe("Belt.Set.remove", () => { + test("Belt.Set.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) + + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) + } + () + }) +}) + +describe("Belt.Set.mergeMany", () => { + test("Belt.Set.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) + } + () + }) +}) + +describe("Belt.Set.add", () => { + test("Belt.Set.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) + + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) + } + () + }) +}) + +describe("Belt.Set.has", () => { + test("Belt.Set.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) + } + () + }) +}) + +describe("Belt.Set.isEmpty", () => { + test("Belt.Set.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) + + Belt.Set.isEmpty(empty)->assertEqual(true) + Belt.Set.isEmpty(notEmpty)->assertEqual(false) + } + () + }) +}) + +describe("Belt.Set.fromArray", () => { + test("Belt.Set.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + } + () + }) +}) + +describe("Belt.Set.make", () => { + test("Belt.Set.make", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + Belt.Set.isEmpty(set)->assertEqual(true) + } + () + }) +}) + +describe("Belt.Range.someBy", () => { + test("Belt.Range.someBy", () => { + module Test = { + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt.Range.some", () => { + test("Belt.Range.some", () => { + module Test = { + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ + } + () + }) +}) + +describe("Belt.Range.everyBy", () => { + test("Belt.Range.everyBy", () => { + module Test = { + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt.Range.every", () => { + test("Belt.Range.every", () => { + module Test = { + Belt.Range.every(0, 4, i => i < 5) /* true */ + + Belt.Range.every(0, 4, i => i < 4) /* false */ + } + () + }) +}) + +describe("Belt.Range.forEach", () => { + test("Belt.Range.forEach", () => { + module Test = { + Belt.Range.forEach(0, 4, i => Js.log(i)) + + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 + } + () + }) +}) + +describe("Belt.List.sort", () => { + test("Belt.List.sort", () => { + module Test = { + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + } + () + }) +}) + +describe("Belt.List.setAssoc", () => { + test("Belt.List.setAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + } + () + }) +}) + +describe("Belt.List.removeAssoc", () => { + test("Belt.List.removeAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ + } + () + }) +}) + +describe("Belt.List.hasAssoc", () => { + test("Belt.List.hasAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ + } + () + }) +}) + +describe("Belt.List.getAssoc", () => { + test("Belt.List.getAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ + } + () + }) +}) + +describe("Belt.List.unzip", () => { + test("Belt.List.unzip", () => { + module Test = { + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + } + () + }) +}) + +describe("Belt.List.partition", () => { + test("Belt.List.partition", () => { + module Test = { + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) + } + () + }) +}) + +describe("Belt.List.keepMap", () => { + test("Belt.List.keepMap", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ + + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + } + () + }) +}) + +describe("Belt.List.filterWithIndex", () => { + test("Belt.List.filterWithIndex", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + } + () + }) +}) + +describe("Belt.List.keepWithIndex", () => { + test("Belt.List.keepWithIndex", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + } + () + }) +}) + +describe("Belt.List.filter", () => { + test("Belt.List.filter", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ + } + () + }) +}) + +describe("Belt.List.keep", () => { + test("Belt.List.keep", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ + } + () + }) +}) + +describe("Belt.List.getBy", () => { + test("Belt.List.getBy", () => { + module Test = { + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + } + () + }) +}) + +describe("Belt.List.has", () => { + test("Belt.List.has", () => { + module Test = { + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + } + () + }) +}) + +describe("Belt.List.eq", () => { + test("Belt.List.eq", () => { + module Test = { + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ + + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + } + () + }) +}) + +describe("Belt.List.cmp", () => { + test("Belt.List.cmp", () => { + module Test = { + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + } + () + }) +}) + +describe("Belt.List.cmpByLength", () => { + test("Belt.List.cmpByLength", () => { + module Test = { + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ + + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ + + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + } + () + }) +}) + +describe("Belt.List.some2", () => { + test("Belt.List.some2", () => { + module Test = { + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ + + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + } + () + }) +}) + +describe("Belt.List.every2", () => { + test("Belt.List.every2", () => { + module Test = { + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + } + () + }) +}) + +describe("Belt.List.some", () => { + test("Belt.List.some", () => { + module Test = { + let isAbove100 = value => value > 100 + + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + } + () + }) +}) + +describe("Belt.List.every", () => { + test("Belt.List.every", () => { + module Test = { + let isBelow10 = value => value < 10 + + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + } + () + }) +}) + +describe("Belt.List.reduceReverse2", () => { + test("Belt.List.reduceReverse2", () => { + module Test = { + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + } + () + }) +}) + +describe("Belt.List.reduce2", () => { + test("Belt.List.reduce2", () => { + module Test = { + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + } + () + }) +}) + +describe("Belt.List.forEach2", () => { + test("Belt.List.forEach2", () => { + module Test = { + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) + + /* + prints: + "Z" "A" + "Y" "B" +*/ + } + () + }) +}) + +describe("Belt.List.mapReverse2", () => { + test("Belt.List.mapReverse2", () => { + module Test = { + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + } + () + }) +}) + +describe("Belt.List.reduceReverse", () => { + test("Belt.List.reduceReverse", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} + } + () + }) +}) + +describe("Belt.List.reduceWithIndex", () => { + test("Belt.List.reduceWithIndex", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ + } + () + }) +}) + +describe("Belt.List.reduce", () => { + test("Belt.List.reduce", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + + /* same as */ + + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + } + () + }) +}) + +describe("Belt.List.forEachWithIndex", () => { + test("Belt.List.forEachWithIndex", () => { + module Test = { + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + } + () + }) +}) + +describe("Belt.List.forEach", () => { + test("Belt.List.forEach", () => { + module Test = { + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ + } + () + }) +}) + +describe("Belt.List.mapReverse", () => { + test("Belt.List.mapReverse", () => { + module Test = { + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) + } + () + }) +}) + +describe("Belt.List.reverse", () => { + test("Belt.List.reverse", () => { + module Test = { + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + } + () + }) +}) + +describe("Belt.List.toArray", () => { + test("Belt.List.toArray", () => { + module Test = { + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + } + () + }) +}) + +describe("Belt.List.fromArray", () => { + test("Belt.List.fromArray", () => { + module Test = { + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + } + () + }) +}) + +describe("Belt.List.mapWithIndex", () => { + test("Belt.List.mapWithIndex", () => { + module Test = { + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + } + () + }) +}) + +describe("Belt.List.zipBy", () => { + test("Belt.List.zipBy", () => { + module Test = { + Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + } + () + }) +}) + +describe("Belt.List.zip", () => { + test("Belt.List.zip", () => { + module Test = { + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + } + () + }) +}) + +describe("Belt.List.map", () => { + test("Belt.List.map", () => { + module Test = { + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + } + () + }) +}) + +describe("Belt.List.flatten", () => { + test("Belt.List.flatten", () => { + module Test = { + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("Belt.List.reverseConcat", () => { + test("Belt.List.reverseConcat", () => { + module Test = { + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + } + () + }) +}) + +describe("Belt.List.concatMany", () => { + test("Belt.List.concatMany", () => { + module Test = { + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("Belt.List.concat", () => { + test("Belt.List.concat", () => { + module Test = { + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + } + () + }) +}) + +describe("Belt.List.splitAt", () => { + test("Belt.List.splitAt", () => { + module Test = { + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + } + () + }) +}) + +describe("Belt.List.take", () => { + test("Belt.List.take", () => { + module Test = { + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) + + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) + + list{1, 2, 3}->Belt.List.take(4) // None + } + () + }) +}) + +describe("Belt.List.drop", () => { + test("Belt.List.drop", () => { + module Test = { + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + + list{1, 2, 3}->Belt.List.drop(4) // None + } + () + }) +}) + +describe("Belt.List.shuffle", () => { + test("Belt.List.shuffle", () => { + module Test = { + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + } + () + }) +}) + +describe("Belt.List.makeBy", () => { + test("Belt.List.makeBy", () => { + module Test = { + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + } + () + }) +}) + +describe("Belt.List.make", () => { + test("Belt.List.make", () => { + module Test = { + Belt.List.make(3, 1) // list{1, 1, 1} + } + () + }) +}) + +describe("Belt.List.getExn", () => { + test("Belt.List.getExn", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc->Belt.List.getExn(1)->assertEqual("B") + + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt.List.get", () => { + test("Belt.List.get", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc->Belt.List.get(1) // Some("B") + + abc->Belt.List.get(4) // None + } + () + }) +}) + +describe("Belt.List.add", () => { + test("Belt.List.add", () => { + module Test = { + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + } + () + }) +}) + +describe("Belt.List.tailExn", () => { + test("Belt.List.tailExn", () => { + module Test = { + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt.List.tail", () => { + test("Belt.List.tail", () => { + module Test = { + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + Belt.List.tail(list{}) // None + } + () + }) +}) + +describe("Belt.List.headExn", () => { + test("Belt.List.headExn", () => { + module Test = { + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt.List.head", () => { + test("Belt.List.head", () => { + module Test = { + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) + } + () + }) +}) + +describe("Belt.List.length", () => { + test("Belt.List.length", () => { + module Test = { + Belt.List.length(list{1, 2, 3}) // 3 + } + () + }) +}) + +describe("Belt.SortArray.binarySearchBy", () => { + test("Belt.SortArray.binarySearchBy", () => { + module Test = { + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + } + () + }) +}) + +describe("Belt.SortArray.strictlySortedLength", () => { + test("Belt.SortArray.strictlySortedLength", () => { + module Test = { + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + } + () + }) +}) + +describe("Belt.Array.truncateToLengthUnsafe", () => { + test("Belt.Array.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt.Array.eq", () => { + test("Belt.Array.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt.Array.cmp", () => { + test("Belt.Array.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt.Array.some2", () => { + test("Belt.Array.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt.Array.every2", () => { + test("Belt.Array.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt.Array.every", () => { + test("Belt.Array.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt.Array.some", () => { + test("Belt.Array.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt.Array.joinWith", () => { + test("Belt.Array.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt.Array.reduceWithIndex", () => { + test("Belt.Array.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt.Array.reduceReverse2", () => { + test("Belt.Array.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt.Array.reduceReverse", () => { + test("Belt.Array.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt.Array.reduce", () => { + test("Belt.Array.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt.Array.partition", () => { + test("Belt.Array.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt.Array.mapWithIndex", () => { + test("Belt.Array.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt.Array.forEachWithIndex", () => { + test("Belt.Array.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt.Array.keepMap", () => { + test("Belt.Array.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt.Array.keepWithIndex", () => { + test("Belt.Array.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt.Array.getIndexBy", () => { + test("Belt.Array.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt.Array.getBy", () => { + test("Belt.Array.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt.Array.flatMap", () => { + test("Belt.Array.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt.Array.map", () => { + test("Belt.Array.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt.Array.forEach", () => { + test("Belt.Array.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt.Array.blit", () => { + test("Belt.Array.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt.Array.fill", () => { + test("Belt.Array.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt.Array.sliceToEnd", () => { + test("Belt.Array.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt.Array.slice", () => { + test("Belt.Array.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt.Array.concatMany", () => { + test("Belt.Array.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt.Array.concat", () => { + test("Belt.Array.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt.Array.unzip", () => { + test("Belt.Array.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt.Array.zipBy", () => { + test("Belt.Array.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt.Array.zip", () => { + test("Belt.Array.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt.Array.makeBy", () => { + test("Belt.Array.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt.Array.rangeBy", () => { + test("Belt.Array.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt.Array.range", () => { + test("Belt.Array.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt.Array.makeUninitializedUnsafe", () => { + test("Belt.Array.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt.Array.makeUninitialized", () => { + test("Belt.Array.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt.Array.reverse", () => { + test("Belt.Array.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt.Array.reverseInPlace", () => { + test("Belt.Array.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt.Array.get", () => { + test("Belt.Array.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt.Array.length", () => { + test("Belt.Array.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Belt.Option", () => { + test("Belt.Option", () => { + module Test = { + type option<'a> = None | Some('a) + + let someString: option = Some("hello") + } + () + }) +}) + +describe("Belt.HashMap", () => { + test("Belt.HashMap", () => { + module Test = { + type t = int + module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) + let s0: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I0), + ) + + module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) + let s1: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I1), + ) + + let () = { + Belt.HashMap.set(s0, 0, 3) + Belt.HashMap.set(s1, 1, "3") + } + } + () + }) +}) + +describe("Belt.HashSet", () => { + test("Belt.HashSet", () => { + module Test = { + module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) + + let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) + + module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) + + let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) + + Belt.HashSet.add(s1, 0) + Belt.HashSet.add(s1, 1) + } + () + }) +}) + +describe("Belt.MutableSet", () => { + test("Belt.MutableSet", () => { + module Test = { + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) + + let mySet = Belt.MutableSet.make(~id=module(PairComparator)) + mySet->Belt.MutableSet.add((1, 2)) + } + () + }) +}) + +describe("Belt.Set", () => { + test("Belt.Set", () => { + module Test = { + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) + + let mySet = Belt.Set.make(~id=module(PairComparator)) + let mySet2 = Belt.Set.add(mySet, (1, 2)) + + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + } + () + }) +}) + +describe("Belt_Int./", () => { + test("Belt_Int./", () => { + module Test = { + open Belt.Int + assertEqual(4 / 2, 2) + } + () + }) +}) + +describe("Belt_Int.*", () => { + test("Belt_Int.*", () => { + module Test = { + open Belt.Int + assertEqual(2 * 2, 4) + } + () + }) +}) + +describe("Belt_Int.-", () => { + test("Belt_Int.-", () => { + module Test = { + open Belt.Int + assertEqual(2 - 1, 1) + } + () + }) +}) + +describe("Belt_Int.+", () => { + test("Belt_Int.+", () => { + module Test = { + open Belt.Int + assertEqual(2 + 2, 4) + } + () + }) +}) + +describe("Belt_Int.toString", () => { + test("Belt_Int.toString", () => { + module Test = { + Belt.Int.toString(1)->assertEqual("1") + } + () + }) +}) + +describe("Belt_Int.fromString", () => { + test("Belt_Int.fromString", () => { + module Test = { + Belt.Int.fromString("1")->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt_Int.fromFloat", () => { + test("Belt_Int.fromFloat", () => { + module Test = { + Belt.Int.fromFloat(1.0)->assertEqual(1) + } + () + }) +}) + +describe("Belt_Int.toFloat", () => { + test("Belt_Int.toFloat", () => { + module Test = { + Belt.Int.toFloat(1)->assertEqual(1.0) + } + () + }) +}) + +describe("Belt_List.sort", () => { + test("Belt_List.sort", () => { + module Test = { + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + } + () + }) +}) + +describe("Belt_List.setAssoc", () => { + test("Belt_List.setAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + } + () + }) +}) + +describe("Belt_List.removeAssoc", () => { + test("Belt_List.removeAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ + } + () + }) +}) + +describe("Belt_List.hasAssoc", () => { + test("Belt_List.hasAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ + } + () + }) +}) + +describe("Belt_List.getAssoc", () => { + test("Belt_List.getAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ + } + () + }) +}) + +describe("Belt_List.unzip", () => { + test("Belt_List.unzip", () => { + module Test = { + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + } + () + }) +}) + +describe("Belt_List.partition", () => { + test("Belt_List.partition", () => { + module Test = { + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) + } + () + }) +}) + +describe("Belt_List.keepMap", () => { + test("Belt_List.keepMap", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ + + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + } + () + }) +}) + +describe("Belt_List.filterWithIndex", () => { + test("Belt_List.filterWithIndex", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + } + () + }) +}) + +describe("Belt_List.keepWithIndex", () => { + test("Belt_List.keepWithIndex", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + } + () + }) +}) + +describe("Belt_List.filter", () => { + test("Belt_List.filter", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ + } + () + }) +}) + +describe("Belt_List.keep", () => { + test("Belt_List.keep", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ + } + () + }) +}) + +describe("Belt_List.getBy", () => { + test("Belt_List.getBy", () => { + module Test = { + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + } + () + }) +}) + +describe("Belt_List.has", () => { + test("Belt_List.has", () => { + module Test = { + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + } + () + }) +}) + +describe("Belt_List.eq", () => { + test("Belt_List.eq", () => { + module Test = { + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ + + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + } + () + }) +}) + +describe("Belt_List.cmp", () => { + test("Belt_List.cmp", () => { + module Test = { + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + } + () + }) +}) + +describe("Belt_List.cmpByLength", () => { + test("Belt_List.cmpByLength", () => { + module Test = { + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ + + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ + + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + } + () + }) +}) + +describe("Belt_List.some2", () => { + test("Belt_List.some2", () => { + module Test = { + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ + + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + } + () + }) +}) + +describe("Belt_List.every2", () => { + test("Belt_List.every2", () => { + module Test = { + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + } + () + }) +}) + +describe("Belt_List.some", () => { + test("Belt_List.some", () => { + module Test = { + let isAbove100 = value => value > 100 + + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + } + () + }) +}) + +describe("Belt_List.every", () => { + test("Belt_List.every", () => { + module Test = { + let isBelow10 = value => value < 10 + + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + } + () + }) +}) + +describe("Belt_List.reduceReverse2", () => { + test("Belt_List.reduceReverse2", () => { + module Test = { + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + } + () + }) +}) + +describe("Belt_List.reduce2", () => { + test("Belt_List.reduce2", () => { + module Test = { + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + } + () + }) +}) + +describe("Belt_List.forEach2", () => { + test("Belt_List.forEach2", () => { + module Test = { + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) + + /* + prints: + "Z" "A" + "Y" "B" +*/ + } + () + }) +}) + +describe("Belt_List.mapReverse2", () => { + test("Belt_List.mapReverse2", () => { + module Test = { + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + } + () + }) +}) + +describe("Belt_List.reduceReverse", () => { + test("Belt_List.reduceReverse", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} + } + () + }) +}) + +describe("Belt_List.reduceWithIndex", () => { + test("Belt_List.reduceWithIndex", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ + } + () + }) +}) + +describe("Belt_List.reduce", () => { + test("Belt_List.reduce", () => { + module Test = { + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + + /* same as */ + + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + } + () + }) +}) + +describe("Belt_List.forEachWithIndex", () => { + test("Belt_List.forEachWithIndex", () => { + module Test = { + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + } + () + }) +}) + +describe("Belt_List.forEach", () => { + test("Belt_List.forEach", () => { + module Test = { + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ + } + () + }) +}) + +describe("Belt_List.mapReverse", () => { + test("Belt_List.mapReverse", () => { + module Test = { + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) + } + () + }) +}) + +describe("Belt_List.reverse", () => { + test("Belt_List.reverse", () => { + module Test = { + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + } + () + }) +}) + +describe("Belt_List.toArray", () => { + test("Belt_List.toArray", () => { + module Test = { + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + } + () + }) +}) + +describe("Belt_List.fromArray", () => { + test("Belt_List.fromArray", () => { + module Test = { + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + } + () + }) +}) + +describe("Belt_List.mapWithIndex", () => { + test("Belt_List.mapWithIndex", () => { + module Test = { + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + } + () + }) +}) + +describe("Belt_List.zipBy", () => { + test("Belt_List.zipBy", () => { + module Test = { + Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + } + () + }) +}) + +describe("Belt_List.zip", () => { + test("Belt_List.zip", () => { + module Test = { + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + } + () + }) +}) + +describe("Belt_List.map", () => { + test("Belt_List.map", () => { + module Test = { + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + } + () + }) +}) + +describe("Belt_List.flatten", () => { + test("Belt_List.flatten", () => { + module Test = { + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("Belt_List.reverseConcat", () => { + test("Belt_List.reverseConcat", () => { + module Test = { + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + } + () + }) +}) + +describe("Belt_List.concatMany", () => { + test("Belt_List.concatMany", () => { + module Test = { + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("Belt_List.concat", () => { + test("Belt_List.concat", () => { + module Test = { + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + } + () + }) +}) + +describe("Belt_List.splitAt", () => { + test("Belt_List.splitAt", () => { + module Test = { + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + } + () + }) +}) + +describe("Belt_List.take", () => { + test("Belt_List.take", () => { + module Test = { + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) + + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) + + list{1, 2, 3}->Belt.List.take(4) // None + } + () + }) +}) + +describe("Belt_List.drop", () => { + test("Belt_List.drop", () => { + module Test = { + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + + list{1, 2, 3}->Belt.List.drop(4) // None + } + () + }) +}) + +describe("Belt_List.shuffle", () => { + test("Belt_List.shuffle", () => { + module Test = { + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + } + () + }) +}) + +describe("Belt_List.makeBy", () => { + test("Belt_List.makeBy", () => { + module Test = { + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + } + () + }) +}) + +describe("Belt_List.make", () => { + test("Belt_List.make", () => { + module Test = { + Belt.List.make(3, 1) // list{1, 1, 1} + } + () + }) +}) + +describe("Belt_List.getExn", () => { + test("Belt_List.getExn", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc->Belt.List.getExn(1)->assertEqual("B") + + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt_List.get", () => { + test("Belt_List.get", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc->Belt.List.get(1) // Some("B") + + abc->Belt.List.get(4) // None + } + () + }) +}) + +describe("Belt_List.add", () => { + test("Belt_List.add", () => { + module Test = { + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + } + () + }) +}) + +describe("Belt_List.tailExn", () => { + test("Belt_List.tailExn", () => { + module Test = { + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt_List.tail", () => { + test("Belt_List.tail", () => { + module Test = { + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + Belt.List.tail(list{}) // None + } + () + }) +}) + +describe("Belt_List.headExn", () => { + test("Belt_List.headExn", () => { + module Test = { + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt_List.head", () => { + test("Belt_List.head", () => { + module Test = { + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) + } + () + }) +}) + +describe("Belt_List.length", () => { + test("Belt_List.length", () => { + module Test = { + Belt.List.length(list{1, 2, 3}) // 3 + } + () + }) +}) + +describe("Belt_Map.Dict.findFirstBy", () => { + test("Belt_Map.Dict.findFirstBy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + } + () + }) +}) + +describe("Belt_Map.String.findFirstBy", () => { + test("Belt_Map.String.findFirstBy", () => { + module Test = { + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) + } + () + }) +}) + +describe("Belt_Map.Int.findFirstBy", () => { + test("Belt_Map.Int.findFirstBy", () => { + module Test = { + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) + } + () + }) +}) + +describe("Belt_Map.set", () => { + test("Belt_Map.set", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.set(s0, 2, "3") + + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + } + () + }) +}) + +describe("Belt_Map.remove", () => { + test("Belt_Map.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] + } + () + }) +}) + +describe("Belt_Map.get", () => { + test("Belt_Map.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") + + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None + } + () + }) +}) + +describe("Belt_Map.valuesToArray", () => { + test("Belt_Map.valuesToArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] + } + () + }) +}) + +describe("Belt_Map.keysToArray", () => { + test("Belt_Map.keysToArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] + } + () + }) +}) + +describe("Belt_Map.fromArray", () => { + test("Belt_Map.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] + } + () + }) +}) + +describe("Belt_Map.toArray", () => { + test("Belt_Map.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] + } + () + }) +}) + +describe("Belt_Map.size", () => { + test("Belt_Map.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 + } + () + }) +}) + +describe("Belt_Map.reduce", () => { + test("Belt_Map.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + } + () + }) +}) + +describe("Belt_Map.forEach", () => { + test("Belt_Map.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + let acc = ref(list{}) + + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + } + () + }) +}) + +describe("Belt_Map.findFirstBy", () => { + test("Belt_Map.findFirstBy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) + } + () + }) +}) + +describe("Belt_Map.has", () => { + test("Belt_Map.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + } + () + }) +}) + +describe("Belt_Map.isEmpty", () => { + test("Belt_Map.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + } + () + }) +}) + +describe("Belt_Map.make", () => { + test("Belt_Map.make", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let m = Belt.Map.make(~id=module(IntCmp)) + + Belt.Map.set(m, 0, "a") + } + () + }) +}) + +describe("Belt_Map.Int", () => { + test("Belt_Map.Int", () => { + module Test = { + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + } + () + }) +}) + +describe("Belt_MapString.findFirstBy", () => { + test("Belt_MapString.findFirstBy", () => { + module Test = { + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) + } + () + }) +}) + +describe("Belt_MapDict.findFirstBy", () => { + test("Belt_MapDict.findFirstBy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + } + () + }) +}) + +describe("Belt_MapInt.findFirstBy", () => { + test("Belt_MapInt.findFirstBy", () => { + module Test = { + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) + } + () + }) +}) + +describe("Belt_MutableSet.split", () => { + test("Belt_MutableSet.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ + } + () + }) +}) + +describe("Belt_MutableSet.get", () => { + test("Belt_MutableSet.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ + } + () + }) +}) + +describe("Belt_MutableSet.maxUndefined", () => { + test("Belt_MutableSet.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ + } + () + }) +}) + +describe("Belt_MutableSet.maximum", () => { + test("Belt_MutableSet.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ + } + () + }) +}) + +describe("Belt_MutableSet.minUndefined", () => { + test("Belt_MutableSet.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ + } + () + }) +}) + +describe("Belt_MutableSet.minimum", () => { + test("Belt_MutableSet.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ + } + () + }) +}) + +describe("Belt_MutableSet.toArray", () => { + test("Belt_MutableSet.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_MutableSet.toList", () => { + test("Belt_MutableSet.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_MutableSet.size", () => { + test("Belt_MutableSet.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.size /* 4 */ + } + () + }) +}) + +describe("Belt_MutableSet.partition", () => { + test("Belt_MutableSet.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt_MutableSet.keep", () => { + test("Belt_MutableSet.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ + } + () + }) +}) + +describe("Belt_MutableSet.some", () => { + test("Belt_MutableSet.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ + } + () + }) +}) + +describe("Belt_MutableSet.every", () => { + test("Belt_MutableSet.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ + } + () + }) +}) + +describe("Belt_MutableSet.reduce", () => { + test("Belt_MutableSet.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_MutableSet.forEach", () => { + test("Belt_MutableSet.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_MutableSet.eq", () => { + test("Belt_MutableSet.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.MutableSet.eq(s0, s1) /* true */ + } + () + }) +}) + +describe("Belt_MutableSet.subset", () => { + test("Belt_MutableSet.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ + } + () + }) +}) + +describe("Belt_MutableSet.diff", () => { + test("Belt_MutableSet.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + } + () + }) +}) + +describe("Belt_MutableSet.intersect", () => { + test("Belt_MutableSet.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ + } + () + }) +}) + +describe("Belt_MutableSet.union", () => { + test("Belt_MutableSet.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + } + () + }) +}) + +describe("Belt_MutableSet.removeMany", () => { + test("Belt_MutableSet.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ + } + () + }) +}) + +describe("Belt_MutableSet.remove", () => { + test("Belt_MutableSet.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ + } + () + }) +}) + +describe("Belt_MutableSet.mergeMany", () => { + test("Belt_MutableSet.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + } + () + }) +}) + +describe("Belt_MutableSet.add", () => { + test("Belt_MutableSet.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) + + s0->Belt.MutableSet.toArray /* [1, 2] */ + } + () + }) +}) + +describe("Belt_MutableSet.has", () => { + test("Belt_MutableSet.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ + } + () + }) +}) + +describe("Belt_MutableSet.isEmpty", () => { + test("Belt_MutableSet.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ + } + () + }) +}) + +describe("Belt_MutableSet.copy", () => { + test("Belt_MutableSet.copy", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt_MutableSet.fromArray", () => { + test("Belt_MutableSet.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt_Range.someBy", () => { + test("Belt_Range.someBy", () => { + module Test = { + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt_Range.some", () => { + test("Belt_Range.some", () => { + module Test = { + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ + } + () + }) +}) + +describe("Belt_Range.everyBy", () => { + test("Belt_Range.everyBy", () => { + module Test = { + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt_Range.every", () => { + test("Belt_Range.every", () => { + module Test = { + Belt.Range.every(0, 4, i => i < 5) /* true */ + + Belt.Range.every(0, 4, i => i < 4) /* false */ + } + () + }) +}) + +describe("Belt_Range.forEach", () => { + test("Belt_Range.forEach", () => { + module Test = { + Belt.Range.forEach(0, 4, i => Js.log(i)) + + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 + } + () + }) +}) + +describe("Belt_Option.cmp", () => { + test("Belt_Option.cmp", () => { + module Test = { + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) + + open Belt.Option + + cmp(Some(3), Some(15), clockCompare) /* 0 */ + + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ + } + () + }) +}) + +describe("Belt_Option.eq", () => { + test("Belt_Option.eq", () => { + module Test = { + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Belt.Option + + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ + } + () + }) +}) + +describe("Belt_Option.isNone", () => { + test("Belt_Option.isNone", () => { + module Test = { + Belt.Option.isNone(None) /* true */ + + Belt.Option.isNone(Some(1)) /* false */ + } + () + }) +}) + +describe("Belt_Option.isSome", () => { + test("Belt_Option.isSome", () => { + module Test = { + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ + } + () + }) +}) + +describe("Belt_Option.orElse", () => { + test("Belt_Option.orElse", () => { + module Test = { + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None + } + () + }) +}) + +describe("Belt_Option.getWithDefault", () => { + test("Belt_Option.getWithDefault", () => { + module Test = { + Belt.Option.getWithDefault(None, "Banana") /* Banana */ + + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ + + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ + } + () + }) +}) + +describe("Belt_Option.flatMap", () => { + test("Belt_Option.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ + + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ + } + () + }) +}) + +describe("Belt_Option.map", () => { + test("Belt_Option.map", () => { + module Test = { + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + + Belt.Option.map(None, x => x * x) /* None */ + } + () + }) +}) + +describe("Belt_Option.mapWithDefault", () => { + test("Belt_Option.mapWithDefault", () => { + module Test = { + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ + + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + } + () + }) +}) + +describe("Belt_Option.getExn", () => { + test("Belt_Option.getExn", () => { + module Test = { + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) + + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt_Option.forEach", () => { + test("Belt_Option.forEach", () => { + module Test = { + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + } + () + }) +}) + +describe("Belt_Option.keep", () => { + test("Belt_Option.keep", () => { + module Test = { + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ + } + () + }) +}) + +describe("Belt_Result.cmp", () => { + test("Belt_Result.cmp", () => { + module Test = { + let good1 = Belt.Result.Ok(59) + + let good2 = Belt.Result.Ok(37) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + } + () + }) +}) + +describe("Belt_Result.eq", () => { + test("Belt_Result.eq", () => { + module Test = { + let good1 = Belt.Result.Ok(42) + + let good2 = Belt.Result.Ok(32) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 + } + () + }) +}) + +describe("Belt_Result.getWithDefault", () => { + test("Belt_Result.getWithDefault", () => { + module Test = { + Belt.Result.getWithDefault(Ok(42), 0) == 42 + + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + } + () + }) +}) + +describe("Belt_Result.flatMap", () => { + test("Belt_Result.flatMap", () => { + module Test = { + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + } + () + }) +}) + +describe("Belt_Result.map", () => { + test("Belt_Result.map", () => { + module Test = { + let f = x => sqrt(Belt.Int.toFloat(x)) + + Belt.Result.map(Ok(64), f) == Ok(8.0) + + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + } + () + }) +}) + +describe("Belt_Result.mapWithDefault", () => { + test("Belt_Result.mapWithDefault", () => { + module Test = { + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + } + () + }) +}) + +describe("Belt_Result.getExn", () => { + test("Belt_Result.getExn", () => { + module Test = { + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) + + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Belt_SetDict.split", () => { + test("Belt_SetDict.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ + } + () + }) +}) + +describe("Belt_SetDict.get", () => { + test("Belt_SetDict.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + } + () + }) +}) + +describe("Belt_SetDict.maxUndefined", () => { + test("Belt_SetDict.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ + } + () + }) +}) + +describe("Belt_SetDict.maximum", () => { + test("Belt_SetDict.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ + } + () + }) +}) + +describe("Belt_SetDict.minUndefined", () => { + test("Belt_SetDict.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ + } + () + }) +}) + +describe("Belt_SetDict.minimum", () => { + test("Belt_SetDict.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ + } + () + }) +}) + +describe("Belt_SetDict.toArray", () => { + test("Belt_SetDict.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_SetDict.toList", () => { + test("Belt_SetDict.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_SetDict.size", () => { + test("Belt_SetDict.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ + } + () + }) +}) + +describe("Belt_SetDict.partition", () => { + test("Belt_SetDict.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt_SetDict.keep", () => { + test("Belt_SetDict.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt_SetDict.some", () => { + test("Belt_SetDict.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ + } + () + }) +}) + +describe("Belt_SetDict.every", () => { + test("Belt_SetDict.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ + } + () + }) +}) + +describe("Belt_SetDict.reduce", () => { + test("Belt_SetDict.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_SetDict.forEach", () => { + test("Belt_SetDict.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_SetDict.eq", () => { + test("Belt_SetDict.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt_SetDict.subset", () => { + test("Belt_SetDict.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + } + () + }) +}) + +describe("Belt_SetDict.diff", () => { + test("Belt_SetDict.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ + } + () + }) +}) + +describe("Belt_SetDict.intersect", () => { + test("Belt_SetDict.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + } + () + }) +}) + +describe("Belt_SetDict.union", () => { + test("Belt_SetDict.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + } + () + }) +}) + +describe("Belt_SetDict.removeMany", () => { + test("Belt_SetDict.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ + } + () + }) +}) + +describe("Belt_SetDict.remove", () => { + test("Belt_SetDict.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt_SetDict.mergeMany", () => { + test("Belt_SetDict.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + } + () + }) +}) + +describe("Belt_SetDict.add", () => { + test("Belt_SetDict.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt_SetDict.has", () => { + test("Belt_SetDict.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt_SetDict.isEmpty", () => { + test("Belt_SetDict.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ + } + () + }) +}) + +describe("Belt_SetDict.fromArray", () => { + test("Belt_SetDict.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt_SetDict.empty", () => { + test("Belt_SetDict.empty", () => { + module Test = { + let s0 = Belt.Set.Dict.empty + } + () + }) +}) + +describe("Belt_Set.Dict.split", () => { + test("Belt_Set.Dict.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ + } + () + }) +}) + +describe("Belt_Set.Dict.get", () => { + test("Belt_Set.Dict.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + } + () + }) +}) + +describe("Belt_Set.Dict.maxUndefined", () => { + test("Belt_Set.Dict.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ + } + () + }) +}) + +describe("Belt_Set.Dict.maximum", () => { + test("Belt_Set.Dict.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ + } + () + }) +}) + +describe("Belt_Set.Dict.minUndefined", () => { + test("Belt_Set.Dict.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ + } + () + }) +}) + +describe("Belt_Set.Dict.minimum", () => { + test("Belt_Set.Dict.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ + } + () + }) +}) + +describe("Belt_Set.Dict.toArray", () => { + test("Belt_Set.Dict.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_Set.Dict.toList", () => { + test("Belt_Set.Dict.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + } + () + }) +}) + +describe("Belt_Set.Dict.size", () => { + test("Belt_Set.Dict.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ + } + () + }) +}) + +describe("Belt_Set.Dict.partition", () => { + test("Belt_Set.Dict.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt_Set.Dict.keep", () => { + test("Belt_Set.Dict.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ + } + () + }) +}) + +describe("Belt_Set.Dict.some", () => { + test("Belt_Set.Dict.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.every", () => { + test("Belt_Set.Dict.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.reduce", () => { + test("Belt_Set.Dict.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_Set.Dict.forEach", () => { + test("Belt_Set.Dict.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ + } + () + }) +}) + +describe("Belt_Set.Dict.eq", () => { + test("Belt_Set.Dict.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.subset", () => { + test("Belt_Set.Dict.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + } + () + }) +}) + +describe("Belt_Set.Dict.diff", () => { + test("Belt_Set.Dict.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ + } + () + }) +}) + +describe("Belt_Set.Dict.intersect", () => { + test("Belt_Set.Dict.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + } + () + }) +}) + +describe("Belt_Set.Dict.union", () => { + test("Belt_Set.Dict.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + } + () + }) +}) + +describe("Belt_Set.Dict.removeMany", () => { + test("Belt_Set.Dict.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ + } + () + }) +}) + +describe("Belt_Set.Dict.remove", () => { + test("Belt_Set.Dict.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.mergeMany", () => { + test("Belt_Set.Dict.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + } + () + }) +}) + +describe("Belt_Set.Dict.add", () => { + test("Belt_Set.Dict.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.has", () => { + test("Belt_Set.Dict.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + } + () + }) +}) + +describe("Belt_Set.Dict.isEmpty", () => { + test("Belt_Set.Dict.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ + } + () + }) +}) + +describe("Belt_Set.Dict.fromArray", () => { + test("Belt_Set.Dict.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + } + () + }) +}) + +describe("Belt_Set.Dict.empty", () => { + test("Belt_Set.Dict.empty", () => { + module Test = { + let s0 = Belt.Set.Dict.empty + } + () + }) +}) + +describe("Belt_Set.split", () => { + test("Belt_Set.split", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.Set.split(3) + + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) + } + () + }) +}) + +describe("Belt_Set.get", () => { + test("Belt_Set.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) + } + () + }) +}) + +describe("Belt_Set.maxUndefined", () => { + test("Belt_Set.maxUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) + } + () + }) +}) + +describe("Belt_Set.maximum", () => { + test("Belt_Set.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.maximum->assertEqual(None) + s1->Belt.Set.maximum->assertEqual(Some(5)) + } + () + }) +}) + +describe("Belt_Set.minUndefined", () => { + test("Belt_Set.minUndefined", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt_Set.minimum", () => { + test("Belt_Set.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) + } + () + }) +}) + +describe("Belt_Set.toList", () => { + test("Belt_Set.toList", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + } + () + }) +}) + +describe("Belt_Set.toArray", () => { + test("Belt_Set.toArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + } + () + }) +}) + +describe("Belt_Set.size", () => { + test("Belt_Set.size", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.Set.size->assertEqual(4) + } + () + }) +}) + +describe("Belt_Set.partition", () => { + test("Belt_Set.partition", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) + + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) + } + () + }) +}) + +describe("Belt_Set.keep", () => { + test("Belt_Set.keep", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.keep(isEven) + + s1->Belt.Set.toArray->assertEqual([2, 4]) + } + () + }) +}) + +describe("Belt_Set.some", () => { + test("Belt_Set.some", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) + } + () + }) +}) + +describe("Belt_Set.every", () => { + test("Belt_Set.every", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) + } + () + }) +}) + +describe("Belt_Set.reduce", () => { + test("Belt_Set.reduce", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) + } + () + }) +}) + +describe("Belt_Set.forEach", () => { + test("Belt_Set.forEach", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + + let acc = ref(list{}) + + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) + } + () + }) +}) + +describe("Belt_Set.eq", () => { + test("Belt_Set.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.Set.eq(s0, s1)->assertEqual(true) + } + () + }) +}) + +describe("Belt_Set.subset", () => { + test("Belt_Set.subset", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) + + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) + } + () + }) +}) + +describe("Belt_Set.diff", () => { + test("Belt_Set.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + Belt.Set.diff(s0, s1) + ->Belt.Set.toArray + ->assertEqual([6]) + + Belt.Set.diff(s1, s0) + ->Belt.Set.toArray + ->assertEqual([1, 4]) + } + () + }) +}) + +describe("Belt_Set.intersect", () => { + test("Belt_Set.intersect", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + let intersect = Belt.Set.intersect(s0, s1) + + intersect + ->Belt.Set.toArray + ->assertEqual([2, 3, 5]) + } + () + }) +}) + +describe("Belt_Set.union", () => { + test("Belt_Set.union", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) + + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) + } + () + }) +}) + +describe("Belt_Set.removeMany", () => { + test("Belt_Set.removeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) + } + () + }) +}) + +describe("Belt_Set.remove", () => { + test("Belt_Set.remove", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) + + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) + } + () + }) +}) + +describe("Belt_Set.mergeMany", () => { + test("Belt_Set.mergeMany", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) + } + () + }) +}) + +describe("Belt_Set.add", () => { + test("Belt_Set.add", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) + + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) + } + () + }) +}) + +describe("Belt_Set.has", () => { + test("Belt_Set.has", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) + } + () + }) +}) + +describe("Belt_Set.isEmpty", () => { + test("Belt_Set.isEmpty", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) + + Belt.Set.isEmpty(empty)->assertEqual(true) + Belt.Set.isEmpty(notEmpty)->assertEqual(false) + } + () + }) +}) + +describe("Belt_Set.fromArray", () => { + test("Belt_Set.fromArray", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + } + () + }) +}) + +describe("Belt_Set.make", () => { + test("Belt_Set.make", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + Belt.Set.isEmpty(set)->assertEqual(true) + } + () + }) +}) + +describe("Belt_SortArray.binarySearchBy", () => { + test("Belt_SortArray.binarySearchBy", () => { + module Test = { + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + } + () + }) +}) + +describe("Belt_SortArray.strictlySortedLength", () => { + test("Belt_SortArray.strictlySortedLength", () => { + module Test = { + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + } + () + }) +}) + +describe("BigInt.toLocaleString", () => { + test("BigInt.toLocaleString", () => { + module Test = { + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log + } + () + }) +}) + +describe("BigInt.toString", () => { + test("BigInt.toString", () => { + module Test = { + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log + } + () + }) +}) + +describe("BigInt.fromStringExn", () => { + test("BigInt.fromStringExn", () => { + module Test = { + /* returns 123n */ + BigInt.fromStringExn("123") + + /* returns 0n */ + BigInt.fromStringExn("") + + /* returns 17n */ + BigInt.fromStringExn("0x11") + + /* returns 3n */ + BigInt.fromStringExn("0b11") + + /* returns 9n */ + BigInt.fromStringExn("0o11") + + /* catch exception */ + try { + BigInt.fromStringExn("a") + } catch { + | Exn.Error(_error) => 0n + } + } + () + }) +}) + +describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt_internalSetString.A.eq", () => { + test("Belt_internalSetString.A.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt_internalSetString.A.cmp", () => { + test("Belt_internalSetString.A.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt_internalSetString.A.some2", () => { + test("Belt_internalSetString.A.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalSetString.A.every2", () => { + test("Belt_internalSetString.A.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalSetString.A.every", () => { + test("Belt_internalSetString.A.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalSetString.A.some", () => { + test("Belt_internalSetString.A.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalSetString.A.joinWith", () => { + test("Belt_internalSetString.A.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt_internalSetString.A.reduceWithIndex", () => { + test("Belt_internalSetString.A.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt_internalSetString.A.reduceReverse2", () => { + test("Belt_internalSetString.A.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt_internalSetString.A.reduceReverse", () => { + test("Belt_internalSetString.A.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt_internalSetString.A.reduce", () => { + test("Belt_internalSetString.A.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt_internalSetString.A.partition", () => { + test("Belt_internalSetString.A.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt_internalSetString.A.mapWithIndex", () => { + test("Belt_internalSetString.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt_internalSetString.A.forEachWithIndex", () => { + test("Belt_internalSetString.A.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt_internalSetString.A.keepMap", () => { + test("Belt_internalSetString.A.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt_internalSetString.A.keepWithIndex", () => { + test("Belt_internalSetString.A.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt_internalSetString.A.getIndexBy", () => { + test("Belt_internalSetString.A.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalSetString.A.getBy", () => { + test("Belt_internalSetString.A.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalSetString.A.flatMap", () => { + test("Belt_internalSetString.A.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt_internalSetString.A.map", () => { + test("Belt_internalSetString.A.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt_internalSetString.A.forEach", () => { + test("Belt_internalSetString.A.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt_internalSetString.A.blit", () => { + test("Belt_internalSetString.A.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt_internalSetString.A.fill", () => { + test("Belt_internalSetString.A.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt_internalSetString.A.sliceToEnd", () => { + test("Belt_internalSetString.A.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt_internalSetString.A.slice", () => { + test("Belt_internalSetString.A.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt_internalSetString.A.concatMany", () => { + test("Belt_internalSetString.A.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt_internalSetString.A.concat", () => { + test("Belt_internalSetString.A.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt_internalSetString.A.unzip", () => { + test("Belt_internalSetString.A.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt_internalSetString.A.zipBy", () => { + test("Belt_internalSetString.A.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt_internalSetString.A.zip", () => { + test("Belt_internalSetString.A.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt_internalSetString.A.makeBy", () => { + test("Belt_internalSetString.A.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt_internalSetString.A.rangeBy", () => { + test("Belt_internalSetString.A.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt_internalSetString.A.range", () => { + test("Belt_internalSetString.A.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt_internalSetString.A.makeUninitialized", () => { + test("Belt_internalSetString.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt_internalSetString.A.reverse", () => { + test("Belt_internalSetString.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalSetString.A.reverseInPlace", () => { + test("Belt_internalSetString.A.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalSetString.A.get", () => { + test("Belt_internalSetString.A.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt_internalSetString.A.length", () => { + test("Belt_internalSetString.A.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Belt_internalMapInt.S.binarySearchBy", () => { + test("Belt_internalMapInt.S.binarySearchBy", () => { + module Test = { + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + } + () + }) +}) + +describe("Belt_internalMapInt.S.strictlySortedLength", () => { + test("Belt_internalMapInt.S.strictlySortedLength", () => { + module Test = { + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + } + () + }) +}) + +describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt_internalMapInt.A.eq", () => { + test("Belt_internalMapInt.A.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt_internalMapInt.A.cmp", () => { + test("Belt_internalMapInt.A.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt_internalMapInt.A.some2", () => { + test("Belt_internalMapInt.A.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalMapInt.A.every2", () => { + test("Belt_internalMapInt.A.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalMapInt.A.every", () => { + test("Belt_internalMapInt.A.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalMapInt.A.some", () => { + test("Belt_internalMapInt.A.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalMapInt.A.joinWith", () => { + test("Belt_internalMapInt.A.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt_internalMapInt.A.reduceWithIndex", () => { + test("Belt_internalMapInt.A.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt_internalMapInt.A.reduceReverse2", () => { + test("Belt_internalMapInt.A.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt_internalMapInt.A.reduceReverse", () => { + test("Belt_internalMapInt.A.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt_internalMapInt.A.reduce", () => { + test("Belt_internalMapInt.A.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt_internalMapInt.A.partition", () => { + test("Belt_internalMapInt.A.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt_internalMapInt.A.mapWithIndex", () => { + test("Belt_internalMapInt.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt_internalMapInt.A.forEachWithIndex", () => { + test("Belt_internalMapInt.A.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt_internalMapInt.A.keepMap", () => { + test("Belt_internalMapInt.A.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt_internalMapInt.A.keepWithIndex", () => { + test("Belt_internalMapInt.A.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt_internalMapInt.A.getIndexBy", () => { + test("Belt_internalMapInt.A.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalMapInt.A.getBy", () => { + test("Belt_internalMapInt.A.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalMapInt.A.flatMap", () => { + test("Belt_internalMapInt.A.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt_internalMapInt.A.map", () => { + test("Belt_internalMapInt.A.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt_internalMapInt.A.forEach", () => { + test("Belt_internalMapInt.A.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt_internalMapInt.A.blit", () => { + test("Belt_internalMapInt.A.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt_internalMapInt.A.fill", () => { + test("Belt_internalMapInt.A.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt_internalMapInt.A.sliceToEnd", () => { + test("Belt_internalMapInt.A.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt_internalMapInt.A.slice", () => { + test("Belt_internalMapInt.A.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt_internalMapInt.A.concatMany", () => { + test("Belt_internalMapInt.A.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt_internalMapInt.A.concat", () => { + test("Belt_internalMapInt.A.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt_internalMapInt.A.unzip", () => { + test("Belt_internalMapInt.A.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt_internalMapInt.A.zipBy", () => { + test("Belt_internalMapInt.A.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt_internalMapInt.A.zip", () => { + test("Belt_internalMapInt.A.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt_internalMapInt.A.makeBy", () => { + test("Belt_internalMapInt.A.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt_internalMapInt.A.rangeBy", () => { + test("Belt_internalMapInt.A.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt_internalMapInt.A.range", () => { + test("Belt_internalMapInt.A.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt_internalMapInt.A.makeUninitialized", () => { + test("Belt_internalMapInt.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt_internalMapInt.A.reverse", () => { + test("Belt_internalMapInt.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalMapInt.A.reverseInPlace", () => { + test("Belt_internalMapInt.A.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalMapInt.A.get", () => { + test("Belt_internalMapInt.A.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt_internalMapInt.A.length", () => { + test("Belt_internalMapInt.A.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Belt_internalMapString.S.binarySearchBy", () => { + test("Belt_internalMapString.S.binarySearchBy", () => { + module Test = { + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + } + () + }) +}) + +describe("Belt_internalMapString.S.strictlySortedLength", () => { + test("Belt_internalMapString.S.strictlySortedLength", () => { + module Test = { + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + } + () + }) +}) + +describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt_internalMapString.A.eq", () => { + test("Belt_internalMapString.A.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt_internalMapString.A.cmp", () => { + test("Belt_internalMapString.A.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt_internalMapString.A.some2", () => { + test("Belt_internalMapString.A.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalMapString.A.every2", () => { + test("Belt_internalMapString.A.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalMapString.A.every", () => { + test("Belt_internalMapString.A.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalMapString.A.some", () => { + test("Belt_internalMapString.A.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalMapString.A.joinWith", () => { + test("Belt_internalMapString.A.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt_internalMapString.A.reduceWithIndex", () => { + test("Belt_internalMapString.A.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt_internalMapString.A.reduceReverse2", () => { + test("Belt_internalMapString.A.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt_internalMapString.A.reduceReverse", () => { + test("Belt_internalMapString.A.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt_internalMapString.A.reduce", () => { + test("Belt_internalMapString.A.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt_internalMapString.A.partition", () => { + test("Belt_internalMapString.A.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt_internalMapString.A.mapWithIndex", () => { + test("Belt_internalMapString.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt_internalMapString.A.forEachWithIndex", () => { + test("Belt_internalMapString.A.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt_internalMapString.A.keepMap", () => { + test("Belt_internalMapString.A.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt_internalMapString.A.keepWithIndex", () => { + test("Belt_internalMapString.A.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt_internalMapString.A.getIndexBy", () => { + test("Belt_internalMapString.A.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalMapString.A.getBy", () => { + test("Belt_internalMapString.A.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalMapString.A.flatMap", () => { + test("Belt_internalMapString.A.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt_internalMapString.A.map", () => { + test("Belt_internalMapString.A.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt_internalMapString.A.forEach", () => { + test("Belt_internalMapString.A.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt_internalMapString.A.blit", () => { + test("Belt_internalMapString.A.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt_internalMapString.A.fill", () => { + test("Belt_internalMapString.A.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt_internalMapString.A.sliceToEnd", () => { + test("Belt_internalMapString.A.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt_internalMapString.A.slice", () => { + test("Belt_internalMapString.A.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt_internalMapString.A.concatMany", () => { + test("Belt_internalMapString.A.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt_internalMapString.A.concat", () => { + test("Belt_internalMapString.A.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt_internalMapString.A.unzip", () => { + test("Belt_internalMapString.A.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt_internalMapString.A.zipBy", () => { + test("Belt_internalMapString.A.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt_internalMapString.A.zip", () => { + test("Belt_internalMapString.A.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt_internalMapString.A.makeBy", () => { + test("Belt_internalMapString.A.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt_internalMapString.A.rangeBy", () => { + test("Belt_internalMapString.A.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt_internalMapString.A.range", () => { + test("Belt_internalMapString.A.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt_internalMapString.A.makeUninitialized", () => { + test("Belt_internalMapString.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt_internalMapString.A.reverse", () => { + test("Belt_internalMapString.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalMapString.A.reverseInPlace", () => { + test("Belt_internalMapString.A.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalMapString.A.get", () => { + test("Belt_internalMapString.A.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt_internalMapString.A.length", () => { + test("Belt_internalMapString.A.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + module Test = { + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] + } + () + }) +}) + +describe("Belt_internalSetInt.A.eq", () => { + test("Belt_internalSetInt.A.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + } + () + }) +}) + +describe("Belt_internalSetInt.A.cmp", () => { + test("Belt_internalSetInt.A.cmp", () => { + module Test = { + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + } + () + }) +}) + +describe("Belt_internalSetInt.A.some2", () => { + test("Belt_internalSetInt.A.some2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalSetInt.A.every2", () => { + test("Belt_internalSetInt.A.every2", () => { + module Test = { + 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 + } + () + }) +}) + +describe("Belt_internalSetInt.A.every", () => { + test("Belt_internalSetInt.A.every", () => { + module Test = { + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalSetInt.A.some", () => { + test("Belt_internalSetInt.A.some", () => { + module Test = { + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false + } + () + }) +}) + +describe("Belt_internalSetInt.A.joinWith", () => { + test("Belt_internalSetInt.A.joinWith", () => { + module Test = { + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + } + () + }) +}) + +describe("Belt_internalSetInt.A.reduceWithIndex", () => { + test("Belt_internalSetInt.A.reduceWithIndex", () => { + module Test = { + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + } + () + }) +}) + +describe("Belt_internalSetInt.A.reduceReverse2", () => { + test("Belt_internalSetInt.A.reduceReverse2", () => { + module Test = { + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + } + () + }) +}) + +describe("Belt_internalSetInt.A.reduceReverse", () => { + test("Belt_internalSetInt.A.reduceReverse", () => { + module Test = { + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + } + () + }) +}) + +describe("Belt_internalSetInt.A.reduce", () => { + test("Belt_internalSetInt.A.reduce", () => { + module Test = { + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) + +describe("Belt_internalSetInt.A.partition", () => { + test("Belt_internalSetInt.A.partition", () => { + module Test = { + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + } + () + }) +}) + +describe("Belt_internalSetInt.A.mapWithIndex", () => { + test("Belt_internalSetInt.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) + +describe("Belt_internalSetInt.A.forEachWithIndex", () => { + test("Belt_internalSetInt.A.forEachWithIndex", () => { + module Test = { + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + } + () + }) +}) + +describe("Belt_internalSetInt.A.keepMap", () => { + test("Belt_internalSetInt.A.keepMap", () => { + module Test = { + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) + +describe("Belt_internalSetInt.A.keepWithIndex", () => { + test("Belt_internalSetInt.A.keepWithIndex", () => { + module Test = { + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + } + () + }) +}) + +describe("Belt_internalSetInt.A.getIndexBy", () => { + test("Belt_internalSetInt.A.getIndexBy", () => { + module Test = { + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalSetInt.A.getBy", () => { + test("Belt_internalSetInt.A.getBy", () => { + module Test = { + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + } + () + }) +}) + +describe("Belt_internalSetInt.A.flatMap", () => { + test("Belt_internalSetInt.A.flatMap", () => { + module Test = { + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + } + () + }) +}) + +describe("Belt_internalSetInt.A.map", () => { + test("Belt_internalSetInt.A.map", () => { + module Test = { + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) + +describe("Belt_internalSetInt.A.forEach", () => { + test("Belt_internalSetInt.A.forEach", () => { + module Test = { + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 + } + () + }) +}) + +describe("Belt_internalSetInt.A.blit", () => { + test("Belt_internalSetInt.A.blit", () => { + module Test = { + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] + } + () + }) +}) + +describe("Belt_internalSetInt.A.fill", () => { + test("Belt_internalSetInt.A.fill", () => { + module Test = { + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] + } + () + }) +}) + +describe("Belt_internalSetInt.A.sliceToEnd", () => { + test("Belt_internalSetInt.A.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + } + () + }) +}) + +describe("Belt_internalSetInt.A.slice", () => { + test("Belt_internalSetInt.A.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + } + () + }) +}) + +describe("Belt_internalSetInt.A.concatMany", () => { + test("Belt_internalSetInt.A.concatMany", () => { + module Test = { + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) + +describe("Belt_internalSetInt.A.concat", () => { + test("Belt_internalSetInt.A.concat", () => { + module Test = { + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + } + () + }) +}) + +describe("Belt_internalSetInt.A.unzip", () => { + test("Belt_internalSetInt.A.unzip", () => { + module Test = { + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + } + () + }) +}) + +describe("Belt_internalSetInt.A.zipBy", () => { + test("Belt_internalSetInt.A.zipBy", () => { + module Test = { + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + } + () + }) +}) + +describe("Belt_internalSetInt.A.zip", () => { + test("Belt_internalSetInt.A.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + } + () + }) +}) + +describe("Belt_internalSetInt.A.makeBy", () => { + test("Belt_internalSetInt.A.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + } + () + }) +}) + +describe("Belt_internalSetInt.A.rangeBy", () => { + test("Belt_internalSetInt.A.rangeBy", () => { + module Test = { + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] + } + () + }) +}) + +describe("Belt_internalSetInt.A.range", () => { + test("Belt_internalSetInt.A.range", () => { + module Test = { + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] + } + () + }) +}) + +describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + module Test = { + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") + } + () + }) +}) + +describe("Belt_internalSetInt.A.makeUninitialized", () => { + test("Belt_internalSetInt.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined + } + () + }) +}) + +describe("Belt_internalSetInt.A.reverse", () => { + test("Belt_internalSetInt.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalSetInt.A.reverseInPlace", () => { + test("Belt_internalSetInt.A.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] + } + () + }) +}) + +describe("Belt_internalSetInt.A.get", () => { + test("Belt_internalSetInt.A.get", () => { + module Test = { + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) + +describe("Belt_internalSetInt.A.length", () => { + test("Belt_internalSetInt.A.length", () => { + module Test = { + // Returns 1 + Belt.Array.length(["test"]) + } + () + }) +}) + +describe("Console.warnMany", () => { + test("Console.warnMany", () => { + module Test = { + Console.warnMany(["Hello", "World"]) + Console.warnMany([1, 2, 3]) + } + () + }) +}) + +describe("Console.warn6", () => { + test("Console.warn6", () => { + module Test = { + Console.warn6("Hello", "World", "from", "JS", "!!!", '!') + Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.warn5", () => { + test("Console.warn5", () => { + module Test = { + Console.warn5("Hello", "World", "from", "JS", "!!!") + Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.warn4", () => { + test("Console.warn4", () => { + module Test = { + Console.warn4("Hello", "World", "ReScript", "!!!") + Console.warn4(#first, #second, #third, "fourth") + } + () + }) +}) + +describe("Console.warn3", () => { + test("Console.warn3", () => { + module Test = { + Console.warn3("Hello", "World", "ReScript") + Console.warn3([1, 2, 3], #4, #5) + } + () + }) +}) + +describe("Console.warn2", () => { + test("Console.warn2", () => { + module Test = { + Console.warn2("Hello", "World") + Console.warn2([1, 2, 3], 4) + } + () + }) +}) + +describe("Console.warn", () => { + test("Console.warn", () => { + module Test = { + Console.warn("Warning") + Console.warn(("Warning", "invalid number")) + } + () + }) +}) + +describe("Console.trace", () => { + test("Console.trace", () => { + module Test = { + let main = () => { + Console.trace() + } + main() + // In the console, the following trace will be displayed: + // main + // + } + () + }) +}) + +describe("Console.timeLog", () => { + test("Console.timeLog", () => { + module Test = { + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") + } + () + }) +}) + +describe("Console.timeEnd", () => { + test("Console.timeEnd", () => { + module Test = { + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") + } + () + }) +}) + +describe("Console.time", () => { + test("Console.time", () => { + module Test = { + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") + } + () + }) +}) + +describe("Console.table", () => { + test("Console.table", () => { + module Test = { + Console.table({"language": "rescript", "version": "10.1.2"}) + } + () + }) +}) + +describe("Console.logMany", () => { + test("Console.logMany", () => { + module Test = { + Console.logMany(["Hello", "World"]) + Console.logMany([1, 2, 3]) + } + () + }) +}) + +describe("Console.log6", () => { + test("Console.log6", () => { + module Test = { + Console.log6("Hello", "World", "JS", '!', '!', '?') + Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.log5", () => { + test("Console.log5", () => { + module Test = { + Console.log5("Hello", "World", "JS", '!', '!') + Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.log4", () => { + test("Console.log4", () => { + module Test = { + Console.log4("Hello", "World", "ReScript", "!!!") + Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) + } + () + }) +}) + +describe("Console.log3", () => { + test("Console.log3", () => { + module Test = { + Console.log3("Hello", "World", "ReScript") + Console.log3("One", 2, #3) + } + () + }) +}) + +describe("Console.log2", () => { + test("Console.log2", () => { + module Test = { + Console.log2("Hello", "World") + Console.log2([1, 2, 3], '4') + } + () + }) +}) + +describe("Console.log", () => { + test("Console.log", () => { + module Test = { + Console.log("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.log(obj) + } + () + }) +}) + +describe("Console.infoMany", () => { + test("Console.infoMany", () => { + module Test = { + Console.infoMany(["Hello", "World"]) + Console.infoMany([1, 2, 3]) + } + () + }) +}) + +describe("Console.info6", () => { + test("Console.info6", () => { + module Test = { + Console.info6("Hello", "World", "from", "JS", "!!!", '!') + Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.info5", () => { + test("Console.info5", () => { + module Test = { + Console.info5("Hello", "World", "from", "JS", "!!!") + Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.info4", () => { + test("Console.info4", () => { + module Test = { + Console.info4("Hello", "World", "ReScript", '!') + Console.info4([1, 2, 3], #4, #5, #lastinfo) + } + () + }) +}) + +describe("Console.info3", () => { + test("Console.info3", () => { + module Test = { + Console.info3("Hello", "World", "ReScript") + Console.info3([1, 2, 3], #4, #5) + } + () + }) +}) + +describe("Console.info2", () => { + test("Console.info2", () => { + module Test = { + Console.info2("Info", "failed to download") + Console.info2(#info, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.info", () => { + test("Console.info", () => { + module Test = { + Console.info("Information") + Console.info(("Hello", "JS")) + } + () + }) +}) + +describe("Console.errorMany", () => { + test("Console.errorMany", () => { + module Test = { + Console.errorMany(["Hello", "World"]) + Console.errorMany([1, 2, 3]) + } + () + }) +}) + +describe("Console.group", () => { + test("Console.group", () => { + module Test = { + 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() + } + () + }) +}) + +describe("Console.error6", () => { + test("Console.error6", () => { + module Test = { + Console.error6("Hello", "World", "from", "JS", "!!!", '!') + Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.error5", () => { + test("Console.error5", () => { + module Test = { + Console.error5('e', 'r', 'r', 'o', 'r') + Console.error5(1, #second, #third, "fourth", 'c') + } + () + }) +}) + +describe("Console.error4", () => { + test("Console.error4", () => { + module Test = { + Console.error4("Hello", "World", "ReScript", '!') + Console.error4(#first, #second, #third, "fourth") + } + () + }) +}) + +describe("Console.error3", () => { + test("Console.error3", () => { + module Test = { + Console.error3("Hello", "World", "!!!") + Console.error3(#first, #second, #third) + } + () + }) +}) + +describe("Console.error2", () => { + test("Console.error2", () => { + module Test = { + Console.error2("Error", "here") + Console.error2(("log", "error"), "message") + } + () + }) +}) + +describe("Console.error", () => { + test("Console.error", () => { + module Test = { + Console.error("error message") + Console.error(("error", "invalid value")) + } + () + }) +}) + +describe("Console.dir", () => { + test("Console.dir", () => { + module Test = { + Console.dir({"language": "rescript", "version": "10.1.2"}) + } + () + }) +}) + +describe("Console.debugMany", () => { + test("Console.debugMany", () => { + module Test = { + Console.debugMany(["Hello", "World"]) + Console.debugMany([1, 2, 3]) + } + () + }) +}) + +describe("Console.debug6", () => { + test("Console.debug6", () => { + module Test = { + Console.debug6("Hello", "World", "JS", '!', '!', '?') + Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.debug5", () => { + test("Console.debug5", () => { + module Test = { + Console.debug5("Hello", "World", "JS", '!', '!') + Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.debug4", () => { + test("Console.debug4", () => { + module Test = { + Console.debug4("Hello", "World", "ReScript", "!!!") + Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) + } + () + }) +}) + +describe("Console.debug3", () => { + test("Console.debug3", () => { + module Test = { + Console.debug3("Hello", "World", "ReScript") + Console.debug3("One", 2, #3) + } + () + }) +}) + +describe("Console.debug2", () => { + test("Console.debug2", () => { + module Test = { + Console.debug2("Hello", "World") + Console.debug2([1, 2, 3], '4') + } + () + }) +}) + +describe("Console.debug", () => { + test("Console.debug", () => { + module Test = { + Console.debug("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.debug(obj) + } + () + }) +}) + +describe("Console.countReset", () => { + test("Console.countReset", () => { + module Test = { + Console.countReset("rescript") + } + () + }) +}) + +describe("Console.count", () => { + test("Console.count", () => { + module Test = { + Console.count("rescript") + } + () + }) +}) + +describe("Console.clear", () => { + test("Console.clear", () => { + module Test = { + Console.clear() + } + () + }) +}) + +describe("Console.assertMany", () => { + test("Console.assertMany", () => { + module Test = { + let value = 42 + Console.assertMany(false, ["Hello", "World"]) + Console.assertMany(value == 42, [1, 2, 3]) + } + () + }) +}) + +describe("Console.assert6", () => { + test("Console.assert6", () => { + module Test = { + let value = 42 + Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') + Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) + +describe("Console.assert5", () => { + test("Console.assert5", () => { + module Test = { + let value = 42 + Console.assert5(false, "Hello", "World", "JS", '!', '!') + Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) + +describe("Console.assert4", () => { + test("Console.assert4", () => { + module Test = { + let value = 42 + Console.assert4(false, "Hello", "World", "ReScript", "!!!") + Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) + } + () + }) +}) + +describe("Console.assert3", () => { + test("Console.assert3", () => { + module Test = { + Console.assert3(false, "Hello", "World", "ReScript") + Console.assert3(42 == 42, "One", 2, #3) + } + () + }) +}) + +describe("Console.assert2", () => { + test("Console.assert2", () => { + module Test = { + Console.assert2(false, "Hello", "World") + Console.assert2(42 == 42, [1, 2, 3], '4') + } + () + }) +}) + +describe("Console.assert_", () => { + test("Console.assert_", () => { + module Test = { + Console.assert_(false, "Hello World!") + Console.assert_(42 == 42, "The answer") + } + () + }) +}) + +describe("Date.UTC.makeWithYMDHMSM", () => { + test("Date.UTC.makeWithYMDHMSM", () => { + module Test = { + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + )->Console.log + // 1676911200000 + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + )->Console.log + // 1676911201000 + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + )->Console.log + // 1676911199999 + } + () + }) +}) + +describe("Date.UTC.makeWithYMDHMS", () => { + test("Date.UTC.makeWithYMDHMS", () => { + module Test = { + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 1676911200000 + + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 1676911260000 + + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 1676911199000 + } + () + }) +}) + +describe("Date.UTC.makeWithYMDHM", () => { + test("Date.UTC.makeWithYMDHM", () => { + module Test = { + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 1676911200000 + + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 1676912400000 + + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 1676908740000 + } + () + }) +}) + +describe("Date.UTC.makeWithYMDH", () => { + test("Date.UTC.makeWithYMDH", () => { + module Test = { + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 1676908800000 + + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 1676937600000 + + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 1676847600000 + } + () + }) +}) + +describe("Date.UTC.makeWithYMD", () => { + test("Date.UTC.makeWithYMD", () => { + module Test = { + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20) + // 1676851200000 + + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1) + // 1675036800000 + + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29) + // 1677628800000 + } + () + }) +}) + +describe("Date.UTC.makeWithYM", () => { + test("Date.UTC.makeWithYM", () => { + module Test = { + Date.UTC.makeWithYM(~year=2023, ~month=0) + // 1672531200000 + + Date.UTC.makeWithYM(~year=2023, ~month=11) + // 1701388800000 + + Date.UTC.makeWithYM(~year=2023, ~month=12) + // 1704067200000 + + Date.UTC.makeWithYM(~year=2023, ~month=-1) + // 1669852800000 + } + () + }) +}) + +describe("Date.toJSON", () => { + test("Date.toJSON", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON + // Some("2023-01-01T00:00:00.000Z") + + Date.fromString("")->Date.toJSON + // None + } + () + }) +}) + +describe("Date.toUTCString", () => { + test("Date.toUTCString", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log + // Sun, 01 Jan 2023 00:00:00 GMT + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log + // Sat, 31 Dec 2022 16:00:00 GMT + } + () + }) +}) + +describe("Date.toISOString", () => { + test("Date.toISOString", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log + // 2023-01-01T00:00:00.000Z + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log + // 2022-12-31T16:00:00.000Z + } + () + }) +}) + +describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + module Test = { + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) + ->Console.log + // 3:40:00 PM GMT+1 + + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 15:40 + } + () + }) +}) + +describe("Date.toLocaleTimeStringWithLocale", () => { + test("Date.toLocaleTimeStringWithLocale", () => { + module Test = { + Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log + // 3:40:00 PM + } + () + }) +}) + +describe("Date.toLocaleTimeString", () => { + test("Date.toLocaleTimeString", () => { + module Test = { + Date.make()->Date.toLocaleTimeString->Console.log + // 3:40:00 PM + } + () + }) +}) + +describe("Date.toLocaleStringWithLocaleAndOptions", () => { + test("Date.toLocaleStringWithLocaleAndOptions", () => { + module Test = { + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) + ->Console.log + // 2/19/23, 3:40 PM + + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions( + "en", + { + era: #long, + year: #numeric, + month: #"2-digit", + day: #"2-digit", + hour: #numeric, + timeZoneName: #short, + }, + ) + ->Console.log + // 02/19/2023 Anno Domini, 3 PM GMT+1 + } + () + }) +}) + +describe("Date.toLocaleStringWithLocale", () => { + test("Date.toLocaleStringWithLocale", () => { + module Test = { + Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log + // 2/19/2023, 3:40:00 PM + } + () + }) +}) + +describe("Date.toLocaleString", () => { + test("Date.toLocaleString", () => { + module Test = { + Date.make()->Date.toLocaleString->Console.log + // 2/19/2023, 3:40:00 PM + } + () + }) +}) + +describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + test("Date.toLocaleDateStringWithLocaleAndOptions", () => { + module Test = { + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) + ->Console.log + // February 19, 2023 + + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 19.2.2023, 15:40 + + Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log + // 2023 + } + () + }) +}) + +describe("Date.toLocaleDateStringWithLocale", () => { + test("Date.toLocaleDateStringWithLocale", () => { + module Test = { + Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log + // 2/19/2023 + } + () + }) +}) + +describe("Date.toLocaleDateString", () => { + test("Date.toLocaleDateString", () => { + module Test = { + Date.make()->Date.toLocaleDateString->Console.log + // 2/19/2023 + } + () + }) +}) + +describe("Date.toTimeString", () => { + test("Date.toTimeString", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log + // 00:00:00 GMT+0100 (Central European Standard Time) + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log + // 17:00:00 GMT+0100 (Central European Standard Time) + } + () + }) +}) + +describe("Date.toString", () => { + test("Date.toString", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log + // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) + + Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log + // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) + } + () + }) +}) + +describe("Date.toDateString", () => { + test("Date.toDateString", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log + // Sun Jan 01 2023 + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log + // Sat Dec 31 2022 + } + () + }) +}) + +describe("Date.setUTCMilliseconds", () => { + test("Date.setUTCMilliseconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) + } + () + }) +}) + +describe("Date.setUTCSecondsMs", () => { + test("Date.setUTCSecondsMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) + } + () + }) +}) + +describe("Date.setUTCSeconds", () => { + test("Date.setUTCSeconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) + } + () + }) +}) + +describe("Date.setUTCMinutesSMs", () => { + test("Date.setUTCMinutesSMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) + } + () + }) +}) + +describe("Date.setUTCMinutesS", () => { + test("Date.setUTCMinutesS", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) + } + () + }) +}) + +describe("Date.setUTCMinutes", () => { + test("Date.setUTCMinutes", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) + } + () + }) +}) + +describe("Date.setUTCHoursMSMs", () => { + test("Date.setUTCHoursMSMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) + } + () + }) +}) + +describe("Date.setUTCHoursMS", () => { + test("Date.setUTCHoursMS", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( + ~hours=0, + ~minutes=0, + ~seconds=0, + ) + } + () + }) +}) + +describe("Date.setUTCHoursM", () => { + test("Date.setUTCHoursM", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) + } + () + }) +}) + +describe("Date.setUTCHours", () => { + test("Date.setUTCHours", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) + } + () + }) +}) + +describe("Date.setUTCDate", () => { + test("Date.setUTCDate", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) + } + () + }) +}) + +describe("Date.setUTCMonth", () => { + test("Date.setUTCMonth", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) + } + () + }) +}) + +describe("Date.setUTCFullYearMD", () => { + test("Date.setUTCFullYearMD", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( + ~year=2024, + ~month=0, + ~date=1, + ) + } + () + }) +}) + +describe("Date.setUTCFullYearM", () => { + test("Date.setUTCFullYearM", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) + } + () + }) +}) + +describe("Date.setUTCFullYear", () => { + test("Date.setUTCFullYear", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) + } + () + }) +}) + +describe("Date.getUTCDay", () => { + test("Date.getUTCDay", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 + } + () + }) +}) + +describe("Date.getUTCMilliseconds", () => { + test("Date.getUTCMilliseconds", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 + } + () + }) +}) + +describe("Date.getUTCSeconds", () => { + test("Date.getUTCSeconds", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 + } + () + }) +}) + +describe("Date.getUTCMinutes", () => { + test("Date.getUTCMinutes", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 + } + () + }) +}) + +describe("Date.getUTCHours", () => { + test("Date.getUTCHours", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 + } + () + }) +}) + +describe("Date.getUTCDate", () => { + test("Date.getUTCDate", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 + } + () + }) +}) + +describe("Date.getUTCMonth", () => { + test("Date.getUTCMonth", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 + } + () + }) +}) + +describe("Date.getUTCFullYear", () => { + test("Date.getUTCFullYear", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 + } + () + }) +}) + +describe("Date.setMilliseconds", () => { + test("Date.setMilliseconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) + } + () + }) +}) + +describe("Date.setSecondsMs", () => { + test("Date.setSecondsMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) + } + () + }) +}) + +describe("Date.setSeconds", () => { + test("Date.setSeconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) + } + () + }) +}) + +describe("Date.setMinutesSMs", () => { + test("Date.setMinutesSMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) + } + () + }) +}) + +describe("Date.setMinutesS", () => { + test("Date.setMinutesS", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) + } + () + }) +}) + +describe("Date.setMinutes", () => { + test("Date.setMinutes", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) + } + () + }) +}) + +describe("Date.setHoursMSMs", () => { + test("Date.setHoursMSMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) + } + () + }) +}) + +describe("Date.setHoursMS", () => { + test("Date.setHoursMS", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) + } + () + }) +}) + +describe("Date.setHoursM", () => { + test("Date.setHoursM", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) + } + () + }) +}) + +describe("Date.setHours", () => { + test("Date.setHours", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) + } + () + }) +}) + +describe("Date.setDate", () => { + test("Date.setDate", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) + } + () + }) +}) + +describe("Date.setMonth", () => { + test("Date.setMonth", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) + } + () + }) +}) + +describe("Date.setFullYearMD", () => { + test("Date.setFullYearMD", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) + } + () + }) +}) + +describe("Date.setFullYearM", () => { + test("Date.setFullYearM", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) + } + () + }) +}) + +describe("Date.setFullYear", () => { + test("Date.setFullYear", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) + } + () + }) +}) + +describe("Date.getDay", () => { + test("Date.getDay", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getDay + // 1 + } + () + }) +}) + +describe("Date.getMilliseconds", () => { + test("Date.getMilliseconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds + // 0 + } + () + }) +}) + +describe("Date.getSeconds", () => { + test("Date.getSeconds", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds + // 0 + } + () + }) +}) + +describe("Date.getMinutes", () => { + test("Date.getMinutes", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes + // 40 + } + () + }) +}) + +describe("Date.getHours", () => { + test("Date.getHours", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getHours + // 16 + } + () + }) +}) + +describe("Date.getDate", () => { + test("Date.getDate", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.getDate + // 20 + } + () + }) +}) + +describe("Date.getMonth", () => { + test("Date.getMonth", () => { + module Test = { + Date.fromString("2023-01-01")->Date.getMonth + // 0 + } + () + }) +}) + +describe("Date.getFullYear", () => { + test("Date.getFullYear", () => { + module Test = { + Date.fromString("2023-02-20")->Date.getFullYear + // 2023 + } + () + }) +}) + +describe("Date.getTimezoneOffset", () => { + test("Date.getTimezoneOffset", () => { + module Test = { + Date.fromString("2023-01-01")->Date.getTimezoneOffset + // -60 with local time zone = Europe/Berlin + + Date.fromString("2023-06-01")->Date.getTimezoneOffset + // -120 with local time zone = Europe/Berlin + } + () + }) +}) + +describe("Date.getTime", () => { + test("Date.getTime", () => { + module Test = { + Date.fromString("2023-02-20")->Date.getTime + // 1676851200000 + } + () + }) +}) + +describe("Date.makeWithYMDHMSM", () => { + test("Date.makeWithYMDHMSM", () => { + module Test = { + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + ) + // 2023-02-20T16:40:00.000Z + + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + ) + // 2023-02-20T16:40:01.000Z + + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + ) + // 2023-02-20T16:39:59.999Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + } + () + }) +}) + +describe("Date.makeWithYMDHMS", () => { + test("Date.makeWithYMDHMS", () => { + module Test = { + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 2023-02-20T16:40:00.000Z + + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 2023-02-20T16:41:00.000Z + + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 2023-02-20T16:39:59.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + } + () + }) +}) + +describe("Date.makeWithYMDHM", () => { + test("Date.makeWithYMDHM", () => { + module Test = { + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 2023-02-20T16:40:00.000Z + + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 2023-02-20T17:00:00.000Z + + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 2023-02-20T15:59:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + } + () + }) +}) + +describe("Date.makeWithYMDH", () => { + test("Date.makeWithYMDH", () => { + module Test = { + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 2023-02-20T16:00:00.000Z + + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 2023-02-21T00:00:00.000Z + + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 2023-02-19T23:00:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + } + () + }) +}) + +describe("Date.makeWithYMD", () => { + test("Date.makeWithYMD", () => { + module Test = { + Date.makeWithYMD(~year=2023, ~month=1, ~date=20) + // 2023-02-20T00:00:00.000Z + + Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) + // 2022-11-29T00:00:00.000Z + + Date.makeWithYMD(~year=2023, ~month=1, ~date=29) + // 2023-03-01T00:00:00.000Z + } + () + }) +}) + +describe("Date.makeWithYM", () => { + test("Date.makeWithYM", () => { + module Test = { + Date.makeWithYM(~year=2023, ~month=0) + // 2023-01-01T00:00:00.000Z + + Date.makeWithYM(~year=2023, ~month=11) + // 2023-12-01T00:00:00.000Z + + Date.makeWithYM(~year=2023, ~month=12) + // 2024-01-01T00:00:00.000Z + + Date.makeWithYM(~year=2023, ~month=-1) + // 2022-12-01T00:00:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + } + () + }) +}) + +describe("Date.fromTime", () => { + test("Date.fromTime", () => { + module Test = { + Date.fromTime(0.0) + // 1970-01-01T00:00:00.000Z + + Date.fromTime(-86_400_000.0) + // 1969-12-31T00:00:00.000Z + + Date.fromTime(86_400_000.0) + // 1970-01-02T00:00:00.000Z + } + () + }) +}) + +describe("Date.fromString", () => { + test("Date.fromString", () => { + module Test = { + Date.fromString("2023") // 2023-01-01T00:00:00.000Z + + Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z + + Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z + + Date.fromString("") // Invalid Date + + Date.fromString("")->Date.getTime // NaN + } + () + }) +}) + +describe("Date.make", () => { + test("Date.make", () => { + module Test = { + Date.make() + } + () + }) +}) + +describe("Dict.mapValues", () => { + test("Dict.mapValues", () => { + module Test = { + let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) + + dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] + dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] + } + () + }) +}) + +describe("Dict.forEachWithKey", () => { + test("Dict.forEachWithKey", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + + dict->Dict.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) + } + () + }) +}) + +describe("Dict.forEach", () => { + test("Dict.forEach", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + + dict->Dict.forEach( + value => { + Console.log(value) + }, + ) + } + () + }) +}) + +describe("Dict.copy", () => { + test("Dict.copy", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let dict2 = dict->Dict.copy + + // Both log `["key1", "key2"]` here. + Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) + } + () + }) +}) + +describe("Dict.assign", () => { + test("Dict.assign", () => { + module Test = { + let dict1 = Dict.make() + dict1->Dict.set("firstKey", 1) + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` + + let dict2 = Dict.make() + dict2->Dict.set("someKey", 2) + dict2->Dict.set("someKey2", 3) + + let dict1 = dict1->Dict.assign(dict2) + + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` + } + () + }) +}) + +describe("Dict.valuesToArray", () => { + test("Dict.valuesToArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let values = dict->Dict.valuesToArray + Console.log(values) // Logs `[1, 2]` to the console + } + () + }) +}) + +describe("Dict.keysToArray", () => { + test("Dict.keysToArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let keys = dict->Dict.keysToArray + Console.log(keys) // Logs `["someKey", "someKey2"]` to the console + } + () + }) +}) + +describe("Dict.toArray", () => { + test("Dict.toArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let asArray = dict->Dict.toArray + Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console + } + () + }) +}) + +describe("Dict.fromIterator", () => { + test("Dict.fromIterator", () => { + module Test = { + let iterator: Iterator.t<(string, int)> = %raw(` + (() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + iterator + ->Dict.fromIterator + ->Dict.valuesToArray + ->assertEqual([1, 2]) + } + () + }) +}) + +describe("Dict.fromArray", () => { + test("Dict.fromArray", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + } + () + }) +}) + +describe("Dict.make", () => { + test("Dict.make", () => { + module Test = { + let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want + + let dict2 = Dict.make() // Or you can let ReScript infer it via usage. + dict2->Dict.set("someKey", 12) + } + () + }) +}) + +describe("Dict.delete", () => { + test("Dict.delete", () => { + module Test = { + let dict = Dict.fromArray([("someKey", "someValue")]) + + dict->Dict.delete("someKey") + } + () + }) +}) + +describe("Dict.set", () => { + test("Dict.set", () => { + module Test = { + let dict = Dict.make() + + dict->Dict.set("someKey", "someValue") + } + () + }) +}) + +describe("Dict.get", () => { + test("Dict.get", () => { + module Test = { + let dict = Dict.fromArray([("someKey", "someValue")]) + + switch dict->Dict.get("someKey") { + | None => Console.log("Nope, didn't have the key.") + | Some(value) => Console.log(value) + } + } + () + }) +}) + +describe("Dict.getUnsafe", () => { + test("Dict.getUnsafe", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let value = dict->Dict.getUnsafe("key1") + Console.log(value) // value1 + } + () + }) +}) + +describe("Error.panic", () => { + test("Error.panic", () => { + module Test = { + try { + Error.panic("Uh oh. This was unexpected!") + } catch { + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") + | None => assert(false) + } + | _ => assert(false) + } + } + () + }) +}) + +describe("Error.raise", () => { + test("Error.raise", () => { + module Test = { + let error = Error.make("Everything is upside down.") + + if 5 > 10 { + error->Error.raise + } else { + Console.log("Phew, sanity still rules.") + } + } + () + }) +}) + +describe("Error.make", () => { + test("Error.make", () => { + module Test = { + let error = Error.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console + Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error + } + () + }) +}) + +describe("Error.name", () => { + test("Error.name", () => { + module Test = { + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.name) // Logs "SyntaxError" to the console + } + () + }) +}) + +describe("Error.message", () => { + test("Error.message", () => { + module Test = { + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console + } + () + }) +}) + +describe("Error.stack", () => { + test("Error.stack", () => { + module Test = { + let error = Error.make("error") + Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` + } + () + }) +}) + +describe("Error.toException", () => { + test("Error.toException", () => { + module Test = { + let error = Error.make("Something went wrong.") + + let asExn = error->Error.toException // `asExn` is now type `exn` + } + () + }) +}) + +describe("Float.Constants.maxValue", () => { + test("Float.Constants.maxValue", () => { + module Test = { + Float.Constants.minValue + } + () + }) +}) + +describe("Float.Constants.minValue", () => { + test("Float.Constants.minValue", () => { + module Test = { + Float.Constants.minValue + } + () + }) +}) + +describe("Float.Constants.negativeInfinity", () => { + test("Float.Constants.negativeInfinity", () => { + module Test = { + Float.Constants.negativeInfinity + } + () + }) +}) + +describe("Float.Constants.positiveInfinity", () => { + test("Float.Constants.positiveInfinity", () => { + module Test = { + Float.Constants.positiveInfinity + } + () + }) +}) + +describe("Float.Constants.epsilon", () => { + test("Float.Constants.epsilon", () => { + module Test = { + Float.Constants.epsilon + } + () + }) +}) + +describe("Float.Constants.nan", () => { + test("Float.Constants.nan", () => { + module Test = { + Float.Constants.nan + } + () + }) +}) + +describe("Float.clamp", () => { + test("Float.clamp", () => { + module Test = { + Float.clamp(4.2) == 4.2 + Float.clamp(4.2, ~min=4.3) == 4.3 + Float.clamp(4.2, ~max=4.1) == 4.1 + Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 + } + () + }) +}) + +describe("Float.mod", () => { + test("Float.mod", () => { + module Test = { + Float.mod(7.0, 4.0) == 3.0 + } + () + }) +}) + +describe("Float.fromInt", () => { + test("Float.fromInt", () => { + module Test = { + Float.fromInt(2) == 2.0 + Float.fromInt(1) == 1.0 + } + () + }) +}) + +describe("Float.toInt", () => { + test("Float.toInt", () => { + module Test = { + Float.toInt(2.0) == 2 + Float.toInt(1.0) == 1 + Float.toInt(1.1) == 1 + Float.toInt(1.6) == 1 + } + () + }) +}) + +describe("Float.fromString", () => { + test("Float.fromString", () => { + module Test = { + Float.fromString("0") == Some(0.0) + Float.fromString("NaN") == None + Float.fromString("6") == Some(6.0) + } + () + }) +}) + +describe("Float.toLocaleString", () => { + test("Float.toLocaleString", () => { + module Test = { + // If the application uses English as the default language + Float.toLocaleString(1000.0) // "1,000" + + // If the application uses Portuguese Brazil as the default language + Float.toLocaleString(1000.0) // "1.000" + } + () + }) +}) + +describe("Float.toStringWithRadix", () => { + test("Float.toStringWithRadix", () => { + module Test = { + Float.toStringWithRadix(6.0, ~radix=2) // "110" + Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" + Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" + } + () + }) +}) + +describe("Float.toString", () => { + test("Float.toString", () => { + module Test = { + Float.toString(1000.0) // "1000" + Float.toString(-1000.0) // "-1000" + } + () + }) +}) + +describe("Float.toPrecisionWithPrecision", () => { + test("Float.toPrecisionWithPrecision", () => { + module Test = { + Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" + } + () + }) +}) + +describe("Float.toPrecision", () => { + test("Float.toPrecision", () => { + module Test = { + Float.toPrecision(100.0) // "100" + Float.toPrecision(1.0) // "1" + Float.toPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecision(1.0, ~digits=1) // "1" + } + () + }) +}) + +describe("Float.toFixedWithPrecision", () => { + test("Float.toFixedWithPrecision", () => { + module Test = { + Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" + Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" + } + () + }) +}) + +describe("Float.toFixed", () => { + test("Float.toFixed", () => { + module Test = { + Float.toFixed(123456.0) // "123456.00" + Float.toFixed(10.0) // "10.00" + Float.toFixed(300.0, ~digits=4) // "300.0000" + Float.toFixed(300.0, ~digits=1) // "300.0" + } + () + }) +}) + +describe("Float.toExponentialWithPrecision", () => { + test("Float.toExponentialWithPrecision", () => { + module Test = { + Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" + Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" + } + () + }) +}) + +describe("Float.toExponential", () => { + test("Float.toExponential", () => { + module Test = { + Float.toExponential(1000.0) // "1e+3" + Float.toExponential(-1000.0) // "-1e+3" + Float.toExponential(77.0, ~digits=2) // "7.70e+1" + Float.toExponential(5678.0, ~digits=2) // "5.68e+3" + } + () + }) +}) + +describe("Float.parseIntWithRadix", () => { + test("Float.parseIntWithRadix", () => { + module Test = { + Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 + Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 + Float.parseIntWithRadix("12", ~radix=13) // 15.0 + Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true + } + () + }) +}) + +describe("Float.parseInt", () => { + test("Float.parseInt", () => { + module Test = { + Float.parseInt("1.0") // 1.0 + Float.parseInt(" 3.14 ") // 3.0 + Float.parseInt(3) // 3.0 + Float.parseInt("3.14some non-digit characters") // 3.0 + Float.parseInt("error")->Float.isNaN // true + Float.parseInt("10.0", ~radix=2) // 2.0 + Float.parseInt("15 * 3", ~radix=10) // 15.0 + Float.parseInt("12", ~radix=13) // 15.0 + Float.parseInt("17", ~radix=40)->Float.isNaN // true + } + () + }) +}) + +describe("Float.parseFloat", () => { + test("Float.parseFloat", () => { + module Test = { + Float.parseFloat("1.0") // 1.0 + Float.parseFloat(" 3.14 ") // 3.14 + Float.parseFloat("3.0") // 3.0 + Float.parseFloat("3.14some non-digit characters") // 3.14 + Float.parseFloat("error")->Float.isNaN // true + } + () + }) +}) + +describe("Float.isFinite", () => { + test("Float.isFinite", () => { + module Test = { + Float.isFinite(1.0) // true + Float.isFinite(Float.Constants.nan) // false + Float.isFinite(Float.Constants.positiveInfinity) // false + } + () + }) +}) + +describe("Float.isNaN", () => { + test("Float.isNaN", () => { + module Test = { + Float.isNaN(3.0) // false + Float.isNaN(Float.Constants.nan) // true + } + () + }) +}) + +describe("Int.Bitwise.asr", () => { + test("Int.Bitwise.asr", () => { + module Test = { + Int.Bitwise.asr(4, 1) == 2 + } + () + }) +}) + +describe("Int.Bitwise.lsr", () => { + test("Int.Bitwise.lsr", () => { + module Test = { + Int.Bitwise.lsr(8, 1) == 4 + } + () + }) +}) + +describe("Int.Bitwise.lsl", () => { + test("Int.Bitwise.lsl", () => { + module Test = { + Int.Bitwise.lsl(4, 1) == 8 + } + () + }) +}) + +describe("Int.Bitwise.lnot", () => { + test("Int.Bitwise.lnot", () => { + module Test = { + Int.Bitwise.lnot(2) == -3 + } + () + }) +}) + +describe("Int.Bitwise.lxor", () => { + test("Int.Bitwise.lxor", () => { + module Test = { + Int.Bitwise.lxor(7, 4) == 3 + } + () + }) +}) + +describe("Int.Bitwise.lor", () => { + test("Int.Bitwise.lor", () => { + module Test = { + Int.Bitwise.lor(7, 4) == 7 + } + () + }) +}) + +describe("Int.Bitwise.land", () => { + test("Int.Bitwise.land", () => { + module Test = { + Int.Bitwise.land(7, 4) == 4 + } + () + }) +}) + +describe("Int.Constants.maxValue", () => { + test("Int.Constants.maxValue", () => { + module Test = { + Console.log(Int.Constants.maxValue) + } + () + }) +}) + +describe("Int.Constants.minValue", () => { + test("Int.Constants.minValue", () => { + module Test = { + Console.log(Int.Constants.minValue) + } + () + }) +}) + +describe("Int.clamp", () => { + test("Int.clamp", () => { + module Test = { + Int.clamp(42) == 42 + Int.clamp(42, ~min=50) == 50 + Int.clamp(42, ~max=40) == 40 + Int.clamp(42, ~min=50, ~max=40) == 50 + } + () + }) +}) + +describe("Int.rangeWithOptions", () => { + test("Int.rangeWithOptions", () => { + module Test = { + Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] + Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] + Int.rangeWithOptions(3, 6, {step: -2}) // RangeError + } + () + }) +}) + +describe("Int.range", () => { + test("Int.range", () => { + module Test = { + Int.range(3, 6) == [3, 4, 5] + Int.range(-3, -1) == [-3, -2] + Int.range(3, 1) == [3, 2] + Int.range(3, 7, ~options={step: 2}) == [3, 5] + Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] + Int.range(3, 6, ~options={step: -2}) // RangeError + } + () + }) +}) + +describe("Int.mod", () => { + test("Int.mod", () => { + module Test = { + Int.mod(7, 4) == 3 + } + () + }) +}) + +describe("Int.fromString", () => { + test("Int.fromString", () => { + module Test = { + Int.fromString("0") == Some(0) + Int.fromString("NaN") == None + Int.fromString("6", ~radix=2) == None + } + () + }) +}) + +describe("Int.fromFloat", () => { + test("Int.fromFloat", () => { + module Test = { + Int.fromFloat(2.0) == 2 + Int.fromFloat(1.999) == 1 + Int.fromFloat(1.5) == 1 + Int.fromFloat(0.9999) == 0 + } + () + }) +}) + +describe("Int.toFloat", () => { + test("Int.toFloat", () => { + module Test = { + Int.toFloat(100) == 100.0 + Int.toFloat(2) == 2.0 + } + () + }) +}) + +describe("Int.toLocaleString", () => { + test("Int.toLocaleString", () => { + module Test = { + // If the application uses English as the default language + Int.toLocaleString(1000) // "1,000" + + // If the application uses Portuguese Brazil as the default language + Int.toLocaleString(1000) // "1.000" + } + () + }) +}) + +describe("Int.toStringWithRadix", () => { + test("Int.toStringWithRadix", () => { + module Test = { + Int.toStringWithRadix(6, ~radix=2) // "110" + Int.toStringWithRadix(373592855, ~radix=16) // "16449317" + Int.toStringWithRadix(123456, ~radix=36) // "2n9c" + } + () + }) +}) + +describe("Int.toString", () => { + test("Int.toString", () => { + module Test = { + Int.toString(1000) // "1000" + Int.toString(-1000) // "-1000" + Int.toString(6, ~radix=2) // "110" + Int.toString(373592855, ~radix=16) // "16449317" + Int.toString(123456, ~radix=36) // "2n9c" + } + () + }) +}) + +describe("Int.toPrecisionWithPrecision", () => { + test("Int.toPrecisionWithPrecision", () => { + module Test = { + Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" + } + () + }) +}) + +describe("Int.toPrecision", () => { + test("Int.toPrecision", () => { + module Test = { + Int.toPrecision(100) // "100" + Int.toPrecision(1) // "1" + Int.toPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecision(1, ~digits=2) // "1.0" + } + () + }) +}) + +describe("Int.toFixedWithPrecision", () => { + test("Int.toFixedWithPrecision", () => { + module Test = { + Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" + Int.toFixedWithPrecision(300, ~digits=1) // "300.0" + } + () + }) +}) + +describe("Int.toFixed", () => { + test("Int.toFixed", () => { + module Test = { + Int.toFixed(123456) // "123456.00" + Int.toFixed(10) // "10.00" + Int.toFixed(300, ~digits=4) // "300.0000" + Int.toFixed(300, ~digits=1) // "300.0" + } + () + }) +}) + +describe("Int.toExponentialWithPrecision", () => { + test("Int.toExponentialWithPrecision", () => { + module Test = { + Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" + Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" + } + () + }) +}) + +describe("Int.toExponential", () => { + test("Int.toExponential", () => { + module Test = { + Int.toExponential(1000) // "1e+3" + Int.toExponential(-1000) // "-1e+3" + Int.toExponential(77, ~digits=2) // "7.70e+1" + Int.toExponential(5678, ~digits=2) // "5.68e+3" + } + () + }) +}) + +describe("Iterator.forEach", () => { + test("Iterator.forEach", () => { + module Test = { + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + iterator->Iterator.forEach( + v => { + switch v { + | Some("a" | "b" | "c") => assert(true) + | other => + other + ->Option.isNone + ->assertEqual(true) + } + }, + ) + } + () + }) +}) + +describe("Iterator.toArrayWithMapper", () => { + test("Iterator.toArrayWithMapper", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = + map + ->Map.keys + ->Iterator.toArrayWithMapper(key => key->String.length) + + Console.log(mapKeysAsArray) // Logs [7, 8] to the console. + } + () + }) +}) + +describe("Iterator.toArray", () => { + test("Iterator.toArray", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = map->Map.keys->Iterator.toArray + + Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. + } + () + }) +}) + +describe("Iterator.next", () => { + test("Iterator.next", () => { + module Test = { + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + (iterator->Iterator.next).done->assertEqual(false) + (iterator->Iterator.next).done->assertEqual(true) + } + () + }) +}) + +describe("JSON.Decode.array", () => { + test("JSON.Decode.array", () => { + module Test = { + JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array + // Some([ 'foo', 'bar' ]) + + JSON.parseExn(`"hello world"`)->JSON.Decode.array + // None + } + () + }) +}) + +describe("JSON.Decode.object", () => { + test("JSON.Decode.object", () => { + module Test = { + JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object + // Some({ foo: 'bar' }) + + JSON.parseExn(`"hello world"`)->JSON.Decode.object + // None + } + () + }) +}) + +describe("JSON.Decode.float", () => { + test("JSON.Decode.float", () => { + module Test = { + JSON.parseExn(`42.0`)->JSON.Decode.float + // Some(42.0) + + JSON.parseExn(`"hello world"`)->JSON.Decode.float + // None + } + () + }) +}) + +describe("JSON.Decode.string", () => { + test("JSON.Decode.string", () => { + module Test = { + JSON.parseExn(`"hello world"`)->JSON.Decode.string + // Some("hello world") + + JSON.parseExn(`42`)->JSON.Decode.string + // None + } + () + }) +}) + +describe("JSON.Decode.null", () => { + test("JSON.Decode.null", () => { + module Test = { + JSON.parseExn(`null`)->JSON.Decode.null + // Some(null) + + JSON.parseExn(`"hello world"`)->JSON.Decode.null + // None + } + () + }) +}) + +describe("JSON.Decode.bool", () => { + test("JSON.Decode.bool", () => { + module Test = { + JSON.parseExn(`true`)->JSON.Decode.bool + // Some(true) + + JSON.parseExn(`"hello world"`)->JSON.Decode.bool + // None + } + () + }) +}) + +describe("JSON.Encode.array", () => { + test("JSON.Encode.array", () => { + module Test = { + let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] + + JSON.Encode.array(array) + } + () + }) +}) + +describe("JSON.Encode.object", () => { + test("JSON.Encode.object", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ]) + + JSON.Encode.object(dict) + } + () + }) +}) + +describe("JSON.Encode.float", () => { + test("JSON.Encode.float", () => { + module Test = { + JSON.Encode.float(42.0) + } + () + }) +}) + +describe("JSON.Encode.int", () => { + test("JSON.Encode.int", () => { + module Test = { + JSON.Encode.int(42) + } + () + }) +}) + +describe("JSON.Encode.string", () => { + test("JSON.Encode.string", () => { + module Test = { + JSON.Encode.string("hello world") + } + () + }) +}) + +describe("JSON.Encode.null", () => { + test("JSON.Encode.null", () => { + module Test = { + JSON.Encode.null + } + () + }) +}) + +describe("JSON.Encode.bool", () => { + test("JSON.Encode.bool", () => { + module Test = { + JSON.Encode.bool(true) + } + () + }) +}) + +describe("JSON.Classify.classify", () => { + test("JSON.Classify.classify", () => { + module Test = { + JSON.Classify.classify("hello world") + // String("hello world") + + JSON.Classify.classify(42) + // Number(42) + } + () + }) +}) + +describe("JSON.stringifyAnyWithFilterAndIndent", () => { + test("JSON.stringifyAnyWithFilterAndIndent", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) + + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyAnyWithFilter", () => { + test("JSON.stringifyAnyWithFilter", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + test("JSON.stringifyAnyWithReplacerAndIndent", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyAnyWithReplacer", () => { + test("JSON.stringifyAnyWithReplacer", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyAnyWithIndent", () => { + test("JSON.stringifyAnyWithIndent", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAnyWithIndent(2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyAny", () => { + test("JSON.stringifyAny", () => { + module Test = { + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) + + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, + ) + + dict + ->JSON.stringifyAny(~replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + // Raise a exception + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("JSON.stringifyWithFilterAndIndent", () => { + test("JSON.stringifyWithFilterAndIndent", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) + // { + // "foo": "bar", + // "someNumber": 42 + // } + } + () + }) +}) + +describe("JSON.stringifyWithFilter", () => { + test("JSON.stringifyWithFilter", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + JSON.stringifyWithFilter(json, ["foo", "someNumber"]) + // {"foo":"bar","someNumber":42} + } + () + }) +}) + +describe("JSON.stringifyWithReplacerAndIndent", () => { + test("JSON.stringifyWithReplacerAndIndent", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + JSON.stringifyWithReplacerAndIndent(json, replacer, 2) + // { + // "foo": "BAR", + // "hello": "WORLD", + // "someNumber": 42 + // } + } + () + }) +}) + +describe("JSON.stringifyWithReplacer", () => { + test("JSON.stringifyWithReplacer", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + JSON.stringifyWithReplacer(json, replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} + } + () + }) +}) + +describe("JSON.stringifyWithIndent", () => { + test("JSON.stringifyWithIndent", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + JSON.stringifyWithIndent(json, 2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } + } + () + }) +}) + +describe("JSON.stringify", () => { + test("JSON.stringify", () => { + module Test = { + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + JSON.stringify(json) + // {"foo":"bar","hello":"world","someNumber":42} + + JSON.stringify(json, ~space=2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } + + JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) + // {"foo":"bar","someNumber":42} + + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, + ) + + JSON.stringify(json, ~replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} + } + () + }) +}) + +describe("JSON.parseExnWithReviver", () => { + test("JSON.parseExnWithReviver", () => { + module Test = { + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } + + let jsonString = `{"hello":"world","someNumber":21}` + + try { + JSON.parseExnWithReviver(jsonString, reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExnWithReviver("", reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } + } + () + }) +}) + +describe("JSON.parseExn", () => { + test("JSON.parseExn", () => { + module Test = { + try { + let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) + // { foo: 'bar', hello: 'world' } + + let _ = JSON.parseExn("") + // error + } catch { + | Exn.Error(_) => Console.log("error") + } + + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } + + let jsonString = `{"hello":"world","someNumber":21}` + + try { + JSON.parseExn(jsonString, ~reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExn("", ~reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } + } + () + }) +}) + +describe("Map.entries", () => { + test("Map.entries", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") + + let entries = map->Map.entries + + // Logs the first value + Console.log(Iterator.next(entries).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. + Console.log(map->Map.entries->Iterator.toArray) + } + () + }) +}) + +describe("Map.values", () => { + test("Map.values", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") + + let values = map->Map.values + + // Logs the first value + Console.log(Iterator.next(values).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(map->Map.values->Iterator.toArray) + } + () + }) +}) + +describe("Map.keys", () => { + test("Map.keys", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") + + let keys = map->Map.keys + + // Logs the first key + Console.log(Iterator.next(keys).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. + Console.log(map->Map.keys->Iterator.toArray) + } + () + }) +}) + +describe("Map.delete", () => { + test("Map.delete", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + let didDeleteKey = map->Map.delete("someKey") + Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted + + let didDeleteKey = map->Map.delete("someNonExistantKey") + Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist + } + () + }) +}) + +describe("Map.set", () => { + test("Map.set", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + } + () + }) +}) + +describe("Map.has", () => { + test("Map.has", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + + switch map->Map.has("someKey") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") + } + } + () + }) +}) + +describe("Map.get", () => { + test("Map.get", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + + switch map->Map.get("someKey") { + | None => Console.log("Nope, didn't have it.") + | Some(value) => Console.log2("Yay, had the value, and it's:", value) + } + } + () + }) +}) + +describe("Map.forEachWithKey", () => { + test("Map.forEachWithKey", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + map->Map.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) + } + () + }) +}) + +describe("Map.forEach", () => { + test("Map.forEach", () => { + module Test = { + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + map->Map.forEach( + value => { + Console.log(value) + }, + ) + } + () + }) +}) + +describe("Map.clear", () => { + test("Map.clear", () => { + module Test = { + let map = Map.make() + + map->Map.set("someKey", "someValue") + map->Map.size // 1 + + map->Map.clear + map->Map.size // 0 + } + () + }) +}) + +describe("Map.size", () => { + test("Map.size", () => { + module Test = { + let map = Map.make() + + map->Map.set("someKey", "someValue") + + let size = map->Map.size // 1 + } + () + }) +}) + +describe("Map.fromIterator", () => { + test("Map.fromIterator", () => { + module Test = { + // Let's pretend we have an interator in the correct shape + let iterator: Iterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + iterator + ->Map.fromIterator + ->Map.size + ->assertEqual(2) + } + () + }) +}) + +describe("Map.fromArray", () => { + test("Map.fromArray", () => { + module Test = { + type languages = ReScript | JavaScript | TypeScript + let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] + + let map = Map.fromArray(languageRank) // Map.t + + switch map->Map.get(ReScript) { + | Some(1) => Console.log("Yay, ReScript is #1!") + | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } + } + () + }) +}) + +describe("Map.make", () => { + test("Map.make", () => { + module Test = { + `make()` + // You can annotate the type of your map if you want to + let myMap: Map.t = Map.make() + + // Or you can let ReScript infer what's in your map + let map = Map.make() + map->Map.set("lang", "ReScript") // Inferred as Map.t + } + () + }) +}) + +describe("Null.flatMap", () => { + test("Null.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Null.make(value + 1) + } else { + Null.null + } + + Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) + Null.flatMap(Null.make(-4), addIfAboveOne) // null + Null.flatMap(Null.null, addIfAboveOne) // null + } + () + }) +}) + +describe("Null.mapOr", () => { + test("Null.mapOr", () => { + module Test = { + let someValue = Null.make(3) + someValue->Null.mapOr(0, x => x + 5) // 8 + + let noneValue = Null.null + noneValue->Null.mapOr(0, x => x + 5) // 0 + } + () + }) +}) + +describe("Null.map", () => { + test("Null.map", () => { + module Test = { + Null.map(Null.make(3), x => x * x) // Null.make(9) + Null.map(Null.null, x => x * x) // null + } + () + }) +}) + +describe("Null.forEach", () => { + test("Null.forEach", () => { + module Test = { + Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" + Null.forEach(Null.null, x => Console.log(x)) // logs nothing + } + () + }) +}) + +describe("Null.getUnsafe", () => { + test("Null.getUnsafe", () => { + module Test = { + Null.getUnsafe(Null.make(3)) == 3 + Null.getUnsafe(Null.null) // Raises an error + } + () + }) +}) + +describe("Null.getExn", () => { + test("Null.getExn", () => { + module Test = { + Null.getExn(Null.make(3))->assertEqual(3) + + switch Null.getExn(%raw("'ReScript'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "ReScript") + } + + switch Null.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Null.getOr", () => { + test("Null.getOr", () => { + module Test = { + Null.getOr(Null.null, "Banana") // Banana + Null.getOr(Null.make("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Null.make("Jane")->Null.toOption->greet // "Greetings Jane" + Null.null->Null.toOption->greet // "Greetings Anonymous" + } + () + }) +}) + +describe("Null.fromOption", () => { + test("Null.fromOption", () => { + module Test = { + let optString: option = None + let asNull = optString->Null.fromOption // Null.t + Console.log(asNull == Null.null) // Logs `true` to the console. + } + () + }) +}) + +describe("Null.toOption", () => { + test("Null.toOption", () => { + module Test = { + let nullStr = Null.make("Hello") + + switch nullStr->Null.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } + } + () + }) +}) + +describe("Null.make", () => { + test("Null.make", () => { + module Test = { + let myStr = "Hello" + let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. + } + () + }) +}) + +describe("Null.null", () => { + test("Null.null", () => { + module Test = { + Console.log(null) // Logs `null` to the console. + } + () + }) +}) + +describe("Null.asNullable", () => { + test("Null.asNullable", () => { + module Test = { + let nullValue = Null.make("Hello") + let asNullable = nullValue->Null.asNullable // Nullable.t + } + () + }) +}) + +describe("List.sort", () => { + test("List.sort", () => { + module Test = { + List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} + } + () + }) +}) + +describe("List.setAssoc", () => { + test("List.setAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} + + list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + // list{(9, "morning"), (15, "afternoon"), (22, "night")} + } + () + }) +}) + +describe("List.removeAssoc", () => { + test("List.removeAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + // list{(15, "afternoon"), (22, "night")} + } + () + }) +}) + +describe("List.hasAssoc", () => { + test("List.hasAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) // false + } + () + }) +}) + +describe("List.getAssoc", () => { + test("List.getAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + // Some("afternoon") + } + () + }) +}) + +describe("List.unzip", () => { + test("List.unzip", () => { + module Test = { + List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) + + List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) + } + () + }) +}) + +describe("List.partition", () => { + test("List.partition", () => { + module Test = { + // (elementsThatSatisfies, elementsThatDoesNotSatisfy) + + List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) + } + () + }) +}) + +describe("List.filterMap", () => { + test("List.filterMap", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->List.filterMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) // list{2, 4} + + list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} + } + () + }) +}) + +describe("List.filterWithIndex", () => { + test("List.filterWithIndex", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} + } + () + }) +}) + +describe("List.filter", () => { + test("List.filter", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 + + List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} + + List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} + } + () + }) +}) + +describe("List.find", () => { + test("List.find", () => { + module Test = { + List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) + + List.find(list{1, 4, 3, 2}, x => x > 4) // None + } + () + }) +}) + +describe("List.has", () => { + test("List.has", () => { + module Test = { + list{1, 2, 3}->List.has(2, (a, b) => a == b) // true + + list{1, 2, 3}->List.has(4, (a, b) => a == b) // false + + list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true + } + () + }) +}) + +describe("List.equal", () => { + test("List.equal", () => { + module Test = { + List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false + + List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true + + List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true + } + () + }) +}) + +describe("List.compare", () => { + test("List.compare", () => { + module Test = { + List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. + } + () + }) +}) + +describe("List.compareLength", () => { + test("List.compareLength", () => { + module Test = { + List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. + + List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. + + List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. + } + () + }) +}) + +describe("List.some2", () => { + test("List.some2", () => { + module Test = { + List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true + + List.some2(list{}, list{1}, (a, b) => a > b) // false + + List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true + } + () + }) +}) + +describe("List.every2", () => { + test("List.every2", () => { + module Test = { + List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true + + List.every2(list{}, list{1}, (a, b) => a > b) // true + + List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false + } + () + }) +}) + +describe("List.some", () => { + test("List.some", () => { + module Test = { + let isAbove100 = value => value > 100 + + list{101, 1, 2, 3}->List.some(isAbove100) // true + + list{1, 2, 3, 4}->List.some(isAbove100) // false + } + () + }) +}) + +describe("List.every", () => { + test("List.every", () => { + module Test = { + let isBelow10 = value => value < 10 + + list{1, 9, 8, 2}->List.every(isBelow10) // true + + list{1, 99, 8, 2}->List.every(isBelow10) // false + } + () + }) +}) + +describe("List.reduceReverse2", () => { + test("List.reduceReverse2", () => { + module Test = { + List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) + } + () + }) +}) + +describe("List.reduce2", () => { + test("List.reduce2", () => { + module Test = { + List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) + } + () + }) +}) + +describe("List.forEach2", () => { + test("List.forEach2", () => { + module Test = { + List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) + + /* + prints: + "Z" "A" + "Y" "B" +*/ + } + () + }) +}) + +describe("List.mapReverse2", () => { + test("List.mapReverse2", () => { + module Test = { + List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + } + () + }) +}) + +describe("List.reduceReverse", () => { + test("List.reduceReverse", () => { + module Test = { + list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 + + list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 + + list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} + } + () + }) +}) + +describe("List.reduceWithIndex", () => { + test("List.reduceWithIndex", () => { + module Test = { + list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 + } + () + }) +}) + +describe("List.reduce", () => { + test("List.reduce", () => { + module Test = { + list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 + + // same as + + list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 + } + () + }) +}) + +describe("List.forEachWithIndex", () => { + test("List.forEachWithIndex", () => { + module Test = { + List.forEachWithIndex( + list{"a", "b", "c"}, + (x, index) => { + Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + } + () + }) +}) + +describe("List.forEach", () => { + test("List.forEach", () => { + module Test = { + List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ + } + () + }) +}) + +describe("List.mapReverse", () => { + test("List.mapReverse", () => { + module Test = { + let f = x => x * x + let l = list{3, 4, 5} + + let withMap = List.map(l, f)->List.reverse + let withMapReverse = l->List.mapReverse(f) + + Console.log(withMap == withMapReverse) // true + } + () + }) +}) + +describe("List.reverse", () => { + test("List.reverse", () => { + module Test = { + List.reverse(list{1, 2, 3}) // list{3, 2, 1} + } + () + }) +}) + +describe("List.toArray", () => { + test("List.toArray", () => { + module Test = { + List.toArray(list{1, 2, 3}) // [1, 2, 3] + } + () + }) +}) + +describe("List.fromArray", () => { + test("List.fromArray", () => { + module Test = { + List.fromArray([1, 2, 3]) // list{1, 2, 3} + } + () + }) +}) + +describe("List.mapWithIndex", () => { + test("List.mapWithIndex", () => { + module Test = { + list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} + } + () + }) +}) + +describe("List.zipBy", () => { + test("List.zipBy", () => { + module Test = { + List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + } + () + }) +}) + +describe("List.zip", () => { + test("List.zip", () => { + module Test = { + List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + } + () + }) +}) + +describe("List.map", () => { + test("List.map", () => { + module Test = { + list{1, 2}->List.map(x => x + 1) // list{3, 4} + } + () + }) +}) + +describe("List.flat", () => { + test("List.flat", () => { + module Test = { + List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("List.reverseConcat", () => { + test("List.reverseConcat", () => { + module Test = { + List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + } + () + }) +}) + +describe("List.concatMany", () => { + test("List.concatMany", () => { + module Test = { + List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + } + () + }) +}) + +describe("List.concat", () => { + test("List.concat", () => { + module Test = { + List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + } + () + }) +}) + +describe("List.splitAt", () => { + test("List.splitAt", () => { + module Test = { + list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + + list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + } + () + }) +}) + +describe("List.take", () => { + test("List.take", () => { + module Test = { + list{1, 2, 3}->List.take(1) // Some(list{1}) + + list{1, 2, 3}->List.take(2) // Some(list{1, 2}) + + list{1, 2, 3}->List.take(4) // None + } + () + }) +}) + +describe("List.drop", () => { + test("List.drop", () => { + module Test = { + list{1, 2, 3}->List.drop(2) // Some(list{3}) + + list{1, 2, 3}->List.drop(3) // Some(list{}) + + list{1, 2, 3}->List.drop(4) // None + } + () + }) +}) + +describe("List.toShuffled", () => { + test("List.toShuffled", () => { + module Test = { + List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} + } + () + }) +}) + +describe("List.fromInitializer", () => { + test("List.fromInitializer", () => { + module Test = { + List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} + + List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} + } + () + }) +}) + +describe("List.make", () => { + test("List.make", () => { + module Test = { + List.make(~length=3, 1) // list{1, 1, 1} + } + () + }) +}) + +describe("List.getExn", () => { + test("List.getExn", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc + ->List.getExn(1) + ->assertEqual("B") + + switch abc->List.getExn(4) { + | exception Not_found => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("List.get", () => { + test("List.get", () => { + module Test = { + let abc = list{"A", "B", "C"} + + abc->List.get(1) // Some("B") + + abc->List.get(4) // None + } + () + }) +}) + +describe("List.add", () => { + test("List.add", () => { + module Test = { + List.add(list{2, 3}, 1) // list{1, 2, 3} + + List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + } + () + }) +}) + +describe("List.tailExn", () => { + test("List.tailExn", () => { + module Test = { + List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch List.tailExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("List.tail", () => { + test("List.tail", () => { + module Test = { + List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + List.tail(list{}) // None + } + () + }) +}) + +describe("List.headExn", () => { + test("List.headExn", () => { + module Test = { + List.headExn(list{1, 2, 3})->assertEqual(1) + + switch List.headExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("List.head", () => { + test("List.head", () => { + module Test = { + List.head(list{}) // None + List.head(list{1, 2, 3}) // Some(1) + } + () + }) +}) + +describe("List.size", () => { + test("List.size", () => { + module Test = { + List.size(list{1, 2, 3}) // 3 + } + () + }) +}) + +describe("List.length", () => { + test("List.length", () => { + module Test = { + List.length(list{1, 2, 3}) // 3 + } + () + }) +}) + +describe("Math.Int.random", () => { + test("Math.Int.random", () => { + module Test = { + Math.Int.random(2, 5) == 4 + Math.Int.random(505, 2000) == 1276 + Math.Int.random(-7, -2) == -4 + } + () + }) +}) + +describe("Math.Int.ceil", () => { + test("Math.Int.ceil", () => { + module Test = { + Math.Int.ceil(3.7) == 4 + Math.Int.ceil(3.0) == 3 + Math.Int.ceil(-3.1) == -3 + } + () + }) +}) + +describe("Math.Int.floor", () => { + test("Math.Int.floor", () => { + module Test = { + Math.Int.floor(3.7) == 3 + Math.Int.floor(3.0) == 3 + Math.Int.floor(-3.1) == -4 + } + () + }) +}) + +describe("Math.Int.sign", () => { + test("Math.Int.sign", () => { + module Test = { + Math.Int.sign(3) // 1 + Math.Int.sign(-3) // -1 + Math.Int.sign(0) // 0 + } + () + }) +}) + +describe("Math.Int.pow", () => { + test("Math.Int.pow", () => { + module Test = { + Math.Int.pow(2, ~exp=4) // 16 + Math.Int.pow(3, ~exp=4) // 81 + } + () + }) +}) + +describe("Math.Int.maxMany", () => { + test("Math.Int.maxMany", () => { + module Test = { + Math.Int.maxMany([1, 2]) // 2 + Math.Int.maxMany([-1, -2]) // -1 + Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false + } + () + }) +}) + +describe("Math.Int.max", () => { + test("Math.Int.max", () => { + module Test = { + Math.Int.max(1, 2) // 2 + Math.Int.max(-1, -2) // -1 + } + () + }) +}) + +describe("Math.Int.minMany", () => { + test("Math.Int.minMany", () => { + module Test = { + Math.Int.minMany([1, 2]) // 1 + Math.Int.minMany([-1, -2]) // -2 + Math.Int.minMany([])->Int.toFloat->Float.isFinite // false + } + () + }) +}) + +describe("Math.Int.min", () => { + test("Math.Int.min", () => { + module Test = { + Math.Int.min(1, 2) // 1 + Math.Int.min(-1, -2) // -2 + } + () + }) +}) + +describe("Math.Int.imul", () => { + test("Math.Int.imul", () => { + module Test = { + Math.Int.imul(3, 4) // 12 + Math.Int.imul(-5, 12) // 60 + } + () + }) +}) + +describe("Math.Int.clz32", () => { + test("Math.Int.clz32", () => { + module Test = { + // 00000000000000000000000000000001 + Math.Int.clz32(1) // 31 + // 00000000000000000000000000000100 + Math.Int.clz32(4) // 29 + } + () + }) +}) + +describe("Math.Int.abs", () => { + test("Math.Int.abs", () => { + module Test = { + Math.Int.abs(-2) // 2 + Math.Int.abs(3) // 3 + } + () + }) +}) + +describe("Math.Constants.sqrt2", () => { + test("Math.Constants.sqrt2", () => { + module Test = { + Math.Constants.sqrt2 + } + () + }) +}) + +describe("Math.Constants.sqrt1_2", () => { + test("Math.Constants.sqrt1_2", () => { + module Test = { + Math.Constants.sqrt1_2 + } + () + }) +}) + +describe("Math.Constants.pi", () => { + test("Math.Constants.pi", () => { + module Test = { + Math.Constants.pi + } + () + }) +}) + +describe("Math.Constants.log10e", () => { + test("Math.Constants.log10e", () => { + module Test = { + Math.Constants.log10e + } + () + }) +}) + +describe("Math.Constants.log2e", () => { + test("Math.Constants.log2e", () => { + module Test = { + Math.Constants.log2e + } + () + }) +}) + +describe("Math.Constants.ln10", () => { + test("Math.Constants.ln10", () => { + module Test = { + Math.Constants.ln10 + } + () + }) +}) + +describe("Math.Constants.ln2", () => { + test("Math.Constants.ln2", () => { + module Test = { + Math.Constants.ln2 + } + () + }) +}) + +describe("Math.Constants.e", () => { + test("Math.Constants.e", () => { + module Test = { + Math.Constants.e + } + () + }) +}) + +describe("Math.trunc", () => { + test("Math.trunc", () => { + module Test = { + Math.trunc(0.123) // 0.0 + Math.trunc(1.999) // 1.0 + Math.trunc(13.37) // 13.0 + Math.trunc(42.84) // 42.0 + } + () + }) +}) + +describe("Math.tanh", () => { + test("Math.tanh", () => { + module Test = { + Math.tanh(-0.0) // -0.0 + Math.tanh(0.0) // 0.0 + Math.tanh(1.0) // 0.7615941559557649 + } + () + }) +}) + +describe("Math.tan", () => { + test("Math.tan", () => { + module Test = { + Math.tan(-0.0) // -0.0 + Math.tan(0.0) // 0.0 + Math.tan(1.0) // 1.5574077246549023 + } + () + }) +}) + +describe("Math.sqrt", () => { + test("Math.sqrt", () => { + module Test = { + Math.sqrt(-1.0)->Float.isNaN // true + Math.sqrt(-0.0) // -0.0 + Math.sqrt(0.0) // 0.0 + Math.sqrt(1.0) // 1.0 + Math.sqrt(9.0) // 3.0 + } + () + }) +}) + +describe("Math.sinh", () => { + test("Math.sinh", () => { + module Test = { + Math.sinh(-0.0) // -0.0 + Math.sinh(0.0) // 0.0 + Math.sinh(1.0) // 1.1752011936438014 + } + () + }) +}) + +describe("Math.sin", () => { + test("Math.sin", () => { + module Test = { + Math.sin(-0.0) // -0.0 + Math.sin(0.0) // 0.0 + Math.sin(1.0) // 0.8414709848078965 + } + () + }) +}) + +describe("Math.sign", () => { + test("Math.sign", () => { + module Test = { + Math.sign(3.0) // 1.0 + Math.sign(-3.0) // 1.0 + Math.sign(0.0) // 0.0 + } + () + }) +}) + +describe("Math.round", () => { + test("Math.round", () => { + module Test = { + Math.round(-20.5) // -20.0 + Math.round(-0.1) // -0.0 + Math.round(0.0) // 0.0 + Math.round(-0.0) // -0.0 + } + () + }) +}) + +describe("Math.random", () => { + test("Math.random", () => { + module Test = { + Math.random() + } + () + }) +}) + +describe("Math.pow", () => { + test("Math.pow", () => { + module Test = { + Math.pow(2.0, ~exp=4.0) // 16.0 + Math.pow(3.0, ~exp=4.0) // 81.0 + } + () + }) +}) + +describe("Math.maxMany", () => { + test("Math.maxMany", () => { + module Test = { + Math.maxMany([1.0, 2.0]) // 2.0 + Math.maxMany([-1.0, -2.0]) // -1.0 + Math.maxMany([])->Float.isFinite // false + } + () + }) +}) + +describe("Math.max", () => { + test("Math.max", () => { + module Test = { + Math.max(1.0, 2.0) // 2.0 + Math.max(-1.0, -2.0) // -1.0 + } + () + }) +}) + +describe("Math.minMany", () => { + test("Math.minMany", () => { + module Test = { + Math.minMany([1.0, 2.0]) // 1.0 + Math.minMany([-1.0, -2.0]) // -2.0 + Math.minMany([])->Float.isFinite // false + } + () + }) +}) + +describe("Math.min", () => { + test("Math.min", () => { + module Test = { + Math.min(1.0, 2.0) // 1.0 + Math.min(-1.0, -2.0) // -2.0 + } + () + }) +}) + +describe("Math.log2", () => { + test("Math.log2", () => { + module Test = { + Math.log2(-2.0)->Float.isNaN // true + Math.log2(-0.0)->Float.isFinite // false + Math.log2(0.0)->Float.isFinite // false + Math.log2(1.0) // 0.0 + } + () + }) +}) + +describe("Math.log10", () => { + test("Math.log10", () => { + module Test = { + Math.log10(-2.0)->Float.isNaN // true + Math.log10(-0.0)->Float.isFinite // false + Math.log10(0.0)->Float.isFinite // false + Math.log10(1.0) // 0 + } + () + }) +}) + +describe("Math.log1p", () => { + test("Math.log1p", () => { + module Test = { + Math.log1p(-2.0)->Float.isNaN // true + Math.log1p(-1.0)->Float.isFinite // false + Math.log1p(-0.0) // -0 + } + () + }) +}) + +describe("Math.log", () => { + test("Math.log", () => { + module Test = { + Math.log(-1.0)->Float.isNaN // true + Math.log(-0.0)->Float.isFinite // false + Math.log(0.0)->Float.isFinite // false + Math.log(1.0) // 0 + } + () + }) +}) + +describe("Math.hypotMany", () => { + test("Math.hypotMany", () => { + module Test = { + Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 + Math.hypotMany([]) // 0.0 + } + () + }) +}) + +describe("Math.hypot", () => { + test("Math.hypot", () => { + module Test = { + Math.hypot(3.0, 4.0) // 5.0 + Math.hypot(3.0, 5.0) // 5.8309518948453 + } + () + }) +}) + +describe("Math.fround", () => { + test("Math.fround", () => { + module Test = { + Math.fround(5.5) == 5.5 + Math.fround(5.05) == 5.050000190734863 + } + () + }) +}) + +describe("Math.floor", () => { + test("Math.floor", () => { + module Test = { + Math.floor(-45.95) // -46.0 + Math.floor(-45.05) // -46.0 + Math.floor(-0.0) // -0.0 + } + () + }) +}) + +describe("Math.expm1", () => { + test("Math.expm1", () => { + module Test = { + Math.expm1(-1.0) // -0.6321205588285577 + Math.expm1(-0.0) // -0 + } + () + }) +}) + +describe("Math.exp", () => { + test("Math.exp", () => { + module Test = { + Math.exp(-1.0) // 0.36787944117144233 + Math.exp(0.0) // 1.0 + } + () + }) +}) + +describe("Math.cosh", () => { + test("Math.cosh", () => { + module Test = { + Math.cosh(-1.0) // 1.5430806348152437 + Math.cosh(-0.0) // 1.0 + Math.cosh(0.0) // 1.0 + } + () + }) +}) + +describe("Math.cos", () => { + test("Math.cos", () => { + module Test = { + Math.cos(-0.0) // 1.0 + Math.cos(0.0) // 1.0 + Math.cos(1.0) // 0.5403023058681398 + } + () + }) +}) + +describe("Math.ceil", () => { + test("Math.ceil", () => { + module Test = { + Math.ceil(3.1) == 4.0 + Math.ceil(3.0) == 3.0 + Math.ceil(-3.1) == -3.0 + Math.ceil(2_150_000_000.3) == 2_150_000_001.0 + } + () + }) +}) + +describe("Math.cbrt", () => { + test("Math.cbrt", () => { + module Test = { + Math.cbrt(-1.0) // -1.0 + Math.cbrt(-0.0) // -0.0 + Math.cbrt(0.0) // 0.0 + } + () + }) +}) + +describe("Math.atan2", () => { + test("Math.atan2", () => { + module Test = { + Math.atan2(~y=0.0, ~x=10.0) == 0.0 + Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 + Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 + Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 + } + () + }) +}) + +describe("Math.atanh", () => { + test("Math.atanh", () => { + module Test = { + Math.atanh(-2.0)->Float.isNaN // true + Math.atanh(-1.0)->Float.isFinite // false + Math.atanh(-0.0) // -0.0 + Math.atanh(0.0) // 0.0 + Math.atanh(0.5) // 0.5493061443340548 + } + () + }) +}) + +describe("Math.atan", () => { + test("Math.atan", () => { + module Test = { + Math.atan(-0.0) // -0.0 + Math.atan(0.0) // 0.0 + Math.atan(1.0) // 0.7853981633974483 + } + () + }) +}) + +describe("Math.asinh", () => { + test("Math.asinh", () => { + module Test = { + Math.asinh(-1.0) // -0.881373587019543 + Math.asinh(-0.0) // -0.0 + } + () + }) +}) + +describe("Math.asin", () => { + test("Math.asin", () => { + module Test = { + Math.asin(-1.0) // -1.5707963267948966 + Math.asin(-2.0)->Float.isNaN // true + } + () + }) +}) + +describe("Math.acosh", () => { + test("Math.acosh", () => { + module Test = { + Math.acosh(1.0) // 0.0 + Math.acosh(0.5)->Float.isNaN // true + } + () + }) +}) + +describe("Math.acos", () => { + test("Math.acos", () => { + module Test = { + Math.acos(-1.0) // 3.141592653589793 + Math.acos(-3.0)->Float.isNaN // true + } + () + }) +}) + +describe("Math.abs", () => { + test("Math.abs", () => { + module Test = { + Math.abs(-2.0) // 2.0 + Math.abs(3.0) // 3.0 + } + () + }) +}) + +describe("Nullable.flatMap", () => { + test("Nullable.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Nullable.make(value + 1) + } else { + Nullable.null + } + + Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) + Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined + Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined + } + () + }) +}) + +describe("Nullable.mapOr", () => { + test("Nullable.mapOr", () => { + module Test = { + let someValue = Nullable.make(3) + someValue->Nullable.mapOr(0, x => x + 5) // 8 + + let noneValue = Nullable.null + noneValue->Nullable.mapOr(0, x => x + 5) // 0 + } + () + }) +}) + +describe("Nullable.map", () => { + test("Nullable.map", () => { + module Test = { + Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) + Nullable.map(undefined, x => x * x) // undefined + } + () + }) +}) + +describe("Nullable.forEach", () => { + test("Nullable.forEach", () => { + module Test = { + Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" + Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () + Nullable.forEach(undefined, x => Console.log(x)) // returns () + } + () + }) +}) + +describe("Nullable.getUnsafe", () => { + test("Nullable.getUnsafe", () => { + module Test = { + Nullable.getUnsafe(Nullable.make(3)) == 3 + Nullable.getUnsafe(Nullable.null) // Raises an error + } + () + }) +}) + +describe("Nullable.getExn", () => { + test("Nullable.getExn", () => { + module Test = { + switch Nullable.getExn(%raw("'Hello'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "Hello") + } + + switch Nullable.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } + + switch Nullable.getExn(%raw("undefined")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Nullable.getOr", () => { + test("Nullable.getOr", () => { + module Test = { + Nullable.getOr(Nullable.null, "Banana") // Banana + Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" + Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" + } + () + }) +}) + +describe("Nullable.fromOption", () => { + test("Nullable.fromOption", () => { + module Test = { + let optString = Some("Hello") + let asNullable = optString->Nullable.fromOption // Nullable.t + } + () + }) +}) + +describe("Nullable.toOption", () => { + test("Nullable.toOption", () => { + module Test = { + let nullableString = Nullable.make("Hello") + + switch nullableString->Nullable.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } + } + () + }) +}) + +describe("Nullable.make", () => { + test("Nullable.make", () => { + module Test = { + let myStr = "Hello" + let asNullable = myStr->Nullable.make + + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable + + // Need to do this + switch asNullable->Nullable.toOption { + | Some(value) if value == myStr => Console.log("Yay, values matched!") + | _ => Console.log("Values did not match.") + } + } + () + }) +}) + +describe("Nullable.isNullable", () => { + test("Nullable.isNullable", () => { + module Test = { + let myStr = "Hello" + let asNullable = myStr->Nullable.make + + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable + + // Check if asNullable is not null or undefined + switch asNullable->Nullable.isNullable { + | true => assert(false) + | false => assert(true) + } + } + () + }) +}) + +describe("Nullable.undefined", () => { + test("Nullable.undefined", () => { + module Test = { + Console.log(undefined) // Logs `undefined` to the console. + } + () + }) +}) + +describe("Nullable.null", () => { + test("Nullable.null", () => { + module Test = { + Console.log(Nullable.null) // Logs `null` to the console. + } + () + }) +}) + +describe("Object.isExtensible", () => { + test("Object.isExtensible", () => { + module Test = { + let obj = {"a": 1} + obj->Object.isExtensible // true + obj->Object.preventExtensions->ignore + obj->Object.isExtensible // false + } + () + }) +}) + +describe("Object.isFrozen", () => { + test("Object.isFrozen", () => { + module Test = { + let point = {"x": 1, "y": 3}->Object.freeze + let pointIsFrozen = point->Object.isFrozen // true + let fruit = {"name": "Apple"} + let fruitIsFrozen = fruit->Object.isFrozen // false + } + () + }) +}) + +describe("Object.isSealed", () => { + test("Object.isSealed", () => { + module Test = { + let point = {"x": 1, "y": 3}->Object.seal + let pointIsSealed = point->Object.isSealed // true + let fruit = {"name": "Apple"} + let fruitIsSealed = fruit->Object.isSealed // false + } + () + }) +}) + +describe("Object.freeze", () => { + test("Object.freeze", () => { + module Test = { + let obj = {"a": 1} + obj->Object.set("a", 2) // succeeds + obj->Object.freeze->ignore + + try { + obj->Object.set("a", 3) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Object.preventExtensions", () => { + test("Object.preventExtensions", () => { + module Test = { + let obj = {"a": 1} + obj->Object.set("b", 2) // succeeds + obj->Object.preventExtensions->ignore + try { + obj->Object.set("c", 3) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } + } + () + }) +}) + +describe("Object.seal", () => { + test("Object.seal", () => { + module Test = { + let point = {"x": 1, "y": 2} + point->Object.set("x", -7) // succeeds + point->Object.seal->ignore + + try { + point->Object.set("z", 9) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } + + point->Object.set("x", 13) // succeeds + } + () + }) +}) + +describe("Object.hasOwnProperty", () => { + test("Object.hasOwnProperty", () => { + module Test = { + let point = {"x": 1, "y": 2} + {"a": 1}->Object.hasOwnProperty("a") // true + {"a": 1}->Object.hasOwnProperty("b") // false + {"a": 1}->Object.hasOwnProperty("toString") // false + } + () + }) +}) + +describe("Object.keysToArray", () => { + test("Object.keysToArray", () => { + module Test = { + {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] + {"a": None}->Object.keysToArray // ["a"] + Object.make()->Object.keysToArray // [] + } + () + }) +}) + +describe("Object.set", () => { + test("Object.set", () => { + module Test = { + {"a": 1}->Object.set("a", 2) // {"a": 2} + {"a": 1}->Object.set("a", None) // {"a": None} + {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} + } + () + }) +}) + +describe("Object.getSymbol", () => { + test("Object.getSymbol", () => { + module Test = { + let fruit = Symbol.make("fruit") + let x = Object.make() + x->Object.setSymbol(fruit, "banana") + x->Object.getSymbol(fruit) // Some("banana") + } + () + }) +}) + +describe("Object.get", () => { + test("Object.get", () => { + module Test = { + {"a": 1}->Object.get("a") // Some(1) + {"a": 1}->Object.get("b") // None + {"a": undefined}->Object.get("a") // None + {"a": null}->Object.get("a") // Some(null) + {"a": 1}->Object.get("toString")->Option.isSome // true + } + () + }) +}) + +describe("Object.assign", () => { + test("Object.assign", () => { + module Test = { + Object.assign({"a": 1}, {"a": 2}) // {"a": 2} + Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} + Object.assign({"a": 1}, {"a": null}) // {"a": null} + } + () + }) +}) + +describe("Object.create", () => { + test("Object.create", () => { + module Test = { + let x = {"fruit": "banana"} + let y = Object.create(x) + y->Object.get("fruit") // Some("banana") + } + () + }) +}) + +describe("Object.is", () => { + test("Object.is", () => { + module Test = { + Object.is(25, 13) // false + Object.is("abc", "abc") // true + Object.is(undefined, undefined) // true + Object.is(undefined, null) // false + Object.is(-0.0, 0.0) // false + Object.is(list{1, 2}, list{1, 2}) // false + + Object.is([1, 2, 3], [1, 2, 3]) // false + [1, 2, 3] == [1, 2, 3] // true + [1, 2, 3] === [1, 2, 3] // false + + let fruit = {"name": "Apple"} + Object.is(fruit, fruit) // true + Object.is(fruit, {"name": "Apple"}) // false + fruit == {"name": "Apple"} // true + fruit === {"name": "Apple"} // false + } + () + }) +}) + +describe("Object.make", () => { + test("Object.make", () => { + module Test = { + let x = Object.make() + x->Object.keysToArray->Array.length // 0 + x->Object.get("toString")->Option.isSome // true + } + () + }) +}) + +describe("Pervasives.assertEqual", () => { + test("Pervasives.assertEqual", () => { + module Test = { + list{1, 2} + ->List.tailExn + ->assertEqual(list{2}) + } + () + }) +}) + +describe("Pervasives.import", () => { + test("Pervasives.import", () => { + module Test = { + @send external indexOf: (array<'a>, 'a) => int = "indexOf" + + let indexOfOpt = (arr, item) => + switch arr->indexOf(item) { + | -1 => None + | index => Some(index) + } + + let main = async () => { + let indexOfOpt = await import(Array.indexOfOpt) + let index = indexOfOpt([1, 2], 2) + Console.log(index) + } + } + () + }) +}) + +describe("Pervasives.decodeURIComponent", () => { + test("Pervasives.decodeURIComponent", () => { + module Test = { + Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) + // Logs "array=[someValue]" to the console. + } + () + }) +}) + +describe("Pervasives.encodeURIComponent", () => { + test("Pervasives.encodeURIComponent", () => { + module Test = { + Console.log(encodeURIComponent("array=[someValue]")) + // Logs "array%3D%5BsomeValue%5D" to the console. + } + () + }) +}) + +describe("Pervasives.decodeURI", () => { + test("Pervasives.decodeURI", () => { + module Test = { + Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) + // Logs "https://rescript-lang.org?array=[someValue]" to the console. + } + () + }) +}) + +describe("Pervasives.encodeURI", () => { + test("Pervasives.encodeURI", () => { + module Test = { + Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) + // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. + } + () + }) +}) + +describe("Pervasives.clearInterval", () => { + test("Pervasives.clearInterval", () => { + module Test = { + let intervalId = setInterval( + () => { + Console.log("This prints in 100 ms") + }, + 100, + ) + + // Stop the interval after 500 ms + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) + }, + 500, + ) + } + () + }) +}) + +describe("Pervasives.setIntervalFloat", () => { + test("Pervasives.setIntervalFloat", () => { + module Test = { + // Log to the console ever 2 seconds (200 milliseconds). + let intervalId = setIntervalFloat( + () => { + Console.log("This prints every 200 ms") + }, + 200., + ) + + // Stop the interval after 500 ms + let timeoutId = setTimeoutFloat( + () => { + clearInterval(intervalId) + }, + 500.0, + ) + } + () + }) +}) + +describe("Pervasives.setInterval", () => { + test("Pervasives.setInterval", () => { + module Test = { + // Log to the console ever 200 ms (200 milliseconds). + let intervalId = setInterval( + () => { + Console.log("This prints every 200 ms.") + }, + 200, + ) + + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) + }, + 500, + ) + } + () + }) +}) + +describe("Pervasives.clearTimeout", () => { + test("Pervasives.clearTimeout", () => { + module Test = { + let timeoutId = setTimeout( + () => { + Console.log("This prints in 2 seconds.") + }, + 2000, + ) + + // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. + clearTimeout(timeoutId) + } + () + }) +}) + +describe("Pervasives.setTimeoutFloat", () => { + test("Pervasives.setTimeoutFloat", () => { + module Test = { + // Log to the console after 200 milliseconds. + let timeoutId = setTimeoutFloat( + () => { + Console.log("This prints in 200 ms.") + }, + 200., + ) + } + () + }) +}) + +describe("Pervasives.setTimeout", () => { + test("Pervasives.setTimeout", () => { + module Test = { + // Log to the console after 200 milliseconds. + let timeoutId = setTimeout( + () => { + Console.log("This prints in 200 ms.") + }, + 200, + ) + } + () + }) +}) + +describe("Option.all", () => { + test("Option.all", () => { + module Test = { + Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) + Option.all([Some(1), None]) // None + } + () + }) +}) + +describe("Option.compare", () => { + test("Option.compare", () => { + module Test = { + let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) + + Option.compare(Some(3), Some(15), clockCompare) // 0. + Option.compare(Some(3), Some(14), clockCompare) // 1. + Option.compare(Some(2), Some(15), clockCompare) // (-1.) + Option.compare(None, Some(15), clockCompare) // (-1.) + Option.compare(Some(14), None, clockCompare) // 1. + Option.compare(None, None, clockCompare) // 0. + } + () + }) +}) + +describe("Option.equal", () => { + test("Option.equal", () => { + module Test = { + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Option + + equal(Some(3), Some(15), clockEqual) // true + equal(Some(3), None, clockEqual) // false + equal(None, Some(3), clockEqual) // false + equal(None, None, clockEqual) // true + } + () + }) +}) + +describe("Option.isNone", () => { + test("Option.isNone", () => { + module Test = { + Option.isNone(None) // true + Option.isNone(Some(1)) // false + } + () + }) +}) + +describe("Option.isSome", () => { + test("Option.isSome", () => { + module Test = { + Option.isSome(None) // false + Option.isSome(Some(1)) // true + } + () + }) +}) + +describe("Option.orElse", () => { + test("Option.orElse", () => { + module Test = { + Option.orElse(Some(1812), Some(1066)) == Some(1812) + Option.orElse(None, Some(1066)) == Some(1066) + Option.orElse(None, None) == None + } + () + }) +}) + +describe("Option.getOr", () => { + test("Option.getOr", () => { + module Test = { + Option.getOr(None, "Banana") // Banana + Option.getOr(Some("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Some("Jane")->greet // "Greetings Jane" + None->greet // "Greetings Anonymous" + } + () + }) +}) + +describe("Option.flatMap", () => { + test("Option.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Option.flatMap(Some(2), addIfAboveOne) // Some(3) + Option.flatMap(Some(-4), addIfAboveOne) // None + Option.flatMap(None, addIfAboveOne) // None + } + () + }) +}) + +describe("Option.map", () => { + test("Option.map", () => { + module Test = { + Option.map(Some(3), x => x * x) // Some(9) + Option.map(None, x => x * x) // None + } + () + }) +}) + +describe("Option.mapOr", () => { + test("Option.mapOr", () => { + module Test = { + let someValue = Some(3) + someValue->Option.mapOr(0, x => x + 5) // 8 + + let noneValue = None + noneValue->Option.mapOr(0, x => x + 5) // 0 + } + () + }) +}) + +describe("Option.getUnsafe", () => { + test("Option.getUnsafe", () => { + module Test = { + Option.getUnsafe(Some(3)) == 3 + Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` + } + () + }) +}) + +describe("Option.getExn", () => { + test("Option.getExn", () => { + module Test = { + Option.getExn(Some(3))->assertEqual(3) + + switch Option.getExn(None) { + | exception _ => assert(true) + | _ => assert(false) + } + + switch Option.getExn(None, ~message="was None!") { + | exception _ => assert(true) // Raises an Error with the message "was None!" + | _ => assert(false) + } + } + () + }) +}) + +describe("Option.forEach", () => { + test("Option.forEach", () => { + module Test = { + Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" + Option.forEach(None, x => Console.log(x)) // returns () + } + () + }) +}) + +describe("Option.filter", () => { + test("Option.filter", () => { + module Test = { + Option.filter(Some(10), x => x > 5) // Some(10) + Option.filter(Some(4), x => x > 5) // None + Option.filter(None, x => x > 5) // None + } + () + }) +}) + +describe("RegExp.Result.input", () => { + test("RegExp.Result.input", () => { + module Test = { + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") + + // This below will log the full input string "ReScript is pretty cool, right?" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.input) + } + } + () + }) +}) + +describe("RegExp.Result.matches", () => { + test("RegExp.Result.matches", () => { + module Test = { + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") + + // This below will log "ReScript" and "is" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => + switch result->RegExp.Result.matches { + | [firstWord, secondWord] => Console.log2(firstWord, secondWord) + | _ => Console.log("Didn't find exactly two words...") + } + } + } + () + }) +}) + +describe("RegExp.Result.fullMatch", () => { + test("RegExp.Result.fullMatch", () => { + module Test = { + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" + } + } + () + }) +}) + +describe("RegExp.unicode", () => { + test("RegExp.unicode", () => { + module Test = { + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set + } + () + }) +}) + +describe("RegExp.sticky", () => { + test("RegExp.sticky", () => { + module Test = { + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set + } + () + }) +}) + +describe("RegExp.source", () => { + test("RegExp.source", () => { + module Test = { + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` + } + () + }) +}) + +describe("RegExp.multiline", () => { + test("RegExp.multiline", () => { + module Test = { + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") + Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set + } + () + }) +}) + +describe("RegExp.global", () => { + test("RegExp.global", () => { + module Test = { + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set + } + () + }) +}) + +describe("RegExp.ignoreCase", () => { + test("RegExp.ignoreCase", () => { + module Test = { + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set + } + () + }) +}) + +describe("RegExp.setLastIndex", () => { + test("RegExp.setLastIndex", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." + + regexp->RegExp.setLastIndex(4) + regexp->RegExp.exec(someStr)->ignore + + Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console + } + () + }) +}) + +describe("RegExp.lastIndex", () => { + test("RegExp.lastIndex", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." + + Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console + + regexp->RegExp.exec(someStr)->ignore + + Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console + } + () + }) +}) + +describe("RegExp.exec", () => { + test("RegExp.exec", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } + } + () + }) +}) + +describe("RegExp.test", () => { + test("RegExp.test", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + if regexp->RegExp.test("ReScript is cool!") { + Console.log("Yay, there's a word in there.") + } + } + () + }) +}) + +describe("RegExp.fromStringWithFlags", () => { + test("RegExp.fromStringWithFlags", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } + } + () + }) +}) + +describe("RegExp.fromString", () => { + test("RegExp.fromString", () => { + module Test = { + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } + } + () + }) +}) + +describe("Result.all", () => { + test("Result.all", () => { + module Test = { + Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) + Result.all([Ok(1), Error(1)]) // Error(1) + } + () + }) +}) + +describe("Result.mapError", () => { + test("Result.mapError", () => { + module Test = { + let format = n => `Error code: ${n->Int.toString}` + Result.mapError(Error(14), format) // Error("Error code: 14") + Result.mapError(Ok("abc"), format) // Ok("abc") + } + () + }) +}) + +describe("Result.forEach", () => { + test("Result.forEach", () => { + module Test = { + Result.forEach(Ok(3), Console.log) // Logs "3", returns () + Result.forEach(Error("x"), Console.log) // Does nothing, returns () + } + () + }) +}) + +describe("Result.compare", () => { + test("Result.compare", () => { + module Test = { + let good1 = Ok(59) + + let good2 = Ok(37) + + let bad1 = Error("invalid") + + let bad2 = Error("really invalid") + + let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) + + Result.compare(Ok(39), Ok(57), mod10cmp) == 1. + + Result.compare(Ok(57), Ok(39), mod10cmp) == -1. + + Result.compare(Ok(39), Error("y"), mod10cmp) == 1. + + Result.compare(Error("x"), Ok(57), mod10cmp) == -1. + + Result.compare(Error("x"), Error("y"), mod10cmp) == 0. + } + () + }) +}) + +describe("Result.equal", () => { + test("Result.equal", () => { + module Test = { + let good1 = Ok(42) + + let good2 = Ok(32) + + let bad1 = Error("invalid") + + let bad2 = Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) + + Result.equal(good1, good2, mod10equal) == true + + Result.equal(good1, bad1, mod10equal) == false + + Result.equal(bad2, good2, mod10equal) == false + + Result.equal(bad1, bad2, mod10equal) == true + } + () + }) +}) + +describe("Result.getOr", () => { + test("Result.getOr", () => { + module Test = { + Result.getOr(Ok(42), 0) == 42 + + Result.getOr(Error("Invalid Data"), 0) == 0 + } + () + }) +}) + +describe("Result.flatMap", () => { + test("Result.flatMap", () => { + module Test = { + let recip = x => + if x !== 0.0 { + Ok(1.0 /. x) + } else { + Error("Divide by zero") + } + + Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + } + () + }) +}) + +describe("Result.map", () => { + test("Result.map", () => { + module Test = { + let f = x => sqrt(Int.toFloat(x)) + + Result.map(Ok(64), f) == Ok(8.0) + + Result.map(Error("Invalid data"), f) == Error("Invalid data") + } + () + }) +}) + +describe("Result.mapOr", () => { + test("Result.mapOr", () => { + module Test = { + let ok = Ok(42) + Result.mapOr(ok, 0, x => x / 2) == 21 + + let error = Error("Invalid data") + Result.mapOr(error, 0, x => x / 2) == 0 + } + () + }) +}) + +describe("Promise.allSettled", () => { + test("Promise.allSettled", () => { + module Test = { + open Promise + + exception TestError(string) + + let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + + allSettled(promises) + ->then( + results => { + results->Array.forEach( + result => { + switch result { + | Fulfilled({value: num}) => Console.log2("Number: ", num) + | Rejected({reason}) => Console.log(reason) + } + }, + ) + + resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.all", () => { + test("Promise.all", () => { + module Test = { + open Promise + let promises = [resolve(1), resolve(2), resolve(3)] + + all(promises) + ->then( + results => { + results->Array.forEach( + num => { + Console.log2("Number: ", num) + }, + ) + + resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.any", () => { + test("Promise.any", () => { + module Test = { + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } + + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + + any(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) + } + () + }) +}) + +describe("Promise.race", () => { + test("Promise.race", () => { + module Test = { + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } + + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + + race(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) + } + () + }) +}) + +describe("Promise.finally", () => { + test("Promise.finally", () => { + module Test = { + open Promise + exception SomeError(string) + let isDone = ref(false) + + resolve(5) + ->then( + _ => { + reject(SomeError("test")) + }, + ) + ->then( + v => { + Console.log2("final result", v) + resolve() + }, + ) + ->catch( + _ => { + Console.log("Error handled") + resolve() + }, + ) + ->finally( + () => { + Console.log("finally") + isDone := true + }, + ) + ->then( + () => { + Console.log2("isDone:", isDone.contents) + resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.thenResolve", () => { + test("Promise.thenResolve", () => { + module Test = { + open Promise + resolve("Anna") + ->thenResolve( + str => { + "Hello " ++ str + }, + ) + ->thenResolve( + str => { + Console.log(str) + }, + ) + ->ignore // Ignore needed for side-effects + } + () + }) +}) + +describe("Promise.then", () => { + test("Promise.then", () => { + module Test = { + open Promise + resolve(5) + ->then( + num => { + resolve(num + 5) + }, + ) + ->then( + num => { + Console.log2("Your lucky number is: ", num) + resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.catch", () => { + test("Promise.catch", () => { + module Test = { + open Promise + + exception SomeError(string) + + reject(SomeError("this is an error")) + ->then( + _ => { + Ok("This result will never be returned")->resolve + }, + ) + ->catch( + e => { + let msg = switch e { + | SomeError(msg) => "ReScript error occurred: " ++ msg + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(msg) => "JS exception occurred: " ++ msg + | None => "Some other JS value has been thrown" + } + | _ => "Unexpected error occurred" + } + + Error(msg)->resolve + }, + ) + ->then( + result => { + switch result { + | Ok(r) => Console.log2("Operation successful: ", r) + | Error(msg) => Console.log2("Operation failed: ", msg) + }->resolve + }, + ) + ->ignore // Ignore needed for side-effects + } + () + }) +}) + +describe("Promise.make", () => { + test("Promise.make", () => { + module Test = { + open Promise + + let n = 4 + Promise.make( + (resolve, reject) => { + if n < 5 { + resolve("success") + } else { + reject("failed") + } + }, + ) + ->then( + str => { + Console.log(str)->resolve + }, + ) + ->catch( + _ => { + Console.log("Error occurred") + resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.reject", () => { + test("Promise.reject", () => { + module Test = { + exception TestError(string) + + TestError("some rejected value") + ->Promise.reject + ->Promise.catch( + v => { + switch v { + | TestError(msg) => assertEqual(msg, "some rejected value") + | _ => assert(false) + } + Promise.resolve() + }, + ) + ->ignore + } + () + }) +}) + +describe("Promise.resolve", () => { + test("Promise.resolve", () => { + module Test = { + let p = Promise.resolve(5) // promise + } + () + }) +}) + +describe("Set.toArray", () => { + test("Set.toArray", () => { + module Test = { + let set = Set.fromArray(["apple", "orange", "apple", "banana"]) + set->Set.toArray // ["apple", "orange", "banana"] + } + () + }) +}) + +describe("Set.values", () => { + test("Set.values", () => { + module Test = { + let set = Set.make() + set->Set.add("someValue") + set->Set.add("anotherValue") + + let values = set->Set.values + + // Logs the first value + Console.log(Iterator.next(values).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(set->Set.values->Iterator.toArray) + } + () + }) +}) + +describe("Set.forEach", () => { + test("Set.forEach", () => { + module Test = { + let set = Set.make() + set->Set.add("someValue") + set->Set.add("someValue2") + + set->Set.forEach( + value => { + Console.log(value) + }, + ) + } + () + }) +}) + +describe("Set.has", () => { + test("Set.has", () => { + module Test = { + let set = Set.make() + set->Set.add("someValue") + + switch set->Set.has("someValue") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") + } + } + () + }) +}) + +describe("Set.delete", () => { + test("Set.delete", () => { + module Test = { + let set = Set.make() + set->Set.add("someValue") + let didDeleteValue = set->Set.delete("someValue") + Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted + + let didDeleteValue = set->Set.delete("someNonExistantKey") + Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set + } + () + }) +}) + +describe("Set.add", () => { + test("Set.add", () => { + module Test = { + let set = Set.make() + set->Set.add("someValue") + } + () + }) +}) + +describe("Set.clear", () => { + test("Set.clear", () => { + module Test = { + let set = Set.make() + + set->Set.add("someKey") + set->Set.size // 1 + + set->Set.clear + set->Set.size // 0 + } + () + }) +}) + +describe("Set.size", () => { + test("Set.size", () => { + module Test = { + let set = Set.make() + + set->Set.add("someValue") + set->Set.add("someValue") + set->Set.add("someValue2") + + let size = set->Set.size // 2 + } + () + }) +}) + +describe("Set.fromIterator", () => { + test("Set.fromIterator", () => { + module Test = { + // Let's pretend we have an interator + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + + iterator + ->Set.fromIterator + ->Set.size + ->assertEqual(3) + } + () + }) +}) + +describe("Set.fromArray", () => { + test("Set.fromArray", () => { + module Test = { + type languages = ReScript | JavaScript | TypeScript + let languageRank = [ReScript, JavaScript, TypeScript] + + let set = Set.fromArray(languageRank) // Set.t + + switch set->Set.has(ReScript) { + | true => Console.log("Yay, ReScript is in there!") + | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } + } + () + }) +}) + +describe("Set.make", () => { + test("Set.make", () => { + module Test = { + // You can annotate the type of your set if you want to + let mySet: Set.t = Set.make() + + // Or you can let ReScript infer what's in your Set + let set = Set.make() + set->Set.add("Fine name") // Inferred as Set.t + } + () + }) +}) + +describe("String.localeCompare", () => { + test("String.localeCompare", () => { + module Test = { + String.localeCompare("a", "c") < 0.0 == true + String.localeCompare("a", "a") == 0.0 + } + () + }) +}) + +describe("String.padEnd", () => { + test("String.padEnd", () => { + module Test = { + String.padEnd("Hello", 10, ".") == "Hello....." + String.padEnd("abc", 1, "") == "abc" + } + () + }) +}) + +describe("String.padStart", () => { + test("String.padStart", () => { + module Test = { + String.padStart("abc", 5, " ") == " abc" + String.padStart("abc", 6, "123465") == "123abc" + } + () + }) +}) + +describe("String.trimEnd", () => { + test("String.trimEnd", () => { + module Test = { + String.trimEnd(" Hello world! ") == " Hello world!" + String.trimEnd(" Hello world! ") == " Hello world!" + } + () + }) +}) + +describe("String.trimStart", () => { + test("String.trimStart", () => { + module Test = { + String.trimStart(" Hello world! ") == "Hello world! " + String.trimStart(" Hello world! ") == "Hello world! " + } + () + }) +}) + +describe("String.trim", () => { + test("String.trim", () => { + module Test = { + String.trim(" abc def ") == "abc def" + String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" + } + () + }) +}) + +describe("String.toUpperCase", () => { + test("String.toUpperCase", () => { + module Test = { + String.toUpperCase("abc") == "ABC" + String.toUpperCase(`Straße`) == `STRASSE` + String.toUpperCase(`πς`) == `ΠΣ` + } + () + }) +}) + +describe("String.toLowerCase", () => { + test("String.toLowerCase", () => { + module Test = { + String.toLowerCase("ABC") == "abc" + String.toLowerCase(`ΣΠ`) == `σπ` + String.toLowerCase(`ΠΣ`) == `πς` + } + () + }) +}) + +describe("String.substringToEnd", () => { + test("String.substringToEnd", () => { + module Test = { + String.substringToEnd("playground", ~start=4) == "ground" + String.substringToEnd("playground", ~start=-3) == "playground" + String.substringToEnd("playground", ~start=12) == "" + } + () + }) +}) + +describe("String.substring", () => { + test("String.substring", () => { + module Test = { + String.substring("playground", ~start=3, ~end=6) == "ygr" + String.substring("playground", ~start=6, ~end=3) == "ygr" + String.substring("playground", ~start=4, ~end=12) == "ground" + } + () + }) +}) + +describe("String.startsWithFrom", () => { + test("String.startsWithFrom", () => { + module Test = { + String.startsWithFrom("BuckleScript", "kle", 3) == true + String.startsWithFrom("BuckleScript", "", 3) == true + String.startsWithFrom("JavaScript", "Buckle", 2) == false + } + () + }) +}) + +describe("String.startsWith", () => { + test("String.startsWith", () => { + module Test = { + String.startsWith("BuckleScript", "Buckle") == true + String.startsWith("BuckleScript", "") == true + String.startsWith("JavaScript", "Buckle") == false + } + () + }) +}) + +describe("String.splitByRegExpAtMost", () => { + test("String.splitByRegExpAtMost", () => { + module Test = { + String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ + Some("Hello"), + Some("World."), + Some("How"), + ] + } + () + }) +}) + +describe("String.splitByRegExp", () => { + test("String.splitByRegExp", () => { + module Test = { + String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] + } + () + }) +}) + +describe("String.splitAtMost", () => { + test("String.splitAtMost", () => { + module Test = { + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ + "ant", + "bee", + "cat", + "dog", + "elk", + ] + } + () + }) +}) + +describe("String.split", () => { + test("String.split", () => { + module Test = { + String.split("2018-01-02", "-") == ["2018", "01", "02"] + String.split("a,b,,c", ",") == ["a", "b", "", "c"] + String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] + String.split("has-no-delimiter", ";") == ["has-no-delimiter"] + } + () + }) +}) + +describe("String.sliceToEnd", () => { + test("String.sliceToEnd", () => { + module Test = { + String.sliceToEnd("abcdefg", ~start=4) == "efg" + String.sliceToEnd("abcdefg", ~start=-2) == "fg" + String.sliceToEnd("abcdefg", ~start=7) == "" + } + () + }) +}) + +describe("String.slice", () => { + test("String.slice", () => { + module Test = { + String.slice("abcdefg", ~start=2, ~end=5) == "cde" + String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" + String.slice("abcdefg", ~start=-4, ~end=-2) == "de" + String.slice("abcdefg", ~start=5, ~end=1) == "" + } + () + }) +}) + +describe("String.searchOpt", () => { + test("String.searchOpt", () => { + module Test = { + String.searchOpt("testing 1 2 3", /\d+/) == Some(8) + String.searchOpt("no numbers", /\d+/) == None + } + () + }) +}) + +describe("String.search", () => { + test("String.search", () => { + module Test = { + String.search("testing 1 2 3", /\d+/) == 8 + String.search("no numbers", /\d+/) == -1 + } + () + }) +}) + +describe("String.unsafeReplaceRegExpBy2", () => { + test("String.unsafeReplaceRegExpBy2", () => { + module Test = { + let str = "7 times 6" + let re = /(\d+) times (\d+)/ + let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } + } + String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" + } + () + }) +}) + +describe("String.unsafeReplaceRegExpBy1", () => { + test("String.unsafeReplaceRegExpBy1", () => { + module Test = { + let str = "Jony is 40" + let re = /(Jony is )\d+/g + let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { + group1 ++ "41" + } + String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" + } + () + }) +}) + +describe("String.unsafeReplaceRegExpBy0", () => { + test("String.unsafeReplaceRegExpBy0", () => { + module Test = { + let str = "beautiful vowels" + let re = /[aeiou]/g + let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) + String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" + } + () + }) +}) + +describe("String.replaceAllRegExp", () => { + test("String.replaceAllRegExp", () => { + module Test = { + String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" + } + () + }) +}) + +describe("String.replaceAll", () => { + test("String.replaceAll", () => { + module Test = { + String.replaceAll("old old string", "old", "new") == "new new string" + String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" + } + () + }) +}) + +describe("String.replaceRegExp", () => { + test("String.replaceRegExp", () => { + module Test = { + String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" + } + () + }) +}) + +describe("String.replace", () => { + test("String.replace", () => { + module Test = { + String.replace("old string", "old", "new") == "new string" + String.replace("the cat and the dog", "the", "this") == "this cat and the dog" + } + () + }) +}) + +describe("String.repeat", () => { + test("String.repeat", () => { + module Test = { + String.repeat("ha", 3) == "hahaha" + String.repeat("empty", 0) == "" + } + () + }) +}) + +describe("String.normalizeForm", () => { + test("String.normalizeForm", () => { + module Test = { + let string1 = "\uFB00" + let string2 = "\u0066\u0066" + Console.log(string1 == string2) // false + + let normalizeString1 = String.normalizeByForm(string1, #NFKD) + let normalizeString2 = String.normalizeByForm(string2, #NFKD) + Console.log(normalizeString1 == normalizeString2) // true + } + () + }) +}) + +describe("String.normalize", () => { + test("String.normalize", () => { + module Test = { + let string1 = "\u00F1" + let string2 = "\u006E\u0303" + + assert(string1 != string2) // true + assertEqual(String.normalize(string1), String.normalize(string2)) + } + () + }) +}) + +describe("String.match", () => { + test("String.match", () => { + module Test = { + String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) + String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) + String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) + String.match("The optional example", /(foo)?(example)/) == + Some([Some("example"), None, Some("example")]) + String.match("The large container.", /b[aeiou]g/) == None + } + () + }) +}) + +describe("String.lastIndexOfFrom", () => { + test("String.lastIndexOfFrom", () => { + module Test = { + String.lastIndexOfFrom("bookseller", "ok", 6) == 2 + String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 + String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 + String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 + } + () + }) +}) + +describe("String.lastIndexOfOpt", () => { + test("String.lastIndexOfOpt", () => { + module Test = { + String.lastIndexOfOpt("bookseller", "ok") == Some(2) + String.lastIndexOfOpt("beekeeper", "ee") == Some(4) + String.lastIndexOfOpt("abcdefg", "xyz") == None + } + () + }) +}) + +describe("String.lastIndexOf", () => { + test("String.lastIndexOf", () => { + module Test = { + String.lastIndexOf("bookseller", "ok") == 2 + String.lastIndexOf("beekeeper", "ee") == 4 + String.lastIndexOf("abcdefg", "xyz") == -1 + } + () + }) +}) + +describe("String.indexOfFrom", () => { + test("String.indexOfFrom", () => { + module Test = { + String.indexOfFrom("bookseller", "ok", 1) == 2 + String.indexOfFrom("bookseller", "sell", 2) == 4 + String.indexOfFrom("bookseller", "sell", 5) == -1 + } + () + }) +}) + +describe("String.indexOfOpt", () => { + test("String.indexOfOpt", () => { + module Test = { + String.indexOfOpt("bookseller", "ok") == Some(2) + String.indexOfOpt("bookseller", "xyz") == None + } + () + }) +}) + +describe("String.indexOf", () => { + test("String.indexOf", () => { + module Test = { + String.indexOf("bookseller", "ok") == 2 + String.indexOf("bookseller", "sell") == 4 + String.indexOf("beekeeper", "ee") == 1 + String.indexOf("bookseller", "xyz") == -1 + } + () + }) +}) + +describe("String.includesFrom", () => { + test("String.includesFrom", () => { + module Test = { + String.includesFrom("programmer", "gram", 1) == true + String.includesFrom("programmer", "gram", 4) == false + String.includesFrom(`대한민국`, `한`, 1) == true + } + () + }) +}) + +describe("String.includes", () => { + test("String.includes", () => { + module Test = { + String.includes("programmer", "gram") == true + String.includes("programmer", "er") == true + String.includes("programmer", "pro") == true + String.includes("programmer.dat", "xyz") == false + } + () + }) +}) + +describe("String.endsWithFrom", () => { + test("String.endsWithFrom", () => { + module Test = { + String.endsWithFrom("abcd", "cd", 4) == true + String.endsWithFrom("abcde", "cd", 3) == false + String.endsWithFrom("abcde", "cde", 99) == true + String.endsWithFrom("example.dat", "ple", 7) == true + } + () + }) +}) + +describe("String.endsWith", () => { + test("String.endsWith", () => { + module Test = { + String.endsWith("BuckleScript", "Script") == true + String.endsWith("BuckleShoes", "Script") == false + } + () + }) +}) + +describe("String.concatMany", () => { + test("String.concatMany", () => { + module Test = { + String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" + } + () + }) +}) + +describe("String.concat", () => { + test("String.concat", () => { + module Test = { + String.concat("cow", "bell") == "cowbell" + String.concat("Re", "Script") == "ReScript" + } + () + }) +}) + +describe("String.codePointAt", () => { + test("String.codePointAt", () => { + module Test = { + String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) + String.codePointAt("abc", 5) == None + } + () + }) +}) + +describe("String.charCodeAt", () => { + test("String.charCodeAt", () => { + module Test = { + String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat + String.codePointAt(`😺`, 0) == Some(0x1f63a) + } + () + }) +}) + +describe("String.charAt", () => { + test("String.charAt", () => { + module Test = { + String.charAt("ReScript", 0) == "R" + String.charAt("Hello", 12) == "" + String.charAt(`JS`, 5) == "" + } + () + }) +}) + +describe("String.getUnsafe", () => { + test("String.getUnsafe", () => { + module Test = { + String.getUnsafe("ReScript", 0) == "R" + String.getUnsafe("Hello", 4) == "o" + } + () + }) +}) + +describe("String.get", () => { + test("String.get", () => { + module Test = { + String.get("ReScript", 0) == Some("R") + String.get("Hello", 4) == Some("o") + String.get(`JS`, 4) == None + } + () + }) +}) + +describe("String.length", () => { + test("String.length", () => { + module Test = { + String.length("abcd") == 4 + } + () + }) +}) + +describe("String.fromCodePointMany", () => { + test("String.fromCodePointMany", () => { + module Test = { + String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` + } + () + }) +}) + +describe("String.fromCodePoint", () => { + test("String.fromCodePoint", () => { + module Test = { + String.fromCodePoint(65) == "A" + String.fromCodePoint(0x3c8) == `ψ` + String.fromCodePoint(0xd55c) == `한` + String.fromCodePoint(0x1f63a) == `😺` + } + () + }) +}) + +describe("String.fromCharCodeMany", () => { + test("String.fromCharCodeMany", () => { + module Test = { + String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" + String.fromCharCodeMany([65, 66, 67]) == "ABC" + } + () + }) +}) + +describe("String.fromCharCode", () => { + test("String.fromCharCode", () => { + module Test = { + String.fromCharCode(65) == "A" + String.fromCharCode(0x3c8) == `ψ` + String.fromCharCode(0xd55c) == `한` + String.fromCharCode(-64568) == `ψ` + } + () + }) +}) + +describe("String.make", () => { + test("String.make", () => { + module Test = { + String.make(3.5) == "3.5" + String.make([1, 2, 3]) == "1,2,3" + } + () + }) +}) + +describe("Type.Classify.classify", () => { + test("Type.Classify.classify", () => { + module Test = { + switch %raw(`null`)->Type.Classify.classify { + | Null => Console.log("Yup, that's null.") + | _ => Console.log("This doesn't actually appear to be null...") + } + } + () + }) +}) + +describe("Type.typeof", () => { + test("Type.typeof", () => { + module Test = { + Console.log(Type.typeof("Hello")) // Logs "string" to the console. + + let someVariable = true + + switch someVariable->Type.typeof { + | #boolean => Console.log("This is a bool, yay!") + | _ => Console.log("Oh, not a bool sadly...") + } + } + () + }) +}) diff --git a/tests/docstrings_examples/mocha_full_test.res.mjs b/tests/docstrings_examples/mocha_full_test.res.mjs new file mode 100644 index 0000000000..20344005cf --- /dev/null +++ b/tests/docstrings_examples/mocha_full_test.res.mjs @@ -0,0 +1,22839 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + +import * as Exn from "rescript/lib/es6/Exn.js"; +import * as Int from "rescript/lib/es6/Int.js"; +import * as Dict from "rescript/lib/es6/Dict.js"; +import * as $$JSON from "rescript/lib/es6/JSON.js"; +import * as List from "rescript/lib/es6/List.js"; +import * as $$Math from "rescript/lib/es6/Math.js"; +import * as Null from "rescript/lib/es6/Null.js"; +import * as Type from "rescript/lib/es6/Type.js"; +import * as $$Array from "rescript/lib/es6/Array.js"; +import * as $$Error from "rescript/lib/es6/Error.js"; +import * as Float from "rescript/lib/es6/Float.js"; +import * as Mocha from "mocha"; +import * as Option from "rescript/lib/es6/Option.js"; +import * as Result from "rescript/lib/es6/Result.js"; +import * as $$String from "rescript/lib/es6/String.js"; +import * as Belt_Id from "rescript/lib/es6/Belt_Id.js"; +import * as $$Promise from "rescript/lib/es6/Promise.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 $$Iterator from "rescript/lib/es6/Iterator.js"; +import * as Nullable from "rescript/lib/es6/Nullable.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 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 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 $$AsyncIterator from "rescript/lib/es6/AsyncIterator.js"; +import * as Primitive_int from "rescript/lib/es6/Primitive_int.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 Belt_MutableSet from "rescript/lib/es6/Belt_MutableSet.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"; + +Mocha.describe("AsyncIterator.forEach", () => { + Mocha.test("AsyncIterator.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 $$AsyncIterator.forEach(asyncIterator, v => { + if (v !== undefined && v[0] === "second") { + return Pervasives.assertEqual(v[1], "2"); + } + + }); + main(); + }); +}); + +Mocha.describe("AsyncIterator.next", () => { + Mocha.test("AsyncIterator.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) { + Pervasives.assertEqual(Option.isNone(match.value), true); + } + + }; + }; + processMyAsyncIterator(); + }); +}); + +Mocha.describe("AsyncIterator.done", () => { + Mocha.test("AsyncIterator.done", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } + }); + }); +}); + +Mocha.describe("AsyncIterator.value", () => { + Mocha.test("AsyncIterator.value", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } + }); + }); +}); + +Mocha.describe("AsyncIterator.make", () => { + Mocha.test("AsyncIterator.make", () => { + let context = { + contents: 0 + }; + let asyncIterator = $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + return { + done: currentValue >= 3, + value: currentValue + }; + }); + let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { + if (value !== undefined) { + console.log(value); + return; + } + + }); + main(); + }); +}); + +Mocha.describe("Array.last", () => { + Mocha.test("Array.last", () => { + Pervasives.assertEqual($$Array.last([ + "Hello", + "Hi", + "Good bye" + ]), "Good bye"); + Pervasives.assertEqual($$Array.last([]), undefined); + }); +}); + +Mocha.describe("Array.at", () => { + Mocha.test("Array.at", () => { + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(0), "a"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(2), "c"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(3), undefined); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-1), "c"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-3), "a"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-4), undefined); + }); +}); + +Mocha.describe("Array.findMap", () => { + Mocha.test("Array.findMap", () => { + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3 + ], n => { + if (n % 2 === 0) { + return n - 2 | 0; + } + + }), 0); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return n - 8 | 0; + } + + }), -6); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), undefined); + Pervasives.assertEqual($$Array.findMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + }), undefined); + }); +}); + +Mocha.describe("Array.flatMapWithIndex", () => { + Mocha.test("Array.flatMapWithIndex", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.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.describe("Array.flatMap", () => { + Mocha.test("Array.flatMap", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.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.describe("Array.shuffle", () => { + Mocha.test("Array.shuffle", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + $$Array.shuffle(array); + console.log(array); + let array2 = [ + 1, + 2, + 3 + ]; + $$Array.shuffle(array2); + Pervasives.assertEqual(array2.length, 3); + }); +}); + +Mocha.describe("Array.toShuffled", () => { + Mocha.test("Array.toShuffled", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let shuffledArray = $$Array.toShuffled(array); + console.log(shuffledArray); + Pervasives.assertEqual($$Array.toShuffled([ + 1, + 2, + 3 + ]).length, 3); + }); +}); + +Mocha.describe("Array.keepSome", () => { + Mocha.test("Array.keepSome", () => { + Pervasives.assertEqual($$Array.keepSome([ + 1, + undefined, + 3 + ]), [ + 1, + 3 + ]); + Pervasives.assertEqual($$Array.keepSome([ + 1, + 2, + 3 + ]), [ + 1, + 2, + 3 + ]); + Pervasives.assertEqual($$Array.keepSome([ + undefined, + undefined, + undefined + ]), []); + Pervasives.assertEqual($$Array.keepSome([]), []); + }); +}); + +Mocha.describe("Array.filterMap", () => { + Mocha.test("Array.filterMap", () => { + Pervasives.assertEqual($$Array.filterMap([ + "Hello", + "Hi", + "Good bye" + ], item => { + if (item === "Hello") { + return item.length; + } + + }), [5]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + }), [ + 4, + 16, + 36 + ]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), []); + Pervasives.assertEqual($$Array.filterMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + }), []); + }); +}); + +Mocha.describe("Array.findIndexOpt", () => { + Mocha.test("Array.findIndexOpt", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); + }); +}); + +Mocha.describe("Array.setUnsafe", () => { + Mocha.test("Array.setUnsafe", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); + }); +}); + +Mocha.describe("Array.unsafe_get", () => { + Mocha.test("Array.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.describe("Array.getUnsafe", () => { + Mocha.test("Array.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.describe("Array.set", () => { + Mocha.test("Array.set", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); + }); +}); + +Mocha.describe("Array.get", () => { + Mocha.test("Array.get", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array[0], "Hello"); + Pervasives.assertEqual(array[3], undefined); + }); +}); + +Mocha.describe("Array.someWithIndex", () => { + Mocha.test("Array.someWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some((greeting, index) => { + if (greeting === "Hello") { + return index === 0; + } else { + return false; + } + }), true); + }); +}); + +Mocha.describe("Array.some", () => { + Mocha.test("Array.some", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); + }); +}); + +Mocha.describe("Array.reduceRightWithIndex", () => { + Mocha.test("Array.reduceRightWithIndex", () => { + Pervasives.assertEqual($$Array.reduceRightWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); + }); +}); + +Mocha.describe("Array.reduceRight", () => { + Mocha.test("Array.reduceRight", () => { + Pervasives.assertEqual($$Array.reduceRight([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "dcba"); + Pervasives.assertEqual($$Array.reduceRight([ + 1, + 2, + 3 + ], /* [] */0, List.add), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); + }); +}); + +Mocha.describe("Array.reduceWithIndex", () => { + Mocha.test("Array.reduceWithIndex", () => { + Pervasives.assertEqual($$Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$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 + } + } + }); + Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); + }); +}); + +Mocha.describe("Array.reduce", () => { + Mocha.test("Array.reduce", () => { + Pervasives.assertEqual($$Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0), 10); + Pervasives.assertEqual($$Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "abcd"); + Pervasives.assertEqual($$Array.reduce([ + 1, + 2, + 3 + ], /* [] */0, List.add), { + hd: 3, + tl: { + hd: 2, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); + }); +}); + +Mocha.describe("Array.mapWithIndex", () => { + Mocha.test("Array.mapWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); + Pervasives.assertEqual(mappedArray, [ + "Hello at position 0", + "Hi at position 1", + "Good bye at position 2" + ]); + }); +}); + +Mocha.describe("Array.map", () => { + Mocha.test("Array.map", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map(greeting => greeting + " to you"); + Pervasives.assertEqual(mappedArray, [ + "Hello to you", + "Hi to you", + "Good bye to you" + ]); + }); +}); + +Mocha.describe("Array.forEachWithIndex", () => { + Mocha.test("Array.forEachWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach((item, index) => { + console.log("At item " + index.toString() + ": " + item); + }); + }); +}); + +Mocha.describe("Array.forEach", () => { + Mocha.test("Array.forEach", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach(item => { + console.log(item); + }); + }); +}); + +Mocha.describe("Array.findIndexWithIndex", () => { + Mocha.test("Array.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; + } + }); + Pervasives.assertEqual(isReScriptFirst, 0); + Pervasives.assertEqual(isTypeScriptFirst, -1); + }); +}); + +Mocha.describe("Array.findIndex", () => { + Mocha.test("Array.findIndex", () => { + let array = [ + "ReScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); + Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); + }); +}); + +Mocha.describe("Array.findWithIndex", () => { + Mocha.test("Array.findWithIndex", () => { + let array = [ + "TypeScript", + "JavaScript", + "ReScript" + ]; + Pervasives.assertEqual(array.find((item, index) => { + if (index > 1) { + return item === "ReScript"; + } else { + return false; + } + }), "ReScript"); + }); +}); + +Mocha.describe("Array.find", () => { + Mocha.test("Array.find", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); + }); +}); + +Mocha.describe("Array.filterWithIndex", () => { + Mocha.test("Array.filterWithIndex", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].filter((num, index) => { + if (index === 0) { + return true; + } else { + return num === 2; + } + }), [ + 1, + 2 + ]); + }); +}); + +Mocha.describe("Array.filter", () => { + Mocha.test("Array.filter", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].filter(num => num > 2), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Array.everyWithIndex", () => { + Mocha.test("Array.everyWithIndex", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every((num, index) => { + if (index < 5) { + return num <= 4; + } else { + return false; + } + }), true); + Pervasives.assertEqual(array.every((num, index) => { + if (index < 2) { + return num >= 2; + } else { + return false; + } + }), false); + }); +}); + +Mocha.describe("Array.every", () => { + Mocha.test("Array.every", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every(num => num <= 4), true); + Pervasives.assertEqual(array.every(num => num === 1), false); + }); +}); + +Mocha.describe("Array.toString", () => { + Mocha.test("Array.toString", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].toString(), "1,2,3,4"); + }); +}); + +Mocha.describe("Array.copy", () => { + Mocha.test("Array.copy", () => { + let myArray = [ + 1, + 2, + 3 + ]; + let copyOfMyArray = myArray.slice(); + Pervasives.assertEqual(copyOfMyArray, [ + 1, + 2, + 3 + ]); + Pervasives.assertEqual(myArray === copyOfMyArray, false); + }); +}); + +Mocha.describe("Array.sliceToEnd", () => { + Mocha.test("Array.sliceToEnd", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1), [ + 2, + 3, + 4 + ]); + }); +}); + +Mocha.describe("Array.slice", () => { + Mocha.test("Array.slice", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1, 3), [ + 2, + 3 + ]); + }); +}); + +Mocha.describe("Array.joinWithUnsafe", () => { + Mocha.test("Array.joinWithUnsafe", () => { + Pervasives.assertEqual([ + 1, + 2, + 3 + ].join(" -- "), "1 -- 2 -- 3"); + }); +}); + +Mocha.describe("Array.joinUnsafe", () => { + Mocha.test("Array.joinUnsafe", () => { + Pervasives.assertEqual([ + 1, + 2, + 3 + ].join(" -- "), "1 -- 2 -- 3"); + }); +}); + +Mocha.describe("Array.joinWith", () => { + Mocha.test("Array.joinWith", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); +}); + +Mocha.describe("Array.join", () => { + Mocha.test("Array.join", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); +}); + +Mocha.describe("Array.indexOfOpt", () => { + Mocha.test("Array.indexOfOpt", () => { + Pervasives.assertEqual($$Array.indexOfOpt([ + 1, + 2 + ], 2), 1); + Pervasives.assertEqual($$Array.indexOfOpt([ + 1, + 2 + ], 3), undefined); + Pervasives.assertEqual($$Array.indexOfOpt([{ + language: "ReScript" + }], { + language: "ReScript" + }), undefined); + }); +}); + +Mocha.describe("Array.indexOf", () => { + Mocha.test("Array.indexOf", () => { + Pervasives.assertEqual([ + 1, + 2 + ].indexOf(2), 1); + Pervasives.assertEqual([ + 1, + 2 + ].indexOf(3), -1); + Pervasives.assertEqual([{ + language: "ReScript" + }].indexOf({ + language: "ReScript" + }), -1); + }); +}); + +Mocha.describe("Array.includes", () => { + Mocha.test("Array.includes", () => { + Pervasives.assertEqual([ + 1, + 2 + ].includes(1), true); + Pervasives.assertEqual([ + 1, + 2 + ].includes(3), false); + Pervasives.assertEqual([{ + language: "ReScript" + }].includes({ + language: "ReScript" + }), false); + }); +}); + +Mocha.describe("Array.flat", () => { + Mocha.test("Array.flat", () => { + Pervasives.assertEqual([ + [1], + [2], + [ + 3, + 4 + ] + ].flat(), [ + 1, + 2, + 3, + 4 + ]); + }); +}); + +Mocha.describe("Array.concatMany", () => { + Mocha.test("Array.concatMany", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = ["yay"]; + let array3 = ["wehoo"]; + let someArray = array1.concat(array2, array3); + console.log(someArray); + }); +}); + +Mocha.describe("Array.concat", () => { + Mocha.test("Array.concat", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = [ + "yay", + "wehoo" + ]; + let someArray = array1.concat(array2); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); + }); +}); + +Mocha.describe("Array.unshiftMany", () => { + Mocha.test("Array.unshiftMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "yay", + "wehoo", + "hi", + "hello" + ]); + }); +}); + +Mocha.describe("Array.unshift", () => { + Mocha.test("Array.unshift", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay"); + Pervasives.assertEqual(someArray, [ + "yay", + "hi", + "hello" + ]); + }); +}); + +Mocha.describe("Array.sort", () => { + Mocha.test("Array.sort", () => { + let array = [ + 3, + 2, + 1 + ]; + array.sort((a, b) => a - b | 0); + Pervasives.assertEqual(array, [ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("Array.shift", () => { + Mocha.test("Array.shift", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.shift(), "hi"); + Pervasives.assertEqual(someArray, ["hello"]); + }); +}); + +Mocha.describe("Array.reverse", () => { + Mocha.test("Array.reverse", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.reverse(); + Pervasives.assertEqual(someArray, [ + "hello", + "hi" + ]); + }); +}); + +Mocha.describe("Array.pushMany", () => { + Mocha.test("Array.pushMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); + }); +}); + +Mocha.describe("Array.push", () => { + Mocha.test("Array.push", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay" + ]); + }); +}); + +Mocha.describe("Array.pop", () => { + Mocha.test("Array.pop", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.pop(), "hello"); + Pervasives.assertEqual(someArray, ["hi"]); + }); +}); + +Mocha.describe("Array.fill", () => { + Mocha.test("Array.fill", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1, 3); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 4 + ]); + }); +}); + +Mocha.describe("Array.fillToEnd", () => { + Mocha.test("Array.fillToEnd", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 9 + ]); + }); +}); + +Mocha.describe("Array.fillAll", () => { + Mocha.test("Array.fillAll", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9); + Pervasives.assertEqual(myArray, [ + 9, + 9, + 9, + 9 + ]); + }); +}); + +Mocha.describe("Array.length", () => { + Mocha.test("Array.length", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.length, 2); + }); +}); + +Mocha.describe("Array.fromInitializer", () => { + Mocha.test("Array.fromInitializer", () => { + Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ + 3, + 4, + 5 + ]); + Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); + }); +}); + +Mocha.describe("Array.make", () => { + Mocha.test("Array.make", () => { + Pervasives.assertEqual($$Array.make(3, "apple"), [ + "apple", + "apple", + "apple" + ]); + Pervasives.assertEqual($$Array.make(6, 7), [ + 7, + 7, + 7, + 7, + 7, + 7 + ]); + }); +}); + +Mocha.describe("Array.fromIterator", () => { + Mocha.test("Array.fromIterator", () => { + Pervasives.assertEqual(Array.from(new Map([ + [ + "foo", + 1 + ], + [ + "bar", + 2 + ] + ]).values()), [ + 1, + 2 + ]); + }); +}); + +Mocha.describe("Belt_Float./", () => { + Mocha.test("Belt_Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); + }); +}); + +Mocha.describe("Belt_Float.*", () => { + Mocha.test("Belt_Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); + }); +}); + +Mocha.describe("Belt_Float.-", () => { + Mocha.test("Belt_Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); + }); +}); + +Mocha.describe("Belt_Float.+", () => { + Mocha.test("Belt_Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); + }); +}); + +Mocha.describe("Belt_Float.toString", () => { + Mocha.test("Belt_Float.toString", () => { + console.log(String(1.0) === "1.0"); + }); +}); + +Mocha.describe("Belt_Float.fromString", () => { + Mocha.test("Belt_Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); + }); +}); + +Mocha.describe("Belt_Float.fromInt", () => { + Mocha.test("Belt_Float.fromInt", () => { + console.log(1 === 1.0); + }); +}); + +Mocha.describe("Belt_Float.toInt", () => { + Mocha.test("Belt_Float.toInt", () => { + console.log(true); + }); +}); + +Mocha.describe("Belt_Array.truncateToLengthUnsafe", () => { + Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt_Array.eq", () => { + Mocha.test("Belt_Array.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_Array.cmp", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.some2", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.every2", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.every", () => { + Mocha.test("Belt_Array.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_Array.some", () => { + Mocha.test("Belt_Array.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_Array.joinWith", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.reduceWithIndex", () => { + Mocha.test("Belt_Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_Array.reduceReverse2", () => { + Mocha.test("Belt_Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_Array.reduceReverse", () => { + Mocha.test("Belt_Array.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt_Array.reduce", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.partition", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.mapWithIndex", () => { + Mocha.test("Belt_Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_Array.forEachWithIndex", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.keepMap", () => { + Mocha.test("Belt_Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_Array.keepWithIndex", () => { + Mocha.test("Belt_Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_Array.getIndexBy", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.getBy", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.flatMap", () => { + Mocha.test("Belt_Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt_Array.map", () => { + Mocha.test("Belt_Array.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_Array.forEach", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.blit", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.fill", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.sliceToEnd", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.slice", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.concatMany", () => { + Mocha.test("Belt_Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt_Array.concat", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.unzip", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.zipBy", () => { + Mocha.test("Belt_Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_Array.zip", () => { + Mocha.test("Belt_Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_Array.makeBy", () => { + Mocha.test("Belt_Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_Array.rangeBy", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.range", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.makeUninitialized", () => { + Mocha.test("Belt_Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_Array.reverse", () => { + Mocha.test("Belt_Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_Array.reverseInPlace", () => { + Mocha.test("Belt_Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_Array.get", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.length", () => { + Mocha.test("Belt_Array.length", () => {}); +}); + +Mocha.describe("Belt_HashMap.logStats", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.getBucketHistogram", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.mergeMany", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.fromArray", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.valuesToArray", () => { + Mocha.test("Belt_HashMap.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_HashMap.keysToArray", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.toArray", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.size", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.keepMapInPlace", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.reduce", () => { + Mocha.test("Belt_HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); + }); +}); + +Mocha.describe("Belt_HashMap.forEach", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.remove", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.has", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.get", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.copy", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.set", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.isEmpty", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.clear", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.make", () => { + Mocha.test("Belt_HashMap.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.describe("Belt.Map.Dict.findFirstBy", () => { + Mocha.test("Belt.Map.Dict.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.String.findFirstBy", () => { + Mocha.test("Belt.Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt.Map.Int.findFirstBy", () => { + Mocha.test("Belt.Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt.Set.Dict.split", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.get", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.maxUndefined", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.maximum", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.minUndefined", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.minimum", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.toArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.toList", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.size", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.partition", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.keep", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.some", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.every", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.reduce", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.forEach", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.eq", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.subset", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.diff", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.intersect", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.union", () => { + Mocha.test("Belt.Set.Dict.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.Set.Dict.removeMany", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.remove", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.mergeMany", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.add", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.has", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.isEmpty", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.fromArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.empty", () => { + Mocha.test("Belt.Set.Dict.empty", () => {}); +}); + +Mocha.describe("Belt.Float./", () => { + Mocha.test("Belt.Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); + }); +}); + +Mocha.describe("Belt.Float.*", () => { + Mocha.test("Belt.Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); + }); +}); + +Mocha.describe("Belt.Float.-", () => { + Mocha.test("Belt.Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); + }); +}); + +Mocha.describe("Belt.Float.+", () => { + Mocha.test("Belt.Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); + }); +}); + +Mocha.describe("Belt.Float.toString", () => { + Mocha.test("Belt.Float.toString", () => { + console.log(String(1.0) === "1.0"); + }); +}); + +Mocha.describe("Belt.Float.fromString", () => { + Mocha.test("Belt.Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); + }); +}); + +Mocha.describe("Belt.Float.fromInt", () => { + Mocha.test("Belt.Float.fromInt", () => { + console.log(1 === 1.0); + }); +}); + +Mocha.describe("Belt.Float.toInt", () => { + Mocha.test("Belt.Float.toInt", () => { + console.log(true); + }); +}); + +Mocha.describe("Belt.Int./", () => { + Mocha.test("Belt.Int./", () => { + Pervasives.assertEqual(2, 2); + }); +}); + +Mocha.describe("Belt.Int.*", () => { + Mocha.test("Belt.Int.*", () => { + Pervasives.assertEqual(4, 4); + }); +}); + +Mocha.describe("Belt.Int.-", () => { + Mocha.test("Belt.Int.-", () => { + Pervasives.assertEqual(1, 1); + }); +}); + +Mocha.describe("Belt.Int.+", () => { + Mocha.test("Belt.Int.+", () => { + Pervasives.assertEqual(4, 4); + }); +}); + +Mocha.describe("Belt.Int.toString", () => { + Mocha.test("Belt.Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt.Int.fromString", () => { + Mocha.test("Belt.Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); + }); +}); + +Mocha.describe("Belt.Int.fromFloat", () => { + Mocha.test("Belt.Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); + }); +}); + +Mocha.describe("Belt.Int.toFloat", () => { + Mocha.test("Belt.Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); + }); +}); + +Mocha.describe("Belt.Result.cmp", () => { + Mocha.test("Belt.Result.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.describe("Belt.Result.eq", () => { + Mocha.test("Belt.Result.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.describe("Belt.Result.getWithDefault", () => { + Mocha.test("Belt.Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); +}); + +Mocha.describe("Belt.Result.flatMap", () => { + Mocha.test("Belt.Result.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.describe("Belt.Result.map", () => { + Mocha.test("Belt.Result.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.describe("Belt.Result.mapWithDefault", () => { + Mocha.test("Belt.Result.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.Result.getExn", () => { + Mocha.test("Belt.Result.getExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 2737, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.Option.cmp", () => { + Mocha.test("Belt.Option.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.describe("Belt.Option.eq", () => { + Mocha.test("Belt.Option.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.describe("Belt.Option.isNone", () => { + Mocha.test("Belt.Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); + }); +}); + +Mocha.describe("Belt.Option.isSome", () => { + Mocha.test("Belt.Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); + }); +}); + +Mocha.describe("Belt.Option.orElse", () => { + Mocha.test("Belt.Option.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.Option.getWithDefault", () => { + Mocha.test("Belt.Option.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.describe("Belt.Option.flatMap", () => { + Mocha.test("Belt.Option.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.describe("Belt.Option.map", () => { + Mocha.test("Belt.Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Belt.Option.mapWithDefault", () => { + Mocha.test("Belt.Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("Belt.Option.getExn", () => { + Mocha.test("Belt.Option.getExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 2891, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.Option.forEach", () => { + Mocha.test("Belt.Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Belt.Option.keep", () => { + Mocha.test("Belt.Option.keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); + }); +}); + +Mocha.describe("Belt.HashMap.logStats", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.getBucketHistogram", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.mergeMany", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.fromArray", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.valuesToArray", () => { + Mocha.test("Belt.HashMap.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.HashMap.keysToArray", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.toArray", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.size", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.keepMapInPlace", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.reduce", () => { + Mocha.test("Belt.HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); + }); +}); + +Mocha.describe("Belt.HashMap.forEach", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.remove", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.has", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.get", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.copy", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.set", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.isEmpty", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.clear", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.make", () => { + Mocha.test("Belt.HashMap.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.describe("Belt.MutableSet.split", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.get", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.maxUndefined", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.maximum", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.minUndefined", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.minimum", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.toArray", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.toList", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.size", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.partition", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.keep", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.some", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.every", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.reduce", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.forEach", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.eq", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.subset", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.diff", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.intersect", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.union", () => { + Mocha.test("Belt.MutableSet.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.MutableSet.removeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.remove", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.mergeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.add", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.has", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.isEmpty", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.copy", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.fromArray", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.Map.set", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.remove", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.get", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.valuesToArray", () => { + Mocha.test("Belt.Map.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.keysToArray", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.fromArray", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.toArray", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.size", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.reduce", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.forEach", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.findFirstBy", () => { + Mocha.test("Belt.Map.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); + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt.Map.has", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.isEmpty", () => { + Mocha.test("Belt.Map.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; + }); +}); + +Mocha.describe("Belt.Map.make", () => { + Mocha.test("Belt.Map.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.describe("Belt.Map.Int", () => { + Mocha.test("Belt.Map.Int", () => {}); +}); + +Mocha.describe("Belt.Set.split", () => { + Mocha.test("Belt.Set.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]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); + }); +}); + +Mocha.describe("Belt.Set.get", () => { + Mocha.test("Belt.Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); + }); +}); + +Mocha.describe("Belt.Set.maxUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + }); +}); + +Mocha.describe("Belt.Set.maximum", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + }); +}); + +Mocha.describe("Belt.Set.minUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + }); +}); + +Mocha.describe("Belt.Set.minimum", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); + }); +}); + +Mocha.describe("Belt.Set.toList", () => { + Mocha.test("Belt.Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt.Set.toArray", () => { + Mocha.test("Belt.Set.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt.Set.size", () => { + Mocha.test("Belt.Set.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.size(s0), 4); + }); +}); + +Mocha.describe("Belt.Set.partition", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ + 1, + 3, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Set.keep", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Set.some", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); + }); +}); + +Mocha.describe("Belt.Set.every", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + }); +}); + +Mocha.describe("Belt.Set.reduce", () => { + Mocha.test("Belt.Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt.Set.forEach", () => { + Mocha.test("Belt.Set.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); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt.Set.eq", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); + }); +}); + +Mocha.describe("Belt.Set.subset", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); + }); +}); + +Mocha.describe("Belt.Set.diff", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Set.intersect", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt.Set.union", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); + }); +}); + +Mocha.describe("Belt.Set.removeMany", () => { + Mocha.test("Belt.Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); + }); +}); + +Mocha.describe("Belt.Set.remove", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); + }); +}); + +Mocha.describe("Belt.Set.mergeMany", () => { + Mocha.test("Belt.Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + 1, + 2, + 3, + 4, + 5 + ]); + }); +}); + +Mocha.describe("Belt.Set.add", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Pervasives.assertEqual(s2, s3); + }); +}); + +Mocha.describe("Belt.Set.has", () => { + Mocha.test("Belt.Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); + }); +}); + +Mocha.describe("Belt.Set.isEmpty", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); +}); + +Mocha.describe("Belt.Set.fromArray", () => { + Mocha.test("Belt.Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Set.make", () => { + Mocha.test("Belt.Set.make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); + }); +}); + +Mocha.describe("Belt.Range.someBy", () => { + Mocha.test("Belt.Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt.Range.some", () => { + Mocha.test("Belt.Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); +}); + +Mocha.describe("Belt.Range.everyBy", () => { + Mocha.test("Belt.Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt.Range.every", () => { + Mocha.test("Belt.Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); +}); + +Mocha.describe("Belt.Range.forEach", () => { + Mocha.test("Belt.Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); +}); + +Mocha.describe("Belt.List.sort", () => { + Mocha.test("Belt.List.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.describe("Belt.List.setAssoc", () => { + Mocha.test("Belt.List.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.describe("Belt.List.removeAssoc", () => { + Mocha.test("Belt.List.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.describe("Belt.List.hasAssoc", () => { + Mocha.test("Belt.List.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.describe("Belt.List.getAssoc", () => { + Mocha.test("Belt.List.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.describe("Belt.List.unzip", () => { + Mocha.test("Belt.List.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.describe("Belt.List.partition", () => { + Mocha.test("Belt.List.partition", () => { + Pervasives.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.describe("Belt.List.keepMap", () => { + Mocha.test("Belt.List.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.describe("Belt.List.filterWithIndex", () => { + Mocha.test("Belt.List.filterWithIndex", () => { + Belt_List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("Belt.List.keepWithIndex", () => { + Mocha.test("Belt.List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("Belt.List.filter", () => { + Mocha.test("Belt.List.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.describe("Belt.List.keep", () => { + Mocha.test("Belt.List.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.describe("Belt.List.getBy", () => { + Mocha.test("Belt.List.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.describe("Belt.List.has", () => { + Mocha.test("Belt.List.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.describe("Belt.List.eq", () => { + Mocha.test("Belt.List.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.describe("Belt.List.cmp", () => { + Mocha.test("Belt.List.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.describe("Belt.List.cmpByLength", () => { + Mocha.test("Belt.List.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.describe("Belt.List.some2", () => { + Mocha.test("Belt.List.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.describe("Belt.List.every2", () => { + Mocha.test("Belt.List.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.describe("Belt.List.some", () => { + Mocha.test("Belt.List.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.describe("Belt.List.every", () => { + Mocha.test("Belt.List.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.describe("Belt.List.reduceReverse2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("Belt.List.reduce2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("Belt.List.forEach2", () => { + Mocha.test("Belt.List.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.describe("Belt.List.mapReverse2", () => { + Mocha.test("Belt.List.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.describe("Belt.List.reduceReverse", () => { + Mocha.test("Belt.List.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.describe("Belt.List.reduceWithIndex", () => { + Mocha.test("Belt.List.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.describe("Belt.List.reduce", () => { + Mocha.test("Belt.List.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.describe("Belt.List.forEachWithIndex", () => { + Mocha.test("Belt.List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); + }); +}); + +Mocha.describe("Belt.List.forEach", () => { + Mocha.test("Belt.List.forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); +}); + +Mocha.describe("Belt.List.mapReverse", () => { + Mocha.test("Belt.List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.reverse", () => { + Mocha.test("Belt.List.reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.toArray", () => { + Mocha.test("Belt.List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.fromArray", () => { + Mocha.test("Belt.List.fromArray", () => { + Belt_List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("Belt.List.mapWithIndex", () => { + Mocha.test("Belt.List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); + }); +}); + +Mocha.describe("Belt.List.zipBy", () => { + Mocha.test("Belt.List.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.List.zip", () => { + Mocha.test("Belt.List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.map", () => { + Mocha.test("Belt.List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); +}); + +Mocha.describe("Belt.List.flatten", () => { + Mocha.test("Belt.List.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.describe("Belt.List.reverseConcat", () => { + Mocha.test("Belt.List.reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("Belt.List.concatMany", () => { + Mocha.test("Belt.List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); +}); + +Mocha.describe("Belt.List.concat", () => { + Mocha.test("Belt.List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("Belt.List.splitAt", () => { + Mocha.test("Belt.List.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.describe("Belt.List.take", () => { + Mocha.test("Belt.List.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.describe("Belt.List.drop", () => { + Mocha.test("Belt.List.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.describe("Belt.List.shuffle", () => { + Mocha.test("Belt.List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.makeBy", () => { + Mocha.test("Belt.List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); + }); +}); + +Mocha.describe("Belt.List.make", () => { + Mocha.test("Belt.List.make", () => { + Belt_List.make(3, 1); + }); +}); + +Mocha.describe("Belt.List.getExn", () => { + Mocha.test("Belt.List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.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: [ + "mocha_full_test.res", + 5213, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.List.get", () => { + Mocha.test("Belt.List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); +}); + +Mocha.describe("Belt.List.add", () => { + Mocha.test("Belt.List.add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("Belt.List.tailExn", () => { + Mocha.test("Belt.List.tailExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 5252, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.List.tail", () => { + Mocha.test("Belt.List.tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Belt_List.tail(/* [] */0); + }); +}); + +Mocha.describe("Belt.List.headExn", () => { + Mocha.test("Belt.List.headExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 5278, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.List.head", () => { + Mocha.test("Belt.List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.length", () => { + Mocha.test("Belt.List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.SortArray.binarySearchBy", () => { + Mocha.test("Belt.SortArray.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.describe("Belt.SortArray.strictlySortedLength", () => { + Mocha.test("Belt.SortArray.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.truncateToLengthUnsafe", () => { + Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt.Array.eq", () => { + Mocha.test("Belt.Array.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt.Array.cmp", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.some2", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.every2", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.every", () => { + Mocha.test("Belt.Array.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt.Array.some", () => { + Mocha.test("Belt.Array.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt.Array.joinWith", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.reduceWithIndex", () => { + Mocha.test("Belt.Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt.Array.reduceReverse2", () => { + Mocha.test("Belt.Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt.Array.reduceReverse", () => { + Mocha.test("Belt.Array.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt.Array.reduce", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.partition", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.mapWithIndex", () => { + Mocha.test("Belt.Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt.Array.forEachWithIndex", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.keepMap", () => { + Mocha.test("Belt.Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt.Array.keepWithIndex", () => { + Mocha.test("Belt.Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt.Array.getIndexBy", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.getBy", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.flatMap", () => { + Mocha.test("Belt.Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt.Array.map", () => { + Mocha.test("Belt.Array.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Array.forEach", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.blit", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.fill", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.sliceToEnd", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.slice", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.concatMany", () => { + Mocha.test("Belt.Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt.Array.concat", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.unzip", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.zipBy", () => { + Mocha.test("Belt.Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt.Array.zip", () => { + Mocha.test("Belt.Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt.Array.makeBy", () => { + Mocha.test("Belt.Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt.Array.rangeBy", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.range", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.makeUninitialized", () => { + Mocha.test("Belt.Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt.Array.reverse", () => { + Mocha.test("Belt.Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt.Array.reverseInPlace", () => { + Mocha.test("Belt.Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt.Array.get", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.length", () => { + Mocha.test("Belt.Array.length", () => {}); +}); + +Mocha.describe("Belt.Option", () => { + Mocha.test("Belt.Option", () => {}); +}); + +Mocha.describe("Belt.HashMap", () => { + Mocha.test("Belt.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.describe("Belt.HashSet", () => { + Mocha.test("Belt.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.describe("Belt.MutableSet", () => { + Mocha.test("Belt.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.describe("Belt.Set", () => { + Mocha.test("Belt.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_Int./", () => { + Mocha.test("Belt_Int./", () => { + Pervasives.assertEqual(2, 2); + }); +}); + +Mocha.describe("Belt_Int.*", () => { + Mocha.test("Belt_Int.*", () => { + Pervasives.assertEqual(4, 4); + }); +}); + +Mocha.describe("Belt_Int.-", () => { + Mocha.test("Belt_Int.-", () => { + Pervasives.assertEqual(1, 1); + }); +}); + +Mocha.describe("Belt_Int.+", () => { + Mocha.test("Belt_Int.+", () => { + Pervasives.assertEqual(4, 4); + }); +}); + +Mocha.describe("Belt_Int.toString", () => { + Mocha.test("Belt_Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt_Int.fromString", () => { + Mocha.test("Belt_Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); + }); +}); + +Mocha.describe("Belt_Int.fromFloat", () => { + Mocha.test("Belt_Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); + }); +}); + +Mocha.describe("Belt_Int.toFloat", () => { + Mocha.test("Belt_Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); + }); +}); + +Mocha.describe("Belt_List.sort", () => { + Mocha.test("Belt_List.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.describe("Belt_List.setAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt_List.removeAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt_List.hasAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt_List.getAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt_List.unzip", () => { + Mocha.test("Belt_List.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.describe("Belt_List.partition", () => { + Mocha.test("Belt_List.partition", () => { + Pervasives.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.describe("Belt_List.keepMap", () => { + Mocha.test("Belt_List.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.describe("Belt_List.filterWithIndex", () => { + Mocha.test("Belt_List.filterWithIndex", () => { + Belt_List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("Belt_List.keepWithIndex", () => { + Mocha.test("Belt_List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("Belt_List.filter", () => { + Mocha.test("Belt_List.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.describe("Belt_List.keep", () => { + Mocha.test("Belt_List.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.describe("Belt_List.getBy", () => { + Mocha.test("Belt_List.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.describe("Belt_List.has", () => { + Mocha.test("Belt_List.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.describe("Belt_List.eq", () => { + Mocha.test("Belt_List.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.describe("Belt_List.cmp", () => { + Mocha.test("Belt_List.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.describe("Belt_List.cmpByLength", () => { + Mocha.test("Belt_List.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.describe("Belt_List.some2", () => { + Mocha.test("Belt_List.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.describe("Belt_List.every2", () => { + Mocha.test("Belt_List.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.describe("Belt_List.some", () => { + Mocha.test("Belt_List.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.describe("Belt_List.every", () => { + Mocha.test("Belt_List.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.describe("Belt_List.reduceReverse2", () => { + Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("Belt_List.reduce2", () => { + Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("Belt_List.forEach2", () => { + Mocha.test("Belt_List.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.describe("Belt_List.mapReverse2", () => { + Mocha.test("Belt_List.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.describe("Belt_List.reduceReverse", () => { + Mocha.test("Belt_List.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.describe("Belt_List.reduceWithIndex", () => { + Mocha.test("Belt_List.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.describe("Belt_List.reduce", () => { + Mocha.test("Belt_List.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.describe("Belt_List.forEachWithIndex", () => { + Mocha.test("Belt_List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); + }); +}); + +Mocha.describe("Belt_List.forEach", () => { + Mocha.test("Belt_List.forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); +}); + +Mocha.describe("Belt_List.mapReverse", () => { + Mocha.test("Belt_List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.reverse", () => { + Mocha.test("Belt_List.reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.toArray", () => { + Mocha.test("Belt_List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.fromArray", () => { + Mocha.test("Belt_List.fromArray", () => { + Belt_List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("Belt_List.mapWithIndex", () => { + Mocha.test("Belt_List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); + }); +}); + +Mocha.describe("Belt_List.zipBy", () => { + Mocha.test("Belt_List.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_List.zip", () => { + Mocha.test("Belt_List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.map", () => { + Mocha.test("Belt_List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); +}); + +Mocha.describe("Belt_List.flatten", () => { + Mocha.test("Belt_List.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.describe("Belt_List.reverseConcat", () => { + Mocha.test("Belt_List.reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("Belt_List.concatMany", () => { + Mocha.test("Belt_List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); +}); + +Mocha.describe("Belt_List.concat", () => { + Mocha.test("Belt_List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("Belt_List.splitAt", () => { + Mocha.test("Belt_List.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.describe("Belt_List.take", () => { + Mocha.test("Belt_List.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.describe("Belt_List.drop", () => { + Mocha.test("Belt_List.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.describe("Belt_List.shuffle", () => { + Mocha.test("Belt_List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.makeBy", () => { + Mocha.test("Belt_List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); + }); +}); + +Mocha.describe("Belt_List.make", () => { + Mocha.test("Belt_List.make", () => { + Belt_List.make(3, 1); + }); +}); + +Mocha.describe("Belt_List.getExn", () => { + Mocha.test("Belt_List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.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: [ + "mocha_full_test.res", + 6599, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_List.get", () => { + Mocha.test("Belt_List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); +}); + +Mocha.describe("Belt_List.add", () => { + Mocha.test("Belt_List.add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("Belt_List.tailExn", () => { + Mocha.test("Belt_List.tailExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 6638, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_List.tail", () => { + Mocha.test("Belt_List.tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Belt_List.tail(/* [] */0); + }); +}); + +Mocha.describe("Belt_List.headExn", () => { + Mocha.test("Belt_List.headExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 6664, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_List.head", () => { + Mocha.test("Belt_List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_List.length", () => { + Mocha.test("Belt_List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt_Map.Dict.findFirstBy", () => { + Mocha.test("Belt_Map.Dict.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.String.findFirstBy", () => { + Mocha.test("Belt_Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt_Map.Int.findFirstBy", () => { + Mocha.test("Belt_Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt_Map.set", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.remove", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.get", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.valuesToArray", () => { + Mocha.test("Belt_Map.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.keysToArray", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.fromArray", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.toArray", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.size", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.reduce", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.forEach", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.findFirstBy", () => { + Mocha.test("Belt_Map.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); + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt_Map.has", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.isEmpty", () => { + Mocha.test("Belt_Map.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; + }); +}); + +Mocha.describe("Belt_Map.make", () => { + Mocha.test("Belt_Map.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.describe("Belt_Map.Int", () => { + Mocha.test("Belt_Map.Int", () => {}); +}); + +Mocha.describe("Belt_MapString.findFirstBy", () => { + Mocha.test("Belt_MapString.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt_MapDict.findFirstBy", () => { + Mocha.test("Belt_MapDict.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.findFirstBy", () => { + Mocha.test("Belt_MapInt.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); + }); +}); + +Mocha.describe("Belt_MutableSet.split", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.get", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.maxUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.maximum", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.minUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.minimum", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.toArray", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.toList", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.size", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.partition", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.keep", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.some", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.every", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.reduce", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.forEach", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.eq", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.subset", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.diff", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.intersect", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.union", () => { + Mocha.test("Belt_MutableSet.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_MutableSet.removeMany", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.remove", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.mergeMany", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.add", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.has", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.isEmpty", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.copy", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.fromArray", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_Range.someBy", () => { + Mocha.test("Belt_Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt_Range.some", () => { + Mocha.test("Belt_Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); +}); + +Mocha.describe("Belt_Range.everyBy", () => { + Mocha.test("Belt_Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt_Range.every", () => { + Mocha.test("Belt_Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); +}); + +Mocha.describe("Belt_Range.forEach", () => { + Mocha.test("Belt_Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); +}); + +Mocha.describe("Belt_Option.cmp", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.eq", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.isNone", () => { + Mocha.test("Belt_Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); + }); +}); + +Mocha.describe("Belt_Option.isSome", () => { + Mocha.test("Belt_Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); + }); +}); + +Mocha.describe("Belt_Option.orElse", () => { + Mocha.test("Belt_Option.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_Option.getWithDefault", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.flatMap", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.map", () => { + Mocha.test("Belt_Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Belt_Option.mapWithDefault", () => { + Mocha.test("Belt_Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("Belt_Option.getExn", () => { + Mocha.test("Belt_Option.getExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 7724, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_Option.forEach", () => { + Mocha.test("Belt_Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Belt_Option.keep", () => { + Mocha.test("Belt_Option.keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); + }); +}); + +Mocha.describe("Belt_Result.cmp", () => { + Mocha.test("Belt_Result.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.describe("Belt_Result.eq", () => { + Mocha.test("Belt_Result.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.describe("Belt_Result.getWithDefault", () => { + Mocha.test("Belt_Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); +}); + +Mocha.describe("Belt_Result.flatMap", () => { + Mocha.test("Belt_Result.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.describe("Belt_Result.map", () => { + Mocha.test("Belt_Result.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.describe("Belt_Result.mapWithDefault", () => { + Mocha.test("Belt_Result.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_Result.getExn", () => { + Mocha.test("Belt_Result.getExn", () => { + Pervasives.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: [ + "mocha_full_test.res", + 7871, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_SetDict.split", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.get", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.maxUndefined", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.maximum", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.minUndefined", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.minimum", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.toArray", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.toList", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.size", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.partition", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.keep", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.some", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.every", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.reduce", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.forEach", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.eq", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.subset", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.diff", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.intersect", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.union", () => { + Mocha.test("Belt_SetDict.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.removeMany", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.remove", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.mergeMany", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.add", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.has", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.isEmpty", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.fromArray", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.empty", () => { + Mocha.test("Belt_SetDict.empty", () => {}); +}); + +Mocha.describe("Belt_Set.Dict.split", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.get", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.maxUndefined", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.maximum", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.minUndefined", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.minimum", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.toArray", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.toList", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.size", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.partition", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.keep", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.some", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.every", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.reduce", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.forEach", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.eq", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.subset", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.diff", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.intersect", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.union", () => { + Mocha.test("Belt_Set.Dict.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_Set.Dict.removeMany", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.remove", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.mergeMany", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.add", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.has", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.isEmpty", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.fromArray", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.empty", () => { + Mocha.test("Belt_Set.Dict.empty", () => {}); +}); + +Mocha.describe("Belt_Set.split", () => { + Mocha.test("Belt_Set.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]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); + }); +}); + +Mocha.describe("Belt_Set.get", () => { + Mocha.test("Belt_Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); + }); +}); + +Mocha.describe("Belt_Set.maxUndefined", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + }); +}); + +Mocha.describe("Belt_Set.maximum", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + }); +}); + +Mocha.describe("Belt_Set.minUndefined", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + }); +}); + +Mocha.describe("Belt_Set.minimum", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); + }); +}); + +Mocha.describe("Belt_Set.toList", () => { + Mocha.test("Belt_Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt_Set.toArray", () => { + Mocha.test("Belt_Set.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_Set.size", () => { + Mocha.test("Belt_Set.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.size(s0), 4); + }); +}); + +Mocha.describe("Belt_Set.partition", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ + 1, + 3, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 + ]); + }); +}); + +Mocha.describe("Belt_Set.keep", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); + }); +}); + +Mocha.describe("Belt_Set.some", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); + }); +}); + +Mocha.describe("Belt_Set.every", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + }); +}); + +Mocha.describe("Belt_Set.reduce", () => { + Mocha.test("Belt_Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt_Set.forEach", () => { + Mocha.test("Belt_Set.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); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); + }); +}); + +Mocha.describe("Belt_Set.eq", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); + }); +}); + +Mocha.describe("Belt_Set.subset", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); + }); +}); + +Mocha.describe("Belt_Set.diff", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); + }); +}); + +Mocha.describe("Belt_Set.intersect", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_Set.union", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); + }); +}); + +Mocha.describe("Belt_Set.removeMany", () => { + Mocha.test("Belt_Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); + }); +}); + +Mocha.describe("Belt_Set.remove", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); + }); +}); + +Mocha.describe("Belt_Set.mergeMany", () => { + Mocha.test("Belt_Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + 1, + 2, + 3, + 4, + 5 + ]); + }); +}); + +Mocha.describe("Belt_Set.add", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Pervasives.assertEqual(s2, s3); + }); +}); + +Mocha.describe("Belt_Set.has", () => { + Mocha.test("Belt_Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); + }); +}); + +Mocha.describe("Belt_Set.isEmpty", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); +}); + +Mocha.describe("Belt_Set.fromArray", () => { + Mocha.test("Belt_Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_Set.make", () => { + Mocha.test("Belt_Set.make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); + }); +}); + +Mocha.describe("Belt_SortArray.binarySearchBy", () => { + Mocha.test("Belt_SortArray.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.describe("Belt_SortArray.strictlySortedLength", () => { + Mocha.test("Belt_SortArray.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("BigInt.toLocaleString", () => { + Mocha.test("BigInt.toLocaleString", () => { + console.log((123n).toString()); + }); +}); + +Mocha.describe("BigInt.toString", () => { + Mocha.test("BigInt.toString", () => { + console.log((123n).toString()); + }); +}); + +Mocha.describe("BigInt.fromStringExn", () => { + Mocha.test("BigInt.fromStringExn", () => { + BigInt("123"); + BigInt(""); + BigInt("0x11"); + BigInt("0b11"); + BigInt("0o11"); + try { + BigInt("a"); + } catch (raw__error) { + let _error = Primitive_exceptions.internalToException(raw__error); + if (_error.RE_EXN_ID !== Exn.$$Error) { + throw _error; + } + + } + }); +}); + +Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.eq", () => { + Mocha.test("Belt_internalSetString.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_internalSetString.A.cmp", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.some2", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.every2", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.every", () => { + Mocha.test("Belt_internalSetString.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalSetString.A.some", () => { + Mocha.test("Belt_internalSetString.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalSetString.A.joinWith", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt_internalSetString.A.reduce", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.partition", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.keepMap", () => { + Mocha.test("Belt_internalSetString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.getBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.flatMap", () => { + Mocha.test("Belt_internalSetString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.map", () => { + Mocha.test("Belt_internalSetString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.forEach", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.blit", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.fill", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.slice", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.concatMany", () => { + Mocha.test("Belt_internalSetString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.concat", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.unzip", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.zipBy", () => { + Mocha.test("Belt_internalSetString.A.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.zip", () => { + Mocha.test("Belt_internalSetString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.makeBy", () => { + Mocha.test("Belt_internalSetString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.rangeBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.range", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalSetString.A.reverse", () => { + Mocha.test("Belt_internalSetString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalSetString.A.get", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.length", () => { + Mocha.test("Belt_internalSetString.A.length", () => {}); +}); + +Mocha.describe("Belt_internalMapInt.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapInt.S.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.describe("Belt_internalMapInt.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapInt.S.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.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.eq", () => { + Mocha.test("Belt_internalMapInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.cmp", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.some2", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.every2", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.every", () => { + Mocha.test("Belt_internalMapInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.some", () => { + Mocha.test("Belt_internalMapInt.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.joinWith", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.reduceReverse", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.reduce", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.partition", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.keepMap", () => { + Mocha.test("Belt_internalMapInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.getIndexBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.getBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.flatMap", () => { + Mocha.test("Belt_internalMapInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.map", () => { + Mocha.test("Belt_internalMapInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.forEach", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.blit", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.fill", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.slice", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.concatMany", () => { + Mocha.test("Belt_internalMapInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.concat", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.unzip", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.zipBy", () => { + Mocha.test("Belt_internalMapInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.zip", () => { + Mocha.test("Belt_internalMapInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.makeBy", () => { + Mocha.test("Belt_internalMapInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.rangeBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.range", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.reverse", () => { + Mocha.test("Belt_internalMapInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.get", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.length", () => { + Mocha.test("Belt_internalMapInt.A.length", () => {}); +}); + +Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapString.S.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.describe("Belt_internalMapString.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapString.S.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.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.eq", () => { + Mocha.test("Belt_internalMapString.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_internalMapString.A.cmp", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.some2", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.every2", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.every", () => { + Mocha.test("Belt_internalMapString.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalMapString.A.some", () => { + Mocha.test("Belt_internalMapString.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalMapString.A.joinWith", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt_internalMapString.A.reduce", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.partition", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.keepMap", () => { + Mocha.test("Belt_internalMapString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.getBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.flatMap", () => { + Mocha.test("Belt_internalMapString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.map", () => { + Mocha.test("Belt_internalMapString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.forEach", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.blit", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.fill", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.slice", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.concatMany", () => { + Mocha.test("Belt_internalMapString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.concat", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.unzip", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.zipBy", () => { + Mocha.test("Belt_internalMapString.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.zip", () => { + Mocha.test("Belt_internalMapString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.makeBy", () => { + Mocha.test("Belt_internalMapString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.rangeBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.range", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalMapString.A.reverse", () => { + Mocha.test("Belt_internalMapString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalMapString.A.get", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.length", () => { + Mocha.test("Belt_internalMapString.A.length", () => {}); +}); + +Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.eq", () => { + Mocha.test("Belt_internalSetInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.cmp", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.some2", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.every2", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.every", () => { + Mocha.test("Belt_internalSetInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.some", () => { + Mocha.test("Belt_internalSetInt.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.joinWith", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.reduce", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.partition", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.keepMap", () => { + Mocha.test("Belt_internalSetInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.getBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.flatMap", () => { + Mocha.test("Belt_internalSetInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.map", () => { + Mocha.test("Belt_internalSetInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.forEach", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.blit", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.fill", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.slice", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.concatMany", () => { + Mocha.test("Belt_internalSetInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.concat", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.unzip", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.zipBy", () => { + Mocha.test("Belt_internalSetInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.zip", () => { + Mocha.test("Belt_internalSetInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.makeBy", () => { + Mocha.test("Belt_internalSetInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.range", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.reverse", () => { + Mocha.test("Belt_internalSetInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_internalSetInt.A.get", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.length", () => { + Mocha.test("Belt_internalSetInt.A.length", () => {}); +}); + +Mocha.describe("Console.warnMany", () => { + Mocha.test("Console.warnMany", () => { + console.warn("Hello", "World"); + console.warn(1, 2, 3); + }); +}); + +Mocha.describe("Console.warn6", () => { + Mocha.test("Console.warn6", () => { + console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.warn([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.warn5", () => { + Mocha.test("Console.warn5", () => { + console.warn("Hello", "World", "from", "JS", "!!!"); + console.warn([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.warn4", () => { + Mocha.test("Console.warn4", () => { + console.warn("Hello", "World", "ReScript", "!!!"); + console.warn("first", "second", "third", "fourth"); + }); +}); + +Mocha.describe("Console.warn3", () => { + Mocha.test("Console.warn3", () => { + console.warn("Hello", "World", "ReScript"); + console.warn([ + 1, + 2, + 3 + ], 4, 5); + }); +}); + +Mocha.describe("Console.warn2", () => { + Mocha.test("Console.warn2", () => { + console.warn("Hello", "World"); + console.warn([ + 1, + 2, + 3 + ], 4); + }); +}); + +Mocha.describe("Console.warn", () => { + Mocha.test("Console.warn", () => { + console.warn("Warning"); + console.warn([ + "Warning", + "invalid number" + ]); + }); +}); + +Mocha.describe("Console.trace", () => { + Mocha.test("Console.trace", () => { + console.trace(); + }); +}); + +Mocha.describe("Console.timeLog", () => { + Mocha.test("Console.timeLog", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); +}); + +Mocha.describe("Console.timeEnd", () => { + Mocha.test("Console.timeEnd", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); +}); + +Mocha.describe("Console.time", () => { + Mocha.test("Console.time", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); +}); + +Mocha.describe("Console.table", () => { + Mocha.test("Console.table", () => { + console.table({ + language: "rescript", + version: "10.1.2" + }); + }); +}); + +Mocha.describe("Console.logMany", () => { + Mocha.test("Console.logMany", () => { + console.log("Hello", "World"); + console.log(1, 2, 3); + }); +}); + +Mocha.describe("Console.log6", () => { + Mocha.test("Console.log6", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.log5", () => { + Mocha.test("Console.log5", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.log4", () => { + Mocha.test("Console.log4", () => { + console.log("Hello", "World", "ReScript", "!!!"); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); +}); + +Mocha.describe("Console.log3", () => { + Mocha.test("Console.log3", () => { + console.log("Hello", "World", "ReScript"); + console.log("One", 2, 3); + }); +}); + +Mocha.describe("Console.log2", () => { + Mocha.test("Console.log2", () => { + console.log("Hello", "World"); + console.log([ + 1, + 2, + 3 + ], /* '4' */52); + }); +}); + +Mocha.describe("Console.log", () => { + Mocha.test("Console.log", () => { + console.log("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.log(obj); + }); +}); + +Mocha.describe("Console.infoMany", () => { + Mocha.test("Console.infoMany", () => { + console.info("Hello", "World"); + console.info(1, 2, 3); + }); +}); + +Mocha.describe("Console.info6", () => { + Mocha.test("Console.info6", () => { + console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.info([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.info5", () => { + Mocha.test("Console.info5", () => { + console.info("Hello", "World", "from", "JS", "!!!"); + console.info([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.info4", () => { + Mocha.test("Console.info4", () => { + console.info("Hello", "World", "ReScript", /* '!' */33); + console.info([ + 1, + 2, + 3 + ], 4, 5, "lastinfo"); + }); +}); + +Mocha.describe("Console.info3", () => { + Mocha.test("Console.info3", () => { + console.info("Hello", "World", "ReScript"); + console.info([ + 1, + 2, + 3 + ], 4, 5); + }); +}); + +Mocha.describe("Console.info2", () => { + Mocha.test("Console.info2", () => { + console.info("Info", "failed to download"); + console.info("info", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.info", () => { + Mocha.test("Console.info", () => { + console.info("Information"); + console.info([ + "Hello", + "JS" + ]); + }); +}); + +Mocha.describe("Console.errorMany", () => { + Mocha.test("Console.errorMany", () => { + console.error("Hello", "World"); + console.error(1, 2, 3); + }); +}); + +Mocha.describe("Console.group", () => { + Mocha.test("Console.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.describe("Console.error6", () => { + Mocha.test("Console.error6", () => { + console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.error([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.error5", () => { + Mocha.test("Console.error5", () => { + console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); + console.error(1, "second", "third", "fourth", /* 'c' */99); + }); +}); + +Mocha.describe("Console.error4", () => { + Mocha.test("Console.error4", () => { + console.error("Hello", "World", "ReScript", /* '!' */33); + console.error("first", "second", "third", "fourth"); + }); +}); + +Mocha.describe("Console.error3", () => { + Mocha.test("Console.error3", () => { + console.error("Hello", "World", "!!!"); + console.error("first", "second", "third"); + }); +}); + +Mocha.describe("Console.error2", () => { + Mocha.test("Console.error2", () => { + console.error("Error", "here"); + console.error([ + "log", + "error" + ], "message"); + }); +}); + +Mocha.describe("Console.error", () => { + Mocha.test("Console.error", () => { + console.error("error message"); + console.error([ + "error", + "invalid value" + ]); + }); +}); + +Mocha.describe("Console.dir", () => { + Mocha.test("Console.dir", () => { + console.dir({ + language: "rescript", + version: "10.1.2" + }); + }); +}); + +Mocha.describe("Console.debugMany", () => { + Mocha.test("Console.debugMany", () => { + console.debug("Hello", "World"); + console.debug(1, 2, 3); + }); +}); + +Mocha.describe("Console.debug6", () => { + Mocha.test("Console.debug6", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.debug5", () => { + Mocha.test("Console.debug5", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.debug4", () => { + Mocha.test("Console.debug4", () => { + console.debug("Hello", "World", "ReScript", "!!!"); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); +}); + +Mocha.describe("Console.debug3", () => { + Mocha.test("Console.debug3", () => { + console.debug("Hello", "World", "ReScript"); + console.debug("One", 2, 3); + }); +}); + +Mocha.describe("Console.debug2", () => { + Mocha.test("Console.debug2", () => { + console.debug("Hello", "World"); + console.debug([ + 1, + 2, + 3 + ], /* '4' */52); + }); +}); + +Mocha.describe("Console.debug", () => { + Mocha.test("Console.debug", () => { + console.debug("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.debug(obj); + }); +}); + +Mocha.describe("Console.countReset", () => { + Mocha.test("Console.countReset", () => { + console.countReset("rescript"); + }); +}); + +Mocha.describe("Console.count", () => { + Mocha.test("Console.count", () => { + console.count("rescript"); + }); +}); + +Mocha.describe("Console.clear", () => { + Mocha.test("Console.clear", () => { + console.clear(); + }); +}); + +Mocha.describe("Console.assertMany", () => { + Mocha.test("Console.assertMany", () => { + console.assert(false, "Hello", "World"); + console.assert(true, 1, 2, 3); + }); +}); + +Mocha.describe("Console.assert6", () => { + Mocha.test("Console.assert6", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); + }); +}); + +Mocha.describe("Console.assert5", () => { + Mocha.test("Console.assert5", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.assert4", () => { + Mocha.test("Console.assert4", () => { + console.assert(false, "Hello", "World", "ReScript", "!!!"); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); + }); +}); + +Mocha.describe("Console.assert3", () => { + Mocha.test("Console.assert3", () => { + console.assert(false, "Hello", "World", "ReScript"); + console.assert(true, "One", 2, 3); + }); +}); + +Mocha.describe("Console.assert2", () => { + Mocha.test("Console.assert2", () => { + console.assert(false, "Hello", "World"); + console.assert(true, [ + 1, + 2, + 3 + ], /* '4' */52); + }); +}); + +Mocha.describe("Console.assert_", () => { + Mocha.test("Console.assert_", () => { + console.assert(false, "Hello World!"); + console.assert(true, "The answer"); + }); +}); + +Mocha.describe("Date.UTC.makeWithYMDHMSM", () => { + Mocha.test("Date.UTC.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("Date.UTC.makeWithYMDHMS", () => { + Mocha.test("Date.UTC.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.describe("Date.UTC.makeWithYMDHM", () => { + Mocha.test("Date.UTC.makeWithYMDHM", () => { + Date.UTC(2023, 1, 20, 16, 40); + Date.UTC(2023, 1, 20, 16, 60); + Date.UTC(2023, 1, 20, 16, -1); + }); +}); + +Mocha.describe("Date.UTC.makeWithYMDH", () => { + Mocha.test("Date.UTC.makeWithYMDH", () => { + Date.UTC(2023, 1, 20, 16); + Date.UTC(2023, 1, 20, 24); + Date.UTC(2023, 1, 20, -1); + }); +}); + +Mocha.describe("Date.UTC.makeWithYMD", () => { + Mocha.test("Date.UTC.makeWithYMD", () => { + Date.UTC(2023, 1, 20); + Date.UTC(2023, 1, -1); + Date.UTC(2023, 1, 29); + }); +}); + +Mocha.describe("Date.UTC.makeWithYM", () => { + Mocha.test("Date.UTC.makeWithYM", () => { + Date.UTC(2023, 0); + Date.UTC(2023, 11); + Date.UTC(2023, 12); + Date.UTC(2023, -1); + }); +}); + +Mocha.describe("Date.toJSON", () => { + Mocha.test("Date.toJSON", () => { + new Date("2023-01-01T00:00:00.00+00:00").toJSON(); + new Date("").toJSON(); + }); +}); + +Mocha.describe("Date.toUTCString", () => { + Mocha.test("Date.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("Date.toISOString", () => { + Mocha.test("Date.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.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleTimeString("en-US", { + timeStyle: "long" + })); + console.log(new Date().toLocaleTimeString("de", { + hour: "2-digit", + minute: "2-digit" + })); + }); +}); + +Mocha.describe("Date.toLocaleTimeStringWithLocale", () => { + Mocha.test("Date.toLocaleTimeStringWithLocale", () => { + console.log(new Date().toLocaleTimeString("en-US")); + }); +}); + +Mocha.describe("Date.toLocaleTimeString", () => { + Mocha.test("Date.toLocaleTimeString", () => { + console.log(new Date().toLocaleTimeString()); + }); +}); + +Mocha.describe("Date.toLocaleStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("Date.toLocaleStringWithLocale", () => { + Mocha.test("Date.toLocaleStringWithLocale", () => { + console.log(new Date().toLocaleString("en-US")); + }); +}); + +Mocha.describe("Date.toLocaleString", () => { + Mocha.test("Date.toLocaleString", () => { + console.log(new Date().toLocaleString()); + }); +}); + +Mocha.describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("Date.toLocaleDateStringWithLocale", () => { + Mocha.test("Date.toLocaleDateStringWithLocale", () => { + console.log(new Date().toLocaleDateString("en-US")); + }); +}); + +Mocha.describe("Date.toLocaleDateString", () => { + Mocha.test("Date.toLocaleDateString", () => { + console.log(new Date().toLocaleDateString()); + }); +}); + +Mocha.describe("Date.toTimeString", () => { + Mocha.test("Date.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.describe("Date.toString", () => { + Mocha.test("Date.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.describe("Date.toDateString", () => { + Mocha.test("Date.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.describe("Date.setUTCMilliseconds", () => { + Mocha.test("Date.setUTCMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); + }); +}); + +Mocha.describe("Date.setUTCSecondsMs", () => { + Mocha.test("Date.setUTCSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); + }); +}); + +Mocha.describe("Date.setUTCSeconds", () => { + Mocha.test("Date.setUTCSeconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); + }); +}); + +Mocha.describe("Date.setUTCMinutesSMs", () => { + Mocha.test("Date.setUTCMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); + }); +}); + +Mocha.describe("Date.setUTCMinutesS", () => { + Mocha.test("Date.setUTCMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); + }); +}); + +Mocha.describe("Date.setUTCMinutes", () => { + Mocha.test("Date.setUTCMinutes", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); + }); +}); + +Mocha.describe("Date.setUTCHoursMSMs", () => { + Mocha.test("Date.setUTCHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); + }); +}); + +Mocha.describe("Date.setUTCHoursMS", () => { + Mocha.test("Date.setUTCHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); + }); +}); + +Mocha.describe("Date.setUTCHoursM", () => { + Mocha.test("Date.setUTCHoursM", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); + }); +}); + +Mocha.describe("Date.setUTCHours", () => { + Mocha.test("Date.setUTCHours", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0); + }); +}); + +Mocha.describe("Date.setUTCDate", () => { + Mocha.test("Date.setUTCDate", () => { + new Date("2023-02-20T16:40:00.00").setUTCDate(1); + }); +}); + +Mocha.describe("Date.setUTCMonth", () => { + Mocha.test("Date.setUTCMonth", () => { + new Date("2023-02-20T16:40:00.00").setUTCMonth(0); + }); +}); + +Mocha.describe("Date.setUTCFullYearMD", () => { + Mocha.test("Date.setUTCFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); + }); +}); + +Mocha.describe("Date.setUTCFullYearM", () => { + Mocha.test("Date.setUTCFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); + }); +}); + +Mocha.describe("Date.setUTCFullYear", () => { + Mocha.test("Date.setUTCFullYear", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); + }); +}); + +Mocha.describe("Date.getUTCDay", () => { + Mocha.test("Date.getUTCDay", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); + }); +}); + +Mocha.describe("Date.getUTCMilliseconds", () => { + Mocha.test("Date.getUTCMilliseconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); + }); +}); + +Mocha.describe("Date.getUTCSeconds", () => { + Mocha.test("Date.getUTCSeconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); + }); +}); + +Mocha.describe("Date.getUTCMinutes", () => { + Mocha.test("Date.getUTCMinutes", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); + }); +}); + +Mocha.describe("Date.getUTCHours", () => { + Mocha.test("Date.getUTCHours", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); + }); +}); + +Mocha.describe("Date.getUTCDate", () => { + Mocha.test("Date.getUTCDate", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); + }); +}); + +Mocha.describe("Date.getUTCMonth", () => { + Mocha.test("Date.getUTCMonth", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); + }); +}); + +Mocha.describe("Date.getUTCFullYear", () => { + Mocha.test("Date.getUTCFullYear", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); + }); +}); + +Mocha.describe("Date.setMilliseconds", () => { + Mocha.test("Date.setMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setMilliseconds(0); + }); +}); + +Mocha.describe("Date.setSecondsMs", () => { + Mocha.test("Date.setSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); + }); +}); + +Mocha.describe("Date.setSeconds", () => { + Mocha.test("Date.setSeconds", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0); + }); +}); + +Mocha.describe("Date.setMinutesSMs", () => { + Mocha.test("Date.setMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); + }); +}); + +Mocha.describe("Date.setMinutesS", () => { + Mocha.test("Date.setMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); + }); +}); + +Mocha.describe("Date.setMinutes", () => { + Mocha.test("Date.setMinutes", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0); + }); +}); + +Mocha.describe("Date.setHoursMSMs", () => { + Mocha.test("Date.setHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); + }); +}); + +Mocha.describe("Date.setHoursMS", () => { + Mocha.test("Date.setHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); + }); +}); + +Mocha.describe("Date.setHoursM", () => { + Mocha.test("Date.setHoursM", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0); + }); +}); + +Mocha.describe("Date.setHours", () => { + Mocha.test("Date.setHours", () => { + new Date("2023-02-20T16:40:00.00").setHours(0); + }); +}); + +Mocha.describe("Date.setDate", () => { + Mocha.test("Date.setDate", () => { + new Date("2023-02-20T16:40:00.00").setDate(1); + }); +}); + +Mocha.describe("Date.setMonth", () => { + Mocha.test("Date.setMonth", () => { + new Date("2023-02-20T16:40:00.00").setMonth(0); + }); +}); + +Mocha.describe("Date.setFullYearMD", () => { + Mocha.test("Date.setFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); + }); +}); + +Mocha.describe("Date.setFullYearM", () => { + Mocha.test("Date.setFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); + }); +}); + +Mocha.describe("Date.setFullYear", () => { + Mocha.test("Date.setFullYear", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024); + }); +}); + +Mocha.describe("Date.getDay", () => { + Mocha.test("Date.getDay", () => { + new Date("2023-02-20T16:40:00.00").getDay(); + }); +}); + +Mocha.describe("Date.getMilliseconds", () => { + Mocha.test("Date.getMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").getMilliseconds(); + }); +}); + +Mocha.describe("Date.getSeconds", () => { + Mocha.test("Date.getSeconds", () => { + new Date("2023-02-20T16:40:00.00").getSeconds(); + }); +}); + +Mocha.describe("Date.getMinutes", () => { + Mocha.test("Date.getMinutes", () => { + new Date("2023-02-20T16:40:00.00").getMinutes(); + }); +}); + +Mocha.describe("Date.getHours", () => { + Mocha.test("Date.getHours", () => { + new Date("2023-02-20T16:40:00.00").getHours(); + }); +}); + +Mocha.describe("Date.getDate", () => { + Mocha.test("Date.getDate", () => { + new Date("2023-02-20T16:40:00.00").getDate(); + }); +}); + +Mocha.describe("Date.getMonth", () => { + Mocha.test("Date.getMonth", () => { + new Date("2023-01-01").getMonth(); + }); +}); + +Mocha.describe("Date.getFullYear", () => { + Mocha.test("Date.getFullYear", () => { + new Date("2023-02-20").getFullYear(); + }); +}); + +Mocha.describe("Date.getTimezoneOffset", () => { + Mocha.test("Date.getTimezoneOffset", () => { + new Date("2023-01-01").getTimezoneOffset(); + new Date("2023-06-01").getTimezoneOffset(); + }); +}); + +Mocha.describe("Date.getTime", () => { + Mocha.test("Date.getTime", () => { + new Date("2023-02-20").getTime(); + }); +}); + +Mocha.describe("Date.makeWithYMDHMSM", () => { + Mocha.test("Date.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.describe("Date.makeWithYMDHMS", () => { + Mocha.test("Date.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.describe("Date.makeWithYMDHM", () => { + Mocha.test("Date.makeWithYMDHM", () => { + new Date(2023, 1, 20, 16, 40); + new Date(2023, 1, 20, 16, 60); + new Date(2023, 1, 20, 16, -1); + }); +}); + +Mocha.describe("Date.makeWithYMDH", () => { + Mocha.test("Date.makeWithYMDH", () => { + new Date(2023, 1, 20, 16); + new Date(2023, 1, 20, 24); + new Date(2023, 1, 20, -1); + }); +}); + +Mocha.describe("Date.makeWithYMD", () => { + Mocha.test("Date.makeWithYMD", () => { + new Date(2023, 1, 20); + new Date(2023, 1, -1); + new Date(2023, 1, 29); + }); +}); + +Mocha.describe("Date.makeWithYM", () => { + Mocha.test("Date.makeWithYM", () => { + new Date(2023, 0); + new Date(2023, 11); + new Date(2023, 12); + new Date(2023, -1); + }); +}); + +Mocha.describe("Date.fromTime", () => { + Mocha.test("Date.fromTime", () => { + new Date(0.0); + new Date(-86400000.0); + new Date(86400000.0); + }); +}); + +Mocha.describe("Date.fromString", () => { + Mocha.test("Date.fromString", () => { + new Date("2023"); + new Date("2023-02-20"); + new Date("2023-02-20T16:40:00.00Z"); + new Date(""); + new Date("").getTime(); + }); +}); + +Mocha.describe("Date.make", () => { + Mocha.test("Date.make", () => { + new Date(); + }); +}); + +Mocha.describe("Dict.mapValues", () => { + Mocha.test("Dict.mapValues", () => { + let dict = Object.fromEntries([ + [ + "key1", + 1 + ], + [ + "key2", + 2 + ] + ]); + Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); + Object.entries(Dict.mapValues(dict, v => v.toString())); + }); +}); + +Mocha.describe("Dict.forEachWithKey", () => { + Mocha.test("Dict.forEachWithKey", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEachWithKey(dict, (value, key) => { + console.log(value, key); + }); + }); +}); + +Mocha.describe("Dict.forEach", () => { + Mocha.test("Dict.forEach", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEach(dict, value => { + console.log(value); + }); + }); +}); + +Mocha.describe("Dict.copy", () => { + Mocha.test("Dict.copy", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + let dict2 = Object.assign({}, dict); + console.log(Object.keys(dict), Object.keys(dict2)); + }); +}); + +Mocha.describe("Dict.assign", () => { + Mocha.test("Dict.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.describe("Dict.valuesToArray", () => { + Mocha.test("Dict.valuesToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let values = Object.values(dict); + console.log(values); + }); +}); + +Mocha.describe("Dict.keysToArray", () => { + Mocha.test("Dict.keysToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let keys = Object.keys(dict); + console.log(keys); + }); +}); + +Mocha.describe("Dict.toArray", () => { + Mocha.test("Dict.toArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let asArray = Object.entries(dict); + console.log(asArray); + }); +}); + +Mocha.describe("Dict.fromIterator", () => { + Mocha.test("Dict.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ + 1, + 2 + ]); + }); +}); + +Mocha.describe("Dict.fromArray", () => { + Mocha.test("Dict.fromArray", () => { + Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + }); +}); + +Mocha.describe("Dict.make", () => { + Mocha.test("Dict.make", () => { + let dict2 = {}; + dict2["someKey"] = 12; + }); +}); + +Mocha.describe("Dict.delete", () => { + Mocha.test("Dict.delete", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + Dict.$$delete(dict, "someKey"); + }); +}); + +Mocha.describe("Dict.set", () => { + Mocha.test("Dict.set", () => { + let dict = {}; + dict["someKey"] = "someValue"; + }); +}); + +Mocha.describe("Dict.get", () => { + Mocha.test("Dict.get", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + let value = dict["someKey"]; + if (value !== undefined) { + console.log(value); + } else { + console.log("Nope, didn't have the key."); + } + }); +}); + +Mocha.describe("Dict.getUnsafe", () => { + Mocha.test("Dict.getUnsafe", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + let value = dict["key1"]; + console.log(value); + }); +}); + +Mocha.describe("Error.panic", () => { + Mocha.test("Error.panic", () => { + try { + $$Error.panic("Uh oh. This was unexpected!"); + } catch (raw_obj) { + let obj = Primitive_exceptions.internalToException(raw_obj); + if (obj.RE_EXN_ID === 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: [ + "mocha_full_test.res", + 13182, + 21 + ], + Error: new Error() + }; + } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 13183, + 18 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 13185, + 13 + ], + Error: new Error() + }; + } + } + }); +}); + +Mocha.describe("Error.raise", () => { + Mocha.test("Error.raise", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); + }); +}); + +Mocha.describe("Error.make", () => { + Mocha.test("Error.make", () => { + let error = new Error("Some message here"); + console.log(error.message); + console.log(error.name); + }); +}); + +Mocha.describe("Error.name", () => { + Mocha.test("Error.name", () => { + let error = new SyntaxError("Some message here"); + console.log(error.name); + }); +}); + +Mocha.describe("Error.message", () => { + Mocha.test("Error.message", () => { + let error = new SyntaxError("Some message here"); + console.log(error.message); + }); +}); + +Mocha.describe("Error.stack", () => { + Mocha.test("Error.stack", () => { + let error = new Error("error"); + console.log(error.stack); + }); +}); + +Mocha.describe("Error.toException", () => { + Mocha.test("Error.toException", () => { + new Error("Something went wrong."); + }); +}); + +Mocha.describe("Float.Constants.maxValue", () => { + Mocha.test("Float.Constants.maxValue", () => {}); +}); + +Mocha.describe("Float.Constants.minValue", () => { + Mocha.test("Float.Constants.minValue", () => {}); +}); + +Mocha.describe("Float.Constants.negativeInfinity", () => { + Mocha.test("Float.Constants.negativeInfinity", () => {}); +}); + +Mocha.describe("Float.Constants.positiveInfinity", () => { + Mocha.test("Float.Constants.positiveInfinity", () => {}); +}); + +Mocha.describe("Float.Constants.epsilon", () => { + Mocha.test("Float.Constants.epsilon", () => {}); +}); + +Mocha.describe("Float.Constants.nan", () => { + Mocha.test("Float.Constants.nan", () => {}); +}); + +Mocha.describe("Float.clamp", () => { + Mocha.test("Float.clamp", () => { + Float.clamp(undefined, undefined, 4.2) === 4.2; + Float.clamp(4.3, undefined, 4.2) === 4.3; + Float.clamp(undefined, 4.1, 4.2) === 4.1; + Float.clamp(4.3, 4.1, 4.2) === 4.3; + }); +}); + +Mocha.describe("Float.mod", () => { + Mocha.test("Float.mod", () => {}); +}); + +Mocha.describe("Float.fromInt", () => { + Mocha.test("Float.fromInt", () => {}); +}); + +Mocha.describe("Float.toInt", () => { + Mocha.test("Float.toInt", () => {}); +}); + +Mocha.describe("Float.fromString", () => { + Mocha.test("Float.fromString", () => { + Primitive_object.equal(Float.fromString("0"), 0.0); + Float.fromString("NaN") === undefined; + Primitive_object.equal(Float.fromString("6"), 6.0); + }); +}); + +Mocha.describe("Float.toLocaleString", () => { + Mocha.test("Float.toLocaleString", () => { + (1000.0).toLocaleString(); + (1000.0).toLocaleString(); + }); +}); + +Mocha.describe("Float.toStringWithRadix", () => { + Mocha.test("Float.toStringWithRadix", () => { + (6.0).toString(2); + (3735928559.0).toString(16); + (123456.0).toString(36); + }); +}); + +Mocha.describe("Float.toString", () => { + Mocha.test("Float.toString", () => { + (1000.0).toString(); + (-1000.0).toString(); + }); +}); + +Mocha.describe("Float.toPrecisionWithPrecision", () => { + Mocha.test("Float.toPrecisionWithPrecision", () => { + (100.0).toPrecision(2); + (1.0).toPrecision(1); + }); +}); + +Mocha.describe("Float.toPrecision", () => { + Mocha.test("Float.toPrecision", () => { + (100.0).toPrecision(); + (1.0).toPrecision(); + (100.0).toPrecision(2); + (1.0).toPrecision(1); + }); +}); + +Mocha.describe("Float.toFixedWithPrecision", () => { + Mocha.test("Float.toFixedWithPrecision", () => { + (300.0).toFixed(4); + (300.0).toFixed(1); + }); +}); + +Mocha.describe("Float.toFixed", () => { + Mocha.test("Float.toFixed", () => { + (123456.0).toFixed(); + (10.0).toFixed(); + (300.0).toFixed(4); + (300.0).toFixed(1); + }); +}); + +Mocha.describe("Float.toExponentialWithPrecision", () => { + Mocha.test("Float.toExponentialWithPrecision", () => { + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); +}); + +Mocha.describe("Float.toExponential", () => { + Mocha.test("Float.toExponential", () => { + (1000.0).toExponential(); + (-1000.0).toExponential(); + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); +}); + +Mocha.describe("Float.parseIntWithRadix", () => { + Mocha.test("Float.parseIntWithRadix", () => { + parseInt("10.0", 2); + parseInt("15 * 3", 10); + parseInt("12", 13); + isNaN(parseInt("17", 40)); + }); +}); + +Mocha.describe("Float.parseInt", () => { + Mocha.test("Float.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.describe("Float.parseFloat", () => { + Mocha.test("Float.parseFloat", () => { + parseFloat("1.0"); + parseFloat(" 3.14 "); + parseFloat("3.0"); + parseFloat("3.14some non-digit characters"); + isNaN(parseFloat("error")); + }); +}); + +Mocha.describe("Float.isFinite", () => { + Mocha.test("Float.isFinite", () => { + isFinite(1.0); + isFinite(NaN); + isFinite(Number.POSITIVE_INFINITY); + }); +}); + +Mocha.describe("Float.isNaN", () => { + Mocha.test("Float.isNaN", () => { + isNaN(3.0); + isNaN(NaN); + }); +}); + +Mocha.describe("Int.Bitwise.asr", () => { + Mocha.test("Int.Bitwise.asr", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsr", () => { + Mocha.test("Int.Bitwise.lsr", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsl", () => { + Mocha.test("Int.Bitwise.lsl", () => {}); +}); + +Mocha.describe("Int.Bitwise.lnot", () => { + Mocha.test("Int.Bitwise.lnot", () => { + Int.Bitwise.lnot(2) === -3; + }); +}); + +Mocha.describe("Int.Bitwise.lxor", () => { + Mocha.test("Int.Bitwise.lxor", () => {}); +}); + +Mocha.describe("Int.Bitwise.lor", () => { + Mocha.test("Int.Bitwise.lor", () => {}); +}); + +Mocha.describe("Int.Bitwise.land", () => { + Mocha.test("Int.Bitwise.land", () => {}); +}); + +Mocha.describe("Int.Constants.maxValue", () => { + Mocha.test("Int.Constants.maxValue", () => { + console.log(Int.Constants.maxValue); + }); +}); + +Mocha.describe("Int.Constants.minValue", () => { + Mocha.test("Int.Constants.minValue", () => { + console.log(Int.Constants.minValue); + }); +}); + +Mocha.describe("Int.clamp", () => { + Mocha.test("Int.clamp", () => { + Int.clamp(undefined, undefined, 42) === 42; + Int.clamp(50, undefined, 42) === 50; + Int.clamp(undefined, 40, 42) === 40; + Int.clamp(50, 40, 42) === 50; + }); +}); + +Mocha.describe("Int.rangeWithOptions", () => { + Mocha.test("Int.rangeWithOptions", () => { + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Int.rangeWithOptions(3, 6, { + step: -2 + }); + }); +}); + +Mocha.describe("Int.range", () => { + Mocha.test("Int.range", () => { + Primitive_object.equal(Int.range(3, 6, undefined), [ + 3, + 4, + 5 + ]); + Primitive_object.equal(Int.range(-3, -1, undefined), [ + -3, + -2 + ]); + Primitive_object.equal(Int.range(3, 1, undefined), [ + 3, + 2 + ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Int.range(3, 6, { + step: -2 + }); + }); +}); + +Mocha.describe("Int.mod", () => { + Mocha.test("Int.mod", () => {}); +}); + +Mocha.describe("Int.fromString", () => { + Mocha.test("Int.fromString", () => { + Primitive_object.equal(Int.fromString("0", undefined), 0); + Int.fromString("NaN", undefined) === undefined; + Int.fromString("6", 2) === undefined; + }); +}); + +Mocha.describe("Int.fromFloat", () => { + Mocha.test("Int.fromFloat", () => {}); +}); + +Mocha.describe("Int.toFloat", () => { + Mocha.test("Int.toFloat", () => {}); +}); + +Mocha.describe("Int.toLocaleString", () => { + Mocha.test("Int.toLocaleString", () => { + (1000).toLocaleString(); + (1000).toLocaleString(); + }); +}); + +Mocha.describe("Int.toStringWithRadix", () => { + Mocha.test("Int.toStringWithRadix", () => { + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); +}); + +Mocha.describe("Int.toString", () => { + Mocha.test("Int.toString", () => { + (1000).toString(); + (-1000).toString(); + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); +}); + +Mocha.describe("Int.toPrecisionWithPrecision", () => { + Mocha.test("Int.toPrecisionWithPrecision", () => { + (100).toPrecision(2); + (1).toPrecision(2); + }); +}); + +Mocha.describe("Int.toPrecision", () => { + Mocha.test("Int.toPrecision", () => { + (100).toPrecision(); + (1).toPrecision(); + (100).toPrecision(2); + (1).toPrecision(2); + }); +}); + +Mocha.describe("Int.toFixedWithPrecision", () => { + Mocha.test("Int.toFixedWithPrecision", () => { + (300).toFixed(4); + (300).toFixed(1); + }); +}); + +Mocha.describe("Int.toFixed", () => { + Mocha.test("Int.toFixed", () => { + (123456).toFixed(); + (10).toFixed(); + (300).toFixed(4); + (300).toFixed(1); + }); +}); + +Mocha.describe("Int.toExponentialWithPrecision", () => { + Mocha.test("Int.toExponentialWithPrecision", () => { + (77).toExponential(2); + (5678).toExponential(2); + }); +}); + +Mocha.describe("Int.toExponential", () => { + Mocha.test("Int.toExponential", () => { + (1000).toExponential(); + (-1000).toExponential(); + (77).toExponential(2); + (5678).toExponential(2); + }); +}); + +Mocha.describe("Iterator.forEach", () => { + Mocha.test("Iterator.forEach", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + $$Iterator.forEach(iterator, v => { + if (v === undefined) { + return Pervasives.assertEqual(Option.isNone(v), true); + } + switch (v) { + case "a" : + case "b" : + case "c" : + return; + default: + return Pervasives.assertEqual(Option.isNone(v), true); + } + }); + }); +}); + +Mocha.describe("Iterator.toArrayWithMapper", () => { + Mocha.test("Iterator.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("Iterator.toArray", () => { + Mocha.test("Iterator.toArray", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + let mapKeysAsArray = Array.from(map.keys()); + console.log(mapKeysAsArray); + }); +}); + +Mocha.describe("Iterator.next", () => { + Mocha.test("Iterator.next", () => { + let iterator = ((() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(iterator.next().done, false); + Pervasives.assertEqual(iterator.next().done, true); + }); +}); + +Mocha.describe("JSON.Decode.array", () => { + Mocha.test("JSON.Decode.array", () => { + $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); + $$JSON.Decode.array(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.object", () => { + Mocha.test("JSON.Decode.object", () => { + $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); + $$JSON.Decode.object(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.float", () => { + Mocha.test("JSON.Decode.float", () => { + $$JSON.Decode.float(JSON.parse("42.0")); + $$JSON.Decode.float(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.string", () => { + Mocha.test("JSON.Decode.string", () => { + $$JSON.Decode.string(JSON.parse("\"hello world\"")); + $$JSON.Decode.string(JSON.parse("42")); + }); +}); + +Mocha.describe("JSON.Decode.null", () => { + Mocha.test("JSON.Decode.null", () => { + $$JSON.Decode.$$null(JSON.parse("null")); + $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.bool", () => { + Mocha.test("JSON.Decode.bool", () => { + $$JSON.Decode.bool(JSON.parse("true")); + $$JSON.Decode.bool(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Encode.array", () => { + Mocha.test("JSON.Encode.array", () => {}); +}); + +Mocha.describe("JSON.Encode.object", () => { + Mocha.test("JSON.Encode.object", () => { + Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ] + ]); + }); +}); + +Mocha.describe("JSON.Encode.float", () => { + Mocha.test("JSON.Encode.float", () => {}); +}); + +Mocha.describe("JSON.Encode.int", () => { + Mocha.test("JSON.Encode.int", () => {}); +}); + +Mocha.describe("JSON.Encode.string", () => { + Mocha.test("JSON.Encode.string", () => {}); +}); + +Mocha.describe("JSON.Encode.null", () => { + Mocha.test("JSON.Encode.null", () => {}); +}); + +Mocha.describe("JSON.Encode.bool", () => { + Mocha.test("JSON.Encode.bool", () => {}); +}); + +Mocha.describe("JSON.Classify.classify", () => { + Mocha.test("JSON.Classify.classify", () => { + $$JSON.Classify.classify("hello world"); + $$JSON.Classify.classify(42); + }); +}); + +Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.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: [ + "mocha_full_test.res", + 14064, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithFilter", () => { + Mocha.test("JSON.stringifyAnyWithFilter", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.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: [ + "mocha_full_test.res", + 14088, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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: [ + "mocha_full_test.res", + 14122, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithReplacer", () => { + Mocha.test("JSON.stringifyAnyWithReplacer", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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: [ + "mocha_full_test.res", + 14156, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithIndent", () => { + Mocha.test("JSON.stringifyAnyWithIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.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: [ + "mocha_full_test.res", + 14185, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAny", () => { + Mocha.test("JSON.stringifyAny", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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: [ + "mocha_full_test.res", + 14241, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyWithFilterAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ], 2); + }); +}); + +Mocha.describe("JSON.stringifyWithFilter", () => { + Mocha.test("JSON.stringifyWithFilter", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ]); + }); +}); + +Mocha.describe("JSON.stringifyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer, 2); + }); +}); + +Mocha.describe("JSON.stringifyWithReplacer", () => { + Mocha.test("JSON.stringifyWithReplacer", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); +}); + +Mocha.describe("JSON.stringifyWithIndent", () => { + Mocha.test("JSON.stringifyWithIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, null, 2); + }); +}); + +Mocha.describe("JSON.stringify", () => { + Mocha.test("JSON.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 = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); +}); + +Mocha.describe("JSON.parseExnWithReviver", () => { + Mocha.test("JSON.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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn; + } + } + }); +}); + +Mocha.describe("JSON.parseExn", () => { + Mocha.test("JSON.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 === 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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn$1; + } + } + }); +}); + +Mocha.describe("Map.entries", () => { + Mocha.test("Map.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.describe("Map.values", () => { + Mocha.test("Map.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("Map.keys", () => { + Mocha.test("Map.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.describe("Map.delete", () => { + Mocha.test("Map.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.describe("Map.set", () => { + Mocha.test("Map.set", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); +}); + +Mocha.describe("Map.has", () => { + Mocha.test("Map.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.describe("Map.get", () => { + Mocha.test("Map.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.describe("Map.forEachWithKey", () => { + Mocha.test("Map.forEachWithKey", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach((value, key) => { + console.log(value, key); + }); + }); +}); + +Mocha.describe("Map.forEach", () => { + Mocha.test("Map.forEach", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach(value => { + console.log(value); + }); + }); +}); + +Mocha.describe("Map.clear", () => { + Mocha.test("Map.clear", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.clear(); + }); +}); + +Mocha.describe("Map.size", () => { + Mocha.test("Map.size", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); +}); + +Mocha.describe("Map.fromIterator", () => { + Mocha.test("Map.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(new Map(iterator).size, 2); + }); +}); + +Mocha.describe("Map.fromArray", () => { + Mocha.test("Map.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.describe("Map.make", () => { + Mocha.test("Map.make", () => { + new Map(); + let map = new Map(); + map.set("lang", "ReScript"); + }); +}); + +Mocha.describe("Null.flatMap", () => { + Mocha.test("Null.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Null.flatMap(2, addIfAboveOne); + Null.flatMap(-4, addIfAboveOne); + Null.flatMap(null, addIfAboveOne); + }); +}); + +Mocha.describe("Null.mapOr", () => { + Mocha.test("Null.mapOr", () => { + Null.mapOr(3, 0, x => x + 5 | 0); + Null.mapOr(null, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("Null.map", () => { + Mocha.test("Null.map", () => { + Null.map(3, x => Math.imul(x, x)); + Null.map(null, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Null.forEach", () => { + Mocha.test("Null.forEach", () => { + Null.forEach("thing", x => { + console.log(x); + }); + Null.forEach(null, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Null.getUnsafe", () => { + Mocha.test("Null.getUnsafe", () => {}); +}); + +Mocha.describe("Null.getExn", () => { + Mocha.test("Null.getExn", () => { + Pervasives.assertEqual(Null.getExn(3), 3); + let exit = 0; + let value; + try { + value = 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: [ + "mocha_full_test.res", + 14766, + 41 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "ReScript"); + } + let exit$1 = 0; + let val; + try { + val = 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: [ + "mocha_full_test.res", + 14772, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Null.getOr", () => { + Mocha.test("Null.getOr", () => { + Null.getOr(null, "Banana"); + Null.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNull("Jane")); + greet(undefined); + }); +}); + +Mocha.describe("Null.fromOption", () => { + Mocha.test("Null.fromOption", () => { + let asNull = Null.fromOption(undefined); + console.log(asNull === null); + }); +}); + +Mocha.describe("Null.toOption", () => { + Mocha.test("Null.toOption", () => { + let nullStr = "Hello"; + if (nullStr !== null) { + console.log("Got string:", nullStr); + } else { + console.log("Didn't have a value."); + } + }); +}); + +Mocha.describe("Null.make", () => { + Mocha.test("Null.make", () => {}); +}); + +Mocha.describe("Null.null", () => { + Mocha.test("Null.null", () => { + console.log(null); + }); +}); + +Mocha.describe("Null.asNullable", () => { + Mocha.test("Null.asNullable", () => {}); +}); + +Mocha.describe("List.sort", () => { + Mocha.test("List.sort", () => { + List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } + } + }, Primitive_int.compare); + }); +}); + +Mocha.describe("List.setAssoc", () => { + Mocha.test("List.setAssoc", () => { + List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); +}); + +Mocha.describe("List.removeAssoc", () => { + Mocha.test("List.removeAssoc", () => { + List.removeAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + List.removeAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); + }); +}); + +Mocha.describe("List.hasAssoc", () => { + Mocha.test("List.hasAssoc", () => { + List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); + }); +}); + +Mocha.describe("List.getAssoc", () => { + Mocha.test("List.getAssoc", () => { + List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); + }); +}); + +Mocha.describe("List.unzip", () => { + Mocha.test("List.unzip", () => { + List.unzip({ + hd: [ + 1, + 2 + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + 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.describe("List.partition", () => { + Mocha.test("List.partition", () => { + List.partition({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => x > 2); + }); +}); + +Mocha.describe("List.filterMap", () => { + Mocha.test("List.filterMap", () => { + let isEven = x => x % 2 === 0; + List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => { + if (isEven(x)) { + return x; + } + + }); + List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); + }); +}); + +Mocha.describe("List.filterWithIndex", () => { + Mocha.test("List.filterWithIndex", () => { + List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("List.filter", () => { + Mocha.test("List.filter", () => { + let isEven = x => x % 2 === 0; + List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Option.isSome); + }); +}); + +Mocha.describe("List.find", () => { + Mocha.test("List.find", () => { + List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 3); + List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); +}); + +Mocha.describe("List.has", () => { + Mocha.test("List.has", () => { + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2, (a, b) => a === b); + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); +}); + +Mocha.describe("List.equal", () => { + Mocha.test("List.equal", () => { + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + 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.describe("List.compare", () => { + Mocha.test("List.compare", () => { + List.compare({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + List.compare({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + 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); + 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); + 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.describe("List.compareLength", () => { + Mocha.test("List.compareLength", () => { + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.some2", () => { + Mocha.test("List.some2", () => { + List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); +}); + +Mocha.describe("List.every2", () => { + Mocha.test("List.every2", () => { + List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); +}); + +Mocha.describe("List.some", () => { + Mocha.test("List.some", () => { + let isAbove100 = value => value > 100; + List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + List.some({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isAbove100); + }); +}); + +Mocha.describe("List.every", () => { + Mocha.test("List.every", () => { + let isBelow10 = value => value < 10; + List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + }); +}); + +Mocha.describe("List.reduceReverse2", () => { + Mocha.test("List.reduceReverse2", () => { + List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("List.reduce2", () => { + Mocha.test("List.reduce2", () => { + List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("List.forEach2", () => { + Mocha.test("List.forEach2", () => { + 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.describe("List.mapReverse2", () => { + Mocha.test("List.mapReverse2", () => { + 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.describe("List.reduceReverse", () => { + Mocha.test("List.reduceReverse", () => { + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, List.add); + }); +}); + +Mocha.describe("List.reduceWithIndex", () => { + Mocha.test("List.reduceWithIndex", () => { + 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.describe("List.reduce", () => { + Mocha.test("List.reduce", () => { + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); + }); +}); + +Mocha.describe("List.forEachWithIndex", () => { + Mocha.test("List.forEachWithIndex", () => { + List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (x, index) => { + console.log("Item " + index.toString() + " is " + x); + }); + }); +}); + +Mocha.describe("List.forEach", () => { + Mocha.test("List.forEach", () => { + List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); +}); + +Mocha.describe("List.mapReverse", () => { + Mocha.test("List.mapReverse", () => { + let f = x => Math.imul(x, x); + let l = { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }; + let withMap = List.reverse(List.map(l, f)); + let withMapReverse = List.mapReverse(l, f); + console.log(Primitive_object.equal(withMap, withMapReverse)); + }); +}); + +Mocha.describe("List.reverse", () => { + Mocha.test("List.reverse", () => { + List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.toArray", () => { + Mocha.test("List.toArray", () => { + List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.fromArray", () => { + Mocha.test("List.fromArray", () => { + List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("List.mapWithIndex", () => { + Mocha.test("List.mapWithIndex", () => { + List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (x, index) => index + x | 0); + }); +}); + +Mocha.describe("List.zipBy", () => { + Mocha.test("List.zipBy", () => { + 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("List.zip", () => { + Mocha.test("List.zip", () => { + List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.map", () => { + Mocha.test("List.map", () => { + List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); +}); + +Mocha.describe("List.flat", () => { + Mocha.test("List.flat", () => { + 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.describe("List.reverseConcat", () => { + Mocha.test("List.reverseConcat", () => { + List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.concatMany", () => { + Mocha.test("List.concatMany", () => { + List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); +}); + +Mocha.describe("List.concat", () => { + Mocha.test("List.concat", () => { + List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.splitAt", () => { + Mocha.test("List.splitAt", () => { + List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); + }); +}); + +Mocha.describe("List.take", () => { + Mocha.test("List.take", () => { + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); +}); + +Mocha.describe("List.drop", () => { + Mocha.test("List.drop", () => { + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 3); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); +}); + +Mocha.describe("List.toShuffled", () => { + Mocha.test("List.toShuffled", () => { + List.toShuffled({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.fromInitializer", () => { + Mocha.test("List.fromInitializer", () => { + List.fromInitializer(5, i => i); + List.fromInitializer(5, i => Math.imul(i, i)); + }); +}); + +Mocha.describe("List.make", () => { + Mocha.test("List.make", () => { + List.make(3, 1); + }); +}); + +Mocha.describe("List.getExn", () => { + Mocha.test("List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.assertEqual(List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = 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: [ + "mocha_full_test.res", + 15409, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("List.get", () => { + Mocha.test("List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + List.get(abc, 1); + List.get(abc, 4); + }); +}); + +Mocha.describe("List.add", () => { + Mocha.test("List.add", () => { + List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("List.tailExn", () => { + Mocha.test("List.tailExn", () => { + Pervasives.assertEqual(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 = 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: [ + "mocha_full_test.res", + 15447, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("List.tail", () => { + Mocha.test("List.tail", () => { + List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + List.tail(/* [] */0); + }); +}); + +Mocha.describe("List.headExn", () => { + Mocha.test("List.headExn", () => { + Pervasives.assertEqual(List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = 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: [ + "mocha_full_test.res", + 15472, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("List.head", () => { + Mocha.test("List.head", () => { + List.head(/* [] */0); + List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.size", () => { + Mocha.test("List.size", () => { + List.size({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.length", () => { + Mocha.test("List.length", () => { + List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Math.Int.random", () => { + Mocha.test("Math.Int.random", () => { + $$Math.Int.random(2, 5) === 4; + $$Math.Int.random(505, 2000) === 1276; + $$Math.Int.random(-7, -2) === -4; + }); +}); + +Mocha.describe("Math.Int.ceil", () => { + Mocha.test("Math.Int.ceil", () => { + $$Math.Int.ceil(3.7) === 4; + $$Math.Int.ceil(3.0) === 3; + $$Math.Int.ceil(-3.1) === -3; + }); +}); + +Mocha.describe("Math.Int.floor", () => { + Mocha.test("Math.Int.floor", () => { + $$Math.Int.floor(3.7) === 3; + $$Math.Int.floor(3.0) === 3; + $$Math.Int.floor(-3.1) === -4; + }); +}); + +Mocha.describe("Math.Int.sign", () => { + Mocha.test("Math.Int.sign", () => { + Math.sign(3); + Math.sign(-3); + Math.sign(0); + }); +}); + +Mocha.describe("Math.Int.pow", () => { + Mocha.test("Math.Int.pow", () => { + Math.pow(2, 4); + Math.pow(3, 4); + }); +}); + +Mocha.describe("Math.Int.maxMany", () => { + Mocha.test("Math.Int.maxMany", () => { + Math.max(1, 2); + Math.max(-1, -2); + isFinite(Math.max()); + }); +}); + +Mocha.describe("Math.Int.max", () => { + Mocha.test("Math.Int.max", () => { + Math.max(1, 2); + Math.max(-1, -2); + }); +}); + +Mocha.describe("Math.Int.minMany", () => { + Mocha.test("Math.Int.minMany", () => { + Math.min(1, 2); + Math.min(-1, -2); + isFinite(Math.min()); + }); +}); + +Mocha.describe("Math.Int.min", () => { + Mocha.test("Math.Int.min", () => { + Math.min(1, 2); + Math.min(-1, -2); + }); +}); + +Mocha.describe("Math.Int.imul", () => { + Mocha.test("Math.Int.imul", () => { + Math.imul(3, 4); + Math.imul(-5, 12); + }); +}); + +Mocha.describe("Math.Int.clz32", () => { + Mocha.test("Math.Int.clz32", () => { + Math.clz32(1); + Math.clz32(4); + }); +}); + +Mocha.describe("Math.Int.abs", () => { + Mocha.test("Math.Int.abs", () => { + Math.abs(-2); + Math.abs(3); + }); +}); + +Mocha.describe("Math.Constants.sqrt2", () => { + Mocha.test("Math.Constants.sqrt2", () => {}); +}); + +Mocha.describe("Math.Constants.sqrt1_2", () => { + Mocha.test("Math.Constants.sqrt1_2", () => {}); +}); + +Mocha.describe("Math.Constants.pi", () => { + Mocha.test("Math.Constants.pi", () => {}); +}); + +Mocha.describe("Math.Constants.log10e", () => { + Mocha.test("Math.Constants.log10e", () => {}); +}); + +Mocha.describe("Math.Constants.log2e", () => { + Mocha.test("Math.Constants.log2e", () => {}); +}); + +Mocha.describe("Math.Constants.ln10", () => { + Mocha.test("Math.Constants.ln10", () => {}); +}); + +Mocha.describe("Math.Constants.ln2", () => { + Mocha.test("Math.Constants.ln2", () => {}); +}); + +Mocha.describe("Math.Constants.e", () => { + Mocha.test("Math.Constants.e", () => {}); +}); + +Mocha.describe("Math.trunc", () => { + Mocha.test("Math.trunc", () => { + Math.trunc(0.123); + Math.trunc(1.999); + Math.trunc(13.37); + Math.trunc(42.84); + }); +}); + +Mocha.describe("Math.tanh", () => { + Mocha.test("Math.tanh", () => { + Math.tanh(-0.0); + Math.tanh(0.0); + Math.tanh(1.0); + }); +}); + +Mocha.describe("Math.tan", () => { + Mocha.test("Math.tan", () => { + Math.tan(-0.0); + Math.tan(0.0); + Math.tan(1.0); + }); +}); + +Mocha.describe("Math.sqrt", () => { + Mocha.test("Math.sqrt", () => { + isNaN(Math.sqrt(-1.0)); + Math.sqrt(-0.0); + Math.sqrt(0.0); + Math.sqrt(1.0); + Math.sqrt(9.0); + }); +}); + +Mocha.describe("Math.sinh", () => { + Mocha.test("Math.sinh", () => { + Math.sinh(-0.0); + Math.sinh(0.0); + Math.sinh(1.0); + }); +}); + +Mocha.describe("Math.sin", () => { + Mocha.test("Math.sin", () => { + Math.sin(-0.0); + Math.sin(0.0); + Math.sin(1.0); + }); +}); + +Mocha.describe("Math.sign", () => { + Mocha.test("Math.sign", () => { + Math.sign(3.0); + Math.sign(-3.0); + Math.sign(0.0); + }); +}); + +Mocha.describe("Math.round", () => { + Mocha.test("Math.round", () => { + Math.round(-20.5); + Math.round(-0.1); + Math.round(0.0); + Math.round(-0.0); + }); +}); + +Mocha.describe("Math.random", () => { + Mocha.test("Math.random", () => { + Math.random(); + }); +}); + +Mocha.describe("Math.pow", () => { + Mocha.test("Math.pow", () => { + Math.pow(2.0, 4.0); + Math.pow(3.0, 4.0); + }); +}); + +Mocha.describe("Math.maxMany", () => { + Mocha.test("Math.maxMany", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + isFinite(Math.max()); + }); +}); + +Mocha.describe("Math.max", () => { + Mocha.test("Math.max", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + }); +}); + +Mocha.describe("Math.minMany", () => { + Mocha.test("Math.minMany", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + isFinite(Math.min()); + }); +}); + +Mocha.describe("Math.min", () => { + Mocha.test("Math.min", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + }); +}); + +Mocha.describe("Math.log2", () => { + Mocha.test("Math.log2", () => { + isNaN(Math.log2(-2.0)); + isFinite(Math.log2(-0.0)); + isFinite(Math.log2(0.0)); + Math.log2(1.0); + }); +}); + +Mocha.describe("Math.log10", () => { + Mocha.test("Math.log10", () => { + isNaN(Math.log10(-2.0)); + isFinite(Math.log10(-0.0)); + isFinite(Math.log10(0.0)); + Math.log10(1.0); + }); +}); + +Mocha.describe("Math.log1p", () => { + Mocha.test("Math.log1p", () => { + isNaN(Math.log1p(-2.0)); + isFinite(Math.log1p(-1.0)); + Math.log1p(-0.0); + }); +}); + +Mocha.describe("Math.log", () => { + Mocha.test("Math.log", () => { + isNaN(Math.log(-1.0)); + isFinite(Math.log(-0.0)); + isFinite(Math.log(0.0)); + Math.log(1.0); + }); +}); + +Mocha.describe("Math.hypotMany", () => { + Mocha.test("Math.hypotMany", () => { + Math.hypot(3.0, 4.0, 5.0); + Math.hypot(); + }); +}); + +Mocha.describe("Math.hypot", () => { + Mocha.test("Math.hypot", () => { + Math.hypot(3.0, 4.0); + Math.hypot(3.0, 5.0); + }); +}); + +Mocha.describe("Math.fround", () => { + Mocha.test("Math.fround", () => { + Math.fround(5.5) === 5.5; + Math.fround(5.05) === 5.050000190734863; + }); +}); + +Mocha.describe("Math.floor", () => { + Mocha.test("Math.floor", () => { + Math.floor(-45.95); + Math.floor(-45.05); + Math.floor(-0.0); + }); +}); + +Mocha.describe("Math.expm1", () => { + Mocha.test("Math.expm1", () => { + Math.expm1(-1.0); + Math.expm1(-0.0); + }); +}); + +Mocha.describe("Math.exp", () => { + Mocha.test("Math.exp", () => { + Math.exp(-1.0); + Math.exp(0.0); + }); +}); + +Mocha.describe("Math.cosh", () => { + Mocha.test("Math.cosh", () => { + Math.cosh(-1.0); + Math.cosh(-0.0); + Math.cosh(0.0); + }); +}); + +Mocha.describe("Math.cos", () => { + Mocha.test("Math.cos", () => { + Math.cos(-0.0); + Math.cos(0.0); + Math.cos(1.0); + }); +}); + +Mocha.describe("Math.ceil", () => { + Mocha.test("Math.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.describe("Math.cbrt", () => { + Mocha.test("Math.cbrt", () => { + Math.cbrt(-1.0); + Math.cbrt(-0.0); + Math.cbrt(0.0); + }); +}); + +Mocha.describe("Math.atan2", () => { + Mocha.test("Math.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.describe("Math.atanh", () => { + Mocha.test("Math.atanh", () => { + isNaN(Math.atanh(-2.0)); + isFinite(Math.atanh(-1.0)); + Math.atanh(-0.0); + Math.atanh(0.0); + Math.atanh(0.5); + }); +}); + +Mocha.describe("Math.atan", () => { + Mocha.test("Math.atan", () => { + Math.atan(-0.0); + Math.atan(0.0); + Math.atan(1.0); + }); +}); + +Mocha.describe("Math.asinh", () => { + Mocha.test("Math.asinh", () => { + Math.asinh(-1.0); + Math.asinh(-0.0); + }); +}); + +Mocha.describe("Math.asin", () => { + Mocha.test("Math.asin", () => { + Math.asin(-1.0); + isNaN(Math.asin(-2.0)); + }); +}); + +Mocha.describe("Math.acosh", () => { + Mocha.test("Math.acosh", () => { + Math.acosh(1.0); + isNaN(Math.acosh(0.5)); + }); +}); + +Mocha.describe("Math.acos", () => { + Mocha.test("Math.acos", () => { + Math.acos(-1.0); + isNaN(Math.acos(-3.0)); + }); +}); + +Mocha.describe("Math.abs", () => { + Mocha.test("Math.abs", () => { + Math.abs(-2.0); + Math.abs(3.0); + }); +}); + +Mocha.describe("Nullable.flatMap", () => { + Mocha.test("Nullable.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Nullable.flatMap(2, addIfAboveOne); + Nullable.flatMap(-4, addIfAboveOne); + Nullable.flatMap(null, addIfAboveOne); + }); +}); + +Mocha.describe("Nullable.mapOr", () => { + Mocha.test("Nullable.mapOr", () => { + Nullable.mapOr(3, 0, x => x + 5 | 0); + Nullable.mapOr(null, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("Nullable.map", () => { + Mocha.test("Nullable.map", () => { + Nullable.map(3, x => Math.imul(x, x)); + Nullable.map(undefined, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Nullable.forEach", () => { + Mocha.test("Nullable.forEach", () => { + Nullable.forEach("thing", x => { + console.log(x); + }); + Nullable.forEach(null, x => { + console.log(x); + }); + Nullable.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Nullable.getUnsafe", () => { + Mocha.test("Nullable.getUnsafe", () => {}); +}); + +Mocha.describe("Nullable.getExn", () => { + Mocha.test("Nullable.getExn", () => { + let exit = 0; + let value; + try { + value = 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: [ + "mocha_full_test.res", + 16165, + 41 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "Hello"); + } + let exit$1 = 0; + let val; + try { + val = 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: [ + "mocha_full_test.res", + 16171, + 13 + ], + Error: new Error() + }; + } + let exit$2 = 0; + let val$1; + try { + val$1 = 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: [ + "mocha_full_test.res", + 16176, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Nullable.getOr", () => { + Mocha.test("Nullable.getOr", () => { + Nullable.getOr(null, "Banana"); + Nullable.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNullable("Jane")); + greet(undefined); + }); +}); + +Mocha.describe("Nullable.fromOption", () => { + Mocha.test("Nullable.fromOption", () => { + Nullable.fromOption("Hello"); + }); +}); + +Mocha.describe("Nullable.toOption", () => { + Mocha.test("Nullable.toOption", () => { + let nullableString = "Hello"; + if (nullableString == null) { + console.log("Didn't have a value."); + } else { + console.log("Got string:", nullableString); + } + }); +}); + +Mocha.describe("Nullable.make", () => { + Mocha.test("Nullable.make", () => { + let myStr = "Hello"; + if ((myStr == null) || myStr !== myStr) { + console.log("Values did not match."); + } else { + console.log("Yay, values matched!"); + } + }); +}); + +Mocha.describe("Nullable.isNullable", () => { + Mocha.test("Nullable.isNullable", () => { + if ("Hello" == null) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16253, + 16 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Nullable.undefined", () => { + Mocha.test("Nullable.undefined", () => { + console.log(undefined); + }); +}); + +Mocha.describe("Nullable.null", () => { + Mocha.test("Nullable.null", () => { + console.log(null); + }); +}); + +Mocha.describe("Object.isExtensible", () => { + Mocha.test("Object.isExtensible", () => { + let obj = { + a: 1 + }; + Object.isExtensible(obj); + Object.preventExtensions(obj); + Object.isExtensible(obj); + }); +}); + +Mocha.describe("Object.isFrozen", () => { + Mocha.test("Object.isFrozen", () => { + let point = Object.freeze({ + x: 1, + y: 3 + }); + Object.isFrozen(point); + let fruit = { + name: "Apple" + }; + Object.isFrozen(fruit); + }); +}); + +Mocha.describe("Object.isSealed", () => { + Mocha.test("Object.isSealed", () => { + let point = Object.seal({ + x: 1, + y: 3 + }); + Object.isSealed(point); + let fruit = { + name: "Apple" + }; + Object.isSealed(fruit); + }); +}); + +Mocha.describe("Object.freeze", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16326, + 13 + ], + Error: new Error() + }; + } + + } + }); +}); + +Mocha.describe("Object.preventExtensions", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16343, + 13 + ], + Error: new Error() + }; + } + + } + }); +}); + +Mocha.describe("Object.seal", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16361, + 13 + ], + Error: new Error() + }; + } + + } + point["x"] = 13; + }); +}); + +Mocha.describe("Object.hasOwnProperty", () => { + Mocha.test("Object.hasOwnProperty", () => { + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "a"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "b"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "toString"); + }); +}); + +Mocha.describe("Object.keysToArray", () => { + Mocha.test("Object.keysToArray", () => { + Object.keys({ + a: 1, + b: 2 + }); + Object.keys({ + a: undefined + }); + Object.keys({}); + }); +}); + +Mocha.describe("Object.set", () => { + Mocha.test("Object.set", () => { + ({ + a: 1 + })["a"] = 2; + ({ + a: 1 + })["a"] = undefined; + ({ + a: 1 + })["b"] = 2; + }); +}); + +Mocha.describe("Object.getSymbol", () => { + Mocha.test("Object.getSymbol", () => { + let fruit = Symbol("fruit"); + let x = {}; + x[fruit] = "banana"; + }); +}); + +Mocha.describe("Object.get", () => { + Mocha.test("Object.get", () => { + Option.isSome(({ + a: 1 + })["toString"]); + }); +}); + +Mocha.describe("Object.assign", () => { + Mocha.test("Object.assign", () => { + Object.assign({ + a: 1 + }, { + a: 2 + }); + Object.assign({ + a: 1, + b: 2 + }, { + a: 0 + }); + Object.assign({ + a: 1 + }, { + a: null + }); + }); +}); + +Mocha.describe("Object.create", () => { + Mocha.test("Object.create", () => { + let x = { + fruit: "banana" + }; + Object.create(x); + }); +}); + +Mocha.describe("Object.is", () => { + Mocha.test("Object.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.describe("Object.make", () => { + Mocha.test("Object.make", () => { + let x = {}; + Object.keys(x).length; + Option.isSome(x["toString"]); + }); +}); + +Mocha.describe("Pervasives.assertEqual", () => { + Mocha.test("Pervasives.assertEqual", () => { + Pervasives.assertEqual(List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }), { + hd: 2, + tl: /* [] */0 + }); + }); +}); + +Mocha.describe("Pervasives.import", () => { + Mocha.test("Pervasives.import", () => {}); +}); + +Mocha.describe("Pervasives.decodeURIComponent", () => { + Mocha.test("Pervasives.decodeURIComponent", () => { + console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); + }); +}); + +Mocha.describe("Pervasives.encodeURIComponent", () => { + Mocha.test("Pervasives.encodeURIComponent", () => { + console.log(encodeURIComponent("array=[someValue]")); + }); +}); + +Mocha.describe("Pervasives.decodeURI", () => { + Mocha.test("Pervasives.decodeURI", () => { + console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); + }); +}); + +Mocha.describe("Pervasives.encodeURI", () => { + Mocha.test("Pervasives.encodeURI", () => { + console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); + }); +}); + +Mocha.describe("Pervasives.clearInterval", () => { + Mocha.test("Pervasives.clearInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints in 100 ms"); + }, 100); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); +}); + +Mocha.describe("Pervasives.setIntervalFloat", () => { + Mocha.test("Pervasives.setIntervalFloat", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms"); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500.0); + }); +}); + +Mocha.describe("Pervasives.setInterval", () => { + Mocha.test("Pervasives.setInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms."); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); +}); + +Mocha.describe("Pervasives.clearTimeout", () => { + Mocha.test("Pervasives.clearTimeout", () => { + let timeoutId = setTimeout(() => { + console.log("This prints in 2 seconds."); + }, 2000); + clearTimeout(timeoutId); + }); +}); + +Mocha.describe("Pervasives.setTimeoutFloat", () => { + Mocha.test("Pervasives.setTimeoutFloat", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); +}); + +Mocha.describe("Pervasives.setTimeout", () => { + Mocha.test("Pervasives.setTimeout", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); +}); + +Mocha.describe("Option.all", () => { + Mocha.test("Option.all", () => { + Option.all([ + 1, + 2, + 3 + ]); + Option.all([ + 1, + undefined + ]); + }); +}); + +Mocha.describe("Option.compare", () => { + Mocha.test("Option.compare", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Option.compare(3, 15, clockCompare); + Option.compare(3, 14, clockCompare); + Option.compare(2, 15, clockCompare); + Option.compare(undefined, 15, clockCompare); + Option.compare(14, undefined, clockCompare); + Option.compare(undefined, undefined, clockCompare); + }); +}); + +Mocha.describe("Option.equal", () => { + Mocha.test("Option.equal", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Option.equal(3, 15, clockEqual); + Option.equal(3, undefined, clockEqual); + Option.equal(undefined, 3, clockEqual); + Option.equal(undefined, undefined, clockEqual); + }); +}); + +Mocha.describe("Option.isNone", () => { + Mocha.test("Option.isNone", () => { + Option.isNone(undefined); + Option.isNone(1); + }); +}); + +Mocha.describe("Option.isSome", () => { + Mocha.test("Option.isSome", () => { + Option.isSome(undefined); + Option.isSome(1); + }); +}); + +Mocha.describe("Option.orElse", () => { + Mocha.test("Option.orElse", () => { + Primitive_object.equal(Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Option.orElse(undefined, 1066), 1066); + Option.orElse(undefined, undefined) === undefined; + }); +}); + +Mocha.describe("Option.getOr", () => { + Mocha.test("Option.getOr", () => { + Option.getOr(undefined, "Banana"); + Option.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); + }); +}); + +Mocha.describe("Option.flatMap", () => { + Mocha.test("Option.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + + }; + Option.flatMap(2, addIfAboveOne); + Option.flatMap(-4, addIfAboveOne); + Option.flatMap(undefined, addIfAboveOne); + }); +}); + +Mocha.describe("Option.map", () => { + Mocha.test("Option.map", () => { + Option.map(3, x => Math.imul(x, x)); + Option.map(undefined, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Option.mapOr", () => { + Mocha.test("Option.mapOr", () => { + Option.mapOr(3, 0, x => x + 5 | 0); + Option.mapOr(undefined, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("Option.getUnsafe", () => { + Mocha.test("Option.getUnsafe", () => {}); +}); + +Mocha.describe("Option.getExn", () => { + Mocha.test("Option.getExn", () => { + Pervasives.assertEqual(Option.getExn(3, undefined), 3); + let exit = 0; + let val; + try { + val = Option.getExn(undefined, undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16819, + 13 + ], + Error: new Error() + }; + } + let exit$1 = 0; + let val$1; + try { + val$1 = Option.getExn(undefined, "was None!"); + exit$1 = 1; + } catch (exn$1) { + + } + if (exit$1 === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 16824, + 13 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Option.forEach", () => { + Mocha.test("Option.forEach", () => { + Option.forEach("thing", x => { + console.log(x); + }); + Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Option.filter", () => { + Mocha.test("Option.filter", () => { + Option.filter(10, x => x > 5); + Option.filter(4, x => x > 5); + Option.filter(undefined, x => x > 5); + }); +}); + +Mocha.describe("RegExp.Result.input", () => { + Mocha.test("RegExp.Result.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.describe("RegExp.Result.matches", () => { + Mocha.test("RegExp.Result.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("RegExp.Result.fullMatch", () => { + Mocha.test("RegExp.Result.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.describe("RegExp.unicode", () => { + Mocha.test("RegExp.unicode", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "mu"); + console.log(regexp2.unicode); + }); +}); + +Mocha.describe("RegExp.sticky", () => { + Mocha.test("RegExp.sticky", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "my"); + console.log(regexp2.unicode); + }); +}); + +Mocha.describe("RegExp.source", () => { + Mocha.test("RegExp.source", () => { + let regexp = new RegExp("\\w+", "g"); + console.log(regexp.source); + }); +}); + +Mocha.describe("RegExp.multiline", () => { + Mocha.test("RegExp.multiline", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.multiline); + let regexp2 = new RegExp("\\w+", "mi"); + console.log(regexp2.multiline); + }); +}); + +Mocha.describe("RegExp.global", () => { + Mocha.test("RegExp.global", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.global); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.global); + }); +}); + +Mocha.describe("RegExp.ignoreCase", () => { + Mocha.test("RegExp.ignoreCase", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.ignoreCase); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.ignoreCase); + }); +}); + +Mocha.describe("RegExp.setLastIndex", () => { + Mocha.test("RegExp.setLastIndex", () => { + let regexp = new RegExp("\\w+"); + regexp.lastIndex = 4; + regexp.exec("Many words here."); + console.log(regexp.lastIndex); + }); +}); + +Mocha.describe("RegExp.lastIndex", () => { + Mocha.test("RegExp.lastIndex", () => { + let regexp = new RegExp("\\w+"); + console.log(regexp.lastIndex); + regexp.exec("Many words here."); + console.log(regexp.lastIndex); + }); +}); + +Mocha.describe("RegExp.exec", () => { + Mocha.test("RegExp.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.describe("RegExp.test", () => { + Mocha.test("RegExp.test", () => { + let regexp = new RegExp("\\w+"); + if (regexp.test("ReScript is cool!")) { + console.log("Yay, there's a word in there."); + } + + }); +}); + +Mocha.describe("RegExp.fromStringWithFlags", () => { + Mocha.test("RegExp.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.describe("RegExp.fromString", () => { + Mocha.test("RegExp.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.describe("Result.all", () => { + Mocha.test("Result.all", () => { + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Ok", + _0: 2 + }, + { + TAG: "Ok", + _0: 3 + } + ]); + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Error", + _0: 1 + } + ]); + }); +}); + +Mocha.describe("Result.mapError", () => { + Mocha.test("Result.mapError", () => { + let format = n => "Error code: " + n.toString(); + Result.mapError({ + TAG: "Error", + _0: 14 + }, format); + Result.mapError({ + TAG: "Ok", + _0: "abc" + }, format); + }); +}); + +Mocha.describe("Result.forEach", () => { + Mocha.test("Result.forEach", () => { + Result.forEach({ + TAG: "Ok", + _0: 3 + }, prim => { + console.log(prim); + }); + Result.forEach({ + TAG: "Error", + _0: "x" + }, prim => { + console.log(prim); + }); + }); +}); + +Mocha.describe("Result.compare", () => { + Mocha.test("Result.compare", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Result.compare({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; + }); +}); + +Mocha.describe("Result.equal", () => { + Mocha.test("Result.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; + Result.equal(good1, good2, mod10equal) === true; + Result.equal(good1, bad1, mod10equal) === false; + Result.equal(bad2, good2, mod10equal) === false; + Result.equal(bad1, bad2, mod10equal) === true; + }); +}); + +Mocha.describe("Result.getOr", () => { + Mocha.test("Result.getOr", () => { + Result.getOr({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Result.getOr({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; + }); +}); + +Mocha.describe("Result.flatMap", () => { + Mocha.test("Result.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(Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 + }); + Primitive_object.equal(Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" + }); + }); +}); + +Mocha.describe("Result.map", () => { + Mocha.test("Result.map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); + }); +}); + +Mocha.describe("Result.mapOr", () => { + Mocha.test("Result.mapOr", () => { + Result.mapOr({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Result.mapOr({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; + }); +}); + +Mocha.describe("Promise.allSettled", () => { + Mocha.test("Promise.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.describe("Promise.all", () => { + Mocha.test("Promise.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.describe("Promise.any", () => { + Mocha.test("Promise.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.describe("Promise.race", () => { + Mocha.test("Promise.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.describe("Promise.finally", () => { + Mocha.test("Promise.finally", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + let isDone = { + contents: false + }; + $$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.describe("Promise.thenResolve", () => { + Mocha.test("Promise.thenResolve", () => { + Promise.resolve("Anna").then(str => "Hello " + str).then(str => { + console.log(str); + }); + }); +}); + +Mocha.describe("Promise.then", () => { + Mocha.test("Promise.then", () => { + Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { + console.log("Your lucky number is: ", num); + return Promise.resolve(); + }); + }); +}); + +Mocha.describe("Promise.catch", () => { + Mocha.test("Promise.catch", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + $$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 === 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.describe("Promise.make", () => { + Mocha.test("Promise.make", () => { + $$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.describe("Promise.reject", () => { + Mocha.test("Promise.reject", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + $$Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }), v => { + if (v.RE_EXN_ID === TestError) { + Pervasives.assertEqual(v._1, "some rejected value"); + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 17495, + 17 + ], + Error: new Error() + }; + } + return Promise.resolve(); + }); + }); +}); + +Mocha.describe("Promise.resolve", () => { + Mocha.test("Promise.resolve", () => { + Promise.resolve(5); + }); +}); + +Mocha.describe("Set.toArray", () => { + Mocha.test("Set.toArray", () => { + let set = new Set([ + "apple", + "orange", + "apple", + "banana" + ]); + Array.from(set); + }); +}); + +Mocha.describe("Set.values", () => { + Mocha.test("Set.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("Set.forEach", () => { + Mocha.test("Set.forEach", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue2"); + set.forEach(value => { + console.log(value); + }); + }); +}); + +Mocha.describe("Set.has", () => { + Mocha.test("Set.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.describe("Set.delete", () => { + Mocha.test("Set.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.describe("Set.add", () => { + Mocha.test("Set.add", () => { + let set = new Set(); + set.add("someValue"); + }); +}); + +Mocha.describe("Set.clear", () => { + Mocha.test("Set.clear", () => { + let set = new Set(); + set.add("someKey"); + set.clear(); + }); +}); + +Mocha.describe("Set.size", () => { + Mocha.test("Set.size", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue"); + set.add("someValue2"); + }); +}); + +Mocha.describe("Set.fromIterator", () => { + Mocha.test("Set.fromIterator", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(new Set(iterator).size, 3); + }); +}); + +Mocha.describe("Set.fromArray", () => { + Mocha.test("Set.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.describe("Set.make", () => { + Mocha.test("Set.make", () => { + new Set(); + let set = new Set(); + set.add("Fine name"); + }); +}); + +Mocha.describe("String.localeCompare", () => { + Mocha.test("String.localeCompare", () => { + "a".localeCompare("c") < 0.0 === true; + "a".localeCompare("a") === 0.0; + }); +}); + +Mocha.describe("String.padEnd", () => { + Mocha.test("String.padEnd", () => { + "Hello".padEnd(10, ".") === "Hello....."; + "abc".padEnd(1, "") === "abc"; + }); +}); + +Mocha.describe("String.padStart", () => { + Mocha.test("String.padStart", () => { + "abc".padStart(5, " ") === " abc"; + "abc".padStart(6, "123465") === "123abc"; + }); +}); + +Mocha.describe("String.trimEnd", () => { + Mocha.test("String.trimEnd", () => { + " Hello world! ".trimEnd() === " Hello world!"; + " Hello world! ".trimEnd() === " Hello world!"; + }); +}); + +Mocha.describe("String.trimStart", () => { + Mocha.test("String.trimStart", () => { + " Hello world! ".trimStart() === "Hello world! "; + " Hello world! ".trimStart() === "Hello world! "; + }); +}); + +Mocha.describe("String.trim", () => { + Mocha.test("String.trim", () => { + " abc def ".trim() === "abc def"; + "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; + }); +}); + +Mocha.describe("String.toUpperCase", () => { + Mocha.test("String.toUpperCase", () => { + "abc".toUpperCase() === "ABC"; + "Straße".toUpperCase() === "STRASSE"; + "πς".toUpperCase() === "ΠΣ"; + }); +}); + +Mocha.describe("String.toLowerCase", () => { + Mocha.test("String.toLowerCase", () => { + "ABC".toLowerCase() === "abc"; + "ΣΠ".toLowerCase() === "σπ"; + "ΠΣ".toLowerCase() === "πς"; + }); +}); + +Mocha.describe("String.substringToEnd", () => { + Mocha.test("String.substringToEnd", () => { + "playground".substring(4) === "ground"; + "playground".substring(-3) === "playground"; + "playground".substring(12) === ""; + }); +}); + +Mocha.describe("String.substring", () => { + Mocha.test("String.substring", () => { + "playground".substring(3, 6) === "ygr"; + "playground".substring(6, 3) === "ygr"; + "playground".substring(4, 12) === "ground"; + }); +}); + +Mocha.describe("String.startsWithFrom", () => { + Mocha.test("String.startsWithFrom", () => { + "BuckleScript".startsWith("kle", 3) === true; + "BuckleScript".startsWith("", 3) === true; + "JavaScript".startsWith("Buckle", 2) === false; + }); +}); + +Mocha.describe("String.startsWith", () => { + Mocha.test("String.startsWith", () => { + "BuckleScript".startsWith("Buckle") === true; + "BuckleScript".startsWith("") === true; + "JavaScript".startsWith("Buckle") === false; + }); +}); + +Mocha.describe("String.splitByRegExpAtMost", () => { + Mocha.test("String.splitByRegExpAtMost", () => { + Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ + "Hello", + "World.", + "How" + ]); + }); +}); + +Mocha.describe("String.splitByRegExp", () => { + Mocha.test("String.splitByRegExp", () => { + Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ + "Jan", + "Feb", + "Mar" + ]); + }); +}); + +Mocha.describe("String.splitAtMost", () => { + Mocha.test("String.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.describe("String.split", () => { + Mocha.test("String.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.describe("String.sliceToEnd", () => { + Mocha.test("String.sliceToEnd", () => { + "abcdefg".slice(4) === "efg"; + "abcdefg".slice(-2) === "fg"; + "abcdefg".slice(7) === ""; + }); +}); + +Mocha.describe("String.slice", () => { + Mocha.test("String.slice", () => { + "abcdefg".slice(2, 5) === "cde"; + "abcdefg".slice(2, 9) === "cdefg"; + "abcdefg".slice(-4, -2) === "de"; + "abcdefg".slice(5, 1) === ""; + }); +}); + +Mocha.describe("String.searchOpt", () => { + Mocha.test("String.searchOpt", () => { + Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); + $$String.searchOpt("no numbers", /\d+/) === undefined; + }); +}); + +Mocha.describe("String.search", () => { + Mocha.test("String.search", () => { + "testing 1 2 3".search(/\d+/) === 8; + "no numbers".search(/\d+/) === -1; + }); +}); + +Mocha.describe("String.unsafeReplaceRegExpBy2", () => { + Mocha.test("String.unsafeReplaceRegExpBy2", () => { + let re = /(\d+) times (\d+)/; + let matchFn = (param, group1, group2, param$1, param$2) => { + let match = Int.fromString(group1, undefined); + let match$1 = Int.fromString(group2, undefined); + if (match !== undefined && match$1 !== undefined) { + return Math.imul(match, match$1).toString(); + } else { + return "???"; + } + }; + "7 times 6".replace(re, matchFn) === "42"; + }); +}); + +Mocha.describe("String.unsafeReplaceRegExpBy1", () => { + Mocha.test("String.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.describe("String.unsafeReplaceRegExpBy0", () => { + Mocha.test("String.unsafeReplaceRegExpBy0", () => { + let re = /[aeiou]/g; + let matchFn = (match, param, param$1) => match.toUpperCase(); + "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; + }); +}); + +Mocha.describe("String.replaceAllRegExp", () => { + Mocha.test("String.replaceAllRegExp", () => { + "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; + }); +}); + +Mocha.describe("String.replaceAll", () => { + Mocha.test("String.replaceAll", () => { + "old old string".replaceAll("old", "new") === "new new string"; + "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; + }); +}); + +Mocha.describe("String.replaceRegExp", () => { + Mocha.test("String.replaceRegExp", () => { + "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; + }); +}); + +Mocha.describe("String.replace", () => { + Mocha.test("String.replace", () => { + "old string".replace("old", "new") === "new string"; + "the cat and the dog".replace("the", "this") === "this cat and the dog"; + }); +}); + +Mocha.describe("String.repeat", () => { + Mocha.test("String.repeat", () => { + "ha".repeat(3) === "hahaha"; + "empty".repeat(0) === ""; + }); +}); + +Mocha.describe("String.normalizeForm", () => { + Mocha.test("String.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.describe("String.normalize", () => { + Mocha.test("String.normalize", () => { + let string1 = "\u00F1"; + let string2 = "\u006E\u0303"; + if (string1 === string2) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "mocha_full_test.res", + 18018, + 6 + ], + Error: new Error() + }; + } + Pervasives.assertEqual(string1.normalize(), string2.normalize()); + }); +}); + +Mocha.describe("String.match", () => { + Mocha.test("String.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.describe("String.lastIndexOfFrom", () => { + Mocha.test("String.lastIndexOfFrom", () => { + "bookseller".lastIndexOf("ok", 6) === 2; + "beekeeper".lastIndexOf("ee", 8) === 4; + "beekeeper".lastIndexOf("ee", 3) === 1; + "abcdefg".lastIndexOf("xyz", 4) === -1; + }); +}); + +Mocha.describe("String.lastIndexOfOpt", () => { + Mocha.test("String.lastIndexOfOpt", () => { + Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); + Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); + $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; + }); +}); + +Mocha.describe("String.lastIndexOf", () => { + Mocha.test("String.lastIndexOf", () => { + "bookseller".lastIndexOf("ok") === 2; + "beekeeper".lastIndexOf("ee") === 4; + "abcdefg".lastIndexOf("xyz") === -1; + }); +}); + +Mocha.describe("String.indexOfFrom", () => { + Mocha.test("String.indexOfFrom", () => { + "bookseller".indexOf("ok", 1) === 2; + "bookseller".indexOf("sell", 2) === 4; + "bookseller".indexOf("sell", 5) === -1; + }); +}); + +Mocha.describe("String.indexOfOpt", () => { + Mocha.test("String.indexOfOpt", () => { + Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); + $$String.indexOfOpt("bookseller", "xyz") === undefined; + }); +}); + +Mocha.describe("String.indexOf", () => { + Mocha.test("String.indexOf", () => { + "bookseller".indexOf("ok") === 2; + "bookseller".indexOf("sell") === 4; + "beekeeper".indexOf("ee") === 1; + "bookseller".indexOf("xyz") === -1; + }); +}); + +Mocha.describe("String.includesFrom", () => { + Mocha.test("String.includesFrom", () => { + "programmer".includes("gram", 1) === true; + "programmer".includes("gram", 4) === false; + "대한민국".includes("한", 1) === true; + }); +}); + +Mocha.describe("String.includes", () => { + Mocha.test("String.includes", () => { + "programmer".includes("gram") === true; + "programmer".includes("er") === true; + "programmer".includes("pro") === true; + "programmer.dat".includes("xyz") === false; + }); +}); + +Mocha.describe("String.endsWithFrom", () => { + Mocha.test("String.endsWithFrom", () => { + "abcd".endsWith("cd", 4) === true; + "abcde".endsWith("cd", 3) === false; + "abcde".endsWith("cde", 99) === true; + "example.dat".endsWith("ple", 7) === true; + }); +}); + +Mocha.describe("String.endsWith", () => { + Mocha.test("String.endsWith", () => { + "BuckleScript".endsWith("Script") === true; + "BuckleShoes".endsWith("Script") === false; + }); +}); + +Mocha.describe("String.concatMany", () => { + Mocha.test("String.concatMany", () => { + "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; + }); +}); + +Mocha.describe("String.concat", () => { + Mocha.test("String.concat", () => { + "cow".concat("bell") === "cowbell"; + "Re".concat("Script") === "ReScript"; + }); +}); + +Mocha.describe("String.codePointAt", () => { + Mocha.test("String.codePointAt", () => { + Primitive_object.equal("¿😺?".codePointAt(1), 128570); + "abc".codePointAt(5) === undefined; + }); +}); + +Mocha.describe("String.charCodeAt", () => { + Mocha.test("String.charCodeAt", () => { + "😺".charCodeAt(0) === 55357; + Primitive_object.equal("😺".codePointAt(0), 128570); + }); +}); + +Mocha.describe("String.charAt", () => { + Mocha.test("String.charAt", () => { + "ReScript".charAt(0) === "R"; + "Hello".charAt(12) === ""; + "JS".charAt(5) === ""; + }); +}); + +Mocha.describe("String.getUnsafe", () => { + Mocha.test("String.getUnsafe", () => {}); +}); + +Mocha.describe("String.get", () => { + Mocha.test("String.get", () => { + Primitive_object.equal("ReScript"[0], "R"); + Primitive_object.equal("Hello"[4], "o"); + }); +}); + +Mocha.describe("String.length", () => { + Mocha.test("String.length", () => {}); +}); + +Mocha.describe("String.fromCodePointMany", () => { + Mocha.test("String.fromCodePointMany", () => { + String.fromCodePoint(54620, 44544, 128570) === "한글😺"; + }); +}); + +Mocha.describe("String.fromCodePoint", () => { + Mocha.test("String.fromCodePoint", () => { + String.fromCodePoint(65) === "A"; + String.fromCodePoint(968) === "ψ"; + String.fromCodePoint(54620) === "한"; + String.fromCodePoint(128570) === "😺"; + }); +}); + +Mocha.describe("String.fromCharCodeMany", () => { + Mocha.test("String.fromCharCodeMany", () => { + String.fromCharCode(189, 43, 190, 61) === "½+¾="; + String.fromCharCode(65, 66, 67) === "ABC"; + }); +}); + +Mocha.describe("String.fromCharCode", () => { + Mocha.test("String.fromCharCode", () => { + String.fromCharCode(65) === "A"; + String.fromCharCode(968) === "ψ"; + String.fromCharCode(54620) === "한"; + String.fromCharCode(-64568) === "ψ"; + }); +}); + +Mocha.describe("String.make", () => { + Mocha.test("String.make", () => { + String(3.5) === "3.5"; + String([ + 1, + 2, + 3 + ]) === "1,2,3"; + }); +}); + +Mocha.describe("Type.Classify.classify", () => { + Mocha.test("Type.Classify.classify", () => { + let match = 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("Type.typeof", () => { + Mocha.test("Type.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 9d5780cf5eaff96b327dd4ac222cbd0a867377a5 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:00:46 -0300 Subject: [PATCH 02/13] trigger ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b097e3265f..4583fe40e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [master, 11.0_release] + branches: [master, 11.0_release, doc-tests-fix] # See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet tags: - "v[0-9]+.[0-9]+.[0-9]+" From 5de1563faa7806635bb1935683d85c6f5f67c017 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:03:45 -0300 Subject: [PATCH 03/13] remove ci branch --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4583fe40e1..b097e3265f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [master, 11.0_release, doc-tests-fix] + branches: [master, 11.0_release] # See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet tags: - "v[0-9]+.[0-9]+.[0-9]+" From 856f721e840d7d2636e78df6dc95f41e4d1f0744 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:09:07 -0300 Subject: [PATCH 04/13] test on all platform --- .github/workflows/ci.yml | 4 ++-- scripts/test.js | 36 ++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b097e3265f..1a750c8407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,7 @@ jobs: # Run the slower tasks on the fastest runner only build_playground: true benchmarks: true - docstring_tests: true + # docstring_tests: true - os: buildjet-2vcpu-ubuntu-2204-arm # ARM ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static upload_binaries: true @@ -314,7 +314,7 @@ jobs: run: node scripts/test.js -all - name: Docstrings tests - if: matrix.docstring_tests + # if: matrix.docstring_tests run: node scripts/test.js -docstrings - name: Check for diffs in tests folder diff --git a/scripts/test.js b/scripts/test.js index c9a008a8bb..9326c66c40 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -128,24 +128,24 @@ async function runTests() { } if (runtimeDocstrings) { - if (process.platform === "win32") { - console.log(`Skipping docstrings tests on ${process.platform}`); - } else { - console.log("Running runtime docstrings tests"); - cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstrings_examples"), - stdio: [0, 1, 2], - }); - // Format file - cp.execSync("./cli/rescript format tests/docstrings_examples/mocha_full_test.res", { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }) - cp.execSync(`npx mocha tests/docstrings_examples/mocha_full_test.res.mjs`, { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }); - } + // if (process.platform === "win32") { + // console.log(`Skipping docstrings tests on ${process.platform}`); + // } else { + console.log("Running runtime docstrings tests"); + cp.execSync(`${rescript_exe} build`, { + cwd: path.join(__dirname, "..", "tests/docstrings_examples"), + stdio: [0, 1, 2], + }); + // Format file + cp.execSync("./cli/rescript format tests/docstrings_examples/mocha_full_test.res", { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }) + cp.execSync(`npx mocha tests/docstrings_examples/mocha_full_test.res.mjs`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); + // } } } From b8cf442242efa019be10e0195f1216555a456d6a Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:16:47 -0300 Subject: [PATCH 05/13] fix windows cli path --- scripts/test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 9326c66c40..a02dbc94cf 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -136,12 +136,13 @@ async function runTests() { cwd: path.join(__dirname, "..", "tests/docstrings_examples"), stdio: [0, 1, 2], }); + const file = path.join("tests", "docstrings_examples", "mocha_full_test.res") // Format file - cp.execSync("./cli/rescript format tests/docstrings_examples/mocha_full_test.res", { + cp.execSync(`${path.resolve("./cli/rescript")} format ${file}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }) - cp.execSync(`npx mocha tests/docstrings_examples/mocha_full_test.res.mjs`, { + cp.execSync(`npx mocha ${file}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }); From 1d014a377b8ea7b35c8dc8637f3618161a3b523a Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:26:38 -0300 Subject: [PATCH 06/13] fix test --- scripts/test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index a02dbc94cf..845a609075 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -136,13 +136,15 @@ async function runTests() { cwd: path.join(__dirname, "..", "tests/docstrings_examples"), stdio: [0, 1, 2], }); - const file = path.join("tests", "docstrings_examples", "mocha_full_test.res") - // Format file - cp.execSync(`${path.resolve("./cli/rescript")} format ${file}`, { + + console.log("Formatting mocha_full_test.res") + cp.execSync(`${path.resolve("./cli/rescript")} format ${path.join("tests", "docstrings_examples", "mocha_full_test.res")}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }) - cp.execSync(`npx mocha ${file}`, { + + console.log("Run mocha test") + cp.execSync(`npx mocha ${path.join("tests", "docstrings_examples", "mocha_full_test.res.mjs")}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }); From 81c10c3c4ac5edb7a274347f0b67304907539c86 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:45:02 -0300 Subject: [PATCH 07/13] skip windows --- .github/workflows/ci.yml | 5 - scripts/test.js | 50 +- tests/docstrings_examples/DocTest.res | 2 +- tests/docstrings_examples/DocTest.res.mjs | 2 +- ...full_test.res => generated_mocha_test.res} | 2664 ++++++++--------- ...t.res.mjs => generated_mocha_test.res.mjs} | 2606 ++++++++-------- 6 files changed, 2667 insertions(+), 2662 deletions(-) rename tests/docstrings_examples/{mocha_full_test.res => generated_mocha_test.res} (100%) rename tests/docstrings_examples/{mocha_full_test.res.mjs => generated_mocha_test.res.mjs} (99%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a750c8407..a4d9763efe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,7 +93,6 @@ jobs: # Run the slower tasks on the fastest runner only build_playground: true benchmarks: true - # docstring_tests: true - os: buildjet-2vcpu-ubuntu-2204-arm # ARM ocaml_compiler: ocaml-variants.5.2.1+options,ocaml-option-static upload_binaries: true @@ -313,10 +312,6 @@ jobs: - name: Run tests run: node scripts/test.js -all - - name: Docstrings tests - # if: matrix.docstring_tests - run: node scripts/test.js -docstrings - - name: Check for diffs in tests folder run: git diff --ignore-cr-at-eol --exit-code tests diff --git a/scripts/test.js b/scripts/test.js index 845a609075..3dc2b5746d 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -34,12 +34,12 @@ if (process.argv.includes("-docstrings")) { runtimeDocstrings = true; } -// -all dont include runtimeDocstrings if (process.argv.includes("-all")) { ounitTest = true; mochaTest = true; bsbTest = true; formatTest = true; + runtimeDocstrings = true; } async function runTests() { @@ -128,27 +128,37 @@ async function runTests() { } if (runtimeDocstrings) { - // if (process.platform === "win32") { - // console.log(`Skipping docstrings tests on ${process.platform}`); - // } else { - console.log("Running runtime docstrings tests"); - cp.execSync(`${rescript_exe} build`, { - cwd: path.join(__dirname, "..", "tests/docstrings_examples"), - stdio: [0, 1, 2], - }); + if (process.platform === "win32") { + console.log(`Skipping docstrings tests on ${process.platform}`); + } else { + console.log("Running runtime docstrings tests"); + cp.execSync(`${rescript_exe} build`, { + cwd: path.join(__dirname, "..", "tests/docstrings_examples"), + stdio: [0, 1, 2], + }); - console.log("Formatting mocha_full_test.res") - cp.execSync(`${path.resolve("./cli/rescript")} format ${path.join("tests", "docstrings_examples", "mocha_full_test.res")}`, { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }) + cp.execSync(`node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }) - console.log("Run mocha test") - cp.execSync(`npx mocha ${path.join("tests", "docstrings_examples", "mocha_full_test.res.mjs")}`, { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }); - // } + cp.execSync(`${rescript_exe} build`, { + cwd: path.join(__dirname, "..", "tests/docstrings_examples"), + stdio: [0, 1, 2], + }); + + console.log("Formatting generated_mocha_test.res") + cp.execSync(`./cli/rescript format ${path.join("tests", "docstrings_examples", "generated_mocha_test.res")}`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }) + + console.log("Run mocha test") + cp.execSync(`npx mocha ${path.join("tests", "docstrings_examples", "generated_mocha_test.res.mjs")}`, { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }); + } } } diff --git a/tests/docstrings_examples/DocTest.res b/tests/docstrings_examples/DocTest.res index b059e0d6aa..2e9a2bb8d0 100644 --- a/tests/docstrings_examples/DocTest.res +++ b/tests/docstrings_examples/DocTest.res @@ -182,7 +182,7 @@ let main = async () => { ->Array.join("\n\n") let dirname = url->URL.fileURLToPath->Path.dirname - let filepath = Path.join([dirname, "mocha_full_test.res"]) + let filepath = Path.join([dirname, "generated_mocha_test.res"]) let fileContent = `open Mocha @@warning("-32-34-60-37-109-3-44") diff --git a/tests/docstrings_examples/DocTest.res.mjs b/tests/docstrings_examples/DocTest.res.mjs index fc5cfecc12..087be47b25 100644 --- a/tests/docstrings_examples/DocTest.res.mjs +++ b/tests/docstrings_examples/DocTest.res.mjs @@ -224,7 +224,7 @@ async function main() { } }).join("\n\n"); let dirname = Path.dirname(Url.fileURLToPath(import.meta.url)); - let filepath = Path.join(dirname, "mocha_full_test.res"); + let filepath = Path.join(dirname, "generated_mocha_test.res"); let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + testsContent; return await Promises.writeFile(filepath, fileContent); } diff --git a/tests/docstrings_examples/mocha_full_test.res b/tests/docstrings_examples/generated_mocha_test.res similarity index 100% rename from tests/docstrings_examples/mocha_full_test.res rename to tests/docstrings_examples/generated_mocha_test.res index 2e0befc698..51f69d0289 100644 --- a/tests/docstrings_examples/mocha_full_test.res +++ b/tests/docstrings_examples/generated_mocha_test.res @@ -6981,19 +6981,6 @@ describe("Belt_Map.Int", () => { }) }) -describe("Belt_MapString.findFirstBy", () => { - test("Belt_MapString.findFirstBy", () => { - module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) - } - () - }) -}) - describe("Belt_MapDict.findFirstBy", () => { test("Belt_MapDict.findFirstBy", () => { module Test = { @@ -7023,6 +7010,19 @@ describe("Belt_MapInt.findFirstBy", () => { }) }) +describe("Belt_MapString.findFirstBy", () => { + test("Belt_MapString.findFirstBy", () => { + module Test = { + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) + } + () + }) +}) + describe("Belt_MutableSet.split", () => { test("Belt_MutableSet.split", () => { module Test = { @@ -7515,65 +7515,6 @@ describe("Belt_MutableSet.fromArray", () => { }) }) -describe("Belt_Range.someBy", () => { - test("Belt_Range.someBy", () => { - module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt_Range.some", () => { - test("Belt_Range.some", () => { - module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ - - Belt.Range.some(0, 4, i => i > 2) /* true */ - } - () - }) -}) - -describe("Belt_Range.everyBy", () => { - test("Belt_Range.everyBy", () => { - module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ - - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt_Range.every", () => { - test("Belt_Range.every", () => { - module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ - - Belt.Range.every(0, 4, i => i < 4) /* false */ - } - () - }) -}) - -describe("Belt_Range.forEach", () => { - test("Belt_Range.forEach", () => { - module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) - - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 - } - () - }) -}) - describe("Belt_Option.cmp", () => { test("Belt_Option.cmp", () => { module Test = { @@ -7875,6 +7816,65 @@ describe("Belt_Result.getExn", () => { }) }) +describe("Belt_Range.someBy", () => { + test("Belt_Range.someBy", () => { + module Test = { + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt_Range.some", () => { + test("Belt_Range.some", () => { + module Test = { + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ + } + () + }) +}) + +describe("Belt_Range.everyBy", () => { + test("Belt_Range.everyBy", () => { + module Test = { + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + } + () + }) +}) + +describe("Belt_Range.every", () => { + test("Belt_Range.every", () => { + module Test = { + Belt.Range.every(0, 4, i => i < 5) /* true */ + + Belt.Range.every(0, 4, i => i < 4) /* false */ + } + () + }) +}) + +describe("Belt_Range.forEach", () => { + test("Belt_Range.forEach", () => { + module Test = { + Belt.Range.forEach(0, 4, i => Js.log(i)) + + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 + } + () + }) +}) + describe("Belt_SetDict.split", () => { test("Belt_SetDict.split", () => { module Test = { @@ -9418,57 +9418,34 @@ describe("Belt_SortArray.strictlySortedLength", () => { }) }) -describe("BigInt.toLocaleString", () => { - test("BigInt.toLocaleString", () => { +describe("Belt_internalMapString.S.binarySearchBy", () => { + test("Belt_internalMapString.S.binarySearchBy", () => { module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log - } - () - }) -}) + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 -describe("BigInt.toString", () => { - test("BigInt.toString", () => { - module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("BigInt.fromStringExn", () => { - test("BigInt.fromStringExn", () => { +describe("Belt_internalMapString.S.strictlySortedLength", () => { + test("Belt_internalMapString.S.strictlySortedLength", () => { module Test = { - /* returns 123n */ - BigInt.fromStringExn("123") - - /* returns 0n */ - BigInt.fromStringExn("") - - /* returns 17n */ - BigInt.fromStringExn("0x11") + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - /* returns 3n */ - BigInt.fromStringExn("0b11") + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - /* returns 9n */ - BigInt.fromStringExn("0o11") + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - /* catch exception */ - try { - BigInt.fromStringExn("a") - } catch { - | Exn.Error(_error) => 0n - } + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { +describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { module Test = { let arr = ["ant", "bee", "cat", "dog", "elk"] @@ -9480,8 +9457,8 @@ describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { }) }) -describe("Belt_internalSetString.A.eq", () => { - test("Belt_internalSetString.A.eq", () => { +describe("Belt_internalMapString.A.eq", () => { + test("Belt_internalMapString.A.eq", () => { module Test = { Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } @@ -9489,8 +9466,8 @@ describe("Belt_internalSetString.A.eq", () => { }) }) -describe("Belt_internalSetString.A.cmp", () => { - test("Belt_internalSetString.A.cmp", () => { +describe("Belt_internalMapString.A.cmp", () => { + test("Belt_internalMapString.A.cmp", () => { module Test = { Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 @@ -9502,8 +9479,8 @@ describe("Belt_internalSetString.A.cmp", () => { }) }) -describe("Belt_internalSetString.A.some2", () => { - test("Belt_internalSetString.A.some2", () => { +describe("Belt_internalMapString.A.some2", () => { + test("Belt_internalMapString.A.some2", () => { module Test = { Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true @@ -9515,8 +9492,8 @@ describe("Belt_internalSetString.A.some2", () => { }) }) -describe("Belt_internalSetString.A.every2", () => { - test("Belt_internalSetString.A.every2", () => { +describe("Belt_internalMapString.A.every2", () => { + test("Belt_internalMapString.A.every2", () => { module Test = { Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true @@ -9530,8 +9507,8 @@ describe("Belt_internalSetString.A.every2", () => { }) }) -describe("Belt_internalSetString.A.every", () => { - test("Belt_internalSetString.A.every", () => { +describe("Belt_internalMapString.A.every", () => { + test("Belt_internalMapString.A.every", () => { module Test = { Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true @@ -9541,8 +9518,8 @@ describe("Belt_internalSetString.A.every", () => { }) }) -describe("Belt_internalSetString.A.some", () => { - test("Belt_internalSetString.A.some", () => { +describe("Belt_internalMapString.A.some", () => { + test("Belt_internalMapString.A.some", () => { module Test = { Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true @@ -9552,8 +9529,8 @@ describe("Belt_internalSetString.A.some", () => { }) }) -describe("Belt_internalSetString.A.joinWith", () => { - test("Belt_internalSetString.A.joinWith", () => { +describe("Belt_internalMapString.A.joinWith", () => { + test("Belt_internalMapString.A.joinWith", () => { module Test = { Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" Belt.Array.joinWith([], " ", Js.Int.toString) == "" @@ -9563,8 +9540,8 @@ describe("Belt_internalSetString.A.joinWith", () => { }) }) -describe("Belt_internalSetString.A.reduceWithIndex", () => { - test("Belt_internalSetString.A.reduceWithIndex", () => { +describe("Belt_internalMapString.A.reduceWithIndex", () => { + test("Belt_internalMapString.A.reduceWithIndex", () => { module Test = { Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } @@ -9572,8 +9549,8 @@ describe("Belt_internalSetString.A.reduceWithIndex", () => { }) }) -describe("Belt_internalSetString.A.reduceReverse2", () => { - test("Belt_internalSetString.A.reduceReverse2", () => { +describe("Belt_internalMapString.A.reduceReverse2", () => { + test("Belt_internalMapString.A.reduceReverse2", () => { module Test = { Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } @@ -9581,8 +9558,8 @@ describe("Belt_internalSetString.A.reduceReverse2", () => { }) }) -describe("Belt_internalSetString.A.reduceReverse", () => { - test("Belt_internalSetString.A.reduceReverse", () => { +describe("Belt_internalMapString.A.reduceReverse", () => { + test("Belt_internalMapString.A.reduceReverse", () => { module Test = { Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } @@ -9590,8 +9567,8 @@ describe("Belt_internalSetString.A.reduceReverse", () => { }) }) -describe("Belt_internalSetString.A.reduce", () => { - test("Belt_internalSetString.A.reduce", () => { +describe("Belt_internalMapString.A.reduce", () => { + test("Belt_internalMapString.A.reduce", () => { module Test = { Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 @@ -9601,8 +9578,8 @@ describe("Belt_internalSetString.A.reduce", () => { }) }) -describe("Belt_internalSetString.A.partition", () => { - test("Belt_internalSetString.A.partition", () => { +describe("Belt_internalMapString.A.partition", () => { + test("Belt_internalMapString.A.partition", () => { module Test = { Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) @@ -9612,8 +9589,8 @@ describe("Belt_internalSetString.A.partition", () => { }) }) -describe("Belt_internalSetString.A.mapWithIndex", () => { - test("Belt_internalSetString.A.mapWithIndex", () => { +describe("Belt_internalMapString.A.mapWithIndex", () => { + test("Belt_internalMapString.A.mapWithIndex", () => { module Test = { Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } @@ -9621,8 +9598,8 @@ describe("Belt_internalSetString.A.mapWithIndex", () => { }) }) -describe("Belt_internalSetString.A.forEachWithIndex", () => { - test("Belt_internalSetString.A.forEachWithIndex", () => { +describe("Belt_internalMapString.A.forEachWithIndex", () => { + test("Belt_internalMapString.A.forEachWithIndex", () => { module Test = { Belt.Array.forEachWithIndex( ["a", "b", "c"], @@ -9645,8 +9622,8 @@ describe("Belt_internalSetString.A.forEachWithIndex", () => { }) }) -describe("Belt_internalSetString.A.keepMap", () => { - test("Belt_internalSetString.A.keepMap", () => { +describe("Belt_internalMapString.A.keepMap", () => { + test("Belt_internalMapString.A.keepMap", () => { module Test = { Belt.Array.keepMap( [1, 2, 3], @@ -9662,8 +9639,8 @@ describe("Belt_internalSetString.A.keepMap", () => { }) }) -describe("Belt_internalSetString.A.keepWithIndex", () => { - test("Belt_internalSetString.A.keepWithIndex", () => { +describe("Belt_internalMapString.A.keepWithIndex", () => { + test("Belt_internalMapString.A.keepWithIndex", () => { module Test = { Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } @@ -9671,8 +9648,8 @@ describe("Belt_internalSetString.A.keepWithIndex", () => { }) }) -describe("Belt_internalSetString.A.getIndexBy", () => { - test("Belt_internalSetString.A.getIndexBy", () => { +describe("Belt_internalMapString.A.getIndexBy", () => { + test("Belt_internalMapString.A.getIndexBy", () => { module Test = { Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -9681,8 +9658,8 @@ describe("Belt_internalSetString.A.getIndexBy", () => { }) }) -describe("Belt_internalSetString.A.getBy", () => { - test("Belt_internalSetString.A.getBy", () => { +describe("Belt_internalMapString.A.getBy", () => { + test("Belt_internalMapString.A.getBy", () => { module Test = { Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -9691,8 +9668,8 @@ describe("Belt_internalSetString.A.getBy", () => { }) }) -describe("Belt_internalSetString.A.flatMap", () => { - test("Belt_internalSetString.A.flatMap", () => { +describe("Belt_internalMapString.A.flatMap", () => { + test("Belt_internalMapString.A.flatMap", () => { module Test = { Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } @@ -9700,8 +9677,8 @@ describe("Belt_internalSetString.A.flatMap", () => { }) }) -describe("Belt_internalSetString.A.map", () => { - test("Belt_internalSetString.A.map", () => { +describe("Belt_internalMapString.A.map", () => { + test("Belt_internalMapString.A.map", () => { module Test = { Belt.Array.map([1, 2], x => x + 1) == [3, 4] } @@ -9709,8 +9686,8 @@ describe("Belt_internalSetString.A.map", () => { }) }) -describe("Belt_internalSetString.A.forEach", () => { - test("Belt_internalSetString.A.forEach", () => { +describe("Belt_internalMapString.A.forEach", () => { + test("Belt_internalMapString.A.forEach", () => { module Test = { Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) @@ -9730,8 +9707,8 @@ describe("Belt_internalSetString.A.forEach", () => { }) }) -describe("Belt_internalSetString.A.blit", () => { - test("Belt_internalSetString.A.blit", () => { +describe("Belt_internalMapString.A.blit", () => { + test("Belt_internalMapString.A.blit", () => { module Test = { let v1 = [10, 11, 12, 13, 14, 15, 16, 17] let v2 = [20, 21, 22, 23, 24, 25, 26, 27] @@ -9746,8 +9723,8 @@ describe("Belt_internalSetString.A.blit", () => { }) }) -describe("Belt_internalSetString.A.fill", () => { - test("Belt_internalSetString.A.fill", () => { +describe("Belt_internalMapString.A.fill", () => { + test("Belt_internalMapString.A.fill", () => { module Test = { let arr = Belt.Array.makeBy(5, i => i) @@ -9763,8 +9740,8 @@ describe("Belt_internalSetString.A.fill", () => { }) }) -describe("Belt_internalSetString.A.sliceToEnd", () => { - test("Belt_internalSetString.A.sliceToEnd", () => { +describe("Belt_internalMapString.A.sliceToEnd", () => { + test("Belt_internalMapString.A.sliceToEnd", () => { module Test = { Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] @@ -9774,8 +9751,8 @@ describe("Belt_internalSetString.A.sliceToEnd", () => { }) }) -describe("Belt_internalSetString.A.slice", () => { - test("Belt_internalSetString.A.slice", () => { +describe("Belt_internalMapString.A.slice", () => { + test("Belt_internalMapString.A.slice", () => { module Test = { Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] @@ -9787,8 +9764,8 @@ describe("Belt_internalSetString.A.slice", () => { }) }) -describe("Belt_internalSetString.A.concatMany", () => { - test("Belt_internalSetString.A.concatMany", () => { +describe("Belt_internalMapString.A.concatMany", () => { + test("Belt_internalMapString.A.concatMany", () => { module Test = { Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } @@ -9796,8 +9773,8 @@ describe("Belt_internalSetString.A.concatMany", () => { }) }) -describe("Belt_internalSetString.A.concat", () => { - test("Belt_internalSetString.A.concat", () => { +describe("Belt_internalMapString.A.concat", () => { + test("Belt_internalMapString.A.concat", () => { module Test = { Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] @@ -9807,8 +9784,8 @@ describe("Belt_internalSetString.A.concat", () => { }) }) -describe("Belt_internalSetString.A.unzip", () => { - test("Belt_internalSetString.A.unzip", () => { +describe("Belt_internalMapString.A.unzip", () => { + test("Belt_internalMapString.A.unzip", () => { module Test = { Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) @@ -9818,8 +9795,8 @@ describe("Belt_internalSetString.A.unzip", () => { }) }) -describe("Belt_internalSetString.A.zipBy", () => { - test("Belt_internalSetString.A.zipBy", () => { +describe("Belt_internalMapString.A.zipBy", () => { + test("Belt_internalMapString.A.zipBy", () => { module Test = { Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } @@ -9827,8 +9804,8 @@ describe("Belt_internalSetString.A.zipBy", () => { }) }) -describe("Belt_internalSetString.A.zip", () => { - test("Belt_internalSetString.A.zip", () => { +describe("Belt_internalMapString.A.zip", () => { + test("Belt_internalMapString.A.zip", () => { module Test = { Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } @@ -9836,8 +9813,8 @@ describe("Belt_internalSetString.A.zip", () => { }) }) -describe("Belt_internalSetString.A.makeBy", () => { - test("Belt_internalSetString.A.makeBy", () => { +describe("Belt_internalMapString.A.makeBy", () => { + test("Belt_internalMapString.A.makeBy", () => { module Test = { Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] @@ -9847,8 +9824,8 @@ describe("Belt_internalSetString.A.makeBy", () => { }) }) -describe("Belt_internalSetString.A.rangeBy", () => { - test("Belt_internalSetString.A.rangeBy", () => { +describe("Belt_internalMapString.A.rangeBy", () => { + test("Belt_internalMapString.A.rangeBy", () => { module Test = { Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] @@ -9868,8 +9845,8 @@ describe("Belt_internalSetString.A.rangeBy", () => { }) }) -describe("Belt_internalSetString.A.range", () => { - test("Belt_internalSetString.A.range", () => { +describe("Belt_internalMapString.A.range", () => { + test("Belt_internalMapString.A.range", () => { module Test = { Belt.Array.range(0, 3) == [0, 1, 2, 3] @@ -9881,8 +9858,8 @@ describe("Belt_internalSetString.A.range", () => { }) }) -describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { +describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { module Test = { let arr = Belt.Array.makeUninitializedUnsafe(5) @@ -9896,8 +9873,8 @@ describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { }) }) -describe("Belt_internalSetString.A.makeUninitialized", () => { - test("Belt_internalSetString.A.makeUninitialized", () => { +describe("Belt_internalMapString.A.makeUninitialized", () => { + test("Belt_internalMapString.A.makeUninitialized", () => { module Test = { let arr: array> = Belt.Array.makeUninitialized(5) @@ -9907,8 +9884,8 @@ describe("Belt_internalSetString.A.makeUninitialized", () => { }) }) -describe("Belt_internalSetString.A.reverse", () => { - test("Belt_internalSetString.A.reverse", () => { +describe("Belt_internalMapString.A.reverse", () => { + test("Belt_internalMapString.A.reverse", () => { module Test = { Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } @@ -9916,8 +9893,8 @@ describe("Belt_internalSetString.A.reverse", () => { }) }) -describe("Belt_internalSetString.A.reverseInPlace", () => { - test("Belt_internalSetString.A.reverseInPlace", () => { +describe("Belt_internalMapString.A.reverseInPlace", () => { + test("Belt_internalMapString.A.reverseInPlace", () => { module Test = { let arr = [10, 11, 12, 13, 14] @@ -9929,8 +9906,8 @@ describe("Belt_internalSetString.A.reverseInPlace", () => { }) }) -describe("Belt_internalSetString.A.get", () => { - test("Belt_internalSetString.A.get", () => { +describe("Belt_internalMapString.A.get", () => { + test("Belt_internalMapString.A.get", () => { module Test = { Belt.Array.get(["a", "b", "c"], 0) == Some("a") Belt.Array.get(["a", "b", "c"], 3) == None @@ -9940,8 +9917,8 @@ describe("Belt_internalSetString.A.get", () => { }) }) -describe("Belt_internalSetString.A.length", () => { - test("Belt_internalSetString.A.length", () => { +describe("Belt_internalMapString.A.length", () => { + test("Belt_internalMapString.A.length", () => { module Test = { // Returns 1 Belt.Array.length(["test"]) @@ -9950,6 +9927,55 @@ describe("Belt_internalSetString.A.length", () => { }) }) +describe("BigInt.toLocaleString", () => { + test("BigInt.toLocaleString", () => { + module Test = { + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log + } + () + }) +}) + +describe("BigInt.toString", () => { + test("BigInt.toString", () => { + module Test = { + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log + } + () + }) +}) + +describe("BigInt.fromStringExn", () => { + test("BigInt.fromStringExn", () => { + module Test = { + /* returns 123n */ + BigInt.fromStringExn("123") + + /* returns 0n */ + BigInt.fromStringExn("") + + /* returns 17n */ + BigInt.fromStringExn("0x11") + + /* returns 3n */ + BigInt.fromStringExn("0b11") + + /* returns 9n */ + BigInt.fromStringExn("0o11") + + /* catch exception */ + try { + BigInt.fromStringExn("a") + } catch { + | Exn.Error(_error) => 0n + } + } + () + }) +}) + describe("Belt_internalMapInt.S.binarySearchBy", () => { test("Belt_internalMapInt.S.binarySearchBy", () => { module Test = { @@ -10459,34 +10485,8 @@ describe("Belt_internalMapInt.A.length", () => { }) }) -describe("Belt_internalMapString.S.binarySearchBy", () => { - test("Belt_internalMapString.S.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 - } - () - }) -}) - -describe("Belt_internalMapString.S.strictlySortedLength", () => { - test("Belt_internalMapString.S.strictlySortedLength", () => { - module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 - } - () - }) -}) - -describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { +describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { module Test = { let arr = ["ant", "bee", "cat", "dog", "elk"] @@ -10498,8 +10498,8 @@ describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { }) }) -describe("Belt_internalMapString.A.eq", () => { - test("Belt_internalMapString.A.eq", () => { +describe("Belt_internalSetInt.A.eq", () => { + test("Belt_internalSetInt.A.eq", () => { module Test = { Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } @@ -10507,8 +10507,8 @@ describe("Belt_internalMapString.A.eq", () => { }) }) -describe("Belt_internalMapString.A.cmp", () => { - test("Belt_internalMapString.A.cmp", () => { +describe("Belt_internalSetInt.A.cmp", () => { + test("Belt_internalSetInt.A.cmp", () => { module Test = { Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 @@ -10520,8 +10520,8 @@ describe("Belt_internalMapString.A.cmp", () => { }) }) -describe("Belt_internalMapString.A.some2", () => { - test("Belt_internalMapString.A.some2", () => { +describe("Belt_internalSetInt.A.some2", () => { + test("Belt_internalSetInt.A.some2", () => { module Test = { Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true @@ -10533,8 +10533,8 @@ describe("Belt_internalMapString.A.some2", () => { }) }) -describe("Belt_internalMapString.A.every2", () => { - test("Belt_internalMapString.A.every2", () => { +describe("Belt_internalSetInt.A.every2", () => { + test("Belt_internalSetInt.A.every2", () => { module Test = { Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true @@ -10548,8 +10548,8 @@ describe("Belt_internalMapString.A.every2", () => { }) }) -describe("Belt_internalMapString.A.every", () => { - test("Belt_internalMapString.A.every", () => { +describe("Belt_internalSetInt.A.every", () => { + test("Belt_internalSetInt.A.every", () => { module Test = { Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true @@ -10559,8 +10559,8 @@ describe("Belt_internalMapString.A.every", () => { }) }) -describe("Belt_internalMapString.A.some", () => { - test("Belt_internalMapString.A.some", () => { +describe("Belt_internalSetInt.A.some", () => { + test("Belt_internalSetInt.A.some", () => { module Test = { Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true @@ -10570,8 +10570,8 @@ describe("Belt_internalMapString.A.some", () => { }) }) -describe("Belt_internalMapString.A.joinWith", () => { - test("Belt_internalMapString.A.joinWith", () => { +describe("Belt_internalSetInt.A.joinWith", () => { + test("Belt_internalSetInt.A.joinWith", () => { module Test = { Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" Belt.Array.joinWith([], " ", Js.Int.toString) == "" @@ -10581,8 +10581,8 @@ describe("Belt_internalMapString.A.joinWith", () => { }) }) -describe("Belt_internalMapString.A.reduceWithIndex", () => { - test("Belt_internalMapString.A.reduceWithIndex", () => { +describe("Belt_internalSetInt.A.reduceWithIndex", () => { + test("Belt_internalSetInt.A.reduceWithIndex", () => { module Test = { Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } @@ -10590,8 +10590,8 @@ describe("Belt_internalMapString.A.reduceWithIndex", () => { }) }) -describe("Belt_internalMapString.A.reduceReverse2", () => { - test("Belt_internalMapString.A.reduceReverse2", () => { +describe("Belt_internalSetInt.A.reduceReverse2", () => { + test("Belt_internalSetInt.A.reduceReverse2", () => { module Test = { Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } @@ -10599,8 +10599,8 @@ describe("Belt_internalMapString.A.reduceReverse2", () => { }) }) -describe("Belt_internalMapString.A.reduceReverse", () => { - test("Belt_internalMapString.A.reduceReverse", () => { +describe("Belt_internalSetInt.A.reduceReverse", () => { + test("Belt_internalSetInt.A.reduceReverse", () => { module Test = { Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } @@ -10608,8 +10608,8 @@ describe("Belt_internalMapString.A.reduceReverse", () => { }) }) -describe("Belt_internalMapString.A.reduce", () => { - test("Belt_internalMapString.A.reduce", () => { +describe("Belt_internalSetInt.A.reduce", () => { + test("Belt_internalSetInt.A.reduce", () => { module Test = { Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 @@ -10619,8 +10619,8 @@ describe("Belt_internalMapString.A.reduce", () => { }) }) -describe("Belt_internalMapString.A.partition", () => { - test("Belt_internalMapString.A.partition", () => { +describe("Belt_internalSetInt.A.partition", () => { + test("Belt_internalSetInt.A.partition", () => { module Test = { Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) @@ -10630,8 +10630,8 @@ describe("Belt_internalMapString.A.partition", () => { }) }) -describe("Belt_internalMapString.A.mapWithIndex", () => { - test("Belt_internalMapString.A.mapWithIndex", () => { +describe("Belt_internalSetInt.A.mapWithIndex", () => { + test("Belt_internalSetInt.A.mapWithIndex", () => { module Test = { Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } @@ -10639,8 +10639,8 @@ describe("Belt_internalMapString.A.mapWithIndex", () => { }) }) -describe("Belt_internalMapString.A.forEachWithIndex", () => { - test("Belt_internalMapString.A.forEachWithIndex", () => { +describe("Belt_internalSetInt.A.forEachWithIndex", () => { + test("Belt_internalSetInt.A.forEachWithIndex", () => { module Test = { Belt.Array.forEachWithIndex( ["a", "b", "c"], @@ -10663,8 +10663,8 @@ describe("Belt_internalMapString.A.forEachWithIndex", () => { }) }) -describe("Belt_internalMapString.A.keepMap", () => { - test("Belt_internalMapString.A.keepMap", () => { +describe("Belt_internalSetInt.A.keepMap", () => { + test("Belt_internalSetInt.A.keepMap", () => { module Test = { Belt.Array.keepMap( [1, 2, 3], @@ -10680,8 +10680,8 @@ describe("Belt_internalMapString.A.keepMap", () => { }) }) -describe("Belt_internalMapString.A.keepWithIndex", () => { - test("Belt_internalMapString.A.keepWithIndex", () => { +describe("Belt_internalSetInt.A.keepWithIndex", () => { + test("Belt_internalSetInt.A.keepWithIndex", () => { module Test = { Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } @@ -10689,8 +10689,8 @@ describe("Belt_internalMapString.A.keepWithIndex", () => { }) }) -describe("Belt_internalMapString.A.getIndexBy", () => { - test("Belt_internalMapString.A.getIndexBy", () => { +describe("Belt_internalSetInt.A.getIndexBy", () => { + test("Belt_internalSetInt.A.getIndexBy", () => { module Test = { Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -10699,8 +10699,8 @@ describe("Belt_internalMapString.A.getIndexBy", () => { }) }) -describe("Belt_internalMapString.A.getBy", () => { - test("Belt_internalMapString.A.getBy", () => { +describe("Belt_internalSetInt.A.getBy", () => { + test("Belt_internalSetInt.A.getBy", () => { module Test = { Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -10709,8 +10709,8 @@ describe("Belt_internalMapString.A.getBy", () => { }) }) -describe("Belt_internalMapString.A.flatMap", () => { - test("Belt_internalMapString.A.flatMap", () => { +describe("Belt_internalSetInt.A.flatMap", () => { + test("Belt_internalSetInt.A.flatMap", () => { module Test = { Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } @@ -10718,8 +10718,8 @@ describe("Belt_internalMapString.A.flatMap", () => { }) }) -describe("Belt_internalMapString.A.map", () => { - test("Belt_internalMapString.A.map", () => { +describe("Belt_internalSetInt.A.map", () => { + test("Belt_internalSetInt.A.map", () => { module Test = { Belt.Array.map([1, 2], x => x + 1) == [3, 4] } @@ -10727,8 +10727,8 @@ describe("Belt_internalMapString.A.map", () => { }) }) -describe("Belt_internalMapString.A.forEach", () => { - test("Belt_internalMapString.A.forEach", () => { +describe("Belt_internalSetInt.A.forEach", () => { + test("Belt_internalSetInt.A.forEach", () => { module Test = { Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) @@ -10748,8 +10748,8 @@ describe("Belt_internalMapString.A.forEach", () => { }) }) -describe("Belt_internalMapString.A.blit", () => { - test("Belt_internalMapString.A.blit", () => { +describe("Belt_internalSetInt.A.blit", () => { + test("Belt_internalSetInt.A.blit", () => { module Test = { let v1 = [10, 11, 12, 13, 14, 15, 16, 17] let v2 = [20, 21, 22, 23, 24, 25, 26, 27] @@ -10764,8 +10764,8 @@ describe("Belt_internalMapString.A.blit", () => { }) }) -describe("Belt_internalMapString.A.fill", () => { - test("Belt_internalMapString.A.fill", () => { +describe("Belt_internalSetInt.A.fill", () => { + test("Belt_internalSetInt.A.fill", () => { module Test = { let arr = Belt.Array.makeBy(5, i => i) @@ -10781,8 +10781,8 @@ describe("Belt_internalMapString.A.fill", () => { }) }) -describe("Belt_internalMapString.A.sliceToEnd", () => { - test("Belt_internalMapString.A.sliceToEnd", () => { +describe("Belt_internalSetInt.A.sliceToEnd", () => { + test("Belt_internalSetInt.A.sliceToEnd", () => { module Test = { Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] @@ -10792,8 +10792,8 @@ describe("Belt_internalMapString.A.sliceToEnd", () => { }) }) -describe("Belt_internalMapString.A.slice", () => { - test("Belt_internalMapString.A.slice", () => { +describe("Belt_internalSetInt.A.slice", () => { + test("Belt_internalSetInt.A.slice", () => { module Test = { Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] @@ -10805,8 +10805,8 @@ describe("Belt_internalMapString.A.slice", () => { }) }) -describe("Belt_internalMapString.A.concatMany", () => { - test("Belt_internalMapString.A.concatMany", () => { +describe("Belt_internalSetInt.A.concatMany", () => { + test("Belt_internalSetInt.A.concatMany", () => { module Test = { Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } @@ -10814,8 +10814,8 @@ describe("Belt_internalMapString.A.concatMany", () => { }) }) -describe("Belt_internalMapString.A.concat", () => { - test("Belt_internalMapString.A.concat", () => { +describe("Belt_internalSetInt.A.concat", () => { + test("Belt_internalSetInt.A.concat", () => { module Test = { Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] @@ -10825,8 +10825,8 @@ describe("Belt_internalMapString.A.concat", () => { }) }) -describe("Belt_internalMapString.A.unzip", () => { - test("Belt_internalMapString.A.unzip", () => { +describe("Belt_internalSetInt.A.unzip", () => { + test("Belt_internalSetInt.A.unzip", () => { module Test = { Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) @@ -10836,8 +10836,8 @@ describe("Belt_internalMapString.A.unzip", () => { }) }) -describe("Belt_internalMapString.A.zipBy", () => { - test("Belt_internalMapString.A.zipBy", () => { +describe("Belt_internalSetInt.A.zipBy", () => { + test("Belt_internalSetInt.A.zipBy", () => { module Test = { Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } @@ -10845,8 +10845,8 @@ describe("Belt_internalMapString.A.zipBy", () => { }) }) -describe("Belt_internalMapString.A.zip", () => { - test("Belt_internalMapString.A.zip", () => { +describe("Belt_internalSetInt.A.zip", () => { + test("Belt_internalSetInt.A.zip", () => { module Test = { Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } @@ -10854,8 +10854,8 @@ describe("Belt_internalMapString.A.zip", () => { }) }) -describe("Belt_internalMapString.A.makeBy", () => { - test("Belt_internalMapString.A.makeBy", () => { +describe("Belt_internalSetInt.A.makeBy", () => { + test("Belt_internalSetInt.A.makeBy", () => { module Test = { Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] @@ -10865,8 +10865,8 @@ describe("Belt_internalMapString.A.makeBy", () => { }) }) -describe("Belt_internalMapString.A.rangeBy", () => { - test("Belt_internalMapString.A.rangeBy", () => { +describe("Belt_internalSetInt.A.rangeBy", () => { + test("Belt_internalSetInt.A.rangeBy", () => { module Test = { Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] @@ -10886,8 +10886,8 @@ describe("Belt_internalMapString.A.rangeBy", () => { }) }) -describe("Belt_internalMapString.A.range", () => { - test("Belt_internalMapString.A.range", () => { +describe("Belt_internalSetInt.A.range", () => { + test("Belt_internalSetInt.A.range", () => { module Test = { Belt.Array.range(0, 3) == [0, 1, 2, 3] @@ -10899,8 +10899,8 @@ describe("Belt_internalMapString.A.range", () => { }) }) -describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { +describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { module Test = { let arr = Belt.Array.makeUninitializedUnsafe(5) @@ -10914,8 +10914,8 @@ describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { }) }) -describe("Belt_internalMapString.A.makeUninitialized", () => { - test("Belt_internalMapString.A.makeUninitialized", () => { +describe("Belt_internalSetInt.A.makeUninitialized", () => { + test("Belt_internalSetInt.A.makeUninitialized", () => { module Test = { let arr: array> = Belt.Array.makeUninitialized(5) @@ -10925,8 +10925,8 @@ describe("Belt_internalMapString.A.makeUninitialized", () => { }) }) -describe("Belt_internalMapString.A.reverse", () => { - test("Belt_internalMapString.A.reverse", () => { +describe("Belt_internalSetInt.A.reverse", () => { + test("Belt_internalSetInt.A.reverse", () => { module Test = { Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } @@ -10934,8 +10934,8 @@ describe("Belt_internalMapString.A.reverse", () => { }) }) -describe("Belt_internalMapString.A.reverseInPlace", () => { - test("Belt_internalMapString.A.reverseInPlace", () => { +describe("Belt_internalSetInt.A.reverseInPlace", () => { + test("Belt_internalSetInt.A.reverseInPlace", () => { module Test = { let arr = [10, 11, 12, 13, 14] @@ -10947,8 +10947,8 @@ describe("Belt_internalMapString.A.reverseInPlace", () => { }) }) -describe("Belt_internalMapString.A.get", () => { - test("Belt_internalMapString.A.get", () => { +describe("Belt_internalSetInt.A.get", () => { + test("Belt_internalSetInt.A.get", () => { module Test = { Belt.Array.get(["a", "b", "c"], 0) == Some("a") Belt.Array.get(["a", "b", "c"], 3) == None @@ -10958,8 +10958,8 @@ describe("Belt_internalMapString.A.get", () => { }) }) -describe("Belt_internalMapString.A.length", () => { - test("Belt_internalMapString.A.length", () => { +describe("Belt_internalSetInt.A.length", () => { + test("Belt_internalSetInt.A.length", () => { module Test = { // Returns 1 Belt.Array.length(["test"]) @@ -10968,8 +10968,8 @@ describe("Belt_internalMapString.A.length", () => { }) }) -describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { +describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { module Test = { let arr = ["ant", "bee", "cat", "dog", "elk"] @@ -10981,8 +10981,8 @@ describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { }) }) -describe("Belt_internalSetInt.A.eq", () => { - test("Belt_internalSetInt.A.eq", () => { +describe("Belt_internalSetString.A.eq", () => { + test("Belt_internalSetString.A.eq", () => { module Test = { Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } @@ -10990,8 +10990,8 @@ describe("Belt_internalSetInt.A.eq", () => { }) }) -describe("Belt_internalSetInt.A.cmp", () => { - test("Belt_internalSetInt.A.cmp", () => { +describe("Belt_internalSetString.A.cmp", () => { + test("Belt_internalSetString.A.cmp", () => { module Test = { Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 @@ -11003,8 +11003,8 @@ describe("Belt_internalSetInt.A.cmp", () => { }) }) -describe("Belt_internalSetInt.A.some2", () => { - test("Belt_internalSetInt.A.some2", () => { +describe("Belt_internalSetString.A.some2", () => { + test("Belt_internalSetString.A.some2", () => { module Test = { Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true @@ -11016,8 +11016,8 @@ describe("Belt_internalSetInt.A.some2", () => { }) }) -describe("Belt_internalSetInt.A.every2", () => { - test("Belt_internalSetInt.A.every2", () => { +describe("Belt_internalSetString.A.every2", () => { + test("Belt_internalSetString.A.every2", () => { module Test = { Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true @@ -11031,8 +11031,8 @@ describe("Belt_internalSetInt.A.every2", () => { }) }) -describe("Belt_internalSetInt.A.every", () => { - test("Belt_internalSetInt.A.every", () => { +describe("Belt_internalSetString.A.every", () => { + test("Belt_internalSetString.A.every", () => { module Test = { Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true @@ -11042,8 +11042,8 @@ describe("Belt_internalSetInt.A.every", () => { }) }) -describe("Belt_internalSetInt.A.some", () => { - test("Belt_internalSetInt.A.some", () => { +describe("Belt_internalSetString.A.some", () => { + test("Belt_internalSetString.A.some", () => { module Test = { Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true @@ -11053,8 +11053,8 @@ describe("Belt_internalSetInt.A.some", () => { }) }) -describe("Belt_internalSetInt.A.joinWith", () => { - test("Belt_internalSetInt.A.joinWith", () => { +describe("Belt_internalSetString.A.joinWith", () => { + test("Belt_internalSetString.A.joinWith", () => { module Test = { Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" Belt.Array.joinWith([], " ", Js.Int.toString) == "" @@ -11064,8 +11064,8 @@ describe("Belt_internalSetInt.A.joinWith", () => { }) }) -describe("Belt_internalSetInt.A.reduceWithIndex", () => { - test("Belt_internalSetInt.A.reduceWithIndex", () => { +describe("Belt_internalSetString.A.reduceWithIndex", () => { + test("Belt_internalSetString.A.reduceWithIndex", () => { module Test = { Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } @@ -11073,8 +11073,8 @@ describe("Belt_internalSetInt.A.reduceWithIndex", () => { }) }) -describe("Belt_internalSetInt.A.reduceReverse2", () => { - test("Belt_internalSetInt.A.reduceReverse2", () => { +describe("Belt_internalSetString.A.reduceReverse2", () => { + test("Belt_internalSetString.A.reduceReverse2", () => { module Test = { Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } @@ -11082,8 +11082,8 @@ describe("Belt_internalSetInt.A.reduceReverse2", () => { }) }) -describe("Belt_internalSetInt.A.reduceReverse", () => { - test("Belt_internalSetInt.A.reduceReverse", () => { +describe("Belt_internalSetString.A.reduceReverse", () => { + test("Belt_internalSetString.A.reduceReverse", () => { module Test = { Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } @@ -11091,8 +11091,8 @@ describe("Belt_internalSetInt.A.reduceReverse", () => { }) }) -describe("Belt_internalSetInt.A.reduce", () => { - test("Belt_internalSetInt.A.reduce", () => { +describe("Belt_internalSetString.A.reduce", () => { + test("Belt_internalSetString.A.reduce", () => { module Test = { Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 @@ -11102,8 +11102,8 @@ describe("Belt_internalSetInt.A.reduce", () => { }) }) -describe("Belt_internalSetInt.A.partition", () => { - test("Belt_internalSetInt.A.partition", () => { +describe("Belt_internalSetString.A.partition", () => { + test("Belt_internalSetString.A.partition", () => { module Test = { Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) @@ -11113,8 +11113,8 @@ describe("Belt_internalSetInt.A.partition", () => { }) }) -describe("Belt_internalSetInt.A.mapWithIndex", () => { - test("Belt_internalSetInt.A.mapWithIndex", () => { +describe("Belt_internalSetString.A.mapWithIndex", () => { + test("Belt_internalSetString.A.mapWithIndex", () => { module Test = { Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } @@ -11122,8 +11122,8 @@ describe("Belt_internalSetInt.A.mapWithIndex", () => { }) }) -describe("Belt_internalSetInt.A.forEachWithIndex", () => { - test("Belt_internalSetInt.A.forEachWithIndex", () => { +describe("Belt_internalSetString.A.forEachWithIndex", () => { + test("Belt_internalSetString.A.forEachWithIndex", () => { module Test = { Belt.Array.forEachWithIndex( ["a", "b", "c"], @@ -11146,8 +11146,8 @@ describe("Belt_internalSetInt.A.forEachWithIndex", () => { }) }) -describe("Belt_internalSetInt.A.keepMap", () => { - test("Belt_internalSetInt.A.keepMap", () => { +describe("Belt_internalSetString.A.keepMap", () => { + test("Belt_internalSetString.A.keepMap", () => { module Test = { Belt.Array.keepMap( [1, 2, 3], @@ -11163,8 +11163,8 @@ describe("Belt_internalSetInt.A.keepMap", () => { }) }) -describe("Belt_internalSetInt.A.keepWithIndex", () => { - test("Belt_internalSetInt.A.keepWithIndex", () => { +describe("Belt_internalSetString.A.keepWithIndex", () => { + test("Belt_internalSetString.A.keepWithIndex", () => { module Test = { Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } @@ -11172,8 +11172,8 @@ describe("Belt_internalSetInt.A.keepWithIndex", () => { }) }) -describe("Belt_internalSetInt.A.getIndexBy", () => { - test("Belt_internalSetInt.A.getIndexBy", () => { +describe("Belt_internalSetString.A.getIndexBy", () => { + test("Belt_internalSetString.A.getIndexBy", () => { module Test = { Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -11182,8 +11182,8 @@ describe("Belt_internalSetInt.A.getIndexBy", () => { }) }) -describe("Belt_internalSetInt.A.getBy", () => { - test("Belt_internalSetInt.A.getBy", () => { +describe("Belt_internalSetString.A.getBy", () => { + test("Belt_internalSetString.A.getBy", () => { module Test = { Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None @@ -11192,8 +11192,8 @@ describe("Belt_internalSetInt.A.getBy", () => { }) }) -describe("Belt_internalSetInt.A.flatMap", () => { - test("Belt_internalSetInt.A.flatMap", () => { +describe("Belt_internalSetString.A.flatMap", () => { + test("Belt_internalSetString.A.flatMap", () => { module Test = { Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } @@ -11201,8 +11201,8 @@ describe("Belt_internalSetInt.A.flatMap", () => { }) }) -describe("Belt_internalSetInt.A.map", () => { - test("Belt_internalSetInt.A.map", () => { +describe("Belt_internalSetString.A.map", () => { + test("Belt_internalSetString.A.map", () => { module Test = { Belt.Array.map([1, 2], x => x + 1) == [3, 4] } @@ -11210,8 +11210,8 @@ describe("Belt_internalSetInt.A.map", () => { }) }) -describe("Belt_internalSetInt.A.forEach", () => { - test("Belt_internalSetInt.A.forEach", () => { +describe("Belt_internalSetString.A.forEach", () => { + test("Belt_internalSetString.A.forEach", () => { module Test = { Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) @@ -11231,8 +11231,8 @@ describe("Belt_internalSetInt.A.forEach", () => { }) }) -describe("Belt_internalSetInt.A.blit", () => { - test("Belt_internalSetInt.A.blit", () => { +describe("Belt_internalSetString.A.blit", () => { + test("Belt_internalSetString.A.blit", () => { module Test = { let v1 = [10, 11, 12, 13, 14, 15, 16, 17] let v2 = [20, 21, 22, 23, 24, 25, 26, 27] @@ -11247,8 +11247,8 @@ describe("Belt_internalSetInt.A.blit", () => { }) }) -describe("Belt_internalSetInt.A.fill", () => { - test("Belt_internalSetInt.A.fill", () => { +describe("Belt_internalSetString.A.fill", () => { + test("Belt_internalSetString.A.fill", () => { module Test = { let arr = Belt.Array.makeBy(5, i => i) @@ -11264,8 +11264,8 @@ describe("Belt_internalSetInt.A.fill", () => { }) }) -describe("Belt_internalSetInt.A.sliceToEnd", () => { - test("Belt_internalSetInt.A.sliceToEnd", () => { +describe("Belt_internalSetString.A.sliceToEnd", () => { + test("Belt_internalSetString.A.sliceToEnd", () => { module Test = { Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] @@ -11275,8 +11275,8 @@ describe("Belt_internalSetInt.A.sliceToEnd", () => { }) }) -describe("Belt_internalSetInt.A.slice", () => { - test("Belt_internalSetInt.A.slice", () => { +describe("Belt_internalSetString.A.slice", () => { + test("Belt_internalSetString.A.slice", () => { module Test = { Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] @@ -11288,8 +11288,8 @@ describe("Belt_internalSetInt.A.slice", () => { }) }) -describe("Belt_internalSetInt.A.concatMany", () => { - test("Belt_internalSetInt.A.concatMany", () => { +describe("Belt_internalSetString.A.concatMany", () => { + test("Belt_internalSetString.A.concatMany", () => { module Test = { Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } @@ -11297,8 +11297,8 @@ describe("Belt_internalSetInt.A.concatMany", () => { }) }) -describe("Belt_internalSetInt.A.concat", () => { - test("Belt_internalSetInt.A.concat", () => { +describe("Belt_internalSetString.A.concat", () => { + test("Belt_internalSetString.A.concat", () => { module Test = { Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] @@ -11308,8 +11308,8 @@ describe("Belt_internalSetInt.A.concat", () => { }) }) -describe("Belt_internalSetInt.A.unzip", () => { - test("Belt_internalSetInt.A.unzip", () => { +describe("Belt_internalSetString.A.unzip", () => { + test("Belt_internalSetString.A.unzip", () => { module Test = { Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) @@ -11319,8 +11319,8 @@ describe("Belt_internalSetInt.A.unzip", () => { }) }) -describe("Belt_internalSetInt.A.zipBy", () => { - test("Belt_internalSetInt.A.zipBy", () => { +describe("Belt_internalSetString.A.zipBy", () => { + test("Belt_internalSetString.A.zipBy", () => { module Test = { Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } @@ -11328,8 +11328,8 @@ describe("Belt_internalSetInt.A.zipBy", () => { }) }) -describe("Belt_internalSetInt.A.zip", () => { - test("Belt_internalSetInt.A.zip", () => { +describe("Belt_internalSetString.A.zip", () => { + test("Belt_internalSetString.A.zip", () => { module Test = { Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } @@ -11337,8 +11337,8 @@ describe("Belt_internalSetInt.A.zip", () => { }) }) -describe("Belt_internalSetInt.A.makeBy", () => { - test("Belt_internalSetInt.A.makeBy", () => { +describe("Belt_internalSetString.A.makeBy", () => { + test("Belt_internalSetString.A.makeBy", () => { module Test = { Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] @@ -11348,8 +11348,8 @@ describe("Belt_internalSetInt.A.makeBy", () => { }) }) -describe("Belt_internalSetInt.A.rangeBy", () => { - test("Belt_internalSetInt.A.rangeBy", () => { +describe("Belt_internalSetString.A.rangeBy", () => { + test("Belt_internalSetString.A.rangeBy", () => { module Test = { Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] @@ -11369,8 +11369,8 @@ describe("Belt_internalSetInt.A.rangeBy", () => { }) }) -describe("Belt_internalSetInt.A.range", () => { - test("Belt_internalSetInt.A.range", () => { +describe("Belt_internalSetString.A.range", () => { + test("Belt_internalSetString.A.range", () => { module Test = { Belt.Array.range(0, 3) == [0, 1, 2, 3] @@ -11382,8 +11382,8 @@ describe("Belt_internalSetInt.A.range", () => { }) }) -describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { +describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { module Test = { let arr = Belt.Array.makeUninitializedUnsafe(5) @@ -11397,8 +11397,8 @@ describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { }) }) -describe("Belt_internalSetInt.A.makeUninitialized", () => { - test("Belt_internalSetInt.A.makeUninitialized", () => { +describe("Belt_internalSetString.A.makeUninitialized", () => { + test("Belt_internalSetString.A.makeUninitialized", () => { module Test = { let arr: array> = Belt.Array.makeUninitialized(5) @@ -11408,8 +11408,8 @@ describe("Belt_internalSetInt.A.makeUninitialized", () => { }) }) -describe("Belt_internalSetInt.A.reverse", () => { - test("Belt_internalSetInt.A.reverse", () => { +describe("Belt_internalSetString.A.reverse", () => { + test("Belt_internalSetString.A.reverse", () => { module Test = { Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } @@ -11417,8 +11417,8 @@ describe("Belt_internalSetInt.A.reverse", () => { }) }) -describe("Belt_internalSetInt.A.reverseInPlace", () => { - test("Belt_internalSetInt.A.reverseInPlace", () => { +describe("Belt_internalSetString.A.reverseInPlace", () => { + test("Belt_internalSetString.A.reverseInPlace", () => { module Test = { let arr = [10, 11, 12, 13, 14] @@ -11430,8 +11430,8 @@ describe("Belt_internalSetInt.A.reverseInPlace", () => { }) }) -describe("Belt_internalSetInt.A.get", () => { - test("Belt_internalSetInt.A.get", () => { +describe("Belt_internalSetString.A.get", () => { + test("Belt_internalSetString.A.get", () => { module Test = { Belt.Array.get(["a", "b", "c"], 0) == Some("a") Belt.Array.get(["a", "b", "c"], 3) == None @@ -11441,8 +11441,8 @@ describe("Belt_internalSetInt.A.get", () => { }) }) -describe("Belt_internalSetInt.A.length", () => { - test("Belt_internalSetInt.A.length", () => { +describe("Belt_internalSetString.A.length", () => { + test("Belt_internalSetString.A.length", () => { module Test = { // Returns 1 Belt.Array.length(["test"]) @@ -11993,30 +11993,232 @@ describe("Console.assert_", () => { }) }) -describe("Date.UTC.makeWithYMDHMSM", () => { - test("Date.UTC.makeWithYMDHMSM", () => { +describe("Dict.mapValues", () => { + test("Dict.mapValues", () => { module Test = { - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - )->Console.log - // 1676911200000 - - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - )->Console.log - // 1676911201000 + let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) + + dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] + dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] + } + () + }) +}) + +describe("Dict.forEachWithKey", () => { + test("Dict.forEachWithKey", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + + dict->Dict.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) + } + () + }) +}) + +describe("Dict.forEach", () => { + test("Dict.forEach", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + + dict->Dict.forEach( + value => { + Console.log(value) + }, + ) + } + () + }) +}) + +describe("Dict.copy", () => { + test("Dict.copy", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let dict2 = dict->Dict.copy + + // Both log `["key1", "key2"]` here. + Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) + } + () + }) +}) + +describe("Dict.assign", () => { + test("Dict.assign", () => { + module Test = { + let dict1 = Dict.make() + dict1->Dict.set("firstKey", 1) + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` + + let dict2 = Dict.make() + dict2->Dict.set("someKey", 2) + dict2->Dict.set("someKey2", 3) + + let dict1 = dict1->Dict.assign(dict2) + + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` + } + () + }) +}) + +describe("Dict.valuesToArray", () => { + test("Dict.valuesToArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let values = dict->Dict.valuesToArray + Console.log(values) // Logs `[1, 2]` to the console + } + () + }) +}) + +describe("Dict.keysToArray", () => { + test("Dict.keysToArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let keys = dict->Dict.keysToArray + Console.log(keys) // Logs `["someKey", "someKey2"]` to the console + } + () + }) +}) + +describe("Dict.toArray", () => { + test("Dict.toArray", () => { + module Test = { + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let asArray = dict->Dict.toArray + Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console + } + () + }) +}) + +describe("Dict.fromIterator", () => { + test("Dict.fromIterator", () => { + module Test = { + let iterator: Iterator.t<(string, int)> = %raw(` + (() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + iterator + ->Dict.fromIterator + ->Dict.valuesToArray + ->assertEqual([1, 2]) + } + () + }) +}) + +describe("Dict.fromArray", () => { + test("Dict.fromArray", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + } + () + }) +}) + +describe("Dict.make", () => { + test("Dict.make", () => { + module Test = { + let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want + + let dict2 = Dict.make() // Or you can let ReScript infer it via usage. + dict2->Dict.set("someKey", 12) + } + () + }) +}) + +describe("Dict.delete", () => { + test("Dict.delete", () => { + module Test = { + let dict = Dict.fromArray([("someKey", "someValue")]) + + dict->Dict.delete("someKey") + } + () + }) +}) + +describe("Dict.set", () => { + test("Dict.set", () => { + module Test = { + let dict = Dict.make() + + dict->Dict.set("someKey", "someValue") + } + () + }) +}) + +describe("Dict.get", () => { + test("Dict.get", () => { + module Test = { + let dict = Dict.fromArray([("someKey", "someValue")]) + + switch dict->Dict.get("someKey") { + | None => Console.log("Nope, didn't have the key.") + | Some(value) => Console.log(value) + } + } + () + }) +}) + +describe("Dict.getUnsafe", () => { + test("Dict.getUnsafe", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let value = dict->Dict.getUnsafe("key1") + Console.log(value) // value1 + } + () + }) +}) + +describe("Date.UTC.makeWithYMDHMSM", () => { + test("Date.UTC.makeWithYMDHMSM", () => { + module Test = { + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + )->Console.log + // 1676911200000 + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + )->Console.log + // 1676911201000 Date.UTC.makeWithYMDHMSM( ~year=2023, @@ -12969,236 +13171,34 @@ describe("Date.make", () => { }) }) -describe("Dict.mapValues", () => { - test("Dict.mapValues", () => { +describe("Error.panic", () => { + test("Error.panic", () => { module Test = { - let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) - - dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] - dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] + try { + Error.panic("Uh oh. This was unexpected!") + } catch { + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") + | None => assert(false) + } + | _ => assert(false) + } } () }) }) -describe("Dict.forEachWithKey", () => { - test("Dict.forEachWithKey", () => { +describe("Error.raise", () => { + test("Error.raise", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let error = Error.make("Everything is upside down.") - dict->Dict.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) - } - () - }) -}) - -describe("Dict.forEach", () => { - test("Dict.forEach", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - - dict->Dict.forEach( - value => { - Console.log(value) - }, - ) - } - () - }) -}) - -describe("Dict.copy", () => { - test("Dict.copy", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let dict2 = dict->Dict.copy - - // Both log `["key1", "key2"]` here. - Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) - } - () - }) -}) - -describe("Dict.assign", () => { - test("Dict.assign", () => { - module Test = { - let dict1 = Dict.make() - dict1->Dict.set("firstKey", 1) - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` - - let dict2 = Dict.make() - dict2->Dict.set("someKey", 2) - dict2->Dict.set("someKey2", 3) - - let dict1 = dict1->Dict.assign(dict2) - - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` - } - () - }) -}) - -describe("Dict.valuesToArray", () => { - test("Dict.valuesToArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let values = dict->Dict.valuesToArray - Console.log(values) // Logs `[1, 2]` to the console - } - () - }) -}) - -describe("Dict.keysToArray", () => { - test("Dict.keysToArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let keys = dict->Dict.keysToArray - Console.log(keys) // Logs `["someKey", "someKey2"]` to the console - } - () - }) -}) - -describe("Dict.toArray", () => { - test("Dict.toArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let asArray = dict->Dict.toArray - Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console - } - () - }) -}) - -describe("Dict.fromIterator", () => { - test("Dict.fromIterator", () => { - module Test = { - let iterator: Iterator.t<(string, int)> = %raw(` - (() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - iterator - ->Dict.fromIterator - ->Dict.valuesToArray - ->assertEqual([1, 2]) - } - () - }) -}) - -describe("Dict.fromArray", () => { - test("Dict.fromArray", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - } - () - }) -}) - -describe("Dict.make", () => { - test("Dict.make", () => { - module Test = { - let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want - - let dict2 = Dict.make() // Or you can let ReScript infer it via usage. - dict2->Dict.set("someKey", 12) - } - () - }) -}) - -describe("Dict.delete", () => { - test("Dict.delete", () => { - module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - dict->Dict.delete("someKey") - } - () - }) -}) - -describe("Dict.set", () => { - test("Dict.set", () => { - module Test = { - let dict = Dict.make() - - dict->Dict.set("someKey", "someValue") - } - () - }) -}) - -describe("Dict.get", () => { - test("Dict.get", () => { - module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - switch dict->Dict.get("someKey") { - | None => Console.log("Nope, didn't have the key.") - | Some(value) => Console.log(value) - } - } - () - }) -}) - -describe("Dict.getUnsafe", () => { - test("Dict.getUnsafe", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let value = dict->Dict.getUnsafe("key1") - Console.log(value) // value1 - } - () - }) -}) - -describe("Error.panic", () => { - test("Error.panic", () => { - module Test = { - try { - Error.panic("Uh oh. This was unexpected!") - } catch { - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") - | None => assert(false) - } - | _ => assert(false) - } - } - () - }) -}) - -describe("Error.raise", () => { - test("Error.raise", () => { - module Test = { - let error = Error.make("Everything is upside down.") - - if 5 > 10 { - error->Error.raise - } else { - Console.log("Phew, sanity still rules.") - } + if 5 > 10 { + error->Error.raise + } else { + Console.log("Phew, sanity still rules.") + } } () }) @@ -14696,193 +14696,43 @@ describe("Map.make", () => { }) }) -describe("Null.flatMap", () => { - test("Null.flatMap", () => { +describe("List.sort", () => { + test("List.sort", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Null.make(value + 1) - } else { - Null.null - } - - Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) - Null.flatMap(Null.make(-4), addIfAboveOne) // null - Null.flatMap(Null.null, addIfAboveOne) // null + List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} } () }) }) -describe("Null.mapOr", () => { - test("Null.mapOr", () => { +describe("List.setAssoc", () => { + test("List.setAssoc", () => { module Test = { - let someValue = Null.make(3) - someValue->Null.mapOr(0, x => x + 5) // 8 + list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} - let noneValue = Null.null - noneValue->Null.mapOr(0, x => x + 5) // 0 + list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + // list{(9, "morning"), (15, "afternoon"), (22, "night")} } () }) }) -describe("Null.map", () => { - test("Null.map", () => { +describe("List.removeAssoc", () => { + test("List.removeAssoc", () => { module Test = { - Null.map(Null.make(3), x => x * x) // Null.make(9) - Null.map(Null.null, x => x * x) // null - } - () - }) -}) - -describe("Null.forEach", () => { - test("Null.forEach", () => { - module Test = { - Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" - Null.forEach(Null.null, x => Console.log(x)) // logs nothing - } - () - }) -}) - -describe("Null.getUnsafe", () => { - test("Null.getUnsafe", () => { - module Test = { - Null.getUnsafe(Null.make(3)) == 3 - Null.getUnsafe(Null.null) // Raises an error - } - () - }) -}) - -describe("Null.getExn", () => { - test("Null.getExn", () => { - module Test = { - Null.getExn(Null.make(3))->assertEqual(3) - - switch Null.getExn(%raw("'ReScript'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "ReScript") - } - - switch Null.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Null.getOr", () => { - test("Null.getOr", () => { - module Test = { - Null.getOr(Null.null, "Banana") // Banana - Null.getOr(Null.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Null.make("Jane")->Null.toOption->greet // "Greetings Jane" - Null.null->Null.toOption->greet // "Greetings Anonymous" - } - () - }) -}) - -describe("Null.fromOption", () => { - test("Null.fromOption", () => { - module Test = { - let optString: option = None - let asNull = optString->Null.fromOption // Null.t - Console.log(asNull == Null.null) // Logs `true` to the console. - } - () - }) -}) - -describe("Null.toOption", () => { - test("Null.toOption", () => { - module Test = { - let nullStr = Null.make("Hello") - - switch nullStr->Null.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } - } - () - }) -}) - -describe("Null.make", () => { - test("Null.make", () => { - module Test = { - let myStr = "Hello" - let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. - } - () - }) -}) - -describe("Null.null", () => { - test("Null.null", () => { - module Test = { - Console.log(null) // Logs `null` to the console. - } - () - }) -}) - -describe("Null.asNullable", () => { - test("Null.asNullable", () => { - module Test = { - let nullValue = Null.make("Hello") - let asNullable = nullValue->Null.asNullable // Nullable.t - } - () - }) -}) - -describe("List.sort", () => { - test("List.sort", () => { - module Test = { - List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} - } - () - }) -}) - -describe("List.setAssoc", () => { - test("List.setAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} - - list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} - - list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - // list{(9, "morning"), (15, "afternoon"), (22, "night")} - } - () - }) -}) - -describe("List.removeAssoc", () => { - test("List.removeAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - // list{(15, "afternoon"), (22, "night")} + list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + // list{(15, "afternoon"), (22, "night")} } () }) @@ -15504,97 +15354,277 @@ describe("List.length", () => { }) }) -describe("Math.Int.random", () => { - test("Math.Int.random", () => { +describe("Nullable.flatMap", () => { + test("Nullable.flatMap", () => { module Test = { - Math.Int.random(2, 5) == 4 - Math.Int.random(505, 2000) == 1276 - Math.Int.random(-7, -2) == -4 - } - () - }) -}) + let addIfAboveOne = value => + if value > 1 { + Nullable.make(value + 1) + } else { + Nullable.null + } -describe("Math.Int.ceil", () => { - test("Math.Int.ceil", () => { - module Test = { - Math.Int.ceil(3.7) == 4 - Math.Int.ceil(3.0) == 3 - Math.Int.ceil(-3.1) == -3 + Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) + Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined + Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined } () }) }) -describe("Math.Int.floor", () => { - test("Math.Int.floor", () => { +describe("Nullable.mapOr", () => { + test("Nullable.mapOr", () => { module Test = { - Math.Int.floor(3.7) == 3 - Math.Int.floor(3.0) == 3 - Math.Int.floor(-3.1) == -4 + let someValue = Nullable.make(3) + someValue->Nullable.mapOr(0, x => x + 5) // 8 + + let noneValue = Nullable.null + noneValue->Nullable.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Math.Int.sign", () => { - test("Math.Int.sign", () => { +describe("Nullable.map", () => { + test("Nullable.map", () => { module Test = { - Math.Int.sign(3) // 1 - Math.Int.sign(-3) // -1 - Math.Int.sign(0) // 0 + Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) + Nullable.map(undefined, x => x * x) // undefined } () }) }) -describe("Math.Int.pow", () => { - test("Math.Int.pow", () => { +describe("Nullable.forEach", () => { + test("Nullable.forEach", () => { module Test = { - Math.Int.pow(2, ~exp=4) // 16 - Math.Int.pow(3, ~exp=4) // 81 + Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" + Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () + Nullable.forEach(undefined, x => Console.log(x)) // returns () } () }) }) -describe("Math.Int.maxMany", () => { - test("Math.Int.maxMany", () => { +describe("Nullable.getUnsafe", () => { + test("Nullable.getUnsafe", () => { module Test = { - Math.Int.maxMany([1, 2]) // 2 - Math.Int.maxMany([-1, -2]) // -1 - Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false + Nullable.getUnsafe(Nullable.make(3)) == 3 + Nullable.getUnsafe(Nullable.null) // Raises an error } () }) }) -describe("Math.Int.max", () => { - test("Math.Int.max", () => { +describe("Nullable.getExn", () => { + test("Nullable.getExn", () => { module Test = { - Math.Int.max(1, 2) // 2 - Math.Int.max(-1, -2) // -1 + switch Nullable.getExn(%raw("'Hello'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "Hello") + } + + switch Nullable.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } + + switch Nullable.getExn(%raw("undefined")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Math.Int.minMany", () => { - test("Math.Int.minMany", () => { +describe("Nullable.getOr", () => { + test("Nullable.getOr", () => { module Test = { - Math.Int.minMany([1, 2]) // 1 - Math.Int.minMany([-1, -2]) // -2 - Math.Int.minMany([])->Int.toFloat->Float.isFinite // false + Nullable.getOr(Nullable.null, "Banana") // Banana + Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" + Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Math.Int.min", () => { - test("Math.Int.min", () => { +describe("Nullable.fromOption", () => { + test("Nullable.fromOption", () => { module Test = { - Math.Int.min(1, 2) // 1 - Math.Int.min(-1, -2) // -2 + let optString = Some("Hello") + let asNullable = optString->Nullable.fromOption // Nullable.t + } + () + }) +}) + +describe("Nullable.toOption", () => { + test("Nullable.toOption", () => { + module Test = { + let nullableString = Nullable.make("Hello") + + switch nullableString->Nullable.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } + } + () + }) +}) + +describe("Nullable.make", () => { + test("Nullable.make", () => { + module Test = { + let myStr = "Hello" + let asNullable = myStr->Nullable.make + + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable + + // Need to do this + switch asNullable->Nullable.toOption { + | Some(value) if value == myStr => Console.log("Yay, values matched!") + | _ => Console.log("Values did not match.") + } + } + () + }) +}) + +describe("Nullable.isNullable", () => { + test("Nullable.isNullable", () => { + module Test = { + let myStr = "Hello" + let asNullable = myStr->Nullable.make + + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable + + // Check if asNullable is not null or undefined + switch asNullable->Nullable.isNullable { + | true => assert(false) + | false => assert(true) + } + } + () + }) +}) + +describe("Nullable.undefined", () => { + test("Nullable.undefined", () => { + module Test = { + Console.log(undefined) // Logs `undefined` to the console. + } + () + }) +}) + +describe("Nullable.null", () => { + test("Nullable.null", () => { + module Test = { + Console.log(Nullable.null) // Logs `null` to the console. + } + () + }) +}) + +describe("Math.Int.random", () => { + test("Math.Int.random", () => { + module Test = { + Math.Int.random(2, 5) == 4 + Math.Int.random(505, 2000) == 1276 + Math.Int.random(-7, -2) == -4 + } + () + }) +}) + +describe("Math.Int.ceil", () => { + test("Math.Int.ceil", () => { + module Test = { + Math.Int.ceil(3.7) == 4 + Math.Int.ceil(3.0) == 3 + Math.Int.ceil(-3.1) == -3 + } + () + }) +}) + +describe("Math.Int.floor", () => { + test("Math.Int.floor", () => { + module Test = { + Math.Int.floor(3.7) == 3 + Math.Int.floor(3.0) == 3 + Math.Int.floor(-3.1) == -4 + } + () + }) +}) + +describe("Math.Int.sign", () => { + test("Math.Int.sign", () => { + module Test = { + Math.Int.sign(3) // 1 + Math.Int.sign(-3) // -1 + Math.Int.sign(0) // 0 + } + () + }) +}) + +describe("Math.Int.pow", () => { + test("Math.Int.pow", () => { + module Test = { + Math.Int.pow(2, ~exp=4) // 16 + Math.Int.pow(3, ~exp=4) // 81 + } + () + }) +}) + +describe("Math.Int.maxMany", () => { + test("Math.Int.maxMany", () => { + module Test = { + Math.Int.maxMany([1, 2]) // 2 + Math.Int.maxMany([-1, -2]) // -1 + Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false + } + () + }) +}) + +describe("Math.Int.max", () => { + test("Math.Int.max", () => { + module Test = { + Math.Int.max(1, 2) // 2 + Math.Int.max(-1, -2) // -1 + } + () + }) +}) + +describe("Math.Int.minMany", () => { + test("Math.Int.minMany", () => { + module Test = { + Math.Int.minMany([1, 2]) // 1 + Math.Int.minMany([-1, -2]) // -2 + Math.Int.minMany([])->Int.toFloat->Float.isFinite // false + } + () + }) +}) + +describe("Math.Int.min", () => { + test("Math.Int.min", () => { + module Test = { + Math.Int.min(1, 2) // 1 + Math.Int.min(-1, -2) // -2 } () }) @@ -16096,82 +16126,78 @@ describe("Math.abs", () => { }) }) -describe("Nullable.flatMap", () => { - test("Nullable.flatMap", () => { +describe("Null.flatMap", () => { + test("Null.flatMap", () => { module Test = { let addIfAboveOne = value => if value > 1 { - Nullable.make(value + 1) + Null.make(value + 1) } else { - Nullable.null + Null.null } - Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) - Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined - Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined + Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) + Null.flatMap(Null.make(-4), addIfAboveOne) // null + Null.flatMap(Null.null, addIfAboveOne) // null } () }) }) -describe("Nullable.mapOr", () => { - test("Nullable.mapOr", () => { +describe("Null.mapOr", () => { + test("Null.mapOr", () => { module Test = { - let someValue = Nullable.make(3) - someValue->Nullable.mapOr(0, x => x + 5) // 8 + let someValue = Null.make(3) + someValue->Null.mapOr(0, x => x + 5) // 8 - let noneValue = Nullable.null - noneValue->Nullable.mapOr(0, x => x + 5) // 0 + let noneValue = Null.null + noneValue->Null.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Nullable.map", () => { - test("Nullable.map", () => { +describe("Null.map", () => { + test("Null.map", () => { module Test = { - Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) - Nullable.map(undefined, x => x * x) // undefined + Null.map(Null.make(3), x => x * x) // Null.make(9) + Null.map(Null.null, x => x * x) // null } () }) }) -describe("Nullable.forEach", () => { - test("Nullable.forEach", () => { +describe("Null.forEach", () => { + test("Null.forEach", () => { module Test = { - Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" - Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () - Nullable.forEach(undefined, x => Console.log(x)) // returns () + Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" + Null.forEach(Null.null, x => Console.log(x)) // logs nothing } () }) }) -describe("Nullable.getUnsafe", () => { - test("Nullable.getUnsafe", () => { +describe("Null.getUnsafe", () => { + test("Null.getUnsafe", () => { module Test = { - Nullable.getUnsafe(Nullable.make(3)) == 3 - Nullable.getUnsafe(Nullable.null) // Raises an error + Null.getUnsafe(Null.make(3)) == 3 + Null.getUnsafe(Null.null) // Raises an error } () }) }) -describe("Nullable.getExn", () => { - test("Nullable.getExn", () => { +describe("Null.getExn", () => { + test("Null.getExn", () => { module Test = { - switch Nullable.getExn(%raw("'Hello'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "Hello") - } + Null.getExn(Null.make(3))->assertEqual(3) - switch Nullable.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) + switch Null.getExn(%raw("'ReScript'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "ReScript") } - switch Nullable.getExn(%raw("undefined")) { + switch Null.getExn(%raw("null")) { | exception Invalid_argument(_) => assert(true) | _ => assert(false) } @@ -16180,38 +16206,39 @@ describe("Nullable.getExn", () => { }) }) -describe("Nullable.getOr", () => { - test("Nullable.getOr", () => { +describe("Null.getOr", () => { + test("Null.getOr", () => { module Test = { - Nullable.getOr(Nullable.null, "Banana") // Banana - Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple + Null.getOr(Null.null, "Banana") // Banana + Null.getOr(Null.make("Apple"), "Banana") // Apple let greet = (firstName: option) => "Greetings " ++ firstName->Option.getOr("Anonymous") - Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" - Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" + Null.make("Jane")->Null.toOption->greet // "Greetings Jane" + Null.null->Null.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Nullable.fromOption", () => { - test("Nullable.fromOption", () => { +describe("Null.fromOption", () => { + test("Null.fromOption", () => { module Test = { - let optString = Some("Hello") - let asNullable = optString->Nullable.fromOption // Nullable.t + let optString: option = None + let asNull = optString->Null.fromOption // Null.t + Console.log(asNull == Null.null) // Logs `true` to the console. } () }) }) -describe("Nullable.toOption", () => { - test("Nullable.toOption", () => { +describe("Null.toOption", () => { + test("Null.toOption", () => { module Test = { - let nullableString = Nullable.make("Hello") + let nullStr = Null.make("Hello") - switch nullableString->Nullable.toOption { + switch nullStr->Null.toOption { | Some(str) => Console.log2("Got string:", str) | None => Console.log("Didn't have a value.") } @@ -16220,57 +16247,30 @@ describe("Nullable.toOption", () => { }) }) -describe("Nullable.make", () => { - test("Nullable.make", () => { - module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Need to do this - switch asNullable->Nullable.toOption { - | Some(value) if value == myStr => Console.log("Yay, values matched!") - | _ => Console.log("Values did not match.") - } - } - () - }) -}) - -describe("Nullable.isNullable", () => { - test("Nullable.isNullable", () => { +describe("Null.make", () => { + test("Null.make", () => { module Test = { let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Check if asNullable is not null or undefined - switch asNullable->Nullable.isNullable { - | true => assert(false) - | false => assert(true) - } + let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. } () }) }) -describe("Nullable.undefined", () => { - test("Nullable.undefined", () => { +describe("Null.null", () => { + test("Null.null", () => { module Test = { - Console.log(undefined) // Logs `undefined` to the console. + Console.log(null) // Logs `null` to the console. } () }) }) -describe("Nullable.null", () => { - test("Nullable.null", () => { +describe("Null.asNullable", () => { + test("Null.asNullable", () => { module Test = { - Console.log(Nullable.null) // Logs `null` to the console. + let nullValue = Null.make("Hello") + let asNullable = nullValue->Null.asNullable // Nullable.t } () }) @@ -16483,6 +16483,186 @@ describe("Object.make", () => { }) }) +describe("Option.all", () => { + test("Option.all", () => { + module Test = { + Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) + Option.all([Some(1), None]) // None + } + () + }) +}) + +describe("Option.compare", () => { + test("Option.compare", () => { + module Test = { + let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) + + Option.compare(Some(3), Some(15), clockCompare) // 0. + Option.compare(Some(3), Some(14), clockCompare) // 1. + Option.compare(Some(2), Some(15), clockCompare) // (-1.) + Option.compare(None, Some(15), clockCompare) // (-1.) + Option.compare(Some(14), None, clockCompare) // 1. + Option.compare(None, None, clockCompare) // 0. + } + () + }) +}) + +describe("Option.equal", () => { + test("Option.equal", () => { + module Test = { + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Option + + equal(Some(3), Some(15), clockEqual) // true + equal(Some(3), None, clockEqual) // false + equal(None, Some(3), clockEqual) // false + equal(None, None, clockEqual) // true + } + () + }) +}) + +describe("Option.isNone", () => { + test("Option.isNone", () => { + module Test = { + Option.isNone(None) // true + Option.isNone(Some(1)) // false + } + () + }) +}) + +describe("Option.isSome", () => { + test("Option.isSome", () => { + module Test = { + Option.isSome(None) // false + Option.isSome(Some(1)) // true + } + () + }) +}) + +describe("Option.orElse", () => { + test("Option.orElse", () => { + module Test = { + Option.orElse(Some(1812), Some(1066)) == Some(1812) + Option.orElse(None, Some(1066)) == Some(1066) + Option.orElse(None, None) == None + } + () + }) +}) + +describe("Option.getOr", () => { + test("Option.getOr", () => { + module Test = { + Option.getOr(None, "Banana") // Banana + Option.getOr(Some("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Some("Jane")->greet // "Greetings Jane" + None->greet // "Greetings Anonymous" + } + () + }) +}) + +describe("Option.flatMap", () => { + test("Option.flatMap", () => { + module Test = { + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Option.flatMap(Some(2), addIfAboveOne) // Some(3) + Option.flatMap(Some(-4), addIfAboveOne) // None + Option.flatMap(None, addIfAboveOne) // None + } + () + }) +}) + +describe("Option.map", () => { + test("Option.map", () => { + module Test = { + Option.map(Some(3), x => x * x) // Some(9) + Option.map(None, x => x * x) // None + } + () + }) +}) + +describe("Option.mapOr", () => { + test("Option.mapOr", () => { + module Test = { + let someValue = Some(3) + someValue->Option.mapOr(0, x => x + 5) // 8 + + let noneValue = None + noneValue->Option.mapOr(0, x => x + 5) // 0 + } + () + }) +}) + +describe("Option.getUnsafe", () => { + test("Option.getUnsafe", () => { + module Test = { + Option.getUnsafe(Some(3)) == 3 + Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` + } + () + }) +}) + +describe("Option.getExn", () => { + test("Option.getExn", () => { + module Test = { + Option.getExn(Some(3))->assertEqual(3) + + switch Option.getExn(None) { + | exception _ => assert(true) + | _ => assert(false) + } + + switch Option.getExn(None, ~message="was None!") { + | exception _ => assert(true) // Raises an Error with the message "was None!" + | _ => assert(false) + } + } + () + }) +}) + +describe("Option.forEach", () => { + test("Option.forEach", () => { + module Test = { + Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" + Option.forEach(None, x => Console.log(x)) // returns () + } + () + }) +}) + +describe("Option.filter", () => { + test("Option.filter", () => { + module Test = { + Option.filter(Some(10), x => x > 5) // Some(10) + Option.filter(Some(4), x => x > 5) // None + Option.filter(None, x => x > 5) // None + } + () + }) +}) + describe("Pervasives.assertEqual", () => { test("Pervasives.assertEqual", () => { module Test = { @@ -16669,181 +16849,306 @@ describe("Pervasives.setTimeout", () => { }) }) -describe("Option.all", () => { - test("Option.all", () => { +describe("Promise.allSettled", () => { + test("Promise.allSettled", () => { module Test = { - Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) - Option.all([Some(1), None]) // None - } - () - }) -}) + open Promise -describe("Option.compare", () => { - test("Option.compare", () => { - module Test = { - let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) + exception TestError(string) - Option.compare(Some(3), Some(15), clockCompare) // 0. - Option.compare(Some(3), Some(14), clockCompare) // 1. - Option.compare(Some(2), Some(15), clockCompare) // (-1.) - Option.compare(None, Some(15), clockCompare) // (-1.) - Option.compare(Some(14), None, clockCompare) // 1. - Option.compare(None, None, clockCompare) // 0. + let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + + allSettled(promises) + ->then( + results => { + results->Array.forEach( + result => { + switch result { + | Fulfilled({value: num}) => Console.log2("Number: ", num) + | Rejected({reason}) => Console.log(reason) + } + }, + ) + + resolve() + }, + ) + ->ignore } () }) }) -describe("Option.equal", () => { - test("Option.equal", () => { +describe("Promise.all", () => { + test("Promise.all", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + open Promise + let promises = [resolve(1), resolve(2), resolve(3)] - open Option + all(promises) + ->then( + results => { + results->Array.forEach( + num => { + Console.log2("Number: ", num) + }, + ) - equal(Some(3), Some(15), clockEqual) // true - equal(Some(3), None, clockEqual) // false - equal(None, Some(3), clockEqual) // false - equal(None, None, clockEqual) // true + resolve() + }, + ) + ->ignore } () }) }) -describe("Option.isNone", () => { - test("Option.isNone", () => { +describe("Promise.any", () => { + test("Promise.any", () => { module Test = { - Option.isNone(None) // true - Option.isNone(Some(1)) // false - } - () - }) -}) + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } -describe("Option.isSome", () => { - test("Option.isSome", () => { - module Test = { - Option.isSome(None) // false - Option.isSome(Some(1)) // true - } - () - }) -}) + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] -describe("Option.orElse", () => { - test("Option.orElse", () => { - module Test = { - Option.orElse(Some(1812), Some(1066)) == Some(1812) - Option.orElse(None, Some(1066)) == Some(1066) - Option.orElse(None, None) == None + any(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Option.getOr", () => { - test("Option.getOr", () => { +describe("Promise.race", () => { + test("Promise.race", () => { module Test = { - Option.getOr(None, "Banana") // Banana - Option.getOr(Some("Apple"), "Banana") // Apple + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - Some("Jane")->greet // "Greetings Jane" - None->greet // "Greetings Anonymous" + race(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Option.flatMap", () => { - test("Option.flatMap", () => { +describe("Promise.finally", () => { + test("Promise.finally", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } + open Promise + exception SomeError(string) + let isDone = ref(false) - Option.flatMap(Some(2), addIfAboveOne) // Some(3) - Option.flatMap(Some(-4), addIfAboveOne) // None - Option.flatMap(None, addIfAboveOne) // None + resolve(5) + ->then( + _ => { + reject(SomeError("test")) + }, + ) + ->then( + v => { + Console.log2("final result", v) + resolve() + }, + ) + ->catch( + _ => { + Console.log("Error handled") + resolve() + }, + ) + ->finally( + () => { + Console.log("finally") + isDone := true + }, + ) + ->then( + () => { + Console.log2("isDone:", isDone.contents) + resolve() + }, + ) + ->ignore } () }) }) -describe("Option.map", () => { - test("Option.map", () => { +describe("Promise.thenResolve", () => { + test("Promise.thenResolve", () => { module Test = { - Option.map(Some(3), x => x * x) // Some(9) - Option.map(None, x => x * x) // None + open Promise + resolve("Anna") + ->thenResolve( + str => { + "Hello " ++ str + }, + ) + ->thenResolve( + str => { + Console.log(str) + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Option.mapOr", () => { - test("Option.mapOr", () => { +describe("Promise.then", () => { + test("Promise.then", () => { module Test = { - let someValue = Some(3) - someValue->Option.mapOr(0, x => x + 5) // 8 - - let noneValue = None - noneValue->Option.mapOr(0, x => x + 5) // 0 + open Promise + resolve(5) + ->then( + num => { + resolve(num + 5) + }, + ) + ->then( + num => { + Console.log2("Your lucky number is: ", num) + resolve() + }, + ) + ->ignore } () }) }) -describe("Option.getUnsafe", () => { - test("Option.getUnsafe", () => { +describe("Promise.catch", () => { + test("Promise.catch", () => { module Test = { - Option.getUnsafe(Some(3)) == 3 - Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` + open Promise + + exception SomeError(string) + + reject(SomeError("this is an error")) + ->then( + _ => { + Ok("This result will never be returned")->resolve + }, + ) + ->catch( + e => { + let msg = switch e { + | SomeError(msg) => "ReScript error occurred: " ++ msg + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(msg) => "JS exception occurred: " ++ msg + | None => "Some other JS value has been thrown" + } + | _ => "Unexpected error occurred" + } + + Error(msg)->resolve + }, + ) + ->then( + result => { + switch result { + | Ok(r) => Console.log2("Operation successful: ", r) + | Error(msg) => Console.log2("Operation failed: ", msg) + }->resolve + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Option.getExn", () => { - test("Option.getExn", () => { +describe("Promise.make", () => { + test("Promise.make", () => { module Test = { - Option.getExn(Some(3))->assertEqual(3) + open Promise - switch Option.getExn(None) { - | exception _ => assert(true) - | _ => assert(false) - } - - switch Option.getExn(None, ~message="was None!") { - | exception _ => assert(true) // Raises an Error with the message "was None!" - | _ => assert(false) - } + let n = 4 + Promise.make( + (resolve, reject) => { + if n < 5 { + resolve("success") + } else { + reject("failed") + } + }, + ) + ->then( + str => { + Console.log(str)->resolve + }, + ) + ->catch( + _ => { + Console.log("Error occurred") + resolve() + }, + ) + ->ignore } () }) }) -describe("Option.forEach", () => { - test("Option.forEach", () => { +describe("Promise.reject", () => { + test("Promise.reject", () => { module Test = { - Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" - Option.forEach(None, x => Console.log(x)) // returns () + exception TestError(string) + + TestError("some rejected value") + ->Promise.reject + ->Promise.catch( + v => { + switch v { + | TestError(msg) => assertEqual(msg, "some rejected value") + | _ => assert(false) + } + Promise.resolve() + }, + ) + ->ignore } () }) }) -describe("Option.filter", () => { - test("Option.filter", () => { +describe("Promise.resolve", () => { + test("Promise.resolve", () => { module Test = { - Option.filter(Some(10), x => x > 5) // Some(10) - Option.filter(Some(4), x => x > 5) // None - Option.filter(None, x => x > 5) // None + let p = Promise.resolve(5) // promise } () }) @@ -17207,311 +17512,6 @@ describe("Result.mapOr", () => { }) }) -describe("Promise.allSettled", () => { - test("Promise.allSettled", () => { - module Test = { - open Promise - - exception TestError(string) - - let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] - - allSettled(promises) - ->then( - results => { - results->Array.forEach( - result => { - switch result { - | Fulfilled({value: num}) => Console.log2("Number: ", num) - | Rejected({reason}) => Console.log(reason) - } - }, - ) - - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.all", () => { - test("Promise.all", () => { - module Test = { - open Promise - let promises = [resolve(1), resolve(2), resolve(3)] - - all(promises) - ->then( - results => { - results->Array.forEach( - num => { - Console.log2("Number: ", num) - }, - ) - - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.any", () => { - test("Promise.any", () => { - module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - any(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) - } - () - }) -}) - -describe("Promise.race", () => { - test("Promise.race", () => { - module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - race(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) - } - () - }) -}) - -describe("Promise.finally", () => { - test("Promise.finally", () => { - module Test = { - open Promise - exception SomeError(string) - let isDone = ref(false) - - resolve(5) - ->then( - _ => { - reject(SomeError("test")) - }, - ) - ->then( - v => { - Console.log2("final result", v) - resolve() - }, - ) - ->catch( - _ => { - Console.log("Error handled") - resolve() - }, - ) - ->finally( - () => { - Console.log("finally") - isDone := true - }, - ) - ->then( - () => { - Console.log2("isDone:", isDone.contents) - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.thenResolve", () => { - test("Promise.thenResolve", () => { - module Test = { - open Promise - resolve("Anna") - ->thenResolve( - str => { - "Hello " ++ str - }, - ) - ->thenResolve( - str => { - Console.log(str) - }, - ) - ->ignore // Ignore needed for side-effects - } - () - }) -}) - -describe("Promise.then", () => { - test("Promise.then", () => { - module Test = { - open Promise - resolve(5) - ->then( - num => { - resolve(num + 5) - }, - ) - ->then( - num => { - Console.log2("Your lucky number is: ", num) - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.catch", () => { - test("Promise.catch", () => { - module Test = { - open Promise - - exception SomeError(string) - - reject(SomeError("this is an error")) - ->then( - _ => { - Ok("This result will never be returned")->resolve - }, - ) - ->catch( - e => { - let msg = switch e { - | SomeError(msg) => "ReScript error occurred: " ++ msg - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(msg) => "JS exception occurred: " ++ msg - | None => "Some other JS value has been thrown" - } - | _ => "Unexpected error occurred" - } - - Error(msg)->resolve - }, - ) - ->then( - result => { - switch result { - | Ok(r) => Console.log2("Operation successful: ", r) - | Error(msg) => Console.log2("Operation failed: ", msg) - }->resolve - }, - ) - ->ignore // Ignore needed for side-effects - } - () - }) -}) - -describe("Promise.make", () => { - test("Promise.make", () => { - module Test = { - open Promise - - let n = 4 - Promise.make( - (resolve, reject) => { - if n < 5 { - resolve("success") - } else { - reject("failed") - } - }, - ) - ->then( - str => { - Console.log(str)->resolve - }, - ) - ->catch( - _ => { - Console.log("Error occurred") - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.reject", () => { - test("Promise.reject", () => { - module Test = { - exception TestError(string) - - TestError("some rejected value") - ->Promise.reject - ->Promise.catch( - v => { - switch v { - | TestError(msg) => assertEqual(msg, "some rejected value") - | _ => assert(false) - } - Promise.resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.resolve", () => { - test("Promise.resolve", () => { - module Test = { - let p = Promise.resolve(5) // promise - } - () - }) -}) - describe("Set.toArray", () => { test("Set.toArray", () => { module Test = { diff --git a/tests/docstrings_examples/mocha_full_test.res.mjs b/tests/docstrings_examples/generated_mocha_test.res.mjs similarity index 99% rename from tests/docstrings_examples/mocha_full_test.res.mjs rename to tests/docstrings_examples/generated_mocha_test.res.mjs index 20344005cf..abc53bd4c0 100644 --- a/tests/docstrings_examples/mocha_full_test.res.mjs +++ b/tests/docstrings_examples/generated_mocha_test.res.mjs @@ -3365,9 +3365,9 @@ Mocha.describe("Belt.Result.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 2737, - 13 + "generated_mocha_test.res", + 2698, + 7 ], Error: new Error() }; @@ -3473,9 +3473,9 @@ Mocha.describe("Belt.Option.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 2891, - 13 + "generated_mocha_test.res", + 2851, + 7 ], Error: new Error() }; @@ -6916,9 +6916,9 @@ Mocha.describe("Belt.List.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 5213, - 13 + "generated_mocha_test.res", + 5127, + 7 ], Error: new Error() }; @@ -6993,9 +6993,9 @@ Mocha.describe("Belt.List.tailExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 5252, - 13 + "generated_mocha_test.res", + 5165, + 7 ], Error: new Error() }; @@ -7044,9 +7044,9 @@ Mocha.describe("Belt.List.headExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 5278, - 13 + "generated_mocha_test.res", + 5190, + 7 ], Error: new Error() }; @@ -9500,9 +9500,9 @@ Mocha.describe("Belt_List.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 6599, - 13 + "generated_mocha_test.res", + 6471, + 7 ], Error: new Error() }; @@ -9577,9 +9577,9 @@ Mocha.describe("Belt_List.tailExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 6638, - 13 + "generated_mocha_test.res", + 6509, + 7 ], Error: new Error() }; @@ -9628,9 +9628,9 @@ Mocha.describe("Belt_List.headExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 6664, - 13 + "generated_mocha_test.res", + 6534, + 7 ], Error: new Error() }; @@ -10173,35 +10173,6 @@ Mocha.describe("Belt_Map.Int", () => { Mocha.test("Belt_Map.Int", () => {}); }); -Mocha.describe("Belt_MapString.findFirstBy", () => { - Mocha.test("Belt_MapString.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - Mocha.describe("Belt_MapDict.findFirstBy", () => { Mocha.test("Belt_MapDict.findFirstBy", () => { let cmp = Primitive_object.compare; @@ -10262,6 +10233,35 @@ Mocha.describe("Belt_MapInt.findFirstBy", () => { }); }); +Mocha.describe("Belt_MapString.findFirstBy", () => { + Mocha.test("Belt_MapString.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + Mocha.describe("Belt_MutableSet.split", () => { Mocha.test("Belt_MutableSet.split", () => { let cmp = Primitive_object.compare; @@ -10797,42 +10797,6 @@ Mocha.describe("Belt_MutableSet.fromArray", () => { }); }); -Mocha.describe("Belt_Range.someBy", () => { - Mocha.test("Belt_Range.someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Range.some", () => { - Mocha.test("Belt_Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); -}); - -Mocha.describe("Belt_Range.everyBy", () => { - Mocha.test("Belt_Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Range.every", () => { - Mocha.test("Belt_Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); -}); - -Mocha.describe("Belt_Range.forEach", () => { - Mocha.test("Belt_Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); -}); - Mocha.describe("Belt_Option.cmp", () => { Mocha.test("Belt_Option.cmp", () => { let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); @@ -10930,9 +10894,9 @@ Mocha.describe("Belt_Option.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 7724, - 13 + "generated_mocha_test.res", + 7531, + 7 ], Error: new Error() }; @@ -11133,9 +11097,9 @@ Mocha.describe("Belt_Result.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 7871, - 13 + "generated_mocha_test.res", + 7678, + 7 ], Error: new Error() }; @@ -11144,6 +11108,42 @@ Mocha.describe("Belt_Result.getExn", () => { }); }); +Mocha.describe("Belt_Range.someBy", () => { + Mocha.test("Belt_Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt_Range.some", () => { + Mocha.test("Belt_Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); +}); + +Mocha.describe("Belt_Range.everyBy", () => { + Mocha.test("Belt_Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt_Range.every", () => { + Mocha.test("Belt_Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); +}); + +Mocha.describe("Belt_Range.forEach", () => { + Mocha.test("Belt_Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); +}); + Mocha.describe("Belt_SetDict.split", () => { Mocha.test("Belt_SetDict.split", () => { let cmp = Primitive_object.compare; @@ -12866,39 +12866,48 @@ Mocha.describe("Belt_SortArray.strictlySortedLength", () => { }); }); -Mocha.describe("BigInt.toLocaleString", () => { - Mocha.test("BigInt.toLocaleString", () => { - console.log((123n).toString()); - }); -}); - -Mocha.describe("BigInt.toString", () => { - Mocha.test("BigInt.toString", () => { - console.log((123n).toString()); +Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapString.S.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.describe("BigInt.fromStringExn", () => { - Mocha.test("BigInt.fromStringExn", () => { - BigInt("123"); - BigInt(""); - BigInt("0x11"); - BigInt("0b11"); - BigInt("0o11"); - try { - BigInt("a"); - } catch (raw__error) { - let _error = Primitive_exceptions.internalToException(raw__error); - if (_error.RE_EXN_ID !== Exn.$$Error) { - throw _error; - } - - } +Mocha.describe("Belt_internalMapString.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapString.S.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_internalSetString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { +Mocha.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { let arr = [ "ant", "bee", @@ -12915,8 +12924,8 @@ Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { }); }); -Mocha.describe("Belt_internalSetString.A.eq", () => { - Mocha.test("Belt_internalSetString.A.eq", () => { +Mocha.describe("Belt_internalMapString.A.eq", () => { + Mocha.test("Belt_internalMapString.A.eq", () => { Belt_Array.eq([ 1, 2, @@ -12929,8 +12938,8 @@ Mocha.describe("Belt_internalSetString.A.eq", () => { }); }); -Mocha.describe("Belt_internalSetString.A.cmp", () => { - Mocha.test("Belt_internalSetString.A.cmp", () => { +Mocha.describe("Belt_internalMapString.A.cmp", () => { + Mocha.test("Belt_internalMapString.A.cmp", () => { Belt_Array.cmp([ 1, 3, @@ -12961,8 +12970,8 @@ Mocha.describe("Belt_internalSetString.A.cmp", () => { }); }); -Mocha.describe("Belt_internalSetString.A.some2", () => { - Mocha.test("Belt_internalSetString.A.some2", () => { +Mocha.describe("Belt_internalMapString.A.some2", () => { + Mocha.test("Belt_internalMapString.A.some2", () => { Belt_Array.some2([ 0, 2 @@ -12982,8 +12991,8 @@ Mocha.describe("Belt_internalSetString.A.some2", () => { }); }); -Mocha.describe("Belt_internalSetString.A.every2", () => { - Mocha.test("Belt_internalSetString.A.every2", () => { +Mocha.describe("Belt_internalMapString.A.every2", () => { + Mocha.test("Belt_internalMapString.A.every2", () => { Belt_Array.every2([ 1, 2, @@ -13007,8 +13016,8 @@ Mocha.describe("Belt_internalSetString.A.every2", () => { }); }); -Mocha.describe("Belt_internalSetString.A.every", () => { - Mocha.test("Belt_internalSetString.A.every", () => { +Mocha.describe("Belt_internalMapString.A.every", () => { + Mocha.test("Belt_internalMapString.A.every", () => { Belt_Array.every([ 1, 3, @@ -13022,8 +13031,8 @@ Mocha.describe("Belt_internalSetString.A.every", () => { }); }); -Mocha.describe("Belt_internalSetString.A.some", () => { - Mocha.test("Belt_internalSetString.A.some", () => { +Mocha.describe("Belt_internalMapString.A.some", () => { + Mocha.test("Belt_internalMapString.A.some", () => { Belt_Array.some([ 2, 3, @@ -13037,8 +13046,8 @@ Mocha.describe("Belt_internalSetString.A.some", () => { }); }); -Mocha.describe("Belt_internalSetString.A.joinWith", () => { - Mocha.test("Belt_internalSetString.A.joinWith", () => { +Mocha.describe("Belt_internalMapString.A.joinWith", () => { + Mocha.test("Belt_internalMapString.A.joinWith", () => { Belt_Array.joinWith([ 0, 1 @@ -13048,8 +13057,8 @@ Mocha.describe("Belt_internalSetString.A.joinWith", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { +Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { Belt_Array.reduceWithIndex([ 1, 2, @@ -13059,8 +13068,8 @@ Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { +Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { Belt_Array.reduceReverse2([ 1, 2, @@ -13072,8 +13081,8 @@ Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse", () => { +Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse", () => { Belt_Array.reduceReverse([ "a", "b", @@ -13083,8 +13092,8 @@ Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reduce", () => { - Mocha.test("Belt_internalSetString.A.reduce", () => { +Mocha.describe("Belt_internalMapString.A.reduce", () => { + Mocha.test("Belt_internalMapString.A.reduce", () => { Belt_Array.reduce([ 2, 3, @@ -13099,8 +13108,8 @@ Mocha.describe("Belt_internalSetString.A.reduce", () => { }); }); -Mocha.describe("Belt_internalSetString.A.partition", () => { - Mocha.test("Belt_internalSetString.A.partition", () => { +Mocha.describe("Belt_internalMapString.A.partition", () => { + Mocha.test("Belt_internalMapString.A.partition", () => { Primitive_object.equal(Belt_Array.partition([ 1, 2, @@ -13138,8 +13147,8 @@ Mocha.describe("Belt_internalSetString.A.partition", () => { }); }); -Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { +Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { Primitive_object.equal(Belt_Array.mapWithIndex([ 1, 2, @@ -13152,8 +13161,8 @@ Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetString.A.forEachWithIndex", () => { +Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapString.A.forEachWithIndex", () => { Belt_Array.forEachWithIndex([ "a", "b", @@ -13175,8 +13184,8 @@ Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetString.A.keepMap", () => { - Mocha.test("Belt_internalSetString.A.keepMap", () => { +Mocha.describe("Belt_internalMapString.A.keepMap", () => { + Mocha.test("Belt_internalMapString.A.keepMap", () => { Primitive_object.equal(Belt_Array.keepMap([ 1, 2, @@ -13190,9 +13199,9 @@ Mocha.describe("Belt_internalSetString.A.keepMap", () => { }); }); -Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ +Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ 1, 2, 3 @@ -13200,8 +13209,8 @@ Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { - Mocha.test("Belt_internalSetString.A.getIndexBy", () => { +Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { + Mocha.test("Belt_internalMapString.A.getIndexBy", () => { Primitive_object.equal(Belt_Array.getIndexBy([ 1, 4, @@ -13216,8 +13225,8 @@ Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { }); }); -Mocha.describe("Belt_internalSetString.A.getBy", () => { - Mocha.test("Belt_internalSetString.A.getBy", () => { +Mocha.describe("Belt_internalMapString.A.getBy", () => { + Mocha.test("Belt_internalMapString.A.getBy", () => { Primitive_object.equal(Belt_Array.getBy([ 1, 4, @@ -13232,8 +13241,8 @@ Mocha.describe("Belt_internalSetString.A.getBy", () => { }); }); -Mocha.describe("Belt_internalSetString.A.flatMap", () => { - Mocha.test("Belt_internalSetString.A.flatMap", () => { +Mocha.describe("Belt_internalMapString.A.flatMap", () => { + Mocha.test("Belt_internalMapString.A.flatMap", () => { Primitive_object.equal(Belt_Array.flatMap([ 1, 2 @@ -13249,8 +13258,8 @@ Mocha.describe("Belt_internalSetString.A.flatMap", () => { }); }); -Mocha.describe("Belt_internalSetString.A.map", () => { - Mocha.test("Belt_internalSetString.A.map", () => { +Mocha.describe("Belt_internalMapString.A.map", () => { + Mocha.test("Belt_internalMapString.A.map", () => { Primitive_object.equal(Belt_Array.map([ 1, 2 @@ -13261,8 +13270,8 @@ Mocha.describe("Belt_internalSetString.A.map", () => { }); }); -Mocha.describe("Belt_internalSetString.A.forEach", () => { - Mocha.test("Belt_internalSetString.A.forEach", () => { +Mocha.describe("Belt_internalMapString.A.forEach", () => { + Mocha.test("Belt_internalMapString.A.forEach", () => { Belt_Array.forEach([ "a", "b", @@ -13284,8 +13293,8 @@ Mocha.describe("Belt_internalSetString.A.forEach", () => { }); }); -Mocha.describe("Belt_internalSetString.A.blit", () => { - Mocha.test("Belt_internalSetString.A.blit", () => { +Mocha.describe("Belt_internalMapString.A.blit", () => { + Mocha.test("Belt_internalMapString.A.blit", () => { let v1 = [ 10, 11, @@ -13331,8 +13340,8 @@ Mocha.describe("Belt_internalSetString.A.blit", () => { }); }); -Mocha.describe("Belt_internalSetString.A.fill", () => { - Mocha.test("Belt_internalSetString.A.fill", () => { +Mocha.describe("Belt_internalMapString.A.fill", () => { + Mocha.test("Belt_internalMapString.A.fill", () => { let arr = Belt_Array.makeBy(5, i => i); Belt_Array.fill(arr, 2, 2, 9); Primitive_object.equal(arr, [ @@ -13353,8 +13362,8 @@ Mocha.describe("Belt_internalSetString.A.fill", () => { }); }); -Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetString.A.sliceToEnd", () => { +Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapString.A.sliceToEnd", () => { Primitive_object.equal(Belt_Array.sliceToEnd([ 10, 11, @@ -13387,8 +13396,8 @@ Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { }); }); -Mocha.describe("Belt_internalSetString.A.slice", () => { - Mocha.test("Belt_internalSetString.A.slice", () => { +Mocha.describe("Belt_internalMapString.A.slice", () => { + Mocha.test("Belt_internalMapString.A.slice", () => { Primitive_object.equal(Belt_Array.slice([ 10, 11, @@ -13431,8 +13440,8 @@ Mocha.describe("Belt_internalSetString.A.slice", () => { }); }); -Mocha.describe("Belt_internalSetString.A.concatMany", () => { - Mocha.test("Belt_internalSetString.A.concatMany", () => { +Mocha.describe("Belt_internalMapString.A.concatMany", () => { + Mocha.test("Belt_internalMapString.A.concatMany", () => { Primitive_object.equal(Belt_Array.concatMany([ [ 1, @@ -13461,8 +13470,8 @@ Mocha.describe("Belt_internalSetString.A.concatMany", () => { }); }); -Mocha.describe("Belt_internalSetString.A.concat", () => { - Mocha.test("Belt_internalSetString.A.concat", () => { +Mocha.describe("Belt_internalMapString.A.concat", () => { + Mocha.test("Belt_internalMapString.A.concat", () => { Primitive_object.equal(Belt_Array.concat([ 1, 2, @@ -13489,8 +13498,8 @@ Mocha.describe("Belt_internalSetString.A.concat", () => { }); }); -Mocha.describe("Belt_internalSetString.A.unzip", () => { - Mocha.test("Belt_internalSetString.A.unzip", () => { +Mocha.describe("Belt_internalMapString.A.unzip", () => { + Mocha.test("Belt_internalMapString.A.unzip", () => { Primitive_object.equal(Belt_Array.unzip([ [ 1, @@ -13544,8 +13553,8 @@ Mocha.describe("Belt_internalSetString.A.unzip", () => { }); }); -Mocha.describe("Belt_internalSetString.A.zipBy", () => { - Mocha.test("Belt_internalSetString.A.zipBy", () => { +Mocha.describe("Belt_internalMapString.A.zipBy", () => { + Mocha.test("Belt_internalMapString.A.zipBy", () => { Primitive_object.equal(Belt_Array.zipBy([ 1, 2, @@ -13560,8 +13569,8 @@ Mocha.describe("Belt_internalSetString.A.zipBy", () => { }); }); -Mocha.describe("Belt_internalSetString.A.zip", () => { - Mocha.test("Belt_internalSetString.A.zip", () => { +Mocha.describe("Belt_internalMapString.A.zip", () => { + Mocha.test("Belt_internalMapString.A.zip", () => { Primitive_object.equal(Belt_Array.zip([ 1, 2 @@ -13582,8 +13591,8 @@ Mocha.describe("Belt_internalSetString.A.zip", () => { }); }); -Mocha.describe("Belt_internalSetString.A.makeBy", () => { - Mocha.test("Belt_internalSetString.A.makeBy", () => { +Mocha.describe("Belt_internalMapString.A.makeBy", () => { + Mocha.test("Belt_internalMapString.A.makeBy", () => { Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ 0, 1, @@ -13601,8 +13610,8 @@ Mocha.describe("Belt_internalSetString.A.makeBy", () => { }); }); -Mocha.describe("Belt_internalSetString.A.rangeBy", () => { - Mocha.test("Belt_internalSetString.A.rangeBy", () => { +Mocha.describe("Belt_internalMapString.A.rangeBy", () => { + Mocha.test("Belt_internalMapString.A.rangeBy", () => { Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, 3, @@ -13624,8 +13633,8 @@ Mocha.describe("Belt_internalSetString.A.rangeBy", () => { }); }); -Mocha.describe("Belt_internalSetString.A.range", () => { - Mocha.test("Belt_internalSetString.A.range", () => { +Mocha.describe("Belt_internalMapString.A.range", () => { + Mocha.test("Belt_internalMapString.A.range", () => { Primitive_object.equal(Belt_Array.range(0, 3), [ 0, 1, @@ -13637,8 +13646,8 @@ Mocha.describe("Belt_internalSetString.A.range", () => { }); }); -Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { +Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { let arr = new Array(5); console.log(Belt_Array.getExn(arr, 0)); Belt_Array.setExn(arr, 0, "example"); @@ -13646,15 +13655,15 @@ Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { }); }); -Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { +Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { let arr = new Array(5); Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Belt_internalSetString.A.reverse", () => { - Mocha.test("Belt_internalSetString.A.reverse", () => { +Mocha.describe("Belt_internalMapString.A.reverse", () => { + Mocha.test("Belt_internalMapString.A.reverse", () => { Primitive_object.equal(Belt_Array.reverse([ 10, 11, @@ -13671,8 +13680,8 @@ Mocha.describe("Belt_internalSetString.A.reverse", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { +Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { let arr = [ 10, 11, @@ -13691,8 +13700,8 @@ Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { }); }); -Mocha.describe("Belt_internalSetString.A.get", () => { - Mocha.test("Belt_internalSetString.A.get", () => { +Mocha.describe("Belt_internalMapString.A.get", () => { + Mocha.test("Belt_internalMapString.A.get", () => { Primitive_object.equal(Belt_Array.get([ "a", "b", @@ -13711,8 +13720,39 @@ Mocha.describe("Belt_internalSetString.A.get", () => { }); }); -Mocha.describe("Belt_internalSetString.A.length", () => { - Mocha.test("Belt_internalSetString.A.length", () => {}); +Mocha.describe("Belt_internalMapString.A.length", () => { + Mocha.test("Belt_internalMapString.A.length", () => {}); +}); + +Mocha.describe("BigInt.toLocaleString", () => { + Mocha.test("BigInt.toLocaleString", () => { + console.log((123n).toString()); + }); +}); + +Mocha.describe("BigInt.toString", () => { + Mocha.test("BigInt.toString", () => { + console.log((123n).toString()); + }); +}); + +Mocha.describe("BigInt.fromStringExn", () => { + Mocha.test("BigInt.fromStringExn", () => { + BigInt("123"); + BigInt(""); + BigInt("0x11"); + BigInt("0b11"); + BigInt("0o11"); + try { + BigInt("a"); + } catch (raw__error) { + let _error = Primitive_exceptions.internalToException(raw__error); + if (_error.RE_EXN_ID !== Exn.$$Error) { + throw _error; + } + + } + }); }); Mocha.describe("Belt_internalMapInt.S.binarySearchBy", () => { @@ -14573,48 +14613,8 @@ Mocha.describe("Belt_internalMapInt.A.length", () => { Mocha.test("Belt_internalMapInt.A.length", () => {}); }); -Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { - Mocha.test("Belt_internalMapString.S.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.describe("Belt_internalMapString.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapString.S.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.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { +Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { let arr = [ "ant", "bee", @@ -14631,8 +14631,8 @@ Mocha.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { }); }); -Mocha.describe("Belt_internalMapString.A.eq", () => { - Mocha.test("Belt_internalMapString.A.eq", () => { +Mocha.describe("Belt_internalSetInt.A.eq", () => { + Mocha.test("Belt_internalSetInt.A.eq", () => { Belt_Array.eq([ 1, 2, @@ -14645,8 +14645,8 @@ Mocha.describe("Belt_internalMapString.A.eq", () => { }); }); -Mocha.describe("Belt_internalMapString.A.cmp", () => { - Mocha.test("Belt_internalMapString.A.cmp", () => { +Mocha.describe("Belt_internalSetInt.A.cmp", () => { + Mocha.test("Belt_internalSetInt.A.cmp", () => { Belt_Array.cmp([ 1, 3, @@ -14677,8 +14677,8 @@ Mocha.describe("Belt_internalMapString.A.cmp", () => { }); }); -Mocha.describe("Belt_internalMapString.A.some2", () => { - Mocha.test("Belt_internalMapString.A.some2", () => { +Mocha.describe("Belt_internalSetInt.A.some2", () => { + Mocha.test("Belt_internalSetInt.A.some2", () => { Belt_Array.some2([ 0, 2 @@ -14698,8 +14698,8 @@ Mocha.describe("Belt_internalMapString.A.some2", () => { }); }); -Mocha.describe("Belt_internalMapString.A.every2", () => { - Mocha.test("Belt_internalMapString.A.every2", () => { +Mocha.describe("Belt_internalSetInt.A.every2", () => { + Mocha.test("Belt_internalSetInt.A.every2", () => { Belt_Array.every2([ 1, 2, @@ -14723,8 +14723,8 @@ Mocha.describe("Belt_internalMapString.A.every2", () => { }); }); -Mocha.describe("Belt_internalMapString.A.every", () => { - Mocha.test("Belt_internalMapString.A.every", () => { +Mocha.describe("Belt_internalSetInt.A.every", () => { + Mocha.test("Belt_internalSetInt.A.every", () => { Belt_Array.every([ 1, 3, @@ -14738,8 +14738,8 @@ Mocha.describe("Belt_internalMapString.A.every", () => { }); }); -Mocha.describe("Belt_internalMapString.A.some", () => { - Mocha.test("Belt_internalMapString.A.some", () => { +Mocha.describe("Belt_internalSetInt.A.some", () => { + Mocha.test("Belt_internalSetInt.A.some", () => { Belt_Array.some([ 2, 3, @@ -14753,8 +14753,8 @@ Mocha.describe("Belt_internalMapString.A.some", () => { }); }); -Mocha.describe("Belt_internalMapString.A.joinWith", () => { - Mocha.test("Belt_internalMapString.A.joinWith", () => { +Mocha.describe("Belt_internalSetInt.A.joinWith", () => { + Mocha.test("Belt_internalSetInt.A.joinWith", () => { Belt_Array.joinWith([ 0, 1 @@ -14764,8 +14764,8 @@ Mocha.describe("Belt_internalMapString.A.joinWith", () => { }); }); -Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { +Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { Belt_Array.reduceWithIndex([ 1, 2, @@ -14775,8 +14775,8 @@ Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { +Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { Belt_Array.reduceReverse2([ 1, 2, @@ -14788,8 +14788,8 @@ Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse", () => { +Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { Belt_Array.reduceReverse([ "a", "b", @@ -14799,8 +14799,8 @@ Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { }); }); -Mocha.describe("Belt_internalMapString.A.reduce", () => { - Mocha.test("Belt_internalMapString.A.reduce", () => { +Mocha.describe("Belt_internalSetInt.A.reduce", () => { + Mocha.test("Belt_internalSetInt.A.reduce", () => { Belt_Array.reduce([ 2, 3, @@ -14815,8 +14815,8 @@ Mocha.describe("Belt_internalMapString.A.reduce", () => { }); }); -Mocha.describe("Belt_internalMapString.A.partition", () => { - Mocha.test("Belt_internalMapString.A.partition", () => { +Mocha.describe("Belt_internalSetInt.A.partition", () => { + Mocha.test("Belt_internalSetInt.A.partition", () => { Primitive_object.equal(Belt_Array.partition([ 1, 2, @@ -14854,8 +14854,8 @@ Mocha.describe("Belt_internalMapString.A.partition", () => { }); }); -Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { +Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { Primitive_object.equal(Belt_Array.mapWithIndex([ 1, 2, @@ -14868,8 +14868,8 @@ Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { }); }); -Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapString.A.forEachWithIndex", () => { +Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.forEachWithIndex", () => { Belt_Array.forEachWithIndex([ "a", "b", @@ -14891,8 +14891,8 @@ Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { }); }); -Mocha.describe("Belt_internalMapString.A.keepMap", () => { - Mocha.test("Belt_internalMapString.A.keepMap", () => { +Mocha.describe("Belt_internalSetInt.A.keepMap", () => { + Mocha.test("Belt_internalSetInt.A.keepMap", () => { Primitive_object.equal(Belt_Array.keepMap([ 1, 2, @@ -14906,8 +14906,8 @@ Mocha.describe("Belt_internalMapString.A.keepMap", () => { }); }); -Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { +Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { Primitive_object.equal(Belt_Array.keepWithIndex([ 1, 2, @@ -14916,8 +14916,8 @@ Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { }); }); -Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { - Mocha.test("Belt_internalMapString.A.getIndexBy", () => { +Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { + Mocha.test("Belt_internalSetInt.A.getIndexBy", () => { Primitive_object.equal(Belt_Array.getIndexBy([ 1, 4, @@ -14932,8 +14932,8 @@ Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.getBy", () => { - Mocha.test("Belt_internalMapString.A.getBy", () => { +Mocha.describe("Belt_internalSetInt.A.getBy", () => { + Mocha.test("Belt_internalSetInt.A.getBy", () => { Primitive_object.equal(Belt_Array.getBy([ 1, 4, @@ -14948,8 +14948,8 @@ Mocha.describe("Belt_internalMapString.A.getBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.flatMap", () => { - Mocha.test("Belt_internalMapString.A.flatMap", () => { +Mocha.describe("Belt_internalSetInt.A.flatMap", () => { + Mocha.test("Belt_internalSetInt.A.flatMap", () => { Primitive_object.equal(Belt_Array.flatMap([ 1, 2 @@ -14965,8 +14965,8 @@ Mocha.describe("Belt_internalMapString.A.flatMap", () => { }); }); -Mocha.describe("Belt_internalMapString.A.map", () => { - Mocha.test("Belt_internalMapString.A.map", () => { +Mocha.describe("Belt_internalSetInt.A.map", () => { + Mocha.test("Belt_internalSetInt.A.map", () => { Primitive_object.equal(Belt_Array.map([ 1, 2 @@ -14977,8 +14977,8 @@ Mocha.describe("Belt_internalMapString.A.map", () => { }); }); -Mocha.describe("Belt_internalMapString.A.forEach", () => { - Mocha.test("Belt_internalMapString.A.forEach", () => { +Mocha.describe("Belt_internalSetInt.A.forEach", () => { + Mocha.test("Belt_internalSetInt.A.forEach", () => { Belt_Array.forEach([ "a", "b", @@ -15000,8 +15000,8 @@ Mocha.describe("Belt_internalMapString.A.forEach", () => { }); }); -Mocha.describe("Belt_internalMapString.A.blit", () => { - Mocha.test("Belt_internalMapString.A.blit", () => { +Mocha.describe("Belt_internalSetInt.A.blit", () => { + Mocha.test("Belt_internalSetInt.A.blit", () => { let v1 = [ 10, 11, @@ -15047,8 +15047,8 @@ Mocha.describe("Belt_internalMapString.A.blit", () => { }); }); -Mocha.describe("Belt_internalMapString.A.fill", () => { - Mocha.test("Belt_internalMapString.A.fill", () => { +Mocha.describe("Belt_internalSetInt.A.fill", () => { + Mocha.test("Belt_internalSetInt.A.fill", () => { let arr = Belt_Array.makeBy(5, i => i); Belt_Array.fill(arr, 2, 2, 9); Primitive_object.equal(arr, [ @@ -15069,8 +15069,8 @@ Mocha.describe("Belt_internalMapString.A.fill", () => { }); }); -Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapString.A.sliceToEnd", () => { +Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetInt.A.sliceToEnd", () => { Primitive_object.equal(Belt_Array.sliceToEnd([ 10, 11, @@ -15103,8 +15103,8 @@ Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { }); }); -Mocha.describe("Belt_internalMapString.A.slice", () => { - Mocha.test("Belt_internalMapString.A.slice", () => { +Mocha.describe("Belt_internalSetInt.A.slice", () => { + Mocha.test("Belt_internalSetInt.A.slice", () => { Primitive_object.equal(Belt_Array.slice([ 10, 11, @@ -15147,8 +15147,8 @@ Mocha.describe("Belt_internalMapString.A.slice", () => { }); }); -Mocha.describe("Belt_internalMapString.A.concatMany", () => { - Mocha.test("Belt_internalMapString.A.concatMany", () => { +Mocha.describe("Belt_internalSetInt.A.concatMany", () => { + Mocha.test("Belt_internalSetInt.A.concatMany", () => { Primitive_object.equal(Belt_Array.concatMany([ [ 1, @@ -15177,8 +15177,8 @@ Mocha.describe("Belt_internalMapString.A.concatMany", () => { }); }); -Mocha.describe("Belt_internalMapString.A.concat", () => { - Mocha.test("Belt_internalMapString.A.concat", () => { +Mocha.describe("Belt_internalSetInt.A.concat", () => { + Mocha.test("Belt_internalSetInt.A.concat", () => { Primitive_object.equal(Belt_Array.concat([ 1, 2, @@ -15205,8 +15205,8 @@ Mocha.describe("Belt_internalMapString.A.concat", () => { }); }); -Mocha.describe("Belt_internalMapString.A.unzip", () => { - Mocha.test("Belt_internalMapString.A.unzip", () => { +Mocha.describe("Belt_internalSetInt.A.unzip", () => { + Mocha.test("Belt_internalSetInt.A.unzip", () => { Primitive_object.equal(Belt_Array.unzip([ [ 1, @@ -15260,8 +15260,8 @@ Mocha.describe("Belt_internalMapString.A.unzip", () => { }); }); -Mocha.describe("Belt_internalMapString.A.zipBy", () => { - Mocha.test("Belt_internalMapString.A.zipBy", () => { +Mocha.describe("Belt_internalSetInt.A.zipBy", () => { + Mocha.test("Belt_internalSetInt.A.zipBy", () => { Primitive_object.equal(Belt_Array.zipBy([ 1, 2, @@ -15276,8 +15276,8 @@ Mocha.describe("Belt_internalMapString.A.zipBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.zip", () => { - Mocha.test("Belt_internalMapString.A.zip", () => { +Mocha.describe("Belt_internalSetInt.A.zip", () => { + Mocha.test("Belt_internalSetInt.A.zip", () => { Primitive_object.equal(Belt_Array.zip([ 1, 2 @@ -15298,8 +15298,8 @@ Mocha.describe("Belt_internalMapString.A.zip", () => { }); }); -Mocha.describe("Belt_internalMapString.A.makeBy", () => { - Mocha.test("Belt_internalMapString.A.makeBy", () => { +Mocha.describe("Belt_internalSetInt.A.makeBy", () => { + Mocha.test("Belt_internalSetInt.A.makeBy", () => { Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ 0, 1, @@ -15317,8 +15317,8 @@ Mocha.describe("Belt_internalMapString.A.makeBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.rangeBy", () => { - Mocha.test("Belt_internalMapString.A.rangeBy", () => { +Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { + Mocha.test("Belt_internalSetInt.A.rangeBy", () => { Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, 3, @@ -15340,8 +15340,8 @@ Mocha.describe("Belt_internalMapString.A.rangeBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.range", () => { - Mocha.test("Belt_internalMapString.A.range", () => { +Mocha.describe("Belt_internalSetInt.A.range", () => { + Mocha.test("Belt_internalSetInt.A.range", () => { Primitive_object.equal(Belt_Array.range(0, 3), [ 0, 1, @@ -15353,8 +15353,8 @@ Mocha.describe("Belt_internalMapString.A.range", () => { }); }); -Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { +Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { let arr = new Array(5); console.log(Belt_Array.getExn(arr, 0)); Belt_Array.setExn(arr, 0, "example"); @@ -15362,15 +15362,15 @@ Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { }); }); -Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { +Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { let arr = new Array(5); Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Belt_internalMapString.A.reverse", () => { - Mocha.test("Belt_internalMapString.A.reverse", () => { +Mocha.describe("Belt_internalSetInt.A.reverse", () => { + Mocha.test("Belt_internalSetInt.A.reverse", () => { Primitive_object.equal(Belt_Array.reverse([ 10, 11, @@ -15387,8 +15387,8 @@ Mocha.describe("Belt_internalMapString.A.reverse", () => { }); }); -Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { +Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { let arr = [ 10, 11, @@ -15407,8 +15407,8 @@ Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { }); }); -Mocha.describe("Belt_internalMapString.A.get", () => { - Mocha.test("Belt_internalMapString.A.get", () => { +Mocha.describe("Belt_internalSetInt.A.get", () => { + Mocha.test("Belt_internalSetInt.A.get", () => { Primitive_object.equal(Belt_Array.get([ "a", "b", @@ -15427,12 +15427,12 @@ Mocha.describe("Belt_internalMapString.A.get", () => { }); }); -Mocha.describe("Belt_internalMapString.A.length", () => { - Mocha.test("Belt_internalMapString.A.length", () => {}); +Mocha.describe("Belt_internalSetInt.A.length", () => { + Mocha.test("Belt_internalSetInt.A.length", () => {}); }); -Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { +Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { let arr = [ "ant", "bee", @@ -15449,8 +15449,8 @@ Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.eq", () => { - Mocha.test("Belt_internalSetInt.A.eq", () => { +Mocha.describe("Belt_internalSetString.A.eq", () => { + Mocha.test("Belt_internalSetString.A.eq", () => { Belt_Array.eq([ 1, 2, @@ -15463,8 +15463,8 @@ Mocha.describe("Belt_internalSetInt.A.eq", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.cmp", () => { - Mocha.test("Belt_internalSetInt.A.cmp", () => { +Mocha.describe("Belt_internalSetString.A.cmp", () => { + Mocha.test("Belt_internalSetString.A.cmp", () => { Belt_Array.cmp([ 1, 3, @@ -15495,8 +15495,8 @@ Mocha.describe("Belt_internalSetInt.A.cmp", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.some2", () => { - Mocha.test("Belt_internalSetInt.A.some2", () => { +Mocha.describe("Belt_internalSetString.A.some2", () => { + Mocha.test("Belt_internalSetString.A.some2", () => { Belt_Array.some2([ 0, 2 @@ -15516,8 +15516,8 @@ Mocha.describe("Belt_internalSetInt.A.some2", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.every2", () => { - Mocha.test("Belt_internalSetInt.A.every2", () => { +Mocha.describe("Belt_internalSetString.A.every2", () => { + Mocha.test("Belt_internalSetString.A.every2", () => { Belt_Array.every2([ 1, 2, @@ -15541,8 +15541,8 @@ Mocha.describe("Belt_internalSetInt.A.every2", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.every", () => { - Mocha.test("Belt_internalSetInt.A.every", () => { +Mocha.describe("Belt_internalSetString.A.every", () => { + Mocha.test("Belt_internalSetString.A.every", () => { Belt_Array.every([ 1, 3, @@ -15556,8 +15556,8 @@ Mocha.describe("Belt_internalSetInt.A.every", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.some", () => { - Mocha.test("Belt_internalSetInt.A.some", () => { +Mocha.describe("Belt_internalSetString.A.some", () => { + Mocha.test("Belt_internalSetString.A.some", () => { Belt_Array.some([ 2, 3, @@ -15571,8 +15571,8 @@ Mocha.describe("Belt_internalSetInt.A.some", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.joinWith", () => { - Mocha.test("Belt_internalSetInt.A.joinWith", () => { +Mocha.describe("Belt_internalSetString.A.joinWith", () => { + Mocha.test("Belt_internalSetString.A.joinWith", () => { Belt_Array.joinWith([ 0, 1 @@ -15582,8 +15582,8 @@ Mocha.describe("Belt_internalSetInt.A.joinWith", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { +Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { Belt_Array.reduceWithIndex([ 1, 2, @@ -15593,8 +15593,8 @@ Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { +Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { Belt_Array.reduceReverse2([ 1, 2, @@ -15606,8 +15606,8 @@ Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { +Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse", () => { Belt_Array.reduceReverse([ "a", "b", @@ -15617,8 +15617,8 @@ Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.reduce", () => { - Mocha.test("Belt_internalSetInt.A.reduce", () => { +Mocha.describe("Belt_internalSetString.A.reduce", () => { + Mocha.test("Belt_internalSetString.A.reduce", () => { Belt_Array.reduce([ 2, 3, @@ -15633,8 +15633,8 @@ Mocha.describe("Belt_internalSetInt.A.reduce", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.partition", () => { - Mocha.test("Belt_internalSetInt.A.partition", () => { +Mocha.describe("Belt_internalSetString.A.partition", () => { + Mocha.test("Belt_internalSetString.A.partition", () => { Primitive_object.equal(Belt_Array.partition([ 1, 2, @@ -15672,8 +15672,8 @@ Mocha.describe("Belt_internalSetInt.A.partition", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { +Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { Primitive_object.equal(Belt_Array.mapWithIndex([ 1, 2, @@ -15686,8 +15686,8 @@ Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.forEachWithIndex", () => { +Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetString.A.forEachWithIndex", () => { Belt_Array.forEachWithIndex([ "a", "b", @@ -15709,8 +15709,8 @@ Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.keepMap", () => { - Mocha.test("Belt_internalSetInt.A.keepMap", () => { +Mocha.describe("Belt_internalSetString.A.keepMap", () => { + Mocha.test("Belt_internalSetString.A.keepMap", () => { Primitive_object.equal(Belt_Array.keepMap([ 1, 2, @@ -15724,8 +15724,8 @@ Mocha.describe("Belt_internalSetInt.A.keepMap", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { +Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { Primitive_object.equal(Belt_Array.keepWithIndex([ 1, 2, @@ -15734,8 +15734,8 @@ Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { - Mocha.test("Belt_internalSetInt.A.getIndexBy", () => { +Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { + Mocha.test("Belt_internalSetString.A.getIndexBy", () => { Primitive_object.equal(Belt_Array.getIndexBy([ 1, 4, @@ -15750,8 +15750,8 @@ Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.getBy", () => { - Mocha.test("Belt_internalSetInt.A.getBy", () => { +Mocha.describe("Belt_internalSetString.A.getBy", () => { + Mocha.test("Belt_internalSetString.A.getBy", () => { Primitive_object.equal(Belt_Array.getBy([ 1, 4, @@ -15766,8 +15766,8 @@ Mocha.describe("Belt_internalSetInt.A.getBy", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.flatMap", () => { - Mocha.test("Belt_internalSetInt.A.flatMap", () => { +Mocha.describe("Belt_internalSetString.A.flatMap", () => { + Mocha.test("Belt_internalSetString.A.flatMap", () => { Primitive_object.equal(Belt_Array.flatMap([ 1, 2 @@ -15783,8 +15783,8 @@ Mocha.describe("Belt_internalSetInt.A.flatMap", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.map", () => { - Mocha.test("Belt_internalSetInt.A.map", () => { +Mocha.describe("Belt_internalSetString.A.map", () => { + Mocha.test("Belt_internalSetString.A.map", () => { Primitive_object.equal(Belt_Array.map([ 1, 2 @@ -15795,8 +15795,8 @@ Mocha.describe("Belt_internalSetInt.A.map", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.forEach", () => { - Mocha.test("Belt_internalSetInt.A.forEach", () => { +Mocha.describe("Belt_internalSetString.A.forEach", () => { + Mocha.test("Belt_internalSetString.A.forEach", () => { Belt_Array.forEach([ "a", "b", @@ -15818,8 +15818,8 @@ Mocha.describe("Belt_internalSetInt.A.forEach", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.blit", () => { - Mocha.test("Belt_internalSetInt.A.blit", () => { +Mocha.describe("Belt_internalSetString.A.blit", () => { + Mocha.test("Belt_internalSetString.A.blit", () => { let v1 = [ 10, 11, @@ -15865,8 +15865,8 @@ Mocha.describe("Belt_internalSetInt.A.blit", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.fill", () => { - Mocha.test("Belt_internalSetInt.A.fill", () => { +Mocha.describe("Belt_internalSetString.A.fill", () => { + Mocha.test("Belt_internalSetString.A.fill", () => { let arr = Belt_Array.makeBy(5, i => i); Belt_Array.fill(arr, 2, 2, 9); Primitive_object.equal(arr, [ @@ -15887,8 +15887,8 @@ Mocha.describe("Belt_internalSetInt.A.fill", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetInt.A.sliceToEnd", () => { +Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetString.A.sliceToEnd", () => { Primitive_object.equal(Belt_Array.sliceToEnd([ 10, 11, @@ -15921,8 +15921,8 @@ Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.slice", () => { - Mocha.test("Belt_internalSetInt.A.slice", () => { +Mocha.describe("Belt_internalSetString.A.slice", () => { + Mocha.test("Belt_internalSetString.A.slice", () => { Primitive_object.equal(Belt_Array.slice([ 10, 11, @@ -15965,8 +15965,8 @@ Mocha.describe("Belt_internalSetInt.A.slice", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.concatMany", () => { - Mocha.test("Belt_internalSetInt.A.concatMany", () => { +Mocha.describe("Belt_internalSetString.A.concatMany", () => { + Mocha.test("Belt_internalSetString.A.concatMany", () => { Primitive_object.equal(Belt_Array.concatMany([ [ 1, @@ -15995,8 +15995,8 @@ Mocha.describe("Belt_internalSetInt.A.concatMany", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.concat", () => { - Mocha.test("Belt_internalSetInt.A.concat", () => { +Mocha.describe("Belt_internalSetString.A.concat", () => { + Mocha.test("Belt_internalSetString.A.concat", () => { Primitive_object.equal(Belt_Array.concat([ 1, 2, @@ -16023,8 +16023,8 @@ Mocha.describe("Belt_internalSetInt.A.concat", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.unzip", () => { - Mocha.test("Belt_internalSetInt.A.unzip", () => { +Mocha.describe("Belt_internalSetString.A.unzip", () => { + Mocha.test("Belt_internalSetString.A.unzip", () => { Primitive_object.equal(Belt_Array.unzip([ [ 1, @@ -16078,8 +16078,8 @@ Mocha.describe("Belt_internalSetInt.A.unzip", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.zipBy", () => { - Mocha.test("Belt_internalSetInt.A.zipBy", () => { +Mocha.describe("Belt_internalSetString.A.zipBy", () => { + Mocha.test("Belt_internalSetString.A.zipBy", () => { Primitive_object.equal(Belt_Array.zipBy([ 1, 2, @@ -16094,8 +16094,8 @@ Mocha.describe("Belt_internalSetInt.A.zipBy", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.zip", () => { - Mocha.test("Belt_internalSetInt.A.zip", () => { +Mocha.describe("Belt_internalSetString.A.zip", () => { + Mocha.test("Belt_internalSetString.A.zip", () => { Primitive_object.equal(Belt_Array.zip([ 1, 2 @@ -16116,8 +16116,8 @@ Mocha.describe("Belt_internalSetInt.A.zip", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.makeBy", () => { - Mocha.test("Belt_internalSetInt.A.makeBy", () => { +Mocha.describe("Belt_internalSetString.A.makeBy", () => { + Mocha.test("Belt_internalSetString.A.makeBy", () => { Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ 0, 1, @@ -16135,8 +16135,8 @@ Mocha.describe("Belt_internalSetInt.A.makeBy", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { - Mocha.test("Belt_internalSetInt.A.rangeBy", () => { +Mocha.describe("Belt_internalSetString.A.rangeBy", () => { + Mocha.test("Belt_internalSetString.A.rangeBy", () => { Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, 3, @@ -16158,8 +16158,8 @@ Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.range", () => { - Mocha.test("Belt_internalSetInt.A.range", () => { +Mocha.describe("Belt_internalSetString.A.range", () => { + Mocha.test("Belt_internalSetString.A.range", () => { Primitive_object.equal(Belt_Array.range(0, 3), [ 0, 1, @@ -16171,8 +16171,8 @@ Mocha.describe("Belt_internalSetInt.A.range", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { +Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { let arr = new Array(5); console.log(Belt_Array.getExn(arr, 0)); Belt_Array.setExn(arr, 0, "example"); @@ -16180,15 +16180,15 @@ Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { +Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { let arr = new Array(5); Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Belt_internalSetInt.A.reverse", () => { - Mocha.test("Belt_internalSetInt.A.reverse", () => { +Mocha.describe("Belt_internalSetString.A.reverse", () => { + Mocha.test("Belt_internalSetString.A.reverse", () => { Primitive_object.equal(Belt_Array.reverse([ 10, 11, @@ -16205,8 +16205,8 @@ Mocha.describe("Belt_internalSetInt.A.reverse", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { +Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { let arr = [ 10, 11, @@ -16225,8 +16225,8 @@ Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.get", () => { - Mocha.test("Belt_internalSetInt.A.get", () => { +Mocha.describe("Belt_internalSetString.A.get", () => { + Mocha.test("Belt_internalSetString.A.get", () => { Primitive_object.equal(Belt_Array.get([ "a", "b", @@ -16245,8 +16245,8 @@ Mocha.describe("Belt_internalSetInt.A.get", () => { }); }); -Mocha.describe("Belt_internalSetInt.A.length", () => { - Mocha.test("Belt_internalSetInt.A.length", () => {}); +Mocha.describe("Belt_internalSetString.A.length", () => { + Mocha.test("Belt_internalSetString.A.length", () => {}); }); Mocha.describe("Console.warnMany", () => { @@ -16827,21 +16827,221 @@ Mocha.describe("Console.assert_", () => { }); }); -Mocha.describe("Date.UTC.makeWithYMDHMSM", () => { - Mocha.test("Date.UTC.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("Dict.mapValues", () => { + Mocha.test("Dict.mapValues", () => { + let dict = Object.fromEntries([ + [ + "key1", + 1 + ], + [ + "key2", + 2 + ] + ]); + Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); + Object.entries(Dict.mapValues(dict, v => v.toString())); }); }); -Mocha.describe("Date.UTC.makeWithYMDHMS", () => { - Mocha.test("Date.UTC.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.describe("Dict.forEachWithKey", () => { + Mocha.test("Dict.forEachWithKey", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEachWithKey(dict, (value, key) => { + console.log(value, key); + }); + }); +}); + +Mocha.describe("Dict.forEach", () => { + Mocha.test("Dict.forEach", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEach(dict, value => { + console.log(value); + }); + }); +}); + +Mocha.describe("Dict.copy", () => { + Mocha.test("Dict.copy", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + let dict2 = Object.assign({}, dict); + console.log(Object.keys(dict), Object.keys(dict2)); + }); +}); + +Mocha.describe("Dict.assign", () => { + Mocha.test("Dict.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.describe("Dict.valuesToArray", () => { + Mocha.test("Dict.valuesToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let values = Object.values(dict); + console.log(values); + }); +}); + +Mocha.describe("Dict.keysToArray", () => { + Mocha.test("Dict.keysToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let keys = Object.keys(dict); + console.log(keys); + }); +}); + +Mocha.describe("Dict.toArray", () => { + Mocha.test("Dict.toArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let asArray = Object.entries(dict); + console.log(asArray); + }); +}); + +Mocha.describe("Dict.fromIterator", () => { + Mocha.test("Dict.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ + 1, + 2 + ]); + }); +}); + +Mocha.describe("Dict.fromArray", () => { + Mocha.test("Dict.fromArray", () => { + Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + }); +}); + +Mocha.describe("Dict.make", () => { + Mocha.test("Dict.make", () => { + let dict2 = {}; + dict2["someKey"] = 12; + }); +}); + +Mocha.describe("Dict.delete", () => { + Mocha.test("Dict.delete", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + Dict.$$delete(dict, "someKey"); + }); +}); + +Mocha.describe("Dict.set", () => { + Mocha.test("Dict.set", () => { + let dict = {}; + dict["someKey"] = "someValue"; + }); +}); + +Mocha.describe("Dict.get", () => { + Mocha.test("Dict.get", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + let value = dict["someKey"]; + if (value !== undefined) { + console.log(value); + } else { + console.log("Nope, didn't have the key."); + } + }); +}); + +Mocha.describe("Dict.getUnsafe", () => { + Mocha.test("Dict.getUnsafe", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + let value = dict["key1"]; + console.log(value); + }); +}); + +Mocha.describe("Date.UTC.makeWithYMDHMSM", () => { + Mocha.test("Date.UTC.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("Date.UTC.makeWithYMDHMS", () => { + Mocha.test("Date.UTC.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.describe("Date.UTC.makeWithYMDHM", () => { Mocha.test("Date.UTC.makeWithYMDHM", () => { @@ -17360,250 +17560,50 @@ Mocha.describe("Date.make", () => { }); }); -Mocha.describe("Dict.mapValues", () => { - Mocha.test("Dict.mapValues", () => { - let dict = Object.fromEntries([ - [ - "key1", - 1 - ], - [ - "key2", - 2 - ] - ]); - Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); - Object.entries(Dict.mapValues(dict, v => v.toString())); - }); -}); - -Mocha.describe("Dict.forEachWithKey", () => { - Mocha.test("Dict.forEachWithKey", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEachWithKey(dict, (value, key) => { - console.log(value, key); - }); - }); -}); - -Mocha.describe("Dict.forEach", () => { - Mocha.test("Dict.forEach", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEach(dict, value => { - console.log(value); - }); - }); -}); - -Mocha.describe("Dict.copy", () => { - Mocha.test("Dict.copy", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let dict2 = Object.assign({}, dict); - console.log(Object.keys(dict), Object.keys(dict2)); - }); -}); - -Mocha.describe("Dict.assign", () => { - Mocha.test("Dict.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.describe("Dict.valuesToArray", () => { - Mocha.test("Dict.valuesToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let values = Object.values(dict); - console.log(values); - }); -}); - -Mocha.describe("Dict.keysToArray", () => { - Mocha.test("Dict.keysToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let keys = Object.keys(dict); - console.log(keys); - }); -}); - -Mocha.describe("Dict.toArray", () => { - Mocha.test("Dict.toArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let asArray = Object.entries(dict); - console.log(asArray); - }); -}); - -Mocha.describe("Dict.fromIterator", () => { - Mocha.test("Dict.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ - 1, - 2 - ]); - }); -}); - -Mocha.describe("Dict.fromArray", () => { - Mocha.test("Dict.fromArray", () => { - Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - }); -}); - -Mocha.describe("Dict.make", () => { - Mocha.test("Dict.make", () => { - let dict2 = {}; - dict2["someKey"] = 12; - }); -}); - -Mocha.describe("Dict.delete", () => { - Mocha.test("Dict.delete", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - Dict.$$delete(dict, "someKey"); - }); -}); - -Mocha.describe("Dict.set", () => { - Mocha.test("Dict.set", () => { - let dict = {}; - dict["someKey"] = "someValue"; - }); -}); - -Mocha.describe("Dict.get", () => { - Mocha.test("Dict.get", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - let value = dict["someKey"]; - if (value !== undefined) { - console.log(value); - } else { - console.log("Nope, didn't have the key."); - } - }); -}); - -Mocha.describe("Dict.getUnsafe", () => { - Mocha.test("Dict.getUnsafe", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let value = dict["key1"]; - console.log(value); - }); -}); - -Mocha.describe("Error.panic", () => { - Mocha.test("Error.panic", () => { - try { - $$Error.panic("Uh oh. This was unexpected!"); - } catch (raw_obj) { - let obj = Primitive_exceptions.internalToException(raw_obj); - if (obj.RE_EXN_ID === 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: [ - "mocha_full_test.res", - 13182, - 21 - ], - Error: new Error() - }; - } - - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mocha_full_test.res", - 13183, - 18 - ], - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mocha_full_test.res", - 13185, - 13 - ], - Error: new Error() - }; - } - } +Mocha.describe("Error.panic", () => { + Mocha.test("Error.panic", () => { + try { + $$Error.panic("Uh oh. This was unexpected!"); + } catch (raw_obj) { + let obj = Primitive_exceptions.internalToException(raw_obj); + if (obj.RE_EXN_ID === 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", + 12931, + 15 + ], + Error: new Error() + }; + } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12932, + 12 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12934, + 7 + ], + Error: new Error() + }; + } + } }); }); @@ -18199,9 +18199,9 @@ Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14064, - 13 + "generated_mocha_test.res", + 13810, + 7 ], Error: new Error() }; @@ -18243,9 +18243,9 @@ Mocha.describe("JSON.stringifyAnyWithFilter", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14088, - 13 + "generated_mocha_test.res", + 13834, + 7 ], Error: new Error() }; @@ -18292,9 +18292,9 @@ Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14122, - 13 + "generated_mocha_test.res", + 13868, + 7 ], Error: new Error() }; @@ -18341,9 +18341,9 @@ Mocha.describe("JSON.stringifyAnyWithReplacer", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14156, - 13 + "generated_mocha_test.res", + 13902, + 7 ], Error: new Error() }; @@ -18382,9 +18382,9 @@ Mocha.describe("JSON.stringifyAnyWithIndent", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14185, - 13 + "generated_mocha_test.res", + 13931, + 7 ], Error: new Error() }; @@ -18437,9 +18437,9 @@ Mocha.describe("JSON.stringifyAny", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 14241, - 13 + "generated_mocha_test.res", + 13986, + 7 ], Error: new Error() }; @@ -18829,163 +18829,24 @@ Mocha.describe("Map.make", () => { }); }); -Mocha.describe("Null.flatMap", () => { - Mocha.test("Null.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; +Mocha.describe("List.sort", () => { + Mocha.test("List.sort", () => { + List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } } - }; - Null.flatMap(2, addIfAboveOne); - Null.flatMap(-4, addIfAboveOne); - Null.flatMap(null, addIfAboveOne); - }); -}); - -Mocha.describe("Null.mapOr", () => { - Mocha.test("Null.mapOr", () => { - Null.mapOr(3, 0, x => x + 5 | 0); - Null.mapOr(null, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Null.map", () => { - Mocha.test("Null.map", () => { - Null.map(3, x => Math.imul(x, x)); - Null.map(null, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Null.forEach", () => { - Mocha.test("Null.forEach", () => { - Null.forEach("thing", x => { - console.log(x); - }); - Null.forEach(null, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Null.getUnsafe", () => { - Mocha.test("Null.getUnsafe", () => {}); -}); - -Mocha.describe("Null.getExn", () => { - Mocha.test("Null.getExn", () => { - Pervasives.assertEqual(Null.getExn(3), 3); - let exit = 0; - let value; - try { - value = 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: [ - "mocha_full_test.res", - 14766, - 41 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "ReScript"); - } - let exit$1 = 0; - let val; - try { - val = 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: [ - "mocha_full_test.res", - 14772, - 13 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Null.getOr", () => { - Mocha.test("Null.getOr", () => { - Null.getOr(null, "Banana"); - Null.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNull("Jane")); - greet(undefined); - }); -}); - -Mocha.describe("Null.fromOption", () => { - Mocha.test("Null.fromOption", () => { - let asNull = Null.fromOption(undefined); - console.log(asNull === null); - }); -}); - -Mocha.describe("Null.toOption", () => { - Mocha.test("Null.toOption", () => { - let nullStr = "Hello"; - if (nullStr !== null) { - console.log("Got string:", nullStr); - } else { - console.log("Didn't have a value."); - } - }); -}); - -Mocha.describe("Null.make", () => { - Mocha.test("Null.make", () => {}); -}); - -Mocha.describe("Null.null", () => { - Mocha.test("Null.null", () => { - console.log(null); - }); -}); - -Mocha.describe("Null.asNullable", () => { - Mocha.test("Null.asNullable", () => {}); -}); - -Mocha.describe("List.sort", () => { - Mocha.test("List.sort", () => { - List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, Primitive_int.compare); + }, Primitive_int.compare); }); }); @@ -20338,9 +20199,9 @@ Mocha.describe("List.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 15409, - 13 + "generated_mocha_test.res", + 14986, + 7 ], Error: new Error() }; @@ -20419,9 +20280,9 @@ Mocha.describe("List.tailExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 15447, - 13 + "generated_mocha_test.res", + 15024, + 7 ], Error: new Error() }; @@ -20474,9 +20335,9 @@ Mocha.describe("List.headExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 15472, - 13 + "generated_mocha_test.res", + 15049, + 7 ], Error: new Error() }; @@ -20531,57 +20392,246 @@ Mocha.describe("List.length", () => { }); }); -Mocha.describe("Math.Int.random", () => { - Mocha.test("Math.Int.random", () => { - $$Math.Int.random(2, 5) === 4; - $$Math.Int.random(505, 2000) === 1276; - $$Math.Int.random(-7, -2) === -4; - }); -}); - -Mocha.describe("Math.Int.ceil", () => { - Mocha.test("Math.Int.ceil", () => { - $$Math.Int.ceil(3.7) === 4; - $$Math.Int.ceil(3.0) === 3; - $$Math.Int.ceil(-3.1) === -3; +Mocha.describe("Nullable.flatMap", () => { + Mocha.test("Nullable.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Nullable.flatMap(2, addIfAboveOne); + Nullable.flatMap(-4, addIfAboveOne); + Nullable.flatMap(null, addIfAboveOne); }); }); -Mocha.describe("Math.Int.floor", () => { - Mocha.test("Math.Int.floor", () => { - $$Math.Int.floor(3.7) === 3; - $$Math.Int.floor(3.0) === 3; - $$Math.Int.floor(-3.1) === -4; +Mocha.describe("Nullable.mapOr", () => { + Mocha.test("Nullable.mapOr", () => { + Nullable.mapOr(3, 0, x => x + 5 | 0); + Nullable.mapOr(null, 0, x => x + 5 | 0); }); }); -Mocha.describe("Math.Int.sign", () => { - Mocha.test("Math.Int.sign", () => { - Math.sign(3); - Math.sign(-3); - Math.sign(0); +Mocha.describe("Nullable.map", () => { + Mocha.test("Nullable.map", () => { + Nullable.map(3, x => Math.imul(x, x)); + Nullable.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Math.Int.pow", () => { - Mocha.test("Math.Int.pow", () => { - Math.pow(2, 4); - Math.pow(3, 4); +Mocha.describe("Nullable.forEach", () => { + Mocha.test("Nullable.forEach", () => { + Nullable.forEach("thing", x => { + console.log(x); + }); + Nullable.forEach(null, x => { + console.log(x); + }); + Nullable.forEach(undefined, x => { + console.log(x); + }); }); }); -Mocha.describe("Math.Int.maxMany", () => { - Mocha.test("Math.Int.maxMany", () => { - Math.max(1, 2); - Math.max(-1, -2); - isFinite(Math.max()); - }); +Mocha.describe("Nullable.getUnsafe", () => { + Mocha.test("Nullable.getUnsafe", () => {}); }); -Mocha.describe("Math.Int.max", () => { - Mocha.test("Math.Int.max", () => { - Math.max(1, 2); - Math.max(-1, -2); +Mocha.describe("Nullable.getExn", () => { + Mocha.test("Nullable.getExn", () => { + let exit = 0; + let value; + try { + value = 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", + 15150, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "Hello"); + } + let exit$1 = 0; + let val; + try { + val = 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", + 15156, + 7 + ], + Error: new Error() + }; + } + let exit$2 = 0; + let val$1; + try { + val$1 = 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", + 15161, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Nullable.getOr", () => { + Mocha.test("Nullable.getOr", () => { + Nullable.getOr(null, "Banana"); + Nullable.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNullable("Jane")); + greet(undefined); + }); +}); + +Mocha.describe("Nullable.fromOption", () => { + Mocha.test("Nullable.fromOption", () => { + Nullable.fromOption("Hello"); + }); +}); + +Mocha.describe("Nullable.toOption", () => { + Mocha.test("Nullable.toOption", () => { + let nullableString = "Hello"; + if (nullableString == null) { + console.log("Didn't have a value."); + } else { + console.log("Got string:", nullableString); + } + }); +}); + +Mocha.describe("Nullable.make", () => { + Mocha.test("Nullable.make", () => { + let myStr = "Hello"; + if ((myStr == null) || myStr !== myStr) { + console.log("Values did not match."); + } else { + console.log("Yay, values matched!"); + } + }); +}); + +Mocha.describe("Nullable.isNullable", () => { + Mocha.test("Nullable.isNullable", () => { + if ("Hello" == null) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 15238, + 10 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Nullable.undefined", () => { + Mocha.test("Nullable.undefined", () => { + console.log(undefined); + }); +}); + +Mocha.describe("Nullable.null", () => { + Mocha.test("Nullable.null", () => { + console.log(null); + }); +}); + +Mocha.describe("Math.Int.random", () => { + Mocha.test("Math.Int.random", () => { + $$Math.Int.random(2, 5) === 4; + $$Math.Int.random(505, 2000) === 1276; + $$Math.Int.random(-7, -2) === -4; + }); +}); + +Mocha.describe("Math.Int.ceil", () => { + Mocha.test("Math.Int.ceil", () => { + $$Math.Int.ceil(3.7) === 4; + $$Math.Int.ceil(3.0) === 3; + $$Math.Int.ceil(-3.1) === -3; + }); +}); + +Mocha.describe("Math.Int.floor", () => { + Mocha.test("Math.Int.floor", () => { + $$Math.Int.floor(3.7) === 3; + $$Math.Int.floor(3.0) === 3; + $$Math.Int.floor(-3.1) === -4; + }); +}); + +Mocha.describe("Math.Int.sign", () => { + Mocha.test("Math.Int.sign", () => { + Math.sign(3); + Math.sign(-3); + Math.sign(0); + }); +}); + +Mocha.describe("Math.Int.pow", () => { + Mocha.test("Math.Int.pow", () => { + Math.pow(2, 4); + Math.pow(3, 4); + }); +}); + +Mocha.describe("Math.Int.maxMany", () => { + Mocha.test("Math.Int.maxMany", () => { + Math.max(1, 2); + Math.max(-1, -2); + isFinite(Math.max()); + }); +}); + +Mocha.describe("Math.Int.max", () => { + Mocha.test("Math.Int.max", () => { + Math.max(1, 2); + Math.max(-1, -2); }); }); @@ -20937,8 +20987,8 @@ Mocha.describe("Math.abs", () => { }); }); -Mocha.describe("Nullable.flatMap", () => { - Mocha.test("Nullable.flatMap", () => { +Mocha.describe("Null.flatMap", () => { + Mocha.test("Null.flatMap", () => { let addIfAboveOne = value => { if (value > 1) { return value + 1 | 0; @@ -20946,50 +20996,48 @@ Mocha.describe("Nullable.flatMap", () => { return null; } }; - Nullable.flatMap(2, addIfAboveOne); - Nullable.flatMap(-4, addIfAboveOne); - Nullable.flatMap(null, addIfAboveOne); + Null.flatMap(2, addIfAboveOne); + Null.flatMap(-4, addIfAboveOne); + Null.flatMap(null, addIfAboveOne); }); }); -Mocha.describe("Nullable.mapOr", () => { - Mocha.test("Nullable.mapOr", () => { - Nullable.mapOr(3, 0, x => x + 5 | 0); - Nullable.mapOr(null, 0, x => x + 5 | 0); +Mocha.describe("Null.mapOr", () => { + Mocha.test("Null.mapOr", () => { + Null.mapOr(3, 0, x => x + 5 | 0); + Null.mapOr(null, 0, x => x + 5 | 0); }); }); -Mocha.describe("Nullable.map", () => { - Mocha.test("Nullable.map", () => { - Nullable.map(3, x => Math.imul(x, x)); - Nullable.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Null.map", () => { + Mocha.test("Null.map", () => { + Null.map(3, x => Math.imul(x, x)); + Null.map(null, x => Math.imul(x, x)); }); }); -Mocha.describe("Nullable.forEach", () => { - Mocha.test("Nullable.forEach", () => { - Nullable.forEach("thing", x => { - console.log(x); - }); - Nullable.forEach(null, x => { +Mocha.describe("Null.forEach", () => { + Mocha.test("Null.forEach", () => { + Null.forEach("thing", x => { console.log(x); }); - Nullable.forEach(undefined, x => { + Null.forEach(null, x => { console.log(x); }); }); }); -Mocha.describe("Nullable.getUnsafe", () => { - Mocha.test("Nullable.getUnsafe", () => {}); +Mocha.describe("Null.getUnsafe", () => { + Mocha.test("Null.getUnsafe", () => {}); }); -Mocha.describe("Nullable.getExn", () => { - Mocha.test("Nullable.getExn", () => { +Mocha.describe("Null.getExn", () => { + Mocha.test("Null.getExn", () => { + Pervasives.assertEqual(Null.getExn(3), 3); let exit = 0; let value; try { - value = Nullable.getExn('Hello'); + value = Null.getExn('ReScript'); exit = 1; } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); @@ -20997,9 +21045,9 @@ Mocha.describe("Nullable.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16165, - 41 + "generated_mocha_test.res", + 15923, + 35 ], Error: new Error() }; @@ -21007,12 +21055,12 @@ Mocha.describe("Nullable.getExn", () => { throw exn; } if (exit === 1) { - Pervasives.assertEqual(value, "Hello"); + Pervasives.assertEqual(value, "ReScript"); } let exit$1 = 0; let val; try { - val = Nullable.getExn(null); + val = Null.getExn(null); exit$1 = 1; } catch (raw_exn$1) { let exn$1 = Primitive_exceptions.internalToException(raw_exn$1); @@ -21025,32 +21073,9 @@ Mocha.describe("Nullable.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16171, - 13 - ], - Error: new Error() - }; - } - let exit$2 = 0; - let val$1; - try { - val$1 = 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: [ - "mocha_full_test.res", - 16176, - 13 + "generated_mocha_test.res", + 15929, + 7 ], Error: new Error() }; @@ -21059,71 +21084,46 @@ Mocha.describe("Nullable.getExn", () => { }); }); -Mocha.describe("Nullable.getOr", () => { - Mocha.test("Nullable.getOr", () => { - Nullable.getOr(null, "Banana"); - Nullable.getOr("Apple", "Banana"); +Mocha.describe("Null.getOr", () => { + Mocha.test("Null.getOr", () => { + Null.getOr(null, "Banana"); + Null.getOr("Apple", "Banana"); let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNullable("Jane")); + greet(Primitive_option.fromNull("Jane")); greet(undefined); }); }); -Mocha.describe("Nullable.fromOption", () => { - Mocha.test("Nullable.fromOption", () => { - Nullable.fromOption("Hello"); - }); -}); - -Mocha.describe("Nullable.toOption", () => { - Mocha.test("Nullable.toOption", () => { - let nullableString = "Hello"; - if (nullableString == null) { - console.log("Didn't have a value."); - } else { - console.log("Got string:", nullableString); - } +Mocha.describe("Null.fromOption", () => { + Mocha.test("Null.fromOption", () => { + let asNull = Null.fromOption(undefined); + console.log(asNull === null); }); }); -Mocha.describe("Nullable.make", () => { - Mocha.test("Nullable.make", () => { - let myStr = "Hello"; - if ((myStr == null) || myStr !== myStr) { - console.log("Values did not match."); +Mocha.describe("Null.toOption", () => { + Mocha.test("Null.toOption", () => { + let nullStr = "Hello"; + if (nullStr !== null) { + console.log("Got string:", nullStr); } else { - console.log("Yay, values matched!"); + console.log("Didn't have a value."); } }); }); -Mocha.describe("Nullable.isNullable", () => { - Mocha.test("Nullable.isNullable", () => { - if ("Hello" == null) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mocha_full_test.res", - 16253, - 16 - ], - Error: new Error() - }; - } - - }); +Mocha.describe("Null.make", () => { + Mocha.test("Null.make", () => {}); }); -Mocha.describe("Nullable.undefined", () => { - Mocha.test("Nullable.undefined", () => { - console.log(undefined); +Mocha.describe("Null.null", () => { + Mocha.test("Null.null", () => { + console.log(null); }); }); -Mocha.describe("Nullable.null", () => { - Mocha.test("Nullable.null", () => { - console.log(null); - }); +Mocha.describe("Null.asNullable", () => { + Mocha.test("Null.asNullable", () => {}); }); Mocha.describe("Object.isExtensible", () => { @@ -21180,9 +21180,9 @@ Mocha.describe("Object.freeze", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16326, - 13 + "generated_mocha_test.res", + 16053, + 7 ], Error: new Error() }; @@ -21207,9 +21207,9 @@ Mocha.describe("Object.preventExtensions", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16343, - 13 + "generated_mocha_test.res", + 16070, + 7 ], Error: new Error() }; @@ -21235,9 +21235,9 @@ Mocha.describe("Object.seal", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16361, - 13 + "generated_mocha_test.res", + 16088, + 7 ], Error: new Error() }; @@ -21394,107 +21394,6 @@ Mocha.describe("Object.make", () => { }); }); -Mocha.describe("Pervasives.assertEqual", () => { - Mocha.test("Pervasives.assertEqual", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }), { - hd: 2, - tl: /* [] */0 - }); - }); -}); - -Mocha.describe("Pervasives.import", () => { - Mocha.test("Pervasives.import", () => {}); -}); - -Mocha.describe("Pervasives.decodeURIComponent", () => { - Mocha.test("Pervasives.decodeURIComponent", () => { - console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); - }); -}); - -Mocha.describe("Pervasives.encodeURIComponent", () => { - Mocha.test("Pervasives.encodeURIComponent", () => { - console.log(encodeURIComponent("array=[someValue]")); - }); -}); - -Mocha.describe("Pervasives.decodeURI", () => { - Mocha.test("Pervasives.decodeURI", () => { - console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); - }); -}); - -Mocha.describe("Pervasives.encodeURI", () => { - Mocha.test("Pervasives.encodeURI", () => { - console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); - }); -}); - -Mocha.describe("Pervasives.clearInterval", () => { - Mocha.test("Pervasives.clearInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints in 100 ms"); - }, 100); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); -}); - -Mocha.describe("Pervasives.setIntervalFloat", () => { - Mocha.test("Pervasives.setIntervalFloat", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms"); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500.0); - }); -}); - -Mocha.describe("Pervasives.setInterval", () => { - Mocha.test("Pervasives.setInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms."); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); -}); - -Mocha.describe("Pervasives.clearTimeout", () => { - Mocha.test("Pervasives.clearTimeout", () => { - let timeoutId = setTimeout(() => { - console.log("This prints in 2 seconds."); - }, 2000); - clearTimeout(timeoutId); - }); -}); - -Mocha.describe("Pervasives.setTimeoutFloat", () => { - Mocha.test("Pervasives.setTimeoutFloat", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); -}); - -Mocha.describe("Pervasives.setTimeout", () => { - Mocha.test("Pervasives.setTimeout", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); -}); - Mocha.describe("Option.all", () => { Mocha.test("Option.all", () => { Option.all([ @@ -21610,9 +21509,9 @@ Mocha.describe("Option.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16819, - 13 + "generated_mocha_test.res", + 16360, + 7 ], Error: new Error() }; @@ -21629,9 +21528,9 @@ Mocha.describe("Option.getExn", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 16824, - 13 + "generated_mocha_test.res", + 16365, + 7 ], Error: new Error() }; @@ -21640,22 +21539,316 @@ Mocha.describe("Option.getExn", () => { }); }); -Mocha.describe("Option.forEach", () => { - Mocha.test("Option.forEach", () => { - Option.forEach("thing", x => { - console.log(x); +Mocha.describe("Option.forEach", () => { + Mocha.test("Option.forEach", () => { + Option.forEach("thing", x => { + console.log(x); + }); + Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Option.filter", () => { + Mocha.test("Option.filter", () => { + Option.filter(10, x => x > 5); + Option.filter(4, x => x > 5); + Option.filter(undefined, x => x > 5); + }); +}); + +Mocha.describe("Pervasives.assertEqual", () => { + Mocha.test("Pervasives.assertEqual", () => { + Pervasives.assertEqual(List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }), { + hd: 2, + tl: /* [] */0 + }); + }); +}); + +Mocha.describe("Pervasives.import", () => { + Mocha.test("Pervasives.import", () => {}); +}); + +Mocha.describe("Pervasives.decodeURIComponent", () => { + Mocha.test("Pervasives.decodeURIComponent", () => { + console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); + }); +}); + +Mocha.describe("Pervasives.encodeURIComponent", () => { + Mocha.test("Pervasives.encodeURIComponent", () => { + console.log(encodeURIComponent("array=[someValue]")); + }); +}); + +Mocha.describe("Pervasives.decodeURI", () => { + Mocha.test("Pervasives.decodeURI", () => { + console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); + }); +}); + +Mocha.describe("Pervasives.encodeURI", () => { + Mocha.test("Pervasives.encodeURI", () => { + console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); + }); +}); + +Mocha.describe("Pervasives.clearInterval", () => { + Mocha.test("Pervasives.clearInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints in 100 ms"); + }, 100); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); +}); + +Mocha.describe("Pervasives.setIntervalFloat", () => { + Mocha.test("Pervasives.setIntervalFloat", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms"); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500.0); + }); +}); + +Mocha.describe("Pervasives.setInterval", () => { + Mocha.test("Pervasives.setInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms."); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500); + }); +}); + +Mocha.describe("Pervasives.clearTimeout", () => { + Mocha.test("Pervasives.clearTimeout", () => { + let timeoutId = setTimeout(() => { + console.log("This prints in 2 seconds."); + }, 2000); + clearTimeout(timeoutId); + }); +}); + +Mocha.describe("Pervasives.setTimeoutFloat", () => { + Mocha.test("Pervasives.setTimeoutFloat", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); +}); + +Mocha.describe("Pervasives.setTimeout", () => { + Mocha.test("Pervasives.setTimeout", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); + }); +}); + +Mocha.describe("Promise.allSettled", () => { + Mocha.test("Promise.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.describe("Promise.all", () => { + Mocha.test("Promise.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.describe("Promise.any", () => { + Mocha.test("Promise.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.describe("Promise.race", () => { + Mocha.test("Promise.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.describe("Promise.finally", () => { + Mocha.test("Promise.finally", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + let isDone = { + contents: false + }; + $$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.describe("Promise.thenResolve", () => { + Mocha.test("Promise.thenResolve", () => { + Promise.resolve("Anna").then(str => "Hello " + str).then(str => { + console.log(str); + }); + }); +}); + +Mocha.describe("Promise.then", () => { + Mocha.test("Promise.then", () => { + Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { + console.log("Your lucky number is: ", num); + return Promise.resolve(); + }); + }); +}); + +Mocha.describe("Promise.catch", () => { + Mocha.test("Promise.catch", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + $$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 === 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.describe("Promise.make", () => { + Mocha.test("Promise.make", () => { + $$Promise.$$catch(new Promise((resolve, reject) => resolve("success")).then(str => Promise.resolve((console.log(str), undefined))), param => { + console.log("Error occurred"); + return Promise.resolve(); }); - Option.forEach(undefined, x => { - console.log(x); + }); +}); + +Mocha.describe("Promise.reject", () => { + Mocha.test("Promise.reject", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + $$Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }), v => { + if (v.RE_EXN_ID === TestError) { + Pervasives.assertEqual(v._1, "some rejected value"); + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16787, + 9 + ], + Error: new Error() + }; + } + return Promise.resolve(); }); }); }); -Mocha.describe("Option.filter", () => { - Mocha.test("Option.filter", () => { - Option.filter(10, x => x > 5); - Option.filter(4, x => x > 5); - Option.filter(undefined, x => x > 5); +Mocha.describe("Promise.resolve", () => { + Mocha.test("Promise.resolve", () => { + Promise.resolve(5); }); }); @@ -22030,199 +22223,6 @@ Mocha.describe("Result.mapOr", () => { }); }); -Mocha.describe("Promise.allSettled", () => { - Mocha.test("Promise.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.describe("Promise.all", () => { - Mocha.test("Promise.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.describe("Promise.any", () => { - Mocha.test("Promise.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.describe("Promise.race", () => { - Mocha.test("Promise.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.describe("Promise.finally", () => { - Mocha.test("Promise.finally", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - let isDone = { - contents: false - }; - $$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.describe("Promise.thenResolve", () => { - Mocha.test("Promise.thenResolve", () => { - Promise.resolve("Anna").then(str => "Hello " + str).then(str => { - console.log(str); - }); - }); -}); - -Mocha.describe("Promise.then", () => { - Mocha.test("Promise.then", () => { - Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { - console.log("Your lucky number is: ", num); - return Promise.resolve(); - }); - }); -}); - -Mocha.describe("Promise.catch", () => { - Mocha.test("Promise.catch", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - $$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 === 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.describe("Promise.make", () => { - Mocha.test("Promise.make", () => { - $$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.describe("Promise.reject", () => { - Mocha.test("Promise.reject", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - $$Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }), v => { - if (v.RE_EXN_ID === TestError) { - Pervasives.assertEqual(v._1, "some rejected value"); - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "mocha_full_test.res", - 17495, - 17 - ], - Error: new Error() - }; - } - return Promise.resolve(); - }); - }); -}); - -Mocha.describe("Promise.resolve", () => { - Mocha.test("Promise.resolve", () => { - Promise.resolve(5); - }); -}); - Mocha.describe("Set.toArray", () => { Mocha.test("Set.toArray", () => { let set = new Set([ @@ -22606,9 +22606,9 @@ Mocha.describe("String.normalize", () => { throw { RE_EXN_ID: "Assert_failure", _1: [ - "mocha_full_test.res", - 18018, - 6 + "generated_mocha_test.res", + 17658, + 0 ], Error: new Error() }; From 79d1346c3a23cd70d4de53f5fbc273af2857df61 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 22:57:52 -0300 Subject: [PATCH 08/13] order output --- tests/docstrings_examples/DocTest.res | 3 + tests/docstrings_examples/DocTest.res.mjs | 8 + .../generated_mocha_test.res | 19418 ++++----- .../generated_mocha_test.res.mjs | 35930 ++++++++-------- 4 files changed, 27685 insertions(+), 27674 deletions(-) diff --git a/tests/docstrings_examples/DocTest.res b/tests/docstrings_examples/DocTest.res index 2e9a2bb8d0..779825a748 100644 --- a/tests/docstrings_examples/DocTest.res +++ b/tests/docstrings_examples/DocTest.res @@ -155,6 +155,9 @@ let extractExamples = async () => { let main = async () => { let examples = await extractExamples() + examples->Array.sort((a, b) => + String.length(a.id) > String.length(b.id) ? Ordering.fromInt(1) : Ordering.fromInt(-1) + ) let testsContent = examples ->Array.filterMap(example => { diff --git a/tests/docstrings_examples/DocTest.res.mjs b/tests/docstrings_examples/DocTest.res.mjs index 087be47b25..483d6080f3 100644 --- a/tests/docstrings_examples/DocTest.res.mjs +++ b/tests/docstrings_examples/DocTest.res.mjs @@ -8,6 +8,7 @@ import * as List from "rescript/lib/es6/List.js"; import * as Path from "path"; import * as $$Array from "rescript/lib/es6/Array.js"; import * as $$Error from "rescript/lib/es6/Error.js"; +import * as Ordering from "rescript/lib/es6/Ordering.js"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as ArrayUtils from "./ArrayUtils.res.mjs"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; @@ -214,6 +215,13 @@ async function extractExamples() { async function main() { let examples = await extractExamples(); + examples.sort((a, b) => { + if (a.id.length > b.id.length) { + return Ordering.fromInt(1); + } else { + return Ordering.fromInt(-1); + } + }); let testsContent = $$Array.filterMap(examples, example => { let codeExamples = getCodeBlocks(example); let ignore = ignoreRuntimeTests.includes(example.id); diff --git a/tests/docstrings_examples/generated_mocha_test.res b/tests/docstrings_examples/generated_mocha_test.res index 51f69d0289..b5c0e9d814 100644 --- a/tests/docstrings_examples/generated_mocha_test.res +++ b/tests/docstrings_examples/generated_mocha_test.res @@ -1,926 +1,747 @@ open Mocha @@warning("-32-34-60-37-109-3-44") -describe("AsyncIterator.forEach", () => { - test("AsyncIterator.forEach", () => { +describe("Set.add", () => { + test("Set.add", () => { module Test = { - // Let's pretend we get an async iterator returning ints from somewhere. - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let main = async () => - await asyncIterator->AsyncIterator.forEach( - v => { - switch v { - | Some(("second", value)) => assertEqual(value, "2") - | _ => () - } - }, - ) - - main()->ignore + let set = Set.make() + set->Set.add("someValue") } () }) }) -describe("AsyncIterator.next", () => { - test("AsyncIterator.next", () => { +describe("Set.has", () => { + test("Set.has", () => { module Test = { - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let processMyAsyncIterator = async () => { - // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. - let break = ref(false) - - while !break.contents { - // Await the next iterator value - let {value, done} = await asyncIterator->AsyncIterator.next - - // Exit the while loop if the iterator says it's done - break := done + let set = Set.make() + set->Set.add("someValue") - if done { - value - ->Option.isNone - ->assertEqual(true) - } - } + switch set->Set.has("someValue") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") } - - processMyAsyncIterator()->ignore } () }) }) -describe("AsyncIterator.done", () => { - test("AsyncIterator.done", () => { +describe("Map.get", () => { + test("Map.get", () => { module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 + let map = Map.make() + map->Map.set("someKey", "someValue") - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) + switch map->Map.get("someKey") { + | None => Console.log("Nope, didn't have it.") + | Some(value) => Console.log2("Yay, had the value, and it's:", value) + } } () }) }) -describe("AsyncIterator.value", () => { - test("AsyncIterator.value", () => { +describe("Map.has", () => { + test("Map.has", () => { module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 + let map = Map.make() + map->Map.set("someKey", "someValue") - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) + switch map->Map.has("someKey") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") + } } () }) }) -describe("AsyncIterator.make", () => { - test("AsyncIterator.make", () => { +describe("Map.set", () => { + test("Map.set", () => { module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 - - { - AsyncIterator.value: Some(currentValue), - done: currentValue >= 3, - } - }, - ) - - // This will log 1, 2, 3 - let main = async () => - await asyncIterator->AsyncIterator.forEach( - value => - switch value { - | Some(value) => Console.log(value) - | None => () - }, - ) - - main()->ignore + let map = Map.make() + map->Map.set("someKey", "someValue") } () }) }) -describe("Array.last", () => { - test("Array.last", () => { +describe("Int.mod", () => { + test("Int.mod", () => { module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.last - ->assertEqual(Some("Good bye")) - - [] - ->Array.last - ->assertEqual(None) + Int.mod(7, 4) == 3 } () }) }) -describe("Array.at", () => { - test("Array.at", () => { +describe("Set.make", () => { + test("Set.make", () => { module Test = { - ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(3)->assertEqual(None) - ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(-4)->assertEqual(None) + // You can annotate the type of your set if you want to + let mySet: Set.t = Set.make() + + // Or you can let ReScript infer what's in your Set + let set = Set.make() + set->Set.add("Fine name") // Inferred as Set.t } () }) }) -describe("Array.findMap", () => { - test("Array.findMap", () => { +describe("Set.size", () => { + test("Set.size", () => { module Test = { - Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) - - Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( - Some(-6), - ) + let set = Set.make() - Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) + set->Set.add("someValue") + set->Set.add("someValue") + set->Set.add("someValue2") - Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) + let size = set->Set.size // 2 } () }) }) -describe("Array.flatMapWithIndex", () => { - test("Array.flatMapWithIndex", () => { +describe("List.add", () => { + test("List.add", () => { module Test = { - type language = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] + List.add(list{2, 3}, 1) // list{1, 2, 3} - array - ->Array.flatMapWithIndex( - (item, index) => - switch item { - | ReScript => [index] - | TypeScript => [index, index + 1] - | JavaScript => [index, index + 1, index + 2] - }, - ) - ->assertEqual([0, 1, 2, 2, 3, 4]) + List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Array.flatMap", () => { - test("Array.flatMap", () => { +describe("List.get", () => { + test("List.get", () => { module Test = { - type language = ReScript | TypeScript | JavaScript + let abc = list{"A", "B", "C"} - let array = [ReScript, TypeScript, JavaScript] + abc->List.get(1) // Some("B") - array - ->Array.flatMap( - item => - switch item { - | ReScript => [1, 2, 3] - | TypeScript => [4, 5, 6] - | JavaScript => [7, 8, 9] - }, - ) - ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) + abc->List.get(4) // None } () }) }) -describe("Array.shuffle", () => { - test("Array.shuffle", () => { +describe("List.map", () => { + test("List.map", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.shuffle - Console.log(array) - - let array2 = [1, 2, 3] - array2->Array.shuffle - - array2 - ->Array.length - ->assertEqual(3) + list{1, 2}->List.map(x => x + 1) // list{3, 4} } () }) }) -describe("Array.toShuffled", () => { - test("Array.toShuffled", () => { +describe("List.zip", () => { + test("List.zip", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let shuffledArray = array->Array.toShuffled - Console.log(shuffledArray) - - Array.toShuffled([1, 2, 3]) - ->Array.length - ->assertEqual(3) + List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} } () }) }) -describe("Array.keepSome", () => { - test("Array.keepSome", () => { +describe("List.has", () => { + test("List.has", () => { module Test = { - Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) - - Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) + list{1, 2, 3}->List.has(2, (a, b) => a == b) // true - Array.keepSome([None, None, None])->assertEqual([]) + list{1, 2, 3}->List.has(4, (a, b) => a == b) // false - Array.keepSome([])->assertEqual([]) + list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true } () }) }) -describe("Array.filterMap", () => { - test("Array.filterMap", () => { +describe("Null.map", () => { + test("Null.map", () => { module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.filterMap( - item => - switch item { - | "Hello" => Some(item->String.length) - | _ => None - }, - ) - ->assertEqual([5]) - - [1, 2, 3, 4, 5, 6] - ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) - ->assertEqual([4, 16, 36]) - - Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) - - Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) + Null.map(Null.make(3), x => x * x) // Null.make(9) + Null.map(Null.null, x => x * x) // null } () }) }) -describe("Array.findIndexOpt", () => { - test("Array.findIndexOpt", () => { +describe("Math.abs", () => { + test("Math.abs", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.findIndexOpt(item => item == ReScript) - ->assertEqual(Some(0)) + Math.abs(-2.0) // 2.0 + Math.abs(3.0) // 3.0 } () }) }) -describe("Array.setUnsafe", () => { - test("Array.setUnsafe", () => { +describe("Math.cos", () => { + test("Math.cos", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.setUnsafe(1, "Hello") - - assertEqual(array[1], Some("Hello")) + Math.cos(-0.0) // 1.0 + Math.cos(0.0) // 1.0 + Math.cos(1.0) // 0.5403023058681398 } () }) }) -describe("Array.unsafe_get", () => { - test("Array.unsafe_get", () => { +describe("Math.exp", () => { + test("Math.exp", () => { module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.unsafe_get(index) - Console.log(value) - } + Math.exp(-1.0) // 0.36787944117144233 + Math.exp(0.0) // 1.0 } () }) }) -describe("Array.getUnsafe", () => { - test("Array.getUnsafe", () => { +describe("Math.log", () => { + test("Math.log", () => { module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.getUnsafe(index) - Console.log(value) - } + Math.log(-1.0)->Float.isNaN // true + Math.log(-0.0)->Float.isFinite // false + Math.log(0.0)->Float.isFinite // false + Math.log(1.0) // 0 } () }) }) -describe("Array.set", () => { - test("Array.set", () => { +describe("Math.min", () => { + test("Math.min", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.set(1, "Hello") - - array[1]->assertEqual(Some("Hello")) + Math.min(1.0, 2.0) // 1.0 + Math.min(-1.0, -2.0) // -2.0 } () }) }) -describe("Array.get", () => { - test("Array.get", () => { +describe("Math.max", () => { + test("Math.max", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.get(0) - ->assertEqual(Some("Hello")) - - array - ->Array.get(3) - ->assertEqual(None) + Math.max(1.0, 2.0) // 2.0 + Math.max(-1.0, -2.0) // -1.0 } () }) }) -describe("Array.someWithIndex", () => { - test("Array.someWithIndex", () => { +describe("Math.pow", () => { + test("Math.pow", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) - ->assertEqual(true) + Math.pow(2.0, ~exp=4.0) // 16.0 + Math.pow(3.0, ~exp=4.0) // 81.0 } () }) }) -describe("Array.some", () => { - test("Array.some", () => { +describe("Math.sin", () => { + test("Math.sin", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.some(greeting => greeting === "Hello") - ->assertEqual(true) + Math.sin(-0.0) // -0.0 + Math.sin(0.0) // 0.0 + Math.sin(1.0) // 0.8414709848078965 } () }) }) -describe("Array.reduceRightWithIndex", () => { - test("Array.reduceRightWithIndex", () => { +describe("Math.tan", () => { + test("Math.tan", () => { module Test = { - Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) - - Array.reduceRightWithIndex( - [], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{}) + Math.tan(-0.0) // -0.0 + Math.tan(0.0) // 0.0 + Math.tan(1.0) // 1.5574077246549023 } () }) }) -describe("Array.reduceRight", () => { - test("Array.reduceRight", () => { +describe("Map.make", () => { + test("Map.make", () => { module Test = { - Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") - - Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) + `make()` + // You can annotate the type of your map if you want to + let myMap: Map.t = Map.make() - Array.reduceRight([], list{}, List.add)->assertEqual(list{}) + // Or you can let ReScript infer what's in your map + let map = Map.make() + map->Map.set("lang", "ReScript") // Inferred as Map.t } () }) }) -describe("Array.reduceWithIndex", () => { - test("Array.reduceWithIndex", () => { +describe("Map.size", () => { + test("Map.size", () => { module Test = { - Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + let map = Map.make() - Array.reduceWithIndex( - [1, 2, 3], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{5, 3, 1}) + map->Map.set("someKey", "someValue") - Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) + let size = map->Map.size // 1 } () }) }) -describe("Array.reduce", () => { - test("Array.reduce", () => { +describe("Map.keys", () => { + test("Map.keys", () => { module Test = { - Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") - Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") + let keys = map->Map.keys - [1, 2, 3] - ->Array.reduce(list{}, List.add) - ->assertEqual(list{3, 2, 1}) + // Logs the first key + Console.log(Iterator.next(keys).value) - Array.reduce([], list{}, List.add)->assertEqual(list{}) + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. + Console.log(map->Map.keys->Iterator.toArray) } () }) }) -describe("Array.mapWithIndex", () => { - test("Array.mapWithIndex", () => { +describe("Dict.get", () => { + test("Dict.get", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = - array->Array.mapWithIndex( - (greeting, index) => greeting ++ " at position " ++ Int.toString(index), - ) + let dict = Dict.fromArray([("someKey", "someValue")]) - assertEqual( - mappedArray, - ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], - ) + switch dict->Dict.get("someKey") { + | None => Console.log("Nope, didn't have the key.") + | Some(value) => Console.log(value) + } } () }) }) -describe("Array.map", () => { - test("Array.map", () => { +describe("Dict.set", () => { + test("Dict.set", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = array->Array.map(greeting => greeting ++ " to you") + let dict = Dict.make() - assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) + dict->Dict.set("someKey", "someValue") } () }) }) -describe("Array.forEachWithIndex", () => { - test("Array.forEachWithIndex", () => { +describe("Belt.Set", () => { + test("Belt.Set", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) - array->Array.forEachWithIndex( - (item, index) => { - Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) - }, - ) + let mySet = Belt.Set.make(~id=module(PairComparator)) + let mySet2 = Belt.Set.add(mySet, (1, 2)) + + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) } () }) }) -describe("Array.forEach", () => { - test("Array.forEach", () => { +describe("Array.at", () => { + test("Array.at", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array->Array.forEach( - item => { - Console.log(item) - }, - ) + ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(3)->assertEqual(None) + ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(-4)->assertEqual(None) } () }) }) -describe("Array.findIndexWithIndex", () => { - test("Array.findIndexWithIndex", () => { +describe("Set.clear", () => { + test("Set.clear", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] + let set = Set.make() - let isReScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) - let isTypeScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) + set->Set.add("someKey") + set->Set.size // 1 - assertEqual(isReScriptFirst, 0) - assertEqual(isTypeScriptFirst, -1) + set->Set.clear + set->Set.size // 0 } () }) }) -describe("Array.findIndex", () => { - test("Array.findIndex", () => { +describe("Object.is", () => { + test("Object.is", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] + Object.is(25, 13) // false + Object.is("abc", "abc") // true + Object.is(undefined, undefined) // true + Object.is(undefined, null) // false + Object.is(-0.0, 0.0) // false + Object.is(list{1, 2}, list{1, 2}) // false - array - ->Array.findIndex(item => item == ReScript) - ->assertEqual(0) + Object.is([1, 2, 3], [1, 2, 3]) // false + [1, 2, 3] == [1, 2, 3] // true + [1, 2, 3] === [1, 2, 3] // false - array - ->Array.findIndex(item => item == TypeScript) - ->assertEqual(-1) + let fruit = {"name": "Apple"} + Object.is(fruit, fruit) // true + Object.is(fruit, {"name": "Apple"}) // false + fruit == {"name": "Apple"} // true + fruit === {"name": "Apple"} // false } () }) }) -describe("Array.findWithIndex", () => { - test("Array.findWithIndex", () => { +describe("List.size", () => { + test("List.size", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [TypeScript, JavaScript, ReScript] - - array - ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) - ->assertEqual(Some(ReScript)) + List.size(list{1, 2, 3}) // 3 } () }) }) -describe("Array.find", () => { - test("Array.find", () => { +describe("List.head", () => { + test("List.head", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.find(item => item == ReScript) - ->assertEqual(Some(ReScript)) + List.head(list{}) // None + List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Array.filterWithIndex", () => { - test("Array.filterWithIndex", () => { +describe("List.tail", () => { + test("List.tail", () => { module Test = { - [1, 2, 3, 4] - ->Array.filterWithIndex((num, index) => index === 0 || num === 2) - ->assertEqual([1, 2]) + List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + List.tail(list{}) // None } () }) }) -describe("Array.filter", () => { - test("Array.filter", () => { +describe("List.make", () => { + test("List.make", () => { module Test = { - [1, 2, 3, 4] - ->Array.filter(num => num > 2) - ->assertEqual([3, 4]) + List.make(~length=3, 1) // list{1, 1, 1} } () }) }) -describe("Array.everyWithIndex", () => { - test("Array.everyWithIndex", () => { +describe("List.drop", () => { + test("List.drop", () => { module Test = { - let array = [1, 2, 3, 4] + list{1, 2, 3}->List.drop(2) // Some(list{3}) - array - ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) - ->assertEqual(true) + list{1, 2, 3}->List.drop(3) // Some(list{}) - array - ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) - ->assertEqual(false) + list{1, 2, 3}->List.drop(4) // None } () }) }) -describe("Array.every", () => { - test("Array.every", () => { +describe("List.take", () => { + test("List.take", () => { module Test = { - let array = [1, 2, 3, 4] + list{1, 2, 3}->List.take(1) // Some(list{1}) - array - ->Array.every(num => num <= 4) - ->assertEqual(true) + list{1, 2, 3}->List.take(2) // Some(list{1, 2}) - array - ->Array.every(num => num === 1) - ->assertEqual(false) + list{1, 2, 3}->List.take(4) // None } () }) }) -describe("Array.toString", () => { - test("Array.toString", () => { +describe("List.flat", () => { + test("List.flat", () => { module Test = { - [1, 2, 3, 4] - ->Array.toString - ->assertEqual("1,2,3,4") + List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("Array.copy", () => { - test("Array.copy", () => { +describe("List.some", () => { + test("List.some", () => { module Test = { - let myArray = [1, 2, 3] - let copyOfMyArray = myArray->Array.copy + let isAbove100 = value => value > 100 - copyOfMyArray->assertEqual([1, 2, 3]) - assertEqual(myArray === copyOfMyArray, false) + list{101, 1, 2, 3}->List.some(isAbove100) // true + + list{1, 2, 3, 4}->List.some(isAbove100) // false } () }) }) -describe("Array.sliceToEnd", () => { - test("Array.sliceToEnd", () => { +describe("List.find", () => { + test("List.find", () => { module Test = { - [1, 2, 3, 4] - ->Array.sliceToEnd(~start=1) - ->assertEqual([2, 3, 4]) + List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) + + List.find(list{1, 4, 3, 2}, x => x > 4) // None } () }) }) -describe("Array.slice", () => { - test("Array.slice", () => { +describe("List.sort", () => { + test("List.sort", () => { module Test = { - [1, 2, 3, 4] - ->Array.slice(~start=1, ~end=3) - ->assertEqual([2, 3]) + List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} } () }) }) -describe("Array.joinWithUnsafe", () => { - test("Array.joinWithUnsafe", () => { +describe("Null.null", () => { + test("Null.null", () => { module Test = { - [1, 2, 3] - ->Array.joinWithUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") + Console.log(null) // Logs `null` to the console. } () }) }) -describe("Array.joinUnsafe", () => { - test("Array.joinUnsafe", () => { +describe("Null.make", () => { + test("Null.make", () => { module Test = { - [1, 2, 3] - ->Array.joinUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") + let myStr = "Hello" + let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. } () }) }) -describe("Array.joinWith", () => { - test("Array.joinWith", () => { +describe("Math.acos", () => { + test("Math.acos", () => { module Test = { - ["One", "Two", "Three"] - ->Array.joinWith(" -- ") - ->assertEqual("One -- Two -- Three") + Math.acos(-1.0) // 3.141592653589793 + Math.acos(-3.0)->Float.isNaN // true } () }) }) -describe("Array.join", () => { - test("Array.join", () => { +describe("Math.asin", () => { + test("Math.asin", () => { module Test = { - ["One", "Two", "Three"] - ->Array.join(" -- ") - ->assertEqual("One -- Two -- Three") + Math.asin(-1.0) // -1.5707963267948966 + Math.asin(-2.0)->Float.isNaN // true } () }) }) -describe("Array.indexOfOpt", () => { - test("Array.indexOfOpt", () => { +describe("Math.atan", () => { + test("Math.atan", () => { module Test = { - [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) - [1, 2]->Array.indexOfOpt(3)->assertEqual(None) - [{"language": "ReScript"}] - ->Array.indexOfOpt({"language": "ReScript"}) - ->assertEqual(None) // None, because of strict equality + Math.atan(-0.0) // -0.0 + Math.atan(0.0) // 0.0 + Math.atan(1.0) // 0.7853981633974483 } () }) }) -describe("Array.indexOf", () => { - test("Array.indexOf", () => { +describe("Math.cbrt", () => { + test("Math.cbrt", () => { module Test = { - [1, 2]->Array.indexOf(2)->assertEqual(1) - [1, 2]->Array.indexOf(3)->assertEqual(-1) - - [{"language": "ReScript"}] - ->Array.indexOf({"language": "ReScript"}) - ->assertEqual(-1) // -1, because of strict equality + Math.cbrt(-1.0) // -1.0 + Math.cbrt(-0.0) // -0.0 + Math.cbrt(0.0) // 0.0 } () }) }) -describe("Array.includes", () => { - test("Array.includes", () => { +describe("Math.ceil", () => { + test("Math.ceil", () => { module Test = { - [1, 2]->Array.includes(1)->assertEqual(true) - [1, 2]->Array.includes(3)->assertEqual(false) - - [{"language": "ReScript"}] - ->Array.includes({"language": "ReScript"}) - ->assertEqual(false) // false, because of strict equality + Math.ceil(3.1) == 4.0 + Math.ceil(3.0) == 3.0 + Math.ceil(-3.1) == -3.0 + Math.ceil(2_150_000_000.3) == 2_150_000_001.0 } () }) }) -describe("Array.flat", () => { - test("Array.flat", () => { +describe("Math.cosh", () => { + test("Math.cosh", () => { module Test = { - [[1], [2], [3, 4]] - ->Array.flat - ->assertEqual([1, 2, 3, 4]) + Math.cosh(-1.0) // 1.5430806348152437 + Math.cosh(-0.0) // 1.0 + Math.cosh(0.0) // 1.0 } () }) }) -describe("Array.concatMany", () => { - test("Array.concatMany", () => { +describe("Math.log2", () => { + test("Math.log2", () => { module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay"] - let array3 = ["wehoo"] - - let someArray = array1->Array.concatMany([array2, array3]) - - Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] + Math.log2(-2.0)->Float.isNaN // true + Math.log2(-0.0)->Float.isFinite // false + Math.log2(0.0)->Float.isFinite // false + Math.log2(1.0) // 0.0 } () }) }) -describe("Array.concat", () => { - test("Array.concat", () => { +describe("Math.sign", () => { + test("Math.sign", () => { module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay", "wehoo"] - - let someArray = array1->Array.concat(array2) - - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) + Math.sign(3.0) // 1.0 + Math.sign(-3.0) // 1.0 + Math.sign(0.0) // 0.0 } () }) }) -describe("Array.unshiftMany", () => { - test("Array.unshiftMany", () => { +describe("Math.sinh", () => { + test("Math.sinh", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshiftMany(["yay", "wehoo"]) - someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) + Math.sinh(-0.0) // -0.0 + Math.sinh(0.0) // 0.0 + Math.sinh(1.0) // 1.1752011936438014 } () }) }) -describe("Array.unshift", () => { - test("Array.unshift", () => { +describe("Math.sqrt", () => { + test("Math.sqrt", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshift("yay") - someArray->assertEqual(["yay", "hi", "hello"]) + Math.sqrt(-1.0)->Float.isNaN // true + Math.sqrt(-0.0) // -0.0 + Math.sqrt(0.0) // 0.0 + Math.sqrt(1.0) // 1.0 + Math.sqrt(9.0) // 3.0 } () }) }) -describe("Array.sort", () => { - test("Array.sort", () => { +describe("Math.tanh", () => { + test("Math.tanh", () => { module Test = { - let array = [3, 2, 1] - array->Array.sort((a, b) => float(a - b)) - array->assertEqual([1, 2, 3]) + Math.tanh(-0.0) // -0.0 + Math.tanh(0.0) // 0.0 + Math.tanh(1.0) // 0.7615941559557649 } () }) }) -describe("Array.shift", () => { - test("Array.shift", () => { +describe("Map.clear", () => { + test("Map.clear", () => { module Test = { - let someArray = ["hi", "hello"] + let map = Map.make() - someArray - ->Array.shift - ->assertEqual(Some("hi")) + map->Map.set("someKey", "someValue") + map->Map.size // 1 - someArray->assertEqual(["hello"]) // Notice first item is gone. + map->Map.clear + map->Map.size // 0 } () }) }) -describe("Array.reverse", () => { - test("Array.reverse", () => { +describe("Int.range", () => { + test("Int.range", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.reverse + Int.range(3, 6) == [3, 4, 5] + Int.range(-3, -1) == [-3, -2] + Int.range(3, 1) == [3, 2] + Int.range(3, 7, ~options={step: 2}) == [3, 5] + Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] + Int.range(3, 6, ~options={step: -2}) // RangeError + } + () + }) +}) - someArray->assertEqual(["hello", "hi"]) +describe("Int.clamp", () => { + test("Int.clamp", () => { + module Test = { + Int.clamp(42) == 42 + Int.clamp(42, ~min=50) == 50 + Int.clamp(42, ~max=40) == 40 + Int.clamp(42, ~min=50, ~max=40) == 50 } () }) }) -describe("Array.pushMany", () => { - test("Array.pushMany", () => { +describe("Float.mod", () => { + test("Float.mod", () => { module Test = { - let someArray = ["hi", "hello"] + Float.mod(7.0, 4.0) == 3.0 + } + () + }) +}) - someArray->Array.pushMany(["yay", "wehoo"]) - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) +describe("Date.make", () => { + test("Date.make", () => { + module Test = { + Date.make() } () }) }) -describe("Array.push", () => { - test("Array.push", () => { +describe("Dict.make", () => { + test("Dict.make", () => { module Test = { - let someArray = ["hi", "hello"] + let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want - someArray->Array.push("yay") + let dict2 = Dict.make() // Or you can let ReScript infer it via usage. + dict2->Dict.set("someKey", 12) + } + () + }) +}) - someArray->assertEqual(["hi", "hello", "yay"]) +describe("Dict.copy", () => { + test("Dict.copy", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let dict2 = dict->Dict.copy + + // Both log `["key1", "key2"]` here. + Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) } () }) @@ -941,3389 +762,2997 @@ describe("Array.pop", () => { }) }) -describe("Array.fill", () => { - test("Array.fill", () => { +describe("Array.map", () => { + test("Array.map", () => { module Test = { - let myArray = [1, 2, 3, 4] - - myArray->Array.fill(9, ~start=1, ~end=3) + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = array->Array.map(greeting => greeting ++ " to you") - myArray->assertEqual([1, 9, 9, 4]) + assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) } () }) }) -describe("Array.fillToEnd", () => { - test("Array.fillToEnd", () => { +describe("Array.get", () => { + test("Array.get", () => { module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillToEnd(9, ~start=1) - myArray->assertEqual([1, 9, 9, 9]) + let array = ["Hello", "Hi", "Good bye"] + + array + ->Array.get(0) + ->assertEqual(Some("Hello")) + + array + ->Array.get(3) + ->assertEqual(None) } () }) }) -describe("Array.fillAll", () => { - test("Array.fillAll", () => { +describe("Array.set", () => { + test("Array.set", () => { module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillAll(9) - myArray->assertEqual([9, 9, 9, 9]) + let array = ["Hello", "Hi", "Good bye"] + array->Array.set(1, "Hello") + + array[1]->assertEqual(Some("Hello")) } () }) }) -describe("Array.length", () => { - test("Array.length", () => { +describe("String.get", () => { + test("String.get", () => { module Test = { - let someArray = ["hi", "hello"] - - someArray - ->Array.length - ->assertEqual(2) + String.get("ReScript", 0) == Some("R") + String.get("Hello", 4) == Some("o") + String.get(`JS`, 4) == None } () }) }) -describe("Array.fromInitializer", () => { - test("Array.fromInitializer", () => { +describe("Set.delete", () => { + test("Set.delete", () => { module Test = { - Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) + let set = Set.make() + set->Set.add("someValue") + let didDeleteValue = set->Set.delete("someValue") + Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted - Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) + let didDeleteValue = set->Set.delete("someNonExistantKey") + Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set } () }) }) -describe("Array.make", () => { - test("Array.make", () => { +describe("Set.values", () => { + test("Set.values", () => { module Test = { - Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) - Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) + let set = Set.make() + set->Set.add("someValue") + set->Set.add("anotherValue") + + let values = set->Set.values + + // Logs the first value + Console.log(Iterator.next(values).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(set->Set.values->Iterator.toArray) } () }) }) -describe("Array.fromIterator", () => { - test("Array.fromIterator", () => { +describe("Result.map", () => { + test("Result.map", () => { module Test = { - Map.fromArray([("foo", 1), ("bar", 2)]) - ->Map.values - ->Array.fromIterator - ->assertEqual([1, 2]) + let f = x => sqrt(Int.toFloat(x)) + + Result.map(Ok(64), f) == Ok(8.0) + + Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Belt_Float./", () => { - test("Belt_Float./", () => { +describe("Result.all", () => { + test("Result.all", () => { module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) + Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) + Result.all([Ok(1), Error(1)]) // Error(1) } () }) }) -describe("Belt_Float.*", () => { - test("Belt_Float.*", () => { +describe("Option.map", () => { + test("Option.map", () => { module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) + Option.map(Some(3), x => x * x) // Some(9) + Option.map(None, x => x * x) // None } () }) }) -describe("Belt_Float.-", () => { - test("Belt_Float.-", () => { +describe("Option.all", () => { + test("Option.all", () => { module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) + Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) + Option.all([Some(1), None]) // None } () }) }) -describe("Belt_Float.+", () => { - test("Belt_Float.+", () => { +describe("Object.get", () => { + test("Object.get", () => { module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) + {"a": 1}->Object.get("a") // Some(1) + {"a": 1}->Object.get("b") // None + {"a": undefined}->Object.get("a") // None + {"a": null}->Object.get("a") // Some(null) + {"a": 1}->Object.get("toString")->Option.isSome // true } () }) }) -describe("Belt_Float.toString", () => { - test("Belt_Float.toString", () => { - module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ +describe("Object.set", () => { + test("Object.set", () => { + module Test = { + {"a": 1}->Object.set("a", 2) // {"a": 2} + {"a": 1}->Object.set("a", None) // {"a": None} + {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} } () }) }) -describe("Belt_Float.fromString", () => { - test("Belt_Float.fromString", () => { +describe("List.zipBy", () => { + test("List.zipBy", () => { module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} } () }) }) -describe("Belt_Float.fromInt", () => { - test("Belt_Float.fromInt", () => { +describe("List.every", () => { + test("List.every", () => { module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + let isBelow10 = value => value < 10 + + list{1, 9, 8, 2}->List.every(isBelow10) // true + + list{1, 99, 8, 2}->List.every(isBelow10) // false } () }) }) -describe("Belt_Float.toInt", () => { - test("Belt_Float.toInt", () => { +describe("List.some2", () => { + test("List.some2", () => { module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true + + List.some2(list{}, list{1}, (a, b) => a > b) // false + + List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true } () }) }) -describe("Belt_Array.truncateToLengthUnsafe", () => { - test("Belt_Array.truncateToLengthUnsafe", () => { +describe("List.equal", () => { + test("List.equal", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] + List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false - Belt.Array.truncateToLengthUnsafe(arr, 3) + List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true - arr == ["ant", "bee", "cat"] + List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true } () }) }) -describe("Belt_Array.eq", () => { - test("Belt_Array.eq", () => { +describe("List.unzip", () => { + test("List.unzip", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) + + List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) } () }) }) -describe("Belt_Array.cmp", () => { - test("Belt_Array.cmp", () => { +describe("Null.getOr", () => { + test("Null.getOr", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + Null.getOr(Null.null, "Banana") // Banana + Null.getOr(Null.make("Apple"), "Banana") // Apple - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Null.make("Jane")->Null.toOption->greet // "Greetings Jane" + Null.null->Null.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Belt_Array.some2", () => { - test("Belt_Array.some2", () => { +describe("Null.mapOr", () => { + test("Null.mapOr", () => { module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - - Belt.Array.some2([], [1], (x, y) => x > y) == false + let someValue = Null.make(3) + someValue->Null.mapOr(0, x => x + 5) // 8 - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + let noneValue = Null.null + noneValue->Null.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Belt_Array.every2", () => { - test("Belt_Array.every2", () => { +describe("Math.acosh", () => { + test("Math.acosh", () => { module Test = { - 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 + Math.acosh(1.0) // 0.0 + Math.acosh(0.5)->Float.isNaN // true } () }) }) -describe("Belt_Array.every", () => { - test("Belt_Array.every", () => { +describe("Math.asinh", () => { + test("Math.asinh", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false + Math.asinh(-1.0) // -0.881373587019543 + Math.asinh(-0.0) // -0.0 } () }) }) -describe("Belt_Array.some", () => { - test("Belt_Array.some", () => { +describe("Math.atanh", () => { + test("Math.atanh", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + Math.atanh(-2.0)->Float.isNaN // true + Math.atanh(-1.0)->Float.isFinite // false + Math.atanh(-0.0) // -0.0 + Math.atanh(0.0) // 0.0 + Math.atanh(0.5) // 0.5493061443340548 } () }) }) -describe("Belt_Array.joinWith", () => { - test("Belt_Array.joinWith", () => { +describe("Math.atan2", () => { + test("Math.atan2", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + Math.atan2(~y=0.0, ~x=10.0) == 0.0 + Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 + Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 + Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 } () }) }) -describe("Belt_Array.reduceWithIndex", () => { - test("Belt_Array.reduceWithIndex", () => { +describe("Math.expm1", () => { + test("Math.expm1", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Math.expm1(-1.0) // -0.6321205588285577 + Math.expm1(-0.0) // -0 } () }) }) -describe("Belt_Array.reduceReverse2", () => { - test("Belt_Array.reduceReverse2", () => { +describe("Math.floor", () => { + test("Math.floor", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + Math.floor(-45.95) // -46.0 + Math.floor(-45.05) // -46.0 + Math.floor(-0.0) // -0.0 } () }) }) -describe("Belt_Array.reduceReverse", () => { - test("Belt_Array.reduceReverse", () => { +describe("Math.hypot", () => { + test("Math.hypot", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + Math.hypot(3.0, 4.0) // 5.0 + Math.hypot(3.0, 5.0) // 5.8309518948453 } () }) }) -describe("Belt_Array.reduce", () => { - test("Belt_Array.reduce", () => { +describe("Math.log1p", () => { + test("Math.log1p", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Math.log1p(-2.0)->Float.isNaN // true + Math.log1p(-1.0)->Float.isFinite // false + Math.log1p(-0.0) // -0 } () }) }) -describe("Belt_Array.partition", () => { - test("Belt_Array.partition", () => { +describe("Math.log10", () => { + test("Math.log10", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + Math.log10(-2.0)->Float.isNaN // true + Math.log10(-0.0)->Float.isFinite // false + Math.log10(0.0)->Float.isFinite // false + Math.log10(1.0) // 0 } () }) }) -describe("Belt_Array.mapWithIndex", () => { - test("Belt_Array.mapWithIndex", () => { +describe("Math.round", () => { + test("Math.round", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + Math.round(-20.5) // -20.0 + Math.round(-0.1) // -0.0 + Math.round(0.0) // 0.0 + Math.round(-0.0) // -0.0 } () }) }) -describe("Belt_Array.forEachWithIndex", () => { - test("Belt_Array.forEachWithIndex", () => { +describe("Math.trunc", () => { + test("Math.trunc", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + Math.trunc(0.123) // 0.0 + Math.trunc(1.999) // 1.0 + Math.trunc(13.37) // 13.0 + Math.trunc(42.84) // 42.0 } () }) }) -describe("Belt_Array.keepMap", () => { - test("Belt_Array.keepMap", () => { +describe("Map.delete", () => { + test("Map.delete", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + let map = Map.make() + map->Map.set("someKey", "someValue") + let didDeleteKey = map->Map.delete("someKey") + Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted + + let didDeleteKey = map->Map.delete("someNonExistantKey") + Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist } () }) }) -describe("Belt_Array.keepWithIndex", () => { - test("Belt_Array.keepWithIndex", () => { +describe("Map.values", () => { + test("Map.values", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") + + let values = map->Map.values + + // Logs the first value + Console.log(Iterator.next(values).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(map->Map.values->Iterator.toArray) } () }) }) -describe("Belt_Array.getIndexBy", () => { - test("Belt_Array.getIndexBy", () => { +describe("Error.name", () => { + test("Error.name", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.name) // Logs "SyntaxError" to the console } () }) }) -describe("Belt_Array.getBy", () => { - test("Belt_Array.getBy", () => { +describe("Error.make", () => { + test("Error.make", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + let error = Error.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console + Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error } () }) }) -describe("Belt_Array.flatMap", () => { - test("Belt_Array.flatMap", () => { +describe("Belt_Int.+", () => { + test("Belt_Int.+", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + open Belt.Int + assertEqual(2 + 2, 4) } () }) }) -describe("Belt_Array.map", () => { - test("Belt_Array.map", () => { +describe("Belt_Int.-", () => { + test("Belt_Int.-", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + open Belt.Int + assertEqual(2 - 1, 1) } () }) }) -describe("Belt_Array.forEach", () => { - test("Belt_Array.forEach", () => { +describe("Belt_Int.*", () => { + test("Belt_Int.*", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 + open Belt.Int + assertEqual(2 * 2, 4) } () }) }) -describe("Belt_Array.blit", () => { - test("Belt_Array.blit", () => { +describe("Belt_Int./", () => { + test("Belt_Int./", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + open Belt.Int + assertEqual(4 / 2, 2) } () }) }) -describe("Belt_Array.fill", () => { - test("Belt_Array.fill", () => { +describe("Belt.Int.+", () => { + test("Belt.Int.+", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + open Belt.Int + assertEqual(2 + 2, 4) } () }) }) -describe("Belt_Array.sliceToEnd", () => { - test("Belt_Array.sliceToEnd", () => { +describe("Belt.Int.-", () => { + test("Belt.Int.-", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + open Belt.Int + assertEqual(2 - 1, 1) } () }) }) -describe("Belt_Array.slice", () => { - test("Belt_Array.slice", () => { +describe("Belt.Int.*", () => { + test("Belt.Int.*", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + open Belt.Int + assertEqual(2 * 2, 4) } () }) }) -describe("Belt_Array.concatMany", () => { - test("Belt_Array.concatMany", () => { +describe("Belt.Int./", () => { + test("Belt.Int./", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + open Belt.Int + assertEqual(4 / 2, 2) } () }) }) -describe("Belt_Array.concat", () => { - test("Belt_Array.concat", () => { +describe("Array.make", () => { + test("Array.make", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) + Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) } () }) }) -describe("Belt_Array.unzip", () => { - test("Belt_Array.unzip", () => { +describe("Array.fill", () => { + test("Array.fill", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + let myArray = [1, 2, 3, 4] - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + myArray->Array.fill(9, ~start=1, ~end=3) + + myArray->assertEqual([1, 9, 9, 4]) } () }) }) -describe("Belt_Array.zipBy", () => { - test("Belt_Array.zipBy", () => { +describe("Array.push", () => { + test("Array.push", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + let someArray = ["hi", "hello"] + + someArray->Array.push("yay") + + someArray->assertEqual(["hi", "hello", "yay"]) } () }) }) -describe("Belt_Array.zip", () => { - test("Belt_Array.zip", () => { +describe("Array.sort", () => { + test("Array.sort", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + let array = [3, 2, 1] + array->Array.sort((a, b) => float(a - b)) + array->assertEqual([1, 2, 3]) } () }) }) -describe("Belt_Array.makeBy", () => { - test("Belt_Array.makeBy", () => { +describe("Array.flat", () => { + test("Array.flat", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + [[1], [2], [3, 4]] + ->Array.flat + ->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Belt_Array.rangeBy", () => { - test("Belt_Array.rangeBy", () => { +describe("Array.join", () => { + test("Array.join", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + ["One", "Two", "Three"] + ->Array.join(" -- ") + ->assertEqual("One -- Two -- Three") } () }) }) -describe("Belt_Array.range", () => { - test("Belt_Array.range", () => { +describe("Array.copy", () => { + test("Array.copy", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] + let myArray = [1, 2, 3] + let copyOfMyArray = myArray->Array.copy - Belt.Array.range(3, 3) == [3] + copyOfMyArray->assertEqual([1, 2, 3]) + assertEqual(myArray === copyOfMyArray, false) } () }) }) -describe("Belt_Array.makeUninitializedUnsafe", () => { - test("Belt_Array.makeUninitializedUnsafe", () => { +describe("Array.find", () => { + test("Array.find", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined + type languages = ReScript | TypeScript | JavaScript - Belt.Array.setExn(arr, 0, "example") + let array = [ReScript, TypeScript, JavaScript] - Js.log(Belt.Array.getExn(arr, 0) == "example") + array + ->Array.find(item => item == ReScript) + ->assertEqual(Some(ReScript)) } () }) }) -describe("Belt_Array.makeUninitialized", () => { - test("Belt_Array.makeUninitialized", () => { +describe("Array.some", () => { + test("Array.some", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + let array = ["Hello", "Hi", "Good bye"] - Belt.Array.getExn(arr, 0) == Js.undefined + array + ->Array.some(greeting => greeting === "Hello") + ->assertEqual(true) } () }) }) -describe("Belt_Array.reverse", () => { - test("Belt_Array.reverse", () => { +describe("Array.last", () => { + test("Array.last", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + ["Hello", "Hi", "Good bye"] + ->Array.last + ->assertEqual(Some("Good bye")) + + [] + ->Array.last + ->assertEqual(None) } () }) }) -describe("Belt_Array.reverseInPlace", () => { - test("Belt_Array.reverseInPlace", () => { +describe("Type.typeof", () => { + test("Type.typeof", () => { module Test = { - let arr = [10, 11, 12, 13, 14] + Console.log(Type.typeof("Hello")) // Logs "string" to the console. - let () = Belt.Array.reverseInPlace(arr) + let someVariable = true - arr == [14, 13, 12, 11, 10] + switch someVariable->Type.typeof { + | #boolean => Console.log("This is a bool, yay!") + | _ => Console.log("Oh, not a bool sadly...") + } } () }) }) -describe("Belt_Array.get", () => { - test("Belt_Array.get", () => { +describe("String.make", () => { + test("String.make", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + String.make(3.5) == "3.5" + String.make([1, 2, 3]) == "1,2,3" } () }) }) -describe("Belt_Array.length", () => { - test("Belt_Array.length", () => { +describe("String.trim", () => { + test("String.trim", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + String.trim(" abc def ") == "abc def" + String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" } () }) }) -describe("Belt_HashMap.logStats", () => { - test("Belt_HashMap.logStats", () => { +describe("Set.forEach", () => { + test("Set.forEach", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") + let set = Set.make() + set->Set.add("someValue") + set->Set.add("someValue2") - Belt.HashMap.logStats(hMap) + set->Set.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt_HashMap.getBucketHistogram", () => { - test("Belt_HashMap.getBucketHistogram", () => { +describe("Set.toArray", () => { + test("Set.toArray", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.getBucketHistogram(hMap) + let set = Set.fromArray(["apple", "orange", "apple", "banana"]) + set->Set.toArray // ["apple", "orange", "banana"] } () }) }) -describe("Belt_HashMap.mergeMany", () => { - test("Belt_HashMap.mergeMany", () => { +describe("RegExp.test", () => { + test("RegExp.test", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + if regexp->RegExp.test("ReScript is cool!") { + Console.log("Yay, there's a word in there.") + } } () }) }) -describe("Belt_HashMap.fromArray", () => { - test("Belt_HashMap.fromArray", () => { +describe("RegExp.exec", () => { + test("RegExp.exec", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("Belt_HashMap.valuesToArray", () => { - test("Belt_HashMap.valuesToArray", () => { +describe("Promise.any", () => { + test("Promise.any", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + any(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Belt_HashMap.keysToArray", () => { - test("Belt_HashMap.keysToArray", () => { +describe("Promise.all", () => { + test("Promise.all", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + open Promise + let promises = [resolve(1), resolve(2), resolve(3)] - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + all(promises) + ->then( + results => { + results->Array.forEach( + num => { + Console.log2("Number: ", num) + }, + ) - Belt.HashMap.keysToArray(s0) == [1, 2] + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_HashMap.toArray", () => { - test("Belt_HashMap.toArray", () => { +describe("Object.make", () => { + test("Object.make", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + let x = Object.make() + x->Object.keysToArray->Array.length // 0 + x->Object.get("toString")->Option.isSome // true } () }) }) -describe("Belt_HashMap.size", () => { - test("Belt_HashMap.size", () => { +describe("Object.seal", () => { + test("Object.seal", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + let point = {"x": 1, "y": 2} + point->Object.set("x", -7) // succeeds + point->Object.seal->ignore - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + try { + point->Object.set("z", 9) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } - Belt.HashMap.size(s0) == 2 + point->Object.set("x", 13) // succeeds } () }) }) -describe("Belt_HashMap.keepMapInPlace", () => { - test("Belt_HashMap.keepMapInPlace", () => { +describe("List.length", () => { + test("List.length", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + List.length(list{1, 2, 3}) // 3 } () }) }) -describe("Belt_HashMap.reduce", () => { - test("Belt_HashMap.reduce", () => { +describe("List.getExn", () => { + test("List.getExn", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + let abc = list{"A", "B", "C"} - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") + abc + ->List.getExn(1) + ->assertEqual("B") - Console.log("lol") + switch abc->List.getExn(4) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_HashMap.forEach", () => { - test("Belt_HashMap.forEach", () => { +describe("List.concat", () => { + test("List.concat", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") + List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("Belt_HashMap.remove", () => { - test("Belt_HashMap.remove", () => { +describe("List.reduce", () => { + test("List.reduce", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false + // same as + + list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 } () }) }) -describe("Belt_HashMap.has", () => { - test("Belt_HashMap.has", () => { +describe("List.every2", () => { + test("List.every2", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") + List.every2(list{}, list{1}, (a, b) => a > b) // true - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false + List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false } () }) }) -describe("Belt_HashMap.get", () => { - test("Belt_HashMap.get", () => { +describe("List.filter", () => { + test("List.filter", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + let isEven = x => mod(x, 2) == 0 - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") + List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None + List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} } () }) }) -describe("Belt_HashMap.copy", () => { - test("Belt_HashMap.copy", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) +describe("Null.getExn", () => { + test("Null.getExn", () => { + module Test = { + Null.getExn(Null.make(3))->assertEqual(3) - Belt.HashMap.set(s0, 2, "3") + switch Null.getExn(%raw("'ReScript'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "ReScript") + } - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + switch Null.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_HashMap.set", () => { - test("Belt_HashMap.set", () => { +describe("Math.fround", () => { + test("Math.fround", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + Math.fround(5.5) == 5.5 + Math.fround(5.05) == 5.050000190734863 } () }) }) -describe("Belt_HashMap.isEmpty", () => { - test("Belt_HashMap.isEmpty", () => { +describe("Math.random", () => { + test("Math.random", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + Math.random() } () }) }) -describe("Belt_HashMap.clear", () => { - test("Belt_HashMap.clear", () => { +describe("Map.forEach", () => { + test("Map.forEach", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true + map->Map.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt_HashMap.make", () => { - test("Belt_HashMap.make", () => { +describe("Map.entries", () => { + test("Map.entries", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + let entries = map->Map.entries - Belt.HashMap.set(hMap, 0, "a") + // Logs the first value + Console.log(Iterator.next(entries).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. + Console.log(map->Map.entries->Iterator.toArray) } () }) }) -describe("Belt.Map.Dict.findFirstBy", () => { - test("Belt.Map.Dict.findFirstBy", () => { +describe("Int.toFixed", () => { + test("Int.toFixed", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + Int.toFixed(123456) // "123456.00" + Int.toFixed(10) // "10.00" + Int.toFixed(300, ~digits=4) // "300.0000" + Int.toFixed(300, ~digits=1) // "300.0" } () }) }) -describe("Belt.Map.String.findFirstBy", () => { - test("Belt.Map.String.findFirstBy", () => { +describe("Int.toFloat", () => { + test("Int.toFloat", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + Int.toFloat(100) == 100.0 + Int.toFloat(2) == 2.0 } () }) }) -describe("Belt.Map.Int.findFirstBy", () => { - test("Belt.Map.Int.findFirstBy", () => { +describe("Float.isNaN", () => { + test("Float.isNaN", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) + Float.isNaN(3.0) // false + Float.isNaN(Float.Constants.nan) // true } () }) }) -describe("Belt.Set.Dict.split", () => { - test("Belt.Set.Dict.split", () => { +describe("Float.toInt", () => { + test("Float.toInt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + Float.toInt(2.0) == 2 + Float.toInt(1.0) == 1 + Float.toInt(1.1) == 1 + Float.toInt(1.6) == 1 } () }) }) -describe("Belt.Set.Dict.get", () => { - test("Belt.Set.Dict.get", () => { +describe("Float.clamp", () => { + test("Float.clamp", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + Float.clamp(4.2) == 4.2 + Float.clamp(4.2, ~min=4.3) == 4.3 + Float.clamp(4.2, ~max=4.1) == 4.1 + Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 } () }) }) -describe("Belt.Set.Dict.maxUndefined", () => { - test("Belt.Set.Dict.maxUndefined", () => { +describe("Error.stack", () => { + test("Error.stack", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ + let error = Error.make("error") + Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` } () }) }) -describe("Belt.Set.Dict.maximum", () => { - test("Belt.Set.Dict.maximum", () => { +describe("Error.raise", () => { + test("Error.raise", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let error = Error.make("Everything is upside down.") - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + if 5 > 10 { + error->Error.raise + } else { + Console.log("Phew, sanity still rules.") + } } () }) }) -describe("Belt.Set.Dict.minUndefined", () => { - test("Belt.Set.Dict.minUndefined", () => { +describe("Error.panic", () => { + test("Error.panic", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + try { + Error.panic("Uh oh. This was unexpected!") + } catch { + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") + | None => assert(false) + } + | _ => assert(false) + } } () }) }) -describe("Belt.Set.Dict.minimum", () => { - test("Belt.Set.Dict.minimum", () => { +describe("Date.getDay", () => { + test("Date.getDay", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.fromString("2023-02-20T16:40:00.00")->Date.getDay + // 1 + } + () + }) +}) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) +describe("Date.toJSON", () => { + test("Date.toJSON", () => { + module Test = { + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON + // Some("2023-01-01T00:00:00.000Z") - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + Date.fromString("")->Date.toJSON + // None } () }) }) -describe("Belt.Set.Dict.toArray", () => { - test("Belt.Set.Dict.toArray", () => { +describe("Dict.delete", () => { + test("Dict.delete", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let dict = Dict.fromArray([("someKey", "someValue")]) - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + dict->Dict.delete("someKey") } () }) }) -describe("Belt.Set.Dict.toList", () => { - test("Belt.Set.Dict.toList", () => { +describe("Dict.assign", () => { + test("Dict.assign", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let dict1 = Dict.make() + dict1->Dict.set("firstKey", 1) + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let dict2 = Dict.make() + dict2->Dict.set("someKey", 2) + dict2->Dict.set("someKey2", 3) - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + let dict1 = dict1->Dict.assign(dict2) + + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` } () }) }) -describe("Belt.Set.Dict.size", () => { - test("Belt.Set.Dict.size", () => { +describe("Console.dir", () => { + test("Console.dir", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ + Console.dir({"language": "rescript", "version": "10.1.2"}) } () }) }) -describe("Belt.Set.Dict.partition", () => { - test("Belt.Set.Dict.partition", () => { +describe("Console.log", () => { + test("Console.log", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) - - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ + Console.log("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.log(obj) } () }) }) -describe("Belt.Set.Dict.keep", () => { - test("Belt.Set.Dict.keep", () => { +describe("Belt_Set.eq", () => { + test("Belt_Set.eq", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - s1->Belt.Set.Dict.toArray /* [2,4] */ + Belt.Set.eq(s0, s1)->assertEqual(true) } () }) }) -describe("Belt.Set.Dict.some", () => { - test("Belt.Set.Dict.some", () => { +describe("Belt.Option", () => { + test("Belt.Option", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + type option<'a> = None | Some('a) - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ + let someString: option = Some("hello") } () }) }) -describe("Belt.Set.Dict.every", () => { - test("Belt.Set.Dict.every", () => { +describe("Belt.Set.eq", () => { + test("Belt.Set.eq", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let isEven = x => mod(x, 2) == 0 + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Belt.Set.eq(s0, s1)->assertEqual(true) } () }) }) -describe("Belt.Set.Dict.reduce", () => { - test("Belt.Set.Dict.reduce", () => { +describe("Array.shift", () => { + test("Array.shift", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let someArray = ["hi", "hello"] - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + someArray + ->Array.shift + ->assertEqual(Some("hi")) + + someArray->assertEqual(["hello"]) // Notice first item is gone. } () }) }) -describe("Belt.Set.Dict.forEach", () => { - test("Belt.Set.Dict.forEach", () => { +describe("Array.slice", () => { + test("Array.slice", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + [1, 2, 3, 4] + ->Array.slice(~start=1, ~end=3) + ->assertEqual([2, 3]) } () }) }) -describe("Belt.Set.Dict.eq", () => { - test("Belt.Set.Dict.eq", () => { +describe("Array.every", () => { + test("Array.every", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let array = [1, 2, 3, 4] - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + array + ->Array.every(num => num <= 4) + ->assertEqual(true) - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + array + ->Array.every(num => num === 1) + ->assertEqual(false) } () }) }) -describe("Belt.Set.Dict.subset", () => { - test("Belt.Set.Dict.subset", () => { +describe("String.match", () => { + test("String.match", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) + String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) + String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) + String.match("The optional example", /(foo)?(example)/) == + Some([Some("example"), None, Some("example")]) + String.match("The large container.", /b[aeiou]g/) == None } () }) }) -describe("Belt.Set.Dict.diff", () => { - test("Belt.Set.Dict.diff", () => { +describe("String.slice", () => { + test("String.slice", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + String.slice("abcdefg", ~start=2, ~end=5) == "cde" + String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" + String.slice("abcdefg", ~start=-4, ~end=-2) == "de" + String.slice("abcdefg", ~start=5, ~end=1) == "" } () }) }) -describe("Belt.Set.Dict.intersect", () => { - test("Belt.Set.Dict.intersect", () => { +describe("String.split", () => { + test("String.split", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + String.split("2018-01-02", "-") == ["2018", "01", "02"] + String.split("a,b,,c", ",") == ["a", "b", "", "c"] + String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] + String.split("has-no-delimiter", ";") == ["has-no-delimiter"] } () }) }) -describe("Belt.Set.Dict.union", () => { - test("Belt.Set.Dict.union", () => { +describe("Result.mapOr", () => { + test("Result.mapOr", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let ok = Ok(42) + Result.mapOr(ok, 0, x => x / 2) == 21 - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + let error = Error("Invalid data") + Result.mapOr(error, 0, x => x / 2) == 0 } () }) }) -describe("Belt.Set.Dict.removeMany", () => { - test("Belt.Set.Dict.removeMany", () => { +describe("Result.getOr", () => { + test("Result.getOr", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + Result.getOr(Ok(42), 0) == 42 - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + Result.getOr(Error("Invalid Data"), 0) == 0 } () }) }) -describe("Belt.Set.Dict.remove", () => { - test("Belt.Set.Dict.remove", () => { +describe("Result.equal", () => { + test("Result.equal", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let good1 = Ok(42) - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let good2 = Ok(32) - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ - } - () - }) -}) + let bad1 = Error("invalid") -describe("Belt.Set.Dict.mergeMany", () => { - test("Belt.Set.Dict.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let bad2 = Error("really invalid") - let set = Belt.Set.Dict.empty + let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + Result.equal(good1, good2, mod10equal) == true + + Result.equal(good1, bad1, mod10equal) == false + + Result.equal(bad2, good2, mod10equal) == false + + Result.equal(bad1, bad2, mod10equal) == true } () }) }) -describe("Belt.Set.Dict.add", () => { - test("Belt.Set.Dict.add", () => { +describe("Promise.make", () => { + test("Promise.make", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + open Promise - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + let n = 4 + Promise.make( + (resolve, reject) => { + if n < 5 { + resolve("success") + } else { + reject("failed") + } + }, + ) + ->then( + str => { + Console.log(str)->resolve + }, + ) + ->catch( + _ => { + Console.log("Error occurred") + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt.Set.Dict.has", () => { - test("Belt.Set.Dict.has", () => { +describe("Promise.then", () => { + test("Promise.then", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + open Promise + resolve(5) + ->then( + num => { + resolve(num + 5) + }, + ) + ->then( + num => { + Console.log2("Your lucky number is: ", num) + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt.Set.Dict.isEmpty", () => { - test("Belt.Set.Dict.isEmpty", () => { +describe("Promise.race", () => { + test("Promise.race", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + race(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Belt.Set.Dict.fromArray", () => { - test("Belt.Set.Dict.fromArray", () => { +describe("Option.mapOr", () => { + test("Option.mapOr", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + let someValue = Some(3) + someValue->Option.mapOr(0, x => x + 5) // 8 - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + let noneValue = None + noneValue->Option.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Belt.Set.Dict.empty", () => { - test("Belt.Set.Dict.empty", () => { +describe("Option.getOr", () => { + test("Option.getOr", () => { module Test = { - let s0 = Belt.Set.Dict.empty + Option.getOr(None, "Banana") // Banana + Option.getOr(Some("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Some("Jane")->greet // "Greetings Jane" + None->greet // "Greetings Anonymous" } () }) }) -describe("Belt.Float./", () => { - test("Belt.Float./", () => { +describe("Option.equal", () => { + test("Option.equal", () => { module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Option + + equal(Some(3), Some(15), clockEqual) // true + equal(Some(3), None, clockEqual) // false + equal(None, Some(3), clockEqual) // false + equal(None, None, clockEqual) // true } () }) }) -describe("Belt.Float.*", () => { - test("Belt.Float.*", () => { +describe("Nullable.map", () => { + test("Nullable.map", () => { module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) + Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) + Nullable.map(undefined, x => x * x) // undefined } () }) }) -describe("Belt.Float.-", () => { - test("Belt.Float.-", () => { +describe("List.headExn", () => { + test("List.headExn", () => { module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) + List.headExn(list{1, 2, 3})->assertEqual(1) + + switch List.headExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.Float.+", () => { - test("Belt.Float.+", () => { +describe("List.tailExn", () => { + test("List.tailExn", () => { module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) + List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch List.tailExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.Float.toString", () => { - test("Belt.Float.toString", () => { +describe("List.splitAt", () => { + test("List.splitAt", () => { module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ + list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + + list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Belt.Float.fromString", () => { - test("Belt.Float.fromString", () => { +describe("List.toArray", () => { + test("List.toArray", () => { module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Belt.Float.fromInt", () => { - test("Belt.Float.fromInt", () => { +describe("List.reverse", () => { + test("List.reverse", () => { module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + List.reverse(list{1, 2, 3}) // list{3, 2, 1} } () }) }) -describe("Belt.Float.toInt", () => { - test("Belt.Float.toInt", () => { +describe("List.forEach", () => { + test("List.forEach", () => { module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("Belt.Int./", () => { - test("Belt.Int./", () => { +describe("List.reduce2", () => { + test("List.reduce2", () => { module Test = { - open Belt.Int - assertEqual(4 / 2, 2) + List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) } () }) }) -describe("Belt.Int.*", () => { - test("Belt.Int.*", () => { +describe("List.compare", () => { + test("List.compare", () => { module Test = { - open Belt.Int - assertEqual(2 * 2, 4) + List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. } () }) }) -describe("Belt.Int.-", () => { - test("Belt.Int.-", () => { +describe("Null.forEach", () => { + test("Null.forEach", () => { module Test = { - open Belt.Int - assertEqual(2 - 1, 1) + Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" + Null.forEach(Null.null, x => Console.log(x)) // logs nothing } () }) }) -describe("Belt.Int.+", () => { - test("Belt.Int.+", () => { +describe("Null.flatMap", () => { + test("Null.flatMap", () => { module Test = { - open Belt.Int - assertEqual(2 + 2, 4) + let addIfAboveOne = value => + if value > 1 { + Null.make(value + 1) + } else { + Null.null + } + + Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) + Null.flatMap(Null.make(-4), addIfAboveOne) // null + Null.flatMap(Null.null, addIfAboveOne) // null } () }) }) -describe("Belt.Int.toString", () => { - test("Belt.Int.toString", () => { +describe("Math.minMany", () => { + test("Math.minMany", () => { module Test = { - Belt.Int.toString(1)->assertEqual("1") + Math.minMany([1.0, 2.0]) // 1.0 + Math.minMany([-1.0, -2.0]) // -2.0 + Math.minMany([])->Float.isFinite // false } () }) }) -describe("Belt.Int.fromString", () => { - test("Belt.Int.fromString", () => { +describe("Math.maxMany", () => { + test("Math.maxMany", () => { module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) + Math.maxMany([1.0, 2.0]) // 2.0 + Math.maxMany([-1.0, -2.0]) // -1.0 + Math.maxMany([])->Float.isFinite // false } () }) }) -describe("Belt.Int.fromFloat", () => { - test("Belt.Int.fromFloat", () => { +describe("Math.Int.abs", () => { + test("Math.Int.abs", () => { module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) + Math.Int.abs(-2) // 2 + Math.Int.abs(3) // 3 } () }) }) -describe("Belt.Int.toFloat", () => { - test("Belt.Int.toFloat", () => { +describe("Math.Int.min", () => { + test("Math.Int.min", () => { module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) + Math.Int.min(1, 2) // 1 + Math.Int.min(-1, -2) // -2 } () }) }) -describe("Belt.Result.cmp", () => { - test("Belt.Result.cmp", () => { +describe("Math.Int.max", () => { + test("Math.Int.max", () => { module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 - - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + Math.Int.max(1, 2) // 2 + Math.Int.max(-1, -2) // -1 } () }) }) -describe("Belt.Result.eq", () => { - test("Belt.Result.eq", () => { +describe("Math.Int.pow", () => { + test("Math.Int.pow", () => { module Test = { - let good1 = Belt.Result.Ok(42) - - let good2 = Belt.Result.Ok(32) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(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 + Math.Int.pow(2, ~exp=4) // 16 + Math.Int.pow(3, ~exp=4) // 81 } () }) }) -describe("Belt.Result.getWithDefault", () => { - test("Belt.Result.getWithDefault", () => { +describe("Int.toString", () => { + test("Int.toString", () => { module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 - - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + Int.toString(1000) // "1000" + Int.toString(-1000) // "-1000" + Int.toString(6, ~radix=2) // "110" + Int.toString(373592855, ~radix=16) // "16449317" + Int.toString(123456, ~radix=36) // "2n9c" } () }) }) -describe("Belt.Result.flatMap", () => { - test("Belt.Result.flatMap", () => { +describe("Date.getTime", () => { + test("Date.getTime", () => { module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } - - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + Date.fromString("2023-02-20")->Date.getTime + // 1676851200000 } () }) }) -describe("Belt.Result.map", () => { - test("Belt.Result.map", () => { +describe("Date.getDate", () => { + test("Date.getDate", () => { module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) - - Belt.Result.map(Ok(64), f) == Ok(8.0) - - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + Date.fromString("2023-02-20T16:40:00.00")->Date.getDate + // 20 } () }) }) -describe("Belt.Result.mapWithDefault", () => { - test("Belt.Result.mapWithDefault", () => { +describe("Date.setDate", () => { + test("Date.setDate", () => { module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) } () }) }) -describe("Belt.Result.getExn", () => { - test("Belt.Result.getExn", () => { +describe("Dict.toArray", () => { + test("Dict.toArray", () => { module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) - - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let asArray = dict->Dict.toArray + Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console } () }) }) -describe("Belt.Option.cmp", () => { - test("Belt.Option.cmp", () => { +describe("Dict.forEach", () => { + test("Dict.forEach", () => { module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ - - cmp(Some(14), None, clockCompare) /* 1 */ + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - cmp(None, None, clockCompare) /* 0 */ + dict->Dict.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt.Option.eq", () => { - test("Belt.Option.eq", () => { +describe("Console.info", () => { + test("Console.info", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Belt.Option - - eq(Some(3), Some(15), clockEqual) /* true */ - - eq(Some(3), None, clockEqual) /* false */ - - eq(None, Some(3), clockEqual) /* false */ - - eq(None, None, clockEqual) /* true */ + Console.info("Information") + Console.info(("Hello", "JS")) } () }) }) -describe("Belt.Option.isNone", () => { - test("Belt.Option.isNone", () => { +describe("Console.log2", () => { + test("Console.log2", () => { module Test = { - Belt.Option.isNone(None) /* true */ - - Belt.Option.isNone(Some(1)) /* false */ + Console.log2("Hello", "World") + Console.log2([1, 2, 3], '4') } () }) }) -describe("Belt.Option.isSome", () => { - test("Belt.Option.isSome", () => { +describe("Console.log3", () => { + test("Console.log3", () => { module Test = { - Belt.Option.isSome(None) /* false */ - - Belt.Option.isSome(Some(1)) /* true */ + Console.log3("Hello", "World", "ReScript") + Console.log3("One", 2, #3) } () }) }) -describe("Belt.Option.orElse", () => { - test("Belt.Option.orElse", () => { +describe("Console.log4", () => { + test("Console.log4", () => { module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None + Console.log4("Hello", "World", "ReScript", "!!!") + Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Belt.Option.getWithDefault", () => { - test("Belt.Option.getWithDefault", () => { +describe("Console.log5", () => { + test("Console.log5", () => { module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ + Console.log5("Hello", "World", "JS", '!', '!') + Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt.Option.flatMap", () => { - test("Belt.Option.flatMap", () => { +describe("Console.log6", () => { + test("Console.log6", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ + Console.log6("Hello", "World", "JS", '!', '!', '?') + Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.Option.map", () => { - test("Belt.Option.map", () => { +describe("Console.time", () => { + test("Console.time", () => { module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ - - Belt.Option.map(None, x => x * x) /* None */ + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt.Option.mapWithDefault", () => { - test("Belt.Option.mapWithDefault", () => { +describe("Console.warn", () => { + test("Console.warn", () => { module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + Console.warn("Warning") + Console.warn(("Warning", "invalid number")) } () }) }) -describe("Belt.Option.getExn", () => { - test("Belt.Option.getExn", () => { +describe("Belt_Set.has", () => { + test("Belt_Set.has", () => { module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) } () }) }) -describe("Belt.Option.forEach", () => { - test("Belt.Option.forEach", () => { +describe("Belt_Set.add", () => { + test("Belt_Set.add", () => { module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) + + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) } () }) }) -describe("Belt.Option.keep", () => { - test("Belt.Option.keep", () => { +describe("Belt_Set.get", () => { + test("Belt_Set.get", () => { module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) } () }) }) -describe("Belt.HashMap.logStats", () => { - test("Belt.HashMap.logStats", () => { +describe("Belt_Map.Int", () => { + test("Belt_Map.Int", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.logStats(hMap) + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> } () }) }) -describe("Belt.HashMap.getBucketHistogram", () => { - test("Belt.HashMap.getBucketHistogram", () => { +describe("Belt_Map.has", () => { + test("Belt_Map.has", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - Belt.HashMap.getBucketHistogram(hMap) + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true } () }) }) -describe("Belt.HashMap.mergeMany", () => { - test("Belt.HashMap.mergeMany", () => { +describe("Belt_Map.get", () => { + test("Belt_Map.get", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") + + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None } () }) }) -describe("Belt.HashMap.fromArray", () => { - test("Belt.HashMap.fromArray", () => { +describe("Belt_Map.set", () => { + test("Belt_Map.set", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.set(s0, 2, "3") + + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] } () }) }) -describe("Belt.HashMap.valuesToArray", () => { - test("Belt.HashMap.valuesToArray", () => { +describe("Belt_List.eq", () => { + test("Belt_List.eq", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Belt.HashMap.keysToArray", () => { - test("Belt.HashMap.keysToArray", () => { +describe("Belt.HashSet", () => { + test("Belt.HashSet", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) - Belt.HashMap.keysToArray(s0) == [1, 2] + module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) + + let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) + + Belt.HashSet.add(s1, 0) + Belt.HashSet.add(s1, 1) } () }) }) -describe("Belt.HashMap.toArray", () => { - test("Belt.HashMap.toArray", () => { +describe("Belt.HashMap", () => { + test("Belt.HashMap", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + type t = int + module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) + let s0: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I0), + ) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) + let s1: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I1), + ) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + let () = { + Belt.HashMap.set(s0, 0, 3) + Belt.HashMap.set(s1, 1, "3") + } } () }) }) -describe("Belt.HashMap.size", () => { - test("Belt.HashMap.size", () => { +describe("Belt.List.eq", () => { + test("Belt.List.eq", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - Belt.HashMap.size(s0) == 2 + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Belt.HashMap.keepMapInPlace", () => { - test("Belt.HashMap.keepMapInPlace", () => { +describe("Belt.Set.has", () => { + test("Belt.Set.has", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) } () }) }) -describe("Belt.HashMap.reduce", () => { - test("Belt.HashMap.reduce", () => { +describe("Belt.Set.add", () => { + test("Belt.Set.add", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + let s0 = Belt.Set.make(~id=module(IntCmp)) - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) - Console.log("lol") + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) } () }) }) -describe("Belt.HashMap.forEach", () => { - test("Belt.HashMap.forEach", () => { +describe("Belt.Set.get", () => { + test("Belt.Set.get", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) } () }) }) -describe("Belt.HashMap.remove", () => { - test("Belt.HashMap.remove", () => { +describe("Belt.Map.Int", () => { + test("Belt.Map.Int", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> } () }) }) -describe("Belt.HashMap.has", () => { - test("Belt.HashMap.has", () => { +describe("Belt.Map.has", () => { + test("Belt.Map.has", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true } () }) }) -describe("Belt.HashMap.get", () => { - test("Belt.HashMap.get", () => { +describe("Belt.Map.get", () => { + test("Belt.Map.get", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None } () }) }) -describe("Belt.HashMap.copy", () => { - test("Belt.HashMap.copy", () => { +describe("Belt.Map.set", () => { + test("Belt.Map.set", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - Belt.HashMap.set(s0, 2, "3") + let s1 = Belt.Map.set(s0, 2, "3") - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] } () }) }) -describe("Belt.HashMap.set", () => { - test("Belt.HashMap.set", () => { +describe("Belt.Float.+", () => { + test("Belt.Float.+", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) } () }) }) -describe("Belt.HashMap.isEmpty", () => { - test("Belt.HashMap.isEmpty", () => { +describe("Belt.Float.-", () => { + test("Belt.Float.-", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) } () }) }) -describe("Belt.HashMap.clear", () => { - test("Belt.HashMap.clear", () => { +describe("Belt.Float.*", () => { + test("Belt.Float.*", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) } () }) }) -describe("Belt.HashMap.make", () => { - test("Belt.HashMap.make", () => { +describe("Belt.Float./", () => { + test("Belt.Float./", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(hMap, 0, "a") + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) } () }) }) -describe("Belt.MutableSet.split", () => { - test("Belt.MutableSet.split", () => { +describe("Belt_Float.+", () => { + test("Belt_Float.+", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) - - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) } () }) }) -describe("Belt.MutableSet.get", () => { - test("Belt.MutableSet.get", () => { +describe("Belt_Float.-", () => { + test("Belt_Float.-", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) } () }) }) -describe("Belt.MutableSet.maxUndefined", () => { - test("Belt.MutableSet.maxUndefined", () => { +describe("Belt_Float.*", () => { + test("Belt_Float.*", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) } () }) }) -describe("Belt.MutableSet.maximum", () => { - test("Belt.MutableSet.maximum", () => { +describe("Belt_Float./", () => { + test("Belt_Float./", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) } () }) }) -describe("Belt.MutableSet.minUndefined", () => { - test("Belt.MutableSet.minUndefined", () => { +describe("Array.length", () => { + test("Array.length", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let someArray = ["hi", "hello"] - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ + someArray + ->Array.length + ->assertEqual(2) } () }) }) -describe("Belt.MutableSet.minimum", () => { - test("Belt.MutableSet.minimum", () => { +describe("Array.concat", () => { + test("Array.concat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let array1 = ["hi", "hello"] + let array2 = ["yay", "wehoo"] - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let someArray = array1->Array.concat(array2) - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) } () }) }) -describe("Belt.MutableSet.toArray", () => { - test("Belt.MutableSet.toArray", () => { +describe("Array.filter", () => { + test("Array.filter", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + [1, 2, 3, 4] + ->Array.filter(num => num > 2) + ->assertEqual([3, 4]) } () }) }) -describe("Belt.MutableSet.toList", () => { - test("Belt.MutableSet.toList", () => { +describe("Array.reduce", () => { + test("Array.reduce", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") - s0->Belt.MutableSet.toList /* [1,2,3,5] */ + [1, 2, 3] + ->Array.reduce(list{}, List.add) + ->assertEqual(list{3, 2, 1}) + + Array.reduce([], list{}, List.add)->assertEqual(list{}) } () }) }) -describe("Belt.MutableSet.size", () => { - test("Belt.MutableSet.size", () => { +describe("String.length", () => { + test("String.length", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ + String.length("abcd") == 4 } () }) }) -describe("Belt.MutableSet.partition", () => { - test("Belt.MutableSet.partition", () => { +describe("String.charAt", () => { + test("String.charAt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ + String.charAt("ReScript", 0) == "R" + String.charAt("Hello", 12) == "" + String.charAt(`JS`, 5) == "" } () }) }) -describe("Belt.MutableSet.keep", () => { - test("Belt.MutableSet.keep", () => { +describe("String.concat", () => { + test("String.concat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ + String.concat("cow", "bell") == "cowbell" + String.concat("Re", "Script") == "ReScript" } () }) }) -describe("Belt.MutableSet.some", () => { - test("Belt.MutableSet.some", () => { +describe("String.repeat", () => { + test("String.repeat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ + String.repeat("ha", 3) == "hahaha" + String.repeat("empty", 0) == "" } () }) }) -describe("Belt.MutableSet.every", () => { - test("Belt.MutableSet.every", () => { +describe("String.search", () => { + test("String.search", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ + String.search("testing 1 2 3", /\d+/) == 8 + String.search("no numbers", /\d+/) == -1 } () }) }) -describe("Belt.MutableSet.reduce", () => { - test("Belt.MutableSet.reduce", () => { +describe("String.padEnd", () => { + test("String.padEnd", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + String.padEnd("Hello", 10, ".") == "Hello....." + String.padEnd("abc", 1, "") == "abc" } () }) }) -describe("Belt.MutableSet.forEach", () => { - test("Belt.MutableSet.forEach", () => { +describe("Set.fromArray", () => { + test("Set.fromArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + type languages = ReScript | JavaScript | TypeScript + let languageRank = [ReScript, JavaScript, TypeScript] - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + let set = Set.fromArray(languageRank) // Set.t + + switch set->Set.has(ReScript) { + | true => Console.log("Yay, ReScript is in there!") + | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } } () }) }) -describe("Belt.MutableSet.eq", () => { - test("Belt.MutableSet.eq", () => { +describe("RegExp.global", () => { + test("RegExp.global", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set - Belt.MutableSet.eq(s0, s1) /* true */ + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set } () }) }) -describe("Belt.MutableSet.subset", () => { - test("Belt.MutableSet.subset", () => { +describe("RegExp.source", () => { + test("RegExp.source", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` } () }) }) -describe("Belt.MutableSet.diff", () => { - test("Belt.MutableSet.diff", () => { +describe("RegExp.sticky", () => { + test("RegExp.sticky", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set } () }) }) -describe("Belt.MutableSet.intersect", () => { - test("Belt.MutableSet.intersect", () => { +describe("Promise.catch", () => { + test("Promise.catch", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + open Promise - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ + exception SomeError(string) + + reject(SomeError("this is an error")) + ->then( + _ => { + Ok("This result will never be returned")->resolve + }, + ) + ->catch( + e => { + let msg = switch e { + | SomeError(msg) => "ReScript error occurred: " ++ msg + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(msg) => "JS exception occurred: " ++ msg + | None => "Some other JS value has been thrown" + } + | _ => "Unexpected error occurred" + } + + Error(msg)->resolve + }, + ) + ->then( + result => { + switch result { + | Ok(r) => Console.log2("Operation successful: ", r) + | Error(msg) => Console.log2("Operation failed: ", msg) + }->resolve + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Belt.MutableSet.union", () => { - test("Belt.MutableSet.union", () => { +describe("Option.filter", () => { + test("Option.filter", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + Option.filter(Some(10), x => x > 5) // Some(10) + Option.filter(Some(4), x => x > 5) // None + Option.filter(None, x => x > 5) // None } () }) }) -describe("Belt.MutableSet.removeMany", () => { - test("Belt.MutableSet.removeMany", () => { +describe("Option.getExn", () => { + test("Option.getExn", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Option.getExn(Some(3))->assertEqual(3) - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + switch Option.getExn(None) { + | exception _ => assert(true) + | _ => assert(false) + } - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ + switch Option.getExn(None, ~message="was None!") { + | exception _ => assert(true) // Raises an Error with the message "was None!" + | _ => assert(false) + } } () }) }) -describe("Belt.MutableSet.remove", () => { - test("Belt.MutableSet.remove", () => { +describe("Option.orElse", () => { + test("Option.orElse", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) - - s0->Belt.MutableSet.toArray /* [2,4,5] */ + Option.orElse(Some(1812), Some(1066)) == Some(1812) + Option.orElse(None, Some(1066)) == Some(1066) + Option.orElse(None, None) == None } () }) }) -describe("Belt.MutableSet.mergeMany", () => { - test("Belt.MutableSet.mergeMany", () => { +describe("Option.isSome", () => { + test("Option.isSome", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.make(~id=module(IntCmp)) - - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + Option.isSome(None) // false + Option.isSome(Some(1)) // true } () }) }) -describe("Belt.MutableSet.add", () => { - test("Belt.MutableSet.add", () => { +describe("Option.isNone", () => { + test("Option.isNone", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ + Option.isNone(None) // true + Option.isNone(Some(1)) // false } () }) }) -describe("Belt.MutableSet.has", () => { - test("Belt.MutableSet.has", () => { +describe("Object.create", () => { + test("Object.create", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ + let x = {"fruit": "banana"} + let y = Object.create(x) + y->Object.get("fruit") // Some("banana") } () }) }) -describe("Belt.MutableSet.isEmpty", () => { - test("Belt.MutableSet.isEmpty", () => { +describe("Object.assign", () => { + test("Object.assign", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ + Object.assign({"a": 1}, {"a": 2}) // {"a": 2} + Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} + Object.assign({"a": 1}, {"a": null}) // {"a": null} } () }) }) -describe("Belt.MutableSet.copy", () => { - test("Belt.MutableSet.copy", () => { +describe("Object.freeze", () => { + test("Object.freeze", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + let obj = {"a": 1} + obj->Object.set("a", 2) // succeeds + obj->Object.freeze->ignore - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + try { + obj->Object.set("a", 3) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.MutableSet.fromArray", () => { - test("Belt.MutableSet.fromArray", () => { +describe("Nullable.null", () => { + test("Nullable.null", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + Console.log(Nullable.null) // Logs `null` to the console. } () }) }) -describe("Belt.Map.set", () => { - test("Belt.Map.set", () => { +describe("Nullable.make", () => { + test("Nullable.make", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + let myStr = "Hello" + let asNullable = myStr->Nullable.make - let s1 = Belt.Map.set(s0, 2, "3") + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + // Need to do this + switch asNullable->Nullable.toOption { + | Some(value) if value == myStr => Console.log("Yay, values matched!") + | _ => Console.log("Values did not match.") + } } () }) }) -describe("Belt.Map.remove", () => { - test("Belt.Map.remove", () => { +describe("List.forEach2", () => { + test("List.forEach2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) - - s1 === s2 + List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) - Belt.Map.keysToArray(s1) == [2, 3] + /* + prints: + "Z" "A" + "Y" "B" +*/ } () }) }) -describe("Belt.Map.get", () => { - test("Belt.Map.get", () => { +describe("List.getAssoc", () => { + test("List.getAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") + list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + // Some("afternoon") } () }) }) -describe("Belt.Map.valuesToArray", () => { - test("Belt.Map.valuesToArray", () => { +describe("List.hasAssoc", () => { + test("List.hasAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) // false } () }) }) -describe("Belt.Map.keysToArray", () => { - test("Belt.Map.keysToArray", () => { +describe("List.setAssoc", () => { + test("List.setAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] + list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + // list{(9, "morning"), (15, "afternoon"), (22, "night")} } () }) }) -describe("Belt.Map.fromArray", () => { - test("Belt.Map.fromArray", () => { +describe("Null.toOption", () => { + test("Null.toOption", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + let nullStr = Null.make("Hello") - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + switch nullStr->Null.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } } () }) }) -describe("Belt.Map.toArray", () => { - test("Belt.Map.toArray", () => { +describe("Math.Int.imul", () => { + test("Math.Int.imul", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + Math.Int.imul(3, 4) // 12 + Math.Int.imul(-5, 12) // 60 } () }) }) -describe("Belt.Map.size", () => { - test("Belt.Map.size", () => { +describe("Math.Int.sign", () => { + test("Math.Int.sign", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + Math.Int.sign(3) // 1 + Math.Int.sign(-3) // -1 + Math.Int.sign(0) // 0 + } + () + }) +}) - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 +describe("Math.Int.ceil", () => { + test("Math.Int.ceil", () => { + module Test = { + Math.Int.ceil(3.7) == 4 + Math.Int.ceil(3.0) == 3 + Math.Int.ceil(-3.1) == -3 } () }) }) -describe("Belt.Map.reduce", () => { - test("Belt.Map.reduce", () => { +describe("Map.fromArray", () => { + test("Map.fromArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + type languages = ReScript | JavaScript | TypeScript + let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + let map = Map.fromArray(languageRank) // Map.t - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + switch map->Map.get(ReScript) { + | Some(1) => Console.log("Yay, ReScript is #1!") + | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } } () }) }) -describe("Belt.Map.forEach", () => { - test("Belt.Map.forEach", () => { +describe("JSON.parseExn", () => { + test("JSON.parseExn", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + try { + let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) + // { foo: 'bar', hello: 'world' } - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + let _ = JSON.parseExn("") + // error + } catch { + | Exn.Error(_) => Console.log("error") + } - let acc = ref(list{}) + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + let jsonString = `{"hello":"world","someNumber":21}` - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + try { + JSON.parseExn(jsonString, ~reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExn("", ~reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } } () }) }) -describe("Belt.Map.findFirstBy", () => { - test("Belt.Map.findFirstBy", () => { +describe("Iterator.next", () => { + test("Iterator.next", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + (iterator->Iterator.next).done->assertEqual(false) + (iterator->Iterator.next).done->assertEqual(true) } () }) }) -describe("Belt.Map.has", () => { - test("Belt.Map.has", () => { +describe("Int.fromFloat", () => { + test("Int.fromFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + Int.fromFloat(2.0) == 2 + Int.fromFloat(1.999) == 1 + Int.fromFloat(1.5) == 1 + Int.fromFloat(0.9999) == 0 } () }) }) -describe("Belt.Map.isEmpty", () => { - test("Belt.Map.isEmpty", () => { +describe("Float.toFixed", () => { + test("Float.toFixed", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + Float.toFixed(123456.0) // "123456.00" + Float.toFixed(10.0) // "10.00" + Float.toFixed(300.0, ~digits=4) // "300.0000" + Float.toFixed(300.0, ~digits=1) // "300.0" } () }) }) -describe("Belt.Map.make", () => { - test("Belt.Map.make", () => { +describe("Float.fromInt", () => { + test("Float.fromInt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let m = Belt.Map.make(~id=module(IntCmp)) - - Belt.Map.set(m, 0, "a") + Float.fromInt(2) == 2.0 + Float.fromInt(1) == 1.0 } () }) }) -describe("Belt.Map.Int", () => { - test("Belt.Map.Int", () => { +describe("Error.message", () => { + test("Error.message", () => { module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console } () }) }) -describe("Belt.Set.split", () => { - test("Belt.Set.split", () => { +describe("Date.fromTime", () => { + test("Date.fromTime", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + Date.fromTime(0.0) + // 1970-01-01T00:00:00.000Z - let ((smaller, larger), present) = s0->Belt.Set.split(3) + Date.fromTime(-86_400_000.0) + // 1969-12-31T00:00:00.000Z - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) + Date.fromTime(86_400_000.0) + // 1970-01-02T00:00:00.000Z } () }) }) -describe("Belt.Set.get", () => { - test("Belt.Set.get", () => { +describe("Date.getMonth", () => { + test("Date.getMonth", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) + Date.fromString("2023-01-01")->Date.getMonth + // 0 } () }) }) -describe("Belt.Set.maxUndefined", () => { - test("Belt.Set.maxUndefined", () => { +describe("Date.getHours", () => { + test("Date.getHours", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) - - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) + Date.fromString("2023-02-20T16:40:00.00")->Date.getHours + // 16 } () }) }) -describe("Belt.Set.maximum", () => { - test("Belt.Set.maximum", () => { +describe("Date.setMonth", () => { + test("Date.setMonth", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.maximum->assertEqual(None) - s1->Belt.Set.maximum->assertEqual(Some(5)) + Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) } () }) }) -describe("Belt.Set.minUndefined", () => { - test("Belt.Set.minUndefined", () => { +describe("Date.setHours", () => { + test("Date.setHours", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) } () }) }) -describe("Belt.Set.minimum", () => { - test("Belt.Set.minimum", () => { +describe("Date.toString", () => { + test("Date.toString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log + // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) + Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log + // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) } () }) }) -describe("Belt.Set.toList", () => { - test("Belt.Set.toList", () => { +describe("Console.clear", () => { + test("Console.clear", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + Console.clear() } () }) }) -describe("Belt.Set.toArray", () => { - test("Belt.Set.toArray", () => { +describe("Console.count", () => { + test("Console.count", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + Console.count("rescript") } () }) }) -describe("Belt.Set.size", () => { - test("Belt.Set.size", () => { +describe("Console.debug", () => { + test("Console.debug", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.Set.size->assertEqual(4) + Console.debug("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.debug(obj) } () }) }) -describe("Belt.Set.partition", () => { - test("Belt.Set.partition", () => { +describe("Console.error", () => { + test("Console.error", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) - - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) + Console.error("error message") + Console.error(("error", "invalid value")) } () }) }) -describe("Belt.Set.keep", () => { - test("Belt.Set.keep", () => { +describe("Console.group", () => { + test("Console.group", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.keep(isEven) - - s1->Belt.Set.toArray->assertEqual([2, 4]) + 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() } () }) }) -describe("Belt.Set.some", () => { - test("Belt.Set.some", () => { +describe("Console.info2", () => { + test("Console.info2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) + Console.info2("Info", "failed to download") + Console.info2(#info, {"name": "ReScript"}) } () }) }) -describe("Belt.Set.every", () => { - test("Belt.Set.every", () => { +describe("Console.info3", () => { + test("Console.info3", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) + Console.info3("Hello", "World", "ReScript") + Console.info3([1, 2, 3], #4, #5) } () }) }) -describe("Belt.Set.reduce", () => { - test("Belt.Set.reduce", () => { +describe("Console.info4", () => { + test("Console.info4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Console.info4("Hello", "World", "ReScript", '!') + Console.info4([1, 2, 3], #4, #5, #lastinfo) + } + () + }) +}) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) +describe("Console.info5", () => { + test("Console.info5", () => { + module Test = { + Console.info5("Hello", "World", "from", "JS", "!!!") + Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt.Set.forEach", () => { - test("Belt.Set.forEach", () => { +describe("Console.info6", () => { + test("Console.info6", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Console.info6("Hello", "World", "from", "JS", "!!!", '!') + Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + } + () + }) +}) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) +describe("Console.table", () => { + test("Console.table", () => { + module Test = { + Console.table({"language": "rescript", "version": "10.1.2"}) + } + () + }) +}) - let acc = ref(list{}) +describe("Console.trace", () => { + test("Console.trace", () => { + module Test = { + let main = () => { + Console.trace() + } + main() + // In the console, the following trace will be displayed: + // main + // + } + () + }) +}) - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) - }, - ) +describe("Console.warn2", () => { + test("Console.warn2", () => { + module Test = { + Console.warn2("Hello", "World") + Console.warn2([1, 2, 3], 4) + } + () + }) +}) - acc.contents->assertEqual(list{6, 5, 3, 2}) +describe("Console.warn3", () => { + test("Console.warn3", () => { + module Test = { + Console.warn3("Hello", "World", "ReScript") + Console.warn3([1, 2, 3], #4, #5) } () }) }) -describe("Belt.Set.eq", () => { - test("Belt.Set.eq", () => { +describe("Console.warn4", () => { + test("Console.warn4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Console.warn4("Hello", "World", "ReScript", "!!!") + Console.warn4(#first, #second, #third, "fourth") + } + () + }) +}) - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) +describe("Console.warn5", () => { + test("Console.warn5", () => { + module Test = { + Console.warn5("Hello", "World", "from", "JS", "!!!") + Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + } + () + }) +}) - Belt.Set.eq(s0, s1)->assertEqual(true) +describe("Console.warn6", () => { + test("Console.warn6", () => { + module Test = { + Console.warn6("Hello", "World", "from", "JS", "!!!", '!') + Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.Set.subset", () => { - test("Belt.Set.subset", () => { +describe("Belt_Set.make", () => { + test("Belt_Set.make", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) + let set = Belt.Set.make(~id=module(IntCmp)) - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) + Belt.Set.isEmpty(set)->assertEqual(true) } () }) }) -describe("Belt.Set.diff", () => { - test("Belt.Set.diff", () => { +describe("Belt_Set.diff", () => { + test("Belt_Set.diff", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -4345,1216 +3774,1221 @@ describe("Belt.Set.diff", () => { }) }) -describe("Belt.Set.intersect", () => { - test("Belt.Set.intersect", () => { - module Test = { +describe("Belt_Set.some", () => { + test("Belt_Set.some", () => { + module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - let intersect = Belt.Set.intersect(s0, s1) + let isOdd = x => mod(x, 2) != 0 - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) } () }) }) -describe("Belt.Set.union", () => { - test("Belt.Set.union", () => { +describe("Belt_Set.keep", () => { + test("Belt_Set.keep", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) + let isEven = x => mod(x, 2) == 0 - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.keep(isEven) + + s1->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt.Set.removeMany", () => { - test("Belt.Set.removeMany", () => { +describe("Belt_Set.size", () => { + test("Belt_Set.size", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - newSet - ->Belt.Set.toArray - ->assertEqual([]) + s0->Belt.Set.size->assertEqual(4) } () }) }) -describe("Belt.Set.remove", () => { - test("Belt.Set.remove", () => { +describe("Belt_Map.make", () => { + test("Belt_Map.make", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) + let m = Belt.Map.make(~id=module(IntCmp)) - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) + Belt.Map.set(m, 0, "a") } () }) }) -describe("Belt.Set.mergeMany", () => { - test("Belt.Set.mergeMany", () => { +describe("Belt_Map.size", () => { + test("Belt_Map.size", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let set = Belt.Set.make(~id=module(IntCmp)) - - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 } () }) }) -describe("Belt.Set.add", () => { - test("Belt.Set.add", () => { +describe("Belt_List.add", () => { + test("Belt_List.add", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Belt.Set.has", () => { - test("Belt.Set.has", () => { +describe("Belt_List.get", () => { + test("Belt_List.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let abc = list{"A", "B", "C"} - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + abc->Belt.List.get(1) // Some("B") - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) + abc->Belt.List.get(4) // None } () }) }) -describe("Belt.Set.isEmpty", () => { - test("Belt.Set.isEmpty", () => { +describe("Belt_List.map", () => { + test("Belt_List.map", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) - - Belt.Set.isEmpty(empty)->assertEqual(true) - Belt.Set.isEmpty(notEmpty)->assertEqual(false) + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} } () }) }) -describe("Belt.Set.fromArray", () => { - test("Belt.Set.fromArray", () => { +describe("Belt_List.zip", () => { + test("Belt_List.zip", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} } () }) }) -describe("Belt.Set.make", () => { - test("Belt.Set.make", () => { +describe("Belt_List.cmp", () => { + test("Belt_List.cmp", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - let set = Belt.Set.make(~id=module(IntCmp)) + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - Belt.Set.isEmpty(set)->assertEqual(true) + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ } () }) }) -describe("Belt.Range.someBy", () => { - test("Belt.Range.someBy", () => { +describe("Belt_List.has", () => { + test("Belt_List.has", () => { module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Belt.Range.some", () => { - test("Belt.Range.some", () => { +describe("Belt.Array.eq", () => { + test("Belt.Array.eq", () => { module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ - - Belt.Range.some(0, 4, i => i > 2) /* true */ + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Belt.Range.everyBy", () => { - test("Belt.Range.everyBy", () => { +describe("Belt.List.add", () => { + test("Belt.List.add", () => { module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Belt.Range.every", () => { - test("Belt.Range.every", () => { +describe("Belt.List.get", () => { + test("Belt.List.get", () => { module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ + let abc = list{"A", "B", "C"} - Belt.Range.every(0, 4, i => i < 4) /* false */ + abc->Belt.List.get(1) // Some("B") + + abc->Belt.List.get(4) // None } () }) }) -describe("Belt.Range.forEach", () => { - test("Belt.Range.forEach", () => { +describe("Belt.List.map", () => { + test("Belt.List.map", () => { module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) - - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} } () }) }) -describe("Belt.List.sort", () => { - test("Belt.List.sort", () => { +describe("Belt.List.zip", () => { + test("Belt.List.zip", () => { module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} } () }) }) -describe("Belt.List.setAssoc", () => { - test("Belt.List.setAssoc", () => { +describe("Belt.List.cmp", () => { + test("Belt.List.cmp", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ } () }) }) -describe("Belt.List.removeAssoc", () => { - test("Belt.List.removeAssoc", () => { +describe("Belt.List.has", () => { + test("Belt.List.has", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Belt.List.hasAssoc", () => { - test("Belt.List.hasAssoc", () => { +describe("Belt.Set.make", () => { + test("Belt.Set.make", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + Belt.Set.isEmpty(set)->assertEqual(true) } () }) }) -describe("Belt.List.getAssoc", () => { - test("Belt.List.getAssoc", () => { +describe("Belt.Set.diff", () => { + test("Belt.Set.diff", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + Belt.Set.diff(s0, s1) + ->Belt.Set.toArray + ->assertEqual([6]) + + Belt.Set.diff(s1, s0) + ->Belt.Set.toArray + ->assertEqual([1, 4]) } () }) }) -describe("Belt.List.unzip", () => { - test("Belt.List.unzip", () => { +describe("Belt.Set.some", () => { + test("Belt.Set.some", () => { module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) } () }) }) -describe("Belt.List.partition", () => { - test("Belt.List.partition", () => { +describe("Belt.Set.keep", () => { + test("Belt.Set.keep", () => { module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.keep(isEven) + + s1->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt.List.keepMap", () => { - test("Belt.List.keepMap", () => { +describe("Belt.Set.size", () => { + test("Belt.Set.size", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + s0->Belt.Set.size->assertEqual(4) } () }) }) -describe("Belt.List.filterWithIndex", () => { - test("Belt.List.filterWithIndex", () => { +describe("Belt.Map.make", () => { + test("Belt.Map.make", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + let m = Belt.Map.make(~id=module(IntCmp)) + + Belt.Map.set(m, 0, "a") } () }) }) -describe("Belt.List.keepWithIndex", () => { - test("Belt.List.keepWithIndex", () => { +describe("Belt.Map.size", () => { + test("Belt.Map.size", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 } () }) }) -describe("Belt.List.filter", () => { - test("Belt.List.filter", () => { +describe("Belt_Array.eq", () => { + test("Belt_Array.eq", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Belt.List.keep", () => { - test("Belt.List.keep", () => { +describe("Array.fillAll", () => { + test("Array.fillAll", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + let myArray = [1, 2, 3, 4] + myArray->Array.fillAll(9) + myArray->assertEqual([9, 9, 9, 9]) } () }) }) -describe("Belt.List.getBy", () => { - test("Belt.List.getBy", () => { +describe("Array.reverse", () => { + test("Array.reverse", () => { module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + let someArray = ["hi", "hello"] + someArray->Array.reverse - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + someArray->assertEqual(["hello", "hi"]) } () }) }) -describe("Belt.List.has", () => { - test("Belt.List.has", () => { +describe("Array.unshift", () => { + test("Array.unshift", () => { module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ - - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + let someArray = ["hi", "hello"] + someArray->Array.unshift("yay") + someArray->assertEqual(["yay", "hi", "hello"]) } () }) }) -describe("Belt.List.eq", () => { - test("Belt.List.eq", () => { +describe("Array.indexOf", () => { + test("Array.indexOf", () => { module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + [1, 2]->Array.indexOf(2)->assertEqual(1) + [1, 2]->Array.indexOf(3)->assertEqual(-1) - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + [{"language": "ReScript"}] + ->Array.indexOf({"language": "ReScript"}) + ->assertEqual(-1) // -1, because of strict equality } () }) }) -describe("Belt.List.cmp", () => { - test("Belt.List.cmp", () => { +describe("Array.forEach", () => { + test("Array.forEach", () => { module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + let array = ["Hello", "Hi", "Good bye"] - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + array->Array.forEach( + item => { + Console.log(item) + }, + ) } () }) }) -describe("Belt.List.cmpByLength", () => { - test("Belt.List.cmpByLength", () => { +describe("Array.shuffle", () => { + test("Array.shuffle", () => { module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ + let array = ["Hello", "Hi", "Good bye"] + array->Array.shuffle + Console.log(array) - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ + let array2 = [1, 2, 3] + array2->Array.shuffle - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + array2 + ->Array.length + ->assertEqual(3) } () }) }) -describe("Belt.List.some2", () => { - test("Belt.List.some2", () => { +describe("Array.flatMap", () => { + test("Array.flatMap", () => { module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ + type language = ReScript | TypeScript | JavaScript - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + let array = [ReScript, TypeScript, JavaScript] - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + array + ->Array.flatMap( + item => + switch item { + | ReScript => [1, 2, 3] + | TypeScript => [4, 5, 6] + | JavaScript => [7, 8, 9] + }, + ) + ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) } () }) }) -describe("Belt.List.every2", () => { - test("Belt.List.every2", () => { +describe("Array.findMap", () => { + test("Array.findMap", () => { module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( + Some(-6), + ) - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) } () }) }) -describe("Belt.List.some", () => { - test("Belt.List.some", () => { +describe("String.indexOf", () => { + test("String.indexOf", () => { module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + String.indexOf("bookseller", "ok") == 2 + String.indexOf("bookseller", "sell") == 4 + String.indexOf("beekeeper", "ee") == 1 + String.indexOf("bookseller", "xyz") == -1 } () }) }) -describe("Belt.List.every", () => { - test("Belt.List.every", () => { +describe("String.replace", () => { + test("String.replace", () => { module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + String.replace("old string", "old", "new") == "new string" + String.replace("the cat and the dog", "the", "this") == "this cat and the dog" } () }) }) -describe("Belt.List.reduceReverse2", () => { - test("Belt.List.reduceReverse2", () => { +describe("String.trimEnd", () => { + test("String.trimEnd", () => { module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + String.trimEnd(" Hello world! ") == " Hello world!" + String.trimEnd(" Hello world! ") == " Hello world!" } () }) }) -describe("Belt.List.reduce2", () => { - test("Belt.List.reduce2", () => { +describe("Result.flatMap", () => { + test("Result.flatMap", () => { module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ - } - () - }) -}) + let recip = x => + if x !== 0.0 { + Ok(1.0 /. x) + } else { + Error("Divide by zero") + } -describe("Belt.List.forEach2", () => { - test("Belt.List.forEach2", () => { - module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) + Result.flatMap(Ok(2.0), recip) == Ok(0.5) - /* - prints: - "Z" "A" - "Y" "B" -*/ - } - () - }) -}) + Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") -describe("Belt.List.mapReverse2", () => { - test("Belt.List.mapReverse2", () => { - module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Belt.List.reduceReverse", () => { - test("Belt.List.reduceReverse", () => { +describe("Result.compare", () => { + test("Result.compare", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + let good1 = Ok(59) - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + let good2 = Ok(37) - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} + let bad1 = Error("invalid") + + let bad2 = Error("really invalid") + + let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) + + Result.compare(Ok(39), Ok(57), mod10cmp) == 1. + + Result.compare(Ok(57), Ok(39), mod10cmp) == -1. + + Result.compare(Ok(39), Error("y"), mod10cmp) == 1. + + Result.compare(Error("x"), Ok(57), mod10cmp) == -1. + + Result.compare(Error("x"), Error("y"), mod10cmp) == 0. } () }) }) -describe("Belt.List.reduceWithIndex", () => { - test("Belt.List.reduceWithIndex", () => { +describe("Result.forEach", () => { + test("Result.forEach", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ + Result.forEach(Ok(3), Console.log) // Logs "3", returns () + Result.forEach(Error("x"), Console.log) // Does nothing, returns () } () }) }) -describe("Belt.List.reduce", () => { - test("Belt.List.reduce", () => { +describe("RegExp.unicode", () => { + test("RegExp.unicode", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - - /* same as */ + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set } () }) }) -describe("Belt.List.forEachWithIndex", () => { - test("Belt.List.forEachWithIndex", () => { +describe("Promise.reject", () => { + test("Promise.reject", () => { module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + exception TestError(string) + + TestError("some rejected value") + ->Promise.reject + ->Promise.catch( + v => { + switch v { + | TestError(msg) => assertEqual(msg, "some rejected value") + | _ => assert(false) + } + Promise.resolve() }, ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + ->ignore } () }) }) -describe("Belt.List.forEach", () => { - test("Belt.List.forEach", () => { +describe("Option.forEach", () => { + test("Option.forEach", () => { module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ + Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" + Option.forEach(None, x => Console.log(x)) // returns () } () }) }) -describe("Belt.List.mapReverse", () => { - test("Belt.List.mapReverse", () => { +describe("Option.flatMap", () => { + test("Option.flatMap", () => { module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Option.flatMap(Some(2), addIfAboveOne) // Some(3) + Option.flatMap(Some(-4), addIfAboveOne) // None + Option.flatMap(None, addIfAboveOne) // None } () }) }) -describe("Belt.List.reverse", () => { - test("Belt.List.reverse", () => { +describe("Option.compare", () => { + test("Option.compare", () => { module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) + + Option.compare(Some(3), Some(15), clockCompare) // 0. + Option.compare(Some(3), Some(14), clockCompare) // 1. + Option.compare(Some(2), Some(15), clockCompare) // (-1.) + Option.compare(None, Some(15), clockCompare) // (-1.) + Option.compare(Some(14), None, clockCompare) // 1. + Option.compare(None, None, clockCompare) // 0. } () }) }) -describe("Belt.List.toArray", () => { - test("Belt.List.toArray", () => { +describe("Nullable.getOr", () => { + test("Nullable.getOr", () => { module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + Nullable.getOr(Nullable.null, "Banana") // Banana + Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" + Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Belt.List.fromArray", () => { - test("Belt.List.fromArray", () => { +describe("Nullable.mapOr", () => { + test("Nullable.mapOr", () => { module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + let someValue = Nullable.make(3) + someValue->Nullable.mapOr(0, x => x + 5) // 8 + + let noneValue = Nullable.null + noneValue->Nullable.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Belt.List.mapWithIndex", () => { - test("Belt.List.mapWithIndex", () => { +describe("List.fromArray", () => { + test("List.fromArray", () => { module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + List.fromArray([1, 2, 3]) // list{1, 2, 3} } () }) }) -describe("Belt.List.zipBy", () => { - test("Belt.List.zipBy", () => { +describe("List.filterMap", () => { + test("List.filterMap", () => { module Test = { - Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->List.filterMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) // list{2, 4} + + list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} } () }) }) -describe("Belt.List.zip", () => { - test("Belt.List.zip", () => { +describe("List.partition", () => { + test("List.partition", () => { module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + // (elementsThatSatisfies, elementsThatDoesNotSatisfy) + + List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) } () }) }) -describe("Belt.List.map", () => { - test("Belt.List.map", () => { +describe("Null.getUnsafe", () => { + test("Null.getUnsafe", () => { module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + Null.getUnsafe(Null.make(3)) == 3 + Null.getUnsafe(Null.null) // Raises an error } () }) }) -describe("Belt.List.flatten", () => { - test("Belt.List.flatten", () => { +describe("Math.hypotMany", () => { + test("Math.hypotMany", () => { module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 + Math.hypotMany([]) // 0.0 } () }) }) -describe("Belt.List.reverseConcat", () => { - test("Belt.List.reverseConcat", () => { +describe("Math.Int.clz32", () => { + test("Math.Int.clz32", () => { module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + // 00000000000000000000000000000001 + Math.Int.clz32(1) // 31 + // 00000000000000000000000000000100 + Math.Int.clz32(4) // 29 } () }) }) -describe("Belt.List.concatMany", () => { - test("Belt.List.concatMany", () => { +describe("Math.Int.floor", () => { + test("Math.Int.floor", () => { module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + Math.Int.floor(3.7) == 3 + Math.Int.floor(3.0) == 3 + Math.Int.floor(-3.1) == -4 } () }) }) -describe("Belt.List.concat", () => { - test("Belt.List.concat", () => { +describe("JSON.stringify", () => { + test("JSON.stringify", () => { module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} - } - () - }) -}) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object -describe("Belt.List.splitAt", () => { - test("Belt.List.splitAt", () => { - module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + JSON.stringify(json) + // {"foo":"bar","hello":"world","someNumber":42} - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + JSON.stringify(json, ~space=2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } + + JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) + // {"foo":"bar","someNumber":42} + + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, + ) + + JSON.stringify(json, ~replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} } () }) }) -describe("Belt.List.take", () => { - test("Belt.List.take", () => { +describe("Int.fromString", () => { + test("Int.fromString", () => { module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->Belt.List.take(4) // None + Int.fromString("0") == Some(0) + Int.fromString("NaN") == None + Int.fromString("6", ~radix=2) == None } () }) }) -describe("Belt.List.drop", () => { - test("Belt.List.drop", () => { +describe("Float.isFinite", () => { + test("Float.isFinite", () => { module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) - - list{1, 2, 3}->Belt.List.drop(4) // None + Float.isFinite(1.0) // true + Float.isFinite(Float.Constants.nan) // false + Float.isFinite(Float.Constants.positiveInfinity) // false } () }) }) -describe("Belt.List.shuffle", () => { - test("Belt.List.shuffle", () => { +describe("Float.parseInt", () => { + test("Float.parseInt", () => { module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + Float.parseInt("1.0") // 1.0 + Float.parseInt(" 3.14 ") // 3.0 + Float.parseInt(3) // 3.0 + Float.parseInt("3.14some non-digit characters") // 3.0 + Float.parseInt("error")->Float.isNaN // true + Float.parseInt("10.0", ~radix=2) // 2.0 + Float.parseInt("15 * 3", ~radix=10) // 15.0 + Float.parseInt("12", ~radix=13) // 15.0 + Float.parseInt("17", ~radix=40)->Float.isNaN // true } () }) }) -describe("Belt.List.makeBy", () => { - test("Belt.List.makeBy", () => { +describe("Float.toString", () => { + test("Float.toString", () => { module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} - - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + Float.toString(1000.0) // "1000" + Float.toString(-1000.0) // "-1000" } () }) }) -describe("Belt.List.make", () => { - test("Belt.List.make", () => { +describe("Date.setHoursM", () => { + test("Date.setHoursM", () => { module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) } () }) }) -describe("Belt.List.getExn", () => { - test("Belt.List.getExn", () => { +describe("Date.getUTCDay", () => { + test("Date.getUTCDay", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.getExn(1)->assertEqual("B") - - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 } () }) }) -describe("Belt.List.get", () => { - test("Belt.List.get", () => { +describe("Dict.getUnsafe", () => { + test("Dict.getUnsafe", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.get(1) // Some("B") - - abc->Belt.List.get(4) // None + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let value = dict->Dict.getUnsafe("key1") + Console.log(value) // value1 } () }) }) -describe("Belt.List.add", () => { - test("Belt.List.add", () => { +describe("Dict.fromArray", () => { + test("Dict.fromArray", () => { module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) } () }) }) -describe("Belt.List.tailExn", () => { - test("Belt.List.tailExn", () => { +describe("Dict.mapValues", () => { + test("Dict.mapValues", () => { module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] + dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] } () }) }) -describe("Belt.List.tail", () => { - test("Belt.List.tail", () => { +describe("Console.debug2", () => { + test("Console.debug2", () => { module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - - Belt.List.tail(list{}) // None + Console.debug2("Hello", "World") + Console.debug2([1, 2, 3], '4') } () }) }) -describe("Belt.List.headExn", () => { - test("Belt.List.headExn", () => { +describe("Console.debug3", () => { + test("Console.debug3", () => { module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Console.debug3("Hello", "World", "ReScript") + Console.debug3("One", 2, #3) } () }) }) -describe("Belt.List.head", () => { - test("Belt.List.head", () => { +describe("Console.debug4", () => { + test("Console.debug4", () => { module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) + Console.debug4("Hello", "World", "ReScript", "!!!") + Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Belt.List.length", () => { - test("Belt.List.length", () => { +describe("Console.debug5", () => { + test("Console.debug5", () => { module Test = { - Belt.List.length(list{1, 2, 3}) // 3 + Console.debug5("Hello", "World", "JS", '!', '!') + Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt.SortArray.binarySearchBy", () => { - test("Belt.SortArray.binarySearchBy", () => { +describe("Console.debug6", () => { + test("Console.debug6", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + Console.debug6("Hello", "World", "JS", '!', '!', '?') + Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.SortArray.strictlySortedLength", () => { - test("Belt.SortArray.strictlySortedLength", () => { +describe("Console.error2", () => { + test("Console.error2", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + Console.error2("Error", "here") + Console.error2(("log", "error"), "message") } () }) }) -describe("Belt.Array.truncateToLengthUnsafe", () => { - test("Belt.Array.truncateToLengthUnsafe", () => { +describe("Console.error3", () => { + test("Console.error3", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] + Console.error3("Hello", "World", "!!!") + Console.error3(#first, #second, #third) } () }) }) -describe("Belt.Array.eq", () => { - test("Belt.Array.eq", () => { +describe("Console.error4", () => { + test("Console.error4", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + Console.error4("Hello", "World", "ReScript", '!') + Console.error4(#first, #second, #third, "fourth") } () }) }) -describe("Belt.Array.cmp", () => { - test("Belt.Array.cmp", () => { +describe("Console.error5", () => { + test("Console.error5", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Console.error5('e', 'r', 'r', 'o', 'r') + Console.error5(1, #second, #third, "fourth", 'c') } () }) }) -describe("Belt.Array.some2", () => { - test("Belt.Array.some2", () => { +describe("Console.error6", () => { + test("Console.error6", () => { module Test = { - 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 + Console.error6("Hello", "World", "from", "JS", "!!!", '!') + Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.Array.every2", () => { - test("Belt.Array.every2", () => { +describe("Belt_Set.union", () => { + test("Belt_Set.union", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - - Belt.Array.every2([], [1], (x, y) => x > y) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) } () }) }) -describe("Belt.Array.every", () => { - test("Belt.Array.every", () => { +describe("Belt_Set.every", () => { + test("Belt_Set.every", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every([1, -3, 5], x => x > 0) == false + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) } () }) }) -describe("Belt.Array.some", () => { - test("Belt.Array.some", () => { +describe("Belt_Set.split", () => { + test("Belt_Set.split", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) -describe("Belt.Array.joinWith", () => { - test("Belt.Array.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + let ((smaller, larger), present) = s0->Belt.Set.split(3) + + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) } () }) }) -describe("Belt.Array.reduceWithIndex", () => { - test("Belt.Array.reduceWithIndex", () => { +describe("Belt_Result.eq", () => { + test("Belt_Result.eq", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + let good1 = Belt.Result.Ok(42) + + let good2 = Belt.Result.Ok(32) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 } () }) }) -describe("Belt.Array.reduceReverse2", () => { - test("Belt.Array.reduceReverse2", () => { +describe("Belt_Option.eq", () => { + test("Belt_Option.eq", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Belt.Option + + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ } () }) }) -describe("Belt.Array.reduceReverse", () => { - test("Belt.Array.reduceReverse", () => { +describe("Belt_List.head", () => { + test("Belt_List.head", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Belt.Array.reduce", () => { - test("Belt.Array.reduce", () => { +describe("Belt_List.tail", () => { + test("Belt_List.tail", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Belt.List.tail(list{}) // None } () }) }) -describe("Belt.Array.partition", () => { - test("Belt.Array.partition", () => { +describe("Belt_List.make", () => { + test("Belt_List.make", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + Belt.List.make(3, 1) // list{1, 1, 1} } () }) }) -describe("Belt.Array.mapWithIndex", () => { - test("Belt.Array.mapWithIndex", () => { +describe("Belt_List.drop", () => { + test("Belt_List.drop", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + + list{1, 2, 3}->Belt.List.drop(4) // None } () }) }) -describe("Belt.Array.forEachWithIndex", () => { - test("Belt.Array.forEachWithIndex", () => { +describe("Belt_List.take", () => { + test("Belt_List.take", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + list{1, 2, 3}->Belt.List.take(4) // None } () }) }) -describe("Belt.Array.keepMap", () => { - test("Belt.Array.keepMap", () => { +describe("Belt_List.some", () => { + test("Belt_List.some", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + let isAbove100 = value => value > 100 + + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ } () }) }) -describe("Belt.Array.keepWithIndex", () => { - test("Belt.Array.keepWithIndex", () => { +describe("Belt_List.keep", () => { + test("Belt_List.keep", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + let isEven = x => mod(x, 2) == 0 + + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Belt.Array.getIndexBy", () => { - test("Belt.Array.getIndexBy", () => { +describe("Belt_List.sort", () => { + test("Belt_List.sort", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} } () }) }) -describe("Belt.Array.getBy", () => { - test("Belt.Array.getBy", () => { +describe("Belt.Array.get", () => { + test("Belt.Array.get", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Belt.Array.flatMap", () => { - test("Belt.Array.flatMap", () => { +describe("Belt.Array.zip", () => { + test("Belt.Array.zip", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) @@ -5569,4356 +5003,4026 @@ describe("Belt.Array.map", () => { }) }) -describe("Belt.Array.forEach", () => { - test("Belt.Array.forEach", () => { +describe("Belt.Array.cmp", () => { + test("Belt.Array.cmp", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - total.contents == 1 + 2 + 3 + 4 + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Belt.Array.blit", () => { - test("Belt.Array.blit", () => { +describe("Belt.List.head", () => { + test("Belt.List.head", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Belt.Array.fill", () => { - test("Belt.Array.fill", () => { +describe("Belt.List.tail", () => { + test("Belt.List.tail", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - arr == [0, 1, 9, 9, 4] + Belt.List.tail(list{}) // None } () }) }) -describe("Belt.Array.sliceToEnd", () => { - test("Belt.Array.sliceToEnd", () => { +describe("Belt.List.make", () => { + test("Belt.List.make", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + Belt.List.make(3, 1) // list{1, 1, 1} } () }) }) -describe("Belt.Array.slice", () => { - test("Belt.Array.slice", () => { +describe("Belt.List.drop", () => { + test("Belt.List.drop", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + list{1, 2, 3}->Belt.List.drop(4) // None } () }) }) -describe("Belt.Array.concatMany", () => { - test("Belt.Array.concatMany", () => { +describe("Belt.List.take", () => { + test("Belt.List.take", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) + + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) + + list{1, 2, 3}->Belt.List.take(4) // None } () }) }) -describe("Belt.Array.concat", () => { - test("Belt.Array.concat", () => { +describe("Belt.List.some", () => { + test("Belt.List.some", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + let isAbove100 = value => value > 100 - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ } () }) }) -describe("Belt.Array.unzip", () => { - test("Belt.Array.unzip", () => { +describe("Belt.List.keep", () => { + test("Belt.List.keep", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + let isEven = x => mod(x, 2) == 0 - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Belt.Array.zipBy", () => { - test("Belt.Array.zipBy", () => { +describe("Belt.List.sort", () => { + test("Belt.List.sort", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} } () }) }) -describe("Belt.Array.zip", () => { - test("Belt.Array.zip", () => { +describe("Belt.Set.union", () => { + test("Belt.Set.union", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) + + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) } () }) }) -describe("Belt.Array.makeBy", () => { - test("Belt.Array.makeBy", () => { +describe("Belt.Set.every", () => { + test("Belt.Set.every", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) } () }) }) -describe("Belt.Array.rangeBy", () => { - test("Belt.Array.rangeBy", () => { +describe("Belt.Set.split", () => { + test("Belt.Set.split", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.rangeBy(3, 12, ~step=-1) == [] + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - Belt.Array.rangeBy(3, 3, ~step=0) == [] + let ((smaller, larger), present) = s0->Belt.Set.split(3) - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) } () }) }) -describe("Belt.Array.range", () => { - test("Belt.Array.range", () => { +describe("Belt.Option.eq", () => { + test("Belt.Option.eq", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - Belt.Array.range(3, 0) == [] + open Belt.Option - Belt.Array.range(3, 3) == [3] + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ } () }) }) -describe("Belt.Array.makeUninitializedUnsafe", () => { - test("Belt.Array.makeUninitializedUnsafe", () => { +describe("Belt.Result.eq", () => { + test("Belt.Result.eq", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) + let good1 = Belt.Result.Ok(42) - Js.log(Belt.Array.getExn(arr, 0)) // undefined + let good2 = Belt.Result.Ok(32) - Belt.Array.setExn(arr, 0, "example") + let bad1 = Belt.Result.Error("invalid") - Js.log(Belt.Array.getExn(arr, 0) == "example") + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 } () }) }) -describe("Belt.Array.makeUninitialized", () => { - test("Belt.Array.makeUninitialized", () => { +describe("Belt_Array.get", () => { + test("Belt_Array.get", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None + } + () + }) +}) - Belt.Array.getExn(arr, 0) == Js.undefined +describe("Belt_Array.zip", () => { + test("Belt_Array.zip", () => { + module Test = { + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Belt.Array.reverse", () => { - test("Belt.Array.reverse", () => { +describe("Belt_Array.map", () => { + test("Belt_Array.map", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Belt.Array.reverseInPlace", () => { - test("Belt.Array.reverseInPlace", () => { +describe("Belt_Array.cmp", () => { + test("Belt_Array.cmp", () => { module Test = { - let arr = [10, 11, 12, 13, 14] + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - let () = Belt.Array.reverseInPlace(arr) + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - arr == [14, 13, 12, 11, 10] + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Belt.Array.get", () => { - test("Belt.Array.get", () => { +describe("Array.pushMany", () => { + test("Array.pushMany", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + let someArray = ["hi", "hello"] + + someArray->Array.pushMany(["yay", "wehoo"]) + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) } () }) }) -describe("Belt.Array.length", () => { - test("Belt.Array.length", () => { +describe("Array.includes", () => { + test("Array.includes", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + [1, 2]->Array.includes(1)->assertEqual(true) + [1, 2]->Array.includes(3)->assertEqual(false) + + [{"language": "ReScript"}] + ->Array.includes({"language": "ReScript"}) + ->assertEqual(false) // false, because of strict equality } () }) }) -describe("Belt.Option", () => { - test("Belt.Option", () => { +describe("Array.joinWith", () => { + test("Array.joinWith", () => { module Test = { - type option<'a> = None | Some('a) - - let someString: option = Some("hello") + ["One", "Two", "Three"] + ->Array.joinWith(" -- ") + ->assertEqual("One -- Two -- Three") } () }) }) -describe("Belt.HashMap", () => { - test("Belt.HashMap", () => { +describe("Array.toString", () => { + test("Array.toString", () => { module Test = { - type t = int - module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) - let s0: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I0), - ) - - module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) - let s1: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I1), - ) - - let () = { - Belt.HashMap.set(s0, 0, 3) - Belt.HashMap.set(s1, 1, "3") - } + [1, 2, 3, 4] + ->Array.toString + ->assertEqual("1,2,3,4") } () }) }) -describe("Belt.HashSet", () => { - test("Belt.HashSet", () => { +describe("Array.keepSome", () => { + test("Array.keepSome", () => { module Test = { - module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) + Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) - let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) + Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) - module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) + Array.keepSome([None, None, None])->assertEqual([]) - let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) + Array.keepSome([])->assertEqual([]) + } + () + }) +}) - Belt.HashSet.add(s1, 0) - Belt.HashSet.add(s1, 1) +describe("String.endsWith", () => { + test("String.endsWith", () => { + module Test = { + String.endsWith("BuckleScript", "Script") == true + String.endsWith("BuckleShoes", "Script") == false } () }) }) -describe("Belt.MutableSet", () => { - test("Belt.MutableSet", () => { +describe("String.includes", () => { + test("String.includes", () => { module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) - - let mySet = Belt.MutableSet.make(~id=module(PairComparator)) - mySet->Belt.MutableSet.add((1, 2)) + String.includes("programmer", "gram") == true + String.includes("programmer", "er") == true + String.includes("programmer", "pro") == true + String.includes("programmer.dat", "xyz") == false } () }) }) -describe("Belt.Set", () => { - test("Belt.Set", () => { +describe("String.padStart", () => { + test("String.padStart", () => { module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) - - let mySet = Belt.Set.make(~id=module(PairComparator)) - let mySet2 = Belt.Set.add(mySet, (1, 2)) - - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + String.padStart("abc", 5, " ") == " abc" + String.padStart("abc", 6, "123465") == "123abc" } () }) }) -describe("Belt_Int./", () => { - test("Belt_Int./", () => { +describe("Result.mapError", () => { + test("Result.mapError", () => { module Test = { - open Belt.Int - assertEqual(4 / 2, 2) + let format = n => `Error code: ${n->Int.toString}` + Result.mapError(Error(14), format) // Error("Error code: 14") + Result.mapError(Ok("abc"), format) // Ok("abc") } () }) }) -describe("Belt_Int.*", () => { - test("Belt_Int.*", () => { +describe("Promise.resolve", () => { + test("Promise.resolve", () => { module Test = { - open Belt.Int - assertEqual(2 * 2, 4) + let p = Promise.resolve(5) // promise } () }) }) -describe("Belt_Int.-", () => { - test("Belt_Int.-", () => { +describe("Promise.finally", () => { + test("Promise.finally", () => { module Test = { - open Belt.Int - assertEqual(2 - 1, 1) - } - () - }) -}) + open Promise + exception SomeError(string) + let isDone = ref(false) -describe("Belt_Int.+", () => { - test("Belt_Int.+", () => { - module Test = { - open Belt.Int - assertEqual(2 + 2, 4) + resolve(5) + ->then( + _ => { + reject(SomeError("test")) + }, + ) + ->then( + v => { + Console.log2("final result", v) + resolve() + }, + ) + ->catch( + _ => { + Console.log("Error handled") + resolve() + }, + ) + ->finally( + () => { + Console.log("finally") + isDone := true + }, + ) + ->then( + () => { + Console.log2("isDone:", isDone.contents) + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_Int.toString", () => { - test("Belt_Int.toString", () => { +describe("Object.isSealed", () => { + test("Object.isSealed", () => { module Test = { - Belt.Int.toString(1)->assertEqual("1") + let point = {"x": 1, "y": 3}->Object.seal + let pointIsSealed = point->Object.isSealed // true + let fruit = {"name": "Apple"} + let fruitIsSealed = fruit->Object.isSealed // false } () }) }) -describe("Belt_Int.fromString", () => { - test("Belt_Int.fromString", () => { +describe("Object.isFrozen", () => { + test("Object.isFrozen", () => { module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) + let point = {"x": 1, "y": 3}->Object.freeze + let pointIsFrozen = point->Object.isFrozen // true + let fruit = {"name": "Apple"} + let fruitIsFrozen = fruit->Object.isFrozen // false } () }) }) -describe("Belt_Int.fromFloat", () => { - test("Belt_Int.fromFloat", () => { +describe("Nullable.getExn", () => { + test("Nullable.getExn", () => { module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) + switch Nullable.getExn(%raw("'Hello'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "Hello") + } + + switch Nullable.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } + + switch Nullable.getExn(%raw("undefined")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_Int.toFloat", () => { - test("Belt_Int.toFloat", () => { +describe("List.toShuffled", () => { + test("List.toShuffled", () => { module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) + List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Belt_List.sort", () => { - test("Belt_List.sort", () => { +describe("List.concatMany", () => { + test("List.concatMany", () => { module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Belt_List.setAssoc", () => { - test("Belt_List.setAssoc", () => { +describe("List.mapReverse", () => { + test("List.mapReverse", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + let f = x => x * x + let l = list{3, 4, 5} - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + let withMap = List.map(l, f)->List.reverse + let withMapReverse = l->List.mapReverse(f) - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + Console.log(withMap == withMapReverse) // true } () }) }) -describe("Belt_List.removeAssoc", () => { - test("Belt_List.removeAssoc", () => { +describe("Null.asNullable", () => { + test("Null.asNullable", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ + let nullValue = Null.make("Hello") + let asNullable = nullValue->Null.asNullable // Nullable.t } () }) }) -describe("Belt_List.hasAssoc", () => { - test("Belt_List.hasAssoc", () => { +describe("Null.fromOption", () => { + test("Null.fromOption", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ + let optString: option = None + let asNull = optString->Null.fromOption // Null.t + Console.log(asNull == Null.null) // Logs `true` to the console. } () }) }) -describe("Belt_List.getAssoc", () => { - test("Belt_List.getAssoc", () => { +describe("Math.Int.random", () => { + test("Math.Int.random", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ + Math.Int.random(2, 5) == 4 + Math.Int.random(505, 2000) == 1276 + Math.Int.random(-7, -2) == -4 } () }) }) -describe("Belt_List.unzip", () => { - test("Belt_List.unzip", () => { +describe("JSON.Encode.int", () => { + test("JSON.Encode.int", () => { module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ - - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + JSON.Encode.int(42) } () }) }) -describe("Belt_List.partition", () => { - test("Belt_List.partition", () => { +describe("Int.toPrecision", () => { + test("Int.toPrecision", () => { module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) + Int.toPrecision(100) // "100" + Int.toPrecision(1) // "1" + Int.toPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecision(1, ~digits=2) // "1.0" } () }) }) -describe("Belt_List.keepMap", () => { - test("Belt_List.keepMap", () => { +describe("Int.Bitwise.lor", () => { + test("Int.Bitwise.lor", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ - - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + Int.Bitwise.lor(7, 4) == 7 } () }) }) -describe("Belt_List.filterWithIndex", () => { - test("Belt_List.filterWithIndex", () => { +describe("Int.Bitwise.lsl", () => { + test("Int.Bitwise.lsl", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + Int.Bitwise.lsl(4, 1) == 8 } () }) }) -describe("Belt_List.keepWithIndex", () => { - test("Belt_List.keepWithIndex", () => { +describe("Int.Bitwise.lsr", () => { + test("Int.Bitwise.lsr", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + Int.Bitwise.lsr(8, 1) == 4 } () }) }) -describe("Belt_List.filter", () => { - test("Belt_List.filter", () => { +describe("Int.Bitwise.asr", () => { + test("Int.Bitwise.asr", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + Int.Bitwise.asr(4, 1) == 2 } () }) }) -describe("Belt_List.keep", () => { - test("Belt_List.keep", () => { +describe("Date.fromString", () => { + test("Date.fromString", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + Date.fromString("2023") // 2023-01-01T00:00:00.000Z - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ - } - () - }) -}) + Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z -describe("Belt_List.getBy", () => { - test("Belt_List.getBy", () => { - module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + Date.fromString("") // Invalid Date - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + Date.fromString("")->Date.getTime // NaN } () }) }) -describe("Belt_List.has", () => { - test("Belt_List.has", () => { +describe("Date.makeWithYM", () => { + test("Date.makeWithYM", () => { module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + Date.makeWithYM(~year=2023, ~month=0) + // 2023-01-01T00:00:00.000Z - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + Date.makeWithYM(~year=2023, ~month=11) + // 2023-12-01T00:00:00.000Z - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + Date.makeWithYM(~year=2023, ~month=12) + // 2024-01-01T00:00:00.000Z + + Date.makeWithYM(~year=2023, ~month=-1) + // 2022-12-01T00:00:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_List.eq", () => { - test("Belt_List.eq", () => { +describe("Date.getMinutes", () => { + test("Date.getMinutes", () => { module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes + // 40 } () }) }) -describe("Belt_List.cmp", () => { - test("Belt_List.cmp", () => { +describe("Date.getSeconds", () => { + test("Date.getSeconds", () => { module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds + // 0 } () }) }) -describe("Belt_List.cmpByLength", () => { - test("Belt_List.cmpByLength", () => { +describe("Date.setHoursMS", () => { + test("Date.setHoursMS", () => { module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) } () }) }) -describe("Belt_List.some2", () => { - test("Belt_List.some2", () => { +describe("Date.setMinutes", () => { + test("Date.setMinutes", () => { module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) } () }) }) -describe("Belt_List.every2", () => { - test("Belt_List.every2", () => { +describe("Date.setSeconds", () => { + test("Date.setSeconds", () => { module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) } () }) }) -describe("Belt_List.some", () => { - test("Belt_List.some", () => { +describe("Date.getUTCDate", () => { + test("Date.getUTCDate", () => { module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 } () }) }) -describe("Belt_List.every", () => { - test("Belt_List.every", () => { +describe("Date.setUTCDate", () => { + test("Date.setUTCDate", () => { module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) } () }) }) -describe("Belt_List.reduceReverse2", () => { - test("Belt_List.reduceReverse2", () => { +describe("Console.assert_", () => { + test("Console.assert_", () => { module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + Console.assert_(false, "Hello World!") + Console.assert_(42 == 42, "The answer") } () }) }) -describe("Belt_List.reduce2", () => { - test("Belt_List.reduce2", () => { +describe("Console.assert2", () => { + test("Console.assert2", () => { module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + Console.assert2(false, "Hello", "World") + Console.assert2(42 == 42, [1, 2, 3], '4') } () }) }) -describe("Belt_List.forEach2", () => { - test("Belt_List.forEach2", () => { +describe("Console.assert3", () => { + test("Console.assert3", () => { module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ + Console.assert3(false, "Hello", "World", "ReScript") + Console.assert3(42 == 42, "One", 2, #3) } () }) }) -describe("Belt_List.mapReverse2", () => { - test("Belt_List.mapReverse2", () => { +describe("Console.assert4", () => { + test("Console.assert4", () => { module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + let value = 42 + Console.assert4(false, "Hello", "World", "ReScript", "!!!") + Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Belt_List.reduceReverse", () => { - test("Belt_List.reduceReverse", () => { +describe("Console.assert5", () => { + test("Console.assert5", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} + let value = 42 + Console.assert5(false, "Hello", "World", "JS", '!', '!') + Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt_List.reduceWithIndex", () => { - test("Belt_List.reduceWithIndex", () => { +describe("Console.assert6", () => { + test("Console.assert6", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ + let value = 42 + Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') + Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt_List.reduce", () => { - test("Belt_List.reduce", () => { +describe("Console.logMany", () => { + test("Console.logMany", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - - /* same as */ - - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + Console.logMany(["Hello", "World"]) + Console.logMany([1, 2, 3]) } () }) }) -describe("Belt_List.forEachWithIndex", () => { - test("Belt_List.forEachWithIndex", () => { +describe("Console.timeEnd", () => { + test("Console.timeEnd", () => { module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt_List.forEach", () => { - test("Belt_List.forEach", () => { +describe("Console.timeLog", () => { + test("Console.timeLog", () => { module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt_List.mapReverse", () => { - test("Belt_List.mapReverse", () => { +describe("BigInt.toString", () => { + test("BigInt.toString", () => { module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log } () }) }) -describe("Belt_List.reverse", () => { - test("Belt_List.reverse", () => { +describe("Belt_Set.remove", () => { + test("Belt_Set.remove", () => { module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) + + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) } () }) }) -describe("Belt_List.toArray", () => { - test("Belt_List.toArray", () => { +describe("Belt_Set.subset", () => { + test("Belt_Set.subset", () => { module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) + + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) } () }) }) -describe("Belt_List.fromArray", () => { - test("Belt_List.fromArray", () => { +describe("Belt_Set.reduce", () => { + test("Belt_Set.reduce", () => { module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt_List.mapWithIndex", () => { - test("Belt_List.mapWithIndex", () => { +describe("Belt_Set.toList", () => { + test("Belt_Set.toList", () => { module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) } () }) }) -describe("Belt_List.zipBy", () => { - test("Belt_List.zipBy", () => { +describe("Belt_SetDict.eq", () => { + test("Belt_SetDict.eq", () => { module Test = { - Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_List.zip", () => { - test("Belt_List.zip", () => { +describe("Belt_Result.map", () => { + test("Belt_Result.map", () => { module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + let f = x => sqrt(Belt.Int.toFloat(x)) + + Belt.Result.map(Ok(64), f) == Ok(8.0) + + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Belt_List.map", () => { - test("Belt_List.map", () => { +describe("Belt_Result.cmp", () => { + test("Belt_Result.cmp", () => { module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + let good1 = Belt.Result.Ok(59) + + let good2 = Belt.Result.Ok(37) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 } () }) }) -describe("Belt_List.flatten", () => { - test("Belt_List.flatten", () => { +describe("Belt_Range.some", () => { + test("Belt_Range.some", () => { module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ } () }) }) -describe("Belt_List.reverseConcat", () => { - test("Belt_List.reverseConcat", () => { +describe("Belt_Option.map", () => { + test("Belt_Option.map", () => { module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + + Belt.Option.map(None, x => x * x) /* None */ } () }) }) -describe("Belt_List.concatMany", () => { - test("Belt_List.concatMany", () => { +describe("Belt_Option.cmp", () => { + test("Belt_Option.cmp", () => { module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) + + open Belt.Option + + cmp(Some(3), Some(15), clockCompare) /* 0 */ + + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ } () }) }) -describe("Belt_List.concat", () => { - test("Belt_List.concat", () => { +describe("Belt_Map.reduce", () => { + test("Belt_Map.reduce", () => { module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ } () }) }) -describe("Belt_List.splitAt", () => { - test("Belt_List.splitAt", () => { +describe("Belt_Map.remove", () => { + test("Belt_Map.remove", () => { module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] } () }) }) -describe("Belt_List.take", () => { - test("Belt_List.take", () => { +describe("Belt_List.zipBy", () => { + test("Belt_List.zipBy", () => { module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->Belt.List.take(4) // None + Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} } () }) }) -describe("Belt_List.drop", () => { - test("Belt_List.drop", () => { +describe("Belt_List.every", () => { + test("Belt_List.every", () => { module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + let isBelow10 = value => value < 10 - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - list{1, 2, 3}->Belt.List.drop(4) // None + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ } () }) }) -describe("Belt_List.shuffle", () => { - test("Belt_List.shuffle", () => { +describe("Belt_List.some2", () => { + test("Belt_List.some2", () => { module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ + + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ } () }) }) -describe("Belt_List.makeBy", () => { - test("Belt_List.makeBy", () => { +describe("Belt_List.getBy", () => { + test("Belt_List.getBy", () => { module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ } () }) }) -describe("Belt_List.make", () => { - test("Belt_List.make", () => { +describe("Belt_List.unzip", () => { + test("Belt_List.unzip", () => { module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ } () }) }) -describe("Belt_List.getExn", () => { - test("Belt_List.getExn", () => { +describe("Belt.MutableSet", () => { + test("Belt.MutableSet", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.getExn(1)->assertEqual("B") + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + let mySet = Belt.MutableSet.make(~id=module(PairComparator)) + mySet->Belt.MutableSet.add((1, 2)) } () }) }) -describe("Belt_List.get", () => { - test("Belt_List.get", () => { +describe("Belt.Array.fill", () => { + test("Belt.Array.fill", () => { module Test = { - let abc = list{"A", "B", "C"} + let arr = Belt.Array.makeBy(5, i => i) - abc->Belt.List.get(1) // Some("B") + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - abc->Belt.List.get(4) // None - } - () - }) -}) + arr == [0, 1, 9, 9, 4] -describe("Belt_List.add", () => { - test("Belt_List.add", () => { - module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Belt_List.tailExn", () => { - test("Belt_List.tailExn", () => { +describe("Belt.Array.blit", () => { + test("Belt.Array.blit", () => { module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] -describe("Belt_List.tail", () => { - test("Belt_List.tail", () => { - module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] - Belt.List.tail(list{}) // None + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Belt_List.headExn", () => { - test("Belt_List.headExn", () => { +describe("Belt.Array.some", () => { + test("Belt.Array.some", () => { module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Belt_List.head", () => { - test("Belt_List.head", () => { +describe("Belt.List.zipBy", () => { + test("Belt.List.zipBy", () => { module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) + Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} } () }) }) -describe("Belt_List.length", () => { - test("Belt_List.length", () => { +describe("Belt.List.every", () => { + test("Belt.List.every", () => { module Test = { - Belt.List.length(list{1, 2, 3}) // 3 + let isBelow10 = value => value < 10 + + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ } () }) }) -describe("Belt_Map.Dict.findFirstBy", () => { - test("Belt_Map.Dict.findFirstBy", () => { +describe("Belt.List.some2", () => { + test("Belt.List.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ } () }) }) -describe("Belt_Map.String.findFirstBy", () => { - test("Belt_Map.String.findFirstBy", () => { +describe("Belt.List.getBy", () => { + test("Belt.List.getBy", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ } () }) }) -describe("Belt_Map.Int.findFirstBy", () => { - test("Belt_Map.Int.findFirstBy", () => { +describe("Belt.List.unzip", () => { + test("Belt.List.unzip", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ } () }) }) -describe("Belt_Map.set", () => { - test("Belt_Map.set", () => { +describe("Belt.Range.some", () => { + test("Belt.Range.some", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.set(s0, 2, "3") + Belt.Range.some(0, 4, i => i > 5) /* false */ - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + Belt.Range.some(0, 4, i => i > 2) /* true */ } () }) }) -describe("Belt_Map.remove", () => { - test("Belt_Map.remove", () => { +describe("Belt.Set.remove", () => { + test("Belt.Set.remove", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) - - s1 === s2 + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) - Belt.Map.keysToArray(s1) == [2, 3] + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) } () }) }) -describe("Belt_Map.get", () => { - test("Belt_Map.get", () => { +describe("Belt.Set.subset", () => { + test("Belt.Set.subset", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) } () }) }) -describe("Belt_Map.valuesToArray", () => { - test("Belt_Map.valuesToArray", () => { +describe("Belt.Set.reduce", () => { + test("Belt.Set.reduce", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt_Map.keysToArray", () => { - test("Belt_Map.keysToArray", () => { +describe("Belt.Set.toList", () => { + test("Belt.Set.toList", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) } () }) }) -describe("Belt_Map.fromArray", () => { - test("Belt_Map.fromArray", () => { +describe("Belt.Map.reduce", () => { + test("Belt.Map.reduce", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ } () }) }) -describe("Belt_Map.toArray", () => { - test("Belt_Map.toArray", () => { +describe("Belt.Map.remove", () => { + test("Belt.Map.remove", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] } () }) }) -describe("Belt_Map.size", () => { - test("Belt_Map.size", () => { +describe("Belt.Option.map", () => { + test("Belt.Option.map", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 + Belt.Option.map(None, x => x * x) /* None */ } () }) }) -describe("Belt_Map.reduce", () => { - test("Belt_Map.reduce", () => { +describe("Belt.Option.cmp", () => { + test("Belt.Option.cmp", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + open Belt.Option - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + cmp(Some(3), Some(15), clockCompare) /* 0 */ + + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ } () }) }) -describe("Belt_Map.forEach", () => { - test("Belt_Map.forEach", () => { +describe("Belt.Result.map", () => { + test("Belt.Result.map", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - let acc = ref(list{}) + let f = x => sqrt(Belt.Int.toFloat(x)) - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + Belt.Result.map(Ok(64), f) == Ok(8.0) - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Belt_Map.findFirstBy", () => { - test("Belt_Map.findFirstBy", () => { +describe("Belt.Result.cmp", () => { + test("Belt.Result.cmp", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + let good1 = Belt.Result.Ok(59) - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + let good2 = Belt.Result.Ok(37) - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 } () }) }) -describe("Belt_Map.has", () => { - test("Belt_Map.has", () => { +describe("Belt_Array.fill", () => { + test("Belt_Array.fill", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + let arr = Belt.Array.makeBy(5, i => i) - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Belt_Map.isEmpty", () => { - test("Belt_Map.isEmpty", () => { +describe("Belt_Array.blit", () => { + test("Belt_Array.blit", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Belt_Map.make", () => { - test("Belt_Map.make", () => { +describe("Belt_Array.some", () => { + test("Belt_Array.some", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let m = Belt.Map.make(~id=module(IntCmp)) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - Belt.Map.set(m, 0, "a") + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Belt_Map.Int", () => { - test("Belt_Map.Int", () => { +describe("Array.fillToEnd", () => { + test("Array.fillToEnd", () => { module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + let myArray = [1, 2, 3, 4] + myArray->Array.fillToEnd(9, ~start=1) + myArray->assertEqual([1, 9, 9, 9]) } () }) }) -describe("Belt_MapDict.findFirstBy", () => { - test("Belt_MapDict.findFirstBy", () => { +describe("Array.findIndex", () => { + test("Array.findIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + type languages = ReScript | TypeScript | JavaScript - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + let array = [ReScript, JavaScript] - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + array + ->Array.findIndex(item => item == ReScript) + ->assertEqual(0) + + array + ->Array.findIndex(item => item == TypeScript) + ->assertEqual(-1) } () }) }) -describe("Belt_MapInt.findFirstBy", () => { - test("Belt_MapInt.findFirstBy", () => { +describe("Array.getUnsafe", () => { + test("Array.getUnsafe", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.getUnsafe(index) + Console.log(value) + } } () }) }) -describe("Belt_MapString.findFirstBy", () => { - test("Belt_MapString.findFirstBy", () => { +describe("Array.setUnsafe", () => { + test("Array.setUnsafe", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + let array = ["Hello", "Hi", "Good bye"] + array->Array.setUnsafe(1, "Hello") - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + assertEqual(array[1], Some("Hello")) } () }) }) -describe("Belt_MutableSet.split", () => { - test("Belt_MutableSet.split", () => { +describe("Array.filterMap", () => { + test("Array.filterMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + ["Hello", "Hi", "Good bye"] + ->Array.filterMap( + item => + switch item { + | "Hello" => Some(item->String.length) + | _ => None + }, + ) + ->assertEqual([5]) - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + [1, 2, 3, 4, 5, 6] + ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) + ->assertEqual([4, 16, 36]) - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ + Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) } () }) }) -describe("Belt_MutableSet.get", () => { - test("Belt_MutableSet.get", () => { +describe("String.getUnsafe", () => { + test("String.getUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ + String.getUnsafe("ReScript", 0) == "R" + String.getUnsafe("Hello", 4) == "o" } () }) }) -describe("Belt_MutableSet.maxUndefined", () => { - test("Belt_MutableSet.maxUndefined", () => { +describe("String.normalize", () => { + test("String.normalize", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let string1 = "\u00F1" + let string2 = "\u006E\u0303" - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ + assert(string1 != string2) // true + assertEqual(String.normalize(string1), String.normalize(string2)) } () }) }) -describe("Belt_MutableSet.maximum", () => { - test("Belt_MutableSet.maximum", () => { +describe("String.searchOpt", () => { + test("String.searchOpt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + String.searchOpt("testing 1 2 3", /\d+/) == Some(8) + String.searchOpt("no numbers", /\d+/) == None + } + () + }) +}) - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ +describe("String.substring", () => { + test("String.substring", () => { + module Test = { + String.substring("playground", ~start=3, ~end=6) == "ygr" + String.substring("playground", ~start=6, ~end=3) == "ygr" + String.substring("playground", ~start=4, ~end=12) == "ground" } () }) }) -describe("Belt_MutableSet.minUndefined", () => { - test("Belt_MutableSet.minUndefined", () => { +describe("String.trimStart", () => { + test("String.trimStart", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ + String.trimStart(" Hello world! ") == "Hello world! " + String.trimStart(" Hello world! ") == "Hello world! " } () }) }) -describe("Belt_MutableSet.minimum", () => { - test("Belt_MutableSet.minimum", () => { +describe("Set.fromIterator", () => { + test("Set.fromIterator", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + // Let's pretend we have an interator + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ + iterator + ->Set.fromIterator + ->Set.size + ->assertEqual(3) } () }) }) -describe("Belt_MutableSet.toArray", () => { - test("Belt_MutableSet.toArray", () => { +describe("RegExp.lastIndex", () => { + test("RegExp.lastIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + regexp->RegExp.exec(someStr)->ignore + + Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console } () }) }) -describe("Belt_MutableSet.toList", () => { - test("Belt_MutableSet.toList", () => { +describe("RegExp.multiline", () => { + test("RegExp.multiline", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set - s0->Belt.MutableSet.toList /* [1,2,3,5] */ + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") + Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set } () }) }) -describe("Belt_MutableSet.size", () => { - test("Belt_MutableSet.size", () => { +describe("Option.getUnsafe", () => { + test("Option.getUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ + Option.getUnsafe(Some(3)) == 3 + Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` } () }) }) -describe("Belt_MutableSet.partition", () => { - test("Belt_MutableSet.partition", () => { +describe("Object.getSymbol", () => { + test("Object.getSymbol", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ + let fruit = Symbol.make("fruit") + let x = Object.make() + x->Object.setSymbol(fruit, "banana") + x->Object.getSymbol(fruit) // Some("banana") } () }) }) -describe("Belt_MutableSet.keep", () => { - test("Belt_MutableSet.keep", () => { +describe("Nullable.forEach", () => { + test("Nullable.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ + Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" + Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () + Nullable.forEach(undefined, x => Console.log(x)) // returns () } () }) }) -describe("Belt_MutableSet.some", () => { - test("Belt_MutableSet.some", () => { +describe("Nullable.flatMap", () => { + test("Nullable.flatMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + let addIfAboveOne = value => + if value > 1 { + Nullable.make(value + 1) + } else { + Nullable.null + } - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ + Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) + Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined + Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined } () }) }) -describe("Belt_MutableSet.every", () => { - test("Belt_MutableSet.every", () => { +describe("List.mapReverse2", () => { + test("List.mapReverse2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ + List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Belt_MutableSet.reduce", () => { - test("Belt_MutableSet.reduce", () => { +describe("List.removeAssoc", () => { + test("List.removeAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + // list{(15, "afternoon"), (22, "night")} } () }) }) -describe("Belt_MutableSet.forEach", () => { - test("Belt_MutableSet.forEach", () => { +describe("Math.Constants.e", () => { + test("Math.Constants.e", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + Math.Constants.e } () }) }) -describe("Belt_MutableSet.eq", () => { - test("Belt_MutableSet.eq", () => { +describe("Math.Int.minMany", () => { + test("Math.Int.minMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.MutableSet.eq(s0, s1) /* true */ + Math.Int.minMany([1, 2]) // 1 + Math.Int.minMany([-1, -2]) // -2 + Math.Int.minMany([])->Int.toFloat->Float.isFinite // false } () }) }) -describe("Belt_MutableSet.subset", () => { - test("Belt_MutableSet.subset", () => { +describe("Math.Int.maxMany", () => { + test("Math.Int.maxMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ + Math.Int.maxMany([1, 2]) // 2 + Math.Int.maxMany([-1, -2]) // -1 + Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false } () }) }) -describe("Belt_MutableSet.diff", () => { - test("Belt_MutableSet.diff", () => { +describe("Map.fromIterator", () => { + test("Map.fromIterator", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + // Let's pretend we have an interator in the correct shape + let iterator: Iterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + iterator + ->Map.fromIterator + ->Map.size + ->assertEqual(2) } () }) }) -describe("Belt_MutableSet.intersect", () => { - test("Belt_MutableSet.intersect", () => { +describe("JSON.Encode.bool", () => { + test("JSON.Encode.bool", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ + JSON.Encode.bool(true) } () }) }) -describe("Belt_MutableSet.union", () => { - test("Belt_MutableSet.union", () => { +describe("JSON.Encode.null", () => { + test("JSON.Encode.null", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + JSON.Encode.null } () }) }) -describe("Belt_MutableSet.removeMany", () => { - test("Belt_MutableSet.removeMany", () => { +describe("JSON.Decode.bool", () => { + test("JSON.Decode.bool", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + JSON.parseExn(`true`)->JSON.Decode.bool + // Some(true) - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ + JSON.parseExn(`"hello world"`)->JSON.Decode.bool + // None } () }) }) -describe("Belt_MutableSet.remove", () => { - test("Belt_MutableSet.remove", () => { +describe("JSON.Decode.null", () => { + test("JSON.Decode.null", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) + JSON.parseExn(`null`)->JSON.Decode.null + // Some(null) - s0->Belt.MutableSet.toArray /* [2,4,5] */ + JSON.parseExn(`"hello world"`)->JSON.Decode.null + // None } () }) }) -describe("Belt_MutableSet.mergeMany", () => { - test("Belt_MutableSet.mergeMany", () => { +describe("Iterator.toArray", () => { + test("Iterator.toArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - let set = Belt.MutableSet.make(~id=module(IntCmp)) + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = map->Map.keys->Iterator.toArray - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. } () }) }) -describe("Belt_MutableSet.add", () => { - test("Belt_MutableSet.add", () => { +describe("Iterator.forEach", () => { + test("Iterator.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + iterator->Iterator.forEach( + v => { + switch v { + | Some("a" | "b" | "c") => assert(true) + | other => + other + ->Option.isNone + ->assertEqual(true) + } + }, + ) } () }) }) -describe("Belt_MutableSet.has", () => { - test("Belt_MutableSet.has", () => { +describe("Int.Bitwise.land", () => { + test("Int.Bitwise.land", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ + Int.Bitwise.land(7, 4) == 4 } () }) }) -describe("Belt_MutableSet.isEmpty", () => { - test("Belt_MutableSet.isEmpty", () => { +describe("Int.Bitwise.lxor", () => { + test("Int.Bitwise.lxor", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ + Int.Bitwise.lxor(7, 4) == 3 } () }) }) -describe("Belt_MutableSet.copy", () => { - test("Belt_MutableSet.copy", () => { +describe("Int.Bitwise.lnot", () => { + test("Int.Bitwise.lnot", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + Int.Bitwise.lnot(2) == -3 } () }) }) -describe("Belt_MutableSet.fromArray", () => { - test("Belt_MutableSet.fromArray", () => { +describe("Float.parseFloat", () => { + test("Float.parseFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + Float.parseFloat("1.0") // 1.0 + Float.parseFloat(" 3.14 ") // 3.14 + Float.parseFloat("3.0") // 3.0 + Float.parseFloat("3.14some non-digit characters") // 3.14 + Float.parseFloat("error")->Float.isNaN // true } () }) }) -describe("Belt_Option.cmp", () => { - test("Belt_Option.cmp", () => { +describe("Float.fromString", () => { + test("Float.fromString", () => { module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ - - cmp(Some(14), None, clockCompare) /* 1 */ - - cmp(None, None, clockCompare) /* 0 */ + Float.fromString("0") == Some(0.0) + Float.fromString("NaN") == None + Float.fromString("6") == Some(6.0) } () }) }) -describe("Belt_Option.eq", () => { - test("Belt_Option.eq", () => { +describe("Date.makeWithYMD", () => { + test("Date.makeWithYMD", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Belt.Option - - eq(Some(3), Some(15), clockEqual) /* true */ - - eq(Some(3), None, clockEqual) /* false */ + Date.makeWithYMD(~year=2023, ~month=1, ~date=20) + // 2023-02-20T00:00:00.000Z - eq(None, Some(3), clockEqual) /* false */ + Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) + // 2022-11-29T00:00:00.000Z - eq(None, None, clockEqual) /* true */ + Date.makeWithYMD(~year=2023, ~month=1, ~date=29) + // 2023-03-01T00:00:00.000Z } () }) }) -describe("Belt_Option.isNone", () => { - test("Belt_Option.isNone", () => { +describe("Date.getFullYear", () => { + test("Date.getFullYear", () => { module Test = { - Belt.Option.isNone(None) /* true */ - - Belt.Option.isNone(Some(1)) /* false */ + Date.fromString("2023-02-20")->Date.getFullYear + // 2023 } () }) }) -describe("Belt_Option.isSome", () => { - test("Belt_Option.isSome", () => { +describe("Date.setFullYear", () => { + test("Date.setFullYear", () => { module Test = { - Belt.Option.isSome(None) /* false */ - - Belt.Option.isSome(Some(1)) /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) } () }) }) -describe("Belt_Option.orElse", () => { - test("Belt_Option.orElse", () => { +describe("Date.setMinutesS", () => { + test("Date.setMinutesS", () => { module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) } () }) }) -describe("Belt_Option.getWithDefault", () => { - test("Belt_Option.getWithDefault", () => { +describe("Date.getUTCMonth", () => { + test("Date.getUTCMonth", () => { module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 } () }) }) -describe("Belt_Option.flatMap", () => { - test("Belt_Option.flatMap", () => { +describe("Date.getUTCHours", () => { + test("Date.getUTCHours", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 } () }) }) -describe("Belt_Option.map", () => { - test("Belt_Option.map", () => { +describe("Date.setUTCMonth", () => { + test("Date.setUTCMonth", () => { module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ - - Belt.Option.map(None, x => x * x) /* None */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) } () }) }) -describe("Belt_Option.mapWithDefault", () => { - test("Belt_Option.mapWithDefault", () => { +describe("Date.setUTCHours", () => { + test("Date.setUTCHours", () => { module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) } () }) }) -describe("Belt_Option.getExn", () => { - test("Belt_Option.getExn", () => { +describe("Date.toISOString", () => { + test("Date.toISOString", () => { module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log + // 2023-01-01T00:00:00.000Z - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log + // 2022-12-31T16:00:00.000Z } () }) }) -describe("Belt_Option.forEach", () => { - test("Belt_Option.forEach", () => { +describe("Date.toUTCString", () => { + test("Date.toUTCString", () => { module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log + // Sun, 01 Jan 2023 00:00:00 GMT + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log + // Sat, 31 Dec 2022 16:00:00 GMT } () }) }) -describe("Belt_Option.keep", () => { - test("Belt_Option.keep", () => { +describe("Dict.keysToArray", () => { + test("Dict.keysToArray", () => { module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let keys = dict->Dict.keysToArray + Console.log(keys) // Logs `["someKey", "someKey2"]` to the console } () }) }) -describe("Belt_Result.cmp", () => { - test("Belt_Result.cmp", () => { +describe("Console.infoMany", () => { + test("Console.infoMany", () => { module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 - - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + Console.infoMany(["Hello", "World"]) + Console.infoMany([1, 2, 3]) } () }) }) -describe("Belt_Result.eq", () => { - test("Belt_Result.eq", () => { +describe("Console.warnMany", () => { + test("Console.warnMany", () => { module Test = { - let good1 = Belt.Result.Ok(42) - - let good2 = Belt.Result.Ok(32) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(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 + Console.warnMany(["Hello", "World"]) + Console.warnMany([1, 2, 3]) } () }) }) -describe("Belt_Result.getWithDefault", () => { - test("Belt_Result.getWithDefault", () => { +describe("Belt_Set.isEmpty", () => { + test("Belt_Set.isEmpty", () => { module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) + + Belt.Set.isEmpty(empty)->assertEqual(true) + Belt.Set.isEmpty(notEmpty)->assertEqual(false) } () }) }) -describe("Belt_Result.flatMap", () => { - test("Belt_Result.flatMap", () => { +describe("Belt_Set.forEach", () => { + test("Belt_Set.forEach", () => { module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + let acc = ref(list{}) - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt_Result.map", () => { - test("Belt_Result.map", () => { +describe("Belt_Set.toArray", () => { + test("Belt_Set.toArray", () => { module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Result.map(Ok(64), f) == Ok(8.0) + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) } () }) }) -describe("Belt_Result.mapWithDefault", () => { - test("Belt_Result.mapWithDefault", () => { +describe("Belt_Set.minimum", () => { + test("Belt_Set.minimum", () => { module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) } () }) }) -describe("Belt_Result.getExn", () => { - test("Belt_Result.getExn", () => { +describe("Belt_Set.maximum", () => { + test("Belt_Set.maximum", () => { module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.maximum->assertEqual(None) + s1->Belt.Set.maximum->assertEqual(Some(5)) } () }) }) -describe("Belt_Range.someBy", () => { - test("Belt_Range.someBy", () => { +describe("Belt_Set.Dict.eq", () => { + test("Belt_Set.Dict.eq", () => { module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_Range.some", () => { - test("Belt_Range.some", () => { +describe("Belt_SetDict.has", () => { + test("Belt_SetDict.has", () => { module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Range.some(0, 4, i => i > 2) /* true */ + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_Range.everyBy", () => { - test("Belt_Range.everyBy", () => { +describe("Belt_SetDict.add", () => { + test("Belt_SetDict.add", () => { module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_Range.every", () => { - test("Belt_Range.every", () => { +describe("Belt_SetDict.get", () => { + test("Belt_SetDict.get", () => { module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Range.every(0, 4, i => i < 4) /* false */ + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ } () }) }) -describe("Belt_Range.forEach", () => { - test("Belt_Range.forEach", () => { +describe("Belt_Range.every", () => { + test("Belt_Range.every", () => { module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) + Belt.Range.every(0, 4, i => i < 5) /* true */ - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 + Belt.Range.every(0, 4, i => i < 4) /* false */ } () }) }) -describe("Belt_SetDict.split", () => { - test("Belt_SetDict.split", () => { +describe("Belt_Option.keep", () => { + test("Belt_Option.keep", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ } () }) }) -describe("Belt_SetDict.get", () => { - test("Belt_SetDict.get", () => { +describe("Belt_Map.isEmpty", () => { + test("Belt_Map.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false } () }) }) -describe("Belt_SetDict.maxUndefined", () => { - test("Belt_SetDict.maxUndefined", () => { +describe("Belt_Map.forEach", () => { + test("Belt_Map.forEach", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ + let acc = ref(list{}) + + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} } () }) }) -describe("Belt_SetDict.maximum", () => { - test("Belt_SetDict.maximum", () => { +describe("Belt_Map.toArray", () => { + test("Belt_Map.toArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt_SetDict.minUndefined", () => { - test("Belt_SetDict.minUndefined", () => { +describe("Belt_Int.toFloat", () => { + test("Belt_Int.toFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + Belt.Int.toFloat(1)->assertEqual(1.0) } () }) }) -describe("Belt_SetDict.minimum", () => { - test("Belt_SetDict.minimum", () => { +describe("Belt_List.length", () => { + test("Belt_List.length", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + Belt.List.length(list{1, 2, 3}) // 3 } () }) }) -describe("Belt_SetDict.toArray", () => { - test("Belt_SetDict.toArray", () => { +describe("Belt_List.getExn", () => { + test("Belt_List.getExn", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let abc = list{"A", "B", "C"} - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + abc->Belt.List.getExn(1)->assertEqual("B") - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_SetDict.toList", () => { - test("Belt_SetDict.toList", () => { +describe("Belt_List.makeBy", () => { + test("Belt_List.makeBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} } () }) }) -describe("Belt_SetDict.size", () => { - test("Belt_SetDict.size", () => { +describe("Belt_List.concat", () => { + test("Belt_List.concat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("Belt_SetDict.partition", () => { - test("Belt_SetDict.partition", () => { +describe("Belt_List.reduce", () => { + test("Belt_List.reduce", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + /* same as */ - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ } () }) }) -describe("Belt_SetDict.keep", () => { - test("Belt_SetDict.keep", () => { +describe("Belt_List.every2", () => { + test("Belt_List.every2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - let isEven = x => mod(x, 2) == 0 + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - s1->Belt.Set.Dict.toArray /* [2,4] */ + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ } () }) }) -describe("Belt_SetDict.some", () => { - test("Belt_SetDict.some", () => { +describe("Belt_List.filter", () => { + test("Belt_List.filter", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let isEven = x => mod(x, 2) == 0 - let isOdd = x => mod(x, 2) != 0 + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Belt_SetDict.every", () => { - test("Belt_SetDict.every", () => { +describe("Belt.Array.range", () => { + test("Belt.Array.range", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.range(0, 3) == [0, 1, 2, 3] - let isEven = x => mod(x, 2) == 0 + Belt.Array.range(3, 0) == [] - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Belt_SetDict.reduce", () => { - test("Belt_SetDict.reduce", () => { +describe("Belt.Array.zipBy", () => { + test("Belt.Array.zipBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Belt_SetDict.forEach", () => { - test("Belt_SetDict.forEach", () => { +describe("Belt.Array.unzip", () => { + test("Belt.Array.unzip", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Belt_SetDict.eq", () => { - test("Belt_SetDict.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) +describe("Belt.Array.slice", () => { + test("Belt.Array.slice", () => { + module Test = { + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Belt_SetDict.subset", () => { - test("Belt_SetDict.subset", () => { +describe("Belt.Array.getBy", () => { + test("Belt.Array.getBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_SetDict.diff", () => { - test("Belt_SetDict.diff", () => { +describe("Belt.Array.every", () => { + test("Belt.Array.every", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Belt_SetDict.intersect", () => { - test("Belt_SetDict.intersect", () => { +describe("Belt.Array.some2", () => { + test("Belt.Array.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + Belt.Array.some2([], [1], (x, y) => x > y) == false + + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Belt_SetDict.union", () => { - test("Belt_SetDict.union", () => { +describe("Belt.List.length", () => { + test("Belt.List.length", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + Belt.List.length(list{1, 2, 3}) // 3 } () }) }) -describe("Belt_SetDict.removeMany", () => { - test("Belt_SetDict.removeMany", () => { +describe("Belt.List.getExn", () => { + test("Belt.List.getExn", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let abc = list{"A", "B", "C"} - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + abc->Belt.List.getExn(1)->assertEqual("B") - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_SetDict.remove", () => { - test("Belt_SetDict.remove", () => { +describe("Belt.List.makeBy", () => { + test("Belt.List.makeBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + } + () + }) +}) - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ +describe("Belt.List.concat", () => { + test("Belt.List.concat", () => { + module Test = { + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("Belt_SetDict.mergeMany", () => { - test("Belt_SetDict.mergeMany", () => { +describe("Belt.List.reduce", () => { + test("Belt.List.reduce", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - let set = Belt.Set.Dict.empty + /* same as */ - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ } () }) }) -describe("Belt_SetDict.add", () => { - test("Belt_SetDict.add", () => { +describe("Belt.List.every2", () => { + test("Belt.List.every2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ } () }) }) -describe("Belt_SetDict.has", () => { - test("Belt_SetDict.has", () => { +describe("Belt.List.filter", () => { + test("Belt.List.filter", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let isEven = x => mod(x, 2) == 0 - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Belt_SetDict.isEmpty", () => { - test("Belt_SetDict.isEmpty", () => { +describe("Belt.Range.every", () => { + test("Belt.Range.every", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + Belt.Range.every(0, 4, i => i < 5) /* true */ - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + Belt.Range.every(0, 4, i => i < 4) /* false */ } () }) }) -describe("Belt_SetDict.fromArray", () => { - test("Belt_SetDict.fromArray", () => { +describe("Belt.Set.isEmpty", () => { + test("Belt.Set.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) + let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) -describe("Belt_SetDict.empty", () => { - test("Belt_SetDict.empty", () => { - module Test = { - let s0 = Belt.Set.Dict.empty + Belt.Set.isEmpty(empty)->assertEqual(true) + Belt.Set.isEmpty(notEmpty)->assertEqual(false) } () }) }) -describe("Belt_Set.Dict.split", () => { - test("Belt_Set.Dict.split", () => { +describe("Belt.Set.forEach", () => { + test("Belt.Set.forEach", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + let acc = ref(list{}) - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt_Set.Dict.get", () => { - test("Belt_Set.Dict.get", () => { +describe("Belt.Set.toArray", () => { + test("Belt.Set.toArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) } () }) }) -describe("Belt_Set.Dict.maxUndefined", () => { - test("Belt_Set.Dict.maxUndefined", () => { +describe("Belt.Set.minimum", () => { + test("Belt.Set.minimum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) } () }) }) -describe("Belt_Set.Dict.maximum", () => { - test("Belt_Set.Dict.maximum", () => { +describe("Belt.Set.maximum", () => { + test("Belt.Set.maximum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + s0->Belt.Set.maximum->assertEqual(None) + s1->Belt.Set.maximum->assertEqual(Some(5)) } () }) }) -describe("Belt_Set.Dict.minUndefined", () => { - test("Belt_Set.Dict.minUndefined", () => { +describe("Belt.Map.isEmpty", () => { + test("Belt.Map.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false } () }) }) -describe("Belt_Set.Dict.minimum", () => { - test("Belt_Set.Dict.minimum", () => { +describe("Belt.Map.forEach", () => { + test("Belt.Map.forEach", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + let acc = ref(list{}) + + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} } () }) }) -describe("Belt_Set.Dict.toArray", () => { - test("Belt_Set.Dict.toArray", () => { +describe("Belt.Map.toArray", () => { + test("Belt.Map.toArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt_Set.Dict.toList", () => { - test("Belt_Set.Dict.toList", () => { +describe("Belt.HashMap.set", () => { + test("Belt.HashMap.set", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] } () }) }) -describe("Belt_Set.Dict.size", () => { - test("Belt_Set.Dict.size", () => { +describe("Belt.HashMap.get", () => { + test("Belt.HashMap.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - s0->Belt.Set.Dict.size /* 4 */ + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None } () }) }) -describe("Belt_Set.Dict.partition", () => { - test("Belt_Set.Dict.partition", () => { +describe("Belt.HashMap.has", () => { + test("Belt.HashMap.has", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false } () }) }) -describe("Belt_Set.Dict.keep", () => { - test("Belt_Set.Dict.keep", () => { +describe("Belt.Option.keep", () => { + test("Belt.Option.keep", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ } () }) }) -describe("Belt_Set.Dict.some", () => { - test("Belt_Set.Dict.some", () => { +describe("Belt.Int.toFloat", () => { + test("Belt.Int.toFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + Belt.Int.toFloat(1)->assertEqual(1.0) + } + () + }) +}) - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ +describe("Belt.Float.toInt", () => { + test("Belt.Float.toInt", () => { + module Test = { + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ } () }) }) -describe("Belt_Set.Dict.every", () => { - test("Belt_Set.Dict.every", () => { +describe("Belt.Set.Dict.eq", () => { + test("Belt.Set.Dict.eq", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let isEven = x => mod(x, 2) == 0 + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_Set.Dict.reduce", () => { - test("Belt_Set.Dict.reduce", () => { +describe("Belt_Float.toInt", () => { + test("Belt_Float.toInt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ } () }) }) -describe("Belt_Set.Dict.forEach", () => { - test("Belt_Set.Dict.forEach", () => { +describe("Belt_Array.range", () => { + test("Belt_Array.range", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.range(0, 3) == [0, 1, 2, 3] - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Belt_Set.Dict.eq", () => { - test("Belt_Set.Dict.eq", () => { +describe("Belt_Array.zipBy", () => { + test("Belt_Array.zipBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Belt_Set.Dict.subset", () => { - test("Belt_Set.Dict.subset", () => { +describe("Belt_Array.unzip", () => { + test("Belt_Array.unzip", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Belt_Set.Dict.diff", () => { - test("Belt_Set.Dict.diff", () => { +describe("Belt_Array.slice", () => { + test("Belt_Array.slice", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Belt_Set.Dict.intersect", () => { - test("Belt_Set.Dict.intersect", () => { +describe("Belt_Array.getBy", () => { + test("Belt_Array.getBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_Set.Dict.union", () => { - test("Belt_Set.Dict.union", () => { +describe("Belt_Array.every", () => { + test("Belt_Array.every", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Belt_Set.Dict.removeMany", () => { - test("Belt_Set.Dict.removeMany", () => { +describe("Belt_Array.some2", () => { + test("Belt_Array.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + Belt.Array.some2([], [1], (x, y) => x > y) == false - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Belt_Set.Dict.remove", () => { - test("Belt_Set.Dict.remove", () => { +describe("Belt_HashMap.set", () => { + test("Belt_HashMap.set", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] } () }) }) -describe("Belt_Set.Dict.mergeMany", () => { - test("Belt_Set.Dict.mergeMany", () => { +describe("Belt_HashMap.get", () => { + test("Belt_HashMap.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let set = Belt.Set.Dict.empty + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None } () }) }) -describe("Belt_Set.Dict.add", () => { - test("Belt_Set.Dict.add", () => { +describe("Belt_HashMap.has", () => { + test("Belt_HashMap.has", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false } () }) }) -describe("Belt_Set.Dict.has", () => { - test("Belt_Set.Dict.has", () => { +describe("Array.concatMany", () => { + test("Array.concatMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let array1 = ["hi", "hello"] + let array2 = ["yay"] + let array3 = ["wehoo"] - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + let someArray = array1->Array.concatMany([array2, array3]) - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] } () }) }) -describe("Belt_Set.Dict.isEmpty", () => { - test("Belt_Set.Dict.isEmpty", () => { +describe("Array.indexOfOpt", () => { + test("Array.indexOfOpt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) + [1, 2]->Array.indexOfOpt(3)->assertEqual(None) + [{"language": "ReScript"}] + ->Array.indexOfOpt({"language": "ReScript"}) + ->assertEqual(None) // None, because of strict equality } () }) }) -describe("Belt_Set.Dict.fromArray", () => { - test("Belt_Set.Dict.fromArray", () => { +describe("Array.joinUnsafe", () => { + test("Array.joinUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + [1, 2, 3] + ->Array.joinUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") } () }) }) -describe("Belt_Set.Dict.empty", () => { - test("Belt_Set.Dict.empty", () => { +describe("Array.sliceToEnd", () => { + test("Array.sliceToEnd", () => { module Test = { - let s0 = Belt.Set.Dict.empty + [1, 2, 3, 4] + ->Array.sliceToEnd(~start=1) + ->assertEqual([2, 3, 4]) } () }) }) -describe("Belt_Set.split", () => { - test("Belt_Set.split", () => { +describe("Array.unsafe_get", () => { + test("Array.unsafe_get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.Set.split(3) - - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.unsafe_get(index) + Console.log(value) + } } () }) }) -describe("Belt_Set.get", () => { - test("Belt_Set.get", () => { +describe("Array.toShuffled", () => { + test("Array.toShuffled", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let array = ["Hello", "Hi", "Good bye"] + let shuffledArray = array->Array.toShuffled + Console.log(shuffledArray) - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) + Array.toShuffled([1, 2, 3]) + ->Array.length + ->assertEqual(3) } () }) }) -describe("Belt_Set.maxUndefined", () => { - test("Belt_Set.maxUndefined", () => { +describe("String.charCodeAt", () => { + test("String.charCodeAt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) - - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) + String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat + String.codePointAt(`😺`, 0) == Some(0x1f63a) } () }) }) -describe("Belt_Set.maximum", () => { - test("Belt_Set.maximum", () => { +describe("String.concatMany", () => { + test("String.concatMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.maximum->assertEqual(None) - s1->Belt.Set.maximum->assertEqual(Some(5)) + String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" } () }) }) -describe("Belt_Set.minUndefined", () => { - test("Belt_Set.minUndefined", () => { +describe("String.indexOfOpt", () => { + test("String.indexOfOpt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + String.indexOfOpt("bookseller", "ok") == Some(2) + String.indexOfOpt("bookseller", "xyz") == None } () }) }) -describe("Belt_Set.minimum", () => { - test("Belt_Set.minimum", () => { +describe("String.replaceAll", () => { + test("String.replaceAll", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) + String.replaceAll("old old string", "old", "new") == "new new string" + String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" } () }) }) -describe("Belt_Set.toList", () => { - test("Belt_Set.toList", () => { +describe("String.sliceToEnd", () => { + test("String.sliceToEnd", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + String.sliceToEnd("abcdefg", ~start=4) == "efg" + String.sliceToEnd("abcdefg", ~start=-2) == "fg" + String.sliceToEnd("abcdefg", ~start=7) == "" } () }) }) -describe("Belt_Set.toArray", () => { - test("Belt_Set.toArray", () => { +describe("String.startsWith", () => { + test("String.startsWith", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + String.startsWith("BuckleScript", "Buckle") == true + String.startsWith("BuckleScript", "") == true + String.startsWith("JavaScript", "Buckle") == false } () }) }) -describe("Belt_Set.size", () => { - test("Belt_Set.size", () => { +describe("RegExp.fromString", () => { + test("RegExp.fromString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") - s0->Belt.Set.size->assertEqual(4) + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("Belt_Set.partition", () => { - test("Belt_Set.partition", () => { +describe("RegExp.ignoreCase", () => { + test("RegExp.ignoreCase", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set } () }) }) -describe("Belt_Set.keep", () => { - test("Belt_Set.keep", () => { +describe("Pervasives.import", () => { + test("Pervasives.import", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 + @send external indexOf: (array<'a>, 'a) => int = "indexOf" - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.keep(isEven) + let indexOfOpt = (arr, item) => + switch arr->indexOf(item) { + | -1 => None + | index => Some(index) + } - s1->Belt.Set.toArray->assertEqual([2, 4]) + let main = async () => { + let indexOfOpt = await import(Array.indexOfOpt) + let index = indexOfOpt([1, 2], 2) + Console.log(index) + } } () }) }) -describe("Belt_Set.some", () => { - test("Belt_Set.some", () => { +describe("Nullable.toOption", () => { + test("Nullable.toOption", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + let nullableString = Nullable.make("Hello") - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) + switch nullableString->Nullable.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } } () }) }) -describe("Belt_Set.every", () => { - test("Belt_Set.every", () => { +describe("List.mapWithIndex", () => { + test("List.mapWithIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) + list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} } () }) }) -describe("Belt_Set.reduce", () => { - test("Belt_Set.reduce", () => { +describe("Math.Constants.pi", () => { + test("Math.Constants.pi", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) + Math.Constants.pi } () }) }) -describe("Belt_Set.forEach", () => { - test("Belt_Set.forEach", () => { +describe("JSON.stringifyAny", () => { + test("JSON.stringifyAny", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - let acc = ref(list{}) + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } }, ) - acc.contents->assertEqual(list{6, 5, 3, 2}) + dict + ->JSON.stringifyAny(~replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + // Raise a exception + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_Set.eq", () => { - test("Belt_Set.eq", () => { +describe("JSON.Encode.float", () => { + test("JSON.Encode.float", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.Set.eq(s0, s1)->assertEqual(true) + JSON.Encode.float(42.0) } () }) }) -describe("Belt_Set.subset", () => { - test("Belt_Set.subset", () => { +describe("JSON.Encode.array", () => { + test("JSON.Encode.array", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) + let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) + JSON.Encode.array(array) } () }) }) -describe("Belt_Set.diff", () => { - test("Belt_Set.diff", () => { +describe("JSON.Decode.float", () => { + test("JSON.Decode.float", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - Belt.Set.diff(s0, s1) - ->Belt.Set.toArray - ->assertEqual([6]) + JSON.parseExn(`42.0`)->JSON.Decode.float + // Some(42.0) - Belt.Set.diff(s1, s0) - ->Belt.Set.toArray - ->assertEqual([1, 4]) + JSON.parseExn(`"hello world"`)->JSON.Decode.float + // None } () }) }) -describe("Belt_Set.intersect", () => { - test("Belt_Set.intersect", () => { +describe("JSON.Decode.array", () => { + test("JSON.Decode.array", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - let intersect = Belt.Set.intersect(s0, s1) + JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array + // Some([ 'foo', 'bar' ]) - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) + JSON.parseExn(`"hello world"`)->JSON.Decode.array + // None } () }) }) -describe("Belt_Set.union", () => { - test("Belt_Set.union", () => { +describe("Int.toExponential", () => { + test("Int.toExponential", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) - - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) + Int.toExponential(1000) // "1e+3" + Int.toExponential(-1000) // "-1e+3" + Int.toExponential(77, ~digits=2) // "7.70e+1" + Int.toExponential(5678, ~digits=2) // "5.68e+3" } () }) }) -describe("Belt_Set.removeMany", () => { - test("Belt_Set.removeMany", () => { +describe("Float.toPrecision", () => { + test("Float.toPrecision", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([]) + Float.toPrecision(100.0) // "100" + Float.toPrecision(1.0) // "1" + Float.toPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecision(1.0, ~digits=1) // "1" } () }) }) -describe("Belt_Set.remove", () => { - test("Belt_Set.remove", () => { +describe("Error.toException", () => { + test("Error.toException", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) + let error = Error.make("Something went wrong.") - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) + let asExn = error->Error.toException // `asExn` is now type `exn` } () }) }) -describe("Belt_Set.mergeMany", () => { - test("Belt_Set.mergeMany", () => { +describe("Date.makeWithYMDH", () => { + test("Date.makeWithYMDH", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 2023-02-20T16:00:00.000Z - let set = Belt.Set.make(~id=module(IntCmp)) + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 2023-02-21T00:00:00.000Z - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 2023-02-19T23:00:00.000Z - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_Set.add", () => { - test("Belt_Set.add", () => { +describe("Date.setFullYearM", () => { + test("Date.setFullYearM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) - - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) } () }) }) -describe("Belt_Set.has", () => { - test("Belt_Set.has", () => { +describe("Date.setHoursMSMs", () => { + test("Date.setHoursMSMs", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt_Set.isEmpty", () => { - test("Belt_Set.isEmpty", () => { +describe("Date.setSecondsMs", () => { + test("Date.setSecondsMs", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) - - Belt.Set.isEmpty(empty)->assertEqual(true) - Belt.Set.isEmpty(notEmpty)->assertEqual(false) + Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) } () }) }) -describe("Belt_Set.fromArray", () => { - test("Belt_Set.fromArray", () => { +describe("Date.setUTCHoursM", () => { + test("Date.setUTCHoursM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) } () }) }) -describe("Belt_Set.make", () => { - test("Belt_Set.make", () => { +describe("Date.toDateString", () => { + test("Date.toDateString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log + // Sun Jan 01 2023 - Belt.Set.isEmpty(set)->assertEqual(true) + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log + // Sat Dec 31 2022 } () }) }) -describe("Belt_SortArray.binarySearchBy", () => { - test("Belt_SortArray.binarySearchBy", () => { +describe("Date.toTimeString", () => { + test("Date.toTimeString", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log + // 00:00:00 GMT+0100 (Central European Standard Time) - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log + // 17:00:00 GMT+0100 (Central European Standard Time) } () }) }) -describe("Belt_SortArray.strictlySortedLength", () => { - test("Belt_SortArray.strictlySortedLength", () => { +describe("Dict.fromIterator", () => { + test("Dict.fromIterator", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + let iterator: Iterator.t<(string, int)> = %raw(` + (() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + iterator + ->Dict.fromIterator + ->Dict.valuesToArray + ->assertEqual([1, 2]) } () }) }) -describe("Belt_internalMapString.S.binarySearchBy", () => { - test("Belt_internalMapString.S.binarySearchBy", () => { +describe("Console.debugMany", () => { + test("Console.debugMany", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + Console.debugMany(["Hello", "World"]) + Console.debugMany([1, 2, 3]) } () }) }) -describe("Belt_internalMapString.S.strictlySortedLength", () => { - test("Belt_internalMapString.S.strictlySortedLength", () => { +describe("Console.errorMany", () => { + test("Console.errorMany", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + Console.errorMany(["Hello", "World"]) + Console.errorMany([1, 2, 3]) } () }) }) -describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { +describe("Belt_Set.Dict.has", () => { + test("Belt_Set.Dict.has", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.truncateToLengthUnsafe(arr, 3) + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - arr == ["ant", "bee", "cat"] + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_internalMapString.A.eq", () => { - test("Belt_internalMapString.A.eq", () => { +describe("Belt_Set.Dict.add", () => { + test("Belt_Set.Dict.add", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_internalMapString.A.cmp", () => { - test("Belt_internalMapString.A.cmp", () => { +describe("Belt_Set.Dict.get", () => { + test("Belt_Set.Dict.get", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ } () }) }) -describe("Belt_internalMapString.A.some2", () => { - test("Belt_internalMapString.A.some2", () => { - module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true +describe("Belt_SetDict.diff", () => { + test("Belt_SetDict.diff", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some2([], [1], (x, y) => x > y) == false + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Belt_internalMapString.A.every2", () => { - test("Belt_internalMapString.A.every2", () => { +describe("Belt_SetDict.some", () => { + test("Belt_SetDict.some", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - - Belt.Array.every2([], [1], (x, y) => x > y) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + let isOdd = x => mod(x, 2) != 0 - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("Belt_internalMapString.A.every", () => { - test("Belt_internalMapString.A.every", () => { +describe("Belt_SetDict.keep", () => { + test("Belt_SetDict.keep", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every([1, -3, 5], x => x > 0) == false + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_internalMapString.A.some", () => { - test("Belt_internalMapString.A.some", () => { +describe("Belt_SetDict.size", () => { + test("Belt_SetDict.size", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some([-1, -3, -5], x => x > 0) == false + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Belt_internalMapString.A.joinWith", () => { - test("Belt_internalMapString.A.joinWith", () => { +describe("Belt_Range.someBy", () => { + test("Belt_Range.someBy", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Belt_internalMapString.A.reduceWithIndex", () => { - test("Belt_internalMapString.A.reduceWithIndex", () => { +describe("Belt_Int.toString", () => { + test("Belt_Int.toString", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Belt.Int.toString(1)->assertEqual("1") } () }) }) -describe("Belt_internalMapString.A.reduceReverse2", () => { - test("Belt_internalMapString.A.reduceReverse2", () => { +describe("Belt_List.headExn", () => { + test("Belt_List.headExn", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapString.A.reduceReverse", () => { - test("Belt_internalMapString.A.reduceReverse", () => { +describe("Belt_List.tailExn", () => { + test("Belt_List.tailExn", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapString.A.reduce", () => { - test("Belt_internalMapString.A.reduce", () => { +describe("Belt_List.shuffle", () => { + test("Belt_List.shuffle", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Belt_internalMapString.A.partition", () => { - test("Belt_internalMapString.A.partition", () => { +describe("Belt_List.splitAt", () => { + test("Belt_List.splitAt", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Belt_internalMapString.A.mapWithIndex", () => { - test("Belt_internalMapString.A.mapWithIndex", () => { +describe("Belt_List.flatten", () => { + test("Belt_List.flatten", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("Belt_internalMapString.A.forEachWithIndex", () => { - test("Belt_internalMapString.A.forEachWithIndex", () => { +describe("Belt_List.toArray", () => { + test("Belt_List.toArray", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Belt_internalMapString.A.keepMap", () => { - test("Belt_internalMapString.A.keepMap", () => { +describe("Belt_List.reverse", () => { + test("Belt_List.reverse", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ } () }) }) -describe("Belt_internalMapString.A.keepWithIndex", () => { - test("Belt_internalMapString.A.keepWithIndex", () => { +describe("Belt_List.forEach", () => { + test("Belt_List.forEach", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("Belt_internalMapString.A.getIndexBy", () => { - test("Belt_internalMapString.A.getIndexBy", () => { +describe("Belt_List.reduce2", () => { + test("Belt_List.reduce2", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("Belt_internalMapString.A.getBy", () => { - test("Belt_internalMapString.A.getBy", () => { +describe("Belt_List.keepMap", () => { + test("Belt_List.keepMap", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ + + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ } () }) }) -describe("Belt_internalMapString.A.flatMap", () => { - test("Belt_internalMapString.A.flatMap", () => { +describe("Belt.Array.length", () => { + test("Belt.Array.length", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Belt_internalMapString.A.map", () => { - test("Belt_internalMapString.A.map", () => { +describe("Belt.Array.makeBy", () => { + test("Belt.Array.makeBy", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Belt_internalMapString.A.forEach", () => { - test("Belt_internalMapString.A.forEach", () => { +describe("Belt.Array.concat", () => { + test("Belt.Array.concat", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - total.contents == 1 + 2 + 3 + 4 + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Belt_internalMapString.A.blit", () => { - test("Belt_internalMapString.A.blit", () => { +describe("Belt.Array.reduce", () => { + test("Belt.Array.reduce", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Belt_internalMapString.A.fill", () => { - test("Belt_internalMapString.A.fill", () => { +describe("Belt.Array.every2", () => { + test("Belt.Array.every2", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + Belt.Array.every2([], [1], (x, y) => x > y) == true - arr == [0, 1, 9, 9, 4] + Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false } () }) }) -describe("Belt_internalMapString.A.sliceToEnd", () => { - test("Belt_internalMapString.A.sliceToEnd", () => { +describe("Belt.List.headExn", () => { + test("Belt.List.headExn", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapString.A.slice", () => { - test("Belt_internalMapString.A.slice", () => { +describe("Belt.List.tailExn", () => { + test("Belt.List.tailExn", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapString.A.concatMany", () => { - test("Belt_internalMapString.A.concatMany", () => { +describe("Belt.List.shuffle", () => { + test("Belt.List.shuffle", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Belt_internalMapString.A.concat", () => { - test("Belt_internalMapString.A.concat", () => { +describe("Belt.List.splitAt", () => { + test("Belt.List.splitAt", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Belt_internalMapString.A.unzip", () => { - test("Belt_internalMapString.A.unzip", () => { +describe("Belt.List.flatten", () => { + test("Belt.List.flatten", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("Belt_internalMapString.A.zipBy", () => { - test("Belt_internalMapString.A.zipBy", () => { +describe("Belt.List.toArray", () => { + test("Belt.List.toArray", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Belt_internalMapString.A.zip", () => { - test("Belt_internalMapString.A.zip", () => { +describe("Belt.List.reverse", () => { + test("Belt.List.reverse", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ } () }) }) -describe("Belt_internalMapString.A.makeBy", () => { - test("Belt_internalMapString.A.makeBy", () => { +describe("Belt.List.forEach", () => { + test("Belt.List.forEach", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("Belt_internalMapString.A.rangeBy", () => { - test("Belt_internalMapString.A.rangeBy", () => { +describe("Belt.List.reduce2", () => { + test("Belt.List.reduce2", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + } + () + }) +}) - Belt.Array.rangeBy(33, 0, ~step=-1) == [] +describe("Belt.List.keepMap", () => { + test("Belt.List.keepMap", () => { + module Test = { + let isEven = x => mod(x, 2) == 0 - Belt.Array.rangeBy(3, 12, ~step=-1) == [] + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ - Belt.Array.rangeBy(3, 3, ~step=0) == [] + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + } + () + }) +}) - Belt.Array.rangeBy(3, 3, ~step=1) == [3] +describe("Belt.Range.someBy", () => { + test("Belt.Range.someBy", () => { + module Test = { + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Belt_internalMapString.A.range", () => { - test("Belt_internalMapString.A.range", () => { +describe("Belt.HashMap.make", () => { + test("Belt.HashMap.make", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.Array.range(3, 0) == [] + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.Array.range(3, 3) == [3] + Belt.HashMap.set(hMap, 0, "a") } () }) }) -describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { +describe("Belt.HashMap.copy", () => { + test("Belt.HashMap.copy", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Js.log(Belt.Array.getExn(arr, 0)) // undefined + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) - Belt.Array.setExn(arr, 0, "example") + Belt.HashMap.set(s0, 2, "3") - Js.log(Belt.Array.getExn(arr, 0) == "example") + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) } () }) }) -describe("Belt_internalMapString.A.makeUninitialized", () => { - test("Belt_internalMapString.A.makeUninitialized", () => { +describe("Belt.HashMap.size", () => { + test("Belt.HashMap.size", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.Array.getExn(arr, 0) == Js.undefined + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.size(s0) == 2 } () }) }) -describe("Belt_internalMapString.A.reverse", () => { - test("Belt_internalMapString.A.reverse", () => { +describe("Belt.Int.toString", () => { + test("Belt.Int.toString", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + Belt.Int.toString(1)->assertEqual("1") } () }) }) -describe("Belt_internalMapString.A.reverseInPlace", () => { - test("Belt_internalMapString.A.reverseInPlace", () => { +describe("Belt.Set.Dict.has", () => { + test("Belt.Set.Dict.has", () => { module Test = { - let arr = [10, 11, 12, 13, 14] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let () = Belt.Array.reverseInPlace(arr) + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - arr == [14, 13, 12, 11, 10] + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_internalMapString.A.get", () => { - test("Belt_internalMapString.A.get", () => { +describe("Belt.Set.Dict.add", () => { + test("Belt.Set.Dict.add", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_internalMapString.A.length", () => { - test("Belt_internalMapString.A.length", () => { +describe("Belt.Set.Dict.get", () => { + test("Belt.Set.Dict.get", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + } + () + }) +}) + +describe("Belt_Array.length", () => { + test("Belt_Array.length", () => { module Test = { // Returns 1 Belt.Array.length(["test"]) @@ -9927,808 +9031,964 @@ describe("Belt_internalMapString.A.length", () => { }) }) -describe("BigInt.toLocaleString", () => { - test("BigInt.toLocaleString", () => { +describe("Belt_Array.makeBy", () => { + test("Belt_Array.makeBy", () => { module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("BigInt.toString", () => { - test("BigInt.toString", () => { +describe("Belt_Array.concat", () => { + test("Belt_Array.concat", () => { module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("BigInt.fromStringExn", () => { - test("BigInt.fromStringExn", () => { +describe("Belt_Array.reduce", () => { + test("Belt_Array.reduce", () => { module Test = { - /* returns 123n */ - BigInt.fromStringExn("123") + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - /* returns 0n */ - BigInt.fromStringExn("") + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + } + () + }) +}) - /* returns 17n */ - BigInt.fromStringExn("0x11") +describe("Belt_Array.every2", () => { + test("Belt_Array.every2", () => { + module Test = { + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - /* returns 3n */ - BigInt.fromStringExn("0b11") + Belt.Array.every2([], [1], (x, y) => x > y) == true - /* returns 9n */ - BigInt.fromStringExn("0o11") + Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true - /* catch exception */ - try { - BigInt.fromStringExn("a") - } catch { - | Exn.Error(_error) => 0n - } + Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false } () }) }) -describe("Belt_internalMapInt.S.binarySearchBy", () => { - test("Belt_internalMapInt.S.binarySearchBy", () => { +describe("Belt_HashMap.make", () => { + test("Belt_HashMap.make", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(hMap, 0, "a") } () }) }) -describe("Belt_internalMapInt.S.strictlySortedLength", () => { - test("Belt_internalMapInt.S.strictlySortedLength", () => { +describe("Belt_HashMap.copy", () => { + test("Belt_HashMap.copy", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + Belt.HashMap.set(s0, 2, "3") - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) } () }) }) -describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { +describe("Belt_HashMap.size", () => { + test("Belt_HashMap.size", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.Array.truncateToLengthUnsafe(arr, 3) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - arr == ["ant", "bee", "cat"] + Belt.HashMap.size(s0) == 2 } () }) }) -describe("Belt_internalMapInt.A.eq", () => { - test("Belt_internalMapInt.A.eq", () => { +describe("Array.unshiftMany", () => { + test("Array.unshiftMany", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + let someArray = ["hi", "hello"] + someArray->Array.unshiftMany(["yay", "wehoo"]) + someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) } () }) }) -describe("Belt_internalMapInt.A.cmp", () => { - test("Belt_internalMapInt.A.cmp", () => { +describe("Array.reduceRight", () => { + test("Array.reduceRight", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Array.reduceRight([], list{}, List.add)->assertEqual(list{}) } () }) }) -describe("Belt_internalMapInt.A.some2", () => { - test("Belt_internalMapInt.A.some2", () => { +describe("String.codePointAt", () => { + test("String.codePointAt", () => { module Test = { - 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 + String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) + String.codePointAt("abc", 5) == None } () }) }) -describe("Belt_internalMapInt.A.every2", () => { - test("Belt_internalMapInt.A.every2", () => { +describe("String.indexOfFrom", () => { + test("String.indexOfFrom", () => { module Test = { - 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 + String.indexOfFrom("bookseller", "ok", 1) == 2 + String.indexOfFrom("bookseller", "sell", 2) == 4 + String.indexOfFrom("bookseller", "sell", 5) == -1 } () }) }) -describe("Belt_internalMapInt.A.every", () => { - test("Belt_internalMapInt.A.every", () => { +describe("String.lastIndexOf", () => { + test("String.lastIndexOf", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false + String.lastIndexOf("bookseller", "ok") == 2 + String.lastIndexOf("beekeeper", "ee") == 4 + String.lastIndexOf("abcdefg", "xyz") == -1 } () }) }) -describe("Belt_internalMapInt.A.some", () => { - test("Belt_internalMapInt.A.some", () => { +describe("String.splitAtMost", () => { + test("String.splitAtMost", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ + "ant", + "bee", + "cat", + "dog", + "elk", + ] } () }) }) -describe("Belt_internalMapInt.A.joinWith", () => { - test("Belt_internalMapInt.A.joinWith", () => { +describe("String.toLowerCase", () => { + test("String.toLowerCase", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + String.toLowerCase("ABC") == "abc" + String.toLowerCase(`ΣΠ`) == `σπ` + String.toLowerCase(`ΠΣ`) == `πς` } () }) }) -describe("Belt_internalMapInt.A.reduceWithIndex", () => { - test("Belt_internalMapInt.A.reduceWithIndex", () => { +describe("String.toUpperCase", () => { + test("String.toUpperCase", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + String.toUpperCase("abc") == "ABC" + String.toUpperCase(`Straße`) == `STRASSE` + String.toUpperCase(`πς`) == `ΠΣ` } () }) }) -describe("Belt_internalMapInt.A.reduceReverse2", () => { - test("Belt_internalMapInt.A.reduceReverse2", () => { +describe("Promise.allSettled", () => { + test("Promise.allSettled", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + open Promise + + exception TestError(string) + + let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + + allSettled(promises) + ->then( + results => { + results->Array.forEach( + result => { + switch result { + | Fulfilled({value: num}) => Console.log2("Number: ", num) + | Rejected({reason}) => Console.log(reason) + } + }, + ) + + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalMapInt.A.reduceReverse", () => { - test("Belt_internalMapInt.A.reduceReverse", () => { +describe("Object.keysToArray", () => { + test("Object.keysToArray", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] + {"a": None}->Object.keysToArray // ["a"] + Object.make()->Object.keysToArray // [] } () }) }) -describe("Belt_internalMapInt.A.reduce", () => { - test("Belt_internalMapInt.A.reduce", () => { +describe("Nullable.undefined", () => { + test("Nullable.undefined", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Console.log(undefined) // Logs `undefined` to the console. } () }) }) -describe("Belt_internalMapInt.A.partition", () => { - test("Belt_internalMapInt.A.partition", () => { +describe("Nullable.getUnsafe", () => { + test("Nullable.getUnsafe", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + Nullable.getUnsafe(Nullable.make(3)) == 3 + Nullable.getUnsafe(Nullable.null) // Raises an error } () }) }) -describe("Belt_internalMapInt.A.mapWithIndex", () => { - test("Belt_internalMapInt.A.mapWithIndex", () => { +describe("List.reverseConcat", () => { + test("List.reverseConcat", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("Belt_internalMapInt.A.forEachWithIndex", () => { - test("Belt_internalMapInt.A.forEachWithIndex", () => { +describe("List.reduceReverse", () => { + test("List.reduceReverse", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) + list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) + list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} + } + () + }) +}) - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 +describe("List.compareLength", () => { + test("List.compareLength", () => { + module Test = { + List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. + + List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. + + List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. } () }) }) -describe("Belt_internalMapInt.A.keepMap", () => { - test("Belt_internalMapInt.A.keepMap", () => { +describe("Math.Constants.ln2", () => { + test("Math.Constants.ln2", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + Math.Constants.ln2 } () }) }) -describe("Belt_internalMapInt.A.keepWithIndex", () => { - test("Belt_internalMapInt.A.keepWithIndex", () => { +describe("Map.forEachWithKey", () => { + test("Map.forEachWithKey", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + map->Map.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) } () }) }) -describe("Belt_internalMapInt.A.getIndexBy", () => { - test("Belt_internalMapInt.A.getIndexBy", () => { +describe("JSON.Encode.string", () => { + test("JSON.Encode.string", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + JSON.Encode.string("hello world") } () }) }) -describe("Belt_internalMapInt.A.getBy", () => { - test("Belt_internalMapInt.A.getBy", () => { +describe("JSON.Encode.object", () => { + test("JSON.Encode.object", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ]) + + JSON.Encode.object(dict) } () }) }) -describe("Belt_internalMapInt.A.flatMap", () => { - test("Belt_internalMapInt.A.flatMap", () => { +describe("JSON.Decode.string", () => { + test("JSON.Decode.string", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + JSON.parseExn(`"hello world"`)->JSON.Decode.string + // Some("hello world") + + JSON.parseExn(`42`)->JSON.Decode.string + // None } () }) }) -describe("Belt_internalMapInt.A.map", () => { - test("Belt_internalMapInt.A.map", () => { +describe("JSON.Decode.object", () => { + test("JSON.Decode.object", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object + // Some({ foo: 'bar' }) + + JSON.parseExn(`"hello world"`)->JSON.Decode.object + // None } () }) }) -describe("Belt_internalMapInt.A.forEach", () => { - test("Belt_internalMapInt.A.forEach", () => { +describe("Int.toLocaleString", () => { + test("Int.toLocaleString", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + // If the application uses English as the default language + Int.toLocaleString(1000) // "1,000" - total.contents == 1 + 2 + 3 + 4 + // If the application uses Portuguese Brazil as the default language + Int.toLocaleString(1000) // "1.000" } () }) }) -describe("Belt_internalMapInt.A.blit", () => { - test("Belt_internalMapInt.A.blit", () => { +describe("Date.makeWithYMDHM", () => { + test("Date.makeWithYMDHM", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 2023-02-20T16:40:00.000Z - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 2023-02-20T17:00:00.000Z - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 2023-02-20T15:59:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_internalMapInt.A.fill", () => { - test("Belt_internalMapInt.A.fill", () => { +describe("Date.setFullYearMD", () => { + test("Date.setFullYearMD", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) } () }) }) -describe("Belt_internalMapInt.A.sliceToEnd", () => { - test("Belt_internalMapInt.A.sliceToEnd", () => { +describe("Date.setMinutesSMs", () => { + test("Date.setMinutesSMs", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt_internalMapInt.A.slice", () => { - test("Belt_internalMapInt.A.slice", () => { +describe("Date.getUTCMinutes", () => { + test("Date.getUTCMinutes", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 } () }) }) -describe("Belt_internalMapInt.A.concatMany", () => { - test("Belt_internalMapInt.A.concatMany", () => { +describe("Date.getUTCSeconds", () => { + test("Date.getUTCSeconds", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 } () }) }) -describe("Belt_internalMapInt.A.concat", () => { - test("Belt_internalMapInt.A.concat", () => { +describe("Date.setUTCHoursMS", () => { + test("Date.setUTCHoursMS", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( + ~hours=0, + ~minutes=0, + ~seconds=0, + ) } () }) }) -describe("Belt_internalMapInt.A.unzip", () => { - test("Belt_internalMapInt.A.unzip", () => { +describe("Date.setUTCMinutes", () => { + test("Date.setUTCMinutes", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) } () }) }) -describe("Belt_internalMapInt.A.zipBy", () => { - test("Belt_internalMapInt.A.zipBy", () => { +describe("Date.setUTCSeconds", () => { + test("Date.setUTCSeconds", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) } () }) }) -describe("Belt_internalMapInt.A.zip", () => { - test("Belt_internalMapInt.A.zip", () => { +describe("Dict.valuesToArray", () => { + test("Dict.valuesToArray", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let values = dict->Dict.valuesToArray + Console.log(values) // Logs `[1, 2]` to the console } () }) }) -describe("Belt_internalMapInt.A.makeBy", () => { - test("Belt_internalMapInt.A.makeBy", () => { +describe("Console.assertMany", () => { + test("Console.assertMany", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + let value = 42 + Console.assertMany(false, ["Hello", "World"]) + Console.assertMany(value == 42, [1, 2, 3]) } () }) }) -describe("Belt_internalMapInt.A.rangeBy", () => { - test("Belt_internalMapInt.A.rangeBy", () => { +describe("Console.countReset", () => { + test("Console.countReset", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + Console.countReset("rescript") } () }) }) -describe("Belt_internalMapInt.A.range", () => { - test("Belt_internalMapInt.A.range", () => { +describe("Belt_Set.fromArray", () => { + test("Belt_Set.fromArray", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.range(3, 0) == [] + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - Belt.Array.range(3, 3) == [3] + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { +describe("Belt_Set.mergeMany", () => { + test("Belt_Set.mergeMany", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Js.log(Belt.Array.getExn(arr, 0)) // undefined + let set = Belt.Set.make(~id=module(IntCmp)) - Belt.Array.setExn(arr, 0, "example") + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) - Js.log(Belt.Array.getExn(arr, 0) == "example") + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) } () }) }) -describe("Belt_internalMapInt.A.makeUninitialized", () => { - test("Belt_internalMapInt.A.makeUninitialized", () => { +describe("Belt_Set.intersect", () => { + test("Belt_Set.intersect", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.getExn(arr, 0) == Js.undefined + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + let intersect = Belt.Set.intersect(s0, s1) + + intersect + ->Belt.Set.toArray + ->assertEqual([2, 3, 5]) } () }) }) -describe("Belt_internalMapInt.A.reverse", () => { - test("Belt_internalMapInt.A.reverse", () => { +describe("Belt_Set.partition", () => { + test("Belt_Set.partition", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) + + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt_internalMapInt.A.reverseInPlace", () => { - test("Belt_internalMapInt.A.reverseInPlace", () => { +describe("Belt_Set.Dict.diff", () => { + test("Belt_Set.Dict.diff", () => { module Test = { - let arr = [10, 11, 12, 13, 14] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let () = Belt.Array.reverseInPlace(arr) + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - arr == [14, 13, 12, 11, 10] + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Belt_internalMapInt.A.get", () => { - test("Belt_internalMapInt.A.get", () => { +describe("Belt_Set.Dict.some", () => { + test("Belt_Set.Dict.some", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("Belt_internalMapInt.A.length", () => { - test("Belt_internalMapInt.A.length", () => { +describe("Belt_Set.Dict.keep", () => { + test("Belt_Set.Dict.keep", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { +describe("Belt_Set.Dict.size", () => { + test("Belt_Set.Dict.size", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.truncateToLengthUnsafe(arr, 3) + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - arr == ["ant", "bee", "cat"] + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Belt_internalSetInt.A.eq", () => { - test("Belt_internalSetInt.A.eq", () => { +describe("Belt_SetDict.empty", () => { + test("Belt_SetDict.empty", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + let s0 = Belt.Set.Dict.empty } () }) }) -describe("Belt_internalSetInt.A.cmp", () => { - test("Belt_internalSetInt.A.cmp", () => { +describe("Belt_SetDict.union", () => { + test("Belt_SetDict.union", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Belt_internalSetInt.A.some2", () => { - test("Belt_internalSetInt.A.some2", () => { +describe("Belt_SetDict.every", () => { + test("Belt_SetDict.every", () => { module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some2([], [1], (x, y) => x > y) == false + let isEven = x => mod(x, 2) == 0 - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Belt_internalSetInt.A.every2", () => { - test("Belt_internalSetInt.A.every2", () => { +describe("Belt_SetDict.split", () => { + test("Belt_SetDict.split", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every2([], [1], (x, y) => x > y) == true + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("Belt_internalSetInt.A.every", () => { - test("Belt_internalSetInt.A.every", () => { +describe("Belt_Result.getExn", () => { + test("Belt_Result.getExn", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) - Belt.Array.every([1, -3, 5], x => x > 0) == false + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalSetInt.A.some", () => { - test("Belt_internalSetInt.A.some", () => { +describe("Belt_Range.forEach", () => { + test("Belt_Range.forEach", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + Belt.Range.forEach(0, 4, i => Js.log(i)) - Belt.Array.some([-1, -3, -5], x => x > 0) == false + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 } () }) }) -describe("Belt_internalSetInt.A.joinWith", () => { - test("Belt_internalSetInt.A.joinWith", () => { +describe("Belt_Range.everyBy", () => { + test("Belt_Range.everyBy", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Belt_internalSetInt.A.reduceWithIndex", () => { - test("Belt_internalSetInt.A.reduceWithIndex", () => { +describe("Belt_Option.getExn", () => { + test("Belt_Option.getExn", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) + + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalSetInt.A.reduceReverse2", () => { - test("Belt_internalSetInt.A.reduceReverse2", () => { +describe("Belt_Option.orElse", () => { + test("Belt_Option.orElse", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None } () }) }) -describe("Belt_internalSetInt.A.reduceReverse", () => { - test("Belt_internalSetInt.A.reduceReverse", () => { +describe("Belt_Option.isSome", () => { + test("Belt_Option.isSome", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ } () }) }) -describe("Belt_internalSetInt.A.reduce", () => { - test("Belt_internalSetInt.A.reduce", () => { +describe("Belt_Option.isNone", () => { + test("Belt_Option.isNone", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + Belt.Option.isNone(None) /* true */ - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Belt.Option.isNone(Some(1)) /* false */ } () }) }) -describe("Belt_internalSetInt.A.partition", () => { - test("Belt_internalSetInt.A.partition", () => { +describe("Belt_MutableSet.eq", () => { + test("Belt_MutableSet.eq", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.MutableSet.eq(s0, s1) /* true */ } () }) }) -describe("Belt_internalSetInt.A.mapWithIndex", () => { - test("Belt_internalSetInt.A.mapWithIndex", () => { +describe("Belt_Map.fromArray", () => { + test("Belt_Map.fromArray", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt_internalSetInt.A.forEachWithIndex", () => { - test("Belt_internalSetInt.A.forEachWithIndex", () => { +describe("Belt_Int.fromFloat", () => { + test("Belt_Int.fromFloat", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) + Belt.Int.fromFloat(1.0)->assertEqual(1) + } + () + }) +}) + +describe("Belt_List.forEach2", () => { + test("Belt_List.forEach2", () => { + module Test = { + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) /* prints: - Item 0 is a - Item 1 is b - Item 2 is cc + "Z" "A" + "Y" "B" */ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Belt_internalSetInt.A.keepMap", () => { - test("Belt_internalSetInt.A.keepMap", () => { +describe("Belt_List.getAssoc", () => { + test("Belt_List.getAssoc", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ -describe("Belt_internalSetInt.A.keepWithIndex", () => { - test("Belt_internalSetInt.A.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ } () }) }) -describe("Belt_internalSetInt.A.getIndexBy", () => { - test("Belt_internalSetInt.A.getIndexBy", () => { +describe("Belt_List.hasAssoc", () => { + test("Belt_List.hasAssoc", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ } () }) }) -describe("Belt_internalSetInt.A.getBy", () => { - test("Belt_internalSetInt.A.getBy", () => { +describe("Belt_List.setAssoc", () => { + test("Belt_List.setAssoc", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ } () }) }) -describe("Belt_internalSetInt.A.flatMap", () => { - test("Belt_internalSetInt.A.flatMap", () => { +describe("Belt.Array.reverse", () => { + test("Belt.Array.reverse", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Belt_internalSetInt.A.map", () => { - test("Belt_internalSetInt.A.map", () => { +describe("Belt.Array.rangeBy", () => { + test("Belt.Array.rangeBy", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Belt_internalSetInt.A.forEach", () => { - test("Belt_internalSetInt.A.forEach", () => { +describe("Belt.Array.forEach", () => { + test("Belt.Array.forEach", () => { module Test = { Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) @@ -10748,406 +10008,487 @@ describe("Belt_internalSetInt.A.forEach", () => { }) }) -describe("Belt_internalSetInt.A.blit", () => { - test("Belt_internalSetInt.A.blit", () => { +describe("Belt.Array.flatMap", () => { + test("Belt.Array.flatMap", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Belt_internalSetInt.A.fill", () => { - test("Belt_internalSetInt.A.fill", () => { +describe("Belt.Array.keepMap", () => { + test("Belt.Array.keepMap", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Belt_internalSetInt.A.sliceToEnd", () => { - test("Belt_internalSetInt.A.sliceToEnd", () => { +describe("Belt.List.forEach2", () => { + test("Belt.List.forEach2", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + /* + prints: + "Z" "A" + "Y" "B" +*/ } () }) }) -describe("Belt_internalSetInt.A.slice", () => { - test("Belt_internalSetInt.A.slice", () => { +describe("Belt.List.getAssoc", () => { + test("Belt.List.getAssoc", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ } () }) }) -describe("Belt_internalSetInt.A.concatMany", () => { - test("Belt_internalSetInt.A.concatMany", () => { +describe("Belt.List.hasAssoc", () => { + test("Belt.List.hasAssoc", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ } () }) }) -describe("Belt_internalSetInt.A.concat", () => { - test("Belt_internalSetInt.A.concat", () => { +describe("Belt.List.setAssoc", () => { + test("Belt.List.setAssoc", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ } () }) }) -describe("Belt_internalSetInt.A.unzip", () => { - test("Belt_internalSetInt.A.unzip", () => { +describe("Belt.Range.forEach", () => { + test("Belt.Range.forEach", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + Belt.Range.forEach(0, 4, i => Js.log(i)) - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 } () }) }) -describe("Belt_internalSetInt.A.zipBy", () => { - test("Belt_internalSetInt.A.zipBy", () => { +describe("Belt.Range.everyBy", () => { + test("Belt.Range.everyBy", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Belt_internalSetInt.A.zip", () => { - test("Belt_internalSetInt.A.zip", () => { +describe("Belt.Set.fromArray", () => { + test("Belt.Set.fromArray", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Belt_internalSetInt.A.makeBy", () => { - test("Belt_internalSetInt.A.makeBy", () => { +describe("Belt.Set.mergeMany", () => { + test("Belt.Set.mergeMany", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + let set = Belt.Set.make(~id=module(IntCmp)) + + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) } () }) }) -describe("Belt_internalSetInt.A.rangeBy", () => { - test("Belt_internalSetInt.A.rangeBy", () => { +describe("Belt.Set.intersect", () => { + test("Belt.Set.intersect", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.Array.rangeBy(3, 3, ~step=0) == [] + let intersect = Belt.Set.intersect(s0, s1) - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + intersect + ->Belt.Set.toArray + ->assertEqual([2, 3, 5]) } () }) }) -describe("Belt_internalSetInt.A.range", () => { - test("Belt_internalSetInt.A.range", () => { +describe("Belt.Set.partition", () => { + test("Belt.Set.partition", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.range(3, 0) == [] + let isOdd = x => mod(x, 2) != 0 - Belt.Array.range(3, 3) == [3] + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) + + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { +describe("Belt.Map.fromArray", () => { + test("Belt.Map.fromArray", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Js.log(Belt.Array.getExn(arr, 0) == "example") + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt_internalSetInt.A.makeUninitialized", () => { - test("Belt_internalSetInt.A.makeUninitialized", () => { +describe("Belt.MutableSet.eq", () => { + test("Belt.MutableSet.eq", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.getExn(arr, 0) == Js.undefined + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.MutableSet.eq(s0, s1) /* true */ } () }) }) -describe("Belt_internalSetInt.A.reverse", () => { - test("Belt_internalSetInt.A.reverse", () => { +describe("Belt.HashMap.clear", () => { + test("Belt.HashMap.clear", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true } () }) }) -describe("Belt_internalSetInt.A.reverseInPlace", () => { - test("Belt_internalSetInt.A.reverseInPlace", () => { +describe("Belt.Option.getExn", () => { + test("Belt.Option.getExn", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) - arr == [14, 13, 12, 11, 10] + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalSetInt.A.get", () => { - test("Belt_internalSetInt.A.get", () => { +describe("Belt.Option.orElse", () => { + test("Belt.Option.orElse", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None } () }) }) -describe("Belt_internalSetInt.A.length", () => { - test("Belt_internalSetInt.A.length", () => { +describe("Belt.Option.isSome", () => { + test("Belt.Option.isSome", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ } () }) }) -describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { +describe("Belt.Option.isNone", () => { + test("Belt.Option.isNone", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) + Belt.Option.isNone(None) /* true */ - arr == ["ant", "bee", "cat"] + Belt.Option.isNone(Some(1)) /* false */ } () }) }) -describe("Belt_internalSetString.A.eq", () => { - test("Belt_internalSetString.A.eq", () => { +describe("Belt.Result.getExn", () => { + test("Belt.Result.getExn", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) + + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalSetString.A.cmp", () => { - test("Belt_internalSetString.A.cmp", () => { +describe("Belt.Int.fromFloat", () => { + test("Belt.Int.fromFloat", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Belt.Int.fromFloat(1.0)->assertEqual(1) } () }) }) -describe("Belt_internalSetString.A.some2", () => { - test("Belt_internalSetString.A.some2", () => { +describe("Belt.Float.fromInt", () => { + test("Belt.Float.fromInt", () => { module Test = { - 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 + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ } () }) }) -describe("Belt_internalSetString.A.every2", () => { - test("Belt_internalSetString.A.every2", () => { +describe("Belt.Set.Dict.diff", () => { + test("Belt.Set.Dict.diff", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every2([], [1], (x, y) => x > y) == true + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Belt_internalSetString.A.every", () => { - test("Belt_internalSetString.A.every", () => { +describe("Belt.Set.Dict.some", () => { + test("Belt.Set.Dict.some", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every([1, -3, 5], x => x > 0) == false + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("Belt_internalSetString.A.some", () => { - test("Belt_internalSetString.A.some", () => { +describe("Belt.Set.Dict.keep", () => { + test("Belt.Set.Dict.keep", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some([-1, -3, -5], x => x > 0) == false + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_internalSetString.A.joinWith", () => { - test("Belt_internalSetString.A.joinWith", () => { +describe("Belt.Set.Dict.size", () => { + test("Belt.Set.Dict.size", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Belt_internalSetString.A.reduceWithIndex", () => { - test("Belt_internalSetString.A.reduceWithIndex", () => { +describe("Belt_Float.fromInt", () => { + test("Belt_Float.fromInt", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ } () }) }) -describe("Belt_internalSetString.A.reduceReverse2", () => { - test("Belt_internalSetString.A.reduceReverse2", () => { +describe("Belt_Array.reverse", () => { + test("Belt_Array.reverse", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Belt_internalSetString.A.reduceReverse", () => { - test("Belt_internalSetString.A.reduceReverse", () => { +describe("Belt_Array.rangeBy", () => { + test("Belt_Array.rangeBy", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Belt_internalSetString.A.reduce", () => { - test("Belt_internalSetString.A.reduce", () => { +describe("Belt_Array.forEach", () => { + test("Belt_Array.forEach", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_internalSetString.A.partition", () => { - test("Belt_internalSetString.A.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) -describe("Belt_internalSetString.A.mapWithIndex", () => { - test("Belt_internalSetString.A.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Belt_internalSetString.A.forEachWithIndex", () => { - test("Belt_internalSetString.A.forEachWithIndex", () => { +describe("Belt_Array.flatMap", () => { + test("Belt_Array.flatMap", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Belt_internalSetString.A.keepMap", () => { - test("Belt_internalSetString.A.keepMap", () => { +describe("Belt_Array.keepMap", () => { + test("Belt_Array.keepMap", () => { module Test = { Belt.Array.keepMap( [1, 2, 3], @@ -11163,1042 +10504,1255 @@ describe("Belt_internalSetString.A.keepMap", () => { }) }) -describe("Belt_internalSetString.A.keepWithIndex", () => { - test("Belt_internalSetString.A.keepWithIndex", () => { +describe("Belt_HashMap.clear", () => { + test("Belt_HashMap.clear", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) -describe("Belt_internalSetString.A.getIndexBy", () => { - test("Belt_internalSetString.A.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true } () }) }) -describe("Belt_internalSetString.A.getBy", () => { - test("Belt_internalSetString.A.getBy", () => { +describe("AsyncIterator.make", () => { + test("AsyncIterator.make", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) + let context = ref(0) -describe("Belt_internalSetString.A.flatMap", () => { - test("Belt_internalSetString.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + { + AsyncIterator.value: Some(currentValue), + done: currentValue >= 3, + } + }, + ) + + // This will log 1, 2, 3 + let main = async () => + await asyncIterator->AsyncIterator.forEach( + value => + switch value { + | Some(value) => Console.log(value) + | None => () + }, + ) + + main()->ignore } () }) }) -describe("Belt_internalSetString.A.map", () => { - test("Belt_internalSetString.A.map", () => { +describe("AsyncIterator.done", () => { + test("AsyncIterator.done", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) } () }) }) -describe("Belt_internalSetString.A.forEach", () => { - test("Belt_internalSetString.A.forEach", () => { +describe("AsyncIterator.next", () => { + test("AsyncIterator.next", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) + map1.set('first', '1'); + map1.set('second', '2'); - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) + let processMyAsyncIterator = async () => { + // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. + let break = ref(false) -describe("Belt_internalSetString.A.blit", () => { - test("Belt_internalSetString.A.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + while !break.contents { + // Await the next iterator value + let {value, done} = await asyncIterator->AsyncIterator.next - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + // Exit the while loop if the iterator says it's done + break := done - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + if done { + value + ->Option.isNone + ->assertEqual(true) + } + } + } + + processMyAsyncIterator()->ignore } () }) }) -describe("Belt_internalSetString.A.fill", () => { - test("Belt_internalSetString.A.fill", () => { +describe("Array.fromIterator", () => { + test("Array.fromIterator", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + Map.fromArray([("foo", 1), ("bar", 2)]) + ->Map.values + ->Array.fromIterator + ->assertEqual([1, 2]) } () }) }) -describe("Belt_internalSetString.A.sliceToEnd", () => { - test("Belt_internalSetString.A.sliceToEnd", () => { +describe("Array.mapWithIndex", () => { + test("Array.mapWithIndex", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = + array->Array.mapWithIndex( + (greeting, index) => greeting ++ " at position " ++ Int.toString(index), + ) - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + assertEqual( + mappedArray, + ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], + ) } () }) }) -describe("Belt_internalSetString.A.slice", () => { - test("Belt_internalSetString.A.slice", () => { +describe("Array.findIndexOpt", () => { + test("Array.findIndexOpt", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + type languages = ReScript | TypeScript | JavaScript - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + let array = [ReScript, TypeScript, JavaScript] - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + array + ->Array.findIndexOpt(item => item == ReScript) + ->assertEqual(Some(0)) } () }) }) -describe("Belt_internalSetString.A.concatMany", () => { - test("Belt_internalSetString.A.concatMany", () => { +describe("String.fromCharCode", () => { + test("String.fromCharCode", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + String.fromCharCode(65) == "A" + String.fromCharCode(0x3c8) == `ψ` + String.fromCharCode(0xd55c) == `한` + String.fromCharCode(-64568) == `ψ` } () }) }) -describe("Belt_internalSetString.A.concat", () => { - test("Belt_internalSetString.A.concat", () => { +describe("String.endsWithFrom", () => { + test("String.endsWithFrom", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + String.endsWithFrom("abcd", "cd", 4) == true + String.endsWithFrom("abcde", "cd", 3) == false + String.endsWithFrom("abcde", "cde", 99) == true + String.endsWithFrom("example.dat", "ple", 7) == true } () }) }) -describe("Belt_internalSetString.A.unzip", () => { - test("Belt_internalSetString.A.unzip", () => { +describe("String.includesFrom", () => { + test("String.includesFrom", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + String.includesFrom("programmer", "gram", 1) == true + String.includesFrom("programmer", "gram", 4) == false + String.includesFrom(`대한민국`, `한`, 1) == true } () }) }) -describe("Belt_internalSetString.A.zipBy", () => { - test("Belt_internalSetString.A.zipBy", () => { +describe("RegExp.setLastIndex", () => { + test("RegExp.setLastIndex", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." -describe("Belt_internalSetString.A.zip", () => { - test("Belt_internalSetString.A.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + regexp->RegExp.setLastIndex(4) + regexp->RegExp.exec(someStr)->ignore + + Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console } () }) }) -describe("Belt_internalSetString.A.makeBy", () => { - test("Belt_internalSetString.A.makeBy", () => { +describe("RegExp.Result.input", () => { + test("RegExp.Result.input", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + // This below will log the full input string "ReScript is pretty cool, right?" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.input) + } } () }) }) -describe("Belt_internalSetString.A.rangeBy", () => { - test("Belt_internalSetString.A.rangeBy", () => { +describe("Promise.thenResolve", () => { + test("Promise.thenResolve", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + open Promise + resolve("Anna") + ->thenResolve( + str => { + "Hello " ++ str + }, + ) + ->thenResolve( + str => { + Console.log(str) + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Belt_internalSetString.A.range", () => { - test("Belt_internalSetString.A.range", () => { +describe("Object.isExtensible", () => { + test("Object.isExtensible", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] + let obj = {"a": 1} + obj->Object.isExtensible // true + obj->Object.preventExtensions->ignore + obj->Object.isExtensible // false } () }) }) -describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { +describe("Nullable.isNullable", () => { + test("Nullable.isNullable", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined + let myStr = "Hello" + let asNullable = myStr->Nullable.make - Belt.Array.setExn(arr, 0, "example") + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable - Js.log(Belt.Array.getExn(arr, 0) == "example") + // Check if asNullable is not null or undefined + switch asNullable->Nullable.isNullable { + | true => assert(false) + | false => assert(true) + } } () }) }) -describe("Belt_internalSetString.A.makeUninitialized", () => { - test("Belt_internalSetString.A.makeUninitialized", () => { +describe("Nullable.fromOption", () => { + test("Nullable.fromOption", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined + let optString = Some("Hello") + let asNullable = optString->Nullable.fromOption // Nullable.t } () }) }) -describe("Belt_internalSetString.A.reverse", () => { - test("Belt_internalSetString.A.reverse", () => { +describe("List.reduceReverse2", () => { + test("List.reduceReverse2", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) } () }) }) -describe("Belt_internalSetString.A.reverseInPlace", () => { - test("Belt_internalSetString.A.reverseInPlace", () => { +describe("Math.Constants.ln10", () => { + test("Math.Constants.ln10", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] + Math.Constants.ln10 } () }) }) -describe("Belt_internalSetString.A.get", () => { - test("Belt_internalSetString.A.get", () => { +describe("Float.toExponential", () => { + test("Float.toExponential", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + Float.toExponential(1000.0) // "1e+3" + Float.toExponential(-1000.0) // "-1e+3" + Float.toExponential(77.0, ~digits=2) // "7.70e+1" + Float.toExponential(5678.0, ~digits=2) // "5.68e+3" } () }) }) -describe("Belt_internalSetString.A.length", () => { - test("Belt_internalSetString.A.length", () => { +describe("Float.Constants.nan", () => { + test("Float.Constants.nan", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + Float.Constants.nan } () }) }) -describe("Console.warnMany", () => { - test("Console.warnMany", () => { +describe("Date.makeWithYMDHMS", () => { + test("Date.makeWithYMDHMS", () => { module Test = { - Console.warnMany(["Hello", "World"]) - Console.warnMany([1, 2, 3]) + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 2023-02-20T16:40:00.000Z + + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 2023-02-20T16:41:00.000Z + + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 2023-02-20T16:39:59.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Console.warn6", () => { - test("Console.warn6", () => { +describe("Date.getUTCFullYear", () => { + test("Date.getUTCFullYear", () => { module Test = { - Console.warn6("Hello", "World", "from", "JS", "!!!", '!') - Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 } () }) }) -describe("Console.warn5", () => { - test("Console.warn5", () => { +describe("Date.setUTCFullYear", () => { + test("Date.setUTCFullYear", () => { module Test = { - Console.warn5("Hello", "World", "from", "JS", "!!!") - Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) } () }) }) -describe("Console.warn4", () => { - test("Console.warn4", () => { +describe("Date.setUTCMinutesS", () => { + test("Date.setUTCMinutesS", () => { module Test = { - Console.warn4("Hello", "World", "ReScript", "!!!") - Console.warn4(#first, #second, #third, "fourth") + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) } () }) }) -describe("Console.warn3", () => { - test("Console.warn3", () => { +describe("Date.toLocaleString", () => { + test("Date.toLocaleString", () => { module Test = { - Console.warn3("Hello", "World", "ReScript") - Console.warn3([1, 2, 3], #4, #5) + Date.make()->Date.toLocaleString->Console.log + // 2/19/2023, 3:40:00 PM } () }) }) -describe("Console.warn2", () => { - test("Console.warn2", () => { +describe("Date.UTC.makeWithYM", () => { + test("Date.UTC.makeWithYM", () => { module Test = { - Console.warn2("Hello", "World") - Console.warn2([1, 2, 3], 4) + Date.UTC.makeWithYM(~year=2023, ~month=0) + // 1672531200000 + + Date.UTC.makeWithYM(~year=2023, ~month=11) + // 1701388800000 + + Date.UTC.makeWithYM(~year=2023, ~month=12) + // 1704067200000 + + Date.UTC.makeWithYM(~year=2023, ~month=-1) + // 1669852800000 } () }) }) -describe("Console.warn", () => { - test("Console.warn", () => { +describe("Dict.forEachWithKey", () => { + test("Dict.forEachWithKey", () => { module Test = { - Console.warn("Warning") - Console.warn(("Warning", "invalid number")) + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + + dict->Dict.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) } () }) }) -describe("Console.trace", () => { - test("Console.trace", () => { +describe("Belt_Set.removeMany", () => { + test("Belt_Set.removeMany", () => { module Test = { - let main = () => { - Console.trace() - } - main() - // In the console, the following trace will be displayed: - // main - // + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) } () }) }) -describe("Console.timeLog", () => { - test("Console.timeLog", () => { +describe("Belt_Set.Dict.empty", () => { + test("Belt_Set.Dict.empty", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + let s0 = Belt.Set.Dict.empty } () }) }) -describe("Console.timeEnd", () => { - test("Console.timeEnd", () => { +describe("Belt_Set.Dict.union", () => { + test("Belt_Set.Dict.union", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Console.time", () => { - test("Console.time", () => { +describe("Belt_Set.Dict.every", () => { + test("Belt_Set.Dict.every", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Console.table", () => { - test("Console.table", () => { +describe("Belt_Set.Dict.split", () => { + test("Belt_Set.Dict.split", () => { module Test = { - Console.table({"language": "rescript", "version": "10.1.2"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("Console.logMany", () => { - test("Console.logMany", () => { +describe("Belt_SetDict.remove", () => { + test("Belt_SetDict.remove", () => { module Test = { - Console.logMany(["Hello", "World"]) - Console.logMany([1, 2, 3]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Console.log6", () => { - test("Console.log6", () => { +describe("Belt_SetDict.subset", () => { + test("Belt_SetDict.subset", () => { module Test = { - Console.log6("Hello", "World", "JS", '!', '!', '?') - Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("Console.log5", () => { - test("Console.log5", () => { +describe("Belt_SetDict.reduce", () => { + test("Belt_SetDict.reduce", () => { module Test = { - Console.log5("Hello", "World", "JS", '!', '!') - Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Console.log4", () => { - test("Console.log4", () => { +describe("Belt_SetDict.toList", () => { + test("Belt_SetDict.toList", () => { module Test = { - Console.log4("Hello", "World", "ReScript", "!!!") - Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("Console.log3", () => { - test("Console.log3", () => { +describe("Belt_Result.flatMap", () => { + test("Belt_Result.flatMap", () => { module Test = { - Console.log3("Hello", "World", "ReScript") - Console.log3("One", 2, #3) + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Console.log2", () => { - test("Console.log2", () => { +describe("Belt_Option.forEach", () => { + test("Belt_Option.forEach", () => { module Test = { - Console.log2("Hello", "World") - Console.log2([1, 2, 3], '4') + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ } () }) }) -describe("Console.log", () => { - test("Console.log", () => { +describe("Belt_Option.flatMap", () => { + test("Belt_Option.flatMap", () => { module Test = { - Console.log("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.log(obj) + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ + + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ } () }) }) -describe("Console.infoMany", () => { - test("Console.infoMany", () => { +describe("Belt_MutableSet.has", () => { + test("Belt_MutableSet.has", () => { module Test = { - Console.infoMany(["Hello", "World"]) - Console.infoMany([1, 2, 3]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ } () }) }) -describe("Console.info6", () => { - test("Console.info6", () => { +describe("Belt_MutableSet.add", () => { + test("Belt_MutableSet.add", () => { module Test = { - Console.info6("Hello", "World", "from", "JS", "!!!", '!') - Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) + + s0->Belt.MutableSet.toArray /* [1, 2] */ } () }) }) -describe("Console.info5", () => { - test("Console.info5", () => { +describe("Belt_MutableSet.get", () => { + test("Belt_MutableSet.get", () => { module Test = { - Console.info5("Hello", "World", "from", "JS", "!!!") - Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ } () }) }) -describe("Console.info4", () => { - test("Console.info4", () => { +describe("Belt_Int.fromString", () => { + test("Belt_Int.fromString", () => { module Test = { - Console.info4("Hello", "World", "ReScript", '!') - Console.info4([1, 2, 3], #4, #5, #lastinfo) + Belt.Int.fromString("1")->assertEqual(Some(1)) } () }) }) -describe("Console.info3", () => { - test("Console.info3", () => { +describe("Belt_List.fromArray", () => { + test("Belt_List.fromArray", () => { module Test = { - Console.info3("Hello", "World", "ReScript") - Console.info3([1, 2, 3], #4, #5) + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} } () }) }) -describe("Console.info2", () => { - test("Console.info2", () => { +describe("Belt_List.partition", () => { + test("Belt_List.partition", () => { module Test = { - Console.info2("Info", "failed to download") - Console.info2(#info, {"name": "ReScript"}) + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) } () }) }) -describe("Console.info", () => { - test("Console.info", () => { +describe("Belt.Array.joinWith", () => { + test("Belt.Array.joinWith", () => { module Test = { - Console.info("Information") - Console.info(("Hello", "JS")) + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Console.errorMany", () => { - test("Console.errorMany", () => { +describe("Belt.List.fromArray", () => { + test("Belt.List.fromArray", () => { module Test = { - Console.errorMany(["Hello", "World"]) - Console.errorMany([1, 2, 3]) + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} } () }) }) -describe("Console.group", () => { - test("Console.group", () => { +describe("Belt.List.partition", () => { + test("Belt.List.partition", () => { module Test = { - 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() + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) } () }) }) -describe("Console.error6", () => { - test("Console.error6", () => { +describe("Belt.Set.removeMany", () => { + test("Belt.Set.removeMany", () => { module Test = { - Console.error6("Hello", "World", "from", "JS", "!!!", '!') - Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) } () }) }) -describe("Console.error5", () => { - test("Console.error5", () => { +describe("Belt.MutableSet.has", () => { + test("Belt.MutableSet.has", () => { module Test = { - Console.error5('e', 'r', 'r', 'o', 'r') - Console.error5(1, #second, #third, "fourth", 'c') + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ } () }) }) -describe("Console.error4", () => { - test("Console.error4", () => { +describe("Belt.MutableSet.add", () => { + test("Belt.MutableSet.add", () => { module Test = { - Console.error4("Hello", "World", "ReScript", '!') - Console.error4(#first, #second, #third, "fourth") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) + + s0->Belt.MutableSet.toArray /* [1, 2] */ } () }) }) -describe("Console.error3", () => { - test("Console.error3", () => { +describe("Belt.MutableSet.get", () => { + test("Belt.MutableSet.get", () => { module Test = { - Console.error3("Hello", "World", "!!!") - Console.error3(#first, #second, #third) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ } () }) }) -describe("Console.error2", () => { - test("Console.error2", () => { +describe("Belt.HashMap.remove", () => { + test("Belt.HashMap.remove", () => { module Test = { - Console.error2("Error", "here") - Console.error2(("log", "error"), "message") + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false } () }) }) -describe("Console.error", () => { - test("Console.error", () => { +describe("Belt.HashMap.reduce", () => { + test("Belt.HashMap.reduce", () => { module Test = { - Console.error("error message") - Console.error(("error", "invalid value")) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") } () }) }) -describe("Console.dir", () => { - test("Console.dir", () => { +describe("Belt.Option.forEach", () => { + test("Belt.Option.forEach", () => { module Test = { - Console.dir({"language": "rescript", "version": "10.1.2"}) + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ } () }) }) -describe("Console.debugMany", () => { - test("Console.debugMany", () => { +describe("Belt.Option.flatMap", () => { + test("Belt.Option.flatMap", () => { module Test = { - Console.debugMany(["Hello", "World"]) - Console.debugMany([1, 2, 3]) + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ + + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ } () }) }) -describe("Console.debug6", () => { - test("Console.debug6", () => { +describe("Belt.Result.flatMap", () => { + test("Belt.Result.flatMap", () => { module Test = { - Console.debug6("Hello", "World", "JS", '!', '!', '?') - Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Console.debug5", () => { - test("Console.debug5", () => { +describe("Belt.Int.fromString", () => { + test("Belt.Int.fromString", () => { module Test = { - Console.debug5("Hello", "World", "JS", '!', '!') - Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + Belt.Int.fromString("1")->assertEqual(Some(1)) } () }) }) -describe("Console.debug4", () => { - test("Console.debug4", () => { +describe("Belt.Float.toString", () => { + test("Belt.Float.toString", () => { module Test = { - Console.debug4("Hello", "World", "ReScript", "!!!") - Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ } () }) }) -describe("Console.debug3", () => { - test("Console.debug3", () => { +describe("Belt.Set.Dict.empty", () => { + test("Belt.Set.Dict.empty", () => { module Test = { - Console.debug3("Hello", "World", "ReScript") - Console.debug3("One", 2, #3) + let s0 = Belt.Set.Dict.empty } () }) }) -describe("Console.debug2", () => { - test("Console.debug2", () => { +describe("Belt.Set.Dict.union", () => { + test("Belt.Set.Dict.union", () => { module Test = { - Console.debug2("Hello", "World") - Console.debug2([1, 2, 3], '4') + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Console.debug", () => { - test("Console.debug", () => { +describe("Belt.Set.Dict.every", () => { + test("Belt.Set.Dict.every", () => { module Test = { - Console.debug("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.debug(obj) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Console.countReset", () => { - test("Console.countReset", () => { +describe("Belt.Set.Dict.split", () => { + test("Belt.Set.Dict.split", () => { module Test = { - Console.countReset("rescript") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("Console.count", () => { - test("Console.count", () => { +describe("Belt_Float.toString", () => { + test("Belt_Float.toString", () => { module Test = { - Console.count("rescript") + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ } () }) }) -describe("Console.clear", () => { - test("Console.clear", () => { +describe("Belt_Array.joinWith", () => { + test("Belt_Array.joinWith", () => { module Test = { - Console.clear() + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Console.assertMany", () => { - test("Console.assertMany", () => { +describe("Belt_HashMap.remove", () => { + test("Belt_HashMap.remove", () => { module Test = { - let value = 42 - Console.assertMany(false, ["Hello", "World"]) - Console.assertMany(value == 42, [1, 2, 3]) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false } () }) }) -describe("Console.assert6", () => { - test("Console.assert6", () => { +describe("Belt_HashMap.reduce", () => { + test("Belt_HashMap.reduce", () => { module Test = { - let value = 42 - Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') - Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) -describe("Console.assert5", () => { - test("Console.assert5", () => { - module Test = { - let value = 42 - Console.assert5(false, "Hello", "World", "JS", '!', '!') - Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) -describe("Console.assert4", () => { - test("Console.assert4", () => { - module Test = { - let value = 42 - Console.assert4(false, "Hello", "World", "ReScript", "!!!") - Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) - } - () - }) -}) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") -describe("Console.assert3", () => { - test("Console.assert3", () => { - module Test = { - Console.assert3(false, "Hello", "World", "ReScript") - Console.assert3(42 == 42, "One", 2, #3) + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") } () }) }) -describe("Console.assert2", () => { - test("Console.assert2", () => { +describe("AsyncIterator.value", () => { + test("AsyncIterator.value", () => { module Test = { - Console.assert2(false, "Hello", "World") - Console.assert2(42 == 42, [1, 2, 3], '4') + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) } () }) }) -describe("Console.assert_", () => { - test("Console.assert_", () => { +describe("Array.findWithIndex", () => { + test("Array.findWithIndex", () => { module Test = { - Console.assert_(false, "Hello World!") - Console.assert_(42 == 42, "The answer") + type languages = ReScript | TypeScript | JavaScript + + let array = [TypeScript, JavaScript, ReScript] + + array + ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) + ->assertEqual(Some(ReScript)) } () }) }) -describe("Dict.mapValues", () => { - test("Dict.mapValues", () => { +describe("Array.someWithIndex", () => { + test("Array.someWithIndex", () => { module Test = { - let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) + let array = ["Hello", "Hi", "Good bye"] - dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] - dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] + array + ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) + ->assertEqual(true) } () }) }) -describe("Dict.forEachWithKey", () => { - test("Dict.forEachWithKey", () => { +describe("String.fromCodePoint", () => { + test("String.fromCodePoint", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - - dict->Dict.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) + String.fromCodePoint(65) == "A" + String.fromCodePoint(0x3c8) == `ψ` + String.fromCodePoint(0xd55c) == `한` + String.fromCodePoint(0x1f63a) == `😺` } () }) }) -describe("Dict.forEach", () => { - test("Dict.forEach", () => { +describe("String.normalizeForm", () => { + test("String.normalizeForm", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let string1 = "\uFB00" + let string2 = "\u0066\u0066" + Console.log(string1 == string2) // false - dict->Dict.forEach( - value => { - Console.log(value) - }, - ) + let normalizeString1 = String.normalizeByForm(string1, #NFKD) + let normalizeString2 = String.normalizeByForm(string2, #NFKD) + Console.log(normalizeString1 == normalizeString2) // true } () }) }) -describe("Dict.copy", () => { - test("Dict.copy", () => { +describe("String.replaceRegExp", () => { + test("String.replaceRegExp", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let dict2 = dict->Dict.copy - - // Both log `["key1", "key2"]` here. - Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) + String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" } () }) }) -describe("Dict.assign", () => { - test("Dict.assign", () => { +describe("String.splitByRegExp", () => { + test("String.splitByRegExp", () => { module Test = { - let dict1 = Dict.make() - dict1->Dict.set("firstKey", 1) - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` - - let dict2 = Dict.make() - dict2->Dict.set("someKey", 2) - dict2->Dict.set("someKey2", 3) - - let dict1 = dict1->Dict.assign(dict2) - - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` + String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] } () }) }) -describe("Dict.valuesToArray", () => { - test("Dict.valuesToArray", () => { +describe("String.localeCompare", () => { + test("String.localeCompare", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let values = dict->Dict.valuesToArray - Console.log(values) // Logs `[1, 2]` to the console + String.localeCompare("a", "c") < 0.0 == true + String.localeCompare("a", "a") == 0.0 } () }) }) -describe("Dict.keysToArray", () => { - test("Dict.keysToArray", () => { +describe("Pervasives.encodeURI", () => { + test("Pervasives.encodeURI", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let keys = dict->Dict.keysToArray - Console.log(keys) // Logs `["someKey", "someKey2"]` to the console + Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) + // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. } () }) }) -describe("Dict.toArray", () => { - test("Dict.toArray", () => { +describe("Pervasives.decodeURI", () => { + test("Pervasives.decodeURI", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let asArray = dict->Dict.toArray - Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console + Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) + // Logs "https://rescript-lang.org?array=[someValue]" to the console. } () }) }) -describe("Dict.fromIterator", () => { - test("Dict.fromIterator", () => { +describe("List.fromInitializer", () => { + test("List.fromInitializer", () => { module Test = { - let iterator: Iterator.t<(string, int)> = %raw(` - (() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - iterator - ->Dict.fromIterator - ->Dict.valuesToArray - ->assertEqual([1, 2]) + List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} + + List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} } () }) }) -describe("Dict.fromArray", () => { - test("Dict.fromArray", () => { +describe("List.reduceWithIndex", () => { + test("List.reduceWithIndex", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 } () }) }) -describe("Dict.make", () => { - test("Dict.make", () => { +describe("List.filterWithIndex", () => { + test("List.filterWithIndex", () => { module Test = { - let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want + let isEven = x => mod(x, 2) == 0 - let dict2 = Dict.make() // Or you can let ReScript infer it via usage. - dict2->Dict.set("someKey", 12) + List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} } () }) }) -describe("Dict.delete", () => { - test("Dict.delete", () => { +describe("Math.Constants.log2e", () => { + test("Math.Constants.log2e", () => { module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - dict->Dict.delete("someKey") + Math.Constants.log2e } () }) }) -describe("Dict.set", () => { - test("Dict.set", () => { +describe("Math.Constants.sqrt2", () => { + test("Math.Constants.sqrt2", () => { module Test = { - let dict = Dict.make() - - dict->Dict.set("someKey", "someValue") + Math.Constants.sqrt2 } () }) }) -describe("Dict.get", () => { - test("Dict.get", () => { +describe("Int.rangeWithOptions", () => { + test("Int.rangeWithOptions", () => { module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - switch dict->Dict.get("someKey") { - | None => Console.log("Nope, didn't have the key.") - | Some(value) => Console.log(value) - } + Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] + Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] + Int.rangeWithOptions(3, 6, {step: -2}) // RangeError } () }) }) -describe("Dict.getUnsafe", () => { - test("Dict.getUnsafe", () => { +describe("Float.toLocaleString", () => { + test("Float.toLocaleString", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let value = dict->Dict.getUnsafe("key1") - Console.log(value) // value1 + // If the application uses English as the default language + Float.toLocaleString(1000.0) // "1,000" + + // If the application uses Portuguese Brazil as the default language + Float.toLocaleString(1000.0) // "1.000" } () }) }) -describe("Date.UTC.makeWithYMDHMSM", () => { - test("Date.UTC.makeWithYMDHMSM", () => { +describe("Date.makeWithYMDHMSM", () => { + test("Date.makeWithYMDHMSM", () => { module Test = { - Date.UTC.makeWithYMDHMSM( + Date.makeWithYMDHMSM( ~year=2023, ~month=1, ~date=20, @@ -12206,10 +11760,10 @@ describe("Date.UTC.makeWithYMDHMSM", () => { ~minutes=40, ~seconds=0, ~milliseconds=0, - )->Console.log - // 1676911200000 + ) + // 2023-02-20T16:40:00.000Z - Date.UTC.makeWithYMDHMSM( + Date.makeWithYMDHMSM( ~year=2023, ~month=1, ~date=20, @@ -12217,10 +11771,10 @@ describe("Date.UTC.makeWithYMDHMSM", () => { ~minutes=40, ~seconds=0, ~milliseconds=1000, - )->Console.log - // 1676911201000 + ) + // 2023-02-20T16:40:01.000Z - Date.UTC.makeWithYMDHMSM( + Date.makeWithYMDHMSM( ~year=2023, ~month=1, ~date=20, @@ -12228,56 +11782,62 @@ describe("Date.UTC.makeWithYMDHMSM", () => { ~minutes=40, ~seconds=0, ~milliseconds=-1, - )->Console.log - // 1676911199999 + ) + // 2023-02-20T16:39:59.999Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Date.UTC.makeWithYMDHMS", () => { - test("Date.UTC.makeWithYMDHMS", () => { +describe("Date.getMilliseconds", () => { + test("Date.getMilliseconds", () => { module Test = { - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 1676911200000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 1676911260000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 1676911199000 + Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds + // 0 } () }) }) -describe("Date.UTC.makeWithYMDHM", () => { - test("Date.UTC.makeWithYMDHM", () => { +describe("Date.setMilliseconds", () => { + test("Date.setMilliseconds", () => { module Test = { - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 1676911200000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 1676912400000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 1676908740000 + Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) } () }) }) -describe("Date.UTC.makeWithYMDH", () => { - test("Date.UTC.makeWithYMDH", () => { +describe("Date.setUTCFullYearM", () => { + test("Date.setUTCFullYearM", () => { module Test = { - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 1676908800000 + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) + } + () + }) +}) - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 1676937600000 +describe("Date.setUTCHoursMSMs", () => { + test("Date.setUTCHoursMSMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) + } + () + }) +}) - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 1676847600000 +describe("Date.setUTCSecondsMs", () => { + test("Date.setUTCSecondsMs", () => { + module Test = { + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) } () }) @@ -12299,4030 +11859,4627 @@ describe("Date.UTC.makeWithYMD", () => { }) }) -describe("Date.UTC.makeWithYM", () => { - test("Date.UTC.makeWithYM", () => { +describe("BigInt.fromStringExn", () => { + test("BigInt.fromStringExn", () => { module Test = { - Date.UTC.makeWithYM(~year=2023, ~month=0) - // 1672531200000 + /* returns 123n */ + BigInt.fromStringExn("123") - Date.UTC.makeWithYM(~year=2023, ~month=11) - // 1701388800000 + /* returns 0n */ + BigInt.fromStringExn("") - Date.UTC.makeWithYM(~year=2023, ~month=12) - // 1704067200000 + /* returns 17n */ + BigInt.fromStringExn("0x11") - Date.UTC.makeWithYM(~year=2023, ~month=-1) - // 1669852800000 - } - () - }) -}) + /* returns 3n */ + BigInt.fromStringExn("0b11") -describe("Date.toJSON", () => { - test("Date.toJSON", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON - // Some("2023-01-01T00:00:00.000Z") + /* returns 9n */ + BigInt.fromStringExn("0o11") - Date.fromString("")->Date.toJSON - // None + /* catch exception */ + try { + BigInt.fromStringExn("a") + } catch { + | Exn.Error(_error) => 0n + } } () }) }) -describe("Date.toUTCString", () => { - test("Date.toUTCString", () => { +describe("Belt_Set.Dict.remove", () => { + test("Belt_Set.Dict.remove", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log - // Sun, 01 Jan 2023 00:00:00 GMT + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log - // Sat, 31 Dec 2022 16:00:00 GMT + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Date.toISOString", () => { - test("Date.toISOString", () => { +describe("Belt_Set.Dict.subset", () => { + test("Belt_Set.Dict.subset", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log - // 2023-01-01T00:00:00.000Z + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log - // 2022-12-31T16:00:00.000Z + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { +describe("Belt_Set.Dict.reduce", () => { + test("Belt_Set.Dict.reduce", () => { module Test = { - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) - ->Console.log - // 3:40:00 PM GMT+1 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 15:40 + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Date.toLocaleTimeStringWithLocale", () => { - test("Date.toLocaleTimeStringWithLocale", () => { +describe("Belt_Set.Dict.toList", () => { + test("Belt_Set.Dict.toList", () => { module Test = { - Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log - // 3:40:00 PM + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("Date.toLocaleTimeString", () => { - test("Date.toLocaleTimeString", () => { +describe("Belt_SetDict.isEmpty", () => { + test("Belt_SetDict.isEmpty", () => { module Test = { - Date.make()->Date.toLocaleTimeString->Console.log - // 3:40:00 PM + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("Date.toLocaleStringWithLocaleAndOptions", () => { - test("Date.toLocaleStringWithLocaleAndOptions", () => { +describe("Belt_SetDict.forEach", () => { + test("Belt_SetDict.forEach", () => { module Test = { - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) - ->Console.log - // 2/19/23, 3:40 PM + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions( - "en", - { - era: #long, - year: #numeric, - month: #"2-digit", - day: #"2-digit", - hour: #numeric, - timeZoneName: #short, - }, - ) - ->Console.log - // 02/19/2023 Anno Domini, 3 PM GMT+1 + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Date.toLocaleStringWithLocale", () => { - test("Date.toLocaleStringWithLocale", () => { +describe("Belt_SetDict.toArray", () => { + test("Belt_SetDict.toArray", () => { module Test = { - Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log - // 2/19/2023, 3:40:00 PM + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("Date.toLocaleString", () => { - test("Date.toLocaleString", () => { +describe("Belt_SetDict.minimum", () => { + test("Belt_SetDict.minimum", () => { module Test = { - Date.make()->Date.toLocaleString->Console.log - // 2/19/2023, 3:40:00 PM + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { - test("Date.toLocaleDateStringWithLocaleAndOptions", () => { +describe("Belt_SetDict.maximum", () => { + test("Belt_SetDict.maximum", () => { module Test = { - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) - ->Console.log - // February 19, 2023 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 19.2.2023, 15:40 + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log - // 2023 + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("Date.toLocaleDateStringWithLocale", () => { - test("Date.toLocaleDateStringWithLocale", () => { +describe("Belt_MutableSet.copy", () => { + test("Belt_MutableSet.copy", () => { module Test = { - Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log - // 2/19/2023 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Date.toLocaleDateString", () => { - test("Date.toLocaleDateString", () => { +describe("Belt_MutableSet.diff", () => { + test("Belt_MutableSet.diff", () => { module Test = { - Date.make()->Date.toLocaleDateString->Console.log - // 2/19/2023 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ } () }) }) -describe("Date.toTimeString", () => { - test("Date.toTimeString", () => { +describe("Belt_MutableSet.some", () => { + test("Belt_MutableSet.some", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log - // 00:00:00 GMT+0100 (Central European Standard Time) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log - // 17:00:00 GMT+0100 (Central European Standard Time) + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ } () }) }) -describe("Date.toString", () => { - test("Date.toString", () => { +describe("Belt_MutableSet.keep", () => { + test("Belt_MutableSet.keep", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log - // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log - // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ } () }) }) -describe("Date.toDateString", () => { - test("Date.toDateString", () => { +describe("Belt_MutableSet.size", () => { + test("Belt_MutableSet.size", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log - // Sun Jan 01 2023 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log - // Sat Dec 31 2022 + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.size /* 4 */ } () }) }) -describe("Date.setUTCMilliseconds", () => { - test("Date.setUTCMilliseconds", () => { +describe("Belt_Map.findFirstBy", () => { + test("Belt_Map.findFirstBy", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) } () }) }) -describe("Date.setUTCSecondsMs", () => { - test("Date.setUTCSecondsMs", () => { +describe("Belt_Map.keysToArray", () => { + test("Belt_Map.keysToArray", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] } () }) }) -describe("Date.setUTCSeconds", () => { - test("Date.setUTCSeconds", () => { +describe("Belt_List.concatMany", () => { + test("Belt_List.concatMany", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Date.setUTCMinutesSMs", () => { - test("Date.setUTCMinutesSMs", () => { +describe("Belt_List.mapReverse", () => { + test("Belt_List.mapReverse", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) } () }) }) -describe("Date.setUTCMinutesS", () => { - test("Date.setUTCMinutesS", () => { +describe("Belt.Array.partition", () => { + test("Belt.Array.partition", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Date.setUTCMinutes", () => { - test("Date.setUTCMinutes", () => { +describe("Belt.List.concatMany", () => { + test("Belt.List.concatMany", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Date.setUTCHoursMSMs", () => { - test("Date.setUTCHoursMSMs", () => { +describe("Belt.List.mapReverse", () => { + test("Belt.List.mapReverse", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) } () }) }) -describe("Date.setUTCHoursMS", () => { - test("Date.setUTCHoursMS", () => { +describe("Belt.Map.findFirstBy", () => { + test("Belt.Map.findFirstBy", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( - ~hours=0, - ~minutes=0, - ~seconds=0, - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) } () }) }) -describe("Date.setUTCHoursM", () => { - test("Date.setUTCHoursM", () => { +describe("Belt.Map.keysToArray", () => { + test("Belt.Map.keysToArray", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] } () }) }) -describe("Date.setUTCHours", () => { - test("Date.setUTCHours", () => { +describe("Belt.MutableSet.copy", () => { + test("Belt.MutableSet.copy", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Date.setUTCDate", () => { - test("Date.setUTCDate", () => { +describe("Belt.MutableSet.diff", () => { + test("Belt.MutableSet.diff", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ } () }) }) -describe("Date.setUTCMonth", () => { - test("Date.setUTCMonth", () => { +describe("Belt.MutableSet.some", () => { + test("Belt.MutableSet.some", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ + } () }) }) -describe("Date.setUTCFullYearMD", () => { - test("Date.setUTCFullYearMD", () => { +describe("Belt.MutableSet.keep", () => { + test("Belt.MutableSet.keep", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( - ~year=2024, - ~month=0, - ~date=1, - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ } () }) }) -describe("Date.setUTCFullYearM", () => { - test("Date.setUTCFullYearM", () => { +describe("Belt.MutableSet.size", () => { + test("Belt.MutableSet.size", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.size /* 4 */ } () }) }) -describe("Date.setUTCFullYear", () => { - test("Date.setUTCFullYear", () => { +describe("Belt.HashMap.isEmpty", () => { + test("Belt.HashMap.isEmpty", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false } () }) }) -describe("Date.getUTCDay", () => { - test("Date.getUTCDay", () => { +describe("Belt.HashMap.forEach", () => { + test("Belt.HashMap.forEach", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") } () }) }) -describe("Date.getUTCMilliseconds", () => { - test("Date.getUTCMilliseconds", () => { +describe("Belt.HashMap.toArray", () => { + test("Belt.HashMap.toArray", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Date.getUTCSeconds", () => { - test("Date.getUTCSeconds", () => { +describe("Belt.Set.Dict.remove", () => { + test("Belt.Set.Dict.remove", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Date.getUTCMinutes", () => { - test("Date.getUTCMinutes", () => { +describe("Belt.Set.Dict.subset", () => { + test("Belt.Set.Dict.subset", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("Date.getUTCHours", () => { - test("Date.getUTCHours", () => { +describe("Belt.Set.Dict.reduce", () => { + test("Belt.Set.Dict.reduce", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Date.getUTCDate", () => { - test("Date.getUTCDate", () => { +describe("Belt.Set.Dict.toList", () => { + test("Belt.Set.Dict.toList", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("Date.getUTCMonth", () => { - test("Date.getUTCMonth", () => { +describe("Belt_Array.partition", () => { + test("Belt_Array.partition", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Date.getUTCFullYear", () => { - test("Date.getUTCFullYear", () => { +describe("Belt_HashMap.isEmpty", () => { + test("Belt_HashMap.isEmpty", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false } () }) }) -describe("Date.setMilliseconds", () => { - test("Date.setMilliseconds", () => { +describe("Belt_HashMap.forEach", () => { + test("Belt_HashMap.forEach", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") } () }) }) -describe("Date.setSecondsMs", () => { - test("Date.setSecondsMs", () => { +describe("Belt_HashMap.toArray", () => { + test("Belt_HashMap.toArray", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Date.setSeconds", () => { - test("Date.setSeconds", () => { +describe("Array.joinWithUnsafe", () => { + test("Array.joinWithUnsafe", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) + [1, 2, 3] + ->Array.joinWithUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") } () }) }) -describe("Date.setMinutesSMs", () => { - test("Date.setMinutesSMs", () => { +describe("Array.everyWithIndex", () => { + test("Array.everyWithIndex", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + let array = [1, 2, 3, 4] + + array + ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) + ->assertEqual(true) + + array + ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) + ->assertEqual(false) } () }) }) -describe("Date.setMinutesS", () => { - test("Date.setMinutesS", () => { +describe("String.lastIndexOfOpt", () => { + test("String.lastIndexOfOpt", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) + String.lastIndexOfOpt("bookseller", "ok") == Some(2) + String.lastIndexOfOpt("beekeeper", "ee") == Some(4) + String.lastIndexOfOpt("abcdefg", "xyz") == None } () }) }) -describe("Date.setMinutes", () => { - test("Date.setMinutes", () => { +describe("String.startsWithFrom", () => { + test("String.startsWithFrom", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) + String.startsWithFrom("BuckleScript", "kle", 3) == true + String.startsWithFrom("BuckleScript", "", 3) == true + String.startsWithFrom("JavaScript", "Buckle", 2) == false } () }) }) -describe("Date.setHoursMSMs", () => { - test("Date.setHoursMSMs", () => { +describe("String.substringToEnd", () => { + test("String.substringToEnd", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + String.substringToEnd("playground", ~start=4) == "ground" + String.substringToEnd("playground", ~start=-3) == "playground" + String.substringToEnd("playground", ~start=12) == "" } () }) }) -describe("Date.setHoursMS", () => { - test("Date.setHoursMS", () => { +describe("RegExp.Result.matches", () => { + test("RegExp.Result.matches", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") + + // This below will log "ReScript" and "is" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => + switch result->RegExp.Result.matches { + | [firstWord, secondWord] => Console.log2(firstWord, secondWord) + | _ => Console.log("Didn't find exactly two words...") + } + } } () }) }) -describe("Date.setHoursM", () => { - test("Date.setHoursM", () => { +describe("Pervasives.setTimeout", () => { + test("Pervasives.setTimeout", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) + // Log to the console after 200 milliseconds. + let timeoutId = setTimeout( + () => { + Console.log("This prints in 200 ms.") + }, + 200, + ) } () }) }) -describe("Date.setHours", () => { - test("Date.setHours", () => { +describe("Object.hasOwnProperty", () => { + test("Object.hasOwnProperty", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) + let point = {"x": 1, "y": 2} + {"a": 1}->Object.hasOwnProperty("a") // true + {"a": 1}->Object.hasOwnProperty("b") // false + {"a": 1}->Object.hasOwnProperty("toString") // false } () }) }) -describe("Date.setDate", () => { - test("Date.setDate", () => { +describe("List.forEachWithIndex", () => { + test("List.forEachWithIndex", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) + List.forEachWithIndex( + list{"a", "b", "c"}, + (x, index) => { + Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ } () }) }) -describe("Date.setMonth", () => { - test("Date.setMonth", () => { +describe("Math.Constants.log10e", () => { + test("Math.Constants.log10e", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) + Math.Constants.log10e } () }) }) -describe("Date.setFullYearMD", () => { - test("Date.setFullYearMD", () => { +describe("Int.toStringWithRadix", () => { + test("Int.toStringWithRadix", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) + Int.toStringWithRadix(6, ~radix=2) // "110" + Int.toStringWithRadix(373592855, ~radix=16) // "16449317" + Int.toStringWithRadix(123456, ~radix=36) // "2n9c" } () }) }) -describe("Date.setFullYearM", () => { - test("Date.setFullYearM", () => { +describe("Date.setUTCFullYearMD", () => { + test("Date.setUTCFullYearMD", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( + ~year=2024, + ~month=0, + ~date=1, + ) } () }) }) -describe("Date.setFullYear", () => { - test("Date.setFullYear", () => { +describe("Date.setUTCMinutesSMs", () => { + test("Date.setUTCMinutesSMs", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Date.getDay", () => { - test("Date.getDay", () => { +describe("Date.UTC.makeWithYMDH", () => { + test("Date.UTC.makeWithYMDH", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDay - // 1 + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 1676908800000 + + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 1676937600000 + + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 1676847600000 } () }) }) -describe("Date.getMilliseconds", () => { - test("Date.getMilliseconds", () => { +describe("BigInt.toLocaleString", () => { + test("BigInt.toLocaleString", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds - // 0 + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log } () }) }) -describe("Date.getSeconds", () => { - test("Date.getSeconds", () => { +describe("Belt_Set.minUndefined", () => { + test("Belt_Set.minUndefined", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds - // 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) } () }) }) -describe("Date.getMinutes", () => { - test("Date.getMinutes", () => { +describe("Belt_Set.maxUndefined", () => { + test("Belt_Set.maxUndefined", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes - // 40 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) } () }) }) -describe("Date.getHours", () => { - test("Date.getHours", () => { +describe("Belt_Set.Dict.isEmpty", () => { + test("Belt_Set.Dict.isEmpty", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getHours - // 16 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("Date.getDate", () => { - test("Date.getDate", () => { +describe("Belt_Set.Dict.forEach", () => { + test("Belt_Set.Dict.forEach", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDate - // 20 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Date.getMonth", () => { - test("Date.getMonth", () => { +describe("Belt_Set.Dict.toArray", () => { + test("Belt_Set.Dict.toArray", () => { module Test = { - Date.fromString("2023-01-01")->Date.getMonth - // 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("Date.getFullYear", () => { - test("Date.getFullYear", () => { +describe("Belt_Set.Dict.minimum", () => { + test("Belt_Set.Dict.minimum", () => { module Test = { - Date.fromString("2023-02-20")->Date.getFullYear - // 2023 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("Date.getTimezoneOffset", () => { - test("Date.getTimezoneOffset", () => { +describe("Belt_Set.Dict.maximum", () => { + test("Belt_Set.Dict.maximum", () => { module Test = { - Date.fromString("2023-01-01")->Date.getTimezoneOffset - // -60 with local time zone = Europe/Berlin + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.fromString("2023-06-01")->Date.getTimezoneOffset - // -120 with local time zone = Europe/Berlin + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("Date.getTime", () => { - test("Date.getTime", () => { +describe("Belt_MutableSet.union", () => { + test("Belt_MutableSet.union", () => { module Test = { - Date.fromString("2023-02-20")->Date.getTime - // 1676851200000 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Date.makeWithYMDHMSM", () => { - test("Date.makeWithYMDHMSM", () => { +describe("Belt_MutableSet.every", () => { + test("Belt_MutableSet.every", () => { module Test = { - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - ) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - ) - // 2023-02-20T16:40:01.000Z + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=-1, - ) - // 2023-02-20T16:39:59.999Z + let isEven = x => mod(x, 2) == 0 - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ } () }) }) -describe("Date.makeWithYMDHMS", () => { - test("Date.makeWithYMDHMS", () => { +describe("Belt_MutableSet.split", () => { + test("Belt_MutableSet.split", () => { module Test = { - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 2023-02-20T16:40:00.000Z + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 2023-02-20T16:41:00.000Z + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 2023-02-20T16:39:59.000Z + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ } () }) }) -describe("Date.makeWithYMDHM", () => { - test("Date.makeWithYMDHM", () => { +describe("Belt_List.mapReverse2", () => { + test("Belt_List.mapReverse2", () => { module Test = { - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 2023-02-20T17:00:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 2023-02-20T15:59:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Date.makeWithYMDH", () => { - test("Date.makeWithYMDH", () => { +describe("Belt_List.cmpByLength", () => { + test("Belt_List.cmpByLength", () => { module Test = { - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 2023-02-20T16:00:00.000Z - - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 2023-02-21T00:00:00.000Z + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 2023-02-19T23:00:00.000Z + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ } () }) }) -describe("Date.makeWithYMD", () => { - test("Date.makeWithYMD", () => { +describe("Belt_List.removeAssoc", () => { + test("Belt_List.removeAssoc", () => { module Test = { - Date.makeWithYMD(~year=2023, ~month=1, ~date=20) - // 2023-02-20T00:00:00.000Z - - Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) - // 2022-11-29T00:00:00.000Z + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ - Date.makeWithYMD(~year=2023, ~month=1, ~date=29) - // 2023-03-01T00:00:00.000Z + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ } () }) }) -describe("Date.makeWithYM", () => { - test("Date.makeWithYM", () => { +describe("Belt.Array.concatMany", () => { + test("Belt.Array.concatMany", () => { module Test = { - Date.makeWithYM(~year=2023, ~month=0) - // 2023-01-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=11) - // 2023-12-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=12) - // 2024-01-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=-1) - // 2022-12-01T00:00:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Date.fromTime", () => { - test("Date.fromTime", () => { +describe("Belt.Array.sliceToEnd", () => { + test("Belt.Array.sliceToEnd", () => { module Test = { - Date.fromTime(0.0) - // 1970-01-01T00:00:00.000Z - - Date.fromTime(-86_400_000.0) - // 1969-12-31T00:00:00.000Z + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - Date.fromTime(86_400_000.0) - // 1970-01-02T00:00:00.000Z + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Date.fromString", () => { - test("Date.fromString", () => { +describe("Belt.Array.getIndexBy", () => { + test("Belt.Array.getIndexBy", () => { module Test = { - Date.fromString("2023") // 2023-01-01T00:00:00.000Z - - Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z - - Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z - - Date.fromString("") // Invalid Date - - Date.fromString("")->Date.getTime // NaN + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Date.make", () => { - test("Date.make", () => { +describe("Belt.List.mapReverse2", () => { + test("Belt.List.mapReverse2", () => { module Test = { - Date.make() + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Error.panic", () => { - test("Error.panic", () => { +describe("Belt.List.cmpByLength", () => { + test("Belt.List.cmpByLength", () => { module Test = { - try { - Error.panic("Uh oh. This was unexpected!") - } catch { - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") - | None => assert(false) - } - | _ => assert(false) - } - } - () - }) -}) + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ -describe("Error.raise", () => { - test("Error.raise", () => { - module Test = { - let error = Error.make("Everything is upside down.") + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - if 5 > 10 { - error->Error.raise - } else { - Console.log("Phew, sanity still rules.") - } + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ } () }) }) -describe("Error.make", () => { - test("Error.make", () => { +describe("Belt.List.removeAssoc", () => { + test("Belt.List.removeAssoc", () => { module Test = { - let error = Error.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console - Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ } () }) }) -describe("Error.name", () => { - test("Error.name", () => { +describe("Belt.Set.minUndefined", () => { + test("Belt.Set.minUndefined", () => { module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.name) // Logs "SyntaxError" to the console + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) } () }) }) -describe("Error.message", () => { - test("Error.message", () => { +describe("Belt.Set.maxUndefined", () => { + test("Belt.Set.maxUndefined", () => { module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) } () }) }) -describe("Error.stack", () => { - test("Error.stack", () => { +describe("Belt.MutableSet.union", () => { + test("Belt.MutableSet.union", () => { module Test = { - let error = Error.make("error") - Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Error.toException", () => { - test("Error.toException", () => { +describe("Belt.MutableSet.every", () => { + test("Belt.MutableSet.every", () => { module Test = { - let error = Error.make("Something went wrong.") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let asExn = error->Error.toException // `asExn` is now type `exn` + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ } () }) }) -describe("Float.Constants.maxValue", () => { - test("Float.Constants.maxValue", () => { +describe("Belt.MutableSet.split", () => { + test("Belt.MutableSet.split", () => { module Test = { - Float.Constants.minValue + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ } () }) }) -describe("Float.Constants.minValue", () => { - test("Float.Constants.minValue", () => { +describe("Belt.HashMap.logStats", () => { + test("Belt.HashMap.logStats", () => { module Test = { - Float.Constants.minValue + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.logStats(hMap) } () }) }) -describe("Float.Constants.negativeInfinity", () => { - test("Float.Constants.negativeInfinity", () => { +describe("Belt.Float.fromString", () => { + test("Belt.Float.fromString", () => { module Test = { - Float.Constants.negativeInfinity + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ } () }) }) -describe("Float.Constants.positiveInfinity", () => { - test("Float.Constants.positiveInfinity", () => { +describe("Belt.Set.Dict.isEmpty", () => { + test("Belt.Set.Dict.isEmpty", () => { module Test = { - Float.Constants.positiveInfinity + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("Float.Constants.epsilon", () => { - test("Float.Constants.epsilon", () => { +describe("Belt.Set.Dict.forEach", () => { + test("Belt.Set.Dict.forEach", () => { module Test = { - Float.Constants.epsilon + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Float.Constants.nan", () => { - test("Float.Constants.nan", () => { +describe("Belt.Set.Dict.toArray", () => { + test("Belt.Set.Dict.toArray", () => { module Test = { - Float.Constants.nan + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("Float.clamp", () => { - test("Float.clamp", () => { +describe("Belt.Set.Dict.minimum", () => { + test("Belt.Set.Dict.minimum", () => { module Test = { - Float.clamp(4.2) == 4.2 - Float.clamp(4.2, ~min=4.3) == 4.3 - Float.clamp(4.2, ~max=4.1) == 4.1 - Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("Float.mod", () => { - test("Float.mod", () => { +describe("Belt.Set.Dict.maximum", () => { + test("Belt.Set.Dict.maximum", () => { module Test = { - Float.mod(7.0, 4.0) == 3.0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("Float.fromInt", () => { - test("Float.fromInt", () => { +describe("Belt_Float.fromString", () => { + test("Belt_Float.fromString", () => { module Test = { - Float.fromInt(2) == 2.0 - Float.fromInt(1) == 1.0 + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ } () }) }) -describe("Float.toInt", () => { - test("Float.toInt", () => { +describe("Belt_Array.concatMany", () => { + test("Belt_Array.concatMany", () => { module Test = { - Float.toInt(2.0) == 2 - Float.toInt(1.0) == 1 - Float.toInt(1.1) == 1 - Float.toInt(1.6) == 1 + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Float.fromString", () => { - test("Float.fromString", () => { +describe("Belt_Array.sliceToEnd", () => { + test("Belt_Array.sliceToEnd", () => { module Test = { - Float.fromString("0") == Some(0.0) - Float.fromString("NaN") == None - Float.fromString("6") == Some(6.0) + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Float.toLocaleString", () => { - test("Float.toLocaleString", () => { +describe("Belt_Array.getIndexBy", () => { + test("Belt_Array.getIndexBy", () => { module Test = { - // If the application uses English as the default language - Float.toLocaleString(1000.0) // "1,000" - - // If the application uses Portuguese Brazil as the default language - Float.toLocaleString(1000.0) // "1.000" + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Float.toStringWithRadix", () => { - test("Float.toStringWithRadix", () => { +describe("Belt_HashMap.logStats", () => { + test("Belt_HashMap.logStats", () => { module Test = { - Float.toStringWithRadix(6.0, ~radix=2) // "110" - Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" - Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.logStats(hMap) } () }) }) -describe("Float.toString", () => { - test("Float.toString", () => { +describe("AsyncIterator.forEach", () => { + test("AsyncIterator.forEach", () => { module Test = { - Float.toString(1000.0) // "1000" - Float.toString(-1000.0) // "-1000" + // Let's pretend we get an async iterator returning ints from somewhere. + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + let main = async () => + await asyncIterator->AsyncIterator.forEach( + v => { + switch v { + | Some(("second", value)) => assertEqual(value, "2") + | _ => () + } + }, + ) + + main()->ignore } () }) }) -describe("Float.toPrecisionWithPrecision", () => { - test("Float.toPrecisionWithPrecision", () => { +describe("Array.fromInitializer", () => { + test("Array.fromInitializer", () => { module Test = { - Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" + Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) + + Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) } () }) }) -describe("Float.toPrecision", () => { - test("Float.toPrecision", () => { +describe("Array.filterWithIndex", () => { + test("Array.filterWithIndex", () => { module Test = { - Float.toPrecision(100.0) // "100" - Float.toPrecision(1.0) // "1" - Float.toPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecision(1.0, ~digits=1) // "1" + [1, 2, 3, 4] + ->Array.filterWithIndex((num, index) => index === 0 || num === 2) + ->assertEqual([1, 2]) } () }) }) -describe("Float.toFixedWithPrecision", () => { - test("Float.toFixedWithPrecision", () => { +describe("Array.reduceWithIndex", () => { + test("Array.reduceWithIndex", () => { module Test = { - Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" - Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" + Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceWithIndex( + [1, 2, 3], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{5, 3, 1}) + + Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) } () }) }) -describe("Float.toFixed", () => { - test("Float.toFixed", () => { +describe("Type.Classify.classify", () => { + test("Type.Classify.classify", () => { module Test = { - Float.toFixed(123456.0) // "123456.00" - Float.toFixed(10.0) // "10.00" - Float.toFixed(300.0, ~digits=4) // "300.0000" - Float.toFixed(300.0, ~digits=1) // "300.0" + switch %raw(`null`)->Type.Classify.classify { + | Null => Console.log("Yup, that's null.") + | _ => Console.log("This doesn't actually appear to be null...") + } } () }) }) -describe("Float.toExponentialWithPrecision", () => { - test("Float.toExponentialWithPrecision", () => { +describe("String.lastIndexOfFrom", () => { + test("String.lastIndexOfFrom", () => { module Test = { - Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" - Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" + String.lastIndexOfFrom("bookseller", "ok", 6) == 2 + String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 + String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 + String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 } () }) }) -describe("Float.toExponential", () => { - test("Float.toExponential", () => { +describe("Pervasives.setInterval", () => { + test("Pervasives.setInterval", () => { module Test = { - Float.toExponential(1000.0) // "1e+3" - Float.toExponential(-1000.0) // "-1e+3" - Float.toExponential(77.0, ~digits=2) // "7.70e+1" - Float.toExponential(5678.0, ~digits=2) // "5.68e+3" + // Log to the console ever 200 ms (200 milliseconds). + let intervalId = setInterval( + () => { + Console.log("This prints every 200 ms.") + }, + 200, + ) + + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) + }, + 500, + ) } () }) }) -describe("Float.parseIntWithRadix", () => { - test("Float.parseIntWithRadix", () => { +describe("Pervasives.assertEqual", () => { + test("Pervasives.assertEqual", () => { module Test = { - Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 - Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 - Float.parseIntWithRadix("12", ~radix=13) // 15.0 - Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true + list{1, 2} + ->List.tailExn + ->assertEqual(list{2}) } () }) }) -describe("Float.parseInt", () => { - test("Float.parseInt", () => { +describe("Math.Constants.sqrt1_2", () => { + test("Math.Constants.sqrt1_2", () => { module Test = { - Float.parseInt("1.0") // 1.0 - Float.parseInt(" 3.14 ") // 3.0 - Float.parseInt(3) // 3.0 - Float.parseInt("3.14some non-digit characters") // 3.0 - Float.parseInt("error")->Float.isNaN // true - Float.parseInt("10.0", ~radix=2) // 2.0 - Float.parseInt("15 * 3", ~radix=10) // 15.0 - Float.parseInt("12", ~radix=13) // 15.0 - Float.parseInt("17", ~radix=40)->Float.isNaN // true + Math.Constants.sqrt1_2 } () }) }) -describe("Float.parseFloat", () => { - test("Float.parseFloat", () => { +describe("JSON.Classify.classify", () => { + test("JSON.Classify.classify", () => { module Test = { - Float.parseFloat("1.0") // 1.0 - Float.parseFloat(" 3.14 ") // 3.14 - Float.parseFloat("3.0") // 3.0 - Float.parseFloat("3.14some non-digit characters") // 3.14 - Float.parseFloat("error")->Float.isNaN // true + JSON.Classify.classify("hello world") + // String("hello world") + + JSON.Classify.classify(42) + // Number(42) } () }) }) -describe("Float.isFinite", () => { - test("Float.isFinite", () => { +describe("Int.Constants.minValue", () => { + test("Int.Constants.minValue", () => { module Test = { - Float.isFinite(1.0) // true - Float.isFinite(Float.Constants.nan) // false - Float.isFinite(Float.Constants.positiveInfinity) // false + Console.log(Int.Constants.minValue) } () }) }) -describe("Float.isNaN", () => { - test("Float.isNaN", () => { +describe("Int.Constants.maxValue", () => { + test("Int.Constants.maxValue", () => { module Test = { - Float.isNaN(3.0) // false - Float.isNaN(Float.Constants.nan) // true + Console.log(Int.Constants.maxValue) } () }) }) -describe("Int.Bitwise.asr", () => { - test("Int.Bitwise.asr", () => { +describe("Date.getTimezoneOffset", () => { + test("Date.getTimezoneOffset", () => { module Test = { - Int.Bitwise.asr(4, 1) == 2 + Date.fromString("2023-01-01")->Date.getTimezoneOffset + // -60 with local time zone = Europe/Berlin + + Date.fromString("2023-06-01")->Date.getTimezoneOffset + // -120 with local time zone = Europe/Berlin } () }) }) -describe("Int.Bitwise.lsr", () => { - test("Int.Bitwise.lsr", () => { +describe("Date.UTC.makeWithYMDHM", () => { + test("Date.UTC.makeWithYMDHM", () => { module Test = { - Int.Bitwise.lsr(8, 1) == 4 + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 1676911200000 + + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 1676912400000 + + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 1676908740000 } () }) }) -describe("Int.Bitwise.lsl", () => { - test("Int.Bitwise.lsl", () => { +describe("Belt_SetDict.fromArray", () => { + test("Belt_SetDict.fromArray", () => { module Test = { - Int.Bitwise.lsl(4, 1) == 8 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Int.Bitwise.lnot", () => { - test("Int.Bitwise.lnot", () => { +describe("Belt_SetDict.mergeMany", () => { + test("Belt_SetDict.mergeMany", () => { module Test = { - Int.Bitwise.lnot(2) == -3 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("Int.Bitwise.lxor", () => { - test("Int.Bitwise.lxor", () => { +describe("Belt_SetDict.intersect", () => { + test("Belt_SetDict.intersect", () => { module Test = { - Int.Bitwise.lxor(7, 4) == 3 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ } () }) }) -describe("Int.Bitwise.lor", () => { - test("Int.Bitwise.lor", () => { +describe("Belt_SetDict.partition", () => { + test("Belt_SetDict.partition", () => { module Test = { - Int.Bitwise.lor(7, 4) == 7 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Int.Bitwise.land", () => { - test("Int.Bitwise.land", () => { +describe("Belt_MutableSet.remove", () => { + test("Belt_MutableSet.remove", () => { module Test = { - Int.Bitwise.land(7, 4) == 4 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ } () }) }) -describe("Int.Constants.maxValue", () => { - test("Int.Constants.maxValue", () => { +describe("Belt_MutableSet.subset", () => { + test("Belt_MutableSet.subset", () => { module Test = { - Console.log(Int.Constants.maxValue) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ } () }) }) -describe("Int.Constants.minValue", () => { - test("Int.Constants.minValue", () => { +describe("Belt_MutableSet.reduce", () => { + test("Belt_MutableSet.reduce", () => { module Test = { - Console.log(Int.Constants.minValue) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Int.clamp", () => { - test("Int.clamp", () => { +describe("Belt_MutableSet.toList", () => { + test("Belt_MutableSet.toList", () => { module Test = { - Int.clamp(42) == 42 - Int.clamp(42, ~min=50) == 50 - Int.clamp(42, ~max=40) == 40 - Int.clamp(42, ~min=50, ~max=40) == 50 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ } () }) }) -describe("Int.rangeWithOptions", () => { - test("Int.rangeWithOptions", () => { +describe("Belt_Map.valuesToArray", () => { + test("Belt_Map.valuesToArray", () => { module Test = { - Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] - Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] - Int.rangeWithOptions(3, 6, {step: -2}) // RangeError + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] } () }) }) -describe("Int.range", () => { - test("Int.range", () => { +describe("Belt_List.mapWithIndex", () => { + test("Belt_List.mapWithIndex", () => { module Test = { - Int.range(3, 6) == [3, 4, 5] - Int.range(-3, -1) == [-3, -2] - Int.range(3, 1) == [3, 2] - Int.range(3, 7, ~options={step: 2}) == [3, 5] - Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] - Int.range(3, 6, ~options={step: -2}) // RangeError + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} } () }) }) -describe("Int.mod", () => { - test("Int.mod", () => { +describe("Belt.List.mapWithIndex", () => { + test("Belt.List.mapWithIndex", () => { module Test = { - Int.mod(7, 4) == 3 + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} } () }) }) -describe("Int.fromString", () => { - test("Int.fromString", () => { +describe("Belt.Map.valuesToArray", () => { + test("Belt.Map.valuesToArray", () => { module Test = { - Int.fromString("0") == Some(0) - Int.fromString("NaN") == None - Int.fromString("6", ~radix=2) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] } () }) }) -describe("Int.fromFloat", () => { - test("Int.fromFloat", () => { +describe("Belt.MutableSet.remove", () => { + test("Belt.MutableSet.remove", () => { module Test = { - Int.fromFloat(2.0) == 2 - Int.fromFloat(1.999) == 1 - Int.fromFloat(1.5) == 1 - Int.fromFloat(0.9999) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ } () }) }) -describe("Int.toFloat", () => { - test("Int.toFloat", () => { +describe("Belt.MutableSet.subset", () => { + test("Belt.MutableSet.subset", () => { module Test = { - Int.toFloat(100) == 100.0 - Int.toFloat(2) == 2.0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ } () }) }) -describe("Int.toLocaleString", () => { - test("Int.toLocaleString", () => { +describe("Belt.MutableSet.reduce", () => { + test("Belt.MutableSet.reduce", () => { module Test = { - // If the application uses English as the default language - Int.toLocaleString(1000) // "1,000" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - // If the application uses Portuguese Brazil as the default language - Int.toLocaleString(1000) // "1.000" + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Int.toStringWithRadix", () => { - test("Int.toStringWithRadix", () => { +describe("Belt.MutableSet.toList", () => { + test("Belt.MutableSet.toList", () => { module Test = { - Int.toStringWithRadix(6, ~radix=2) // "110" - Int.toStringWithRadix(373592855, ~radix=16) // "16449317" - Int.toStringWithRadix(123456, ~radix=36) // "2n9c" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ } () }) }) -describe("Int.toString", () => { - test("Int.toString", () => { +describe("Belt.HashMap.fromArray", () => { + test("Belt.HashMap.fromArray", () => { module Test = { - Int.toString(1000) // "1000" - Int.toString(-1000) // "-1000" - Int.toString(6, ~radix=2) // "110" - Int.toString(373592855, ~radix=16) // "16449317" - Int.toString(123456, ~radix=36) // "2n9c" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Int.toPrecisionWithPrecision", () => { - test("Int.toPrecisionWithPrecision", () => { +describe("Belt.HashMap.mergeMany", () => { + test("Belt.HashMap.mergeMany", () => { module Test = { - Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) } () }) }) -describe("Int.toPrecision", () => { - test("Int.toPrecision", () => { +describe("Belt_HashMap.fromArray", () => { + test("Belt_HashMap.fromArray", () => { module Test = { - Int.toPrecision(100) // "100" - Int.toPrecision(1) // "1" - Int.toPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecision(1, ~digits=2) // "1.0" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Int.toFixedWithPrecision", () => { - test("Int.toFixedWithPrecision", () => { +describe("Belt_HashMap.mergeMany", () => { + test("Belt_HashMap.mergeMany", () => { module Test = { - Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" - Int.toFixedWithPrecision(300, ~digits=1) // "300.0" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) } () }) }) -describe("Int.toFixed", () => { - test("Int.toFixed", () => { +describe("Array.forEachWithIndex", () => { + test("Array.forEachWithIndex", () => { module Test = { - Int.toFixed(123456) // "123456.00" - Int.toFixed(10) // "10.00" - Int.toFixed(300, ~digits=4) // "300.0000" - Int.toFixed(300, ~digits=1) // "300.0" + let array = ["Hello", "Hi", "Good bye"] + + array->Array.forEachWithIndex( + (item, index) => { + Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) + }, + ) } () }) }) -describe("Int.toExponentialWithPrecision", () => { - test("Int.toExponentialWithPrecision", () => { +describe("Array.flatMapWithIndex", () => { + test("Array.flatMapWithIndex", () => { module Test = { - Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" - Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" + type language = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.flatMapWithIndex( + (item, index) => + switch item { + | ReScript => [index] + | TypeScript => [index, index + 1] + | JavaScript => [index, index + 1, index + 2] + }, + ) + ->assertEqual([0, 1, 2, 2, 3, 4]) } () }) }) -describe("Int.toExponential", () => { - test("Int.toExponential", () => { +describe("String.fromCharCodeMany", () => { + test("String.fromCharCodeMany", () => { module Test = { - Int.toExponential(1000) // "1e+3" - Int.toExponential(-1000) // "-1e+3" - Int.toExponential(77, ~digits=2) // "7.70e+1" - Int.toExponential(5678, ~digits=2) // "5.68e+3" + String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" + String.fromCharCodeMany([65, 66, 67]) == "ABC" } () }) }) -describe("Iterator.forEach", () => { - test("Iterator.forEach", () => { +describe("String.replaceAllRegExp", () => { + test("String.replaceAllRegExp", () => { module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - iterator->Iterator.forEach( - v => { - switch v { - | Some("a" | "b" | "c") => assert(true) - | other => - other - ->Option.isNone - ->assertEqual(true) - } - }, - ) + String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" } () }) }) -describe("Iterator.toArrayWithMapper", () => { - test("Iterator.toArrayWithMapper", () => { +describe("RegExp.Result.fullMatch", () => { + test("RegExp.Result.fullMatch", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = - map - ->Map.keys - ->Iterator.toArrayWithMapper(key => key->String.length) + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") - Console.log(mapKeysAsArray) // Logs [7, 8] to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" + } } () }) }) -describe("Iterator.toArray", () => { - test("Iterator.toArray", () => { +describe("Pervasives.clearTimeout", () => { + test("Pervasives.clearTimeout", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = map->Map.keys->Iterator.toArray + let timeoutId = setTimeout( + () => { + Console.log("This prints in 2 seconds.") + }, + 2000, + ) - Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. + // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. + clearTimeout(timeoutId) } () }) }) -describe("Iterator.next", () => { - test("Iterator.next", () => { +describe("Float.parseIntWithRadix", () => { + test("Float.parseIntWithRadix", () => { module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - (iterator->Iterator.next).done->assertEqual(false) - (iterator->Iterator.next).done->assertEqual(true) + Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 + Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 + Float.parseIntWithRadix("12", ~radix=13) // 15.0 + Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true } () }) }) -describe("JSON.Decode.array", () => { - test("JSON.Decode.array", () => { +describe("Float.toStringWithRadix", () => { + test("Float.toStringWithRadix", () => { module Test = { - JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array - // Some([ 'foo', 'bar' ]) - - JSON.parseExn(`"hello world"`)->JSON.Decode.array - // None + Float.toStringWithRadix(6.0, ~radix=2) // "110" + Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" + Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" } () }) }) -describe("JSON.Decode.object", () => { - test("JSON.Decode.object", () => { +describe("Float.Constants.epsilon", () => { + test("Float.Constants.epsilon", () => { module Test = { - JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object - // Some({ foo: 'bar' }) - - JSON.parseExn(`"hello world"`)->JSON.Decode.object - // None + Float.Constants.epsilon } () }) }) -describe("JSON.Decode.float", () => { - test("JSON.Decode.float", () => { +describe("Date.getUTCMilliseconds", () => { + test("Date.getUTCMilliseconds", () => { module Test = { - JSON.parseExn(`42.0`)->JSON.Decode.float - // Some(42.0) - - JSON.parseExn(`"hello world"`)->JSON.Decode.float - // None + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 } () }) }) -describe("JSON.Decode.string", () => { - test("JSON.Decode.string", () => { +describe("Date.setUTCMilliseconds", () => { + test("Date.setUTCMilliseconds", () => { module Test = { - JSON.parseExn(`"hello world"`)->JSON.Decode.string - // Some("hello world") - - JSON.parseExn(`42`)->JSON.Decode.string - // None + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) } () }) }) -describe("JSON.Decode.null", () => { - test("JSON.Decode.null", () => { +describe("Date.toLocaleDateString", () => { + test("Date.toLocaleDateString", () => { module Test = { - JSON.parseExn(`null`)->JSON.Decode.null - // Some(null) - - JSON.parseExn(`"hello world"`)->JSON.Decode.null - // None + Date.make()->Date.toLocaleDateString->Console.log + // 2/19/2023 } () }) }) -describe("JSON.Decode.bool", () => { - test("JSON.Decode.bool", () => { +describe("Date.toLocaleTimeString", () => { + test("Date.toLocaleTimeString", () => { module Test = { - JSON.parseExn(`true`)->JSON.Decode.bool - // Some(true) - - JSON.parseExn(`"hello world"`)->JSON.Decode.bool - // None + Date.make()->Date.toLocaleTimeString->Console.log + // 3:40:00 PM } () }) }) -describe("JSON.Encode.array", () => { - test("JSON.Encode.array", () => { +describe("Date.UTC.makeWithYMDHMS", () => { + test("Date.UTC.makeWithYMDHMS", () => { module Test = { - let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 1676911200000 - JSON.Encode.array(array) + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 1676911260000 + + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 1676911199000 } () }) }) -describe("JSON.Encode.object", () => { - test("JSON.Encode.object", () => { +describe("Belt_Set.Dict.fromArray", () => { + test("Belt_Set.Dict.fromArray", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.Encode.object(dict) + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("JSON.Encode.float", () => { - test("JSON.Encode.float", () => { +describe("Belt_Set.Dict.mergeMany", () => { + test("Belt_Set.Dict.mergeMany", () => { module Test = { - JSON.Encode.float(42.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("JSON.Encode.int", () => { - test("JSON.Encode.int", () => { +describe("Belt_Set.Dict.intersect", () => { + test("Belt_Set.Dict.intersect", () => { module Test = { - JSON.Encode.int(42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ } () }) }) -describe("JSON.Encode.string", () => { - test("JSON.Encode.string", () => { +describe("Belt_Set.Dict.partition", () => { + test("Belt_Set.Dict.partition", () => { module Test = { - JSON.Encode.string("hello world") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("JSON.Encode.null", () => { - test("JSON.Encode.null", () => { +describe("Belt_SetDict.removeMany", () => { + test("Belt_SetDict.removeMany", () => { module Test = { - JSON.Encode.null + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("JSON.Encode.bool", () => { - test("JSON.Encode.bool", () => { +describe("Belt_MutableSet.isEmpty", () => { + test("Belt_MutableSet.isEmpty", () => { module Test = { - JSON.Encode.bool(true) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ } () }) }) -describe("JSON.Classify.classify", () => { - test("JSON.Classify.classify", () => { +describe("Belt_MutableSet.forEach", () => { + test("Belt_MutableSet.forEach", () => { module Test = { - JSON.Classify.classify("hello world") - // String("hello world") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.Classify.classify(42) - // Number(42) + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("JSON.stringifyAnyWithFilterAndIndent", () => { - test("JSON.stringifyAnyWithFilterAndIndent", () => { +describe("Belt_MutableSet.toArray", () => { + test("Belt_MutableSet.toArray", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + } + () + }) +}) - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) +describe("Belt_MutableSet.minimum", () => { + test("Belt_MutableSet.minimum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ } () }) }) -describe("JSON.stringifyAnyWithFilter", () => { - test("JSON.stringifyAnyWithFilter", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) - ->assertEqual(`{"foo":"bar","someNumber":42}`) +describe("Belt_MutableSet.maximum", () => { + test("Belt_MutableSet.maximum", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ } () }) }) -describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - test("JSON.stringifyAnyWithReplacerAndIndent", () => { +describe("Belt_MapInt.findFirstBy", () => { + test("Belt_MapInt.findFirstBy", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("JSON.stringifyAnyWithReplacer", () => { - test("JSON.stringifyAnyWithReplacer", () => { +describe("Belt_List.reverseConcat", () => { + test("Belt_List.reverseConcat", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("JSON.stringifyAnyWithIndent", () => { - test("JSON.stringifyAnyWithIndent", () => { +describe("Belt_List.reduceReverse", () => { + test("Belt_List.reduceReverse", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithIndent(2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ - JSON.stringifyAny(() => "hello world")->assertEqual(None) + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} } () }) }) -describe("JSON.stringifyAny", () => { - test("JSON.stringifyAny", () => { +describe("Belt_List.keepWithIndex", () => { + test("Belt_List.keepWithIndex", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) - - dict - ->JSON.stringifyAny(~replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let isEven = x => mod(x, 2) == 0 - // Raise a exception - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("JSON.stringifyWithFilterAndIndent", () => { - test("JSON.stringifyWithFilterAndIndent", () => { +describe("Belt.Array.mapWithIndex", () => { + test("Belt.Array.mapWithIndex", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) - // { - // "foo": "bar", - // "someNumber": 42 - // } + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("JSON.stringifyWithFilter", () => { - test("JSON.stringifyWithFilter", () => { +describe("Belt.List.reverseConcat", () => { + test("Belt.List.reverseConcat", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringifyWithFilter(json, ["foo", "someNumber"]) - // {"foo":"bar","someNumber":42} + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("JSON.stringifyWithReplacerAndIndent", () => { - test("JSON.stringifyWithReplacerAndIndent", () => { +describe("Belt.List.reduceReverse", () => { + test("Belt.List.reduceReverse", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ - JSON.stringifyWithReplacerAndIndent(json, replacer, 2) - // { - // "foo": "BAR", - // "hello": "WORLD", - // "someNumber": 42 - // } + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} } () }) }) -describe("JSON.stringifyWithReplacer", () => { - test("JSON.stringifyWithReplacer", () => { +describe("Belt.List.keepWithIndex", () => { + test("Belt.List.keepWithIndex", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } + let isEven = x => mod(x, 2) == 0 - JSON.stringifyWithReplacer(json, replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("JSON.stringifyWithIndent", () => { - test("JSON.stringifyWithIndent", () => { +describe("Belt.MutableSet.isEmpty", () => { + test("Belt.MutableSet.isEmpty", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.stringifyWithIndent(json, 2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ } () }) }) -describe("JSON.stringify", () => { - test("JSON.stringify", () => { +describe("Belt.MutableSet.forEach", () => { + test("Belt.MutableSet.forEach", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringify(json) - // {"foo":"bar","hello":"world","someNumber":42} - - JSON.stringify(json, ~space=2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } - - JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) - // {"foo":"bar","someNumber":42} - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.stringify(json, ~replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("JSON.parseExnWithReviver", () => { - test("JSON.parseExnWithReviver", () => { +describe("Belt.MutableSet.toArray", () => { + test("Belt.MutableSet.toArray", () => { module Test = { - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - try { - JSON.parseExnWithReviver(jsonString, reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - JSON.parseExnWithReviver("", reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ } () }) }) -describe("JSON.parseExn", () => { - test("JSON.parseExn", () => { +describe("Belt.MutableSet.minimum", () => { + test("Belt.MutableSet.minimum", () => { module Test = { - try { - let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) - // { foo: 'bar', hello: 'world' } - - let _ = JSON.parseExn("") - // error - } catch { - | Exn.Error(_) => Console.log("error") - } - - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - try { - JSON.parseExn(jsonString, ~reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - JSON.parseExn("", ~reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ } () }) }) -describe("Map.entries", () => { - test("Map.entries", () => { +describe("Belt.MutableSet.maximum", () => { + test("Belt.MutableSet.maximum", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let entries = map->Map.entries + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - // Logs the first value - Console.log(Iterator.next(entries).value) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - // You can also turn the iterator into an array. - // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. - Console.log(map->Map.entries->Iterator.toArray) + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ } () }) }) -describe("Map.values", () => { - test("Map.values", () => { +describe("Belt.Set.Dict.fromArray", () => { + test("Belt.Set.Dict.fromArray", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let values = map->Map.values + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - // Logs the first value - Console.log(Iterator.next(values).value) + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(map->Map.values->Iterator.toArray) + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Map.keys", () => { - test("Map.keys", () => { +describe("Belt.Set.Dict.mergeMany", () => { + test("Belt.Set.Dict.mergeMany", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let keys = map->Map.keys + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - // Logs the first key - Console.log(Iterator.next(keys).value) + let set = Belt.Set.Dict.empty - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. - Console.log(map->Map.keys->Iterator.toArray) + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("Map.delete", () => { - test("Map.delete", () => { +describe("Belt.Set.Dict.intersect", () => { + test("Belt.Set.Dict.intersect", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - let didDeleteKey = map->Map.delete("someKey") - Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let didDeleteKey = map->Map.delete("someNonExistantKey") - Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ } () }) }) -describe("Map.set", () => { - test("Map.set", () => { +describe("Belt.Set.Dict.partition", () => { + test("Belt.Set.Dict.partition", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Map.has", () => { - test("Map.has", () => { +describe("Belt_Array.mapWithIndex", () => { + test("Belt_Array.mapWithIndex", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - - switch map->Map.has("someKey") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Map.get", () => { - test("Map.get", () => { +describe("String.fromCodePointMany", () => { + test("String.fromCodePointMany", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - - switch map->Map.get("someKey") { - | None => Console.log("Nope, didn't have it.") - | Some(value) => Console.log2("Yay, had the value, and it's:", value) - } + String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` } () }) }) -describe("Map.forEachWithKey", () => { - test("Map.forEachWithKey", () => { +describe("Pervasives.clearInterval", () => { + test("Pervasives.clearInterval", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") + let intervalId = setInterval( + () => { + Console.log("This prints in 100 ms") + }, + 100, + ) - map->Map.forEachWithKey( - (value, key) => { - Console.log2(value, key) + // Stop the interval after 500 ms + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) }, + 500, ) } () }) }) -describe("Map.forEach", () => { - test("Map.forEach", () => { +describe("Object.preventExtensions", () => { + test("Object.preventExtensions", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - map->Map.forEach( - value => { - Console.log(value) - }, - ) + let obj = {"a": 1} + obj->Object.set("b", 2) // succeeds + obj->Object.preventExtensions->ignore + try { + obj->Object.set("c", 3) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Map.clear", () => { - test("Map.clear", () => { +describe("JSON.parseExnWithReviver", () => { + test("JSON.parseExnWithReviver", () => { module Test = { - let map = Map.make() + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } - map->Map.set("someKey", "someValue") - map->Map.size // 1 + let jsonString = `{"hello":"world","someNumber":21}` - map->Map.clear - map->Map.size // 0 + try { + JSON.parseExnWithReviver(jsonString, reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExnWithReviver("", reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } } () }) }) -describe("Map.size", () => { - test("Map.size", () => { +describe("JSON.stringifyWithIndent", () => { + test("JSON.stringifyWithIndent", () => { module Test = { - let map = Map.make() - - map->Map.set("someKey", "someValue") + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let size = map->Map.size // 1 + JSON.stringifyWithIndent(json, 2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } } () }) }) -describe("Map.fromIterator", () => { - test("Map.fromIterator", () => { +describe("JSON.stringifyWithFilter", () => { + test("JSON.stringifyWithFilter", () => { module Test = { - // Let's pretend we have an interator in the correct shape - let iterator: Iterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - iterator - ->Map.fromIterator - ->Map.size - ->assertEqual(2) + JSON.stringifyWithFilter(json, ["foo", "someNumber"]) + // {"foo":"bar","someNumber":42} } () }) }) -describe("Map.fromArray", () => { - test("Map.fromArray", () => { +describe("Int.toFixedWithPrecision", () => { + test("Int.toFixedWithPrecision", () => { module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] - - let map = Map.fromArray(languageRank) // Map.t - - switch map->Map.get(ReScript) { - | Some(1) => Console.log("Yay, ReScript is #1!") - | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } + Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" + Int.toFixedWithPrecision(300, ~digits=1) // "300.0" } () }) }) -describe("Map.make", () => { - test("Map.make", () => { +describe("Float.Constants.minValue", () => { + test("Float.Constants.minValue", () => { module Test = { - `make()` - // You can annotate the type of your map if you want to - let myMap: Map.t = Map.make() - - // Or you can let ReScript infer what's in your map - let map = Map.make() - map->Map.set("lang", "ReScript") // Inferred as Map.t + Float.Constants.minValue } () }) }) -describe("List.sort", () => { - test("List.sort", () => { +describe("Float.Constants.maxValue", () => { + test("Float.Constants.maxValue", () => { module Test = { - List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} + Float.Constants.minValue } () }) }) -describe("List.setAssoc", () => { - test("List.setAssoc", () => { +describe("Date.UTC.makeWithYMDHMSM", () => { + test("Date.UTC.makeWithYMDHMSM", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + )->Console.log + // 1676911200000 - list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + )->Console.log + // 1676911201000 - list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - // list{(9, "morning"), (15, "afternoon"), (22, "night")} + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + )->Console.log + // 1676911199999 } () }) }) -describe("List.removeAssoc", () => { - test("List.removeAssoc", () => { +describe("Belt_internalMapInt.A.eq", () => { + test("Belt_internalMapInt.A.eq", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - // list{(15, "afternoon"), (22, "night")} + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("List.hasAssoc", () => { - test("List.hasAssoc", () => { +describe("Belt_internalSetInt.A.eq", () => { + test("Belt_internalSetInt.A.eq", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) // false + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("List.getAssoc", () => { - test("List.getAssoc", () => { +describe("Belt_Set.Dict.removeMany", () => { + test("Belt_Set.Dict.removeMany", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - // Some("afternoon") + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("List.unzip", () => { - test("List.unzip", () => { +describe("Belt_MapDict.findFirstBy", () => { + test("Belt_MapDict.findFirstBy", () => { module Test = { - List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("List.partition", () => { - test("List.partition", () => { +describe("Belt_Map.Int.findFirstBy", () => { + test("Belt_Map.Int.findFirstBy", () => { module Test = { - // (elementsThatSatisfies, elementsThatDoesNotSatisfy) + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("List.filterMap", () => { - test("List.filterMap", () => { +describe("Belt_List.reduceReverse2", () => { + test("Belt_List.reduceReverse2", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->List.filterMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) // list{2, 4} - - list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("List.filterWithIndex", () => { - test("List.filterWithIndex", () => { +describe("Belt.Array.keepWithIndex", () => { + test("Belt.Array.keepWithIndex", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("List.filter", () => { - test("List.filter", () => { +describe("Belt.Array.reduceReverse", () => { + test("Belt.Array.reduceReverse", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} - - List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("List.find", () => { - test("List.find", () => { +describe("Belt.List.reduceReverse2", () => { + test("Belt.List.reduceReverse2", () => { module Test = { - List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) - - List.find(list{1, 4, 3, 2}, x => x > 4) // None + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("List.has", () => { - test("List.has", () => { +describe("Belt.HashMap.keysToArray", () => { + test("Belt.HashMap.keysToArray", () => { module Test = { - list{1, 2, 3}->List.has(2, (a, b) => a == b) // true + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - list{1, 2, 3}->List.has(4, (a, b) => a == b) // false + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true + Belt.HashMap.keysToArray(s0) == [1, 2] } () }) }) -describe("List.equal", () => { - test("List.equal", () => { +describe("Belt.Set.Dict.removeMany", () => { + test("Belt.Set.Dict.removeMany", () => { module Test = { - List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("List.compare", () => { - test("List.compare", () => { +describe("Belt.Map.Int.findFirstBy", () => { + test("Belt.Map.Int.findFirstBy", () => { module Test = { - List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("List.compareLength", () => { - test("List.compareLength", () => { +describe("Belt_Array.keepWithIndex", () => { + test("Belt_Array.keepWithIndex", () => { module Test = { - List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. - - List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. - - List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("List.some2", () => { - test("List.some2", () => { +describe("Belt_Array.reduceReverse", () => { + test("Belt_Array.reduceReverse", () => { module Test = { - List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - - List.some2(list{}, list{1}, (a, b) => a > b) // false - - List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true - - List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("List.every2", () => { - test("List.every2", () => { +describe("Belt_HashMap.keysToArray", () => { + test("Belt_HashMap.keysToArray", () => { module Test = { - List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - - List.every2(list{}, list{1}, (a, b) => a > b) // true + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false + Belt.HashMap.keysToArray(s0) == [1, 2] } () }) }) -describe("List.some", () => { - test("List.some", () => { +describe("Array.findIndexWithIndex", () => { + test("Array.findIndexWithIndex", () => { module Test = { - let isAbove100 = value => value > 100 + type languages = ReScript | TypeScript | JavaScript - list{101, 1, 2, 3}->List.some(isAbove100) // true + let array = [ReScript, JavaScript] - list{1, 2, 3, 4}->List.some(isAbove100) // false + let isReScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) + let isTypeScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) + + assertEqual(isReScriptFirst, 0) + assertEqual(isTypeScriptFirst, -1) } () }) }) -describe("List.every", () => { - test("List.every", () => { +describe("Belt_internalMapInt.A.get", () => { + test("Belt_internalMapInt.A.get", () => { module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->List.every(isBelow10) // true - - list{1, 99, 8, 2}->List.every(isBelow10) // false + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("List.reduceReverse2", () => { - test("List.reduceReverse2", () => { +describe("Belt_internalMapInt.A.zip", () => { + test("Belt_internalMapInt.A.zip", () => { module Test = { - List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("List.reduce2", () => { - test("List.reduce2", () => { +describe("Belt_internalMapInt.A.map", () => { + test("Belt_internalMapInt.A.map", () => { module Test = { - List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("List.forEach2", () => { - test("List.forEach2", () => { +describe("Belt_internalMapInt.A.cmp", () => { + test("Belt_internalMapInt.A.cmp", () => { module Test = { - List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - /* - prints: - "Z" "A" - "Y" "B" -*/ + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("List.mapReverse2", () => { - test("List.mapReverse2", () => { +describe("Belt_internalSetInt.A.get", () => { + test("Belt_internalSetInt.A.get", () => { module Test = { - List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("List.reduceReverse", () => { - test("List.reduceReverse", () => { +describe("Belt_internalSetInt.A.zip", () => { + test("Belt_internalSetInt.A.zip", () => { module Test = { - list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 - - list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 - - list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("List.reduceWithIndex", () => { - test("List.reduceWithIndex", () => { +describe("Belt_internalSetInt.A.map", () => { + test("Belt_internalSetInt.A.map", () => { module Test = { - list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("List.reduce", () => { - test("List.reduce", () => { +describe("Belt_internalSetInt.A.cmp", () => { + test("Belt_internalSetInt.A.cmp", () => { module Test = { - list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - // same as + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("List.forEachWithIndex", () => { - test("List.forEachWithIndex", () => { +describe("Belt_SetDict.minUndefined", () => { + test("Belt_SetDict.minUndefined", () => { module Test = { - List.forEachWithIndex( - list{"a", "b", "c"}, - (x, index) => { - Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("List.forEach", () => { - test("List.forEach", () => { +describe("Belt_SetDict.maxUndefined", () => { + test("Belt_SetDict.maxUndefined", () => { module Test = { - List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ + } () }) }) -describe("List.mapReverse", () => { - test("List.mapReverse", () => { +describe("Belt_MutableSet.fromArray", () => { + test("Belt_MutableSet.fromArray", () => { module Test = { - let f = x => x * x - let l = list{3, 4, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let withMap = List.map(l, f)->List.reverse - let withMapReverse = l->List.mapReverse(f) + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - Console.log(withMap == withMapReverse) // true + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("List.reverse", () => { - test("List.reverse", () => { +describe("Belt_MutableSet.mergeMany", () => { + test("Belt_MutableSet.mergeMany", () => { module Test = { - List.reverse(list{1, 2, 3}) // list{3, 2, 1} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("List.toArray", () => { - test("List.toArray", () => { +describe("Belt_MutableSet.intersect", () => { + test("Belt_MutableSet.intersect", () => { module Test = { - List.toArray(list{1, 2, 3}) // [1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ } () }) }) -describe("List.fromArray", () => { - test("List.fromArray", () => { +describe("Belt_MutableSet.partition", () => { + test("Belt_MutableSet.partition", () => { module Test = { - List.fromArray([1, 2, 3]) // list{1, 2, 3} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ } () }) }) -describe("List.mapWithIndex", () => { - test("List.mapWithIndex", () => { +describe("Belt_Map.Dict.findFirstBy", () => { + test("Belt_Map.Dict.findFirstBy", () => { module Test = { - list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("List.zipBy", () => { - test("List.zipBy", () => { +describe("Belt_List.reduceWithIndex", () => { + test("Belt_List.reduceWithIndex", () => { module Test = { - List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ } () }) }) -describe("List.zip", () => { - test("List.zip", () => { +describe("Belt_List.filterWithIndex", () => { + test("Belt_List.filterWithIndex", () => { module Test = { - List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + let isEven = x => mod(x, 2) == 0 + + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("List.map", () => { - test("List.map", () => { +describe("Belt.Array.reverseInPlace", () => { + test("Belt.Array.reverseInPlace", () => { module Test = { - list{1, 2}->List.map(x => x + 1) // list{3, 4} + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("List.flat", () => { - test("List.flat", () => { +describe("Belt.Array.reduceReverse2", () => { + test("Belt.Array.reduceReverse2", () => { module Test = { - List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("List.reverseConcat", () => { - test("List.reverseConcat", () => { +describe("Belt.List.reduceWithIndex", () => { + test("Belt.List.reduceWithIndex", () => { module Test = { - List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ } () }) }) -describe("List.concatMany", () => { - test("List.concatMany", () => { +describe("Belt.List.filterWithIndex", () => { + test("Belt.List.filterWithIndex", () => { module Test = { - List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + let isEven = x => mod(x, 2) == 0 + + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("List.concat", () => { - test("List.concat", () => { +describe("Belt.MutableSet.fromArray", () => { + test("Belt.MutableSet.fromArray", () => { module Test = { - List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("List.splitAt", () => { - test("List.splitAt", () => { +describe("Belt.MutableSet.mergeMany", () => { + test("Belt.MutableSet.mergeMany", () => { module Test = { - list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("List.take", () => { - test("List.take", () => { +describe("Belt.MutableSet.intersect", () => { + test("Belt.MutableSet.intersect", () => { module Test = { - list{1, 2, 3}->List.take(1) // Some(list{1}) - - list{1, 2, 3}->List.take(2) // Some(list{1, 2}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{1, 2, 3}->List.take(4) // None + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ } () }) }) -describe("List.drop", () => { - test("List.drop", () => { +describe("Belt.MutableSet.partition", () => { + test("Belt.MutableSet.partition", () => { module Test = { - list{1, 2, 3}->List.drop(2) // Some(list{3}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{1, 2, 3}->List.drop(3) // Some(list{}) + let isOdd = x => mod(x, 2) != 0 - list{1, 2, 3}->List.drop(4) // None + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ } () }) }) -describe("List.toShuffled", () => { - test("List.toShuffled", () => { +describe("Belt.Map.Dict.findFirstBy", () => { + test("Belt.Map.Dict.findFirstBy", () => { module Test = { - List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("List.fromInitializer", () => { - test("List.fromInitializer", () => { +describe("Belt_Array.reverseInPlace", () => { + test("Belt_Array.reverseInPlace", () => { module Test = { - List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} + let arr = [10, 11, 12, 13, 14] - List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("List.make", () => { - test("List.make", () => { +describe("Belt_Array.reduceReverse2", () => { + test("Belt_Array.reduceReverse2", () => { module Test = { - List.make(~length=3, 1) // list{1, 1, 1} + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("List.getExn", () => { - test("List.getExn", () => { +describe("String.splitByRegExpAtMost", () => { + test("String.splitByRegExpAtMost", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc - ->List.getExn(1) - ->assertEqual("B") - - switch abc->List.getExn(4) { - | exception Not_found => assert(true) - | _ => assert(false) - } + String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ + Some("Hello"), + Some("World."), + Some("How"), + ] } () }) }) -describe("List.get", () => { - test("List.get", () => { +describe("RegExp.fromStringWithFlags", () => { + test("RegExp.fromStringWithFlags", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc->List.get(1) // Some("B") + // Match the first word in a sentence + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") - abc->List.get(4) // None + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("List.add", () => { - test("List.add", () => { +describe("Pervasives.setTimeoutFloat", () => { + test("Pervasives.setTimeoutFloat", () => { module Test = { - List.add(list{2, 3}, 1) // list{1, 2, 3} - - List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + // Log to the console after 200 milliseconds. + let timeoutId = setTimeoutFloat( + () => { + Console.log("This prints in 200 ms.") + }, + 200., + ) } () }) }) -describe("List.tailExn", () => { - test("List.tailExn", () => { +describe("JSON.stringifyWithReplacer", () => { + test("JSON.stringifyWithReplacer", () => { module Test = { - List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - switch List.tailExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } - } - () - }) -}) + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string -describe("List.tail", () => { - test("List.tail", () => { - module Test = { - List.tail(list{1, 2, 3}) // Some(list{2, 3}) + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } - List.tail(list{}) // None + JSON.stringifyWithReplacer(json, replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} } () }) }) -describe("List.headExn", () => { - test("List.headExn", () => { +describe("Iterator.toArrayWithMapper", () => { + test("Iterator.toArrayWithMapper", () => { module Test = { - List.headExn(list{1, 2, 3})->assertEqual(1) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - switch List.headExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = + map + ->Map.keys + ->Iterator.toArrayWithMapper(key => key->String.length) + + Console.log(mapKeysAsArray) // Logs [7, 8] to the console. } () }) }) -describe("List.head", () => { - test("List.head", () => { +describe("Float.toFixedWithPrecision", () => { + test("Float.toFixedWithPrecision", () => { module Test = { - List.head(list{}) // None - List.head(list{1, 2, 3}) // Some(1) + Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" + Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" } () }) }) -describe("List.size", () => { - test("List.size", () => { +describe("Belt_internalMapInt.A.fill", () => { + test("Belt_internalMapInt.A.fill", () => { module Test = { - List.size(list{1, 2, 3}) // 3 + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("List.length", () => { - test("List.length", () => { +describe("Belt_internalMapInt.A.blit", () => { + test("Belt_internalMapInt.A.blit", () => { module Test = { - List.length(list{1, 2, 3}) // 3 + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Nullable.flatMap", () => { - test("Nullable.flatMap", () => { +describe("Belt_internalMapInt.A.some", () => { + test("Belt_internalMapInt.A.some", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Nullable.make(value + 1) - } else { - Nullable.null - } + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) - Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined - Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Nullable.mapOr", () => { - test("Nullable.mapOr", () => { +describe("Belt_internalSetInt.A.fill", () => { + test("Belt_internalSetInt.A.fill", () => { module Test = { - let someValue = Nullable.make(3) - someValue->Nullable.mapOr(0, x => x + 5) // 8 + let arr = Belt.Array.makeBy(5, i => i) - let noneValue = Nullable.null - noneValue->Nullable.mapOr(0, x => x + 5) // 0 + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Nullable.map", () => { - test("Nullable.map", () => { +describe("Belt_internalSetInt.A.blit", () => { + test("Belt_internalSetInt.A.blit", () => { module Test = { - Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) - Nullable.map(undefined, x => x * x) // undefined + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Nullable.forEach", () => { - test("Nullable.forEach", () => { +describe("Belt_internalSetInt.A.some", () => { + test("Belt_internalSetInt.A.some", () => { module Test = { - Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" - Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () - Nullable.forEach(undefined, x => Console.log(x)) // returns () + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Nullable.getUnsafe", () => { - test("Nullable.getUnsafe", () => { +describe("Belt_Set.Dict.minUndefined", () => { + test("Belt_Set.Dict.minUndefined", () => { module Test = { - Nullable.getUnsafe(Nullable.make(3)) == 3 - Nullable.getUnsafe(Nullable.null) // Raises an error + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("Nullable.getExn", () => { - test("Nullable.getExn", () => { +describe("Belt_Set.Dict.maxUndefined", () => { + test("Belt_Set.Dict.maxUndefined", () => { module Test = { - switch Nullable.getExn(%raw("'Hello'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "Hello") - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch Nullable.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - switch Nullable.getExn(%raw("undefined")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ } () }) }) -describe("Nullable.getOr", () => { - test("Nullable.getOr", () => { +describe("Belt_Result.mapWithDefault", () => { + test("Belt_Result.mapWithDefault", () => { module Test = { - Nullable.getOr(Nullable.null, "Banana") // Banana - Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" - Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 } () }) }) -describe("Nullable.fromOption", () => { - test("Nullable.fromOption", () => { +describe("Belt_Result.getWithDefault", () => { + test("Belt_Result.getWithDefault", () => { module Test = { - let optString = Some("Hello") - let asNullable = optString->Nullable.fromOption // Nullable.t + Belt.Result.getWithDefault(Ok(42), 0) == 42 + + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 } () }) }) -describe("Nullable.toOption", () => { - test("Nullable.toOption", () => { +describe("Belt_Option.mapWithDefault", () => { + test("Belt_Option.mapWithDefault", () => { module Test = { - let nullableString = Nullable.make("Hello") + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - switch nullableString->Nullable.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ } () }) }) -describe("Nullable.make", () => { - test("Nullable.make", () => { +describe("Belt_Option.getWithDefault", () => { + test("Belt_Option.getWithDefault", () => { module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make + Belt.Option.getWithDefault(None, "Banana") /* Banana */ - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - // Need to do this - switch asNullable->Nullable.toOption { - | Some(value) if value == myStr => Console.log("Yay, values matched!") - | _ => Console.log("Values did not match.") - } + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ } () }) }) -describe("Nullable.isNullable", () => { - test("Nullable.isNullable", () => { +describe("Belt_MutableSet.removeMany", () => { + test("Belt_MutableSet.removeMany", () => { module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - // Check if asNullable is not null or undefined - switch asNullable->Nullable.isNullable { - | true => assert(false) - | false => assert(true) - } + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ } () }) }) -describe("Nullable.undefined", () => { - test("Nullable.undefined", () => { +describe("Belt_MapString.findFirstBy", () => { + test("Belt_MapString.findFirstBy", () => { module Test = { - Console.log(undefined) // Logs `undefined` to the console. - } - () - }) -}) + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) -describe("Nullable.null", () => { - test("Nullable.null", () => { - module Test = { - Console.log(Nullable.null) // Logs `null` to the console. + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Math.Int.random", () => { - test("Math.Int.random", () => { +describe("Belt_List.forEachWithIndex", () => { + test("Belt_List.forEachWithIndex", () => { module Test = { - Math.Int.random(2, 5) == 4 - Math.Int.random(505, 2000) == 1276 - Math.Int.random(-7, -2) == -4 + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ } () }) }) -describe("Math.Int.ceil", () => { - test("Math.Int.ceil", () => { +describe("Belt.Array.reduceWithIndex", () => { + test("Belt.Array.reduceWithIndex", () => { module Test = { - Math.Int.ceil(3.7) == 4 - Math.Int.ceil(3.0) == 3 - Math.Int.ceil(-3.1) == -3 + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Math.Int.floor", () => { - test("Math.Int.floor", () => { +describe("Belt.List.forEachWithIndex", () => { + test("Belt.List.forEachWithIndex", () => { module Test = { - Math.Int.floor(3.7) == 3 - Math.Int.floor(3.0) == 3 - Math.Int.floor(-3.1) == -4 + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ } () }) }) -describe("Math.Int.sign", () => { - test("Math.Int.sign", () => { +describe("Belt.MutableSet.removeMany", () => { + test("Belt.MutableSet.removeMany", () => { module Test = { - Math.Int.sign(3) // 1 - Math.Int.sign(-3) // -1 - Math.Int.sign(0) // 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ } () }) }) -describe("Math.Int.pow", () => { - test("Math.Int.pow", () => { +describe("Belt.HashMap.valuesToArray", () => { + test("Belt.HashMap.valuesToArray", () => { module Test = { - Math.Int.pow(2, ~exp=4) // 16 - Math.Int.pow(3, ~exp=4) // 81 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] } () }) }) -describe("Math.Int.maxMany", () => { - test("Math.Int.maxMany", () => { +describe("Belt.Option.mapWithDefault", () => { + test("Belt.Option.mapWithDefault", () => { module Test = { - Math.Int.maxMany([1, 2]) // 2 - Math.Int.maxMany([-1, -2]) // -1 - Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ + + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ } () }) }) -describe("Math.Int.max", () => { - test("Math.Int.max", () => { +describe("Belt.Option.getWithDefault", () => { + test("Belt.Option.getWithDefault", () => { module Test = { - Math.Int.max(1, 2) // 2 - Math.Int.max(-1, -2) // -1 + Belt.Option.getWithDefault(None, "Banana") /* Banana */ + + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ + + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ } () }) }) -describe("Math.Int.minMany", () => { - test("Math.Int.minMany", () => { +describe("Belt.Result.mapWithDefault", () => { + test("Belt.Result.mapWithDefault", () => { module Test = { - Math.Int.minMany([1, 2]) // 1 - Math.Int.minMany([-1, -2]) // -2 - Math.Int.minMany([])->Int.toFloat->Float.isFinite // false + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 } () }) }) -describe("Math.Int.min", () => { - test("Math.Int.min", () => { +describe("Belt.Result.getWithDefault", () => { + test("Belt.Result.getWithDefault", () => { module Test = { - Math.Int.min(1, 2) // 1 - Math.Int.min(-1, -2) // -2 + Belt.Result.getWithDefault(Ok(42), 0) == 42 + + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 } () }) }) -describe("Math.Int.imul", () => { - test("Math.Int.imul", () => { +describe("Belt.Set.Dict.minUndefined", () => { + test("Belt.Set.Dict.minUndefined", () => { module Test = { - Math.Int.imul(3, 4) // 12 - Math.Int.imul(-5, 12) // 60 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("Math.Int.clz32", () => { - test("Math.Int.clz32", () => { +describe("Belt.Set.Dict.maxUndefined", () => { + test("Belt.Set.Dict.maxUndefined", () => { module Test = { - // 00000000000000000000000000000001 - Math.Int.clz32(1) // 31 - // 00000000000000000000000000000100 - Math.Int.clz32(4) // 29 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ } () }) }) -describe("Math.Int.abs", () => { - test("Math.Int.abs", () => { +describe("Belt_Array.reduceWithIndex", () => { + test("Belt_Array.reduceWithIndex", () => { module Test = { - Math.Int.abs(-2) // 2 - Math.Int.abs(3) // 3 + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Math.Constants.sqrt2", () => { - test("Math.Constants.sqrt2", () => { +describe("Belt_HashMap.valuesToArray", () => { + test("Belt_HashMap.valuesToArray", () => { module Test = { - Math.Constants.sqrt2 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] } () }) }) -describe("Math.Constants.sqrt1_2", () => { - test("Math.Constants.sqrt1_2", () => { +describe("Array.reduceRightWithIndex", () => { + test("Array.reduceRightWithIndex", () => { module Test = { - Math.Constants.sqrt1_2 + Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceRightWithIndex( + [], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{}) } () }) }) -describe("Math.Constants.pi", () => { - test("Math.Constants.pi", () => { +describe("Pervasives.setIntervalFloat", () => { + test("Pervasives.setIntervalFloat", () => { module Test = { - Math.Constants.pi + // Log to the console ever 2 seconds (200 milliseconds). + let intervalId = setIntervalFloat( + () => { + Console.log("This prints every 200 ms") + }, + 200., + ) + + // Stop the interval after 500 ms + let timeoutId = setTimeoutFloat( + () => { + clearInterval(intervalId) + }, + 500.0, + ) } () }) }) -describe("Math.Constants.log10e", () => { - test("Math.Constants.log10e", () => { +describe("JSON.stringifyAnyWithIndent", () => { + test("JSON.stringifyAnyWithIndent", () => { module Test = { - Math.Constants.log10e + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAnyWithIndent(2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Math.Constants.log2e", () => { - test("Math.Constants.log2e", () => { +describe("JSON.stringifyAnyWithFilter", () => { + test("JSON.stringifyAnyWithFilter", () => { module Test = { - Math.Constants.log2e + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Math.Constants.ln10", () => { - test("Math.Constants.ln10", () => { +describe("Belt_internalSetString.A.eq", () => { + test("Belt_internalSetString.A.eq", () => { module Test = { - Math.Constants.ln10 + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Math.Constants.ln2", () => { - test("Math.Constants.ln2", () => { +describe("Belt_internalMapString.A.eq", () => { + test("Belt_internalMapString.A.eq", () => { module Test = { - Math.Constants.ln2 + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Math.Constants.e", () => { - test("Math.Constants.e", () => { +describe("Belt_internalMapInt.A.range", () => { + test("Belt_internalMapInt.A.range", () => { module Test = { - Math.Constants.e + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Math.trunc", () => { - test("Math.trunc", () => { +describe("Belt_internalMapInt.A.zipBy", () => { + test("Belt_internalMapInt.A.zipBy", () => { module Test = { - Math.trunc(0.123) // 0.0 - Math.trunc(1.999) // 1.0 - Math.trunc(13.37) // 13.0 - Math.trunc(42.84) // 42.0 + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Math.tanh", () => { - test("Math.tanh", () => { +describe("Belt_internalMapInt.A.unzip", () => { + test("Belt_internalMapInt.A.unzip", () => { module Test = { - Math.tanh(-0.0) // -0.0 - Math.tanh(0.0) // 0.0 - Math.tanh(1.0) // 0.7615941559557649 + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Math.tan", () => { - test("Math.tan", () => { +describe("Belt_internalMapInt.A.slice", () => { + test("Belt_internalMapInt.A.slice", () => { module Test = { - Math.tan(-0.0) // -0.0 - Math.tan(0.0) // 0.0 - Math.tan(1.0) // 1.5574077246549023 + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Math.sqrt", () => { - test("Math.sqrt", () => { +describe("Belt_internalMapInt.A.getBy", () => { + test("Belt_internalMapInt.A.getBy", () => { module Test = { - Math.sqrt(-1.0)->Float.isNaN // true - Math.sqrt(-0.0) // -0.0 - Math.sqrt(0.0) // 0.0 - Math.sqrt(1.0) // 1.0 - Math.sqrt(9.0) // 3.0 + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Math.sinh", () => { - test("Math.sinh", () => { +describe("Belt_internalMapInt.A.every", () => { + test("Belt_internalMapInt.A.every", () => { module Test = { - Math.sinh(-0.0) // -0.0 - Math.sinh(0.0) // 0.0 - Math.sinh(1.0) // 1.1752011936438014 + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Math.sin", () => { - test("Math.sin", () => { +describe("Belt_internalMapInt.A.some2", () => { + test("Belt_internalMapInt.A.some2", () => { module Test = { - Math.sin(-0.0) // -0.0 - Math.sin(0.0) // 0.0 - Math.sin(1.0) // 0.8414709848078965 + 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 } () }) }) -describe("Math.sign", () => { - test("Math.sign", () => { +describe("Belt_internalSetInt.A.range", () => { + test("Belt_internalSetInt.A.range", () => { module Test = { - Math.sign(3.0) // 1.0 - Math.sign(-3.0) // 1.0 - Math.sign(0.0) // 0.0 + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Math.round", () => { - test("Math.round", () => { +describe("Belt_internalSetInt.A.zipBy", () => { + test("Belt_internalSetInt.A.zipBy", () => { module Test = { - Math.round(-20.5) // -20.0 - Math.round(-0.1) // -0.0 - Math.round(0.0) // 0.0 - Math.round(-0.0) // -0.0 + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Math.random", () => { - test("Math.random", () => { +describe("Belt_internalSetInt.A.unzip", () => { + test("Belt_internalSetInt.A.unzip", () => { module Test = { - Math.random() + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Math.pow", () => { - test("Math.pow", () => { +describe("Belt_internalSetInt.A.slice", () => { + test("Belt_internalSetInt.A.slice", () => { module Test = { - Math.pow(2.0, ~exp=4.0) // 16.0 - Math.pow(3.0, ~exp=4.0) // 81.0 + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Math.maxMany", () => { - test("Math.maxMany", () => { +describe("Belt_internalSetInt.A.getBy", () => { + test("Belt_internalSetInt.A.getBy", () => { module Test = { - Math.maxMany([1.0, 2.0]) // 2.0 - Math.maxMany([-1.0, -2.0]) // -1.0 - Math.maxMany([])->Float.isFinite // false + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Math.max", () => { - test("Math.max", () => { +describe("Belt_internalSetInt.A.every", () => { + test("Belt_internalSetInt.A.every", () => { module Test = { - Math.max(1.0, 2.0) // 2.0 - Math.max(-1.0, -2.0) // -1.0 + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Math.minMany", () => { - test("Math.minMany", () => { +describe("Belt_internalSetInt.A.some2", () => { + test("Belt_internalSetInt.A.some2", () => { module Test = { - Math.minMany([1.0, 2.0]) // 1.0 - Math.minMany([-1.0, -2.0]) // -2.0 - Math.minMany([])->Float.isFinite // false + 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 } () }) }) -describe("Math.min", () => { - test("Math.min", () => { +describe("Belt_Map.String.findFirstBy", () => { + test("Belt_Map.String.findFirstBy", () => { module Test = { - Math.min(1.0, 2.0) // 1.0 - Math.min(-1.0, -2.0) // -2.0 + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Math.log2", () => { - test("Math.log2", () => { +describe("Belt.Array.forEachWithIndex", () => { + test("Belt.Array.forEachWithIndex", () => { module Test = { - Math.log2(-2.0)->Float.isNaN // true - Math.log2(-0.0)->Float.isFinite // false - Math.log2(0.0)->Float.isFinite // false - Math.log2(1.0) // 0.0 + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Math.log10", () => { - test("Math.log10", () => { +describe("Belt.HashMap.keepMapInPlace", () => { + test("Belt.HashMap.keepMapInPlace", () => { module Test = { - Math.log10(-2.0)->Float.isNaN // true - Math.log10(-0.0)->Float.isFinite // false - Math.log10(0.0)->Float.isFinite // false - Math.log10(1.0) // 0 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) } () }) }) -describe("Math.log1p", () => { - test("Math.log1p", () => { - module Test = { - Math.log1p(-2.0)->Float.isNaN // true - Math.log1p(-1.0)->Float.isFinite // false - Math.log1p(-0.0) // -0 - } - () - }) -}) - -describe("Math.log", () => { - test("Math.log", () => { +describe("Belt.Map.String.findFirstBy", () => { + test("Belt.Map.String.findFirstBy", () => { module Test = { - Math.log(-1.0)->Float.isNaN // true - Math.log(-0.0)->Float.isFinite // false - Math.log(0.0)->Float.isFinite // false - Math.log(1.0) // 0 + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Math.hypotMany", () => { - test("Math.hypotMany", () => { +describe("Belt_Array.forEachWithIndex", () => { + test("Belt_Array.forEachWithIndex", () => { module Test = { - Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 - Math.hypotMany([]) // 0.0 + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Math.hypot", () => { - test("Math.hypot", () => { +describe("Belt_HashMap.keepMapInPlace", () => { + test("Belt_HashMap.keepMapInPlace", () => { module Test = { - Math.hypot(3.0, 4.0) // 5.0 - Math.hypot(3.0, 5.0) // 5.8309518948453 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) } () }) }) -describe("Math.fround", () => { - test("Math.fround", () => { +describe("Int.toPrecisionWithPrecision", () => { + test("Int.toPrecisionWithPrecision", () => { module Test = { - Math.fround(5.5) == 5.5 - Math.fround(5.05) == 5.050000190734863 + Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" } () }) }) -describe("Math.floor", () => { - test("Math.floor", () => { +describe("Belt_internalSetString.A.get", () => { + test("Belt_internalSetString.A.get", () => { module Test = { - Math.floor(-45.95) // -46.0 - Math.floor(-45.05) // -46.0 - Math.floor(-0.0) // -0.0 + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Math.expm1", () => { - test("Math.expm1", () => { +describe("Belt_internalSetString.A.zip", () => { + test("Belt_internalSetString.A.zip", () => { module Test = { - Math.expm1(-1.0) // -0.6321205588285577 - Math.expm1(-0.0) // -0 + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Math.exp", () => { - test("Math.exp", () => { +describe("Belt_internalSetString.A.map", () => { + test("Belt_internalSetString.A.map", () => { module Test = { - Math.exp(-1.0) // 0.36787944117144233 - Math.exp(0.0) // 1.0 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Math.cosh", () => { - test("Math.cosh", () => { +describe("Belt_internalSetString.A.cmp", () => { + test("Belt_internalSetString.A.cmp", () => { module Test = { - Math.cosh(-1.0) // 1.5430806348152437 - Math.cosh(-0.0) // 1.0 - Math.cosh(0.0) // 1.0 + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Math.cos", () => { - test("Math.cos", () => { +describe("Belt_internalMapString.A.get", () => { + test("Belt_internalMapString.A.get", () => { module Test = { - Math.cos(-0.0) // 1.0 - Math.cos(0.0) // 1.0 - Math.cos(1.0) // 0.5403023058681398 + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Math.ceil", () => { - test("Math.ceil", () => { +describe("Belt_internalMapString.A.zip", () => { + test("Belt_internalMapString.A.zip", () => { module Test = { - Math.ceil(3.1) == 4.0 - Math.ceil(3.0) == 3.0 - Math.ceil(-3.1) == -3.0 - Math.ceil(2_150_000_000.3) == 2_150_000_001.0 + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Math.cbrt", () => { - test("Math.cbrt", () => { +describe("Belt_internalMapString.A.map", () => { + test("Belt_internalMapString.A.map", () => { module Test = { - Math.cbrt(-1.0) // -1.0 - Math.cbrt(-0.0) // -0.0 - Math.cbrt(0.0) // 0.0 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Math.atan2", () => { - test("Math.atan2", () => { +describe("Belt_internalMapString.A.cmp", () => { + test("Belt_internalMapString.A.cmp", () => { module Test = { - Math.atan2(~y=0.0, ~x=10.0) == 0.0 - Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 - Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 - Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Math.atanh", () => { - test("Math.atanh", () => { +describe("Belt_internalMapInt.A.length", () => { + test("Belt_internalMapInt.A.length", () => { module Test = { - Math.atanh(-2.0)->Float.isNaN // true - Math.atanh(-1.0)->Float.isFinite // false - Math.atanh(-0.0) // -0.0 - Math.atanh(0.0) // 0.0 - Math.atanh(0.5) // 0.5493061443340548 + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Math.atan", () => { - test("Math.atan", () => { +describe("Belt_internalMapInt.A.makeBy", () => { + test("Belt_internalMapInt.A.makeBy", () => { module Test = { - Math.atan(-0.0) // -0.0 - Math.atan(0.0) // 0.0 - Math.atan(1.0) // 0.7853981633974483 + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Math.asinh", () => { - test("Math.asinh", () => { +describe("Belt_internalMapInt.A.concat", () => { + test("Belt_internalMapInt.A.concat", () => { module Test = { - Math.asinh(-1.0) // -0.881373587019543 - Math.asinh(-0.0) // -0.0 + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Math.asin", () => { - test("Math.asin", () => { +describe("Belt_internalMapInt.A.reduce", () => { + test("Belt_internalMapInt.A.reduce", () => { module Test = { - Math.asin(-1.0) // -1.5707963267948966 - Math.asin(-2.0)->Float.isNaN // true + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Math.acosh", () => { - test("Math.acosh", () => { +describe("Belt_internalMapInt.A.every2", () => { + test("Belt_internalMapInt.A.every2", () => { module Test = { - Math.acosh(1.0) // 0.0 - Math.acosh(0.5)->Float.isNaN // true + 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 } () }) }) -describe("Math.acos", () => { - test("Math.acos", () => { +describe("Belt_internalSetInt.A.length", () => { + test("Belt_internalSetInt.A.length", () => { module Test = { - Math.acos(-1.0) // 3.141592653589793 - Math.acos(-3.0)->Float.isNaN // true + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Math.abs", () => { - test("Math.abs", () => { +describe("Belt_internalSetInt.A.makeBy", () => { + test("Belt_internalSetInt.A.makeBy", () => { module Test = { - Math.abs(-2.0) // 2.0 - Math.abs(3.0) // 3.0 + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Null.flatMap", () => { - test("Null.flatMap", () => { +describe("Belt_internalSetInt.A.concat", () => { + test("Belt_internalSetInt.A.concat", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Null.make(value + 1) - } else { - Null.null - } + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) - Null.flatMap(Null.make(-4), addIfAboveOne) // null - Null.flatMap(Null.null, addIfAboveOne) // null + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Null.mapOr", () => { - test("Null.mapOr", () => { +describe("Belt_internalSetInt.A.reduce", () => { + test("Belt_internalSetInt.A.reduce", () => { module Test = { - let someValue = Null.make(3) - someValue->Null.mapOr(0, x => x + 5) // 8 + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - let noneValue = Null.null - noneValue->Null.mapOr(0, x => x + 5) // 0 + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Null.map", () => { - test("Null.map", () => { +describe("Belt_internalSetInt.A.every2", () => { + test("Belt_internalSetInt.A.every2", () => { module Test = { - Null.map(Null.make(3), x => x * x) // Null.make(9) - Null.map(Null.null, x => x * x) // null + 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 } () }) }) -describe("Null.forEach", () => { - test("Null.forEach", () => { +describe("Belt_MutableSet.minUndefined", () => { + test("Belt_MutableSet.minUndefined", () => { module Test = { - Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" - Null.forEach(Null.null, x => Console.log(x)) // logs nothing - } - () - }) -}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) -describe("Null.getUnsafe", () => { - test("Null.getUnsafe", () => { - module Test = { - Null.getUnsafe(Null.make(3)) == 3 - Null.getUnsafe(Null.null) // Raises an error + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ } () }) }) -describe("Null.getExn", () => { - test("Null.getExn", () => { +describe("Belt_MutableSet.maxUndefined", () => { + test("Belt_MutableSet.maxUndefined", () => { module Test = { - Null.getExn(Null.make(3))->assertEqual(3) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch Null.getExn(%raw("'ReScript'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "ReScript") - } + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - switch Null.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ } () }) }) -describe("Null.getOr", () => { - test("Null.getOr", () => { +describe("Belt.Array.makeUninitialized", () => { + test("Belt.Array.makeUninitialized", () => { module Test = { - Null.getOr(Null.null, "Banana") // Banana - Null.getOr(Null.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") + let arr: array> = Belt.Array.makeUninitialized(5) - Null.make("Jane")->Null.toOption->greet // "Greetings Jane" - Null.null->Null.toOption->greet // "Greetings Anonymous" + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Null.fromOption", () => { - test("Null.fromOption", () => { +describe("Belt.MutableSet.minUndefined", () => { + test("Belt.MutableSet.minUndefined", () => { module Test = { - let optString: option = None - let asNull = optString->Null.fromOption // Null.t - Console.log(asNull == Null.null) // Logs `true` to the console. + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ } () }) }) -describe("Null.toOption", () => { - test("Null.toOption", () => { +describe("Belt.MutableSet.maxUndefined", () => { + test("Belt.MutableSet.maxUndefined", () => { module Test = { - let nullStr = Null.make("Hello") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch nullStr->Null.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ } () }) }) -describe("Null.make", () => { - test("Null.make", () => { +describe("Belt_Array.makeUninitialized", () => { + test("Belt_Array.makeUninitialized", () => { module Test = { - let myStr = "Hello" - let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Null.null", () => { - test("Null.null", () => { +describe("String.unsafeReplaceRegExpBy0", () => { + test("String.unsafeReplaceRegExpBy0", () => { module Test = { - Console.log(null) // Logs `null` to the console. + let str = "beautiful vowels" + let re = /[aeiou]/g + let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) + String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" } () }) }) -describe("Null.asNullable", () => { - test("Null.asNullable", () => { +describe("String.unsafeReplaceRegExpBy1", () => { + test("String.unsafeReplaceRegExpBy1", () => { module Test = { - let nullValue = Null.make("Hello") - let asNullable = nullValue->Null.asNullable // Nullable.t + let str = "Jony is 40" + let re = /(Jony is )\d+/g + let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { + group1 ++ "41" + } + String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" } () }) }) -describe("Object.isExtensible", () => { - test("Object.isExtensible", () => { +describe("String.unsafeReplaceRegExpBy2", () => { + test("String.unsafeReplaceRegExpBy2", () => { module Test = { - let obj = {"a": 1} - obj->Object.isExtensible // true - obj->Object.preventExtensions->ignore - obj->Object.isExtensible // false + let str = "7 times 6" + let re = /(\d+) times (\d+)/ + let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } + } + String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" } () }) }) -describe("Object.isFrozen", () => { - test("Object.isFrozen", () => { +describe("Pervasives.encodeURIComponent", () => { + test("Pervasives.encodeURIComponent", () => { module Test = { - let point = {"x": 1, "y": 3}->Object.freeze - let pointIsFrozen = point->Object.isFrozen // true - let fruit = {"name": "Apple"} - let fruitIsFrozen = fruit->Object.isFrozen // false + Console.log(encodeURIComponent("array=[someValue]")) + // Logs "array%3D%5BsomeValue%5D" to the console. } () }) }) -describe("Object.isSealed", () => { - test("Object.isSealed", () => { +describe("Pervasives.decodeURIComponent", () => { + test("Pervasives.decodeURIComponent", () => { module Test = { - let point = {"x": 1, "y": 3}->Object.seal - let pointIsSealed = point->Object.isSealed // true - let fruit = {"name": "Apple"} - let fruitIsSealed = fruit->Object.isSealed // false + Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) + // Logs "array=[someValue]" to the console. } () }) }) -describe("Object.freeze", () => { - test("Object.freeze", () => { +describe("JSON.stringifyAnyWithReplacer", () => { + test("JSON.stringifyAnyWithReplacer", () => { module Test = { - let obj = {"a": 1} - obj->Object.set("a", 2) // succeeds - obj->Object.freeze->ignore + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - try { - obj->Object.set("a", 3) // fails - } catch { - | Exn.Error(_) => assert(true) + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) | _ => assert(false) } } @@ -16330,1981 +16487,1824 @@ describe("Object.freeze", () => { }) }) -describe("Object.preventExtensions", () => { - test("Object.preventExtensions", () => { +describe("Date.toLocaleStringWithLocale", () => { + test("Date.toLocaleStringWithLocale", () => { module Test = { - let obj = {"a": 1} - obj->Object.set("b", 2) // succeeds - obj->Object.preventExtensions->ignore - try { - obj->Object.set("c", 3) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } + Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log + // 2/19/2023, 3:40:00 PM } () }) }) -describe("Object.seal", () => { - test("Object.seal", () => { +describe("Belt_internalSetString.A.fill", () => { + test("Belt_internalSetString.A.fill", () => { module Test = { - let point = {"x": 1, "y": 2} - point->Object.set("x", -7) // succeeds - point->Object.seal->ignore + let arr = Belt.Array.makeBy(5, i => i) - try { - point->Object.set("z", 9) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - point->Object.set("x", 13) // succeeds + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Object.hasOwnProperty", () => { - test("Object.hasOwnProperty", () => { +describe("Belt_internalSetString.A.blit", () => { + test("Belt_internalSetString.A.blit", () => { module Test = { - let point = {"x": 1, "y": 2} - {"a": 1}->Object.hasOwnProperty("a") // true - {"a": 1}->Object.hasOwnProperty("b") // false - {"a": 1}->Object.hasOwnProperty("toString") // false + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Object.keysToArray", () => { - test("Object.keysToArray", () => { +describe("Belt_internalSetString.A.some", () => { + test("Belt_internalSetString.A.some", () => { module Test = { - {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] - {"a": None}->Object.keysToArray // ["a"] - Object.make()->Object.keysToArray // [] + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Object.set", () => { - test("Object.set", () => { +describe("Belt_internalMapString.A.fill", () => { + test("Belt_internalMapString.A.fill", () => { module Test = { - {"a": 1}->Object.set("a", 2) // {"a": 2} - {"a": 1}->Object.set("a", None) // {"a": None} - {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Object.getSymbol", () => { - test("Object.getSymbol", () => { +describe("Belt_internalMapString.A.blit", () => { + test("Belt_internalMapString.A.blit", () => { module Test = { - let fruit = Symbol.make("fruit") - let x = Object.make() - x->Object.setSymbol(fruit, "banana") - x->Object.getSymbol(fruit) // Some("banana") + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Object.get", () => { - test("Object.get", () => { +describe("Belt_internalMapString.A.some", () => { + test("Belt_internalMapString.A.some", () => { module Test = { - {"a": 1}->Object.get("a") // Some(1) - {"a": 1}->Object.get("b") // None - {"a": undefined}->Object.get("a") // None - {"a": null}->Object.get("a") // Some(null) - {"a": 1}->Object.get("toString")->Option.isSome // true + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Object.assign", () => { - test("Object.assign", () => { +describe("Belt_internalMapInt.A.reverse", () => { + test("Belt_internalMapInt.A.reverse", () => { module Test = { - Object.assign({"a": 1}, {"a": 2}) // {"a": 2} - Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} - Object.assign({"a": 1}, {"a": null}) // {"a": null} + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Object.create", () => { - test("Object.create", () => { +describe("Belt_internalMapInt.A.rangeBy", () => { + test("Belt_internalMapInt.A.rangeBy", () => { module Test = { - let x = {"fruit": "banana"} - let y = Object.create(x) - y->Object.get("fruit") // Some("banana") + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Object.is", () => { - test("Object.is", () => { +describe("Belt_internalMapInt.A.forEach", () => { + test("Belt_internalMapInt.A.forEach", () => { module Test = { - Object.is(25, 13) // false - Object.is("abc", "abc") // true - Object.is(undefined, undefined) // true - Object.is(undefined, null) // false - Object.is(-0.0, 0.0) // false - Object.is(list{1, 2}, list{1, 2}) // false + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - Object.is([1, 2, 3], [1, 2, 3]) // false - [1, 2, 3] == [1, 2, 3] // true - [1, 2, 3] === [1, 2, 3] // false + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - let fruit = {"name": "Apple"} - Object.is(fruit, fruit) // true - Object.is(fruit, {"name": "Apple"}) // false - fruit == {"name": "Apple"} // true - fruit === {"name": "Apple"} // false + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Object.make", () => { - test("Object.make", () => { +describe("Belt_internalMapInt.A.flatMap", () => { + test("Belt_internalMapInt.A.flatMap", () => { module Test = { - let x = Object.make() - x->Object.keysToArray->Array.length // 0 - x->Object.get("toString")->Option.isSome // true + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Option.all", () => { - test("Option.all", () => { +describe("Belt_internalMapInt.A.keepMap", () => { + test("Belt_internalMapInt.A.keepMap", () => { module Test = { - Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) - Option.all([Some(1), None]) // None + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Option.compare", () => { - test("Option.compare", () => { +describe("Belt_internalSetInt.A.reverse", () => { + test("Belt_internalSetInt.A.reverse", () => { module Test = { - let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) - - Option.compare(Some(3), Some(15), clockCompare) // 0. - Option.compare(Some(3), Some(14), clockCompare) // 1. - Option.compare(Some(2), Some(15), clockCompare) // (-1.) - Option.compare(None, Some(15), clockCompare) // (-1.) - Option.compare(Some(14), None, clockCompare) // 1. - Option.compare(None, None, clockCompare) // 0. + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Option.equal", () => { - test("Option.equal", () => { +describe("Belt_internalSetInt.A.rangeBy", () => { + test("Belt_internalSetInt.A.rangeBy", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - open Option + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - equal(Some(3), Some(15), clockEqual) // true - equal(Some(3), None, clockEqual) // false - equal(None, Some(3), clockEqual) // false - equal(None, None, clockEqual) // true + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Option.isNone", () => { - test("Option.isNone", () => { +describe("Belt_internalSetInt.A.forEach", () => { + test("Belt_internalSetInt.A.forEach", () => { module Test = { - Option.isNone(None) // true - Option.isNone(Some(1)) // false + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Option.isSome", () => { - test("Option.isSome", () => { +describe("Belt_internalSetInt.A.flatMap", () => { + test("Belt_internalSetInt.A.flatMap", () => { module Test = { - Option.isSome(None) // false - Option.isSome(Some(1)) // true + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Option.orElse", () => { - test("Option.orElse", () => { +describe("Belt_internalSetInt.A.keepMap", () => { + test("Belt_internalSetInt.A.keepMap", () => { module Test = { - Option.orElse(Some(1812), Some(1066)) == Some(1812) - Option.orElse(None, Some(1066)) == Some(1066) - Option.orElse(None, None) == None + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Option.getOr", () => { - test("Option.getOr", () => { +describe("Belt_SortArray.binarySearchBy", () => { + test("Belt_SortArray.binarySearchBy", () => { module Test = { - Option.getOr(None, "Banana") // Banana - Option.getOr(Some("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - Some("Jane")->greet // "Greetings Jane" - None->greet // "Greetings Anonymous" + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("Option.flatMap", () => { - test("Option.flatMap", () => { +describe("Belt.SortArray.binarySearchBy", () => { + test("Belt.SortArray.binarySearchBy", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - Option.flatMap(Some(2), addIfAboveOne) // Some(3) - Option.flatMap(Some(-4), addIfAboveOne) // None - Option.flatMap(None, addIfAboveOne) // None + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("Option.map", () => { - test("Option.map", () => { +describe("Int.toExponentialWithPrecision", () => { + test("Int.toExponentialWithPrecision", () => { module Test = { - Option.map(Some(3), x => x * x) // Some(9) - Option.map(None, x => x * x) // None + Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" + Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" } () }) }) -describe("Option.mapOr", () => { - test("Option.mapOr", () => { +describe("Float.toPrecisionWithPrecision", () => { + test("Float.toPrecisionWithPrecision", () => { module Test = { - let someValue = Some(3) - someValue->Option.mapOr(0, x => x + 5) // 8 - - let noneValue = None - noneValue->Option.mapOr(0, x => x + 5) // 0 + Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" } () }) }) -describe("Option.getUnsafe", () => { - test("Option.getUnsafe", () => { +describe("Belt_internalSetString.A.range", () => { + test("Belt_internalSetString.A.range", () => { module Test = { - Option.getUnsafe(Some(3)) == 3 - Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Option.getExn", () => { - test("Option.getExn", () => { - module Test = { - Option.getExn(Some(3))->assertEqual(3) - - switch Option.getExn(None) { - | exception _ => assert(true) - | _ => assert(false) - } - - switch Option.getExn(None, ~message="was None!") { - | exception _ => assert(true) // Raises an Error with the message "was None!" - | _ => assert(false) - } - } - () - }) -}) - -describe("Option.forEach", () => { - test("Option.forEach", () => { +describe("Belt_internalSetString.A.zipBy", () => { + test("Belt_internalSetString.A.zipBy", () => { module Test = { - Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" - Option.forEach(None, x => Console.log(x)) // returns () + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Option.filter", () => { - test("Option.filter", () => { +describe("Belt_internalSetString.A.unzip", () => { + test("Belt_internalSetString.A.unzip", () => { module Test = { - Option.filter(Some(10), x => x > 5) // Some(10) - Option.filter(Some(4), x => x > 5) // None - Option.filter(None, x => x > 5) // None - } - () - }) -}) + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) -describe("Pervasives.assertEqual", () => { - test("Pervasives.assertEqual", () => { - module Test = { - list{1, 2} - ->List.tailExn - ->assertEqual(list{2}) + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Pervasives.import", () => { - test("Pervasives.import", () => { +describe("Belt_internalSetString.A.slice", () => { + test("Belt_internalSetString.A.slice", () => { module Test = { - @send external indexOf: (array<'a>, 'a) => int = "indexOf" + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - let indexOfOpt = (arr, item) => - switch arr->indexOf(item) { - | -1 => None - | index => Some(index) - } + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - let main = async () => { - let indexOfOpt = await import(Array.indexOfOpt) - let index = indexOfOpt([1, 2], 2) - Console.log(index) - } + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Pervasives.decodeURIComponent", () => { - test("Pervasives.decodeURIComponent", () => { +describe("Belt_internalSetString.A.getBy", () => { + test("Belt_internalSetString.A.getBy", () => { module Test = { - Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) - // Logs "array=[someValue]" to the console. + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Pervasives.encodeURIComponent", () => { - test("Pervasives.encodeURIComponent", () => { +describe("Belt_internalSetString.A.every", () => { + test("Belt_internalSetString.A.every", () => { module Test = { - Console.log(encodeURIComponent("array=[someValue]")) - // Logs "array%3D%5BsomeValue%5D" to the console. - } - () - }) -}) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true -describe("Pervasives.decodeURI", () => { - test("Pervasives.decodeURI", () => { - module Test = { - Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) - // Logs "https://rescript-lang.org?array=[someValue]" to the console. + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Pervasives.encodeURI", () => { - test("Pervasives.encodeURI", () => { +describe("Belt_internalSetString.A.some2", () => { + test("Belt_internalSetString.A.some2", () => { module Test = { - Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) - // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. + 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 } () }) }) -describe("Pervasives.clearInterval", () => { - test("Pervasives.clearInterval", () => { +describe("Belt_internalMapString.A.range", () => { + test("Belt_internalMapString.A.range", () => { module Test = { - let intervalId = setInterval( - () => { - Console.log("This prints in 100 ms") - }, - 100, - ) + Belt.Array.range(0, 3) == [0, 1, 2, 3] - // Stop the interval after 500 ms - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Pervasives.setIntervalFloat", () => { - test("Pervasives.setIntervalFloat", () => { +describe("Belt_internalMapString.A.zipBy", () => { + test("Belt_internalMapString.A.zipBy", () => { module Test = { - // Log to the console ever 2 seconds (200 milliseconds). - let intervalId = setIntervalFloat( - () => { - Console.log("This prints every 200 ms") - }, - 200., - ) - - // Stop the interval after 500 ms - let timeoutId = setTimeoutFloat( - () => { - clearInterval(intervalId) - }, - 500.0, - ) + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Pervasives.setInterval", () => { - test("Pervasives.setInterval", () => { +describe("Belt_internalMapString.A.unzip", () => { + test("Belt_internalMapString.A.unzip", () => { module Test = { - // Log to the console ever 200 ms (200 milliseconds). - let intervalId = setInterval( - () => { - Console.log("This prints every 200 ms.") - }, - 200, - ) + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Pervasives.clearTimeout", () => { - test("Pervasives.clearTimeout", () => { +describe("Belt_internalMapString.A.slice", () => { + test("Belt_internalMapString.A.slice", () => { module Test = { - let timeoutId = setTimeout( - () => { - Console.log("This prints in 2 seconds.") - }, - 2000, - ) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. - clearTimeout(timeoutId) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Pervasives.setTimeoutFloat", () => { - test("Pervasives.setTimeoutFloat", () => { +describe("Belt_internalMapString.A.getBy", () => { + test("Belt_internalMapString.A.getBy", () => { module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeoutFloat( - () => { - Console.log("This prints in 200 ms.") - }, - 200., - ) + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Pervasives.setTimeout", () => { - test("Pervasives.setTimeout", () => { +describe("Belt_internalMapString.A.every", () => { + test("Belt_internalMapString.A.every", () => { module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeout( - () => { - Console.log("This prints in 200 ms.") - }, - 200, - ) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Promise.allSettled", () => { - test("Promise.allSettled", () => { +describe("Belt_internalMapString.A.some2", () => { + test("Belt_internalMapString.A.some2", () => { module Test = { - open Promise - - exception TestError(string) - - let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - allSettled(promises) - ->then( - results => { - results->Array.forEach( - result => { - switch result { - | Fulfilled({value: num}) => Console.log2("Number: ", num) - | Rejected({reason}) => Console.log(reason) - } - }, - ) + Belt.Array.some2([], [1], (x, y) => x > y) == false - resolve() - }, - ) - ->ignore + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Promise.all", () => { - test("Promise.all", () => { +describe("Belt_internalMapInt.A.joinWith", () => { + test("Belt_internalMapInt.A.joinWith", () => { module Test = { - open Promise - let promises = [resolve(1), resolve(2), resolve(3)] - - all(promises) - ->then( - results => { - results->Array.forEach( - num => { - Console.log2("Number: ", num) - }, - ) - - resolve() - }, - ) - ->ignore + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Promise.any", () => { - test("Promise.any", () => { +describe("Belt_internalSetInt.A.joinWith", () => { + test("Belt_internalSetInt.A.joinWith", () => { module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - any(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Promise.race", () => { - test("Promise.race", () => { +describe("Belt_internalSetString.A.length", () => { + test("Belt_internalSetString.A.length", () => { module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - race(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Promise.finally", () => { - test("Promise.finally", () => { +describe("Belt_internalSetString.A.makeBy", () => { + test("Belt_internalSetString.A.makeBy", () => { module Test = { - open Promise - exception SomeError(string) - let isDone = ref(false) + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - resolve(5) - ->then( - _ => { - reject(SomeError("test")) - }, - ) - ->then( - v => { - Console.log2("final result", v) - resolve() - }, - ) - ->catch( - _ => { - Console.log("Error handled") - resolve() - }, - ) - ->finally( - () => { - Console.log("finally") - isDone := true - }, - ) - ->then( - () => { - Console.log2("isDone:", isDone.contents) - resolve() - }, - ) - ->ignore + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Promise.thenResolve", () => { - test("Promise.thenResolve", () => { +describe("Belt_internalSetString.A.concat", () => { + test("Belt_internalSetString.A.concat", () => { module Test = { - open Promise - resolve("Anna") - ->thenResolve( - str => { - "Hello " ++ str - }, - ) - ->thenResolve( - str => { - Console.log(str) - }, - ) - ->ignore // Ignore needed for side-effects + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Promise.then", () => { - test("Promise.then", () => { +describe("Belt_internalSetString.A.reduce", () => { + test("Belt_internalSetString.A.reduce", () => { module Test = { - open Promise - resolve(5) - ->then( - num => { - resolve(num + 5) - }, - ) - ->then( - num => { - Console.log2("Your lucky number is: ", num) - resolve() - }, - ) - ->ignore + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Promise.catch", () => { - test("Promise.catch", () => { +describe("Belt_internalSetString.A.every2", () => { + test("Belt_internalSetString.A.every2", () => { module Test = { - open Promise + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - exception SomeError(string) + Belt.Array.every2([], [1], (x, y) => x > y) == true - reject(SomeError("this is an error")) - ->then( - _ => { - Ok("This result will never be returned")->resolve - }, - ) - ->catch( - e => { - let msg = switch e { - | SomeError(msg) => "ReScript error occurred: " ++ msg - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(msg) => "JS exception occurred: " ++ msg - | None => "Some other JS value has been thrown" - } - | _ => "Unexpected error occurred" - } + Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true - Error(msg)->resolve - }, - ) - ->then( - result => { - switch result { - | Ok(r) => Console.log2("Operation successful: ", r) - | Error(msg) => Console.log2("Operation failed: ", msg) - }->resolve - }, - ) - ->ignore // Ignore needed for side-effects + Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false } () }) }) -describe("Promise.make", () => { - test("Promise.make", () => { +describe("Belt_internalMapString.A.length", () => { + test("Belt_internalMapString.A.length", () => { module Test = { - open Promise - - let n = 4 - Promise.make( - (resolve, reject) => { - if n < 5 { - resolve("success") - } else { - reject("failed") - } - }, - ) - ->then( - str => { - Console.log(str)->resolve - }, - ) - ->catch( - _ => { - Console.log("Error occurred") - resolve() - }, - ) - ->ignore + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Promise.reject", () => { - test("Promise.reject", () => { - module Test = { - exception TestError(string) - - TestError("some rejected value") - ->Promise.reject - ->Promise.catch( - v => { - switch v { - | TestError(msg) => assertEqual(msg, "some rejected value") - | _ => assert(false) - } - Promise.resolve() - }, - ) - ->ignore +describe("Belt_internalMapString.A.makeBy", () => { + test("Belt_internalMapString.A.makeBy", () => { + module Test = { + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Promise.resolve", () => { - test("Promise.resolve", () => { +describe("Belt_internalMapString.A.concat", () => { + test("Belt_internalMapString.A.concat", () => { module Test = { - let p = Promise.resolve(5) // promise + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("RegExp.Result.input", () => { - test("RegExp.Result.input", () => { +describe("Belt_internalMapString.A.reduce", () => { + test("Belt_internalMapString.A.reduce", () => { module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - // This below will log the full input string "ReScript is pretty cool, right?" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.input) - } + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("RegExp.Result.matches", () => { - test("RegExp.Result.matches", () => { +describe("Belt_internalMapString.A.every2", () => { + test("Belt_internalMapString.A.every2", () => { module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - // This below will log "ReScript" and "is" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => - switch result->RegExp.Result.matches { - | [firstWord, secondWord] => Console.log2(firstWord, secondWord) - | _ => Console.log("Didn't find exactly two words...") - } - } + 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 } () }) }) -describe("RegExp.Result.fullMatch", () => { - test("RegExp.Result.fullMatch", () => { +describe("Belt_internalMapInt.A.partition", () => { + test("Belt_internalMapInt.A.partition", () => { module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" - } + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("RegExp.unicode", () => { - test("RegExp.unicode", () => { +describe("Belt_internalSetInt.A.partition", () => { + test("Belt_internalSetInt.A.partition", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("RegExp.sticky", () => { - test("RegExp.sticky", () => { +describe("Belt.HashMap.getBucketHistogram", () => { + test("Belt.HashMap.getBucketHistogram", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set + Belt.HashMap.getBucketHistogram(hMap) } () }) }) -describe("RegExp.source", () => { - test("RegExp.source", () => { +describe("Belt_HashMap.getBucketHistogram", () => { + test("Belt_HashMap.getBucketHistogram", () => { module Test = { - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.getBucketHistogram(hMap) } () }) }) -describe("RegExp.multiline", () => { - test("RegExp.multiline", () => { +describe("Float.toExponentialWithPrecision", () => { + test("Float.toExponentialWithPrecision", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") - Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set + Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" + Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" } () }) }) -describe("RegExp.global", () => { - test("RegExp.global", () => { +describe("Float.Constants.positiveInfinity", () => { + test("Float.Constants.positiveInfinity", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set + Float.Constants.positiveInfinity } () }) }) -describe("RegExp.ignoreCase", () => { - test("RegExp.ignoreCase", () => { +describe("Float.Constants.negativeInfinity", () => { + test("Float.Constants.negativeInfinity", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set + Float.Constants.negativeInfinity + } + () + }) +}) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set +describe("Belt_internalSetString.A.reverse", () => { + test("Belt_internalSetString.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("RegExp.setLastIndex", () => { - test("RegExp.setLastIndex", () => { +describe("Belt_internalSetString.A.rangeBy", () => { + test("Belt_internalSetString.A.rangeBy", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - regexp->RegExp.setLastIndex(4) - regexp->RegExp.exec(someStr)->ignore + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("RegExp.lastIndex", () => { - test("RegExp.lastIndex", () => { +describe("Belt_internalSetString.A.forEach", () => { + test("Belt_internalSetString.A.forEach", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - regexp->RegExp.exec(someStr)->ignore + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("RegExp.exec", () => { - test("RegExp.exec", () => { +describe("Belt_internalSetString.A.flatMap", () => { + test("Belt_internalSetString.A.flatMap", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("RegExp.test", () => { - test("RegExp.test", () => { +describe("Belt_internalSetString.A.keepMap", () => { + test("Belt_internalSetString.A.keepMap", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] + } + () + }) +}) - if regexp->RegExp.test("ReScript is cool!") { - Console.log("Yay, there's a word in there.") - } +describe("Belt_internalMapString.A.reverse", () => { + test("Belt_internalMapString.A.reverse", () => { + module Test = { + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("RegExp.fromStringWithFlags", () => { - test("RegExp.fromStringWithFlags", () => { +describe("Belt_internalMapString.A.rangeBy", () => { + test("Belt_internalMapString.A.rangeBy", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("RegExp.fromString", () => { - test("RegExp.fromString", () => { +describe("Belt_internalMapString.A.forEach", () => { + test("Belt_internalMapString.A.forEach", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Result.all", () => { - test("Result.all", () => { +describe("Belt_internalMapString.A.flatMap", () => { + test("Belt_internalMapString.A.flatMap", () => { module Test = { - Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) - Result.all([Ok(1), Error(1)]) // Error(1) + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Result.mapError", () => { - test("Result.mapError", () => { +describe("Belt_internalMapString.A.keepMap", () => { + test("Belt_internalMapString.A.keepMap", () => { module Test = { - let format = n => `Error code: ${n->Int.toString}` - Result.mapError(Error(14), format) // Error("Error code: 14") - Result.mapError(Ok("abc"), format) // Ok("abc") + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Result.forEach", () => { - test("Result.forEach", () => { +describe("Belt_internalMapInt.A.concatMany", () => { + test("Belt_internalMapInt.A.concatMany", () => { module Test = { - Result.forEach(Ok(3), Console.log) // Logs "3", returns () - Result.forEach(Error("x"), Console.log) // Does nothing, returns () + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Result.compare", () => { - test("Result.compare", () => { +describe("Belt_internalMapInt.A.sliceToEnd", () => { + test("Belt_internalMapInt.A.sliceToEnd", () => { module Test = { - let good1 = Ok(59) - - let good2 = Ok(37) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") - - let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) - - Result.compare(Ok(39), Ok(57), mod10cmp) == 1. - - Result.compare(Ok(57), Ok(39), mod10cmp) == -1. - - Result.compare(Ok(39), Error("y"), mod10cmp) == 1. - - Result.compare(Error("x"), Ok(57), mod10cmp) == -1. + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - Result.compare(Error("x"), Error("y"), mod10cmp) == 0. + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Result.equal", () => { - test("Result.equal", () => { +describe("Belt_internalMapInt.A.getIndexBy", () => { + test("Belt_internalMapInt.A.getIndexBy", () => { module Test = { - let good1 = Ok(42) - - let good2 = Ok(32) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) - - Result.equal(good1, good2, mod10equal) == true - - Result.equal(good1, bad1, mod10equal) == false - - Result.equal(bad2, good2, mod10equal) == false - - Result.equal(bad1, bad2, mod10equal) == true + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Result.getOr", () => { - test("Result.getOr", () => { +describe("Belt_internalSetInt.A.concatMany", () => { + test("Belt_internalSetInt.A.concatMany", () => { module Test = { - Result.getOr(Ok(42), 0) == 42 - - Result.getOr(Error("Invalid Data"), 0) == 0 + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Result.flatMap", () => { - test("Result.flatMap", () => { +describe("Belt_internalSetInt.A.sliceToEnd", () => { + test("Belt_internalSetInt.A.sliceToEnd", () => { module Test = { - let recip = x => - if x !== 0.0 { - Ok(1.0 /. x) - } else { - Error("Divide by zero") - } - - Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Result.map", () => { - test("Result.map", () => { +describe("Belt_internalSetInt.A.getIndexBy", () => { + test("Belt_internalSetInt.A.getIndexBy", () => { module Test = { - let f = x => sqrt(Int.toFloat(x)) - - Result.map(Ok(64), f) == Ok(8.0) - - Result.map(Error("Invalid data"), f) == Error("Invalid data") + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Result.mapOr", () => { - test("Result.mapOr", () => { +describe("JSON.stringifyWithFilterAndIndent", () => { + test("JSON.stringifyWithFilterAndIndent", () => { module Test = { - let ok = Ok(42) - Result.mapOr(ok, 0, x => x / 2) == 21 + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let error = Error("Invalid data") - Result.mapOr(error, 0, x => x / 2) == 0 + JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) + // { + // "foo": "bar", + // "someNumber": 42 + // } } () }) }) -describe("Set.toArray", () => { - test("Set.toArray", () => { +describe("Date.toLocaleDateStringWithLocale", () => { + test("Date.toLocaleDateStringWithLocale", () => { module Test = { - let set = Set.fromArray(["apple", "orange", "apple", "banana"]) - set->Set.toArray // ["apple", "orange", "banana"] + Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log + // 2/19/2023 } () }) }) -describe("Set.values", () => { - test("Set.values", () => { +describe("Date.toLocaleTimeStringWithLocale", () => { + test("Date.toLocaleTimeStringWithLocale", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("anotherValue") - - let values = set->Set.values - - // Logs the first value - Console.log(Iterator.next(values).value) - - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(set->Set.values->Iterator.toArray) + Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log + // 3:40:00 PM } () }) }) -describe("Set.forEach", () => { - test("Set.forEach", () => { +describe("Belt_internalSetString.A.joinWith", () => { + test("Belt_internalSetString.A.joinWith", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("someValue2") - - set->Set.forEach( - value => { - Console.log(value) - }, - ) + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Set.has", () => { - test("Set.has", () => { +describe("Belt_internalMapString.A.joinWith", () => { + test("Belt_internalMapString.A.joinWith", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - - switch set->Set.has("someValue") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Set.delete", () => { - test("Set.delete", () => { +describe("Belt.Array.truncateToLengthUnsafe", () => { + test("Belt.Array.truncateToLengthUnsafe", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - let didDeleteValue = set->Set.delete("someValue") - Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted + let arr = ["ant", "bee", "cat", "dog", "elk"] - let didDeleteValue = set->Set.delete("someNonExistantKey") - Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("Set.add", () => { - test("Set.add", () => { +describe("Belt_Array.truncateToLengthUnsafe", () => { + test("Belt_Array.truncateToLengthUnsafe", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("Set.clear", () => { - test("Set.clear", () => { +describe("Belt_internalSetString.A.partition", () => { + test("Belt_internalSetString.A.partition", () => { module Test = { - let set = Set.make() - - set->Set.add("someKey") - set->Set.size // 1 + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - set->Set.clear - set->Set.size // 0 + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Set.size", () => { - test("Set.size", () => { +describe("Belt_internalMapString.A.partition", () => { + test("Belt_internalMapString.A.partition", () => { module Test = { - let set = Set.make() - - set->Set.add("someValue") - set->Set.add("someValue") - set->Set.add("someValue2") + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - let size = set->Set.size // 2 + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Set.fromIterator", () => { - test("Set.fromIterator", () => { +describe("Belt_internalMapInt.A.mapWithIndex", () => { + test("Belt_internalMapInt.A.mapWithIndex", () => { module Test = { - // Let's pretend we have an interator - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + } + () + }) +}) - iterator - ->Set.fromIterator - ->Set.size - ->assertEqual(3) +describe("Belt_internalSetInt.A.mapWithIndex", () => { + test("Belt_internalSetInt.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Set.fromArray", () => { - test("Set.fromArray", () => { +describe("Belt.Array.makeUninitializedUnsafe", () => { + test("Belt.Array.makeUninitializedUnsafe", () => { module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [ReScript, JavaScript, TypeScript] + let arr = Belt.Array.makeUninitializedUnsafe(5) - let set = Set.fromArray(languageRank) // Set.t + Js.log(Belt.Array.getExn(arr, 0)) // undefined - switch set->Set.has(ReScript) { - | true => Console.log("Yay, ReScript is in there!") - | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Set.make", () => { - test("Set.make", () => { +describe("Belt_Array.makeUninitializedUnsafe", () => { + test("Belt_Array.makeUninitializedUnsafe", () => { module Test = { - // You can annotate the type of your set if you want to - let mySet: Set.t = Set.make() + let arr = Belt.Array.makeUninitializedUnsafe(5) - // Or you can let ReScript infer what's in your Set - let set = Set.make() - set->Set.add("Fine name") // Inferred as Set.t + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("String.localeCompare", () => { - test("String.localeCompare", () => { +describe("JSON.stringifyWithReplacerAndIndent", () => { + test("JSON.stringifyWithReplacerAndIndent", () => { module Test = { - String.localeCompare("a", "c") < 0.0 == true - String.localeCompare("a", "a") == 0.0 + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + JSON.stringifyWithReplacerAndIndent(json, replacer, 2) + // { + // "foo": "BAR", + // "hello": "WORLD", + // "someNumber": 42 + // } } () }) }) -describe("String.padEnd", () => { - test("String.padEnd", () => { +describe("Belt_internalSetString.A.concatMany", () => { + test("Belt_internalSetString.A.concatMany", () => { module Test = { - String.padEnd("Hello", 10, ".") == "Hello....." - String.padEnd("abc", 1, "") == "abc" + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("String.padStart", () => { - test("String.padStart", () => { +describe("Belt_internalSetString.A.sliceToEnd", () => { + test("Belt_internalSetString.A.sliceToEnd", () => { module Test = { - String.padStart("abc", 5, " ") == " abc" - String.padStart("abc", 6, "123465") == "123abc" + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("String.trimEnd", () => { - test("String.trimEnd", () => { +describe("Belt_internalSetString.A.getIndexBy", () => { + test("Belt_internalSetString.A.getIndexBy", () => { module Test = { - String.trimEnd(" Hello world! ") == " Hello world!" - String.trimEnd(" Hello world! ") == " Hello world!" + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("String.trimStart", () => { - test("String.trimStart", () => { +describe("Belt_internalMapString.A.concatMany", () => { + test("Belt_internalMapString.A.concatMany", () => { module Test = { - String.trimStart(" Hello world! ") == "Hello world! " - String.trimStart(" Hello world! ") == "Hello world! " + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("String.trim", () => { - test("String.trim", () => { +describe("Belt_internalMapString.A.sliceToEnd", () => { + test("Belt_internalMapString.A.sliceToEnd", () => { module Test = { - String.trim(" abc def ") == "abc def" - String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("String.toUpperCase", () => { - test("String.toUpperCase", () => { +describe("Belt_internalMapString.A.getIndexBy", () => { + test("Belt_internalMapString.A.getIndexBy", () => { module Test = { - String.toUpperCase("abc") == "ABC" - String.toUpperCase(`Straße`) == `STRASSE` - String.toUpperCase(`πς`) == `ΠΣ` + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("String.toLowerCase", () => { - test("String.toLowerCase", () => { +describe("Belt_internalMapInt.A.keepWithIndex", () => { + test("Belt_internalMapInt.A.keepWithIndex", () => { module Test = { - String.toLowerCase("ABC") == "abc" - String.toLowerCase(`ΣΠ`) == `σπ` - String.toLowerCase(`ΠΣ`) == `πς` + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("String.substringToEnd", () => { - test("String.substringToEnd", () => { +describe("Belt_internalMapInt.A.reduceReverse", () => { + test("Belt_internalMapInt.A.reduceReverse", () => { module Test = { - String.substringToEnd("playground", ~start=4) == "ground" - String.substringToEnd("playground", ~start=-3) == "playground" - String.substringToEnd("playground", ~start=12) == "" + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("String.substring", () => { - test("String.substring", () => { +describe("Belt_internalSetInt.A.keepWithIndex", () => { + test("Belt_internalSetInt.A.keepWithIndex", () => { module Test = { - String.substring("playground", ~start=3, ~end=6) == "ygr" - String.substring("playground", ~start=6, ~end=3) == "ygr" - String.substring("playground", ~start=4, ~end=12) == "ground" + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("String.startsWithFrom", () => { - test("String.startsWithFrom", () => { +describe("Belt_internalSetInt.A.reduceReverse", () => { + test("Belt_internalSetInt.A.reduceReverse", () => { module Test = { - String.startsWithFrom("BuckleScript", "kle", 3) == true - String.startsWithFrom("BuckleScript", "", 3) == true - String.startsWithFrom("JavaScript", "Buckle", 2) == false + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("String.startsWith", () => { - test("String.startsWith", () => { +describe("Belt_SortArray.strictlySortedLength", () => { + test("Belt_SortArray.strictlySortedLength", () => { module Test = { - String.startsWith("BuckleScript", "Buckle") == true - String.startsWith("BuckleScript", "") == true - String.startsWith("JavaScript", "Buckle") == false + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("String.splitByRegExpAtMost", () => { - test("String.splitByRegExpAtMost", () => { +describe("Belt.SortArray.strictlySortedLength", () => { + test("Belt.SortArray.strictlySortedLength", () => { module Test = { - String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ - Some("Hello"), - Some("World."), - Some("How"), - ] + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("String.splitByRegExp", () => { - test("String.splitByRegExp", () => { +describe("JSON.stringifyAnyWithFilterAndIndent", () => { + test("JSON.stringifyAnyWithFilterAndIndent", () => { module Test = { - String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) + + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("String.splitAtMost", () => { - test("String.splitAtMost", () => { +describe("Belt_internalMapInt.A.reverseInPlace", () => { + test("Belt_internalMapInt.A.reverseInPlace", () => { module Test = { - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ - "ant", - "bee", - "cat", - "dog", - "elk", - ] + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("String.split", () => { - test("String.split", () => { +describe("Belt_internalMapInt.A.reduceReverse2", () => { + test("Belt_internalMapInt.A.reduceReverse2", () => { module Test = { - String.split("2018-01-02", "-") == ["2018", "01", "02"] - String.split("a,b,,c", ",") == ["a", "b", "", "c"] - String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] - String.split("has-no-delimiter", ";") == ["has-no-delimiter"] + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("String.sliceToEnd", () => { - test("String.sliceToEnd", () => { +describe("Belt_internalMapInt.S.binarySearchBy", () => { + test("Belt_internalMapInt.S.binarySearchBy", () => { module Test = { - String.sliceToEnd("abcdefg", ~start=4) == "efg" - String.sliceToEnd("abcdefg", ~start=-2) == "fg" - String.sliceToEnd("abcdefg", ~start=7) == "" + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("String.slice", () => { - test("String.slice", () => { +describe("Belt_internalSetInt.A.reverseInPlace", () => { + test("Belt_internalSetInt.A.reverseInPlace", () => { module Test = { - String.slice("abcdefg", ~start=2, ~end=5) == "cde" - String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" - String.slice("abcdefg", ~start=-4, ~end=-2) == "de" - String.slice("abcdefg", ~start=5, ~end=1) == "" + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("String.searchOpt", () => { - test("String.searchOpt", () => { +describe("Belt_internalSetInt.A.reduceReverse2", () => { + test("Belt_internalSetInt.A.reduceReverse2", () => { module Test = { - String.searchOpt("testing 1 2 3", /\d+/) == Some(8) - String.searchOpt("no numbers", /\d+/) == None + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("String.search", () => { - test("String.search", () => { +describe("Belt_internalSetString.A.mapWithIndex", () => { + test("Belt_internalSetString.A.mapWithIndex", () => { module Test = { - String.search("testing 1 2 3", /\d+/) == 8 - String.search("no numbers", /\d+/) == -1 + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("String.unsafeReplaceRegExpBy2", () => { - test("String.unsafeReplaceRegExpBy2", () => { +describe("Belt_internalMapString.A.mapWithIndex", () => { + test("Belt_internalMapString.A.mapWithIndex", () => { module Test = { - let str = "7 times 6" - let re = /(\d+) times (\d+)/ - let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { - switch (Int.fromString(group1), Int.fromString(group2)) { - | (Some(x), Some(y)) => Int.toString(x * y) - | _ => "???" - } - } - String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("String.unsafeReplaceRegExpBy1", () => { - test("String.unsafeReplaceRegExpBy1", () => { +describe("Belt_internalMapInt.A.reduceWithIndex", () => { + test("Belt_internalMapInt.A.reduceWithIndex", () => { module Test = { - let str = "Jony is 40" - let re = /(Jony is )\d+/g - let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { - group1 ++ "41" - } - String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("String.unsafeReplaceRegExpBy0", () => { - test("String.unsafeReplaceRegExpBy0", () => { +describe("Belt_internalSetInt.A.reduceWithIndex", () => { + test("Belt_internalSetInt.A.reduceWithIndex", () => { module Test = { - let str = "beautiful vowels" - let re = /[aeiou]/g - let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) - String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("String.replaceAllRegExp", () => { - test("String.replaceAllRegExp", () => { +describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + test("JSON.stringifyAnyWithReplacerAndIndent", () => { module Test = { - String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("String.replaceAll", () => { - test("String.replaceAll", () => { +describe("Belt_internalSetString.A.keepWithIndex", () => { + test("Belt_internalSetString.A.keepWithIndex", () => { module Test = { - String.replaceAll("old old string", "old", "new") == "new new string" - String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("String.replaceRegExp", () => { - test("String.replaceRegExp", () => { +describe("Belt_internalSetString.A.reduceReverse", () => { + test("Belt_internalSetString.A.reduceReverse", () => { module Test = { - String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("String.replace", () => { - test("String.replace", () => { +describe("Belt_internalMapString.A.keepWithIndex", () => { + test("Belt_internalMapString.A.keepWithIndex", () => { module Test = { - String.replace("old string", "old", "new") == "new string" - String.replace("the cat and the dog", "the", "this") == "this cat and the dog" + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("String.repeat", () => { - test("String.repeat", () => { +describe("Belt_internalMapString.A.reduceReverse", () => { + test("Belt_internalMapString.A.reduceReverse", () => { module Test = { - String.repeat("ha", 3) == "hahaha" - String.repeat("empty", 0) == "" + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("String.normalizeForm", () => { - test("String.normalizeForm", () => { +describe("Belt_internalMapInt.A.forEachWithIndex", () => { + test("Belt_internalMapInt.A.forEachWithIndex", () => { module Test = { - let string1 = "\uFB00" - let string2 = "\u0066\u0066" - Console.log(string1 == string2) // false + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - let normalizeString1 = String.normalizeByForm(string1, #NFKD) - let normalizeString2 = String.normalizeByForm(string2, #NFKD) - Console.log(normalizeString1 == normalizeString2) // true + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("String.normalize", () => { - test("String.normalize", () => { +describe("Belt_internalSetInt.A.forEachWithIndex", () => { + test("Belt_internalSetInt.A.forEachWithIndex", () => { module Test = { - let string1 = "\u00F1" - let string2 = "\u006E\u0303" + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - assert(string1 != string2) // true - assertEqual(String.normalize(string1), String.normalize(string2)) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("String.match", () => { - test("String.match", () => { +describe("Date.toLocaleStringWithLocaleAndOptions", () => { + test("Date.toLocaleStringWithLocaleAndOptions", () => { module Test = { - String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) - String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) - String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == - Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) - String.match("The optional example", /(foo)?(example)/) == - Some([Some("example"), None, Some("example")]) - String.match("The large container.", /b[aeiou]g/) == None + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) + ->Console.log + // 2/19/23, 3:40 PM + + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions( + "en", + { + era: #long, + year: #numeric, + month: #"2-digit", + day: #"2-digit", + hour: #numeric, + timeZoneName: #short, + }, + ) + ->Console.log + // 02/19/2023 Anno Domini, 3 PM GMT+1 } () }) }) -describe("String.lastIndexOfFrom", () => { - test("String.lastIndexOfFrom", () => { +describe("Belt_internalSetString.A.reverseInPlace", () => { + test("Belt_internalSetString.A.reverseInPlace", () => { module Test = { - String.lastIndexOfFrom("bookseller", "ok", 6) == 2 - String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 - String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 - String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("String.lastIndexOfOpt", () => { - test("String.lastIndexOfOpt", () => { +describe("Belt_internalSetString.A.reduceReverse2", () => { + test("Belt_internalSetString.A.reduceReverse2", () => { module Test = { - String.lastIndexOfOpt("bookseller", "ok") == Some(2) - String.lastIndexOfOpt("beekeeper", "ee") == Some(4) - String.lastIndexOfOpt("abcdefg", "xyz") == None + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("String.lastIndexOf", () => { - test("String.lastIndexOf", () => { +describe("Belt_internalMapString.A.reverseInPlace", () => { + test("Belt_internalMapString.A.reverseInPlace", () => { module Test = { - String.lastIndexOf("bookseller", "ok") == 2 - String.lastIndexOf("beekeeper", "ee") == 4 - String.lastIndexOf("abcdefg", "xyz") == -1 + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("String.indexOfFrom", () => { - test("String.indexOfFrom", () => { +describe("Belt_internalMapString.A.reduceReverse2", () => { + test("Belt_internalMapString.A.reduceReverse2", () => { module Test = { - String.indexOfFrom("bookseller", "ok", 1) == 2 - String.indexOfFrom("bookseller", "sell", 2) == 4 - String.indexOfFrom("bookseller", "sell", 5) == -1 + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("String.indexOfOpt", () => { - test("String.indexOfOpt", () => { +describe("Belt_internalMapString.S.binarySearchBy", () => { + test("Belt_internalMapString.S.binarySearchBy", () => { module Test = { - String.indexOfOpt("bookseller", "ok") == Some(2) - String.indexOfOpt("bookseller", "xyz") == None + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("String.indexOf", () => { - test("String.indexOf", () => { - module Test = { - String.indexOf("bookseller", "ok") == 2 - String.indexOf("bookseller", "sell") == 4 - String.indexOf("beekeeper", "ee") == 1 - String.indexOf("bookseller", "xyz") == -1 +describe("Belt_internalMapInt.A.makeUninitialized", () => { + test("Belt_internalMapInt.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("String.includesFrom", () => { - test("String.includesFrom", () => { +describe("Belt_internalSetInt.A.makeUninitialized", () => { + test("Belt_internalSetInt.A.makeUninitialized", () => { module Test = { - String.includesFrom("programmer", "gram", 1) == true - String.includesFrom("programmer", "gram", 4) == false - String.includesFrom(`대한민국`, `한`, 1) == true + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("String.includes", () => { - test("String.includes", () => { +describe("Belt_internalSetString.A.reduceWithIndex", () => { + test("Belt_internalSetString.A.reduceWithIndex", () => { module Test = { - String.includes("programmer", "gram") == true - String.includes("programmer", "er") == true - String.includes("programmer", "pro") == true - String.includes("programmer.dat", "xyz") == false + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("String.endsWithFrom", () => { - test("String.endsWithFrom", () => { +describe("Belt_internalMapString.A.reduceWithIndex", () => { + test("Belt_internalMapString.A.reduceWithIndex", () => { module Test = { - String.endsWithFrom("abcd", "cd", 4) == true - String.endsWithFrom("abcde", "cd", 3) == false - String.endsWithFrom("abcde", "cde", 99) == true - String.endsWithFrom("example.dat", "ple", 7) == true + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("String.endsWith", () => { - test("String.endsWith", () => { +describe("Belt_internalSetString.A.forEachWithIndex", () => { + test("Belt_internalSetString.A.forEachWithIndex", () => { module Test = { - String.endsWith("BuckleScript", "Script") == true - String.endsWith("BuckleShoes", "Script") == false + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("String.concatMany", () => { - test("String.concatMany", () => { +describe("Belt_internalMapString.A.forEachWithIndex", () => { + test("Belt_internalMapString.A.forEachWithIndex", () => { module Test = { - String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) + + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("String.concat", () => { - test("String.concat", () => { +describe("Belt_internalSetString.A.makeUninitialized", () => { + test("Belt_internalSetString.A.makeUninitialized", () => { module Test = { - String.concat("cow", "bell") == "cowbell" - String.concat("Re", "Script") == "ReScript" + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("String.codePointAt", () => { - test("String.codePointAt", () => { +describe("Belt_internalMapString.A.makeUninitialized", () => { + test("Belt_internalMapString.A.makeUninitialized", () => { module Test = { - String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) - String.codePointAt("abc", 5) == None + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("String.charCodeAt", () => { - test("String.charCodeAt", () => { +describe("Belt_internalMapInt.S.strictlySortedLength", () => { + test("Belt_internalMapInt.S.strictlySortedLength", () => { module Test = { - String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat - String.codePointAt(`😺`, 0) == Some(0x1f63a) + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("String.charAt", () => { - test("String.charAt", () => { +describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + test("Date.toLocaleDateStringWithLocaleAndOptions", () => { module Test = { - String.charAt("ReScript", 0) == "R" - String.charAt("Hello", 12) == "" - String.charAt(`JS`, 5) == "" + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) + ->Console.log + // February 19, 2023 + + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 19.2.2023, 15:40 + + Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log + // 2023 } () }) }) -describe("String.getUnsafe", () => { - test("String.getUnsafe", () => { +describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { module Test = { - String.getUnsafe("ReScript", 0) == "R" - String.getUnsafe("Hello", 4) == "o" + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) + ->Console.log + // 3:40:00 PM GMT+1 + + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 15:40 } () }) }) -describe("String.get", () => { - test("String.get", () => { +describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { module Test = { - String.get("ReScript", 0) == Some("R") - String.get("Hello", 4) == Some("o") - String.get(`JS`, 4) == None + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("String.length", () => { - test("String.length", () => { +describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { module Test = { - String.length("abcd") == 4 + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("String.fromCodePointMany", () => { - test("String.fromCodePointMany", () => { +describe("Belt_internalMapString.S.strictlySortedLength", () => { + test("Belt_internalMapString.S.strictlySortedLength", () => { module Test = { - String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("String.fromCodePoint", () => { - test("String.fromCodePoint", () => { +describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { module Test = { - String.fromCodePoint(65) == "A" - String.fromCodePoint(0x3c8) == `ψ` - String.fromCodePoint(0xd55c) == `한` - String.fromCodePoint(0x1f63a) == `😺` + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("String.fromCharCodeMany", () => { - test("String.fromCharCodeMany", () => { +describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { module Test = { - String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" - String.fromCharCodeMany([65, 66, 67]) == "ABC" + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("String.fromCharCode", () => { - test("String.fromCharCode", () => { +describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { module Test = { - String.fromCharCode(65) == "A" - String.fromCharCode(0x3c8) == `ψ` - String.fromCharCode(0xd55c) == `한` - String.fromCharCode(-64568) == `ψ` + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("String.make", () => { - test("String.make", () => { +describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { module Test = { - String.make(3.5) == "3.5" - String.make([1, 2, 3]) == "1,2,3" + let arr = ["ant", "bee", "cat", "dog", "elk"] + + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("Type.Classify.classify", () => { - test("Type.Classify.classify", () => { +describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { module Test = { - switch %raw(`null`)->Type.Classify.classify { - | Null => Console.log("Yup, that's null.") - | _ => Console.log("This doesn't actually appear to be null...") - } + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Type.typeof", () => { - test("Type.typeof", () => { +describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { module Test = { - Console.log(Type.typeof("Hello")) // Logs "string" to the console. + let arr = Belt.Array.makeUninitializedUnsafe(5) - let someVariable = true + Js.log(Belt.Array.getExn(arr, 0)) // undefined - switch someVariable->Type.typeof { - | #boolean => Console.log("This is a bool, yay!") - | _ => Console.log("Oh, not a bool sadly...") - } + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) diff --git a/tests/docstrings_examples/generated_mocha_test.res.mjs b/tests/docstrings_examples/generated_mocha_test.res.mjs index abc53bd4c0..a973421718 100644 --- a/tests/docstrings_examples/generated_mocha_test.res.mjs +++ b/tests/docstrings_examples/generated_mocha_test.res.mjs @@ -43,135 +43,342 @@ 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"; -Mocha.describe("AsyncIterator.forEach", () => { - Mocha.test("AsyncIterator.forEach", () => { - let asyncIterator = ((() => { - var map1 = new Map(); +Mocha.describe("Set.add", () => { + Mocha.test("Set.add", () => { + let set = new Set(); + set.add("someValue"); + }); +}); - map1.set('first', '1'); - map1.set('second', '2'); +Mocha.describe("Set.has", () => { + Mocha.test("Set.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."); + } + }); +}); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - let main = async () => await $$AsyncIterator.forEach(asyncIterator, v => { - if (v !== undefined && v[0] === "second") { - return Pervasives.assertEqual(v[1], "2"); - } - - }); - main(); +Mocha.describe("Map.get", () => { + Mocha.test("Map.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.describe("AsyncIterator.next", () => { - Mocha.test("AsyncIterator.next", () => { - let asyncIterator = ((() => { - var map1 = new Map(); +Mocha.describe("Map.has", () => { + Mocha.test("Map.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."); + } + }); +}); - map1.set('first', '1'); - map1.set('second', '2'); +Mocha.describe("Map.set", () => { + Mocha.test("Map.set", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); +}); - 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) { - Pervasives.assertEqual(Option.isNone(match.value), true); +Mocha.describe("Int.mod", () => { + Mocha.test("Int.mod", () => {}); +}); + +Mocha.describe("Set.make", () => { + Mocha.test("Set.make", () => { + new Set(); + let set = new Set(); + set.add("Fine name"); + }); +}); + +Mocha.describe("Set.size", () => { + Mocha.test("Set.size", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue"); + set.add("someValue2"); + }); +}); + +Mocha.describe("List.add", () => { + Mocha.test("List.add", () => { + List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("List.get", () => { + Mocha.test("List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 } - - }; + } }; - processMyAsyncIterator(); + List.get(abc, 1); + List.get(abc, 4); }); }); -Mocha.describe("AsyncIterator.done", () => { - Mocha.test("AsyncIterator.done", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); +Mocha.describe("List.map", () => { + Mocha.test("List.map", () => { + List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 } - }); + }, x => x + 1 | 0); }); }); -Mocha.describe("AsyncIterator.value", () => { - Mocha.test("AsyncIterator.value", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); +Mocha.describe("List.zip", () => { + Mocha.test("List.zip", () => { + List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } } }); }); }); -Mocha.describe("AsyncIterator.make", () => { - Mocha.test("AsyncIterator.make", () => { - let context = { - contents: 0 - }; - let asyncIterator = $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - return { - done: currentValue >= 3, - value: currentValue - }; - }); - let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { - if (value !== undefined) { - console.log(value); - return; +Mocha.describe("List.has", () => { + Mocha.test("List.has", () => { + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - - }); - main(); + }, 2, (a, b) => a === b); + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); }); }); -Mocha.describe("Array.last", () => { - Mocha.test("Array.last", () => { - Pervasives.assertEqual($$Array.last([ - "Hello", - "Hi", - "Good bye" - ]), "Good bye"); - Pervasives.assertEqual($$Array.last([]), undefined); +Mocha.describe("Null.map", () => { + Mocha.test("Null.map", () => { + Null.map(3, x => Math.imul(x, x)); + Null.map(null, x => Math.imul(x, x)); }); }); -Mocha.describe("Array.at", () => { - Mocha.test("Array.at", () => { - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(0), "a"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(2), "c"); +Mocha.describe("Math.abs", () => { + Mocha.test("Math.abs", () => { + Math.abs(-2.0); + Math.abs(3.0); + }); +}); + +Mocha.describe("Math.cos", () => { + Mocha.test("Math.cos", () => { + Math.cos(-0.0); + Math.cos(0.0); + Math.cos(1.0); + }); +}); + +Mocha.describe("Math.exp", () => { + Mocha.test("Math.exp", () => { + Math.exp(-1.0); + Math.exp(0.0); + }); +}); + +Mocha.describe("Math.log", () => { + Mocha.test("Math.log", () => { + isNaN(Math.log(-1.0)); + isFinite(Math.log(-0.0)); + isFinite(Math.log(0.0)); + Math.log(1.0); + }); +}); + +Mocha.describe("Math.min", () => { + Mocha.test("Math.min", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + }); +}); + +Mocha.describe("Math.max", () => { + Mocha.test("Math.max", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + }); +}); + +Mocha.describe("Math.pow", () => { + Mocha.test("Math.pow", () => { + Math.pow(2.0, 4.0); + Math.pow(3.0, 4.0); + }); +}); + +Mocha.describe("Math.sin", () => { + Mocha.test("Math.sin", () => { + Math.sin(-0.0); + Math.sin(0.0); + Math.sin(1.0); + }); +}); + +Mocha.describe("Math.tan", () => { + Mocha.test("Math.tan", () => { + Math.tan(-0.0); + Math.tan(0.0); + Math.tan(1.0); + }); +}); + +Mocha.describe("Map.make", () => { + Mocha.test("Map.make", () => { + new Map(); + let map = new Map(); + map.set("lang", "ReScript"); + }); +}); + +Mocha.describe("Map.size", () => { + Mocha.test("Map.size", () => { + let map = new Map(); + map.set("someKey", "someValue"); + }); +}); + +Mocha.describe("Map.keys", () => { + Mocha.test("Map.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.describe("Dict.get", () => { + Mocha.test("Dict.get", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + let value = dict["someKey"]; + if (value !== undefined) { + console.log(value); + } else { + console.log("Nope, didn't have the key."); + } + }); +}); + +Mocha.describe("Dict.set", () => { + Mocha.test("Dict.set", () => { + let dict = {}; + dict["someKey"] = "someValue"; + }); +}); + +Mocha.describe("Belt.Set", () => { + Mocha.test("Belt.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("Array.at", () => { + Mocha.test("Array.at", () => { + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(0), "a"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(2), "c"); Pervasives.assertEqual([ "a", "b", @@ -195,4854 +402,3890 @@ Mocha.describe("Array.at", () => { }); }); -Mocha.describe("Array.findMap", () => { - Mocha.test("Array.findMap", () => { - Pervasives.assertEqual($$Array.findMap([ +Mocha.describe("Set.clear", () => { + Mocha.test("Set.clear", () => { + let set = new Set(); + set.add("someKey"); + set.clear(); + }); +}); + +Mocha.describe("Object.is", () => { + Mocha.test("Object.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 - ], n => { - if (n % 2 === 0) { - return n - 2 | 0; - } - - }), 0); - Pervasives.assertEqual($$Array.findMap([ + ], [ 1, 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return n - 8 | 0; - } - - }), -6); - Pervasives.assertEqual($$Array.findMap([ + 3 + ]); + Primitive_object.equal([ 1, 2, - 3, - 4, - 5, - 6 - ], param => {}), undefined); - Pervasives.assertEqual($$Array.findMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); + 3 + ], [ + 1, + 2, + 3 + ]); + let fruit = { + name: "Apple" + }; + Object.is(fruit, fruit); + Object.is(fruit, { + name: "Apple" + }); + Primitive_object.equal(fruit, { + name: "Apple" + }); + }); +}); + +Mocha.describe("List.size", () => { + Mocha.test("List.size", () => { + List.size({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - - }), undefined); + }); }); }); -Mocha.describe("Array.flatMapWithIndex", () => { - Mocha.test("Array.flatMapWithIndex", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.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 - ]; +Mocha.describe("List.head", () => { + Mocha.test("List.head", () => { + List.head(/* [] */0); + List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - }), [ - 0, - 1, - 2, - 2, - 3, - 4 - ]); + }); }); }); -Mocha.describe("Array.flatMap", () => { - Mocha.test("Array.flatMap", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.flatMap(item => { - switch (item) { - case "ReScript" : - return [ - 1, - 2, - 3 - ]; - case "TypeScript" : - return [ - 4, - 5, - 6 - ]; - case "JavaScript" : - return [ - 7, - 8, - 9 - ]; +Mocha.describe("List.tail", () => { + Mocha.test("List.tail", () => { + List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - }), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); - }); -}); - -Mocha.describe("Array.shuffle", () => { - Mocha.test("Array.shuffle", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - $$Array.shuffle(array); - console.log(array); - let array2 = [ - 1, - 2, - 3 - ]; - $$Array.shuffle(array2); - Pervasives.assertEqual(array2.length, 3); - }); -}); - -Mocha.describe("Array.toShuffled", () => { - Mocha.test("Array.toShuffled", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let shuffledArray = $$Array.toShuffled(array); - console.log(shuffledArray); - Pervasives.assertEqual($$Array.toShuffled([ - 1, - 2, - 3 - ]).length, 3); + }); + List.tail(/* [] */0); }); }); -Mocha.describe("Array.keepSome", () => { - Mocha.test("Array.keepSome", () => { - Pervasives.assertEqual($$Array.keepSome([ - 1, - undefined, - 3 - ]), [ - 1, - 3 - ]); - Pervasives.assertEqual($$Array.keepSome([ - 1, - 2, - 3 - ]), [ - 1, - 2, - 3 - ]); - Pervasives.assertEqual($$Array.keepSome([ - undefined, - undefined, - undefined - ]), []); - Pervasives.assertEqual($$Array.keepSome([]), []); +Mocha.describe("List.make", () => { + Mocha.test("List.make", () => { + List.make(3, 1); }); }); -Mocha.describe("Array.filterMap", () => { - Mocha.test("Array.filterMap", () => { - Pervasives.assertEqual($$Array.filterMap([ - "Hello", - "Hi", - "Good bye" - ], item => { - if (item === "Hello") { - return item.length; +Mocha.describe("List.drop", () => { + Mocha.test("List.drop", () => { + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - - }), [5]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return Math.imul(n, n); + }, 2); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - - }), [ - 4, - 16, - 36 - ]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), []); - Pervasives.assertEqual($$Array.filterMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); + }, 3); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - - }), []); + }, 4); }); }); -Mocha.describe("Array.findIndexOpt", () => { - Mocha.test("Array.findIndexOpt", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); +Mocha.describe("List.take", () => { + Mocha.test("List.take", () => { + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); }); }); -Mocha.describe("Array.setUnsafe", () => { - Mocha.test("Array.setUnsafe", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); - }); -}); - -Mocha.describe("Array.unsafe_get", () => { - Mocha.test("Array.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.describe("Array.getUnsafe", () => { - Mocha.test("Array.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.describe("Array.set", () => { - Mocha.test("Array.set", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); - }); -}); - -Mocha.describe("Array.get", () => { - Mocha.test("Array.get", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array[0], "Hello"); - Pervasives.assertEqual(array[3], undefined); - }); -}); - -Mocha.describe("Array.someWithIndex", () => { - Mocha.test("Array.someWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some((greeting, index) => { - if (greeting === "Hello") { - return index === 0; - } else { - return false; +Mocha.describe("List.flat", () => { + Mocha.test("List.flat", () => { + List.flat({ + hd: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + tl: { + hd: /* [] */0, + tl: { + hd: { + hd: 3, + tl: /* [] */0 + }, + tl: /* [] */0 + } } - }), true); - }); -}); - -Mocha.describe("Array.some", () => { - Mocha.test("Array.some", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); - }); -}); - -Mocha.describe("Array.reduceRightWithIndex", () => { - Mocha.test("Array.reduceRightWithIndex", () => { - Pervasives.assertEqual($$Array.reduceRightWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); + }); }); }); -Mocha.describe("Array.reduceRight", () => { - Mocha.test("Array.reduceRight", () => { - Pervasives.assertEqual($$Array.reduceRight([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "dcba"); - Pervasives.assertEqual($$Array.reduceRight([ - 1, - 2, - 3 - ], /* [] */0, List.add), { +Mocha.describe("List.some", () => { + Mocha.test("List.some", () => { + let isAbove100 = value => value > 100; + List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + List.some({ hd: 1, tl: { hd: 2, tl: { hd: 3, - tl: /* [] */0 + tl: { + hd: 4, + tl: /* [] */0 + } } } - }); - Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); + }, isAbove100); }); }); -Mocha.describe("Array.reduceWithIndex", () => { - Mocha.test("Array.reduceWithIndex", () => { - Pervasives.assertEqual($$Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$Array.reduceWithIndex([ - 1, - 2, - 3 - ], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), { - hd: 5, +Mocha.describe("List.find", () => { + Mocha.test("List.find", () => { + List.find({ + hd: 1, tl: { - hd: 3, + hd: 4, tl: { - hd: 1, - tl: /* [] */0 + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } } } - }); - Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); + }, x => x > 3); + List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); }); }); -Mocha.describe("Array.reduce", () => { - Mocha.test("Array.reduce", () => { - Pervasives.assertEqual($$Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0), 10); - Pervasives.assertEqual($$Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "abcd"); - Pervasives.assertEqual($$Array.reduce([ - 1, - 2, - 3 - ], /* [] */0, List.add), { - hd: 3, +Mocha.describe("List.sort", () => { + Mocha.test("List.sort", () => { + List.sort({ + hd: 5, tl: { - hd: 2, + hd: 4, tl: { - hd: 1, - tl: /* [] */0 + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } } } - }); - Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); + }, Primitive_int.compare); }); }); -Mocha.describe("Array.mapWithIndex", () => { - Mocha.test("Array.mapWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); - Pervasives.assertEqual(mappedArray, [ - "Hello at position 0", - "Hi at position 1", - "Good bye at position 2" - ]); +Mocha.describe("Null.null", () => { + Mocha.test("Null.null", () => { + console.log(null); }); }); -Mocha.describe("Array.map", () => { - Mocha.test("Array.map", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map(greeting => greeting + " to you"); - Pervasives.assertEqual(mappedArray, [ - "Hello to you", - "Hi to you", - "Good bye to you" - ]); - }); +Mocha.describe("Null.make", () => { + Mocha.test("Null.make", () => {}); }); -Mocha.describe("Array.forEachWithIndex", () => { - Mocha.test("Array.forEachWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach((item, index) => { - console.log("At item " + index.toString() + ": " + item); - }); +Mocha.describe("Math.acos", () => { + Mocha.test("Math.acos", () => { + Math.acos(-1.0); + isNaN(Math.acos(-3.0)); }); }); -Mocha.describe("Array.forEach", () => { - Mocha.test("Array.forEach", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach(item => { - console.log(item); - }); +Mocha.describe("Math.asin", () => { + Mocha.test("Math.asin", () => { + Math.asin(-1.0); + isNaN(Math.asin(-2.0)); }); }); -Mocha.describe("Array.findIndexWithIndex", () => { - Mocha.test("Array.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; - } - }); - Pervasives.assertEqual(isReScriptFirst, 0); - Pervasives.assertEqual(isTypeScriptFirst, -1); +Mocha.describe("Math.atan", () => { + Mocha.test("Math.atan", () => { + Math.atan(-0.0); + Math.atan(0.0); + Math.atan(1.0); }); }); -Mocha.describe("Array.findIndex", () => { - Mocha.test("Array.findIndex", () => { - let array = [ - "ReScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); - Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); +Mocha.describe("Math.cbrt", () => { + Mocha.test("Math.cbrt", () => { + Math.cbrt(-1.0); + Math.cbrt(-0.0); + Math.cbrt(0.0); }); }); -Mocha.describe("Array.findWithIndex", () => { - Mocha.test("Array.findWithIndex", () => { - let array = [ - "TypeScript", - "JavaScript", - "ReScript" - ]; - Pervasives.assertEqual(array.find((item, index) => { - if (index > 1) { - return item === "ReScript"; - } else { - return false; - } - }), "ReScript"); +Mocha.describe("Math.ceil", () => { + Mocha.test("Math.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.describe("Array.find", () => { - Mocha.test("Array.find", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); +Mocha.describe("Math.cosh", () => { + Mocha.test("Math.cosh", () => { + Math.cosh(-1.0); + Math.cosh(-0.0); + Math.cosh(0.0); }); }); -Mocha.describe("Array.filterWithIndex", () => { - Mocha.test("Array.filterWithIndex", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].filter((num, index) => { - if (index === 0) { - return true; - } else { - return num === 2; - } - }), [ - 1, - 2 - ]); +Mocha.describe("Math.log2", () => { + Mocha.test("Math.log2", () => { + isNaN(Math.log2(-2.0)); + isFinite(Math.log2(-0.0)); + isFinite(Math.log2(0.0)); + Math.log2(1.0); }); }); -Mocha.describe("Array.filter", () => { - Mocha.test("Array.filter", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].filter(num => num > 2), [ - 3, - 4 - ]); +Mocha.describe("Math.sign", () => { + Mocha.test("Math.sign", () => { + Math.sign(3.0); + Math.sign(-3.0); + Math.sign(0.0); }); }); -Mocha.describe("Array.everyWithIndex", () => { - Mocha.test("Array.everyWithIndex", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Pervasives.assertEqual(array.every((num, index) => { - if (index < 5) { - return num <= 4; - } else { - return false; - } - }), true); - Pervasives.assertEqual(array.every((num, index) => { - if (index < 2) { - return num >= 2; - } else { - return false; - } - }), false); +Mocha.describe("Math.sinh", () => { + Mocha.test("Math.sinh", () => { + Math.sinh(-0.0); + Math.sinh(0.0); + Math.sinh(1.0); }); }); -Mocha.describe("Array.every", () => { - Mocha.test("Array.every", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Pervasives.assertEqual(array.every(num => num <= 4), true); - Pervasives.assertEqual(array.every(num => num === 1), false); +Mocha.describe("Math.sqrt", () => { + Mocha.test("Math.sqrt", () => { + isNaN(Math.sqrt(-1.0)); + Math.sqrt(-0.0); + Math.sqrt(0.0); + Math.sqrt(1.0); + Math.sqrt(9.0); }); }); -Mocha.describe("Array.toString", () => { - Mocha.test("Array.toString", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].toString(), "1,2,3,4"); +Mocha.describe("Math.tanh", () => { + Mocha.test("Math.tanh", () => { + Math.tanh(-0.0); + Math.tanh(0.0); + Math.tanh(1.0); }); }); -Mocha.describe("Array.copy", () => { - Mocha.test("Array.copy", () => { - let myArray = [ - 1, - 2, - 3 - ]; - let copyOfMyArray = myArray.slice(); - Pervasives.assertEqual(copyOfMyArray, [ - 1, - 2, - 3 - ]); - Pervasives.assertEqual(myArray === copyOfMyArray, false); +Mocha.describe("Map.clear", () => { + Mocha.test("Map.clear", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.clear(); }); }); -Mocha.describe("Array.sliceToEnd", () => { - Mocha.test("Array.sliceToEnd", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1), [ - 2, +Mocha.describe("Int.range", () => { + Mocha.test("Int.range", () => { + Primitive_object.equal(Int.range(3, 6, undefined), [ 3, - 4 + 4, + 5 ]); - }); -}); - -Mocha.describe("Array.slice", () => { - Mocha.test("Array.slice", () => { - Pervasives.assertEqual([ - 1, - 2, + Primitive_object.equal(Int.range(-3, -1, undefined), [ + -3, + -2 + ]); + Primitive_object.equal(Int.range(3, 1, undefined), [ 3, - 4 - ].slice(1, 3), [ - 2, - 3 + 2 ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Int.range(3, 6, { + step: -2 + }); }); }); -Mocha.describe("Array.joinWithUnsafe", () => { - Mocha.test("Array.joinWithUnsafe", () => { - Pervasives.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); -}); - -Mocha.describe("Array.joinUnsafe", () => { - Mocha.test("Array.joinUnsafe", () => { - Pervasives.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); -}); - -Mocha.describe("Array.joinWith", () => { - Mocha.test("Array.joinWith", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); - }); -}); - -Mocha.describe("Array.join", () => { - Mocha.test("Array.join", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); +Mocha.describe("Int.clamp", () => { + Mocha.test("Int.clamp", () => { + Int.clamp(undefined, undefined, 42) === 42; + Int.clamp(50, undefined, 42) === 50; + Int.clamp(undefined, 40, 42) === 40; + Int.clamp(50, 40, 42) === 50; }); }); -Mocha.describe("Array.indexOfOpt", () => { - Mocha.test("Array.indexOfOpt", () => { - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 2), 1); - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 3), undefined); - Pervasives.assertEqual($$Array.indexOfOpt([{ - language: "ReScript" - }], { - language: "ReScript" - }), undefined); - }); +Mocha.describe("Float.mod", () => { + Mocha.test("Float.mod", () => {}); }); -Mocha.describe("Array.indexOf", () => { - Mocha.test("Array.indexOf", () => { - Pervasives.assertEqual([ - 1, - 2 - ].indexOf(2), 1); - Pervasives.assertEqual([ - 1, - 2 - ].indexOf(3), -1); - Pervasives.assertEqual([{ - language: "ReScript" - }].indexOf({ - language: "ReScript" - }), -1); +Mocha.describe("Date.make", () => { + Mocha.test("Date.make", () => { + new Date(); }); }); -Mocha.describe("Array.includes", () => { - Mocha.test("Array.includes", () => { - Pervasives.assertEqual([ - 1, - 2 - ].includes(1), true); - Pervasives.assertEqual([ - 1, - 2 - ].includes(3), false); - Pervasives.assertEqual([{ - language: "ReScript" - }].includes({ - language: "ReScript" - }), false); +Mocha.describe("Dict.make", () => { + Mocha.test("Dict.make", () => { + let dict2 = {}; + dict2["someKey"] = 12; }); }); -Mocha.describe("Array.flat", () => { - Mocha.test("Array.flat", () => { - Pervasives.assertEqual([ - [1], - [2], +Mocha.describe("Dict.copy", () => { + Mocha.test("Dict.copy", () => { + let dict = Object.fromEntries([ [ - 3, - 4 + "key1", + "value1" + ], + [ + "key2", + "value2" ] - ].flat(), [ - 1, - 2, - 3, - 4 ]); + let dict2 = Object.assign({}, dict); + console.log(Object.keys(dict), Object.keys(dict2)); }); }); -Mocha.describe("Array.concatMany", () => { - Mocha.test("Array.concatMany", () => { - let array1 = [ +Mocha.describe("Array.pop", () => { + Mocha.test("Array.pop", () => { + let someArray = [ "hi", "hello" ]; - let array2 = ["yay"]; - let array3 = ["wehoo"]; - let someArray = array1.concat(array2, array3); - console.log(someArray); + Pervasives.assertEqual(someArray.pop(), "hello"); + Pervasives.assertEqual(someArray, ["hi"]); }); }); -Mocha.describe("Array.concat", () => { - Mocha.test("Array.concat", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = [ - "yay", - "wehoo" +Mocha.describe("Array.map", () => { + Mocha.test("Array.map", () => { + let array = [ + "Hello", + "Hi", + "Good bye" ]; - let someArray = array1.concat(array2); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" + let mappedArray = array.map(greeting => greeting + " to you"); + Pervasives.assertEqual(mappedArray, [ + "Hello to you", + "Hi to you", + "Good bye to you" ]); }); }); -Mocha.describe("Array.unshiftMany", () => { - Mocha.test("Array.unshiftMany", () => { - let someArray = [ - "hi", - "hello" +Mocha.describe("Array.get", () => { + Mocha.test("Array.get", () => { + let array = [ + "Hello", + "Hi", + "Good bye" ]; - someArray.unshift("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "yay", - "wehoo", - "hi", - "hello" - ]); + Pervasives.assertEqual(array[0], "Hello"); + Pervasives.assertEqual(array[3], undefined); }); }); -Mocha.describe("Array.unshift", () => { - Mocha.test("Array.unshift", () => { - let someArray = [ - "hi", - "hello" +Mocha.describe("Array.set", () => { + Mocha.test("Array.set", () => { + let array = [ + "Hello", + "Hi", + "Good bye" ]; - someArray.unshift("yay"); - Pervasives.assertEqual(someArray, [ - "yay", - "hi", - "hello" - ]); + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); }); }); -Mocha.describe("Array.sort", () => { - Mocha.test("Array.sort", () => { - let array = [ - 3, - 2, - 1 - ]; - array.sort((a, b) => a - b | 0); - Pervasives.assertEqual(array, [ - 1, - 2, - 3 - ]); +Mocha.describe("String.get", () => { + Mocha.test("String.get", () => { + Primitive_object.equal("ReScript"[0], "R"); + Primitive_object.equal("Hello"[4], "o"); }); }); -Mocha.describe("Array.shift", () => { - Mocha.test("Array.shift", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.shift(), "hi"); - Pervasives.assertEqual(someArray, ["hello"]); +Mocha.describe("Set.delete", () => { + Mocha.test("Set.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.describe("Array.reverse", () => { - Mocha.test("Array.reverse", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.reverse(); - Pervasives.assertEqual(someArray, [ - "hello", - "hi" - ]); +Mocha.describe("Set.values", () => { + Mocha.test("Set.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("Array.pushMany", () => { - Mocha.test("Array.pushMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" - ]); +Mocha.describe("Result.map", () => { + Mocha.test("Result.map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); }); }); -Mocha.describe("Array.push", () => { - Mocha.test("Array.push", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay" +Mocha.describe("Result.all", () => { + Mocha.test("Result.all", () => { + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Ok", + _0: 2 + }, + { + TAG: "Ok", + _0: 3 + } + ]); + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Error", + _0: 1 + } ]); }); }); -Mocha.describe("Array.pop", () => { - Mocha.test("Array.pop", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.pop(), "hello"); - Pervasives.assertEqual(someArray, ["hi"]); +Mocha.describe("Option.map", () => { + Mocha.test("Option.map", () => { + Option.map(3, x => Math.imul(x, x)); + Option.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Array.fill", () => { - Mocha.test("Array.fill", () => { - let myArray = [ +Mocha.describe("Option.all", () => { + Mocha.test("Option.all", () => { + Option.all([ 1, 2, - 3, - 4 - ]; - myArray.fill(9, 1, 3); - Pervasives.assertEqual(myArray, [ + 3 + ]); + Option.all([ 1, - 9, - 9, - 4 + undefined ]); }); }); -Mocha.describe("Array.fillToEnd", () => { - Mocha.test("Array.fillToEnd", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1); - Pervasives.assertEqual(myArray, [ - 1, - 9, - 9, - 9 - ]); +Mocha.describe("Object.get", () => { + Mocha.test("Object.get", () => { + Option.isSome(({ + a: 1 + })["toString"]); }); }); -Mocha.describe("Array.fillAll", () => { - Mocha.test("Array.fillAll", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9); - Pervasives.assertEqual(myArray, [ - 9, - 9, - 9, - 9 - ]); +Mocha.describe("Object.set", () => { + Mocha.test("Object.set", () => { + ({ + a: 1 + })["a"] = 2; + ({ + a: 1 + })["a"] = undefined; + ({ + a: 1 + })["b"] = 2; }); }); -Mocha.describe("Array.length", () => { - Mocha.test("Array.length", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.length, 2); +Mocha.describe("List.zipBy", () => { + Mocha.test("List.zipBy", () => { + 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("Array.fromInitializer", () => { - Mocha.test("Array.fromInitializer", () => { - Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ - 3, - 4, - 5 - ]); - Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); +Mocha.describe("List.every", () => { + Mocha.test("List.every", () => { + let isBelow10 = value => value < 10; + List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); }); }); -Mocha.describe("Array.make", () => { - Mocha.test("Array.make", () => { - Pervasives.assertEqual($$Array.make(3, "apple"), [ - "apple", - "apple", - "apple" - ]); - Pervasives.assertEqual($$Array.make(6, 7), [ - 7, - 7, - 7, - 7, - 7, - 7 - ]); +Mocha.describe("List.some2", () => { + Mocha.test("List.some2", () => { + List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); }); }); -Mocha.describe("Array.fromIterator", () => { - Mocha.test("Array.fromIterator", () => { - Pervasives.assertEqual(Array.from(new Map([ - [ - "foo", - 1 - ], - [ - "bar", +Mocha.describe("List.equal", () => { + Mocha.test("List.equal", () => { + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + 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.describe("List.unzip", () => { + Mocha.test("List.unzip", () => { + List.unzip({ + hd: [ + 1, 2 - ] - ]).values()), [ - 1, - 2 - ]); + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + 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.describe("Belt_Float./", () => { - Mocha.test("Belt_Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); +Mocha.describe("Null.getOr", () => { + Mocha.test("Null.getOr", () => { + Null.getOr(null, "Banana"); + Null.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNull("Jane")); + greet(undefined); }); }); -Mocha.describe("Belt_Float.*", () => { - Mocha.test("Belt_Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); +Mocha.describe("Null.mapOr", () => { + Mocha.test("Null.mapOr", () => { + Null.mapOr(3, 0, x => x + 5 | 0); + Null.mapOr(null, 0, x => x + 5 | 0); }); }); -Mocha.describe("Belt_Float.-", () => { - Mocha.test("Belt_Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); +Mocha.describe("Math.acosh", () => { + Mocha.test("Math.acosh", () => { + Math.acosh(1.0); + isNaN(Math.acosh(0.5)); }); }); -Mocha.describe("Belt_Float.+", () => { - Mocha.test("Belt_Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); +Mocha.describe("Math.asinh", () => { + Mocha.test("Math.asinh", () => { + Math.asinh(-1.0); + Math.asinh(-0.0); }); }); -Mocha.describe("Belt_Float.toString", () => { - Mocha.test("Belt_Float.toString", () => { - console.log(String(1.0) === "1.0"); +Mocha.describe("Math.atanh", () => { + Mocha.test("Math.atanh", () => { + isNaN(Math.atanh(-2.0)); + isFinite(Math.atanh(-1.0)); + Math.atanh(-0.0); + Math.atanh(0.0); + Math.atanh(0.5); }); }); -Mocha.describe("Belt_Float.fromString", () => { - Mocha.test("Belt_Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); +Mocha.describe("Math.atan2", () => { + Mocha.test("Math.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.describe("Belt_Float.fromInt", () => { - Mocha.test("Belt_Float.fromInt", () => { - console.log(1 === 1.0); +Mocha.describe("Math.expm1", () => { + Mocha.test("Math.expm1", () => { + Math.expm1(-1.0); + Math.expm1(-0.0); }); }); -Mocha.describe("Belt_Float.toInt", () => { - Mocha.test("Belt_Float.toInt", () => { - console.log(true); +Mocha.describe("Math.floor", () => { + Mocha.test("Math.floor", () => { + Math.floor(-45.95); + Math.floor(-45.05); + Math.floor(-0.0); }); }); -Mocha.describe("Belt_Array.truncateToLengthUnsafe", () => { - Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("Math.hypot", () => { + Mocha.test("Math.hypot", () => { + Math.hypot(3.0, 4.0); + Math.hypot(3.0, 5.0); }); }); -Mocha.describe("Belt_Array.eq", () => { - Mocha.test("Belt_Array.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Math.log1p", () => { + Mocha.test("Math.log1p", () => { + isNaN(Math.log1p(-2.0)); + isFinite(Math.log1p(-1.0)); + Math.log1p(-0.0); }); }); -Mocha.describe("Belt_Array.cmp", () => { - Mocha.test("Belt_Array.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.describe("Math.log10", () => { + Mocha.test("Math.log10", () => { + isNaN(Math.log10(-2.0)); + isFinite(Math.log10(-0.0)); + isFinite(Math.log10(0.0)); + Math.log10(1.0); }); }); -Mocha.describe("Belt_Array.some2", () => { - Mocha.test("Belt_Array.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.describe("Math.round", () => { + Mocha.test("Math.round", () => { + Math.round(-20.5); + Math.round(-0.1); + Math.round(0.0); + Math.round(-0.0); }); }); -Mocha.describe("Belt_Array.every2", () => { - Mocha.test("Belt_Array.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.describe("Math.trunc", () => { + Mocha.test("Math.trunc", () => { + Math.trunc(0.123); + Math.trunc(1.999); + Math.trunc(13.37); + Math.trunc(42.84); }); }); -Mocha.describe("Belt_Array.every", () => { - Mocha.test("Belt_Array.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Map.delete", () => { + Mocha.test("Map.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.describe("Belt_Array.some", () => { - Mocha.test("Belt_Array.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Map.values", () => { + Mocha.test("Map.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("Belt_Array.joinWith", () => { - Mocha.test("Belt_Array.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.describe("Error.name", () => { + Mocha.test("Error.name", () => { + let error = new SyntaxError("Some message here"); + console.log(error.name); }); }); -Mocha.describe("Belt_Array.reduceWithIndex", () => { - Mocha.test("Belt_Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("Error.make", () => { + Mocha.test("Error.make", () => { + let error = new Error("Some message here"); + console.log(error.message); + console.log(error.name); }); }); -Mocha.describe("Belt_Array.reduceReverse2", () => { - Mocha.test("Belt_Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("Belt_Int.+", () => { + Mocha.test("Belt_Int.+", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Belt_Array.reduceReverse", () => { - Mocha.test("Belt_Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("Belt_Int.-", () => { + Mocha.test("Belt_Int.-", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Belt_Array.reduce", () => { - Mocha.test("Belt_Array.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.describe("Belt_Int.*", () => { + Mocha.test("Belt_Int.*", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Belt_Array.partition", () => { - Mocha.test("Belt_Array.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.describe("Belt_Int./", () => { + Mocha.test("Belt_Int./", () => { + Pervasives.assertEqual(2, 2); }); }); -Mocha.describe("Belt_Array.mapWithIndex", () => { - Mocha.test("Belt_Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Belt.Int.+", () => { + Mocha.test("Belt.Int.+", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Belt_Array.forEachWithIndex", () => { - Mocha.test("Belt_Array.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.describe("Belt.Int.-", () => { + Mocha.test("Belt.Int.-", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Belt_Array.keepMap", () => { - Mocha.test("Belt_Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("Belt.Int.*", () => { + Mocha.test("Belt.Int.*", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Belt_Array.keepWithIndex", () => { - Mocha.test("Belt_Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("Belt.Int./", () => { + Mocha.test("Belt.Int./", () => { + Pervasives.assertEqual(2, 2); }); }); -Mocha.describe("Belt_Array.getIndexBy", () => { - Mocha.test("Belt_Array.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.describe("Array.make", () => { + Mocha.test("Array.make", () => { + Pervasives.assertEqual($$Array.make(3, "apple"), [ + "apple", + "apple", + "apple" + ]); + Pervasives.assertEqual($$Array.make(6, 7), [ + 7, + 7, + 7, + 7, + 7, + 7 + ]); }); }); -Mocha.describe("Belt_Array.getBy", () => { - Mocha.test("Belt_Array.getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ +Mocha.describe("Array.fill", () => { + Mocha.test("Array.fill", () => { + let myArray = [ 1, - 4, + 2, 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 4 + ]; + myArray.fill(9, 1, 3); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 4 + ]); }); }); -Mocha.describe("Belt_Array.flatMap", () => { - Mocha.test("Belt_Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 +Mocha.describe("Array.push", () => { + Mocha.test("Array.push", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay" ]); }); }); -Mocha.describe("Belt_Array.map", () => { - Mocha.test("Belt_Array.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ +Mocha.describe("Array.sort", () => { + Mocha.test("Array.sort", () => { + let array = [ 3, - 4 + 2, + 1 + ]; + array.sort((a, b) => a - b | 0); + Pervasives.assertEqual(array, [ + 1, + 2, + 3 ]); }); }); -Mocha.describe("Belt_Array.forEach", () => { - Mocha.test("Belt_Array.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ +Mocha.describe("Array.flat", () => { + Mocha.test("Array.flat", () => { + Pervasives.assertEqual([ + [1], + [2], + [ + 3, + 4 + ] + ].flat(), [ 1, 2, 3, 4 - ], x => { - total.contents = total.contents + x | 0; - }); + ]); }); }); -Mocha.describe("Belt_Array.blit", () => { - Mocha.test("Belt_Array.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.describe("Array.join", () => { + Mocha.test("Array.join", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); }); }); -Mocha.describe("Belt_Array.fill", () => { - Mocha.test("Belt_Array.fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ - 0, +Mocha.describe("Array.copy", () => { + Mocha.test("Array.copy", () => { + let myArray = [ 1, - 9, - 9, - 4 - ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, + 2, + 3 + ]; + let copyOfMyArray = myArray.slice(); + Pervasives.assertEqual(copyOfMyArray, [ 1, - 9, - 9, - 4 + 2, + 3 ]); + Pervasives.assertEqual(myArray === copyOfMyArray, false); }); }); -Mocha.describe("Belt_Array.sliceToEnd", () => { - Mocha.test("Belt_Array.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.describe("Array.find", () => { + Mocha.test("Array.find", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); }); }); -Mocha.describe("Belt_Array.slice", () => { - Mocha.test("Belt_Array.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.describe("Array.some", () => { + Mocha.test("Array.some", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); }); }); -Mocha.describe("Belt_Array.concatMany", () => { - Mocha.test("Belt_Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("Array.last", () => { + Mocha.test("Array.last", () => { + Pervasives.assertEqual($$Array.last([ + "Hello", + "Hi", + "Good bye" + ]), "Good bye"); + Pervasives.assertEqual($$Array.last([]), undefined); }); }); -Mocha.describe("Belt_Array.concat", () => { - Mocha.test("Belt_Array.concat", () => { - Primitive_object.equal(Belt_Array.concat([ +Mocha.describe("Type.typeof", () => { + Mocha.test("Type.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..."); + } + }); +}); + +Mocha.describe("String.make", () => { + Mocha.test("String.make", () => { + String(3.5) === "3.5"; + String([ 1, 2, 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, - 3, - 4, - 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); + ]) === "1,2,3"; }); }); -Mocha.describe("Belt_Array.unzip", () => { - Mocha.test("Belt_Array.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.describe("String.trim", () => { + Mocha.test("String.trim", () => { + " abc def ".trim() === "abc def"; + "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; }); }); -Mocha.describe("Belt_Array.zipBy", () => { - Mocha.test("Belt_Array.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Set.forEach", () => { + Mocha.test("Set.forEach", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue2"); + set.forEach(value => { + console.log(value); + }); }); }); -Mocha.describe("Belt_Array.zip", () => { - Mocha.test("Belt_Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] +Mocha.describe("Set.toArray", () => { + Mocha.test("Set.toArray", () => { + let set = new Set([ + "apple", + "orange", + "apple", + "banana" ]); + Array.from(set); }); }); -Mocha.describe("Belt_Array.makeBy", () => { - Mocha.test("Belt_Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("RegExp.test", () => { + Mocha.test("RegExp.test", () => { + let regexp = new RegExp("\\w+"); + if (regexp.test("ReScript is cool!")) { + console.log("Yay, there's a word in there."); + } + }); }); -Mocha.describe("Belt_Array.rangeBy", () => { - Mocha.test("Belt_Array.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.describe("RegExp.exec", () => { + Mocha.test("RegExp.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.describe("Belt_Array.range", () => { - Mocha.test("Belt_Array.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.describe("Promise.any", () => { + Mocha.test("Promise.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.describe("Belt_Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt_Array.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.describe("Promise.all", () => { + Mocha.test("Promise.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.describe("Belt_Array.makeUninitialized", () => { - Mocha.test("Belt_Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Object.make", () => { + Mocha.test("Object.make", () => { + let x = {}; + Object.keys(x).length; + Option.isSome(x["toString"]); }); }); -Mocha.describe("Belt_Array.reverse", () => { - Mocha.test("Belt_Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Object.seal", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1551, + 7 + ], + Error: new Error() + }; + } + + } + point["x"] = 13; }); }); -Mocha.describe("Belt_Array.reverseInPlace", () => { - Mocha.test("Belt_Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("List.length", () => { + Mocha.test("List.length", () => { + List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt_Array.get", () => { - Mocha.test("Belt_Array.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.describe("List.getExn", () => { + Mocha.test("List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.assertEqual(List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = 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", + 1580, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_Array.length", () => { - Mocha.test("Belt_Array.length", () => {}); -}); - -Mocha.describe("Belt_HashMap.logStats", () => { - Mocha.test("Belt_HashMap.logStats", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("List.concat", () => { + Mocha.test("List.concat", () => { + List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.logStats(hMap); }); }); -Mocha.describe("Belt_HashMap.getBucketHistogram", () => { - Mocha.test("Belt_HashMap.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.describe("List.reduce", () => { + Mocha.test("List.reduce", () => { + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); }); }); -Mocha.describe("Belt_HashMap.mergeMany", () => { - Mocha.test("Belt_HashMap.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.describe("List.every2", () => { + Mocha.test("List.every2", () => { + List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); }); }); -Mocha.describe("Belt_HashMap.fromArray", () => { - Mocha.test("Belt_HashMap.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.describe("List.filter", () => { + Mocha.test("List.filter", () => { + let isEven = x => x % 2 === 0; + List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Option.isSome); }); }); -Mocha.describe("Belt_HashMap.valuesToArray", () => { - Mocha.test("Belt_HashMap.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("Null.getExn", () => { + Mocha.test("Null.getExn", () => { + Pervasives.assertEqual(Null.getExn(3), 3); + let exit = 0; + let value; + try { + value = 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", + 1643, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "ReScript"); + } + let exit$1 = 0; + let val; + try { + val = 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", + 1649, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_HashMap.keysToArray", () => { - Mocha.test("Belt_HashMap.keysToArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Math.fround", () => { + Mocha.test("Math.fround", () => { + Math.fround(5.5) === 5.5; + Math.fround(5.05) === 5.050000190734863; + }); +}); + +Mocha.describe("Math.random", () => { + Mocha.test("Math.random", () => { + Math.random(); + }); +}); + +Mocha.describe("Map.forEach", () => { + Mocha.test("Map.forEach", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach(value => { + console.log(value); }); - 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.describe("Belt_HashMap.toArray", () => { - Mocha.test("Belt_HashMap.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.describe("Map.entries", () => { + Mocha.test("Map.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.describe("Belt_HashMap.size", () => { - Mocha.test("Belt_HashMap.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.describe("Int.toFixed", () => { + Mocha.test("Int.toFixed", () => { + (123456).toFixed(); + (10).toFixed(); + (300).toFixed(4); + (300).toFixed(1); }); }); -Mocha.describe("Belt_HashMap.keepMapInPlace", () => { - Mocha.test("Belt_HashMap.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.describe("Int.toFloat", () => { + Mocha.test("Int.toFloat", () => {}); }); -Mocha.describe("Belt_HashMap.reduce", () => { - Mocha.test("Belt_HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); +Mocha.describe("Float.isNaN", () => { + Mocha.test("Float.isNaN", () => { + isNaN(3.0); + isNaN(NaN); }); }); -Mocha.describe("Belt_HashMap.forEach", () => { - Mocha.test("Belt_HashMap.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.describe("Float.toInt", () => { + Mocha.test("Float.toInt", () => {}); +}); + +Mocha.describe("Float.clamp", () => { + Mocha.test("Float.clamp", () => { + Float.clamp(undefined, undefined, 4.2) === 4.2; + Float.clamp(4.3, undefined, 4.2) === 4.3; + Float.clamp(undefined, 4.1, 4.2) === 4.1; + Float.clamp(4.3, 4.1, 4.2) === 4.3; }); }); -Mocha.describe("Belt_HashMap.remove", () => { - Mocha.test("Belt_HashMap.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.describe("Error.stack", () => { + Mocha.test("Error.stack", () => { + let error = new Error("error"); + console.log(error.stack); }); }); -Mocha.describe("Belt_HashMap.has", () => { - Mocha.test("Belt_HashMap.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.describe("Error.raise", () => { + Mocha.test("Error.raise", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); }); }); -Mocha.describe("Belt_HashMap.get", () => { - Mocha.test("Belt_HashMap.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.describe("Error.panic", () => { + Mocha.test("Error.panic", () => { + try { + $$Error.panic("Uh oh. This was unexpected!"); + } catch (raw_obj) { + let obj = Primitive_exceptions.internalToException(raw_obj); + if (obj.RE_EXN_ID === 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", + 1799, + 15 + ], + Error: new Error() + }; + } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1800, + 12 + ], + Error: new Error() + }; + } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 1802, + 7 + ], + Error: new Error() + }; + } + } }); }); -Mocha.describe("Belt_HashMap.copy", () => { - Mocha.test("Belt_HashMap.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.describe("Date.getDay", () => { + Mocha.test("Date.getDay", () => { + new Date("2023-02-20T16:40:00.00").getDay(); }); }); -Mocha.describe("Belt_HashMap.set", () => { - Mocha.test("Belt_HashMap.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.describe("Date.toJSON", () => { + Mocha.test("Date.toJSON", () => { + new Date("2023-01-01T00:00:00.00+00:00").toJSON(); + new Date("").toJSON(); }); }); -Mocha.describe("Belt_HashMap.isEmpty", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.clear", () => { - Mocha.test("Belt_HashMap.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.describe("Dict.delete", () => { + Mocha.test("Dict.delete", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + Dict.$$delete(dict, "someKey"); }); }); -Mocha.describe("Belt_HashMap.make", () => { - Mocha.test("Belt_HashMap.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.describe("Dict.assign", () => { + Mocha.test("Dict.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.describe("Belt.Map.Dict.findFirstBy", () => { - Mocha.test("Belt.Map.Dict.findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.dir", () => { + Mocha.test("Console.dir", () => { + console.dir({ + language: "rescript", + version: "10.1.2" }); - 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.String.findFirstBy", () => { - Mocha.test("Belt.Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); }); }); -Mocha.describe("Belt.Map.Int.findFirstBy", () => { - Mocha.test("Belt.Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Console.log", () => { + Mocha.test("Console.log", () => { + console.log("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.log(obj); }); }); -Mocha.describe("Belt.Set.Dict.split", () => { - Mocha.test("Belt.Set.Dict.split", () => { +Mocha.describe("Belt_Set.eq", () => { + Mocha.test("Belt_Set.eq", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_SetDict.fromArray([ - 1, + let s0 = Belt_Set.fromArray([ + 5, 2, + 3 + ], IntCmp); + let s1 = Belt_Set.fromArray([ 3, - 4, + 2, 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]); + ], IntCmp); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); }); }); -Mocha.describe("Belt.Set.Dict.get", () => { - Mocha.test("Belt.Set.Dict.get", () => { +Mocha.describe("Belt.Option", () => { + Mocha.test("Belt.Option", () => {}); +}); + +Mocha.describe("Belt.Set.eq", () => { + Mocha.test("Belt.Set.eq", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_SetDict.fromArray([ - 1, + let s0 = Belt_Set.fromArray([ + 5, 2, + 3 + ], IntCmp); + let s1 = Belt_Set.fromArray([ 3, - 4, + 2, 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); + ], IntCmp); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); }); }); -Mocha.describe("Belt.Set.Dict.maxUndefined", () => { - Mocha.test("Belt.Set.Dict.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.describe("Array.shift", () => { + Mocha.test("Array.shift", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.shift(), "hi"); + Pervasives.assertEqual(someArray, ["hello"]); }); }); -Mocha.describe("Belt.Set.Dict.maximum", () => { - Mocha.test("Belt.Set.Dict.maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ +Mocha.describe("Array.slice", () => { + Mocha.test("Array.slice", () => { + Pervasives.assertEqual([ + 1, + 2, 3, + 4 + ].slice(1, 3), [ 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maximum(undefined); - Belt_SetDict.maximum(s1); + 3 + ]); }); }); -Mocha.describe("Belt.Set.Dict.minUndefined", () => { - Mocha.test("Belt.Set.Dict.minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, +Mocha.describe("Array.every", () => { + Mocha.test("Array.every", () => { + let array = [ 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every(num => num <= 4), true); + Pervasives.assertEqual(array.every(num => num === 1), false); }); }); -Mocha.describe("Belt.Set.Dict.minimum", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.toArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("String.match", () => { + Mocha.test("String.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.describe("Belt.Set.Dict.toList", () => { - Mocha.test("Belt.Set.Dict.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.describe("String.slice", () => { + Mocha.test("String.slice", () => { + "abcdefg".slice(2, 5) === "cde"; + "abcdefg".slice(2, 9) === "cdefg"; + "abcdefg".slice(-4, -2) === "de"; + "abcdefg".slice(5, 1) === ""; }); }); -Mocha.describe("Belt.Set.Dict.size", () => { - Mocha.test("Belt.Set.Dict.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.describe("String.split", () => { + Mocha.test("String.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.describe("Belt.Set.Dict.partition", () => { - Mocha.test("Belt.Set.Dict.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.describe("Result.mapOr", () => { + Mocha.test("Result.mapOr", () => { + Result.mapOr({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Result.mapOr({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; }); }); -Mocha.describe("Belt.Set.Dict.keep", () => { - Mocha.test("Belt.Set.Dict.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.describe("Result.getOr", () => { + Mocha.test("Result.getOr", () => { + Result.getOr({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Result.getOr({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("Belt.Set.Dict.some", () => { - Mocha.test("Belt.Set.Dict.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.describe("Result.equal", () => { + Mocha.test("Result.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; + Result.equal(good1, good2, mod10equal) === true; + Result.equal(good1, bad1, mod10equal) === false; + Result.equal(bad2, good2, mod10equal) === false; + Result.equal(bad1, bad2, mod10equal) === true; }); }); -Mocha.describe("Belt.Set.Dict.every", () => { - Mocha.test("Belt.Set.Dict.every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Promise.make", () => { + Mocha.test("Promise.make", () => { + $$Promise.$$catch(new Promise((resolve, reject) => resolve("success")).then(str => Promise.resolve((console.log(str), undefined))), param => { + console.log("Error occurred"); + return Promise.resolve(); }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); }); }); -Mocha.describe("Belt.Set.Dict.reduce", () => { - Mocha.test("Belt.Set.Dict.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Promise.then", () => { + Mocha.test("Promise.then", () => { + Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { + console.log("Your lucky number is: ", num); + return Promise.resolve(); }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp.cmp); - Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); }); }); -Mocha.describe("Belt.Set.Dict.forEach", () => { - Mocha.test("Belt.Set.Dict.forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Promise.race", () => { + Mocha.test("Promise.race", () => { + let racer = (ms, name) => new Promise((resolve, param) => { + setTimeout(() => resolve(name), ms); }); - 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); + 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.describe("Belt.Set.Dict.eq", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.subset", () => { - Mocha.test("Belt.Set.Dict.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.describe("Option.mapOr", () => { + Mocha.test("Option.mapOr", () => { + Option.mapOr(3, 0, x => x + 5 | 0); + Option.mapOr(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("Belt.Set.Dict.diff", () => { - Mocha.test("Belt.Set.Dict.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.describe("Option.getOr", () => { + Mocha.test("Option.getOr", () => { + Option.getOr(undefined, "Banana"); + Option.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); }); }); -Mocha.describe("Belt.Set.Dict.intersect", () => { - Mocha.test("Belt.Set.Dict.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.describe("Option.equal", () => { + Mocha.test("Option.equal", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Option.equal(3, 15, clockEqual); + Option.equal(3, undefined, clockEqual); + Option.equal(undefined, 3, clockEqual); + Option.equal(undefined, undefined, clockEqual); }); }); -Mocha.describe("Belt.Set.Dict.union", () => { - Mocha.test("Belt.Set.Dict.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("Nullable.map", () => { + Mocha.test("Nullable.map", () => { + Nullable.map(3, x => Math.imul(x, x)); + Nullable.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt.Set.Dict.removeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("List.headExn", () => { + Mocha.test("List.headExn", () => { + Pervasives.assertEqual(List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = 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", + 2188, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Set.Dict.remove", () => { - Mocha.test("Belt.Set.Dict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.tailExn", () => { + Mocha.test("List.tailExn", () => { + Pervasives.assertEqual(List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } }); - 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); + let exit = 0; + let val; + try { + val = 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", + 2202, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Set.Dict.mergeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("List.splitAt", () => { + Mocha.test("List.splitAt", () => { + List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); }); }); -Mocha.describe("Belt.Set.Dict.add", () => { - Mocha.test("Belt.Set.Dict.add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.toArray", () => { + Mocha.test("List.toArray", () => { + List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt.Set.Dict.has", () => { - Mocha.test("Belt.Set.Dict.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.reverse", () => { + Mocha.test("List.reverse", () => { + List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt.Set.Dict.isEmpty", () => { - Mocha.test("Belt.Set.Dict.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.forEach", () => { + Mocha.test("List.forEach", () => { + List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); }); }); -Mocha.describe("Belt.Set.Dict.fromArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("List.reduce2", () => { + Mocha.test("List.reduce2", () => { + List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Belt.Set.Dict.empty", () => { - Mocha.test("Belt.Set.Dict.empty", () => {}); -}); - -Mocha.describe("Belt.Float./", () => { - Mocha.test("Belt.Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); +Mocha.describe("List.compare", () => { + Mocha.test("List.compare", () => { + List.compare({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + List.compare({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + 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); + 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); + 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.describe("Belt.Float.*", () => { - Mocha.test("Belt.Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); +Mocha.describe("Null.forEach", () => { + Mocha.test("Null.forEach", () => { + Null.forEach("thing", x => { + console.log(x); + }); + Null.forEach(null, x => { + console.log(x); + }); }); }); -Mocha.describe("Belt.Float.-", () => { - Mocha.test("Belt.Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); +Mocha.describe("Null.flatMap", () => { + Mocha.test("Null.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Null.flatMap(2, addIfAboveOne); + Null.flatMap(-4, addIfAboveOne); + Null.flatMap(null, addIfAboveOne); }); }); -Mocha.describe("Belt.Float.+", () => { - Mocha.test("Belt.Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); +Mocha.describe("Math.minMany", () => { + Mocha.test("Math.minMany", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + isFinite(Math.min()); }); }); -Mocha.describe("Belt.Float.toString", () => { - Mocha.test("Belt.Float.toString", () => { - console.log(String(1.0) === "1.0"); +Mocha.describe("Math.maxMany", () => { + Mocha.test("Math.maxMany", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + isFinite(Math.max()); }); }); -Mocha.describe("Belt.Float.fromString", () => { - Mocha.test("Belt.Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); +Mocha.describe("Math.Int.abs", () => { + Mocha.test("Math.Int.abs", () => { + Math.abs(-2); + Math.abs(3); }); }); -Mocha.describe("Belt.Float.fromInt", () => { - Mocha.test("Belt.Float.fromInt", () => { - console.log(1 === 1.0); +Mocha.describe("Math.Int.min", () => { + Mocha.test("Math.Int.min", () => { + Math.min(1, 2); + Math.min(-1, -2); }); }); -Mocha.describe("Belt.Float.toInt", () => { - Mocha.test("Belt.Float.toInt", () => { - console.log(true); +Mocha.describe("Math.Int.max", () => { + Mocha.test("Math.Int.max", () => { + Math.max(1, 2); + Math.max(-1, -2); }); }); -Mocha.describe("Belt.Int./", () => { - Mocha.test("Belt.Int./", () => { - Pervasives.assertEqual(2, 2); +Mocha.describe("Math.Int.pow", () => { + Mocha.test("Math.Int.pow", () => { + Math.pow(2, 4); + Math.pow(3, 4); }); }); -Mocha.describe("Belt.Int.*", () => { - Mocha.test("Belt.Int.*", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Int.toString", () => { + Mocha.test("Int.toString", () => { + (1000).toString(); + (-1000).toString(); + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); }); }); -Mocha.describe("Belt.Int.-", () => { - Mocha.test("Belt.Int.-", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Date.getTime", () => { + Mocha.test("Date.getTime", () => { + new Date("2023-02-20").getTime(); }); }); -Mocha.describe("Belt.Int.+", () => { - Mocha.test("Belt.Int.+", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Date.getDate", () => { + Mocha.test("Date.getDate", () => { + new Date("2023-02-20T16:40:00.00").getDate(); }); }); -Mocha.describe("Belt.Int.toString", () => { - Mocha.test("Belt.Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); +Mocha.describe("Date.setDate", () => { + Mocha.test("Date.setDate", () => { + new Date("2023-02-20T16:40:00.00").setDate(1); }); }); -Mocha.describe("Belt.Int.fromString", () => { - Mocha.test("Belt.Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); +Mocha.describe("Dict.toArray", () => { + Mocha.test("Dict.toArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let asArray = Object.entries(dict); + console.log(asArray); }); }); -Mocha.describe("Belt.Int.fromFloat", () => { - Mocha.test("Belt.Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Dict.forEach", () => { + Mocha.test("Dict.forEach", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEach(dict, value => { + console.log(value); + }); }); }); -Mocha.describe("Belt.Int.toFloat", () => { - Mocha.test("Belt.Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); +Mocha.describe("Console.info", () => { + Mocha.test("Console.info", () => { + console.info("Information"); + console.info([ + "Hello", + "JS" + ]); }); }); -Mocha.describe("Belt.Result.cmp", () => { - Mocha.test("Belt.Result.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.describe("Console.log2", () => { + Mocha.test("Console.log2", () => { + console.log("Hello", "World"); + console.log([ + 1, + 2, + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt.Result.eq", () => { - Mocha.test("Belt.Result.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.describe("Console.log3", () => { + Mocha.test("Console.log3", () => { + console.log("Hello", "World", "ReScript"); + console.log("One", 2, 3); }); }); -Mocha.describe("Belt.Result.getWithDefault", () => { - Mocha.test("Belt.Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; +Mocha.describe("Console.log4", () => { + Mocha.test("Console.log4", () => { + console.log("Hello", "World", "ReScript", "!!!"); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); }); }); -Mocha.describe("Belt.Result.flatMap", () => { - Mocha.test("Belt.Result.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.describe("Console.log5", () => { + Mocha.test("Console.log5", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" }); }); }); -Mocha.describe("Belt.Result.map", () => { - Mocha.test("Belt.Result.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.describe("Belt.Result.mapWithDefault", () => { - Mocha.test("Belt.Result.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("Console.log6", () => { + Mocha.test("Console.log6", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.log([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.Result.getExn", () => { - Mocha.test("Belt.Result.getExn", () => { - Pervasives.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", - 2698, - 7 - ], - Error: new Error() - }; +Mocha.describe("Console.time", () => { + Mocha.test("Console.time", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); } - - }); -}); - -Mocha.describe("Belt.Option.cmp", () => { - Mocha.test("Belt.Option.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); + console.timeEnd("for_time"); }); }); -Mocha.describe("Belt.Option.eq", () => { - Mocha.test("Belt.Option.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.describe("Console.warn", () => { + Mocha.test("Console.warn", () => { + console.warn("Warning"); + console.warn([ + "Warning", + "invalid number" + ]); }); }); -Mocha.describe("Belt.Option.isNone", () => { - Mocha.test("Belt.Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); +Mocha.describe("Belt_Set.has", () => { + Mocha.test("Belt_Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); }); }); -Mocha.describe("Belt.Option.isSome", () => { - Mocha.test("Belt.Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); +Mocha.describe("Belt_Set.add", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt.Option.orElse", () => { - Mocha.test("Belt.Option.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_Set.get", () => { + Mocha.test("Belt_Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); }); }); -Mocha.describe("Belt.Option.getWithDefault", () => { - Mocha.test("Belt.Option.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.describe("Belt_Map.Int", () => { + Mocha.test("Belt_Map.Int", () => {}); }); -Mocha.describe("Belt.Option.flatMap", () => { - Mocha.test("Belt.Option.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.describe("Belt_Map.has", () => { + Mocha.test("Belt_Map.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.describe("Belt.Option.map", () => { - Mocha.test("Belt.Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Belt_Map.get", () => { + Mocha.test("Belt_Map.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.describe("Belt.Option.mapWithDefault", () => { - Mocha.test("Belt.Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); +Mocha.describe("Belt_Map.set", () => { + Mocha.test("Belt_Map.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.describe("Belt.Option.getExn", () => { - Mocha.test("Belt.Option.getExn", () => { - Pervasives.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", - 2851, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_List.eq", () => { + Mocha.test("Belt_List.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.describe("Belt.Option.forEach", () => { - Mocha.test("Belt.Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); +Mocha.describe("Belt.HashSet", () => { + Mocha.test("Belt.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.describe("Belt.Option.keep", () => { - Mocha.test("Belt.Option.keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); +Mocha.describe("Belt.HashMap", () => { + Mocha.test("Belt.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.describe("Belt.HashMap.logStats", () => { - Mocha.test("Belt.HashMap.logStats", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt.List.eq", () => { + Mocha.test("Belt.List.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.describe("Belt.Set.has", () => { + Mocha.test("Belt.Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.logStats(hMap); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); }); }); -Mocha.describe("Belt.HashMap.getBucketHistogram", () => { - Mocha.test("Belt.HashMap.getBucketHistogram", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt.Set.add", () => { + Mocha.test("Belt.Set.add", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.getBucketHistogram(hMap); + 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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt.HashMap.mergeMany", () => { - Mocha.test("Belt.HashMap.mergeMany", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt.Set.get", () => { + Mocha.test("Belt.Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.mergeMany(hMap, [ - [ + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); + }); +}); + +Mocha.describe("Belt.Map.Int", () => { + Mocha.test("Belt.Map.Int", () => {}); +}); + +Mocha.describe("Belt.Map.has", () => { + Mocha.test("Belt.Map.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.has(Belt_Map.fromArray([[ 1, "1" - ], - [ - 2, - "2" - ] - ]); + ]], IntCmp), 1) === true; }); }); -Mocha.describe("Belt.HashMap.fromArray", () => { - Mocha.test("Belt.HashMap.fromArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt.Map.get", () => { + Mocha.test("Belt.Map.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let s0 = Belt_HashMap.fromArray([ + Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], [ 1, - "value1" + "1" ], [ - 2, - "value2" + 3, + "3" ] - ], IntHash); - Primitive_object.equal(Belt_HashMap.toArray(s0), [ + ], IntCmp), 2), "2"); + Belt_Map.get(Belt_Map.fromArray([ + [ + 2, + "2" + ], [ 1, - "value1" + "1" ], [ - 2, - "value2" + 3, + "3" ] - ]); - }); -}); - -Mocha.describe("Belt.HashMap.valuesToArray", () => { - Mocha.test("Belt.HashMap.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.HashMap.keysToArray", () => { - Mocha.test("Belt.HashMap.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 - ]); + ], IntCmp), 2) === undefined; }); }); -Mocha.describe("Belt.HashMap.toArray", () => { - Mocha.test("Belt.HashMap.toArray", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt.Map.set", () => { + Mocha.test("Belt.Map.set", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - 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), [ + let s0 = Belt_Map.fromArray([ + [ + 2, + "2" + ], [ 1, - "value1" + "1" ], [ - 2, - "value2" + 3, + "3" ] + ], IntCmp); + let s1 = Belt_Map.set(s0, 2, "3"); + Primitive_object.equal(Belt_Map.valuesToArray(s1), [ + "1", + "3", + "3" ]); }); }); -Mocha.describe("Belt.HashMap.size", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.Float.+", () => { + Mocha.test("Belt.Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); }); }); -Mocha.describe("Belt.HashMap.keepMapInPlace", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.Float.-", () => { + Mocha.test("Belt.Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); }); }); -Mocha.describe("Belt.HashMap.reduce", () => { - Mocha.test("Belt.HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); +Mocha.describe("Belt.Float.*", () => { + Mocha.test("Belt.Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); }); }); -Mocha.describe("Belt.HashMap.forEach", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.Float./", () => { + Mocha.test("Belt.Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); }); }); -Mocha.describe("Belt.HashMap.remove", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Float.+", () => { + Mocha.test("Belt_Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); }); }); -Mocha.describe("Belt.HashMap.has", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Float.-", () => { + Mocha.test("Belt_Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); }); }); -Mocha.describe("Belt.HashMap.get", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Float.*", () => { + Mocha.test("Belt_Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); }); }); -Mocha.describe("Belt.HashMap.copy", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Float./", () => { + Mocha.test("Belt_Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); }); }); -Mocha.describe("Belt.HashMap.set", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.isEmpty", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.clear", () => { - Mocha.test("Belt.HashMap.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.describe("Array.length", () => { + Mocha.test("Array.length", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.length, 2); }); }); -Mocha.describe("Belt.HashMap.make", () => { - Mocha.test("Belt.HashMap.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.describe("Array.concat", () => { + Mocha.test("Array.concat", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = [ + "yay", + "wehoo" + ]; + let someArray = array1.concat(array2); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); }); }); -Mocha.describe("Belt.MutableSet.split", () => { - Mocha.test("Belt.MutableSet.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Array.filter", () => { + Mocha.test("Array.filter", () => { + Pervasives.assertEqual([ 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]); + 4 + ].filter(num => num > 2), [ + 3, + 4 + ]); }); }); -Mocha.describe("Belt.MutableSet.get", () => { - Mocha.test("Belt.MutableSet.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 1, +Mocha.describe("Array.reduce", () => { + Mocha.test("Array.reduce", () => { + Pervasives.assertEqual($$Array.reduce([ 2, 3, - 4, - 5 - ], IntCmp); - Belt_MutableSet.get(s0, 3); - Belt_MutableSet.get(s0, 20); + 4 + ], 1, (a, b) => a + b | 0), 10); + Pervasives.assertEqual($$Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "abcd"); + Pervasives.assertEqual($$Array.reduce([ + 1, + 2, + 3 + ], /* [] */0, List.add), { + hd: 3, + tl: { + hd: 2, + tl: { + hd: 1, + tl: /* [] */0 + } + } + }); + Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); }); }); -Mocha.describe("Belt.MutableSet.maxUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("String.length", () => { + Mocha.test("String.length", () => {}); }); -Mocha.describe("Belt.MutableSet.maximum", () => { - Mocha.test("Belt.MutableSet.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.describe("String.charAt", () => { + Mocha.test("String.charAt", () => { + "ReScript".charAt(0) === "R"; + "Hello".charAt(12) === ""; + "JS".charAt(5) === ""; }); }); -Mocha.describe("Belt.MutableSet.minUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("String.concat", () => { + Mocha.test("String.concat", () => { + "cow".concat("bell") === "cowbell"; + "Re".concat("Script") === "ReScript"; }); }); -Mocha.describe("Belt.MutableSet.minimum", () => { - Mocha.test("Belt.MutableSet.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.describe("String.repeat", () => { + Mocha.test("String.repeat", () => { + "ha".repeat(3) === "hahaha"; + "empty".repeat(0) === ""; }); }); -Mocha.describe("Belt.MutableSet.toArray", () => { - Mocha.test("Belt.MutableSet.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.describe("String.search", () => { + Mocha.test("String.search", () => { + "testing 1 2 3".search(/\d+/) === 8; + "no numbers".search(/\d+/) === -1; }); }); -Mocha.describe("Belt.MutableSet.toList", () => { - Mocha.test("Belt.MutableSet.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.describe("String.padEnd", () => { + Mocha.test("String.padEnd", () => { + "Hello".padEnd(10, ".") === "Hello....."; + "abc".padEnd(1, "") === "abc"; }); }); -Mocha.describe("Belt.MutableSet.size", () => { - Mocha.test("Belt.MutableSet.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.describe("Set.fromArray", () => { + Mocha.test("Set.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.describe("Belt.MutableSet.partition", () => { - Mocha.test("Belt.MutableSet.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.describe("RegExp.global", () => { + Mocha.test("RegExp.global", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.global); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.global); }); }); -Mocha.describe("Belt.MutableSet.keep", () => { - Mocha.test("Belt.MutableSet.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.describe("RegExp.source", () => { + Mocha.test("RegExp.source", () => { + let regexp = new RegExp("\\w+", "g"); + console.log(regexp.source); }); }); -Mocha.describe("Belt.MutableSet.some", () => { - Mocha.test("Belt.MutableSet.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.describe("RegExp.sticky", () => { + Mocha.test("RegExp.sticky", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "my"); + console.log(regexp2.unicode); }); }); -Mocha.describe("Belt.MutableSet.every", () => { - Mocha.test("Belt.MutableSet.every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Promise.catch", () => { + Mocha.test("Promise.catch", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + $$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 === 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); }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Belt_MutableSet.every(s0, isEven); }); }); -Mocha.describe("Belt.MutableSet.reduce", () => { - Mocha.test("Belt.MutableSet.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.describe("Option.filter", () => { + Mocha.test("Option.filter", () => { + Option.filter(10, x => x > 5); + Option.filter(4, x => x > 5); + Option.filter(undefined, x => x > 5); }); }); -Mocha.describe("Belt.MutableSet.forEach", () => { - Mocha.test("Belt.MutableSet.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.describe("Option.getExn", () => { + Mocha.test("Option.getExn", () => { + Pervasives.assertEqual(Option.getExn(3, undefined), 3); + let exit = 0; + let val; + try { + val = Option.getExn(undefined, undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 3126, + 7 + ], + Error: new Error() + }; + } + let exit$1 = 0; + let val$1; + try { + val$1 = 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", + 3131, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.MutableSet.eq", () => { - Mocha.test("Belt.MutableSet.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.describe("Option.orElse", () => { + Mocha.test("Option.orElse", () => { + Primitive_object.equal(Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Option.orElse(undefined, 1066), 1066); + Option.orElse(undefined, undefined) === undefined; }); }); -Mocha.describe("Belt.MutableSet.subset", () => { - Mocha.test("Belt.MutableSet.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.describe("Option.isSome", () => { + Mocha.test("Option.isSome", () => { + Option.isSome(undefined); + Option.isSome(1); }); }); -Mocha.describe("Belt.MutableSet.diff", () => { - Mocha.test("Belt.MutableSet.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.describe("Option.isNone", () => { + Mocha.test("Option.isNone", () => { + Option.isNone(undefined); + Option.isNone(1); }); }); -Mocha.describe("Belt.MutableSet.intersect", () => { - Mocha.test("Belt.MutableSet.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.describe("Object.create", () => { + Mocha.test("Object.create", () => { + let x = { + fruit: "banana" + }; + Object.create(x); }); }); -Mocha.describe("Belt.MutableSet.union", () => { - Mocha.test("Belt.MutableSet.union", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Object.assign", () => { + Mocha.test("Object.assign", () => { + Object.assign({ + a: 1 + }, { + a: 2 }); - 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.MutableSet.removeMany", () => { - Mocha.test("Belt.MutableSet.removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp + Object.assign({ + a: 1, + b: 2 + }, { + a: 0 }); - let set = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); - }); -}); - -Mocha.describe("Belt.MutableSet.remove", () => { - Mocha.test("Belt.MutableSet.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp + Object.assign({ + a: 1 + }, { + a: null }); - 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.describe("Belt.MutableSet.mergeMany", () => { - Mocha.test("Belt.MutableSet.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.describe("Object.freeze", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 3202, + 7 + ], + Error: new Error() + }; + } + + } }); }); -Mocha.describe("Belt.MutableSet.add", () => { - Mocha.test("Belt.MutableSet.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.describe("Nullable.null", () => { + Mocha.test("Nullable.null", () => { + console.log(null); }); }); -Mocha.describe("Belt.MutableSet.has", () => { - Mocha.test("Belt.MutableSet.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.describe("Nullable.make", () => { + Mocha.test("Nullable.make", () => { + let myStr = "Hello"; + if ((myStr == null) || myStr !== myStr) { + console.log("Values did not match."); + } else { + console.log("Yay, values matched!"); + } }); }); -Mocha.describe("Belt.MutableSet.isEmpty", () => { - Mocha.test("Belt.MutableSet.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.forEach2", () => { + Mocha.test("List.forEach2", () => { + 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); }); - let empty = Belt_MutableSet.fromArray([], IntCmp); - let notEmpty = Belt_MutableSet.fromArray([1], IntCmp); - Belt_MutableSet.isEmpty(empty); - Belt_MutableSet.isEmpty(notEmpty); }); }); -Mocha.describe("Belt.MutableSet.copy", () => { - Mocha.test("Belt.MutableSet.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.describe("List.getAssoc", () => { + Mocha.test("List.getAssoc", () => { + List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); }); }); -Mocha.describe("Belt.MutableSet.fromArray", () => { - Mocha.test("Belt.MutableSet.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.describe("List.hasAssoc", () => { + Mocha.test("List.hasAssoc", () => { + List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); }); }); -Mocha.describe("Belt.Map.set", () => { - Mocha.test("Belt.Map.set", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" +Mocha.describe("List.setAssoc", () => { + Mocha.test("List.setAssoc", () => { + List.setAssoc({ + hd: [ + 1, + "a" ], - [ + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + List.setAssoc({ + hd: [ 1, - "1" + "a" ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" - ]); + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); }); }); -Mocha.describe("Belt.Map.remove", () => { - Mocha.test("Belt.Map.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.describe("Null.toOption", () => { + Mocha.test("Null.toOption", () => { + let nullStr = "Hello"; + if (nullStr !== null) { + console.log("Got string:", nullStr); + } else { + console.log("Didn't have a value."); + } }); }); -Mocha.describe("Belt.Map.get", () => { - Mocha.test("Belt.Map.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ +Mocha.describe("Math.Int.imul", () => { + Mocha.test("Math.Int.imul", () => { + Math.imul(3, 4); + Math.imul(-5, 12); + }); +}); + +Mocha.describe("Math.Int.sign", () => { + Mocha.test("Math.Int.sign", () => { + Math.sign(3); + Math.sign(-3); + Math.sign(0); + }); +}); + +Mocha.describe("Math.Int.ceil", () => { + Mocha.test("Math.Int.ceil", () => { + $$Math.Int.ceil(3.7) === 4; + $$Math.Int.ceil(3.0) === 3; + $$Math.Int.ceil(-3.1) === -3; + }); +}); + +Mocha.describe("Map.fromArray", () => { + Mocha.test("Map.fromArray", () => { + let languageRank = [ [ - 2, - "2" + "ReScript", + 1 ], [ - 1, - "1" + "JavaScript", + 2 ], [ - 3, - "3" + "TypeScript", + 3 ] - ], IntCmp), 2), "2"); - Belt_Map.get(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2) === undefined; + ]; + 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.describe("Belt.Map.valuesToArray", () => { - Mocha.test("Belt.Map.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("JSON.parseExn", () => { + Mocha.test("JSON.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 === 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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn$1; + } + } }); }); -Mocha.describe("Belt.Map.keysToArray", () => { - Mocha.test("Belt.Map.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.describe("Iterator.next", () => { + Mocha.test("Iterator.next", () => { + let iterator = ((() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(iterator.next().done, false); + Pervasives.assertEqual(iterator.next().done, true); }); }); -Mocha.describe("Belt.Map.fromArray", () => { - Mocha.test("Belt.Map.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.describe("Int.fromFloat", () => { + Mocha.test("Int.fromFloat", () => {}); +}); + +Mocha.describe("Float.toFixed", () => { + Mocha.test("Float.toFixed", () => { + (123456.0).toFixed(); + (10.0).toFixed(); + (300.0).toFixed(4); + (300.0).toFixed(1); }); }); -Mocha.describe("Belt.Map.toArray", () => { - Mocha.test("Belt.Map.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.describe("Float.fromInt", () => { + Mocha.test("Float.fromInt", () => {}); +}); + +Mocha.describe("Error.message", () => { + Mocha.test("Error.message", () => { + let error = new SyntaxError("Some message here"); + console.log(error.message); }); }); -Mocha.describe("Belt.Map.size", () => { - Mocha.test("Belt.Map.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.describe("Date.fromTime", () => { + Mocha.test("Date.fromTime", () => { + new Date(0.0); + new Date(-86400000.0); + new Date(86400000.0); }); }); -Mocha.describe("Belt.Map.reduce", () => { - Mocha.test("Belt.Map.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.describe("Date.getMonth", () => { + Mocha.test("Date.getMonth", () => { + new Date("2023-01-01").getMonth(); }); }); -Mocha.describe("Belt.Map.forEach", () => { - Mocha.test("Belt.Map.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.describe("Date.getHours", () => { + Mocha.test("Date.getHours", () => { + new Date("2023-02-20T16:40:00.00").getHours(); }); }); -Mocha.describe("Belt.Map.findFirstBy", () => { - Mocha.test("Belt.Map.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); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); +Mocha.describe("Date.setMonth", () => { + Mocha.test("Date.setMonth", () => { + new Date("2023-02-20T16:40:00.00").setMonth(0); }); }); -Mocha.describe("Belt.Map.has", () => { - Mocha.test("Belt.Map.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.describe("Date.setHours", () => { + Mocha.test("Date.setHours", () => { + new Date("2023-02-20T16:40:00.00").setHours(0); }); }); -Mocha.describe("Belt.Map.isEmpty", () => { - Mocha.test("Belt.Map.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; +Mocha.describe("Date.toString", () => { + Mocha.test("Date.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.describe("Belt.Map.make", () => { - Mocha.test("Belt.Map.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.describe("Console.clear", () => { + Mocha.test("Console.clear", () => { + console.clear(); }); }); -Mocha.describe("Belt.Map.Int", () => { - Mocha.test("Belt.Map.Int", () => {}); +Mocha.describe("Console.count", () => { + Mocha.test("Console.count", () => { + console.count("rescript"); + }); }); -Mocha.describe("Belt.Set.split", () => { - Mocha.test("Belt.Set.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]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 +Mocha.describe("Console.debug", () => { + Mocha.test("Console.debug", () => { + console.debug("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.debug(obj); + }); +}); + +Mocha.describe("Console.error", () => { + Mocha.test("Console.error", () => { + console.error("error message"); + console.error([ + "error", + "invalid value" ]); }); }); -Mocha.describe("Belt.Set.get", () => { - Mocha.test("Belt.Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); +Mocha.describe("Console.group", () => { + Mocha.test("Console.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.describe("Belt.Set.maxUndefined", () => { - Mocha.test("Belt.Set.maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.info2", () => { + Mocha.test("Console.info2", () => { + console.info("Info", "failed to download"); + console.info("info", { + name: "ReScript" }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); }); }); -Mocha.describe("Belt.Set.maximum", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Console.info3", () => { + Mocha.test("Console.info3", () => { + console.info("Hello", "World", "ReScript"); + console.info([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + 2, + 3 + ], 4, 5); }); }); -Mocha.describe("Belt.Set.minUndefined", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Console.info4", () => { + Mocha.test("Console.info4", () => { + console.info("Hello", "World", "ReScript", /* '!' */33); + console.info([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + 2, + 3 + ], 4, 5, "lastinfo"); }); }); -Mocha.describe("Belt.Set.minimum", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Console.info5", () => { + Mocha.test("Console.info5", () => { + console.info("Hello", "World", "from", "JS", "!!!"); + console.info([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); }); }); -Mocha.describe("Belt.Set.toList", () => { - Mocha.test("Belt.Set.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, +Mocha.describe("Console.info6", () => { + Mocha.test("Console.info6", () => { + console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.info([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.Set.toArray", () => { - Mocha.test("Belt.Set.toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.table", () => { + Mocha.test("Console.table", () => { + console.table({ + language: "rescript", + version: "10.1.2" }); - let s0 = Belt_Set.fromArray([ - 3, - 2, + }); +}); + +Mocha.describe("Console.trace", () => { + Mocha.test("Console.trace", () => { + console.trace(); + }); +}); + +Mocha.describe("Console.warn2", () => { + Mocha.test("Console.warn2", () => { + console.warn("Hello", "World"); + console.warn([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 2, + 3 + ], 4); + }); +}); + +Mocha.describe("Console.warn3", () => { + Mocha.test("Console.warn3", () => { + console.warn("Hello", "World", "ReScript"); + console.warn([ 1, 2, - 3, - 5 - ]); + 3 + ], 4, 5); }); }); -Mocha.describe("Belt.Set.size", () => { - Mocha.test("Belt.Set.size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.warn4", () => { + Mocha.test("Console.warn4", () => { + console.warn("Hello", "World", "ReScript", "!!!"); + console.warn("first", "second", "third", "fourth"); + }); +}); + +Mocha.describe("Console.warn5", () => { + Mocha.test("Console.warn5", () => { + console.warn("Hello", "World", "from", "JS", "!!!"); + console.warn([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" }); - let s0 = Belt_Set.fromArray([ + }); +}); + +Mocha.describe("Console.warn6", () => { + Mocha.test("Console.warn6", () => { + console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.warn([ 1, - 2, + 2 + ], [ 3, 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.Set.partition", () => { - Mocha.test("Belt.Set.partition", () => { +Mocha.describe("Belt_Set.make", () => { + Mocha.test("Belt_Set.make", () => { 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); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); }); }); -Mocha.describe("Belt.Set.keep", () => { - Mocha.test("Belt.Set.keep", () => { +Mocha.describe("Belt_Set.diff", () => { + Mocha.test("Belt_Set.diff", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isEven = x => x % 2 === 0; let s0 = Belt_Set.fromArray([ - 1, + 5, 2, 3, - 4, - 5 + 5, + 6 ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ + let s1 = Belt_Set.fromArray([ + 5, 2, + 3, + 1, + 5, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, 4 ]); }); }); -Mocha.describe("Belt.Set.some", () => { - Mocha.test("Belt.Set.some", () => { +Mocha.describe("Belt_Set.some", () => { + Mocha.test("Belt_Set.some", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -5059,196 +4302,477 @@ Mocha.describe("Belt.Set.some", () => { }); }); -Mocha.describe("Belt.Set.every", () => { - Mocha.test("Belt.Set.every", () => { +Mocha.describe("Belt_Set.keep", () => { + Mocha.test("Belt_Set.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, - 6, - 8 + 5 ], IntCmp); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + let s1 = Belt_Set.keep(s0, isEven); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); }); }); -Mocha.describe("Belt.Set.reduce", () => { - Mocha.test("Belt.Set.reduce", () => { +Mocha.describe("Belt_Set.size", () => { + Mocha.test("Belt_Set.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); let s0 = Belt_Set.fromArray([ - 5, + 1, 2, 3, - 5, - 6 + 4 ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } + Pervasives.assertEqual(Belt_Set.size(s0), 4); + }); +}); + +Mocha.describe("Belt_Map.make", () => { + Mocha.test("Belt_Map.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.describe("Belt.Set.forEach", () => { - Mocha.test("Belt.Set.forEach", () => { +Mocha.describe("Belt_Map.size", () => { + Mocha.test("Belt_Map.size", () => { 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); - }); - Pervasives.assertEqual(acc.contents, { - hd: 6, + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; + }); +}); + +Mocha.describe("Belt_List.add", () => { + Mocha.test("Belt_List.add", () => { + Belt_List.add({ + hd: 2, tl: { - hd: 5, + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("Belt_List.get", () => { + Mocha.test("Belt_List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } + hd: "C", + tl: /* [] */0 } } - }); + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); }); }); -Mocha.describe("Belt.Set.eq", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); +Mocha.describe("Belt_List.map", () => { + Mocha.test("Belt_List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); }); }); -Mocha.describe("Belt.Set.subset", () => { - Mocha.test("Belt.Set.subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.zip", () => { + Mocha.test("Belt_List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } }); - 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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); }); }); -Mocha.describe("Belt.Set.diff", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); +Mocha.describe("Belt_List.cmp", () => { + Mocha.test("Belt_List.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.describe("Belt.Set.intersect", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Belt_List.has", () => { + Mocha.test("Belt_List.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.describe("Belt.Array.eq", () => { + Mocha.test("Belt.Array.eq", () => { + Belt_Array.eq([ 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_Set.intersect(s0, s1); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ 2, - 3, - 5 - ]); + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Belt.Set.union", () => { - Mocha.test("Belt.Set.union", () => { +Mocha.describe("Belt.List.add", () => { + Mocha.test("Belt.List.add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("Belt.List.get", () => { + Mocha.test("Belt.List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); +}); + +Mocha.describe("Belt.List.map", () => { + Mocha.test("Belt.List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); +}); + +Mocha.describe("Belt.List.zip", () => { + Mocha.test("Belt.List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.cmp", () => { + Mocha.test("Belt.List.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.describe("Belt.List.has", () => { + Mocha.test("Belt.List.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.describe("Belt.Set.make", () => { + Mocha.test("Belt.Set.make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); + }); +}); + +Mocha.describe("Belt.Set.diff", () => { + Mocha.test("Belt.Set.diff", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -5268,586 +4792,521 @@ Mocha.describe("Belt.Set.union", () => { 5, 4 ], IntCmp); - let union = Belt_Set.union(s0, s1); - Pervasives.assertEqual(Belt_Set.toArray(union), [ + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ 1, - 2, - 3, - 4, - 5, - 6 + 4 ]); }); }); -Mocha.describe("Belt.Set.removeMany", () => { - Mocha.test("Belt.Set.removeMany", () => { +Mocha.describe("Belt.Set.some", () => { + Mocha.test("Belt.Set.some", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_Set.fromArray([ + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ 1, 2, - 3, - 4 - ], IntCmp); - let newSet = Belt_Set.removeMany(set, [ - 5, 4, - 3, - 2, - 1 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); + 6, + 8 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); }); }); -Mocha.describe("Belt.Set.remove", () => { - Mocha.test("Belt.Set.remove", () => { +Mocha.describe("Belt.Set.keep", () => { + Mocha.test("Belt.Set.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, - 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); + let s1 = Belt_Set.keep(s0, isEven); Pervasives.assertEqual(Belt_Set.toArray(s1), [ 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 + 4 ]); - Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt.Set.mergeMany", () => { - Mocha.test("Belt.Set.mergeMany", () => { +Mocha.describe("Belt.Set.size", () => { + Mocha.test("Belt.Set.size", () => { 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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + let s0 = Belt_Set.fromArray([ 1, 2, 3, - 4, - 5 - ]); + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.size(s0), 4); }); }); -Mocha.describe("Belt.Set.add", () => { - Mocha.test("Belt.Set.add", () => { +Mocha.describe("Belt.Map.make", () => { + Mocha.test("Belt.Map.make", () => { 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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); + let m = Belt_Map.make(IntCmp); + Belt_Map.set(m, 0, "a"); }); }); -Mocha.describe("Belt.Set.has", () => { - Mocha.test("Belt.Set.has", () => { +Mocha.describe("Belt.Map.size", () => { + Mocha.test("Belt.Map.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; }); }); -Mocha.describe("Belt.Set.isEmpty", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); +Mocha.describe("Belt_Array.eq", () => { + Mocha.test("Belt_Array.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Belt.Set.fromArray", () => { - Mocha.test("Belt.Set.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ +Mocha.describe("Array.fillAll", () => { + Mocha.test("Array.fillAll", () => { + let myArray = [ 1, 2, 3, 4 + ]; + myArray.fill(9); + Pervasives.assertEqual(myArray, [ + 9, + 9, + 9, + 9 ]); }); }); -Mocha.describe("Belt.Set.make", () => { - Mocha.test("Belt.Set.make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); +Mocha.describe("Array.reverse", () => { + Mocha.test("Array.reverse", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.reverse(); + Pervasives.assertEqual(someArray, [ + "hello", + "hi" + ]); }); }); -Mocha.describe("Belt.Range.someBy", () => { - Mocha.test("Belt.Range.someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); +Mocha.describe("Array.unshift", () => { + Mocha.test("Array.unshift", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay"); + Pervasives.assertEqual(someArray, [ + "yay", + "hi", + "hello" + ]); }); }); -Mocha.describe("Belt.Range.some", () => { - Mocha.test("Belt.Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); +Mocha.describe("Array.indexOf", () => { + Mocha.test("Array.indexOf", () => { + Pervasives.assertEqual([ + 1, + 2 + ].indexOf(2), 1); + Pervasives.assertEqual([ + 1, + 2 + ].indexOf(3), -1); + Pervasives.assertEqual([{ + language: "ReScript" + }].indexOf({ + language: "ReScript" + }), -1); }); }); -Mocha.describe("Belt.Range.everyBy", () => { - Mocha.test("Belt.Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); +Mocha.describe("Array.forEach", () => { + Mocha.test("Array.forEach", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach(item => { + console.log(item); + }); }); }); -Mocha.describe("Belt.Range.every", () => { - Mocha.test("Belt.Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); +Mocha.describe("Array.shuffle", () => { + Mocha.test("Array.shuffle", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + $$Array.shuffle(array); + console.log(array); + let array2 = [ + 1, + 2, + 3 + ]; + $$Array.shuffle(array2); + Pervasives.assertEqual(array2.length, 3); }); }); -Mocha.describe("Belt.Range.forEach", () => { - Mocha.test("Belt.Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); -}); - -Mocha.describe("Belt.List.sort", () => { - Mocha.test("Belt.List.sort", () => { - Belt_List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } +Mocha.describe("Array.flatMap", () => { + Mocha.test("Array.flatMap", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.flatMap(item => { + switch (item) { + case "ReScript" : + return [ + 1, + 2, + 3 + ]; + case "TypeScript" : + return [ + 4, + 5, + 6 + ]; + case "JavaScript" : + return [ + 7, + 8, + 9 + ]; } - }, (a, b) => a - b | 0); + }), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); }); }); -Mocha.describe("Belt.List.setAssoc", () => { - Mocha.test("Belt.List.setAssoc", () => { - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } +Mocha.describe("Array.findMap", () => { + Mocha.test("Array.findMap", () => { + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3 + ], n => { + if (n % 2 === 0) { + return n - 2 | 0; } - }, 2, "x", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 + + }), 0); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return n - 8 | 0; } - }, 2, "b", (a, b) => a === b); - Belt_List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } + + }), -6); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), undefined); + Pervasives.assertEqual($$Array.findMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); + + }), undefined); }); }); -Mocha.describe("Belt.List.removeAssoc", () => { - Mocha.test("Belt.List.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.describe("String.indexOf", () => { + Mocha.test("String.indexOf", () => { + "bookseller".indexOf("ok") === 2; + "bookseller".indexOf("sell") === 4; + "beekeeper".indexOf("ee") === 1; + "bookseller".indexOf("xyz") === -1; }); }); -Mocha.describe("Belt.List.hasAssoc", () => { - Mocha.test("Belt.List.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.describe("String.replace", () => { + Mocha.test("String.replace", () => { + "old string".replace("old", "new") === "new string"; + "the cat and the dog".replace("the", "this") === "this cat and the dog"; }); }); -Mocha.describe("Belt.List.getAssoc", () => { - Mocha.test("Belt.List.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.describe("String.trimEnd", () => { + Mocha.test("String.trimEnd", () => { + " Hello world! ".trimEnd() === " Hello world!"; + " Hello world! ".trimEnd() === " Hello world!"; }); }); -Mocha.describe("Belt.List.unzip", () => { - Mocha.test("Belt.List.unzip", () => { - Belt_List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 +Mocha.describe("Result.flatMap", () => { + Mocha.test("Result.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(Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 }); - 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 - } - } - } - } - } + Primitive_object.equal(Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" }); }); }); -Mocha.describe("Belt.List.partition", () => { - Mocha.test("Belt.List.partition", () => { - Pervasives.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.describe("Result.compare", () => { + Mocha.test("Result.compare", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Result.compare({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; }); }); -Mocha.describe("Belt.List.keepMap", () => { - Mocha.test("Belt.List.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; - } - +Mocha.describe("Result.forEach", () => { + Mocha.test("Result.forEach", () => { + Result.forEach({ + TAG: "Ok", + _0: 3 + }, prim => { + console.log(prim); + }); + Result.forEach({ + TAG: "Error", + _0: "x" + }, prim => { + console.log(prim); }); - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); }); }); -Mocha.describe("Belt.List.filterWithIndex", () => { - Mocha.test("Belt.List.filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } +Mocha.describe("RegExp.unicode", () => { + Mocha.test("RegExp.unicode", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "mu"); + console.log(regexp2.unicode); + }); +}); + +Mocha.describe("Promise.reject", () => { + Mocha.test("Promise.reject", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + $$Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }), v => { + if (v.RE_EXN_ID === TestError) { + Pervasives.assertEqual(v._1, "some rejected value"); + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 4327, + 9 + ], + Error: new Error() + }; } - }, (_x, index) => index % 2 === 0); + return Promise.resolve(); + }); }); }); -Mocha.describe("Belt.List.keepWithIndex", () => { - Mocha.test("Belt.List.keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } +Mocha.describe("Option.forEach", () => { + Mocha.test("Option.forEach", () => { + Option.forEach("thing", x => { + console.log(x); + }); + Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Option.flatMap", () => { + Mocha.test("Option.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; } - }, (_x, index) => index % 2 === 0); + + }; + Option.flatMap(2, addIfAboveOne); + Option.flatMap(-4, addIfAboveOne); + Option.flatMap(undefined, addIfAboveOne); }); }); -Mocha.describe("Belt.List.filter", () => { - Mocha.test("Belt.List.filter", () => { +Mocha.describe("Option.compare", () => { + Mocha.test("Option.compare", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Option.compare(3, 15, clockCompare); + Option.compare(3, 14, clockCompare); + Option.compare(2, 15, clockCompare); + Option.compare(undefined, 15, clockCompare); + Option.compare(14, undefined, clockCompare); + Option.compare(undefined, undefined, clockCompare); + }); +}); + +Mocha.describe("Nullable.getOr", () => { + Mocha.test("Nullable.getOr", () => { + Nullable.getOr(null, "Banana"); + Nullable.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNullable("Jane")); + greet(undefined); + }); +}); + +Mocha.describe("Nullable.mapOr", () => { + Mocha.test("Nullable.mapOr", () => { + Nullable.mapOr(3, 0, x => x + 5 | 0); + Nullable.mapOr(null, 0, x => x + 5 | 0); + }); +}); + +Mocha.describe("List.fromArray", () => { + Mocha.test("List.fromArray", () => { + List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("List.filterMap", () => { + Mocha.test("List.filterMap", () => { let isEven = x => x % 2 === 0; - Belt_List.filter({ + List.filterMap({ hd: 1, tl: { hd: 2, @@ -5859,27 +5318,28 @@ Mocha.describe("Belt.List.filter", () => { } } } - }, isEven); - Belt_List.filter({ - hd: undefined, + }, x => { + if (isEven(x)) { + return x; + } + + }); + List.filterMap({ + hd: 1, tl: { hd: 2, tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } + hd: undefined, + tl: /* [] */0 } } - }, Belt_Option.isSome); + }, x => x); }); }); -Mocha.describe("Belt.List.keep", () => { - Mocha.test("Belt.List.keep", () => { - let isEven = x => x % 2 === 0; - Belt_List.keep({ +Mocha.describe("List.partition", () => { + Mocha.test("List.partition", () => { + List.partition({ hd: 1, tl: { hd: 2, @@ -5891,862 +5351,419 @@ Mocha.describe("Belt.List.keep", () => { } } } - }, isEven); - Belt_List.keep({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Belt_Option.isSome); + }, x => x > 2); }); }); -Mocha.describe("Belt.List.getBy", () => { - Mocha.test("Belt.List.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.describe("Null.getUnsafe", () => { + Mocha.test("Null.getUnsafe", () => {}); +}); + +Mocha.describe("Math.hypotMany", () => { + Mocha.test("Math.hypotMany", () => { + Math.hypot(3.0, 4.0, 5.0); + Math.hypot(); }); }); -Mocha.describe("Belt.List.has", () => { - Mocha.test("Belt.List.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.describe("Math.Int.clz32", () => { + Mocha.test("Math.Int.clz32", () => { + Math.clz32(1); + Math.clz32(4); }); }); -Mocha.describe("Belt.List.eq", () => { - Mocha.test("Belt.List.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.describe("Math.Int.floor", () => { + Mocha.test("Math.Int.floor", () => { + $$Math.Int.floor(3.7) === 3; + $$Math.Int.floor(3.0) === 3; + $$Math.Int.floor(-3.1) === -4; }); }); -Mocha.describe("Belt.List.cmp", () => { - Mocha.test("Belt.List.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 - } +Mocha.describe("JSON.stringify", () => { + Mocha.test("JSON.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 = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; } - }, Primitive_int.compare); + }; + JSON.stringify(json, replacer); }); }); -Mocha.describe("Belt.List.cmpByLength", () => { - Mocha.test("Belt.List.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.describe("Int.fromString", () => { + Mocha.test("Int.fromString", () => { + Primitive_object.equal(Int.fromString("0", undefined), 0); + Int.fromString("NaN", undefined) === undefined; + Int.fromString("6", 2) === undefined; }); }); -Mocha.describe("Belt.List.some2", () => { - Mocha.test("Belt.List.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.describe("Float.isFinite", () => { + Mocha.test("Float.isFinite", () => { + isFinite(1.0); + isFinite(NaN); + isFinite(Number.POSITIVE_INFINITY); }); }); -Mocha.describe("Belt.List.every2", () => { - Mocha.test("Belt.List.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.describe("Float.parseInt", () => { + Mocha.test("Float.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.describe("Belt.List.some", () => { - Mocha.test("Belt.List.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.describe("Float.toString", () => { + Mocha.test("Float.toString", () => { + (1000.0).toString(); + (-1000.0).toString(); }); }); -Mocha.describe("Belt.List.every", () => { - Mocha.test("Belt.List.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.describe("Date.setHoursM", () => { + Mocha.test("Date.setHoursM", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0); }); }); -Mocha.describe("Belt.List.reduceReverse2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Date.getUTCDay", () => { + Mocha.test("Date.getUTCDay", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); }); }); -Mocha.describe("Belt.List.reduce2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Dict.getUnsafe", () => { + Mocha.test("Dict.getUnsafe", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + let value = dict["key1"]; + console.log(value); }); }); -Mocha.describe("Belt.List.forEach2", () => { - Mocha.test("Belt.List.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.describe("Dict.fromArray", () => { + Mocha.test("Dict.fromArray", () => { + Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); }); }); -Mocha.describe("Belt.List.mapReverse2", () => { - Mocha.test("Belt.List.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.describe("Dict.mapValues", () => { + Mocha.test("Dict.mapValues", () => { + let dict = Object.fromEntries([ + [ + "key1", + 1 + ], + [ + "key2", + 2 + ] + ]); + Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); + Object.entries(Dict.mapValues(dict, v => v.toString())); }); }); -Mocha.describe("Belt.List.reduceReverse", () => { - Mocha.test("Belt.List.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.describe("Console.debug2", () => { + Mocha.test("Console.debug2", () => { + console.debug("Hello", "World"); + console.debug([ + 1, + 2, + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt.List.reduceWithIndex", () => { - Mocha.test("Belt.List.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.describe("Console.debug3", () => { + Mocha.test("Console.debug3", () => { + console.debug("Hello", "World", "ReScript"); + console.debug("One", 2, 3); }); }); -Mocha.describe("Belt.List.reduce", () => { - Mocha.test("Belt.List.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.describe("Console.debug4", () => { + Mocha.test("Console.debug4", () => { + console.debug("Hello", "World", "ReScript", "!!!"); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); }); }); -Mocha.describe("Belt.List.forEachWithIndex", () => { - Mocha.test("Belt.List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); +Mocha.describe("Console.debug5", () => { + Mocha.test("Console.debug5", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" }); }); }); -Mocha.describe("Belt.List.forEach", () => { - Mocha.test("Belt.List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); +Mocha.describe("Console.debug6", () => { + Mocha.test("Console.debug6", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.debug([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.List.mapReverse", () => { - Mocha.test("Belt.List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); +Mocha.describe("Console.error2", () => { + Mocha.test("Console.error2", () => { + console.error("Error", "here"); + console.error([ + "log", + "error" + ], "message"); }); }); -Mocha.describe("Belt.List.reverse", () => { - Mocha.test("Belt.List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Console.error3", () => { + Mocha.test("Console.error3", () => { + console.error("Hello", "World", "!!!"); + console.error("first", "second", "third"); }); }); -Mocha.describe("Belt.List.toArray", () => { - Mocha.test("Belt.List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Console.error4", () => { + Mocha.test("Console.error4", () => { + console.error("Hello", "World", "ReScript", /* '!' */33); + console.error("first", "second", "third", "fourth"); }); }); -Mocha.describe("Belt.List.fromArray", () => { - Mocha.test("Belt.List.fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 - ]); +Mocha.describe("Console.error5", () => { + Mocha.test("Console.error5", () => { + console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); + console.error(1, "second", "third", "fourth", /* 'c' */99); }); }); -Mocha.describe("Belt.List.mapWithIndex", () => { - Mocha.test("Belt.List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); +Mocha.describe("Console.error6", () => { + Mocha.test("Console.error6", () => { + console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.error([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.List.zipBy", () => { - Mocha.test("Belt.List.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_Set.union", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 + ]); }); }); -Mocha.describe("Belt.List.zip", () => { - Mocha.test("Belt.List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.every", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); }); }); -Mocha.describe("Belt.List.map", () => { - Mocha.test("Belt.List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); +Mocha.describe("Belt_Set.split", () => { + Mocha.test("Belt_Set.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]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); }); }); -Mocha.describe("Belt.List.flatten", () => { - Mocha.test("Belt.List.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.describe("Belt_Result.eq", () => { + Mocha.test("Belt_Result.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.describe("Belt.List.reverseConcat", () => { - Mocha.test("Belt.List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); +Mocha.describe("Belt_Option.eq", () => { + Mocha.test("Belt_Option.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.describe("Belt.List.concatMany", () => { - Mocha.test("Belt.List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, +Mocha.describe("Belt_List.head", () => { + Mocha.test("Belt_List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + hd: 3, + tl: /* [] */0 } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 } - ]); + }); }); }); -Mocha.describe("Belt.List.concat", () => { - Mocha.test("Belt.List.concat", () => { - Belt_List.concat({ +Mocha.describe("Belt_List.tail", () => { + Mocha.test("Belt_List.tail", () => { + Belt_List.tail({ hd: 1, tl: { hd: 2, @@ -6755,47 +5772,20 @@ Mocha.describe("Belt.List.concat", () => { tl: /* [] */0 } } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } }); + Belt_List.tail(/* [] */0); }); }); -Mocha.describe("Belt.List.splitAt", () => { - Mocha.test("Belt.List.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.describe("Belt_List.make", () => { + Mocha.test("Belt_List.make", () => { + Belt_List.make(3, 1); }); }); -Mocha.describe("Belt.List.take", () => { - Mocha.test("Belt.List.take", () => { - Belt_List.take({ +Mocha.describe("Belt_List.drop", () => { + Mocha.test("Belt_List.drop", () => { + Belt_List.drop({ hd: 1, tl: { hd: 2, @@ -6804,8 +5794,8 @@ Mocha.describe("Belt.List.take", () => { tl: /* [] */0 } } - }, 1); - Belt_List.take({ + }, 2); + Belt_List.drop({ hd: 1, tl: { hd: 2, @@ -6814,8 +5804,8 @@ Mocha.describe("Belt.List.take", () => { tl: /* [] */0 } } - }, 2); - Belt_List.take({ + }, 3); + Belt_List.drop({ hd: 1, tl: { hd: 2, @@ -6828,9 +5818,9 @@ Mocha.describe("Belt.List.take", () => { }); }); -Mocha.describe("Belt.List.drop", () => { - Mocha.test("Belt.List.drop", () => { - Belt_List.drop({ +Mocha.describe("Belt_List.take", () => { + Mocha.test("Belt_List.take", () => { + Belt_List.take({ hd: 1, tl: { hd: 2, @@ -6839,8 +5829,8 @@ Mocha.describe("Belt.List.drop", () => { tl: /* [] */0 } } - }, 2); - Belt_List.drop({ + }, 1); + Belt_List.take({ hd: 1, tl: { hd: 2, @@ -6849,8 +5839,8 @@ Mocha.describe("Belt.List.drop", () => { tl: /* [] */0 } } - }, 3); - Belt_List.drop({ + }, 2); + Belt_List.take({ hd: 1, tl: { hd: 2, @@ -6863,109 +5853,181 @@ Mocha.describe("Belt.List.drop", () => { }); }); -Mocha.describe("Belt.List.shuffle", () => { - Mocha.test("Belt.List.shuffle", () => { - Belt_List.shuffle({ +Mocha.describe("Belt_List.some", () => { + Mocha.test("Belt_List.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: /* [] */0 + tl: { + hd: 4, + tl: /* [] */0 + } } } - }); + }, isAbove100); }); }); -Mocha.describe("Belt.List.makeBy", () => { - Mocha.test("Belt.List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); - }); -}); - -Mocha.describe("Belt.List.make", () => { - Mocha.test("Belt.List.make", () => { - Belt_List.make(3, 1); - }); -}); - -Mocha.describe("Belt.List.getExn", () => { - Mocha.test("Belt.List.getExn", () => { - let abc = { - hd: "A", +Mocha.describe("Belt_List.keep", () => { + Mocha.test("Belt_List.keep", () => { + let isEven = x => x % 2 === 0; + Belt_List.keep({ + hd: 1, tl: { - hd: "B", + hd: 2, tl: { - hd: "C", - tl: /* [] */0 + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } } } - }; - Pervasives.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", - 5127, - 7 - ], - Error: new Error() - }; - } - + }, isEven); + Belt_List.keep({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Belt_Option.isSome); }); }); -Mocha.describe("Belt.List.get", () => { - Mocha.test("Belt.List.get", () => { - let abc = { - hd: "A", +Mocha.describe("Belt_List.sort", () => { + Mocha.test("Belt_List.sort", () => { + Belt_List.sort({ + hd: 5, tl: { - hd: "B", + hd: 4, tl: { - hd: "C", - tl: /* [] */0 + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } } } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); + }, (a, b) => a - b | 0); }); }); -Mocha.describe("Belt.List.add", () => { - Mocha.test("Belt.List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); +Mocha.describe("Belt.Array.get", () => { + Mocha.test("Belt.Array.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.describe("Belt.List.tailExn", () => { - Mocha.test("Belt.List.tailExn", () => { - Pervasives.assertEqual(Belt_List.tailExn({ +Mocha.describe("Belt.Array.zip", () => { + Mocha.test("Belt.Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt.Array.map", () => { + Mocha.test("Belt.Array.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Array.cmp", () => { + Mocha.test("Belt.Array.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.describe("Belt.List.head", () => { + Mocha.test("Belt.List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ hd: 1, tl: { hd: 2, @@ -6974,33 +6036,7 @@ Mocha.describe("Belt.List.tailExn", () => { 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", - 5165, - 7 - ], - Error: new Error() - }; - } - }); }); @@ -7020,9 +6056,15 @@ Mocha.describe("Belt.List.tail", () => { }); }); -Mocha.describe("Belt.List.headExn", () => { - Mocha.test("Belt.List.headExn", () => { - Pervasives.assertEqual(Belt_List.headExn({ +Mocha.describe("Belt.List.make", () => { + Mocha.test("Belt.List.make", () => { + Belt_List.make(3, 1); + }); +}); + +Mocha.describe("Belt.List.drop", () => { + Mocha.test("Belt.List.drop", () => { + Belt_List.drop({ hd: 1, tl: { hd: 2, @@ -7031,34 +6073,8 @@ Mocha.describe("Belt.List.headExn", () => { 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", - 5190, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.List.head", () => { - Mocha.test("Belt.List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ + }, 2); + Belt_List.drop({ hd: 1, tl: { hd: 2, @@ -7067,13 +6083,23 @@ Mocha.describe("Belt.List.head", () => { tl: /* [] */0 } } - }); + }, 3); + Belt_List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); }); }); -Mocha.describe("Belt.List.length", () => { - Mocha.test("Belt.List.length", () => { - Belt_List.length({ +Mocha.describe("Belt.List.take", () => { + Mocha.test("Belt.List.take", () => { + Belt_List.take({ hd: 1, tl: { hd: 2, @@ -7082,1413 +6108,1229 @@ Mocha.describe("Belt.List.length", () => { 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.describe("Belt.SortArray.binarySearchBy", () => { - Mocha.test("Belt.SortArray.binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ - 1, +Mocha.describe("Belt.List.some", () => { + Mocha.test("Belt.List.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.describe("Belt.List.keep", () => { + Mocha.test("Belt.List.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.describe("Belt.List.sort", () => { + Mocha.test("Belt.List.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.describe("Belt.Set.union", () => { + Mocha.test("Belt.Set.union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ - 1, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, + 2, 3, + 1, 5, - 7 - ], 4, Primitive_int.compare)) === 2; - }); -}); - -Mocha.describe("Belt.SortArray.strictlySortedLength", () => { - Mocha.test("Belt.SortArray.strictlySortedLength", () => { - Belt_SortArray.strictlySortedLength([ + 4 + ], IntCmp); + let union = Belt_Set.union(s0, s1); + Pervasives.assertEqual(Belt_Set.toArray(union), [ 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.truncateToLengthUnsafe", () => { - Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" + 5, + 6 ]); }); }); -Mocha.describe("Belt.Array.eq", () => { - Mocha.test("Belt.Array.eq", () => { - Belt_Array.eq([ - 1, +Mocha.describe("Belt.Set.every", () => { + Mocha.test("Belt.Set.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, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + 4, + 6, + 8 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); }); }); -Mocha.describe("Belt.Array.cmp", () => { - Mocha.test("Belt.Array.cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ +Mocha.describe("Belt.Set.split", () => { + Mocha.test("Belt.Set.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ 1, 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, 3, + 4, 5 - ], [ + ], IntCmp); + let match = Belt_Set.split(s0, 3); + let match$1 = match[0]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ 1, - 3, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, 5 - ], Primitive_int.compare) === 0; + ]); }); }); -Mocha.describe("Belt.Array.some2", () => { - Mocha.test("Belt.Array.some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ +Mocha.describe("Belt.Option.eq", () => { + Mocha.test("Belt.Option.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.describe("Belt.Result.eq", () => { + Mocha.test("Belt.Result.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.describe("Belt_Array.get", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.zip", () => { + Mocha.test("Belt_Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ - 2, - 3 + 2 ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + }); +}); + +Mocha.describe("Belt_Array.map", () => { + Mocha.test("Belt_Array.map", () => { + Primitive_object.equal(Belt_Array.map([ 1, + 2 + ], x => x + 1 | 0), [ + 3, 4 - ], (x, y) => x > y) === true; + ]); }); }); -Mocha.describe("Belt.Array.every2", () => { - Mocha.test("Belt.Array.every2", () => { - Belt_Array.every2([ +Mocha.describe("Belt_Array.cmp", () => { + Mocha.test("Belt_Array.cmp", () => { + Belt_Array.cmp([ 1, - 2, - 3 + 3, + 5 ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, 2, 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); -}); - -Mocha.describe("Belt.Array.every", () => { - Mocha.test("Belt.Array.every", () => { - Belt_Array.every([ + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ 1, 3, 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ + ], [ 1, - -3, + 3, 5 - ], x => x > 0) === false; + ], Primitive_int.compare) === 0; }); }); -Mocha.describe("Belt.Array.some", () => { - Mocha.test("Belt.Array.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Array.pushMany", () => { + Mocha.test("Array.pushMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); }); }); -Mocha.describe("Belt.Array.joinWith", () => { - Mocha.test("Belt.Array.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.describe("Array.includes", () => { + Mocha.test("Array.includes", () => { + Pervasives.assertEqual([ + 1, + 2 + ].includes(1), true); + Pervasives.assertEqual([ + 1, + 2 + ].includes(3), false); + Pervasives.assertEqual([{ + language: "ReScript" + }].includes({ + language: "ReScript" + }), false); }); }); -Mocha.describe("Belt.Array.reduceWithIndex", () => { - Mocha.test("Belt.Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ +Mocha.describe("Array.joinWith", () => { + Mocha.test("Array.joinWith", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); +}); + +Mocha.describe("Array.toString", () => { + Mocha.test("Array.toString", () => { + Pervasives.assertEqual([ 1, 2, 3, 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + ].toString(), "1,2,3,4"); }); }); -Mocha.describe("Belt.Array.reduceReverse2", () => { - Mocha.test("Belt.Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ +Mocha.describe("Array.keepSome", () => { + Mocha.test("Array.keepSome", () => { + Pervasives.assertEqual($$Array.keepSome([ + 1, + undefined, + 3 + ]), [ + 1, + 3 + ]); + Pervasives.assertEqual($$Array.keepSome([ 1, 2, 3 - ], [ + ]), [ 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + 2, + 3 + ]); + Pervasives.assertEqual($$Array.keepSome([ + undefined, + undefined, + undefined + ]), []); + Pervasives.assertEqual($$Array.keepSome([]), []); }); }); -Mocha.describe("Belt.Array.reduceReverse", () => { - Mocha.test("Belt.Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("String.endsWith", () => { + Mocha.test("String.endsWith", () => { + "BuckleScript".endsWith("Script") === true; + "BuckleShoes".endsWith("Script") === false; }); }); -Mocha.describe("Belt.Array.reduce", () => { - Mocha.test("Belt.Array.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.describe("String.includes", () => { + Mocha.test("String.includes", () => { + "programmer".includes("gram") === true; + "programmer".includes("er") === true; + "programmer".includes("pro") === true; + "programmer.dat".includes("xyz") === false; }); }); -Mocha.describe("Belt.Array.partition", () => { - Mocha.test("Belt.Array.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.describe("String.padStart", () => { + Mocha.test("String.padStart", () => { + "abc".padStart(5, " ") === " abc"; + "abc".padStart(6, "123465") === "123abc"; }); }); -Mocha.describe("Belt.Array.mapWithIndex", () => { - Mocha.test("Belt.Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Result.mapError", () => { + Mocha.test("Result.mapError", () => { + let format = n => "Error code: " + n.toString(); + Result.mapError({ + TAG: "Error", + _0: 14 + }, format); + Result.mapError({ + TAG: "Ok", + _0: "abc" + }, format); }); }); -Mocha.describe("Belt.Array.forEachWithIndex", () => { - Mocha.test("Belt.Array.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.describe("Promise.resolve", () => { + Mocha.test("Promise.resolve", () => { + Promise.resolve(5); }); }); -Mocha.describe("Belt.Array.keepMap", () => { - Mocha.test("Belt.Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("Promise.finally", () => { + Mocha.test("Promise.finally", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + let isDone = { + contents: false + }; + $$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.describe("Belt.Array.keepWithIndex", () => { - Mocha.test("Belt.Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("Object.isSealed", () => { + Mocha.test("Object.isSealed", () => { + let point = Object.seal({ + x: 1, + y: 3 + }); + Object.isSealed(point); + let fruit = { + name: "Apple" + }; + Object.isSealed(fruit); }); }); -Mocha.describe("Belt.Array.getIndexBy", () => { - Mocha.test("Belt.Array.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.describe("Object.isFrozen", () => { + Mocha.test("Object.isFrozen", () => { + let point = Object.freeze({ + x: 1, + y: 3 + }); + Object.isFrozen(point); + let fruit = { + name: "Apple" + }; + Object.isFrozen(fruit); }); }); -Mocha.describe("Belt.Array.getBy", () => { - Mocha.test("Belt.Array.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.describe("Nullable.getExn", () => { + Mocha.test("Nullable.getExn", () => { + let exit = 0; + let value; + try { + value = 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", + 5375, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "Hello"); + } + let exit$1 = 0; + let val; + try { + val = 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", + 5381, + 7 + ], + Error: new Error() + }; + } + let exit$2 = 0; + let val$1; + try { + val$1 = 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", + 5386, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Array.flatMap", () => { - Mocha.test("Belt.Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("List.toShuffled", () => { + Mocha.test("List.toShuffled", () => { + List.toShuffled({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt.Array.map", () => { - Mocha.test("Belt.Array.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 +Mocha.describe("List.concatMany", () => { + Mocha.test("List.concatMany", () => { + List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } ]); }); }); -Mocha.describe("Belt.Array.forEach", () => { - Mocha.test("Belt.Array.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 +Mocha.describe("List.mapReverse", () => { + Mocha.test("List.mapReverse", () => { + let f = x => Math.imul(x, x); + let l = { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); + let withMap = List.reverse(List.map(l, f)); + let withMapReverse = List.mapReverse(l, f); + console.log(Primitive_object.equal(withMap, withMapReverse)); }); }); -Mocha.describe("Belt.Array.blit", () => { - Mocha.test("Belt.Array.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.describe("Null.asNullable", () => { + Mocha.test("Null.asNullable", () => {}); }); -Mocha.describe("Belt.Array.fill", () => { - Mocha.test("Belt.Array.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.describe("Null.fromOption", () => { + Mocha.test("Null.fromOption", () => { + let asNull = Null.fromOption(undefined); + console.log(asNull === null); }); }); -Mocha.describe("Belt.Array.sliceToEnd", () => { - Mocha.test("Belt.Array.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.describe("Math.Int.random", () => { + Mocha.test("Math.Int.random", () => { + $$Math.Int.random(2, 5) === 4; + $$Math.Int.random(505, 2000) === 1276; + $$Math.Int.random(-7, -2) === -4; }); }); -Mocha.describe("Belt.Array.slice", () => { - Mocha.test("Belt.Array.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.describe("JSON.Encode.int", () => { + Mocha.test("JSON.Encode.int", () => {}); +}); + +Mocha.describe("Int.toPrecision", () => { + Mocha.test("Int.toPrecision", () => { + (100).toPrecision(); + (1).toPrecision(); + (100).toPrecision(2); + (1).toPrecision(2); }); }); -Mocha.describe("Belt.Array.concatMany", () => { - Mocha.test("Belt.Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("Int.Bitwise.lor", () => { + Mocha.test("Int.Bitwise.lor", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsl", () => { + Mocha.test("Int.Bitwise.lsl", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsr", () => { + Mocha.test("Int.Bitwise.lsr", () => {}); +}); + +Mocha.describe("Int.Bitwise.asr", () => { + Mocha.test("Int.Bitwise.asr", () => {}); +}); + +Mocha.describe("Date.fromString", () => { + Mocha.test("Date.fromString", () => { + new Date("2023"); + new Date("2023-02-20"); + new Date("2023-02-20T16:40:00.00Z"); + new Date(""); + new Date("").getTime(); }); }); -Mocha.describe("Belt.Array.concat", () => { - Mocha.test("Belt.Array.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.describe("Date.makeWithYM", () => { + Mocha.test("Date.makeWithYM", () => { + new Date(2023, 0); + new Date(2023, 11); + new Date(2023, 12); + new Date(2023, -1); }); }); -Mocha.describe("Belt.Array.unzip", () => { - Mocha.test("Belt.Array.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.describe("Date.getMinutes", () => { + Mocha.test("Date.getMinutes", () => { + new Date("2023-02-20T16:40:00.00").getMinutes(); }); }); -Mocha.describe("Belt.Array.zipBy", () => { - Mocha.test("Belt.Array.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Date.getSeconds", () => { + Mocha.test("Date.getSeconds", () => { + new Date("2023-02-20T16:40:00.00").getSeconds(); }); }); -Mocha.describe("Belt.Array.zip", () => { - Mocha.test("Belt.Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); +Mocha.describe("Date.setHoursMS", () => { + Mocha.test("Date.setHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); }); }); -Mocha.describe("Belt.Array.makeBy", () => { - Mocha.test("Belt.Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("Date.setMinutes", () => { + Mocha.test("Date.setMinutes", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0); }); }); -Mocha.describe("Belt.Array.rangeBy", () => { - Mocha.test("Belt.Array.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.describe("Date.setSeconds", () => { + Mocha.test("Date.setSeconds", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0); }); }); -Mocha.describe("Belt.Array.range", () => { - Mocha.test("Belt.Array.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.describe("Date.getUTCDate", () => { + Mocha.test("Date.getUTCDate", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); }); }); -Mocha.describe("Belt.Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt.Array.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.describe("Date.setUTCDate", () => { + Mocha.test("Date.setUTCDate", () => { + new Date("2023-02-20T16:40:00.00").setUTCDate(1); }); }); -Mocha.describe("Belt.Array.makeUninitialized", () => { - Mocha.test("Belt.Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Console.assert_", () => { + Mocha.test("Console.assert_", () => { + console.assert(false, "Hello World!"); + console.assert(true, "The answer"); }); }); -Mocha.describe("Belt.Array.reverse", () => { - Mocha.test("Belt.Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Console.assert2", () => { + Mocha.test("Console.assert2", () => { + console.assert(false, "Hello", "World"); + console.assert(true, [ + 1, + 2, + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt.Array.reverseInPlace", () => { - Mocha.test("Belt.Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt.Array.get", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.length", () => { - Mocha.test("Belt.Array.length", () => {}); -}); - -Mocha.describe("Belt.Option", () => { - Mocha.test("Belt.Option", () => {}); -}); - -Mocha.describe("Belt.HashMap", () => { - Mocha.test("Belt.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.describe("Belt.HashSet", () => { - Mocha.test("Belt.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.describe("Console.assert3", () => { + Mocha.test("Console.assert3", () => { + console.assert(false, "Hello", "World", "ReScript"); + console.assert(true, "One", 2, 3); }); }); -Mocha.describe("Belt.MutableSet", () => { - Mocha.test("Belt.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, [ +Mocha.describe("Console.assert4", () => { + Mocha.test("Console.assert4", () => { + console.assert(false, "Hello", "World", "ReScript", "!!!"); + console.assert(true, [ 1, 2 - ]); + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); }); }); -Mocha.describe("Belt.Set", () => { - Mocha.test("Belt.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, [ +Mocha.describe("Console.assert5", () => { + Mocha.test("Console.assert5", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.assert(true, [ 1, 2 - ]); - let cmp$1 = Primitive_object.compare; - Belt_Id.MakeComparable({ - cmp: cmp$1 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" }); }); }); -Mocha.describe("Belt_Int./", () => { - Mocha.test("Belt_Int./", () => { - Pervasives.assertEqual(2, 2); - }); -}); - -Mocha.describe("Belt_Int.*", () => { - Mocha.test("Belt_Int.*", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Console.assert6", () => { + Mocha.test("Console.assert6", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt_Int.-", () => { - Mocha.test("Belt_Int.-", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Console.logMany", () => { + Mocha.test("Console.logMany", () => { + console.log("Hello", "World"); + console.log(1, 2, 3); }); }); -Mocha.describe("Belt_Int.+", () => { - Mocha.test("Belt_Int.+", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Console.timeEnd", () => { + Mocha.test("Console.timeEnd", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); }); }); -Mocha.describe("Belt_Int.toString", () => { - Mocha.test("Belt_Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); +Mocha.describe("Console.timeLog", () => { + Mocha.test("Console.timeLog", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); }); }); -Mocha.describe("Belt_Int.fromString", () => { - Mocha.test("Belt_Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); +Mocha.describe("BigInt.toString", () => { + Mocha.test("BigInt.toString", () => { + console.log((123n).toString()); }); }); -Mocha.describe("Belt_Int.fromFloat", () => { - Mocha.test("Belt_Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Belt_Set.remove", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt_Int.toFloat", () => { - Mocha.test("Belt_Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); +Mocha.describe("Belt_Set.subset", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); }); }); -Mocha.describe("Belt_List.sort", () => { - Mocha.test("Belt_List.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.describe("Belt_List.setAssoc", () => { - Mocha.test("Belt_List.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" - ], +Mocha.describe("Belt_Set.reduce", () => { + Mocha.test("Belt_Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, tl: { - hd: [ - 3, - "morning?!" - ], + hd: 5, tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } } } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); }); }); -Mocha.describe("Belt_List.removeAssoc", () => { - Mocha.test("Belt_List.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" - ], +Mocha.describe("Belt_Set.toList", () => { + Mocha.test("Belt_Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { + hd: 1, tl: { - hd: [ - 15, - "afternoon" - ], + hd: 2, tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } } } - }, 9, (k, item) => k === item); + }); }); }); -Mocha.describe("Belt_List.hasAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_SetDict.eq", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_List.getAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_Result.map", () => { + Mocha.test("Belt_Result.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.describe("Belt_List.unzip", () => { - Mocha.test("Belt_List.unzip", () => { - Belt_List.unzip({ - hd: [ +Mocha.describe("Belt_Result.cmp", () => { + Mocha.test("Belt_Result.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.describe("Belt_Range.some", () => { + Mocha.test("Belt_Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); + }); +}); + +Mocha.describe("Belt_Option.map", () => { + Mocha.test("Belt_Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); + }); +}); + +Mocha.describe("Belt_Option.cmp", () => { + Mocha.test("Belt_Option.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.describe("Belt_Map.reduce", () => { + Mocha.test("Belt_Map.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ 1, - 2 + "1" ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - Belt_List.unzip({ + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp); + Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ hd: [ - "H", - "W" + k, + v ], - tl: { - hd: [ - "e", - "o" - ], - tl: { - hd: [ - "l", - "r" - ], - tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } - } - } - } + tl: acc + })); + }); +}); + +Mocha.describe("Belt_Map.remove", () => { + Mocha.test("Belt_Map.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.describe("Belt_List.partition", () => { - Mocha.test("Belt_List.partition", () => { - Pervasives.assertEqual(Belt_List.partition({ +Mocha.describe("Belt_List.zipBy", () => { + Mocha.test("Belt_List.zipBy", () => { + Belt_List.zipBy({ 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 } } - ]); + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, (a, b) => (a << 1) + b | 0); }); }); -Mocha.describe("Belt_List.keepMap", () => { - Mocha.test("Belt_List.keepMap", () => { - let isEven = x => x % 2 === 0; - Belt_List.keepMap({ +Mocha.describe("Belt_List.every", () => { + Mocha.test("Belt_List.every", () => { + let isBelow10 = value => value < 10; + Belt_List.every({ hd: 1, tl: { - hd: 2, + hd: 9, tl: { - hd: 3, + hd: 8, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, x => { - if (isEven(x)) { - return x; - } - - }); - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); -}); - -Mocha.describe("Belt_List.filterWithIndex", () => { - Mocha.test("Belt_List.filterWithIndex", () => { - Belt_List.filterWithIndex({ + }, isBelow10); + Belt_List.every({ hd: 1, tl: { - hd: 2, + hd: 99, tl: { - hd: 3, + hd: 8, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, (_x, index) => index % 2 === 0); + }, isBelow10); }); }); -Mocha.describe("Belt_List.keepWithIndex", () => { - Mocha.test("Belt_List.keepWithIndex", () => { - Belt_List.keepWithIndex({ +Mocha.describe("Belt_List.some2", () => { + Mocha.test("Belt_List.some2", () => { + Belt_List.some2({ hd: 1, tl: { hd: 2, tl: { hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } + tl: /* [] */0 } } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("Belt_List.filter", () => { - Mocha.test("Belt_List.filter", () => { - let isEven = x => x % 2 === 0; - Belt_List.filter({ - hd: 1, + }, { + hd: 0, tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } + hd: 1, + tl: /* [] */0 } - }, isEven); - Belt_List.filter({ - hd: undefined, + }, (a, b) => a > b); + Belt_List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 2, tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } + hd: 3, + tl: /* [] */0 } - }, Belt_Option.isSome); - }); -}); - -Mocha.describe("Belt_List.keep", () => { - Mocha.test("Belt_List.keep", () => { - let isEven = x => x % 2 === 0; - Belt_List.keep({ + }, { hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 0, tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } + hd: 1, + tl: /* [] */0 } - }, isEven); - Belt_List.keep({ - hd: undefined, + }, { + hd: 5, tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } + hd: 0, + tl: /* [] */0 } - }, Belt_Option.isSome); + }, (a, b) => a > b); }); }); @@ -8523,145 +7365,169 @@ Mocha.describe("Belt_List.getBy", () => { }); }); -Mocha.describe("Belt_List.has", () => { - Mocha.test("Belt_List.has", () => { - Belt_List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - Belt_List.has({ - hd: 1, +Mocha.describe("Belt_List.unzip", () => { + Mocha.test("Belt_List.unzip", () => { + Belt_List.unzip({ + hd: [ + 1, + 2 + ], tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + hd: [ + 3, + 4 + ], + tl: /* [] */0 } - }, 4, (a, b) => a === b); - Belt_List.has({ - hd: -1, + }); + Belt_List.unzip({ + hd: [ + "H", + "W" + ], tl: { - hd: -2, + hd: [ + "e", + "o" + ], tl: { - hd: -3, - tl: /* [] */0 + hd: [ + "l", + "r" + ], + tl: { + hd: [ + "l", + "l" + ], + tl: { + hd: [ + "o", + "d" + ], + tl: { + hd: [ + " ", + "!" + ], + tl: /* [] */0 + } + } + } } } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); }); }); -Mocha.describe("Belt_List.eq", () => { - Mocha.test("Belt_List.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 - } +Mocha.describe("Belt.MutableSet", () => { + Mocha.test("Belt.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]); } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }; + let PairComparator = Belt_Id.MakeComparable({ + cmp: cmp + }); + let mySet = Belt_MutableSet.make(PairComparator); + Belt_MutableSet.add(mySet, [ + 1, + 2 + ]); }); }); -Mocha.describe("Belt_List.cmp", () => { - Mocha.test("Belt_List.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 - } - } - }, { +Mocha.describe("Belt.Array.fill", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.blit", () => { + Mocha.test("Belt.Array.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.describe("Belt.Array.some", () => { + Mocha.test("Belt.Array.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt.List.zipBy", () => { + Mocha.test("Belt.List.zipBy", () => { + Belt_List.zipBy({ hd: 1, tl: { hd: 2, @@ -8670,93 +7536,50 @@ Mocha.describe("Belt_List.cmp", () => { tl: /* [] */0 } } - }, Primitive_int.compare); - Belt_List.cmp({ - hd: 1, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } }, { - hd: 1, + hd: 4, tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } + hd: 5, + tl: /* [] */0 } - }, Primitive_int.compare); + }, (a, b) => (a << 1) + b | 0); }); }); -Mocha.describe("Belt_List.cmpByLength", () => { - Mocha.test("Belt_List.cmpByLength", () => { - Belt_List.cmpByLength({ +Mocha.describe("Belt.List.every", () => { + Mocha.test("Belt.List.every", () => { + let isBelow10 = value => value < 10; + Belt_List.every({ hd: 1, tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, + hd: 9, tl: { - hd: 5, + hd: 8, tl: { - hd: 6, + hd: 2, 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({ + }, isBelow10); + Belt_List.every({ hd: 1, tl: { - hd: 2, + hd: 99, tl: { - hd: 3, + hd: 8, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); + }, isBelow10); }); }); -Mocha.describe("Belt_List.some2", () => { - Mocha.test("Belt_List.some2", () => { +Mocha.describe("Belt.List.some2", () => { + Mocha.test("Belt.List.some2", () => { Belt_List.some2({ hd: 1, tl: { @@ -8803,593 +7626,661 @@ Mocha.describe("Belt_List.some2", () => { }); }); -Mocha.describe("Belt_List.every2", () => { - Mocha.test("Belt_List.every2", () => { - Belt_List.every2({ +Mocha.describe("Belt.List.getBy", () => { + Mocha.test("Belt.List.getBy", () => { + Belt_List.getBy({ hd: 1, tl: { - hd: 2, + hd: 4, 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.describe("Belt_List.some", () => { - Mocha.test("Belt_List.some", () => { - let isAbove100 = value => value > 100; - Belt_List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, tl: { - hd: 3, + hd: 2, tl: /* [] */0 } } } - }, isAbove100); - Belt_List.some({ + }, x => x > 3); + Belt_List.getBy({ hd: 1, tl: { - hd: 2, + hd: 4, tl: { hd: 3, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, isAbove100); + }, x => x > 4); }); }); -Mocha.describe("Belt_List.every", () => { - Mocha.test("Belt_List.every", () => { - let isBelow10 = value => value < 10; - Belt_List.every({ - hd: 1, +Mocha.describe("Belt.List.unzip", () => { + Mocha.test("Belt.List.unzip", () => { + Belt_List.unzip({ + hd: [ + 1, + 2 + ], tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } + hd: [ + 3, + 4 + ], + tl: /* [] */0 } - }, isBelow10); - Belt_List.every({ - hd: 1, + }); + Belt_List.unzip({ + hd: [ + "H", + "W" + ], tl: { - hd: 99, + hd: [ + "e", + "o" + ], tl: { - hd: 8, + hd: [ + "l", + "r" + ], tl: { - hd: 2, - tl: /* [] */0 + hd: [ + "l", + "l" + ], + tl: { + hd: [ + "o", + "d" + ], + tl: { + hd: [ + " ", + "!" + ], + tl: /* [] */0 + } + } } } } - }, isBelow10); - }); -}); - -Mocha.describe("Belt_List.reduceReverse2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); + }); }); }); -Mocha.describe("Belt_List.reduce2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Belt.Range.some", () => { + Mocha.test("Belt.Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); }); }); -Mocha.describe("Belt_List.forEach2", () => { - Mocha.test("Belt_List.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.describe("Belt.Set.remove", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt_List.mapReverse2", () => { - Mocha.test("Belt_List.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.describe("Belt.Set.subset", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); }); }); -Mocha.describe("Belt_List.reduceReverse", () => { - Mocha.test("Belt_List.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, +Mocha.describe("Belt.Set.reduce", () => { + Mocha.test("Belt.Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, tl: { - hd: 2, + hd: 5, tl: { hd: 3, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, 10, (a, b) => a - b | 0); - Belt_List.reduceReverse({ + }); + }); +}); + +Mocha.describe("Belt.Set.toList", () => { + Mocha.test("Belt.Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { hd: 1, tl: { hd: 2, tl: { hd: 3, tl: { - hd: 4, + hd: 5, tl: /* [] */0 } } } - }, /* [] */0, Belt_List.add); + }); }); }); -Mocha.describe("Belt_List.reduceWithIndex", () => { - Mocha.test("Belt_List.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.describe("Belt_List.reduce", () => { - Mocha.test("Belt_List.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.describe("Belt.Map.reduce", () => { + Mocha.test("Belt.Map.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.describe("Belt_List.forEachWithIndex", () => { - Mocha.test("Belt_List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); +Mocha.describe("Belt.Map.remove", () => { + Mocha.test("Belt.Map.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.describe("Belt_List.forEach", () => { - Mocha.test("Belt_List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); +Mocha.describe("Belt.Option.map", () => { + Mocha.test("Belt.Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt_List.mapReverse", () => { - Mocha.test("Belt_List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt.Option.cmp", () => { + Mocha.test("Belt.Option.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.describe("Belt_List.reverse", () => { - Mocha.test("Belt_List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.Result.map", () => { + Mocha.test("Belt.Result.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.describe("Belt_List.toArray", () => { - Mocha.test("Belt_List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt.Result.cmp", () => { + Mocha.test("Belt.Result.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.describe("Belt_List.fromArray", () => { - Mocha.test("Belt_List.fromArray", () => { - Belt_List.fromArray([ +Mocha.describe("Belt_Array.fill", () => { + Mocha.test("Belt_Array.fill", () => { + let arr = Belt_Array.makeBy(5, i => i); + Belt_Array.fill(arr, 2, 2, 9); + Primitive_object.equal(arr, [ + 0, 1, - 2, - 3 + 9, + 9, + 4 + ]); + Belt_Array.fill(arr, 7, 2, 8); + Primitive_object.equal(arr, [ + 0, + 1, + 9, + 9, + 4 ]); }); }); -Mocha.describe("Belt_List.mapWithIndex", () => { - Mocha.test("Belt_List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); - }); -}); - -Mocha.describe("Belt_List.zipBy", () => { - Mocha.test("Belt_List.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_Array.blit", () => { + Mocha.test("Belt_Array.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.describe("Belt_List.zip", () => { - Mocha.test("Belt_List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt_Array.some", () => { + Mocha.test("Belt_Array.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_List.map", () => { - Mocha.test("Belt_List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); +Mocha.describe("Array.fillToEnd", () => { + Mocha.test("Array.fillToEnd", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 9 + ]); }); }); -Mocha.describe("Belt_List.flatten", () => { - Mocha.test("Belt_List.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.describe("Array.findIndex", () => { + Mocha.test("Array.findIndex", () => { + let array = [ + "ReScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); + Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); }); }); -Mocha.describe("Belt_List.reverseConcat", () => { - Mocha.test("Belt_List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); +Mocha.describe("Array.getUnsafe", () => { + Mocha.test("Array.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.describe("Belt_List.concatMany", () => { - Mocha.test("Belt_List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); +Mocha.describe("Array.setUnsafe", () => { + Mocha.test("Array.setUnsafe", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); }); }); -Mocha.describe("Belt_List.concat", () => { - Mocha.test("Belt_List.concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Array.filterMap", () => { + Mocha.test("Array.filterMap", () => { + Pervasives.assertEqual($$Array.filterMap([ + "Hello", + "Hi", + "Good bye" + ], item => { + if (item === "Hello") { + return item.length; } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 + + }), [5]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return Math.imul(n, n); } - }); - }); + + }), [ + 4, + 16, + 36 + ]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), []); + Pervasives.assertEqual($$Array.filterMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + }), []); + }); }); -Mocha.describe("Belt_List.splitAt", () => { - Mocha.test("Belt_List.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.describe("String.getUnsafe", () => { + Mocha.test("String.getUnsafe", () => {}); +}); + +Mocha.describe("String.normalize", () => { + Mocha.test("String.normalize", () => { + let string1 = "\u00F1"; + let string2 = "\u006E\u0303"; + if (string1 === string2) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 6471, + 0 + ], + Error: new Error() + }; + } + Pervasives.assertEqual(string1.normalize(), string2.normalize()); }); }); -Mocha.describe("Belt_List.take", () => { - Mocha.test("Belt_List.take", () => { - Belt_List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("String.searchOpt", () => { + Mocha.test("String.searchOpt", () => { + Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); + $$String.searchOpt("no numbers", /\d+/) === undefined; + }); +}); + +Mocha.describe("String.substring", () => { + Mocha.test("String.substring", () => { + "playground".substring(3, 6) === "ygr"; + "playground".substring(6, 3) === "ygr"; + "playground".substring(4, 12) === "ground"; + }); +}); + +Mocha.describe("String.trimStart", () => { + Mocha.test("String.trimStart", () => { + " Hello world! ".trimStart() === "Hello world! "; + " Hello world! ".trimStart() === "Hello world! "; + }); +}); + +Mocha.describe("Set.fromIterator", () => { + Mocha.test("Set.fromIterator", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(new Set(iterator).size, 3); + }); +}); + +Mocha.describe("RegExp.lastIndex", () => { + Mocha.test("RegExp.lastIndex", () => { + let regexp = new RegExp("\\w+"); + console.log(regexp.lastIndex); + regexp.exec("Many words here."); + console.log(regexp.lastIndex); + }); +}); + +Mocha.describe("RegExp.multiline", () => { + Mocha.test("RegExp.multiline", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.multiline); + let regexp2 = new RegExp("\\w+", "mi"); + console.log(regexp2.multiline); + }); +}); + +Mocha.describe("Option.getUnsafe", () => { + Mocha.test("Option.getUnsafe", () => {}); +}); + +Mocha.describe("Object.getSymbol", () => { + Mocha.test("Object.getSymbol", () => { + let fruit = Symbol("fruit"); + let x = {}; + x[fruit] = "banana"; + }); +}); + +Mocha.describe("Nullable.forEach", () => { + Mocha.test("Nullable.forEach", () => { + Nullable.forEach("thing", x => { + console.log(x); + }); + Nullable.forEach(null, x => { + console.log(x); + }); + Nullable.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Nullable.flatMap", () => { + Mocha.test("Nullable.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; } - }, 1); - Belt_List.take({ + }; + Nullable.flatMap(2, addIfAboveOne); + Nullable.flatMap(-4, addIfAboveOne); + Nullable.flatMap(null, addIfAboveOne); + }); +}); + +Mocha.describe("List.mapReverse2", () => { + Mocha.test("List.mapReverse2", () => { + List.mapReverse2({ hd: 1, tl: { hd: 2, @@ -9398,642 +8289,471 @@ Mocha.describe("Belt_List.take", () => { tl: /* [] */0 } } - }, 2); - Belt_List.take({ + }, { hd: 1, tl: { hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + tl: /* [] */0 } - }, 4); + }, (a, b) => a + b | 0); }); }); -Mocha.describe("Belt_List.drop", () => { - Mocha.test("Belt_List.drop", () => { - Belt_List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - Belt_List.drop({ - hd: 1, +Mocha.describe("List.removeAssoc", () => { + Mocha.test("List.removeAssoc", () => { + List.removeAssoc({ + hd: [ + 1, + "a" + ], tl: { - hd: 2, + hd: [ + 2, + "b" + ], tl: { - hd: 3, + hd: [ + 3, + "c" + ], tl: /* [] */0 } } - }, 3); - Belt_List.drop({ - hd: 1, + }, 1, (a, b) => a === b); + List.removeAssoc({ + hd: [ + 9, + "morning" + ], tl: { - hd: 2, + hd: [ + 15, + "afternoon" + ], tl: { - hd: 3, + hd: [ + 22, + "night" + ], tl: /* [] */0 } } - }, 4); + }, 9, (k, item) => k === item); }); }); -Mocha.describe("Belt_List.shuffle", () => { - Mocha.test("Belt_List.shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Math.Constants.e", () => { + Mocha.test("Math.Constants.e", () => {}); +}); + +Mocha.describe("Math.Int.minMany", () => { + Mocha.test("Math.Int.minMany", () => { + Math.min(1, 2); + Math.min(-1, -2); + isFinite(Math.min()); }); }); -Mocha.describe("Belt_List.makeBy", () => { - Mocha.test("Belt_List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); +Mocha.describe("Math.Int.maxMany", () => { + Mocha.test("Math.Int.maxMany", () => { + Math.max(1, 2); + Math.max(-1, -2); + isFinite(Math.max()); }); }); -Mocha.describe("Belt_List.make", () => { - Mocha.test("Belt_List.make", () => { - Belt_List.make(3, 1); +Mocha.describe("Map.fromIterator", () => { + Mocha.test("Map.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(new Map(iterator).size, 2); }); }); -Mocha.describe("Belt_List.getExn", () => { - Mocha.test("Belt_List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.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", - 6471, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("JSON.Encode.bool", () => { + Mocha.test("JSON.Encode.bool", () => {}); +}); + +Mocha.describe("JSON.Encode.null", () => { + Mocha.test("JSON.Encode.null", () => {}); +}); + +Mocha.describe("JSON.Decode.bool", () => { + Mocha.test("JSON.Decode.bool", () => { + $$JSON.Decode.bool(JSON.parse("true")); + $$JSON.Decode.bool(JSON.parse("\"hello world\"")); }); }); -Mocha.describe("Belt_List.get", () => { - Mocha.test("Belt_List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); +Mocha.describe("JSON.Decode.null", () => { + Mocha.test("JSON.Decode.null", () => { + $$JSON.Decode.$$null(JSON.parse("null")); + $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); }); }); -Mocha.describe("Belt_List.add", () => { - Mocha.test("Belt_List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); +Mocha.describe("Iterator.toArray", () => { + Mocha.test("Iterator.toArray", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + let mapKeysAsArray = Array.from(map.keys()); + console.log(mapKeysAsArray); }); }); -Mocha.describe("Belt_List.tailExn", () => { - Mocha.test("Belt_List.tailExn", () => { - Pervasives.assertEqual(Belt_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Iterator.forEach", () => { + Mocha.test("Iterator.forEach", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + $$Iterator.forEach(iterator, v => { + if (v === undefined) { + return Pervasives.assertEqual(Option.isNone(v), true); } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 + switch (v) { + case "a" : + case "b" : + case "c" : + return; + default: + return Pervasives.assertEqual(Option.isNone(v), true); } }); - 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", - 6509, - 7 - ], - Error: new Error() - }; - } - }); }); -Mocha.describe("Belt_List.tail", () => { - Mocha.test("Belt_List.tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); - }); +Mocha.describe("Int.Bitwise.land", () => { + Mocha.test("Int.Bitwise.land", () => {}); }); -Mocha.describe("Belt_List.headExn", () => { - Mocha.test("Belt_List.headExn", () => { - Pervasives.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", - 6534, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Int.Bitwise.lxor", () => { + Mocha.test("Int.Bitwise.lxor", () => {}); +}); + +Mocha.describe("Int.Bitwise.lnot", () => { + Mocha.test("Int.Bitwise.lnot", () => { + Int.Bitwise.lnot(2) === -3; }); }); -Mocha.describe("Belt_List.head", () => { - Mocha.test("Belt_List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Float.parseFloat", () => { + Mocha.test("Float.parseFloat", () => { + parseFloat("1.0"); + parseFloat(" 3.14 "); + parseFloat("3.0"); + parseFloat("3.14some non-digit characters"); + isNaN(parseFloat("error")); }); }); -Mocha.describe("Belt_List.length", () => { - Mocha.test("Belt_List.length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Float.fromString", () => { + Mocha.test("Float.fromString", () => { + Primitive_object.equal(Float.fromString("0"), 0.0); + Float.fromString("NaN") === undefined; + Primitive_object.equal(Float.fromString("6"), 6.0); }); }); -Mocha.describe("Belt_Map.Dict.findFirstBy", () => { - Mocha.test("Belt_Map.Dict.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("Date.makeWithYMD", () => { + Mocha.test("Date.makeWithYMD", () => { + new Date(2023, 1, 20); + new Date(2023, 1, -1); + new Date(2023, 1, 29); }); }); -Mocha.describe("Belt_Map.String.findFirstBy", () => { - Mocha.test("Belt_Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); +Mocha.describe("Date.getFullYear", () => { + Mocha.test("Date.getFullYear", () => { + new Date("2023-02-20").getFullYear(); }); }); -Mocha.describe("Belt_Map.Int.findFirstBy", () => { - Mocha.test("Belt_Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Date.setFullYear", () => { + Mocha.test("Date.setFullYear", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024); }); }); -Mocha.describe("Belt_Map.set", () => { - Mocha.test("Belt_Map.set", () => { +Mocha.describe("Date.setMinutesS", () => { + Mocha.test("Date.setMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); + }); +}); + +Mocha.describe("Date.getUTCMonth", () => { + Mocha.test("Date.getUTCMonth", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); + }); +}); + +Mocha.describe("Date.getUTCHours", () => { + Mocha.test("Date.getUTCHours", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); + }); +}); + +Mocha.describe("Date.setUTCMonth", () => { + Mocha.test("Date.setUTCMonth", () => { + new Date("2023-02-20T16:40:00.00").setUTCMonth(0); + }); +}); + +Mocha.describe("Date.setUTCHours", () => { + Mocha.test("Date.setUTCHours", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0); + }); +}); + +Mocha.describe("Date.toISOString", () => { + Mocha.test("Date.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.describe("Date.toUTCString", () => { + Mocha.test("Date.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("Dict.keysToArray", () => { + Mocha.test("Dict.keysToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let keys = Object.keys(dict); + console.log(keys); + }); +}); + +Mocha.describe("Console.infoMany", () => { + Mocha.test("Console.infoMany", () => { + console.info("Hello", "World"); + console.info(1, 2, 3); + }); +}); + +Mocha.describe("Console.warnMany", () => { + Mocha.test("Console.warnMany", () => { + console.warn("Hello", "World"); + console.warn(1, 2, 3); + }); +}); + +Mocha.describe("Belt_Set.isEmpty", () => { + Mocha.test("Belt_Set.isEmpty", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); +}); + +Mocha.describe("Belt_Set.forEach", () => { + Mocha.test("Belt_Set.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 s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" - ]); + let acc = { + contents: /* [] */0 + }; + Belt_Set.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); }); }); -Mocha.describe("Belt_Map.remove", () => { - Mocha.test("Belt_Map.remove", () => { +Mocha.describe("Belt_Set.toArray", () => { + Mocha.test("Belt_Set.toArray", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 ], IntCmp); - let s1 = Belt_Map.remove(s0, 1); - Belt_Map.remove(s1, 1); - Primitive_object.equal(Belt_Map.keysToArray(s1), [ + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, 2, - 3 + 3, + 5 ]); }); }); -Mocha.describe("Belt_Map.get", () => { - Mocha.test("Belt_Map.get", () => { +Mocha.describe("Belt_Set.minimum", () => { + Mocha.test("Belt_Set.minimum", () => { 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; + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); }); }); -Mocha.describe("Belt_Map.valuesToArray", () => { - Mocha.test("Belt_Map.valuesToArray", () => { +Mocha.describe("Belt_Set.maximum", () => { + Mocha.test("Belt_Set.maximum", () => { 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" - ]); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); }); }); -Mocha.describe("Belt_Map.keysToArray", () => { - Mocha.test("Belt_Map.keysToArray", () => { +Mocha.describe("Belt_Set.Dict.eq", () => { + Mocha.test("Belt_Set.Dict.eq", () => { 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, + 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.describe("Belt_Map.fromArray", () => { - Mocha.test("Belt_Map.fromArray", () => { +Mocha.describe("Belt_SetDict.has", () => { + Mocha.test("Belt_SetDict.has", () => { 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" - ] - ]); + 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.describe("Belt_Map.toArray", () => { - Mocha.test("Belt_Map.toArray", () => { +Mocha.describe("Belt_SetDict.add", () => { + Mocha.test("Belt_SetDict.add", () => { 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" - ] - ]); + 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.describe("Belt_Map.size", () => { - Mocha.test("Belt_Map.size", () => { +Mocha.describe("Belt_SetDict.get", () => { + Mocha.test("Belt_SetDict.get", () => { 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; + 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.describe("Belt_Map.reduce", () => { - Mocha.test("Belt_Map.reduce", () => { +Mocha.describe("Belt_Range.every", () => { + Mocha.test("Belt_Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); +}); + +Mocha.describe("Belt_Option.keep", () => { + Mocha.test("Belt_Option.keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); + }); +}); + +Mocha.describe("Belt_Map.isEmpty", () => { + Mocha.test("Belt_Map.isEmpty", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ + Belt_Map.isEmpty(Belt_Map.fromArray([[ 1, "1" - ], - [ - 2, - "2" - ], - [ - 3, - "3" - ] - ], IntCmp); - Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ - hd: [ - k, - v - ], - tl: acc - })); + ]], IntCmp)) === false; }); }); @@ -10101,89 +8821,26 @@ Mocha.describe("Belt_Map.forEach", () => { }); }); -Mocha.describe("Belt_Map.findFirstBy", () => { - Mocha.test("Belt_Map.findFirstBy", () => { +Mocha.describe("Belt_Map.toArray", () => { + Mocha.test("Belt_Map.toArray", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Map.fromArray([ + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ [ - 4, - "4" + 2, + "2" ], [ 1, "1" ], - [ - 2, - "2" - ], [ 3, - "" + "3" ] - ], IntCmp); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt_Map.has", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.isEmpty", () => { - Mocha.test("Belt_Map.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; - }); -}); - -Mocha.describe("Belt_Map.make", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.Int", () => { - Mocha.test("Belt_Map.Int", () => {}); -}); - -Mocha.describe("Belt_MapDict.findFirstBy", () => { - Mocha.test("Belt_MapDict.findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MapDict.fromArray([ - [ - 4, - "4" - ], + ], IntCmp)), [ [ 1, "1" @@ -10196,1413 +8853,1530 @@ Mocha.describe("Belt_MapDict.findFirstBy", () => { 3, "3" ] - ], IntCmp.cmp); - Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" ]); }); }); -Mocha.describe("Belt_MapInt.findFirstBy", () => { - Mocha.test("Belt_MapInt.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Belt_Int.toFloat", () => { + Mocha.test("Belt_Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); }); }); -Mocha.describe("Belt_MapString.findFirstBy", () => { - Mocha.test("Belt_MapString.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; +Mocha.describe("Belt_List.length", () => { + Mocha.test("Belt_List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_MutableSet.split", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.get", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.getExn", () => { + Mocha.test("Belt_List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.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", + 7229, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_MutableSet.maxUndefined", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.makeBy", () => { + Mocha.test("Belt_List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); }); }); -Mocha.describe("Belt_MutableSet.maximum", () => { - Mocha.test("Belt_MutableSet.maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.concat", () => { + Mocha.test("Belt_List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } }); - 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.describe("Belt_MutableSet.minUndefined", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.minimum", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.toArray", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.reduce", () => { + Mocha.test("Belt_List.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.describe("Belt_MutableSet.toList", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.every2", () => { + Mocha.test("Belt_List.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.describe("Belt_MutableSet.size", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.filter", () => { + Mocha.test("Belt_List.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.describe("Belt_MutableSet.partition", () => { - Mocha.test("Belt_MutableSet.partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt.Array.range", () => { + Mocha.test("Belt.Array.range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, 1, 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_MutableSet.partition(s0, isOdd); - Belt_MutableSet.toArray(match[0]); - Belt_MutableSet.toArray(match[1]); + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); }); }); -Mocha.describe("Belt_MutableSet.keep", () => { - Mocha.test("Belt_MutableSet.keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt.Array.zipBy", () => { + Mocha.test("Belt.Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ 1, 2, - 3, + 3 + ], [ 4, 5 - ], IntCmp); - let s1 = Belt_MutableSet.keep(s0, isEven); - Belt_MutableSet.toArray(s1); - }); -}); - -Mocha.describe("Belt_MutableSet.some", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.every", () => { - Mocha.test("Belt_MutableSet.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, + ], (a, b) => (a << 1) + b | 0), [ 6, - 8 - ], IntCmp); - Belt_MutableSet.every(s0, isEven); + 9 + ]); }); }); -Mocha.describe("Belt_MutableSet.reduce", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt.Array.unzip", () => { + Mocha.test("Belt.Array.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.describe("Belt_MutableSet.forEach", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt.Array.slice", () => { + Mocha.test("Belt.Array.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.describe("Belt_MutableSet.eq", () => { - Mocha.test("Belt_MutableSet.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([ +Mocha.describe("Belt.Array.getBy", () => { + Mocha.test("Belt.Array.getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, + 4, 3, - 2, - 5 - ], IntCmp); - Belt_MutableSet.eq(s0, s1); + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; }); }); -Mocha.describe("Belt_MutableSet.subset", () => { - Mocha.test("Belt_MutableSet.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, +Mocha.describe("Belt.Array.every", () => { + Mocha.test("Belt.Array.every", () => { + Belt_Array.every([ + 1, 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ 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); + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_MutableSet.diff", () => { - Mocha.test("Belt_MutableSet.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, +Mocha.describe("Belt.Array.some2", () => { + Mocha.test("Belt.Array.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, + 3 + ], [ 1, - 5, 4 - ], IntCmp); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); + ], (x, y) => x > y) === true; }); }); -Mocha.describe("Belt_MutableSet.intersect", () => { - Mocha.test("Belt_MutableSet.intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.length", () => { + Mocha.test("Belt.List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt_MutableSet.union", () => { - Mocha.test("Belt_MutableSet.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.List.getExn", () => { + Mocha.test("Belt.List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.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", + 7395, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_MutableSet.removeMany", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt.List.makeBy", () => { + Mocha.test("Belt.List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); }); }); -Mocha.describe("Belt_MutableSet.remove", () => { - Mocha.test("Belt_MutableSet.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.concat", () => { + Mocha.test("Belt.List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } }); - 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.describe("Belt_MutableSet.mergeMany", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt.List.reduce", () => { + Mocha.test("Belt.List.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.describe("Belt_MutableSet.add", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt.List.every2", () => { + Mocha.test("Belt.List.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.describe("Belt_MutableSet.has", () => { - Mocha.test("Belt_MutableSet.has", () => { +Mocha.describe("Belt.List.filter", () => { + Mocha.test("Belt.List.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.describe("Belt.Range.every", () => { + Mocha.test("Belt.Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); + }); +}); + +Mocha.describe("Belt.Set.isEmpty", () => { + Mocha.test("Belt.Set.isEmpty", () => { 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); + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); }); }); -Mocha.describe("Belt_MutableSet.isEmpty", () => { - Mocha.test("Belt_MutableSet.isEmpty", () => { +Mocha.describe("Belt.Set.forEach", () => { + Mocha.test("Belt.Set.forEach", () => { 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); + 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); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); }); }); -Mocha.describe("Belt_MutableSet.copy", () => { - Mocha.test("Belt_MutableSet.copy", () => { +Mocha.describe("Belt.Set.toArray", () => { + Mocha.test("Belt.Set.toArray", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_MutableSet.fromArray([ - 1, + let s0 = Belt_Set.fromArray([ 3, 2, - 4 + 1, + 5 ], IntCmp); - let copied = Belt_MutableSet.copy(s0); - Belt_MutableSet.toArray(copied); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); }); }); -Mocha.describe("Belt_MutableSet.fromArray", () => { - Mocha.test("Belt_MutableSet.fromArray", () => { +Mocha.describe("Belt.Set.minimum", () => { + Mocha.test("Belt.Set.minimum", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_MutableSet.fromArray([ - 1, + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ 3, 2, - 4 + 1, + 5 ], IntCmp); - Belt_MutableSet.toArray(s0); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); }); }); -Mocha.describe("Belt_Option.cmp", () => { - Mocha.test("Belt_Option.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.describe("Belt.Set.maximum", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); }); }); -Mocha.describe("Belt_Option.eq", () => { - Mocha.test("Belt_Option.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.describe("Belt.Map.isEmpty", () => { + Mocha.test("Belt.Map.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; }); }); -Mocha.describe("Belt_Option.isNone", () => { - Mocha.test("Belt_Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); +Mocha.describe("Belt.Map.forEach", () => { + Mocha.test("Belt.Map.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.describe("Belt_Option.isSome", () => { - Mocha.test("Belt_Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); +Mocha.describe("Belt.Map.toArray", () => { + Mocha.test("Belt.Map.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.describe("Belt_Option.orElse", () => { - Mocha.test("Belt_Option.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.HashMap.set", () => { + Mocha.test("Belt.HashMap.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.describe("Belt_Option.getWithDefault", () => { - Mocha.test("Belt_Option.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.describe("Belt.HashMap.get", () => { + Mocha.test("Belt.HashMap.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.describe("Belt_Option.flatMap", () => { - Mocha.test("Belt_Option.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.describe("Belt.HashMap.has", () => { + Mocha.test("Belt.HashMap.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.describe("Belt_Option.map", () => { - Mocha.test("Belt_Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Belt.Option.keep", () => { + Mocha.test("Belt.Option.keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); }); }); -Mocha.describe("Belt_Option.mapWithDefault", () => { - Mocha.test("Belt_Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); +Mocha.describe("Belt.Int.toFloat", () => { + Mocha.test("Belt.Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); }); }); -Mocha.describe("Belt_Option.getExn", () => { - Mocha.test("Belt_Option.getExn", () => { - Pervasives.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", - 7531, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt.Float.toInt", () => { + Mocha.test("Belt.Float.toInt", () => { + console.log(true); }); }); -Mocha.describe("Belt_Option.forEach", () => { - Mocha.test("Belt_Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); +Mocha.describe("Belt.Set.Dict.eq", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_Option.keep", () => { - Mocha.test("Belt_Option.keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); +Mocha.describe("Belt_Float.toInt", () => { + Mocha.test("Belt_Float.toInt", () => { + console.log(true); }); }); -Mocha.describe("Belt_Result.cmp", () => { - Mocha.test("Belt_Result.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.describe("Belt_Array.range", () => { + Mocha.test("Belt_Array.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.describe("Belt_Result.eq", () => { - Mocha.test("Belt_Result.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.describe("Belt_Array.zipBy", () => { + Mocha.test("Belt_Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Belt_Result.getWithDefault", () => { - Mocha.test("Belt_Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; +Mocha.describe("Belt_Array.unzip", () => { + Mocha.test("Belt_Array.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.describe("Belt_Result.flatMap", () => { - Mocha.test("Belt_Result.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.describe("Belt_Result.map", () => { - Mocha.test("Belt_Result.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.describe("Belt_Array.slice", () => { + Mocha.test("Belt_Array.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.describe("Belt_Result.mapWithDefault", () => { - Mocha.test("Belt_Result.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_Array.getBy", () => { + Mocha.test("Belt_Array.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.describe("Belt_Result.getExn", () => { - Mocha.test("Belt_Result.getExn", () => { - Pervasives.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", - 7678, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_Array.every", () => { + Mocha.test("Belt_Array.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_Range.someBy", () => { - Mocha.test("Belt_Range.someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); +Mocha.describe("Belt_Array.some2", () => { + Mocha.test("Belt_Array.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.describe("Belt_Range.some", () => { - Mocha.test("Belt_Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); +Mocha.describe("Belt_HashMap.set", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_Range.everyBy", () => { - Mocha.test("Belt_Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); +Mocha.describe("Belt_HashMap.get", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_Range.every", () => { - Mocha.test("Belt_Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); +Mocha.describe("Belt_HashMap.has", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_Range.forEach", () => { - Mocha.test("Belt_Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); +Mocha.describe("Array.concatMany", () => { + Mocha.test("Array.concatMany", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = ["yay"]; + let array3 = ["wehoo"]; + let someArray = array1.concat(array2, array3); + console.log(someArray); }); }); -Mocha.describe("Belt_SetDict.split", () => { - Mocha.test("Belt_SetDict.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Array.indexOfOpt", () => { + Mocha.test("Array.indexOfOpt", () => { + Pervasives.assertEqual($$Array.indexOfOpt([ 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]); + 2 + ], 2), 1); + Pervasives.assertEqual($$Array.indexOfOpt([ + 1, + 2 + ], 3), undefined); + Pervasives.assertEqual($$Array.indexOfOpt([{ + language: "ReScript" + }], { + language: "ReScript" + }), undefined); }); }); -Mocha.describe("Belt_SetDict.get", () => { - Mocha.test("Belt_SetDict.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Array.joinUnsafe", () => { + Mocha.test("Array.joinUnsafe", () => { + Pervasives.assertEqual([ 1, 2, - 3, - 4, - 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); + 3 + ].join(" -- "), "1 -- 2 -- 3"); }); }); -Mocha.describe("Belt_SetDict.maxUndefined", () => { - Mocha.test("Belt_SetDict.maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ +Mocha.describe("Array.sliceToEnd", () => { + Mocha.test("Array.sliceToEnd", () => { + Pervasives.assertEqual([ + 1, + 2, 3, + 4 + ].slice(1), [ 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); + 3, + 4 + ]); }); }); -Mocha.describe("Belt_SetDict.maximum", () => { - Mocha.test("Belt_SetDict.maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, +Mocha.describe("Array.unsafe_get", () => { + Mocha.test("Array.unsafe_get", () => { + let array = [ 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maximum(undefined); - Belt_SetDict.maximum(s1); + 2, + 3 + ]; + for (let index = 0, index_finish = array.length; index < index_finish; ++index) { + let value = array[index]; + console.log(value); + } }); }); -Mocha.describe("Belt_SetDict.minUndefined", () => { - Mocha.test("Belt_SetDict.minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, +Mocha.describe("Array.toShuffled", () => { + Mocha.test("Array.toShuffled", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let shuffledArray = $$Array.toShuffled(array); + console.log(shuffledArray); + Pervasives.assertEqual($$Array.toShuffled([ 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); + 2, + 3 + ]).length, 3); }); }); -Mocha.describe("Belt_SetDict.minimum", () => { - Mocha.test("Belt_SetDict.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.describe("String.charCodeAt", () => { + Mocha.test("String.charCodeAt", () => { + "😺".charCodeAt(0) === 55357; + Primitive_object.equal("😺".codePointAt(0), 128570); }); }); -Mocha.describe("Belt_SetDict.toArray", () => { - Mocha.test("Belt_SetDict.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.describe("String.concatMany", () => { + Mocha.test("String.concatMany", () => { + "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; }); }); -Mocha.describe("Belt_SetDict.toList", () => { - Mocha.test("Belt_SetDict.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.describe("String.indexOfOpt", () => { + Mocha.test("String.indexOfOpt", () => { + Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); + $$String.indexOfOpt("bookseller", "xyz") === undefined; }); }); -Mocha.describe("Belt_SetDict.size", () => { - Mocha.test("Belt_SetDict.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.describe("String.replaceAll", () => { + Mocha.test("String.replaceAll", () => { + "old old string".replaceAll("old", "new") === "new new string"; + "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; }); }); -Mocha.describe("Belt_SetDict.partition", () => { - Mocha.test("Belt_SetDict.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.describe("String.sliceToEnd", () => { + Mocha.test("String.sliceToEnd", () => { + "abcdefg".slice(4) === "efg"; + "abcdefg".slice(-2) === "fg"; + "abcdefg".slice(7) === ""; }); }); -Mocha.describe("Belt_SetDict.keep", () => { - Mocha.test("Belt_SetDict.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.describe("String.startsWith", () => { + Mocha.test("String.startsWith", () => { + "BuckleScript".startsWith("Buckle") === true; + "BuckleScript".startsWith("") === true; + "JavaScript".startsWith("Buckle") === false; }); }); -Mocha.describe("Belt_SetDict.some", () => { - Mocha.test("Belt_SetDict.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.describe("RegExp.fromString", () => { + Mocha.test("RegExp.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.describe("Belt_SetDict.every", () => { - Mocha.test("Belt_SetDict.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.describe("RegExp.ignoreCase", () => { + Mocha.test("RegExp.ignoreCase", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.ignoreCase); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.ignoreCase); }); }); -Mocha.describe("Belt_SetDict.reduce", () => { - Mocha.test("Belt_SetDict.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.describe("Pervasives.import", () => { + Mocha.test("Pervasives.import", () => {}); }); -Mocha.describe("Belt_SetDict.forEach", () => { - Mocha.test("Belt_SetDict.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.describe("Nullable.toOption", () => { + Mocha.test("Nullable.toOption", () => { + let nullableString = "Hello"; + if (nullableString == null) { + console.log("Didn't have a value."); + } else { + console.log("Got string:", nullableString); + } }); }); -Mocha.describe("Belt_SetDict.eq", () => { - Mocha.test("Belt_SetDict.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.describe("List.mapWithIndex", () => { + Mocha.test("List.mapWithIndex", () => { + List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (x, index) => index + x | 0); }); }); -Mocha.describe("Belt_SetDict.subset", () => { - Mocha.test("Belt_SetDict.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.describe("Math.Constants.pi", () => { + Mocha.test("Math.Constants.pi", () => {}); +}); + +Mocha.describe("JSON.stringifyAny", () => { + Mocha.test("JSON.stringifyAny", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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", + 8135, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_SetDict.diff", () => { - Mocha.test("Belt_SetDict.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.describe("JSON.Encode.float", () => { + Mocha.test("JSON.Encode.float", () => {}); +}); + +Mocha.describe("JSON.Encode.array", () => { + Mocha.test("JSON.Encode.array", () => {}); +}); + +Mocha.describe("JSON.Decode.float", () => { + Mocha.test("JSON.Decode.float", () => { + $$JSON.Decode.float(JSON.parse("42.0")); + $$JSON.Decode.float(JSON.parse("\"hello world\"")); }); }); -Mocha.describe("Belt_SetDict.intersect", () => { - Mocha.test("Belt_SetDict.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.describe("JSON.Decode.array", () => { + Mocha.test("JSON.Decode.array", () => { + $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); + $$JSON.Decode.array(JSON.parse("\"hello world\"")); }); }); -Mocha.describe("Belt_SetDict.union", () => { - Mocha.test("Belt_SetDict.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("Int.toExponential", () => { + Mocha.test("Int.toExponential", () => { + (1000).toExponential(); + (-1000).toExponential(); + (77).toExponential(2); + (5678).toExponential(2); }); }); -Mocha.describe("Belt_SetDict.removeMany", () => { - Mocha.test("Belt_SetDict.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.describe("Float.toPrecision", () => { + Mocha.test("Float.toPrecision", () => { + (100.0).toPrecision(); + (1.0).toPrecision(); + (100.0).toPrecision(2); + (1.0).toPrecision(1); }); }); -Mocha.describe("Belt_SetDict.remove", () => { - Mocha.test("Belt_SetDict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 2, - 3, +Mocha.describe("Error.toException", () => { + Mocha.test("Error.toException", () => { + new Error("Something went wrong."); + }); +}); + +Mocha.describe("Date.makeWithYMDH", () => { + Mocha.test("Date.makeWithYMDH", () => { + new Date(2023, 1, 20, 16); + new Date(2023, 1, 20, 24); + new Date(2023, 1, 20, -1); + }); +}); + +Mocha.describe("Date.setFullYearM", () => { + Mocha.test("Date.setFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); + }); +}); + +Mocha.describe("Date.setHoursMSMs", () => { + Mocha.test("Date.setHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); + }); +}); + +Mocha.describe("Date.setSecondsMs", () => { + Mocha.test("Date.setSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); + }); +}); + +Mocha.describe("Date.setUTCHoursM", () => { + Mocha.test("Date.setUTCHoursM", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); + }); +}); + +Mocha.describe("Date.toDateString", () => { + Mocha.test("Date.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.describe("Date.toTimeString", () => { + Mocha.test("Date.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.describe("Dict.fromIterator", () => { + Mocha.test("Dict.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ 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); + 2 + ]); }); }); -Mocha.describe("Belt_SetDict.mergeMany", () => { - Mocha.test("Belt_SetDict.mergeMany", () => { +Mocha.describe("Console.debugMany", () => { + Mocha.test("Console.debugMany", () => { + console.debug("Hello", "World"); + console.debug(1, 2, 3); + }); +}); + +Mocha.describe("Console.errorMany", () => { + Mocha.test("Console.errorMany", () => { + console.error("Hello", "World"); + console.error(1, 2, 3); + }); +}); + +Mocha.describe("Belt_Set.Dict.has", () => { + Mocha.test("Belt_Set.Dict.has", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let newSet = Belt_SetDict.mergeMany(undefined, [ - 5, + let set = Belt_SetDict.fromArray([ + 1, 4, - 3, 2, - 1 + 5 ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); + Belt_SetDict.has(set, 3, IntCmp.cmp); + Belt_SetDict.has(set, 1, IntCmp.cmp); }); }); -Mocha.describe("Belt_SetDict.add", () => { - Mocha.test("Belt_SetDict.add", () => { +Mocha.describe("Belt_Set.Dict.add", () => { + Mocha.test("Belt_Set.Dict.add", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -11618,82 +10392,77 @@ Mocha.describe("Belt_SetDict.add", () => { }); }); -Mocha.describe("Belt_SetDict.has", () => { - Mocha.test("Belt_SetDict.has", () => { +Mocha.describe("Belt_Set.Dict.get", () => { + Mocha.test("Belt_Set.Dict.get", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_SetDict.fromArray([ + let s0 = Belt_SetDict.fromArray([ 1, - 4, 2, + 3, + 4, 5 ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); - }); -}); - -Mocha.describe("Belt_SetDict.isEmpty", () => { - Mocha.test("Belt_SetDict.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); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); }); }); -Mocha.describe("Belt_SetDict.fromArray", () => { - Mocha.test("Belt_SetDict.fromArray", () => { +Mocha.describe("Belt_SetDict.diff", () => { + Mocha.test("Belt_SetDict.diff", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); let s0 = Belt_SetDict.fromArray([ - 1, + 5, + 2, 3, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, 2, + 3, + 1, + 5, 4 ], IntCmp.cmp); - Belt_SetDict.toArray(s0); + 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.describe("Belt_SetDict.empty", () => { - Mocha.test("Belt_SetDict.empty", () => {}); -}); - -Mocha.describe("Belt_Set.Dict.split", () => { - Mocha.test("Belt_Set.Dict.split", () => { +Mocha.describe("Belt_SetDict.some", () => { + Mocha.test("Belt_SetDict.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, - 3, 4, - 5 + 6, + 8 ], 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]); + Belt_SetDict.some(s0, isOdd); }); }); -Mocha.describe("Belt_Set.Dict.get", () => { - Mocha.test("Belt_Set.Dict.get", () => { +Mocha.describe("Belt_SetDict.keep", () => { + Mocha.test("Belt_SetDict.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, @@ -11701,1917 +10470,1887 @@ Mocha.describe("Belt_Set.Dict.get", () => { 4, 5 ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); }); }); -Mocha.describe("Belt_Set.Dict.maxUndefined", () => { - Mocha.test("Belt_Set.Dict.maxUndefined", () => { +Mocha.describe("Belt_SetDict.size", () => { + Mocha.test("Belt_SetDict.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, + let s0 = Belt_SetDict.fromArray([ 1, - 5 + 2, + 3, + 4 ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); + Belt_SetDict.size(s0); }); }); -Mocha.describe("Belt_Set.Dict.maximum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Range.someBy", () => { + Mocha.test("Belt_Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Belt_Set.Dict.minUndefined", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Int.toString", () => { + Mocha.test("Belt_Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); }); }); -Mocha.describe("Belt_Set.Dict.minimum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_List.headExn", () => { + Mocha.test("Belt_List.headExn", () => { + Pervasives.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", + 8501, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_Set.Dict.toArray", () => { - Mocha.test("Belt_Set.Dict.toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.tailExn", () => { + Mocha.test("Belt_List.tailExn", () => { + Pervasives.assertEqual(Belt_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); + 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", + 8515, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_Set.Dict.toList", () => { - Mocha.test("Belt_Set.Dict.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.shuffle", () => { + Mocha.test("Belt_List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); }); }); -Mocha.describe("Belt_Set.Dict.size", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_List.splitAt", () => { + Mocha.test("Belt_List.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.describe("Belt_Set.Dict.partition", () => { - Mocha.test("Belt_Set.Dict.partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.flatten", () => { + Mocha.test("Belt_List.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 + } + } }); - 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.describe("Belt_Set.Dict.keep", () => { - Mocha.test("Belt_Set.Dict.keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.toArray", () => { + Mocha.test("Belt_List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt_Set.Dict.some", () => { - Mocha.test("Belt_Set.Dict.some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.reverse", () => { + Mocha.test("Belt_List.reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ - 1, - 2, - 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.some(s0, isOdd); }); }); -Mocha.describe("Belt_Set.Dict.every", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_List.forEach", () => { + Mocha.test("Belt_List.forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); }); }); -Mocha.describe("Belt_Set.Dict.reduce", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_List.reduce2", () => { + Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Belt_Set.Dict.forEach", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_List.keepMap", () => { + Mocha.test("Belt_List.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.describe("Belt_Set.Dict.eq", () => { - Mocha.test("Belt_Set.Dict.eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, +Mocha.describe("Belt.Array.length", () => { + Mocha.test("Belt.Array.length", () => {}); +}); + +Mocha.describe("Belt.Array.makeBy", () => { + Mocha.test("Belt.Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, 2, - 3 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ 3, - 2, - 5 - ], IntCmp.cmp); - Belt_SetDict.eq(s0, s1, IntCmp.cmp); + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Belt_Set.Dict.subset", () => { - Mocha.test("Belt_Set.Dict.subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, +Mocha.describe("Belt.Array.concat", () => { + Mocha.test("Belt.Array.concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, + 3 + ], [ + 4, + 5 + ]), [ + 1, 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); + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); }); }); -Mocha.describe("Belt_Set.Dict.diff", () => { - Mocha.test("Belt_Set.Dict.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, +Mocha.describe("Belt.Array.reduce", () => { + Mocha.test("Belt.Array.reduce", () => { + Belt_Array.reduce([ 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); + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; }); }); -Mocha.describe("Belt_Set.Dict.intersect", () => { - Mocha.test("Belt_Set.Dict.intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, +Mocha.describe("Belt.Array.every2", () => { + Mocha.test("Belt.Array.every2", () => { + Belt_Array.every2([ + 1, 2, - 3, - 5, - 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, + 3 + ], [ + 0, + 1 + ], (a, b) => a > b) === true; + Belt_Array.every2([], [1], (x, y) => x > y) === true; + Belt_Array.every2([ 2, - 3, - 1, + 3 + ], [1], (x, y) => x > y) === true; + Belt_Array.every2([ + 0, + 1 + ], [ 5, - 4 - ], IntCmp.cmp); - let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(intersect); + 0 + ], (x, y) => x > y) === false; }); }); -Mocha.describe("Belt_Set.Dict.union", () => { - Mocha.test("Belt_Set.Dict.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.List.headExn", () => { + Mocha.test("Belt.List.headExn", () => { + Pervasives.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", + 8678, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_Set.Dict.removeMany", () => { - Mocha.test("Belt_Set.Dict.removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.tailExn", () => { + Mocha.test("Belt.List.tailExn", () => { + Pervasives.assertEqual(Belt_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } }); - 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); + 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", + 8692, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_Set.Dict.remove", () => { - Mocha.test("Belt_Set.Dict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.shuffle", () => { + Mocha.test("Belt.List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt_Set.Dict.mergeMany", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt.List.splitAt", () => { + Mocha.test("Belt.List.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.describe("Belt_Set.Dict.add", () => { - Mocha.test("Belt_Set.Dict.add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.flatten", () => { + Mocha.test("Belt.List.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 + } + } }); - 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.describe("Belt_Set.Dict.has", () => { - Mocha.test("Belt_Set.Dict.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.toArray", () => { + Mocha.test("Belt.List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt_Set.Dict.isEmpty", () => { - Mocha.test("Belt_Set.Dict.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.reverse", () => { + Mocha.test("Belt.List.reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); }); }); -Mocha.describe("Belt_Set.Dict.fromArray", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt.List.forEach", () => { + Mocha.test("Belt.List.forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); }); }); -Mocha.describe("Belt_Set.Dict.empty", () => { - Mocha.test("Belt_Set.Dict.empty", () => {}); +Mocha.describe("Belt.List.reduce2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); + }); }); -Mocha.describe("Belt_Set.split", () => { - Mocha.test("Belt_Set.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.keepMap", () => { + Mocha.test("Belt.List.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; + } + }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.split(s0, 3); - let match$1 = match[0]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); + Belt_List.keepMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); }); }); -Mocha.describe("Belt_Set.get", () => { - Mocha.test("Belt_Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.Range.someBy", () => { + Mocha.test("Belt.Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt.HashMap.make", () => { + Mocha.test("Belt.HashMap.make", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 0, "a"); }); }); -Mocha.describe("Belt_Set.maxUndefined", () => { - Mocha.test("Belt_Set.maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.HashMap.copy", () => { + Mocha.test("Belt.HashMap.copy", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + 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.describe("Belt_Set.maximum", () => { - Mocha.test("Belt_Set.maximum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.HashMap.size", () => { + Mocha.test("Belt.HashMap.size", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + 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.describe("Belt_Set.minUndefined", () => { - Mocha.test("Belt_Set.minUndefined", () => { +Mocha.describe("Belt.Int.toString", () => { + Mocha.test("Belt.Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt.Set.Dict.has", () => { + Mocha.test("Belt.Set.Dict.has", () => { 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, + let set = Belt_SetDict.fromArray([ 1, + 4, + 2, 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + ], IntCmp.cmp); + Belt_SetDict.has(set, 3, IntCmp.cmp); + Belt_SetDict.has(set, 1, IntCmp.cmp); }); }); -Mocha.describe("Belt_Set.minimum", () => { - Mocha.test("Belt_Set.minimum", () => { +Mocha.describe("Belt.Set.Dict.add", () => { + Mocha.test("Belt.Set.Dict.add", () => { 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); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); + 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.describe("Belt_Set.toList", () => { - Mocha.test("Belt_Set.toList", () => { +Mocha.describe("Belt.Set.Dict.get", () => { + Mocha.test("Belt.Set.Dict.get", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 3, - 2, + let s0 = Belt_SetDict.fromArray([ 1, + 2, + 3, + 4, 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); + ], IntCmp.cmp); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); }); }); -Mocha.describe("Belt_Set.toArray", () => { - Mocha.test("Belt_Set.toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 - ]); - }); +Mocha.describe("Belt_Array.length", () => { + Mocha.test("Belt_Array.length", () => {}); }); -Mocha.describe("Belt_Set.size", () => { - Mocha.test("Belt_Set.size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt_Array.makeBy", () => { + Mocha.test("Belt_Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, 1, 2, 3, 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Belt_Set.partition", () => { - Mocha.test("Belt_Set.partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt_Array.concat", () => { + Mocha.test("Belt_Array.concat", () => { + Primitive_object.equal(Belt_Array.concat([ 1, 2, - 3, + 3 + ], [ 4, 5 - ], IntCmp); - let match = Belt_Set.partition(s0, isOdd); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ + ]), [ 1, + 2, 3, + 4, 5 ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" ]); }); }); -Mocha.describe("Belt_Set.keep", () => { - Mocha.test("Belt_Set.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, +Mocha.describe("Belt_Array.reduce", () => { + Mocha.test("Belt_Array.reduce", () => { + Belt_Array.reduce([ 2, 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, 4 - ]); + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; }); }); -Mocha.describe("Belt_Set.some", () => { - Mocha.test("Belt_Set.some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt_Array.every2", () => { + Mocha.test("Belt_Array.every2", () => { + Belt_Array.every2([ 1, 2, - 4, - 6, - 8 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); + 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.describe("Belt_Set.every", () => { - Mocha.test("Belt_Set.every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_HashMap.make", () => { + Mocha.test("Belt_HashMap.make", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 2, - 4, - 6, - 8 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + let hMap = Belt_HashMap.make(10, IntHash); + Belt_HashMap.set(hMap, 0, "a"); }); }); -Mocha.describe("Belt_Set.reduce", () => { - Mocha.test("Belt_Set.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_HashMap.copy", () => { + Mocha.test("Belt_HashMap.copy", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - let s0 = Belt_Set.fromArray([ - 5, + 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.describe("Belt_HashMap.size", () => { + Mocha.test("Belt_HashMap.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.describe("Array.unshiftMany", () => { + Mocha.test("Array.unshiftMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "yay", + "wehoo", + "hi", + "hello" + ]); + }); +}); + +Mocha.describe("Array.reduceRight", () => { + Mocha.test("Array.reduceRight", () => { + Pervasives.assertEqual($$Array.reduceRight([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "dcba"); + Pervasives.assertEqual($$Array.reduceRight([ + 1, 2, - 3, - 5, - 6 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, + 3 + ], /* [] */0, List.add), { + hd: 1, tl: { - hd: 5, + hd: 2, tl: { hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } + tl: /* [] */0 } } }); + Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); }); }); -Mocha.describe("Belt_Set.forEach", () => { - Mocha.test("Belt_Set.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); - }); - Pervasives.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); +Mocha.describe("String.codePointAt", () => { + Mocha.test("String.codePointAt", () => { + Primitive_object.equal("¿😺?".codePointAt(1), 128570); + "abc".codePointAt(5) === undefined; }); }); -Mocha.describe("Belt_Set.eq", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); +Mocha.describe("String.indexOfFrom", () => { + Mocha.test("String.indexOfFrom", () => { + "bookseller".indexOf("ok", 1) === 2; + "bookseller".indexOf("sell", 2) === 4; + "bookseller".indexOf("sell", 5) === -1; }); }); -Mocha.describe("Belt_Set.subset", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); +Mocha.describe("String.lastIndexOf", () => { + Mocha.test("String.lastIndexOf", () => { + "bookseller".lastIndexOf("ok") === 2; + "beekeeper".lastIndexOf("ee") === 4; + "abcdefg".lastIndexOf("xyz") === -1; }); }); -Mocha.describe("Belt_Set.diff", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 +Mocha.describe("String.splitAtMost", () => { + Mocha.test("String.splitAtMost", () => { + Primitive_object.equal("ant/bee/cat/dog/elk".split("/", 3), [ + "ant", + "bee", + "cat" ]); - }); -}); - -Mocha.describe("Belt_Set.intersect", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, - 5 + 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.describe("Belt_Set.union", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, - 3, - 4, - 5, - 6 - ]); +Mocha.describe("String.toLowerCase", () => { + Mocha.test("String.toLowerCase", () => { + "ABC".toLowerCase() === "abc"; + "ΣΠ".toLowerCase() === "σπ"; + "ΠΣ".toLowerCase() === "πς"; }); }); -Mocha.describe("Belt_Set.removeMany", () => { - Mocha.test("Belt_Set.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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); +Mocha.describe("String.toUpperCase", () => { + Mocha.test("String.toUpperCase", () => { + "abc".toUpperCase() === "ABC"; + "Straße".toUpperCase() === "STRASSE"; + "πς".toUpperCase() === "ΠΣ"; }); }); -Mocha.describe("Belt_Set.remove", () => { - Mocha.test("Belt_Set.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Promise.allSettled", () => { + Mocha.test("Promise.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(); }); - 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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt_Set.mergeMany", () => { - Mocha.test("Belt_Set.mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Object.keysToArray", () => { + Mocha.test("Object.keysToArray", () => { + Object.keys({ + a: 1, + b: 2 }); - let set = Belt_Set.make(IntCmp); - let newSet = Belt_Set.mergeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ - 1, - 2, - 3, - 4, - 5 - ]); + Object.keys({ + a: undefined + }); + Object.keys({}); }); }); -Mocha.describe("Belt_Set.add", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); +Mocha.describe("Nullable.undefined", () => { + Mocha.test("Nullable.undefined", () => { + console.log(undefined); }); }); -Mocha.describe("Belt_Set.has", () => { - Mocha.test("Belt_Set.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Nullable.getUnsafe", () => { + Mocha.test("Nullable.getUnsafe", () => {}); +}); + +Mocha.describe("List.reverseConcat", () => { + Mocha.test("List.reverseConcat", () => { + List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); }); }); -Mocha.describe("Belt_Set.isEmpty", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); +Mocha.describe("List.reduceReverse", () => { + Mocha.test("List.reduceReverse", () => { + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, List.add); }); }); -Mocha.describe("Belt_Set.fromArray", () => { - Mocha.test("Belt_Set.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.compareLength", () => { + Mocha.test("List.compareLength", () => { + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); }); }); -Mocha.describe("Belt_Set.make", () => { - Mocha.test("Belt_Set.make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Math.Constants.ln2", () => { + Mocha.test("Math.Constants.ln2", () => {}); +}); + +Mocha.describe("Map.forEachWithKey", () => { + Mocha.test("Map.forEachWithKey", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach((value, key) => { + console.log(value, key); }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); }); }); -Mocha.describe("Belt_SortArray.binarySearchBy", () => { - Mocha.test("Belt_SortArray.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.describe("JSON.Encode.string", () => { + Mocha.test("JSON.Encode.string", () => {}); }); -Mocha.describe("Belt_SortArray.strictlySortedLength", () => { - Mocha.test("Belt_SortArray.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.S.binarySearchBy", () => { - Mocha.test("Belt_internalMapString.S.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.describe("JSON.Encode.object", () => { + Mocha.test("JSON.Encode.object", () => { + Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ] + ]); }); }); -Mocha.describe("Belt_internalMapString.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapString.S.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("JSON.Decode.string", () => { + Mocha.test("JSON.Decode.string", () => { + $$JSON.Decode.string(JSON.parse("\"hello world\"")); + $$JSON.Decode.string(JSON.parse("42")); }); }); -Mocha.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("JSON.Decode.object", () => { + Mocha.test("JSON.Decode.object", () => { + $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); + $$JSON.Decode.object(JSON.parse("\"hello world\"")); }); }); -Mocha.describe("Belt_internalMapString.A.eq", () => { - Mocha.test("Belt_internalMapString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Int.toLocaleString", () => { + Mocha.test("Int.toLocaleString", () => { + (1000).toLocaleString(); + (1000).toLocaleString(); }); }); -Mocha.describe("Belt_internalMapString.A.cmp", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Date.makeWithYMDHM", () => { + Mocha.test("Date.makeWithYMDHM", () => { + new Date(2023, 1, 20, 16, 40); + new Date(2023, 1, 20, 16, 60); + new Date(2023, 1, 20, 16, -1); }); }); -Mocha.describe("Belt_internalMapString.A.some2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Date.setFullYearMD", () => { + Mocha.test("Date.setFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); }); }); -Mocha.describe("Belt_internalMapString.A.every2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Date.setMinutesSMs", () => { + Mocha.test("Date.setMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); }); }); -Mocha.describe("Belt_internalMapString.A.every", () => { - Mocha.test("Belt_internalMapString.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Date.getUTCMinutes", () => { + Mocha.test("Date.getUTCMinutes", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); }); }); -Mocha.describe("Belt_internalMapString.A.some", () => { - Mocha.test("Belt_internalMapString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Date.getUTCSeconds", () => { + Mocha.test("Date.getUTCSeconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); }); }); -Mocha.describe("Belt_internalMapString.A.joinWith", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Date.setUTCHoursMS", () => { + Mocha.test("Date.setUTCHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); }); }); -Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("Date.setUTCMinutes", () => { + Mocha.test("Date.setUTCMinutes", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("Date.setUTCSeconds", () => { + Mocha.test("Date.setUTCSeconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("Dict.valuesToArray", () => { + Mocha.test("Dict.valuesToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let values = Object.values(dict); + console.log(values); }); }); -Mocha.describe("Belt_internalMapString.A.reduce", () => { - Mocha.test("Belt_internalMapString.A.reduce", () => { - Belt_Array.reduce([ +Mocha.describe("Console.assertMany", () => { + Mocha.test("Console.assertMany", () => { + console.assert(false, "Hello", "World"); + console.assert(true, 1, 2, 3); + }); +}); + +Mocha.describe("Console.countReset", () => { + Mocha.test("Console.countReset", () => { + console.countReset("rescript"); + }); +}); + +Mocha.describe("Belt_Set.fromArray", () => { + Mocha.test("Belt_Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, 2, 3, 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; + ]); }); }); -Mocha.describe("Belt_internalMapString.A.partition", () => { - Mocha.test("Belt_internalMapString.A.partition", () => { - Primitive_object.equal(Belt_Array.partition([ +Mocha.describe("Belt_Set.mergeMany", () => { + Mocha.test("Belt_Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ 1, 2, 3, 4, 5 - ], x => x % 2 === 0), [ - [ - 2, - 4 - ], - [ - 1, - 3, - 5 - ] ]); - Primitive_object.equal(Belt_Array.partition([ + }); +}); + +Mocha.describe("Belt_Set.intersect", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ 2, 3, - 4, 5 - ], x => x % 2 !== 0), [ - [ - 1, - 3, - 5 - ], - [ - 2, - 4 - ] ]); }); }); -Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ +Mocha.describe("Belt_Set.partition", () => { + Mocha.test("Belt_Set.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 - ], (i, x) => i + x | 0), [ + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ 1, 3, 5 ]); + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 + ]); }); }); -Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_Set.Dict.diff", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_internalMapString.A.keepMap", () => { - Mocha.test("Belt_internalMapString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ +Mocha.describe("Belt_Set.Dict.some", () => { + Mocha.test("Belt_Set.Dict.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, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); }); }); -Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ +Mocha.describe("Belt_Set.Dict.keep", () => { + Mocha.test("Belt_Set.Dict.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 - ], (_x, i) => i === 1), [2]); + 3, + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); }); }); -Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { - Mocha.test("Belt_internalMapString.A.getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ +Mocha.describe("Belt_Set.Dict.size", () => { + Mocha.test("Belt_Set.Dict.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ 1, - 4, + 2, 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 4 + ], IntCmp.cmp); + Belt_SetDict.size(s0); }); }); -Mocha.describe("Belt_internalMapString.A.getBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_SetDict.empty", () => { + Mocha.test("Belt_SetDict.empty", () => {}); }); -Mocha.describe("Belt_internalMapString.A.flatMap", () => { - Mocha.test("Belt_internalMapString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("Belt_SetDict.union", () => { + Mocha.test("Belt_SetDict.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_internalMapString.A.map", () => { - Mocha.test("Belt_internalMapString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("Belt_SetDict.every", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_internalMapString.A.forEach", () => { - Mocha.test("Belt_internalMapString.A.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); +Mocha.describe("Belt_SetDict.split", () => { + Mocha.test("Belt_SetDict.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ + let s0 = Belt_SetDict.fromArray([ 1, 2, 3, - 4 - ], x => { - total.contents = total.contents + x | 0; + 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.describe("Belt_Result.getExn", () => { + Mocha.test("Belt_Result.getExn", () => { + Pervasives.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", + 9642, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_Range.forEach", () => { + Mocha.test("Belt_Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); }); }); }); -Mocha.describe("Belt_internalMapString.A.blit", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_Range.everyBy", () => { + Mocha.test("Belt_Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Belt_internalMapString.A.fill", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_Option.getExn", () => { + Mocha.test("Belt_Option.getExn", () => { + Pervasives.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", + 9685, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_Option.orElse", () => { + Mocha.test("Belt_Option.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_internalMapString.A.slice", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_Option.isSome", () => { + Mocha.test("Belt_Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); }); }); -Mocha.describe("Belt_internalMapString.A.concatMany", () => { - Mocha.test("Belt_internalMapString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("Belt_Option.isNone", () => { + Mocha.test("Belt_Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); }); }); -Mocha.describe("Belt_internalMapString.A.concat", () => { - Mocha.test("Belt_internalMapString.A.concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, +Mocha.describe("Belt_MutableSet.eq", () => { + Mocha.test("Belt_MutableSet.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, 2, 3 - ], [ - 4, - 5 - ]), [ - 1, - 2, + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ 3, - 4, + 2, 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); + ], IntCmp); + Belt_MutableSet.eq(s0, s1); }); }); -Mocha.describe("Belt_internalMapString.A.unzip", () => { - Mocha.test("Belt_internalMapString.A.unzip", () => { - Primitive_object.equal(Belt_Array.unzip([ +Mocha.describe("Belt_Map.fromArray", () => { + Mocha.test("Belt_Map.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ [ - 1, - 2 + 2, + "2" ], - [ - 3, - 4 - ] - ]), [ [ 1, - 3 + "1" ], [ - 2, - 4 + 3, + "3" ] - ]); - Primitive_object.equal(Belt_Array.unzip([ + ], IntCmp)), [ [ 1, - 2 - ], - [ - 3, - 4 + "1" ], [ - 5, - 6 + 2, + "2" ], [ - 7, - 8 - ] - ]), [ - [ - 1, 3, - 5, - 7 - ], - [ - 2, - 4, - 6, - 8 + "3" ] ]); }); }); -Mocha.describe("Belt_internalMapString.A.zipBy", () => { - Mocha.test("Belt_internalMapString.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Belt_Int.fromFloat", () => { + Mocha.test("Belt_Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Belt_internalMapString.A.zip", () => { - Mocha.test("Belt_internalMapString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ +Mocha.describe("Belt_List.forEach2", () => { + Mocha.test("Belt_List.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.describe("Belt_List.getAssoc", () => { + Mocha.test("Belt_List.getAssoc", () => { + Belt_List.getAssoc({ + hd: [ 1, - 3 + "a" ], - [ - 2, - 4 - ] - ]); + 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.describe("Belt_internalMapString.A.makeBy", () => { - Mocha.test("Belt_internalMapString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 +Mocha.describe("Belt_List.hasAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt_List.setAssoc", () => { + Mocha.test("Belt_List.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.describe("Belt.Array.reverse", () => { + Mocha.test("Belt.Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 ]); }); }); -Mocha.describe("Belt_internalMapString.A.rangeBy", () => { - Mocha.test("Belt_internalMapString.A.rangeBy", () => { +Mocha.describe("Belt.Array.rangeBy", () => { + Mocha.test("Belt.Array.rangeBy", () => { Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, 3, @@ -13633,1946 +12372,1650 @@ Mocha.describe("Belt_internalMapString.A.rangeBy", () => { }); }); -Mocha.describe("Belt_internalMapString.A.range", () => { - Mocha.test("Belt_internalMapString.A.range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, +Mocha.describe("Belt.Array.forEach", () => { + Mocha.test("Belt.Array.forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); + }); + let total = { + contents: 0 + }; + Belt_Array.forEach([ 1, 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; + }); }); }); -Mocha.describe("Belt_internalMapString.A.reverse", () => { - Mocha.test("Belt_internalMapString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 +Mocha.describe("Belt.Array.flatMap", () => { + Mocha.test("Belt.Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { - let arr = [ - 10, 11, + 21, 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 + 22 ]); }); }); -Mocha.describe("Belt_internalMapString.A.get", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt.Array.keepMap", () => { + Mocha.test("Belt.Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Belt_internalMapString.A.length", () => { - Mocha.test("Belt_internalMapString.A.length", () => {}); +Mocha.describe("Belt.List.forEach2", () => { + Mocha.test("Belt.List.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.describe("BigInt.toLocaleString", () => { - Mocha.test("BigInt.toLocaleString", () => { - console.log((123n).toString()); +Mocha.describe("Belt.List.getAssoc", () => { + Mocha.test("Belt.List.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.describe("BigInt.toString", () => { - Mocha.test("BigInt.toString", () => { - console.log((123n).toString()); +Mocha.describe("Belt.List.hasAssoc", () => { + Mocha.test("Belt.List.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.describe("BigInt.fromStringExn", () => { - Mocha.test("BigInt.fromStringExn", () => { - BigInt("123"); - BigInt(""); - BigInt("0x11"); - BigInt("0b11"); - BigInt("0o11"); - try { - BigInt("a"); - } catch (raw__error) { - let _error = Primitive_exceptions.internalToException(raw__error); - if (_error.RE_EXN_ID !== Exn.$$Error) { - throw _error; +Mocha.describe("Belt.List.setAssoc", () => { + Mocha.test("Belt.List.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.describe("Belt_internalMapInt.S.binarySearchBy", () => { - Mocha.test("Belt_internalMapInt.S.binarySearchBy", () => { - Belt_SortArray.binarySearchBy([ +Mocha.describe("Belt.Range.forEach", () => { + Mocha.test("Belt.Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); + }); +}); + +Mocha.describe("Belt.Range.everyBy", () => { + Mocha.test("Belt.Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); + }); +}); + +Mocha.describe("Belt.Set.fromArray", () => { + Mocha.test("Belt.Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ 1, - 2, 3, - 4, - 33, - 35, - 36 - ], 33, Primitive_int.compare) === 4; - Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 2, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ 1, + 2, 3, - 5, - 7 - ], 4, Primitive_int.compare)) === 2; + 4 + ]); }); }); -Mocha.describe("Belt_internalMapInt.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapInt.S.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([ +Mocha.describe("Belt.Set.mergeMany", () => { + Mocha.test("Belt.Set.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 - ], (x, y) => x < y) === -4; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.eq", () => { - Mocha.test("Belt_internalMapInt.A.eq", () => { - Belt_Array.eq([ + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ 1, 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + 3, + 4, + 5 + ]); }); }); -Mocha.describe("Belt_internalMapInt.A.cmp", () => { - Mocha.test("Belt_internalMapInt.A.cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, +Mocha.describe("Belt.Set.intersect", () => { + Mocha.test("Belt.Set.intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.some2", () => { - Mocha.test("Belt_internalMapInt.A.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([ + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, 2, - 3 - ], [ + 3, 1, + 5, 4 - ], (x, y) => x > y) === true; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.every2", () => { - Mocha.test("Belt_internalMapInt.A.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([ + ], IntCmp); + let intersect = Belt_Set.intersect(s0, s1); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.every", () => { - Mocha.test("Belt_internalMapInt.A.every", () => { - Belt_Array.every([ - 1, 3, 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.some", () => { - Mocha.test("Belt_internalMapInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.joinWith", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ +Mocha.describe("Belt.Set.partition", () => { + Mocha.test("Belt.Set.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 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ + 4, + 5 + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reduceReverse", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reduce", () => { - Mocha.test("Belt_internalMapInt.A.reduce", () => { - Belt_Array.reduce([ - 2, 3, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; + ]); }); }); -Mocha.describe("Belt_internalMapInt.A.partition", () => { - Mocha.test("Belt_internalMapInt.A.partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ +Mocha.describe("Belt.Map.fromArray", () => { + Mocha.test("Belt.Map.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ [ 2, - 4 + "2" ], [ 1, + "1" + ], + [ 3, - 5 + "3" ] - ]); - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 !== 0), [ + ], IntCmp)), [ [ 1, - 3, - 5 + "1" ], [ 2, - 4 + "2" + ], + [ + 3, + "3" ] ]); }); }); -Mocha.describe("Belt_internalMapInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, +Mocha.describe("Belt.MutableSet.eq", () => { + Mocha.test("Belt.MutableSet.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, 2, 3 - ], (i, x) => i + x | 0), [ - 1, + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ 3, + 2, 5 - ]); + ], IntCmp); + Belt_MutableSet.eq(s0, s1); }); }); -Mocha.describe("Belt_internalMapInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt.HashMap.clear", () => { + Mocha.test("Belt.HashMap.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.describe("Belt_internalMapInt.A.keepMap", () => { - Mocha.test("Belt_internalMapInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } +Mocha.describe("Belt.Option.getExn", () => { + Mocha.test("Belt.Option.getExn", () => { + Pervasives.assertEqual(Belt_Option.getExn(3), 3); + let exit = 0; + let val; + try { + val = Belt_Option.getExn(undefined); + exit = 1; + } catch (exn) { - }), [2]); + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 10120, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("Belt.Option.orElse", () => { + Mocha.test("Belt.Option.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_internalMapInt.A.getIndexBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt.Option.isSome", () => { + Mocha.test("Belt.Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); }); }); -Mocha.describe("Belt_internalMapInt.A.getBy", () => { - Mocha.test("Belt_internalMapInt.A.getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, +Mocha.describe("Belt.Option.isNone", () => { + Mocha.test("Belt.Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); + }); +}); + +Mocha.describe("Belt.Result.getExn", () => { + Mocha.test("Belt.Result.getExn", () => { + Pervasives.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", + 10170, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.Int.fromFloat", () => { + Mocha.test("Belt.Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); + }); +}); + +Mocha.describe("Belt.Float.fromInt", () => { + Mocha.test("Belt.Float.fromInt", () => { + console.log(1 === 1.0); + }); +}); + +Mocha.describe("Belt.Set.Dict.diff", () => { + Mocha.test("Belt.Set.Dict.diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 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.describe("Belt_internalMapInt.A.flatMap", () => { - Mocha.test("Belt_internalMapInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ +Mocha.describe("Belt.Set.Dict.some", () => { + Mocha.test("Belt.Set.Dict.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 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); }); }); -Mocha.describe("Belt_internalMapInt.A.map", () => { - Mocha.test("Belt_internalMapInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ +Mocha.describe("Belt.Set.Dict.keep", () => { + Mocha.test("Belt.Set.Dict.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 - ], x => x + 1 | 0), [ + 2, 3, - 4 - ]); + 4, + 5 + ], IntCmp.cmp); + let s1 = Belt_SetDict.keep(s0, isEven); + Belt_SetDict.toArray(s1); }); }); -Mocha.describe("Belt_internalMapInt.A.forEach", () => { - Mocha.test("Belt_internalMapInt.A.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); +Mocha.describe("Belt.Set.Dict.size", () => { + Mocha.test("Belt.Set.Dict.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ + let s0 = Belt_SetDict.fromArray([ 1, 2, 3, 4 - ], x => { - total.contents = total.contents + x | 0; - }); + ], IntCmp.cmp); + Belt_SetDict.size(s0); }); }); -Mocha.describe("Belt_internalMapInt.A.blit", () => { - Mocha.test("Belt_internalMapInt.A.blit", () => { - let v1 = [ +Mocha.describe("Belt_Float.fromInt", () => { + Mocha.test("Belt_Float.fromInt", () => { + console.log(1 === 1.0); + }); +}); + +Mocha.describe("Belt_Array.reverse", () => { + Mocha.test("Belt_Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ 10, 11, 12, 13, + 14 + ]), [ 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, + 13, + 12, 11, - 14, - 15, - 16, - 15, - 16, - 17 + 10 ]); }); }); -Mocha.describe("Belt_internalMapInt.A.fill", () => { - Mocha.test("Belt_internalMapInt.A.fill", () => { - let arr = Belt_Array.makeBy(5, i => i); - Belt_Array.fill(arr, 2, 2, 9); - Primitive_object.equal(arr, [ +Mocha.describe("Belt_Array.rangeBy", () => { + Mocha.test("Belt_Array.rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ 0, - 1, - 9, - 9, - 4 + 3, + 6, + 9 ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ 0, - 1, - 9, + 3, + 6, 9, - 4 + 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.describe("Belt_internalMapInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_Array.forEach", () => { + Mocha.test("Belt_Array.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.describe("Belt_internalMapInt.A.slice", () => { - Mocha.test("Belt_internalMapInt.A.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, +Mocha.describe("Belt_Array.flatMap", () => { + Mocha.test("Belt_Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ 11, + 21, 12, - 13, - 14, - 15, - 16 - ], 4, 9), [ - 14, - 15, - 16 + 22 ]); }); }); -Mocha.describe("Belt_internalMapInt.A.concatMany", () => { - Mocha.test("Belt_internalMapInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ +Mocha.describe("Belt_Array.keepMap", () => { + Mocha.test("Belt_Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ 1, 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Belt_internalMapInt.A.concat", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_HashMap.clear", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_internalMapInt.A.unzip", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("AsyncIterator.make", () => { + Mocha.test("AsyncIterator.make", () => { + let context = { + contents: 0 + }; + let asyncIterator = $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + return { + done: currentValue >= 3, + value: currentValue + }; + }); + let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { + if (value !== undefined) { + console.log(value); + return; + } + + }); + main(); }); }); -Mocha.describe("Belt_internalMapInt.A.zipBy", () => { - Mocha.test("Belt_internalMapInt.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("AsyncIterator.done", () => { + Mocha.test("AsyncIterator.done", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } + }); }); }); -Mocha.describe("Belt_internalMapInt.A.zip", () => { - Mocha.test("Belt_internalMapInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ +Mocha.describe("AsyncIterator.next", () => { + Mocha.test("AsyncIterator.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) { + Pervasives.assertEqual(Option.isNone(match.value), true); + } + + }; + }; + processMyAsyncIterator(); + }); +}); + +Mocha.describe("Array.fromIterator", () => { + Mocha.test("Array.fromIterator", () => { + Pervasives.assertEqual(Array.from(new Map([ [ - 1, - 3 + "foo", + 1 ], [ - 2, - 4 + "bar", + 2 ] + ]).values()), [ + 1, + 2 ]); }); }); -Mocha.describe("Belt_internalMapInt.A.makeBy", () => { - Mocha.test("Belt_internalMapInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 +Mocha.describe("Array.mapWithIndex", () => { + Mocha.test("Array.mapWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); + Pervasives.assertEqual(mappedArray, [ + "Hello at position 0", + "Hi at position 1", + "Good bye at position 2" ]); }); }); -Mocha.describe("Belt_internalMapInt.A.rangeBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Array.findIndexOpt", () => { + Mocha.test("Array.findIndexOpt", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); }); }); -Mocha.describe("Belt_internalMapInt.A.range", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("String.fromCharCode", () => { + Mocha.test("String.fromCharCode", () => { + String.fromCharCode(65) === "A"; + String.fromCharCode(968) === "ψ"; + String.fromCharCode(54620) === "한"; + String.fromCharCode(-64568) === "ψ"; }); }); -Mocha.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("String.endsWithFrom", () => { + Mocha.test("String.endsWithFrom", () => { + "abcd".endsWith("cd", 4) === true; + "abcde".endsWith("cd", 3) === false; + "abcde".endsWith("cde", 99) === true; + "example.dat".endsWith("ple", 7) === true; }); }); -Mocha.describe("Belt_internalMapInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("String.includesFrom", () => { + Mocha.test("String.includesFrom", () => { + "programmer".includes("gram", 1) === true; + "programmer".includes("gram", 4) === false; + "대한민국".includes("한", 1) === true; }); }); -Mocha.describe("Belt_internalMapInt.A.reverse", () => { - Mocha.test("Belt_internalMapInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("RegExp.setLastIndex", () => { + Mocha.test("RegExp.setLastIndex", () => { + let regexp = new RegExp("\\w+"); + regexp.lastIndex = 4; + regexp.exec("Many words here."); + console.log(regexp.lastIndex); }); }); -Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("RegExp.Result.input", () => { + Mocha.test("RegExp.Result.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.describe("Belt_internalMapInt.A.get", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Promise.thenResolve", () => { + Mocha.test("Promise.thenResolve", () => { + Promise.resolve("Anna").then(str => "Hello " + str).then(str => { + console.log(str); + }); }); }); -Mocha.describe("Belt_internalMapInt.A.length", () => { - Mocha.test("Belt_internalMapInt.A.length", () => {}); +Mocha.describe("Object.isExtensible", () => { + Mocha.test("Object.isExtensible", () => { + let obj = { + a: 1 + }; + Object.isExtensible(obj); + Object.preventExtensions(obj); + Object.isExtensible(obj); + }); }); -Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("Nullable.isNullable", () => { + Mocha.test("Nullable.isNullable", () => { + if ("Hello" == null) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 10610, + 10 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalSetInt.A.eq", () => { - Mocha.test("Belt_internalSetInt.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Nullable.fromOption", () => { + Mocha.test("Nullable.fromOption", () => { + Nullable.fromOption("Hello"); }); }); -Mocha.describe("Belt_internalSetInt.A.cmp", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("List.reduceReverse2", () => { + Mocha.test("List.reduceReverse2", () => { + List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Belt_internalSetInt.A.some2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.Constants.ln10", () => { + Mocha.test("Math.Constants.ln10", () => {}); }); -Mocha.describe("Belt_internalSetInt.A.every2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Float.toExponential", () => { + Mocha.test("Float.toExponential", () => { + (1000.0).toExponential(); + (-1000.0).toExponential(); + (77.0).toExponential(2); + (5678.0).toExponential(2); }); }); -Mocha.describe("Belt_internalSetInt.A.every", () => { - Mocha.test("Belt_internalSetInt.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Float.Constants.nan", () => { + Mocha.test("Float.Constants.nan", () => {}); +}); + +Mocha.describe("Date.makeWithYMDHMS", () => { + Mocha.test("Date.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.describe("Belt_internalSetInt.A.some", () => { - Mocha.test("Belt_internalSetInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Date.getUTCFullYear", () => { + Mocha.test("Date.getUTCFullYear", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); }); }); -Mocha.describe("Belt_internalSetInt.A.joinWith", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Date.setUTCFullYear", () => { + Mocha.test("Date.setUTCFullYear", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); }); }); -Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("Date.setUTCMinutesS", () => { + Mocha.test("Date.setUTCMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("Date.toLocaleString", () => { + Mocha.test("Date.toLocaleString", () => { + console.log(new Date().toLocaleString()); }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reduce", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Date.UTC.makeWithYM", () => { + Mocha.test("Date.UTC.makeWithYM", () => { + Date.UTC(2023, 0); + Date.UTC(2023, 11); + Date.UTC(2023, 12); + Date.UTC(2023, -1); }); }); -Mocha.describe("Belt_internalSetInt.A.partition", () => { - Mocha.test("Belt_internalSetInt.A.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), [ +Mocha.describe("Dict.forEachWithKey", () => { + Mocha.test("Dict.forEachWithKey", () => { + let dict = Object.fromEntries([ [ - 1, - 3, - 5 + "key1", + "value1" ], [ - 2, - 4 + "key2", + "value2" ] ]); + Dict.forEachWithKey(dict, (value, key) => { + console.log(value, key); + }); }); }); -Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ +Mocha.describe("Belt_Set.removeMany", () => { + Mocha.test("Belt_Set.removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ 1, 2, - 3 - ], (i, x) => i + x | 0), [ - 1, 3, - 5 + 4 + ], IntCmp); + let newSet = Belt_Set.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); }); }); -Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_Set.Dict.empty", () => { + Mocha.test("Belt_Set.Dict.empty", () => {}); +}); + +Mocha.describe("Belt_Set.Dict.union", () => { + Mocha.test("Belt_Set.Dict.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_internalSetInt.A.keepMap", () => { - Mocha.test("Belt_internalSetInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, +Mocha.describe("Belt_Set.Dict.every", () => { + Mocha.test("Belt_Set.Dict.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, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); }); }); -Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ +Mocha.describe("Belt_Set.Dict.split", () => { + Mocha.test("Belt_Set.Dict.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ 1, 2, - 3 - ], (_x, i) => i === 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.describe("Belt_internalSetInt.A.getIndexBy", () => { - Mocha.test("Belt_internalSetInt.A.getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ +Mocha.describe("Belt_SetDict.remove", () => { + Mocha.test("Belt_SetDict.remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 2, + 3, 1, 4, - 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 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.describe("Belt_internalSetInt.A.getBy", () => { - Mocha.test("Belt_internalSetInt.A.getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ - 1, - 4, +Mocha.describe("Belt_SetDict.subset", () => { + Mocha.test("Belt_SetDict.subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 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.describe("Belt_internalSetInt.A.flatMap", () => { - Mocha.test("Belt_internalSetInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("Belt_SetDict.reduce", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_internalSetInt.A.map", () => { - Mocha.test("Belt_internalSetInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ +Mocha.describe("Belt_SetDict.toList", () => { + Mocha.test("Belt_SetDict.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ 3, - 4 - ]); + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.toList(s0); }); }); -Mocha.describe("Belt_internalSetInt.A.forEach", () => { - Mocha.test("Belt_internalSetInt.A.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); +Mocha.describe("Belt_Result.flatMap", () => { + Mocha.test("Belt_Result.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 }); - let total = { - contents: 0 + 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.describe("Belt_Option.forEach", () => { + Mocha.test("Belt_Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Belt_Option.flatMap", () => { + Mocha.test("Belt_Option.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + }; - Belt_Array.forEach([ + Belt_Option.flatMap(2, addIfAboveOne); + Belt_Option.flatMap(-4, addIfAboveOne); + Belt_Option.flatMap(undefined, addIfAboveOne); + }); +}); + +Mocha.describe("Belt_MutableSet.has", () => { + Mocha.test("Belt_MutableSet.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ 1, + 4, 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); + 5 + ], IntCmp); + Belt_MutableSet.has(set, 3); + Belt_MutableSet.has(set, 1); }); }); -Mocha.describe("Belt_internalSetInt.A.blit", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_MutableSet.add", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_internalSetInt.A.fill", () => { - Mocha.test("Belt_internalSetInt.A.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, +Mocha.describe("Belt_MutableSet.get", () => { + Mocha.test("Belt_MutableSet.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, - 9, - 9, - 4 - ]); + 2, + 3, + 4, + 5 + ], IntCmp); + Belt_MutableSet.get(s0, 3); + Belt_MutableSet.get(s0, 20); }); }); -Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_Int.fromString", () => { + Mocha.test("Belt_Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); }); }); -Mocha.describe("Belt_internalSetInt.A.slice", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.concatMany", () => { - Mocha.test("Belt_internalSetInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ +Mocha.describe("Belt_List.fromArray", () => { + Mocha.test("Belt_List.fromArray", () => { + Belt_List.fromArray([ 1, 2, - 3, - 4, - 5, - 6, - 7, - 8 + 3 ]); }); }); -Mocha.describe("Belt_internalSetInt.A.concat", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_List.partition", () => { + Mocha.test("Belt_List.partition", () => { + Pervasives.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.describe("Belt_internalSetInt.A.unzip", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt.Array.joinWith", () => { + Mocha.test("Belt.Array.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.describe("Belt_internalSetInt.A.zipBy", () => { - Mocha.test("Belt_internalSetInt.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ +Mocha.describe("Belt.List.fromArray", () => { + Mocha.test("Belt.List.fromArray", () => { + Belt_List.fromArray([ 1, 2, 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 ]); }); }); -Mocha.describe("Belt_internalSetInt.A.zip", () => { - Mocha.test("Belt_internalSetInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] +Mocha.describe("Belt.List.partition", () => { + Mocha.test("Belt.List.partition", () => { + Pervasives.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.describe("Belt_internalSetInt.A.makeBy", () => { - Mocha.test("Belt_internalSetInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, +Mocha.describe("Belt.Set.removeMany", () => { + Mocha.test("Belt.Set.removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ 1, 2, 3, 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, + ], IntCmp); + let newSet = Belt_Set.removeMany(set, [ + 5, 4, - 9, - 16 + 3, + 2, + 1 ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); }); }); -Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt.MutableSet.has", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt_internalSetInt.A.range", () => { - Mocha.test("Belt_internalSetInt.A.range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, +Mocha.describe("Belt.MutableSet.add", () => { + Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.get", () => { + Mocha.test("Belt.MutableSet.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); + 3, + 4, + 5 + ], IntCmp); + Belt_MutableSet.get(s0, 3); + Belt_MutableSet.get(s0, 20); }); }); -Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt.HashMap.remove", () => { + Mocha.test("Belt.HashMap.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.describe("Belt_internalSetInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Belt.HashMap.reduce", () => { + Mocha.test("Belt.HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); }); }); -Mocha.describe("Belt_internalSetInt.A.reverse", () => { - Mocha.test("Belt_internalSetInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Belt.Option.forEach", () => { + Mocha.test("Belt.Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); }); }); -Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Belt.Option.flatMap", () => { + Mocha.test("Belt.Option.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.describe("Belt_internalSetInt.A.get", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt.Result.flatMap", () => { + Mocha.test("Belt.Result.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.describe("Belt_internalSetInt.A.length", () => { - Mocha.test("Belt_internalSetInt.A.length", () => {}); +Mocha.describe("Belt.Int.fromString", () => { + Mocha.test("Belt.Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); + }); }); -Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("Belt.Float.toString", () => { + Mocha.test("Belt.Float.toString", () => { + console.log(String(1.0) === "1.0"); }); }); -Mocha.describe("Belt_internalSetString.A.eq", () => { - Mocha.test("Belt_internalSetString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); +Mocha.describe("Belt.Set.Dict.empty", () => { + Mocha.test("Belt.Set.Dict.empty", () => {}); }); -Mocha.describe("Belt_internalSetString.A.cmp", () => { - Mocha.test("Belt_internalSetString.A.cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, +Mocha.describe("Belt.Set.Dict.union", () => { + Mocha.test("Belt.Set.Dict.union", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, 3, - 5 - ], [ - 1, - 3, - 5 - ], Primitive_int.compare) === 0; - }); -}); - -Mocha.describe("Belt_internalSetString.A.some2", () => { - Mocha.test("Belt_internalSetString.A.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([ + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, 2, - 3 - ], [ + 3, 1, + 5, 4 - ], (x, y) => x > y) === true; + ], IntCmp.cmp); + let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(union); }); }); -Mocha.describe("Belt_internalSetString.A.every2", () => { - Mocha.test("Belt_internalSetString.A.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([ +Mocha.describe("Belt.Set.Dict.every", () => { + Mocha.test("Belt.Set.Dict.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, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); }); }); -Mocha.describe("Belt_internalSetString.A.every", () => { - Mocha.test("Belt_internalSetString.A.every", () => { - Belt_Array.every([ +Mocha.describe("Belt.Set.Dict.split", () => { + Mocha.test("Belt.Set.Dict.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ 1, + 2, 3, + 4, 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; + ], 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.describe("Belt_internalSetString.A.some", () => { - Mocha.test("Belt_internalSetString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Belt_Float.toString", () => { + Mocha.test("Belt_Float.toString", () => { + console.log(String(1.0) === "1.0"); }); }); -Mocha.describe("Belt_internalSetString.A.joinWith", () => { - Mocha.test("Belt_internalSetString.A.joinWith", () => { +Mocha.describe("Belt_Array.joinWith", () => { + Mocha.test("Belt_Array.joinWith", () => { Belt_Array.joinWith([ 0, 1 @@ -15582,2410 +14025,3527 @@ Mocha.describe("Belt_internalSetString.A.joinWith", () => { }); }); -Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("Belt_HashMap.remove", () => { + Mocha.test("Belt_HashMap.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.describe("Belt_internalSetString.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("Belt_HashMap.reduce", () => { + Mocha.test("Belt_HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); }); }); -Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("AsyncIterator.value", () => { + Mocha.test("AsyncIterator.value", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } + }); }); }); -Mocha.describe("Belt_internalSetString.A.reduce", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Array.findWithIndex", () => { + Mocha.test("Array.findWithIndex", () => { + let array = [ + "TypeScript", + "JavaScript", + "ReScript" + ]; + Pervasives.assertEqual(array.find((item, index) => { + if (index > 1) { + return item === "ReScript"; + } else { + return false; + } + }), "ReScript"); }); }); -Mocha.describe("Belt_internalSetString.A.partition", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Array.someWithIndex", () => { + Mocha.test("Array.someWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some((greeting, index) => { + if (greeting === "Hello") { + return index === 0; + } else { + return false; + } + }), true); }); }); -Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("String.fromCodePoint", () => { + Mocha.test("String.fromCodePoint", () => { + String.fromCodePoint(65) === "A"; + String.fromCodePoint(968) === "ψ"; + String.fromCodePoint(54620) === "한"; + String.fromCodePoint(128570) === "😺"; }); }); -Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetString.A.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.describe("String.normalizeForm", () => { + Mocha.test("String.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.describe("Belt_internalSetString.A.keepMap", () => { - Mocha.test("Belt_internalSetString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("String.replaceRegExp", () => { + Mocha.test("String.replaceRegExp", () => { + "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; }); }); -Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("String.splitByRegExp", () => { + Mocha.test("String.splitByRegExp", () => { + Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ + "Jan", + "Feb", + "Mar" + ]); }); }); -Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("String.localeCompare", () => { + Mocha.test("String.localeCompare", () => { + "a".localeCompare("c") < 0.0 === true; + "a".localeCompare("a") === 0.0; }); }); -Mocha.describe("Belt_internalSetString.A.getBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Pervasives.encodeURI", () => { + Mocha.test("Pervasives.encodeURI", () => { + console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); }); }); -Mocha.describe("Belt_internalSetString.A.flatMap", () => { - Mocha.test("Belt_internalSetString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("Pervasives.decodeURI", () => { + Mocha.test("Pervasives.decodeURI", () => { + console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); }); }); -Mocha.describe("Belt_internalSetString.A.map", () => { - Mocha.test("Belt_internalSetString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("List.fromInitializer", () => { + Mocha.test("List.fromInitializer", () => { + List.fromInitializer(5, i => i); + List.fromInitializer(5, i => Math.imul(i, i)); }); }); -Mocha.describe("Belt_internalSetString.A.forEach", () => { - Mocha.test("Belt_internalSetString.A.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.describe("List.reduceWithIndex", () => { + Mocha.test("List.reduceWithIndex", () => { + 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.describe("Belt_internalSetString.A.blit", () => { - Mocha.test("Belt_internalSetString.A.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.describe("List.filterWithIndex", () => { + Mocha.test("List.filterWithIndex", () => { + List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("Belt_internalSetString.A.fill", () => { - Mocha.test("Belt_internalSetString.A.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 +Mocha.describe("Math.Constants.log2e", () => { + Mocha.test("Math.Constants.log2e", () => {}); +}); + +Mocha.describe("Math.Constants.sqrt2", () => { + Mocha.test("Math.Constants.sqrt2", () => {}); +}); + +Mocha.describe("Int.rangeWithOptions", () => { + Mocha.test("Int.rangeWithOptions", () => { + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2 + }), [ + 3, + 5 ]); - Belt_Array.fill(arr, 7, 2, 8); - Primitive_object.equal(arr, [ - 0, - 1, - 9, - 9, - 4 + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 ]); + Int.rangeWithOptions(3, 6, { + step: -2 + }); }); }); -Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Float.toLocaleString", () => { + Mocha.test("Float.toLocaleString", () => { + (1000.0).toLocaleString(); + (1000.0).toLocaleString(); }); }); -Mocha.describe("Belt_internalSetString.A.slice", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Date.makeWithYMDHMSM", () => { + Mocha.test("Date.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.describe("Belt_internalSetString.A.concatMany", () => { - Mocha.test("Belt_internalSetString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("Date.getMilliseconds", () => { + Mocha.test("Date.getMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").getMilliseconds(); }); }); -Mocha.describe("Belt_internalSetString.A.concat", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Date.setMilliseconds", () => { + Mocha.test("Date.setMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setMilliseconds(0); }); }); -Mocha.describe("Belt_internalSetString.A.unzip", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Date.setUTCFullYearM", () => { + Mocha.test("Date.setUTCFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); }); }); -Mocha.describe("Belt_internalSetString.A.zipBy", () => { - Mocha.test("Belt_internalSetString.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Date.setUTCHoursMSMs", () => { + Mocha.test("Date.setUTCHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); }); }); -Mocha.describe("Belt_internalSetString.A.zip", () => { - Mocha.test("Belt_internalSetString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); +Mocha.describe("Date.setUTCSecondsMs", () => { + Mocha.test("Date.setUTCSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); }); }); -Mocha.describe("Belt_internalSetString.A.makeBy", () => { - Mocha.test("Belt_internalSetString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, +Mocha.describe("Date.UTC.makeWithYMD", () => { + Mocha.test("Date.UTC.makeWithYMD", () => { + Date.UTC(2023, 1, 20); + Date.UTC(2023, 1, -1); + Date.UTC(2023, 1, 29); + }); +}); + +Mocha.describe("BigInt.fromStringExn", () => { + Mocha.test("BigInt.fromStringExn", () => { + BigInt("123"); + BigInt(""); + BigInt("0x11"); + BigInt("0b11"); + BigInt("0o11"); + try { + BigInt("a"); + } catch (raw__error) { + let _error = Primitive_exceptions.internalToException(raw__error); + if (_error.RE_EXN_ID !== Exn.$$Error) { + throw _error; + } + + } + }); +}); + +Mocha.describe("Belt_Set.Dict.remove", () => { + Mocha.test("Belt_Set.Dict.remove", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ 2, 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, 1, 4, - 9, - 16 - ]); + 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.describe("Belt_internalSetString.A.rangeBy", () => { - Mocha.test("Belt_internalSetString.A.rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, +Mocha.describe("Belt_Set.Dict.subset", () => { + Mocha.test("Belt_Set.Dict.subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, 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.describe("Belt_internalSetString.A.range", () => { - Mocha.test("Belt_internalSetString.A.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]); + 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.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_Set.Dict.reduce", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetString.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Belt_Set.Dict.toList", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetString.A.reverse", () => { - Mocha.test("Belt_internalSetString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Belt_SetDict.isEmpty", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_internalSetString.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Belt_SetDict.forEach", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_internalSetString.A.get", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_SetDict.toArray", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_internalSetString.A.length", () => { - Mocha.test("Belt_internalSetString.A.length", () => {}); -}); - -Mocha.describe("Console.warnMany", () => { - Mocha.test("Console.warnMany", () => { - console.warn("Hello", "World"); - console.warn(1, 2, 3); +Mocha.describe("Belt_SetDict.minimum", () => { + Mocha.test("Belt_SetDict.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.describe("Console.warn6", () => { - Mocha.test("Console.warn6", () => { - console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.warn([ - 1, - 2 - ], [ +Mocha.describe("Belt_SetDict.maximum", () => { + Mocha.test("Belt_SetDict.maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maximum(undefined); + Belt_SetDict.maximum(s1); }); }); -Mocha.describe("Console.warn5", () => { - Mocha.test("Console.warn5", () => { - console.warn("Hello", "World", "from", "JS", "!!!"); - console.warn([ +Mocha.describe("Belt_MutableSet.copy", () => { + Mocha.test("Belt_MutableSet.copy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, - 2 - ], [ 3, + 2, 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); + ], IntCmp); + let copied = Belt_MutableSet.copy(s0); + Belt_MutableSet.toArray(copied); }); }); -Mocha.describe("Console.warn4", () => { - Mocha.test("Console.warn4", () => { - console.warn("Hello", "World", "ReScript", "!!!"); - console.warn("first", "second", "third", "fourth"); +Mocha.describe("Belt_MutableSet.diff", () => { + Mocha.test("Belt_MutableSet.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.describe("Console.warn3", () => { - Mocha.test("Console.warn3", () => { - console.warn("Hello", "World", "ReScript"); - console.warn([ +Mocha.describe("Belt_MutableSet.some", () => { + Mocha.test("Belt_MutableSet.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, - 3 - ], 4, 5); + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.some(s0, isOdd); }); }); -Mocha.describe("Console.warn2", () => { - Mocha.test("Console.warn2", () => { - console.warn("Hello", "World"); - console.warn([ +Mocha.describe("Belt_MutableSet.keep", () => { + Mocha.test("Belt_MutableSet.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); - }); -}); - -Mocha.describe("Console.warn", () => { - Mocha.test("Console.warn", () => { - console.warn("Warning"); - console.warn([ - "Warning", - "invalid number" - ]); + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_MutableSet.keep(s0, isEven); + Belt_MutableSet.toArray(s1); }); }); -Mocha.describe("Console.trace", () => { - Mocha.test("Console.trace", () => { - console.trace(); +Mocha.describe("Belt_MutableSet.size", () => { + Mocha.test("Belt_MutableSet.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.describe("Console.timeLog", () => { - Mocha.test("Console.timeLog", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); +Mocha.describe("Belt_Map.findFirstBy", () => { + Mocha.test("Belt_Map.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); + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); }); }); -Mocha.describe("Console.timeEnd", () => { - Mocha.test("Console.timeEnd", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); +Mocha.describe("Belt_Map.keysToArray", () => { + Mocha.test("Belt_Map.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.describe("Console.time", () => { - Mocha.test("Console.time", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); +Mocha.describe("Belt_List.concatMany", () => { + Mocha.test("Belt_List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); }); }); -Mocha.describe("Console.table", () => { - Mocha.test("Console.table", () => { - console.table({ - language: "rescript", - version: "10.1.2" +Mocha.describe("Belt_List.mapReverse", () => { + Mocha.test("Belt_List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } }); }); }); -Mocha.describe("Console.logMany", () => { - Mocha.test("Console.logMany", () => { - console.log("Hello", "World"); - console.log(1, 2, 3); - }); -}); - -Mocha.describe("Console.log6", () => { - Mocha.test("Console.log6", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.log([ +Mocha.describe("Belt.Array.partition", () => { + Mocha.test("Belt.Array.partition", () => { + Primitive_object.equal(Belt_Array.partition([ 1, - 2 - ], [ + 2, 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); + 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.describe("Console.log5", () => { - Mocha.test("Console.log5", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); +Mocha.describe("Belt.List.concatMany", () => { + Mocha.test("Belt.List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); }); }); -Mocha.describe("Console.log4", () => { - Mocha.test("Console.log4", () => { - console.log("Hello", "World", "ReScript", "!!!"); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); +Mocha.describe("Belt.List.mapReverse", () => { + Mocha.test("Belt.List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Console.log3", () => { - Mocha.test("Console.log3", () => { - console.log("Hello", "World", "ReScript"); - console.log("One", 2, 3); +Mocha.describe("Belt.Map.findFirstBy", () => { + Mocha.test("Belt.Map.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); + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); }); }); -Mocha.describe("Console.log2", () => { - Mocha.test("Console.log2", () => { - console.log("Hello", "World"); - console.log([ +Mocha.describe("Belt.Map.keysToArray", () => { + Mocha.test("Belt.Map.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 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.log", () => { - Mocha.test("Console.log", () => { - console.log("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.log(obj); - }); -}); - -Mocha.describe("Console.infoMany", () => { - Mocha.test("Console.infoMany", () => { - console.info("Hello", "World"); - console.info(1, 2, 3); + ]); }); }); -Mocha.describe("Console.info6", () => { - Mocha.test("Console.info6", () => { - console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.info([ +Mocha.describe("Belt.MutableSet.copy", () => { + Mocha.test("Belt.MutableSet.copy", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, - 2 - ], [ 3, + 2, 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); + ], IntCmp); + let copied = Belt_MutableSet.copy(s0); + Belt_MutableSet.toArray(copied); }); }); -Mocha.describe("Console.info5", () => { - Mocha.test("Console.info5", () => { - console.info("Hello", "World", "from", "JS", "!!!"); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); +Mocha.describe("Belt.MutableSet.diff", () => { + Mocha.test("Belt.MutableSet.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.describe("Console.info4", () => { - Mocha.test("Console.info4", () => { - console.info("Hello", "World", "ReScript", /* '!' */33); - console.info([ +Mocha.describe("Belt.MutableSet.some", () => { + Mocha.test("Belt.MutableSet.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, - 3 - ], 4, 5, "lastinfo"); + 4, + 6, + 8 + ], IntCmp); + Belt_MutableSet.some(s0, isOdd); }); }); -Mocha.describe("Console.info3", () => { - Mocha.test("Console.info3", () => { - console.info("Hello", "World", "ReScript"); - console.info([ +Mocha.describe("Belt.MutableSet.keep", () => { + Mocha.test("Belt.MutableSet.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); + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_MutableSet.keep(s0, isEven); + Belt_MutableSet.toArray(s1); }); }); -Mocha.describe("Console.info2", () => { - Mocha.test("Console.info2", () => { - console.info("Info", "failed to download"); - console.info("info", { - name: "ReScript" +Mocha.describe("Belt.MutableSet.size", () => { + Mocha.test("Belt.MutableSet.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - }); -}); - -Mocha.describe("Console.info", () => { - Mocha.test("Console.info", () => { - console.info("Information"); - console.info([ - "Hello", - "JS" - ]); - }); -}); - -Mocha.describe("Console.errorMany", () => { - Mocha.test("Console.errorMany", () => { - console.error("Hello", "World"); - console.error(1, 2, 3); - }); -}); - -Mocha.describe("Console.group", () => { - Mocha.test("Console.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.describe("Console.error6", () => { - Mocha.test("Console.error6", () => { - console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.error([ + let s0 = Belt_MutableSet.fromArray([ 1, - 2 - ], [ + 2, 3, 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); + ], IntCmp); + Belt_MutableSet.size(s0); }); }); -Mocha.describe("Console.error5", () => { - Mocha.test("Console.error5", () => { - console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); - console.error(1, "second", "third", "fourth", /* 'c' */99); +Mocha.describe("Belt.HashMap.isEmpty", () => { + Mocha.test("Belt.HashMap.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.describe("Console.error4", () => { - Mocha.test("Console.error4", () => { - console.error("Hello", "World", "ReScript", /* '!' */33); - console.error("first", "second", "third", "fourth"); +Mocha.describe("Belt.HashMap.forEach", () => { + Mocha.test("Belt.HashMap.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.describe("Console.error3", () => { - Mocha.test("Console.error3", () => { - console.error("Hello", "World", "!!!"); - console.error("first", "second", "third"); +Mocha.describe("Belt.HashMap.toArray", () => { + Mocha.test("Belt.HashMap.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.describe("Console.error2", () => { - Mocha.test("Console.error2", () => { - console.error("Error", "here"); - console.error([ - "log", - "error" - ], "message"); +Mocha.describe("Belt.Set.Dict.remove", () => { + Mocha.test("Belt.Set.Dict.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.describe("Console.error", () => { - Mocha.test("Console.error", () => { - console.error("error message"); - console.error([ - "error", - "invalid value" - ]); +Mocha.describe("Belt.Set.Dict.subset", () => { + Mocha.test("Belt.Set.Dict.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.describe("Console.dir", () => { - Mocha.test("Console.dir", () => { - console.dir({ - language: "rescript", - version: "10.1.2" +Mocha.describe("Belt.Set.Dict.reduce", () => { + Mocha.test("Belt.Set.Dict.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.describe("Console.debugMany", () => { - Mocha.test("Console.debugMany", () => { - console.debug("Hello", "World"); - console.debug(1, 2, 3); +Mocha.describe("Belt.Set.Dict.toList", () => { + Mocha.test("Belt.Set.Dict.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.describe("Console.debug6", () => { - Mocha.test("Console.debug6", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.debug([ +Mocha.describe("Belt_Array.partition", () => { + Mocha.test("Belt_Array.partition", () => { + Primitive_object.equal(Belt_Array.partition([ 1, - 2 - ], [ + 2, 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); + 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.describe("Console.debug5", () => { - Mocha.test("Console.debug5", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" +Mocha.describe("Belt_HashMap.isEmpty", () => { + Mocha.test("Belt_HashMap.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.describe("Console.debug4", () => { - Mocha.test("Console.debug4", () => { - console.debug("Hello", "World", "ReScript", "!!!"); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); +Mocha.describe("Belt_HashMap.forEach", () => { + Mocha.test("Belt_HashMap.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.describe("Console.debug3", () => { - Mocha.test("Console.debug3", () => { - console.debug("Hello", "World", "ReScript"); - console.debug("One", 2, 3); +Mocha.describe("Belt_HashMap.toArray", () => { + Mocha.test("Belt_HashMap.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.describe("Console.debug2", () => { - Mocha.test("Console.debug2", () => { - console.debug("Hello", "World"); - console.debug([ +Mocha.describe("Array.joinWithUnsafe", () => { + Mocha.test("Array.joinWithUnsafe", () => { + Pervasives.assertEqual([ 1, 2, 3 - ], /* '4' */52); + ].join(" -- "), "1 -- 2 -- 3"); }); }); -Mocha.describe("Console.debug", () => { - Mocha.test("Console.debug", () => { - console.debug("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.debug(obj); +Mocha.describe("Array.everyWithIndex", () => { + Mocha.test("Array.everyWithIndex", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every((num, index) => { + if (index < 5) { + return num <= 4; + } else { + return false; + } + }), true); + Pervasives.assertEqual(array.every((num, index) => { + if (index < 2) { + return num >= 2; + } else { + return false; + } + }), false); }); }); -Mocha.describe("Console.countReset", () => { - Mocha.test("Console.countReset", () => { - console.countReset("rescript"); +Mocha.describe("String.lastIndexOfOpt", () => { + Mocha.test("String.lastIndexOfOpt", () => { + Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); + Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); + $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; }); }); -Mocha.describe("Console.count", () => { - Mocha.test("Console.count", () => { - console.count("rescript"); +Mocha.describe("String.startsWithFrom", () => { + Mocha.test("String.startsWithFrom", () => { + "BuckleScript".startsWith("kle", 3) === true; + "BuckleScript".startsWith("", 3) === true; + "JavaScript".startsWith("Buckle", 2) === false; }); }); -Mocha.describe("Console.clear", () => { - Mocha.test("Console.clear", () => { - console.clear(); +Mocha.describe("String.substringToEnd", () => { + Mocha.test("String.substringToEnd", () => { + "playground".substring(4) === "ground"; + "playground".substring(-3) === "playground"; + "playground".substring(12) === ""; }); }); -Mocha.describe("Console.assertMany", () => { - Mocha.test("Console.assertMany", () => { - console.assert(false, "Hello", "World"); - console.assert(true, 1, 2, 3); +Mocha.describe("RegExp.Result.matches", () => { + Mocha.test("RegExp.Result.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("Console.assert6", () => { - Mocha.test("Console.assert6", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); +Mocha.describe("Pervasives.setTimeout", () => { + Mocha.test("Pervasives.setTimeout", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); }); }); -Mocha.describe("Console.assert5", () => { - Mocha.test("Console.assert5", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.assert4", () => { - Mocha.test("Console.assert4", () => { - console.assert(false, "Hello", "World", "ReScript", "!!!"); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); +Mocha.describe("Object.hasOwnProperty", () => { + Mocha.test("Object.hasOwnProperty", () => { + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "a"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "b"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "toString"); }); }); -Mocha.describe("Console.assert3", () => { - Mocha.test("Console.assert3", () => { - console.assert(false, "Hello", "World", "ReScript"); - console.assert(true, "One", 2, 3); +Mocha.describe("List.forEachWithIndex", () => { + Mocha.test("List.forEachWithIndex", () => { + List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (x, index) => { + console.log("Item " + index.toString() + " is " + x); + }); }); }); -Mocha.describe("Console.assert2", () => { - Mocha.test("Console.assert2", () => { - console.assert(false, "Hello", "World"); - console.assert(true, [ - 1, - 2, - 3 - ], /* '4' */52); - }); +Mocha.describe("Math.Constants.log10e", () => { + Mocha.test("Math.Constants.log10e", () => {}); }); -Mocha.describe("Console.assert_", () => { - Mocha.test("Console.assert_", () => { - console.assert(false, "Hello World!"); - console.assert(true, "The answer"); +Mocha.describe("Int.toStringWithRadix", () => { + Mocha.test("Int.toStringWithRadix", () => { + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); }); }); -Mocha.describe("Dict.mapValues", () => { - Mocha.test("Dict.mapValues", () => { - let dict = Object.fromEntries([ - [ - "key1", - 1 - ], - [ - "key2", - 2 - ] - ]); - Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); - Object.entries(Dict.mapValues(dict, v => v.toString())); +Mocha.describe("Date.setUTCFullYearMD", () => { + Mocha.test("Date.setUTCFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); }); }); -Mocha.describe("Dict.forEachWithKey", () => { - Mocha.test("Dict.forEachWithKey", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEachWithKey(dict, (value, key) => { - console.log(value, key); - }); +Mocha.describe("Date.setUTCMinutesSMs", () => { + Mocha.test("Date.setUTCMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); }); }); -Mocha.describe("Dict.forEach", () => { - Mocha.test("Dict.forEach", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEach(dict, value => { - console.log(value); - }); +Mocha.describe("Date.UTC.makeWithYMDH", () => { + Mocha.test("Date.UTC.makeWithYMDH", () => { + Date.UTC(2023, 1, 20, 16); + Date.UTC(2023, 1, 20, 24); + Date.UTC(2023, 1, 20, -1); }); }); -Mocha.describe("Dict.copy", () => { - Mocha.test("Dict.copy", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let dict2 = Object.assign({}, dict); - console.log(Object.keys(dict), Object.keys(dict2)); +Mocha.describe("BigInt.toLocaleString", () => { + Mocha.test("BigInt.toLocaleString", () => { + console.log((123n).toString()); }); }); -Mocha.describe("Dict.assign", () => { - Mocha.test("Dict.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.describe("Belt_Set.minUndefined", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); }); }); -Mocha.describe("Dict.valuesToArray", () => { - Mocha.test("Dict.valuesToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let values = Object.values(dict); - console.log(values); +Mocha.describe("Belt_Set.maxUndefined", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); }); }); -Mocha.describe("Dict.keysToArray", () => { - Mocha.test("Dict.keysToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let keys = Object.keys(dict); - console.log(keys); +Mocha.describe("Belt_Set.Dict.isEmpty", () => { + Mocha.test("Belt_Set.Dict.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.describe("Dict.toArray", () => { - Mocha.test("Dict.toArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let asArray = Object.entries(dict); - console.log(asArray); +Mocha.describe("Belt_Set.Dict.forEach", () => { + Mocha.test("Belt_Set.Dict.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.describe("Dict.fromIterator", () => { - Mocha.test("Dict.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ +Mocha.describe("Belt_Set.Dict.toArray", () => { + Mocha.test("Belt_Set.Dict.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 3, + 2, 1, - 2 - ]); + 5 + ], IntCmp.cmp); + Belt_SetDict.toArray(s0); }); }); -Mocha.describe("Dict.fromArray", () => { - Mocha.test("Dict.fromArray", () => { - Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); +Mocha.describe("Belt_Set.Dict.minimum", () => { + Mocha.test("Belt_Set.Dict.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.describe("Dict.make", () => { - Mocha.test("Dict.make", () => { - let dict2 = {}; - dict2["someKey"] = 12; +Mocha.describe("Belt_Set.Dict.maximum", () => { + Mocha.test("Belt_Set.Dict.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.describe("Dict.delete", () => { - Mocha.test("Dict.delete", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - Dict.$$delete(dict, "someKey"); +Mocha.describe("Belt_MutableSet.union", () => { + Mocha.test("Belt_MutableSet.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("Dict.set", () => { - Mocha.test("Dict.set", () => { - let dict = {}; - dict["someKey"] = "someValue"; +Mocha.describe("Belt_MutableSet.every", () => { + Mocha.test("Belt_MutableSet.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.describe("Dict.get", () => { - Mocha.test("Dict.get", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - let value = dict["someKey"]; - if (value !== undefined) { - console.log(value); - } else { - console.log("Nope, didn't have the key."); - } +Mocha.describe("Belt_MutableSet.split", () => { + Mocha.test("Belt_MutableSet.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.describe("Dict.getUnsafe", () => { - Mocha.test("Dict.getUnsafe", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let value = dict["key1"]; - console.log(value); +Mocha.describe("Belt_List.mapReverse2", () => { + Mocha.test("Belt_List.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.describe("Date.UTC.makeWithYMDHMSM", () => { - Mocha.test("Date.UTC.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("Belt_List.cmpByLength", () => { + Mocha.test("Belt_List.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.describe("Date.UTC.makeWithYMDHMS", () => { - Mocha.test("Date.UTC.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.describe("Belt_List.removeAssoc", () => { + Mocha.test("Belt_List.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.describe("Date.UTC.makeWithYMDHM", () => { - Mocha.test("Date.UTC.makeWithYMDHM", () => { - Date.UTC(2023, 1, 20, 16, 40); - Date.UTC(2023, 1, 20, 16, 60); - Date.UTC(2023, 1, 20, 16, -1); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMDH", () => { - Mocha.test("Date.UTC.makeWithYMDH", () => { - Date.UTC(2023, 1, 20, 16); - Date.UTC(2023, 1, 20, 24); - Date.UTC(2023, 1, 20, -1); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMD", () => { - Mocha.test("Date.UTC.makeWithYMD", () => { - Date.UTC(2023, 1, 20); - Date.UTC(2023, 1, -1); - Date.UTC(2023, 1, 29); +Mocha.describe("Belt.Array.concatMany", () => { + Mocha.test("Belt.Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Date.UTC.makeWithYM", () => { - Mocha.test("Date.UTC.makeWithYM", () => { - Date.UTC(2023, 0); - Date.UTC(2023, 11); - Date.UTC(2023, 12); - Date.UTC(2023, -1); +Mocha.describe("Belt.Array.sliceToEnd", () => { + Mocha.test("Belt.Array.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.describe("Date.toJSON", () => { - Mocha.test("Date.toJSON", () => { - new Date("2023-01-01T00:00:00.00+00:00").toJSON(); - new Date("").toJSON(); +Mocha.describe("Belt.Array.getIndexBy", () => { + Mocha.test("Belt.Array.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.describe("Date.toUTCString", () => { - Mocha.test("Date.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("Belt.List.mapReverse2", () => { + Mocha.test("Belt.List.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.describe("Date.toISOString", () => { - Mocha.test("Date.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.describe("Belt.List.cmpByLength", () => { + Mocha.test("Belt.List.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.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleTimeString("en-US", { - timeStyle: "long" - })); - console.log(new Date().toLocaleTimeString("de", { - hour: "2-digit", - minute: "2-digit" - })); +Mocha.describe("Belt.List.removeAssoc", () => { + Mocha.test("Belt.List.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.describe("Date.toLocaleTimeStringWithLocale", () => { - Mocha.test("Date.toLocaleTimeStringWithLocale", () => { - console.log(new Date().toLocaleTimeString("en-US")); +Mocha.describe("Belt.Set.minUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); }); }); -Mocha.describe("Date.toLocaleTimeString", () => { - Mocha.test("Date.toLocaleTimeString", () => { - console.log(new Date().toLocaleTimeString()); - }); -}); - -Mocha.describe("Date.toLocaleStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("Date.toLocaleStringWithLocale", () => { - Mocha.test("Date.toLocaleStringWithLocale", () => { - console.log(new Date().toLocaleString("en-US")); +Mocha.describe("Belt.Set.maxUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); }); }); -Mocha.describe("Date.toLocaleString", () => { - Mocha.test("Date.toLocaleString", () => { - console.log(new Date().toLocaleString()); +Mocha.describe("Belt.MutableSet.union", () => { + Mocha.test("Belt.MutableSet.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("Date.toLocaleDateStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("Belt.MutableSet.every", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.toLocaleDateStringWithLocale", () => { - Mocha.test("Date.toLocaleDateStringWithLocale", () => { - console.log(new Date().toLocaleDateString("en-US")); +Mocha.describe("Belt.MutableSet.split", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.toLocaleDateString", () => { - Mocha.test("Date.toLocaleDateString", () => { - console.log(new Date().toLocaleDateString()); +Mocha.describe("Belt.HashMap.logStats", () => { + Mocha.test("Belt.HashMap.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.describe("Date.toTimeString", () => { - Mocha.test("Date.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.describe("Belt.Float.fromString", () => { + Mocha.test("Belt.Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); }); }); -Mocha.describe("Date.toString", () => { - Mocha.test("Date.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.describe("Belt.Set.Dict.isEmpty", () => { + Mocha.test("Belt.Set.Dict.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.describe("Date.toDateString", () => { - Mocha.test("Date.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.describe("Belt.Set.Dict.forEach", () => { + Mocha.test("Belt.Set.Dict.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.describe("Date.setUTCMilliseconds", () => { - Mocha.test("Date.setUTCMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); +Mocha.describe("Belt.Set.Dict.toArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Date.setUTCSecondsMs", () => { - Mocha.test("Date.setUTCSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); +Mocha.describe("Belt.Set.Dict.minimum", () => { + Mocha.test("Belt.Set.Dict.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.describe("Date.setUTCSeconds", () => { - Mocha.test("Date.setUTCSeconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); +Mocha.describe("Belt.Set.Dict.maximum", () => { + Mocha.test("Belt.Set.Dict.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.describe("Date.setUTCMinutesSMs", () => { - Mocha.test("Date.setUTCMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); +Mocha.describe("Belt_Float.fromString", () => { + Mocha.test("Belt_Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); }); }); -Mocha.describe("Date.setUTCMinutesS", () => { - Mocha.test("Date.setUTCMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); +Mocha.describe("Belt_Array.concatMany", () => { + Mocha.test("Belt_Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Date.setUTCMinutes", () => { - Mocha.test("Date.setUTCMinutes", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); - }); -}); - -Mocha.describe("Date.setUTCHoursMSMs", () => { - Mocha.test("Date.setUTCHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); +Mocha.describe("Belt_Array.sliceToEnd", () => { + Mocha.test("Belt_Array.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.describe("Date.setUTCHoursMS", () => { - Mocha.test("Date.setUTCHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); +Mocha.describe("Belt_Array.getIndexBy", () => { + Mocha.test("Belt_Array.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.describe("Date.setUTCHoursM", () => { - Mocha.test("Date.setUTCHoursM", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); +Mocha.describe("Belt_HashMap.logStats", () => { + Mocha.test("Belt_HashMap.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.describe("Date.setUTCHours", () => { - Mocha.test("Date.setUTCHours", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0); - }); -}); +Mocha.describe("AsyncIterator.forEach", () => { + Mocha.test("AsyncIterator.forEach", () => { + let asyncIterator = ((() => { + var map1 = new Map(); -Mocha.describe("Date.setUTCDate", () => { - Mocha.test("Date.setUTCDate", () => { - new Date("2023-02-20T16:40:00.00").setUTCDate(1); - }); -}); + map1.set('first', '1'); + map1.set('second', '2'); -Mocha.describe("Date.setUTCMonth", () => { - Mocha.test("Date.setUTCMonth", () => { - new Date("2023-02-20T16:40:00.00").setUTCMonth(0); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + let main = async () => await $$AsyncIterator.forEach(asyncIterator, v => { + if (v !== undefined && v[0] === "second") { + return Pervasives.assertEqual(v[1], "2"); + } + + }); + main(); }); }); -Mocha.describe("Date.setUTCFullYearMD", () => { - Mocha.test("Date.setUTCFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); +Mocha.describe("Array.fromInitializer", () => { + Mocha.test("Array.fromInitializer", () => { + Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ + 3, + 4, + 5 + ]); + Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); }); }); -Mocha.describe("Date.setUTCFullYearM", () => { - Mocha.test("Date.setUTCFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); +Mocha.describe("Array.filterWithIndex", () => { + Mocha.test("Array.filterWithIndex", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].filter((num, index) => { + if (index === 0) { + return true; + } else { + return num === 2; + } + }), [ + 1, + 2 + ]); }); }); -Mocha.describe("Date.setUTCFullYear", () => { - Mocha.test("Date.setUTCFullYear", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); +Mocha.describe("Array.reduceWithIndex", () => { + Mocha.test("Array.reduceWithIndex", () => { + Pervasives.assertEqual($$Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$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 + } + } + }); + Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); }); }); -Mocha.describe("Date.getUTCDay", () => { - Mocha.test("Date.getUTCDay", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); +Mocha.describe("Type.Classify.classify", () => { + Mocha.test("Type.Classify.classify", () => { + let match = 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("Date.getUTCMilliseconds", () => { - Mocha.test("Date.getUTCMilliseconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); +Mocha.describe("String.lastIndexOfFrom", () => { + Mocha.test("String.lastIndexOfFrom", () => { + "bookseller".lastIndexOf("ok", 6) === 2; + "beekeeper".lastIndexOf("ee", 8) === 4; + "beekeeper".lastIndexOf("ee", 3) === 1; + "abcdefg".lastIndexOf("xyz", 4) === -1; }); }); -Mocha.describe("Date.getUTCSeconds", () => { - Mocha.test("Date.getUTCSeconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); +Mocha.describe("Pervasives.setInterval", () => { + Mocha.test("Pervasives.setInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms."); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500); }); }); -Mocha.describe("Date.getUTCMinutes", () => { - Mocha.test("Date.getUTCMinutes", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); +Mocha.describe("Pervasives.assertEqual", () => { + Mocha.test("Pervasives.assertEqual", () => { + Pervasives.assertEqual(List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }), { + hd: 2, + tl: /* [] */0 + }); }); }); -Mocha.describe("Date.getUTCHours", () => { - Mocha.test("Date.getUTCHours", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); - }); +Mocha.describe("Math.Constants.sqrt1_2", () => { + Mocha.test("Math.Constants.sqrt1_2", () => {}); }); -Mocha.describe("Date.getUTCDate", () => { - Mocha.test("Date.getUTCDate", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); +Mocha.describe("JSON.Classify.classify", () => { + Mocha.test("JSON.Classify.classify", () => { + $$JSON.Classify.classify("hello world"); + $$JSON.Classify.classify(42); }); }); -Mocha.describe("Date.getUTCMonth", () => { - Mocha.test("Date.getUTCMonth", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); +Mocha.describe("Int.Constants.minValue", () => { + Mocha.test("Int.Constants.minValue", () => { + console.log(Int.Constants.minValue); }); }); -Mocha.describe("Date.getUTCFullYear", () => { - Mocha.test("Date.getUTCFullYear", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); +Mocha.describe("Int.Constants.maxValue", () => { + Mocha.test("Int.Constants.maxValue", () => { + console.log(Int.Constants.maxValue); }); }); -Mocha.describe("Date.setMilliseconds", () => { - Mocha.test("Date.setMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setMilliseconds(0); +Mocha.describe("Date.getTimezoneOffset", () => { + Mocha.test("Date.getTimezoneOffset", () => { + new Date("2023-01-01").getTimezoneOffset(); + new Date("2023-06-01").getTimezoneOffset(); }); }); -Mocha.describe("Date.setSecondsMs", () => { - Mocha.test("Date.setSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); +Mocha.describe("Date.UTC.makeWithYMDHM", () => { + Mocha.test("Date.UTC.makeWithYMDHM", () => { + Date.UTC(2023, 1, 20, 16, 40); + Date.UTC(2023, 1, 20, 16, 60); + Date.UTC(2023, 1, 20, 16, -1); }); }); -Mocha.describe("Date.setSeconds", () => { - Mocha.test("Date.setSeconds", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0); - }); -}); - -Mocha.describe("Date.setMinutesSMs", () => { - Mocha.test("Date.setMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); - }); -}); - -Mocha.describe("Date.setMinutesS", () => { - Mocha.test("Date.setMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); +Mocha.describe("Belt_SetDict.fromArray", () => { + Mocha.test("Belt_SetDict.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.describe("Date.setMinutes", () => { - Mocha.test("Date.setMinutes", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0); +Mocha.describe("Belt_SetDict.mergeMany", () => { + Mocha.test("Belt_SetDict.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.describe("Date.setHoursMSMs", () => { - Mocha.test("Date.setHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); +Mocha.describe("Belt_SetDict.intersect", () => { + Mocha.test("Belt_SetDict.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.describe("Date.setHoursMS", () => { - Mocha.test("Date.setHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); +Mocha.describe("Belt_SetDict.partition", () => { + Mocha.test("Belt_SetDict.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.describe("Date.setHoursM", () => { - Mocha.test("Date.setHoursM", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0); +Mocha.describe("Belt_MutableSet.remove", () => { + Mocha.test("Belt_MutableSet.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.describe("Date.setHours", () => { - Mocha.test("Date.setHours", () => { - new Date("2023-02-20T16:40:00.00").setHours(0); +Mocha.describe("Belt_MutableSet.subset", () => { + Mocha.test("Belt_MutableSet.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.describe("Date.setDate", () => { - Mocha.test("Date.setDate", () => { - new Date("2023-02-20T16:40:00.00").setDate(1); +Mocha.describe("Belt_MutableSet.reduce", () => { + Mocha.test("Belt_MutableSet.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.describe("Date.setMonth", () => { - Mocha.test("Date.setMonth", () => { - new Date("2023-02-20T16:40:00.00").setMonth(0); +Mocha.describe("Belt_MutableSet.toList", () => { + Mocha.test("Belt_MutableSet.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.describe("Date.setFullYearMD", () => { - Mocha.test("Date.setFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); +Mocha.describe("Belt_Map.valuesToArray", () => { + Mocha.test("Belt_Map.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("Date.setFullYearM", () => { - Mocha.test("Date.setFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); +Mocha.describe("Belt_List.mapWithIndex", () => { + Mocha.test("Belt_List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); }); }); -Mocha.describe("Date.setFullYear", () => { - Mocha.test("Date.setFullYear", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024); +Mocha.describe("Belt.List.mapWithIndex", () => { + Mocha.test("Belt.List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); }); }); -Mocha.describe("Date.getDay", () => { - Mocha.test("Date.getDay", () => { - new Date("2023-02-20T16:40:00.00").getDay(); +Mocha.describe("Belt.Map.valuesToArray", () => { + Mocha.test("Belt.Map.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("Date.getMilliseconds", () => { - Mocha.test("Date.getMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").getMilliseconds(); +Mocha.describe("Belt.MutableSet.remove", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.getSeconds", () => { - Mocha.test("Date.getSeconds", () => { - new Date("2023-02-20T16:40:00.00").getSeconds(); +Mocha.describe("Belt.MutableSet.subset", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.getMinutes", () => { - Mocha.test("Date.getMinutes", () => { - new Date("2023-02-20T16:40:00.00").getMinutes(); +Mocha.describe("Belt.MutableSet.reduce", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.getHours", () => { - Mocha.test("Date.getHours", () => { - new Date("2023-02-20T16:40:00.00").getHours(); +Mocha.describe("Belt.MutableSet.toList", () => { + Mocha.test("Belt.MutableSet.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.describe("Date.getDate", () => { - Mocha.test("Date.getDate", () => { - new Date("2023-02-20T16:40:00.00").getDate(); +Mocha.describe("Belt.HashMap.fromArray", () => { + Mocha.test("Belt.HashMap.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.describe("Date.getMonth", () => { - Mocha.test("Date.getMonth", () => { - new Date("2023-01-01").getMonth(); +Mocha.describe("Belt.HashMap.mergeMany", () => { + Mocha.test("Belt.HashMap.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.describe("Date.getFullYear", () => { - Mocha.test("Date.getFullYear", () => { - new Date("2023-02-20").getFullYear(); +Mocha.describe("Belt_HashMap.fromArray", () => { + Mocha.test("Belt_HashMap.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.describe("Date.getTimezoneOffset", () => { - Mocha.test("Date.getTimezoneOffset", () => { - new Date("2023-01-01").getTimezoneOffset(); - new Date("2023-06-01").getTimezoneOffset(); +Mocha.describe("Belt_HashMap.mergeMany", () => { + Mocha.test("Belt_HashMap.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.describe("Date.getTime", () => { - Mocha.test("Date.getTime", () => { - new Date("2023-02-20").getTime(); +Mocha.describe("Array.forEachWithIndex", () => { + Mocha.test("Array.forEachWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach((item, index) => { + console.log("At item " + index.toString() + ": " + item); + }); }); }); -Mocha.describe("Date.makeWithYMDHMSM", () => { - Mocha.test("Date.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.describe("Array.flatMapWithIndex", () => { + Mocha.test("Array.flatMapWithIndex", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.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.describe("Date.makeWithYMDHMS", () => { - Mocha.test("Date.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.describe("String.fromCharCodeMany", () => { + Mocha.test("String.fromCharCodeMany", () => { + String.fromCharCode(189, 43, 190, 61) === "½+¾="; + String.fromCharCode(65, 66, 67) === "ABC"; }); }); -Mocha.describe("Date.makeWithYMDHM", () => { - Mocha.test("Date.makeWithYMDHM", () => { - new Date(2023, 1, 20, 16, 40); - new Date(2023, 1, 20, 16, 60); - new Date(2023, 1, 20, 16, -1); +Mocha.describe("String.replaceAllRegExp", () => { + Mocha.test("String.replaceAllRegExp", () => { + "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; }); }); -Mocha.describe("Date.makeWithYMDH", () => { - Mocha.test("Date.makeWithYMDH", () => { - new Date(2023, 1, 20, 16); - new Date(2023, 1, 20, 24); - new Date(2023, 1, 20, -1); +Mocha.describe("RegExp.Result.fullMatch", () => { + Mocha.test("RegExp.Result.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.describe("Date.makeWithYMD", () => { - Mocha.test("Date.makeWithYMD", () => { - new Date(2023, 1, 20); - new Date(2023, 1, -1); - new Date(2023, 1, 29); +Mocha.describe("Pervasives.clearTimeout", () => { + Mocha.test("Pervasives.clearTimeout", () => { + let timeoutId = setTimeout(() => { + console.log("This prints in 2 seconds."); + }, 2000); + clearTimeout(timeoutId); }); }); -Mocha.describe("Date.makeWithYM", () => { - Mocha.test("Date.makeWithYM", () => { - new Date(2023, 0); - new Date(2023, 11); - new Date(2023, 12); - new Date(2023, -1); +Mocha.describe("Float.parseIntWithRadix", () => { + Mocha.test("Float.parseIntWithRadix", () => { + parseInt("10.0", 2); + parseInt("15 * 3", 10); + parseInt("12", 13); + isNaN(parseInt("17", 40)); }); }); -Mocha.describe("Date.fromTime", () => { - Mocha.test("Date.fromTime", () => { - new Date(0.0); - new Date(-86400000.0); - new Date(86400000.0); +Mocha.describe("Float.toStringWithRadix", () => { + Mocha.test("Float.toStringWithRadix", () => { + (6.0).toString(2); + (3735928559.0).toString(16); + (123456.0).toString(36); }); }); -Mocha.describe("Date.fromString", () => { - Mocha.test("Date.fromString", () => { - new Date("2023"); - new Date("2023-02-20"); - new Date("2023-02-20T16:40:00.00Z"); - new Date(""); - new Date("").getTime(); - }); +Mocha.describe("Float.Constants.epsilon", () => { + Mocha.test("Float.Constants.epsilon", () => {}); }); -Mocha.describe("Date.make", () => { - Mocha.test("Date.make", () => { - new Date(); +Mocha.describe("Date.getUTCMilliseconds", () => { + Mocha.test("Date.getUTCMilliseconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); }); }); -Mocha.describe("Error.panic", () => { - Mocha.test("Error.panic", () => { - try { - $$Error.panic("Uh oh. This was unexpected!"); - } catch (raw_obj) { - let obj = Primitive_exceptions.internalToException(raw_obj); - if (obj.RE_EXN_ID === 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", - 12931, - 15 - ], - Error: new Error() - }; - } - - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12932, - 12 - ], - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12934, - 7 - ], - Error: new Error() - }; - } - } +Mocha.describe("Date.setUTCMilliseconds", () => { + Mocha.test("Date.setUTCMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); }); }); -Mocha.describe("Error.raise", () => { - Mocha.test("Error.raise", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); +Mocha.describe("Date.toLocaleDateString", () => { + Mocha.test("Date.toLocaleDateString", () => { + console.log(new Date().toLocaleDateString()); }); }); -Mocha.describe("Error.make", () => { - Mocha.test("Error.make", () => { - let error = new Error("Some message here"); - console.log(error.message); - console.log(error.name); +Mocha.describe("Date.toLocaleTimeString", () => { + Mocha.test("Date.toLocaleTimeString", () => { + console.log(new Date().toLocaleTimeString()); }); }); -Mocha.describe("Error.name", () => { - Mocha.test("Error.name", () => { - let error = new SyntaxError("Some message here"); - console.log(error.name); +Mocha.describe("Date.UTC.makeWithYMDHMS", () => { + Mocha.test("Date.UTC.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.describe("Error.message", () => { - Mocha.test("Error.message", () => { - let error = new SyntaxError("Some message here"); - console.log(error.message); +Mocha.describe("Belt_Set.Dict.fromArray", () => { + Mocha.test("Belt_Set.Dict.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.describe("Error.stack", () => { - Mocha.test("Error.stack", () => { - let error = new Error("error"); - console.log(error.stack); +Mocha.describe("Belt_Set.Dict.mergeMany", () => { + Mocha.test("Belt_Set.Dict.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.describe("Error.toException", () => { - Mocha.test("Error.toException", () => { - new Error("Something went wrong."); +Mocha.describe("Belt_Set.Dict.intersect", () => { + Mocha.test("Belt_Set.Dict.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.describe("Float.Constants.maxValue", () => { - Mocha.test("Float.Constants.maxValue", () => {}); -}); - -Mocha.describe("Float.Constants.minValue", () => { - Mocha.test("Float.Constants.minValue", () => {}); -}); - -Mocha.describe("Float.Constants.negativeInfinity", () => { - Mocha.test("Float.Constants.negativeInfinity", () => {}); +Mocha.describe("Belt_Set.Dict.partition", () => { + Mocha.test("Belt_Set.Dict.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.describe("Float.Constants.positiveInfinity", () => { - Mocha.test("Float.Constants.positiveInfinity", () => {}); +Mocha.describe("Belt_SetDict.removeMany", () => { + Mocha.test("Belt_SetDict.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.describe("Float.Constants.epsilon", () => { - Mocha.test("Float.Constants.epsilon", () => {}); +Mocha.describe("Belt_MutableSet.isEmpty", () => { + Mocha.test("Belt_MutableSet.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.describe("Float.Constants.nan", () => { - Mocha.test("Float.Constants.nan", () => {}); -}); - -Mocha.describe("Float.clamp", () => { - Mocha.test("Float.clamp", () => { - Float.clamp(undefined, undefined, 4.2) === 4.2; - Float.clamp(4.3, undefined, 4.2) === 4.3; - Float.clamp(undefined, 4.1, 4.2) === 4.1; - Float.clamp(4.3, 4.1, 4.2) === 4.3; - }); -}); - -Mocha.describe("Float.mod", () => { - Mocha.test("Float.mod", () => {}); -}); - -Mocha.describe("Float.fromInt", () => { - Mocha.test("Float.fromInt", () => {}); -}); - -Mocha.describe("Float.toInt", () => { - Mocha.test("Float.toInt", () => {}); -}); - -Mocha.describe("Float.fromString", () => { - Mocha.test("Float.fromString", () => { - Primitive_object.equal(Float.fromString("0"), 0.0); - Float.fromString("NaN") === undefined; - Primitive_object.equal(Float.fromString("6"), 6.0); +Mocha.describe("Belt_MutableSet.forEach", () => { + Mocha.test("Belt_MutableSet.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.describe("Float.toLocaleString", () => { - Mocha.test("Float.toLocaleString", () => { - (1000.0).toLocaleString(); - (1000.0).toLocaleString(); +Mocha.describe("Belt_MutableSet.toArray", () => { + Mocha.test("Belt_MutableSet.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.describe("Float.toStringWithRadix", () => { - Mocha.test("Float.toStringWithRadix", () => { - (6.0).toString(2); - (3735928559.0).toString(16); - (123456.0).toString(36); +Mocha.describe("Belt_MutableSet.minimum", () => { + Mocha.test("Belt_MutableSet.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.describe("Float.toString", () => { - Mocha.test("Float.toString", () => { - (1000.0).toString(); - (-1000.0).toString(); +Mocha.describe("Belt_MutableSet.maximum", () => { + Mocha.test("Belt_MutableSet.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.describe("Float.toPrecisionWithPrecision", () => { - Mocha.test("Float.toPrecisionWithPrecision", () => { - (100.0).toPrecision(2); - (1.0).toPrecision(1); +Mocha.describe("Belt_MapInt.findFirstBy", () => { + Mocha.test("Belt_MapInt.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("Float.toPrecision", () => { - Mocha.test("Float.toPrecision", () => { - (100.0).toPrecision(); - (1.0).toPrecision(); - (100.0).toPrecision(2); - (1.0).toPrecision(1); +Mocha.describe("Belt_List.reverseConcat", () => { + Mocha.test("Belt_List.reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); }); }); -Mocha.describe("Float.toFixedWithPrecision", () => { - Mocha.test("Float.toFixedWithPrecision", () => { - (300.0).toFixed(4); - (300.0).toFixed(1); +Mocha.describe("Belt_List.reduceReverse", () => { + Mocha.test("Belt_List.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.describe("Float.toFixed", () => { - Mocha.test("Float.toFixed", () => { - (123456.0).toFixed(); - (10.0).toFixed(); - (300.0).toFixed(4); - (300.0).toFixed(1); +Mocha.describe("Belt_List.keepWithIndex", () => { + Mocha.test("Belt_List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("Float.toExponentialWithPrecision", () => { - Mocha.test("Float.toExponentialWithPrecision", () => { - (77.0).toExponential(2); - (5678.0).toExponential(2); +Mocha.describe("Belt.Array.mapWithIndex", () => { + Mocha.test("Belt.Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Float.toExponential", () => { - Mocha.test("Float.toExponential", () => { - (1000.0).toExponential(); - (-1000.0).toExponential(); - (77.0).toExponential(2); - (5678.0).toExponential(2); +Mocha.describe("Belt.List.reverseConcat", () => { + Mocha.test("Belt.List.reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); }); }); -Mocha.describe("Float.parseIntWithRadix", () => { - Mocha.test("Float.parseIntWithRadix", () => { - parseInt("10.0", 2); - parseInt("15 * 3", 10); - parseInt("12", 13); - isNaN(parseInt("17", 40)); +Mocha.describe("Belt.List.reduceReverse", () => { + Mocha.test("Belt.List.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.describe("Float.parseInt", () => { - Mocha.test("Float.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.describe("Belt.List.keepWithIndex", () => { + Mocha.test("Belt.List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("Float.parseFloat", () => { - Mocha.test("Float.parseFloat", () => { - parseFloat("1.0"); - parseFloat(" 3.14 "); - parseFloat("3.0"); - parseFloat("3.14some non-digit characters"); - isNaN(parseFloat("error")); +Mocha.describe("Belt.MutableSet.isEmpty", () => { + Mocha.test("Belt.MutableSet.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.describe("Float.isFinite", () => { - Mocha.test("Float.isFinite", () => { - isFinite(1.0); - isFinite(NaN); - isFinite(Number.POSITIVE_INFINITY); +Mocha.describe("Belt.MutableSet.forEach", () => { + Mocha.test("Belt.MutableSet.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.describe("Float.isNaN", () => { - Mocha.test("Float.isNaN", () => { - isNaN(3.0); - isNaN(NaN); +Mocha.describe("Belt.MutableSet.toArray", () => { + Mocha.test("Belt.MutableSet.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.describe("Int.Bitwise.asr", () => { - Mocha.test("Int.Bitwise.asr", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsr", () => { - Mocha.test("Int.Bitwise.lsr", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsl", () => { - Mocha.test("Int.Bitwise.lsl", () => {}); -}); - -Mocha.describe("Int.Bitwise.lnot", () => { - Mocha.test("Int.Bitwise.lnot", () => { - Int.Bitwise.lnot(2) === -3; +Mocha.describe("Belt.MutableSet.minimum", () => { + Mocha.test("Belt.MutableSet.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.describe("Int.Bitwise.lxor", () => { - Mocha.test("Int.Bitwise.lxor", () => {}); -}); - -Mocha.describe("Int.Bitwise.lor", () => { - Mocha.test("Int.Bitwise.lor", () => {}); -}); - -Mocha.describe("Int.Bitwise.land", () => { - Mocha.test("Int.Bitwise.land", () => {}); -}); - -Mocha.describe("Int.Constants.maxValue", () => { - Mocha.test("Int.Constants.maxValue", () => { - console.log(Int.Constants.maxValue); +Mocha.describe("Belt.MutableSet.maximum", () => { + Mocha.test("Belt.MutableSet.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.describe("Int.Constants.minValue", () => { - Mocha.test("Int.Constants.minValue", () => { - console.log(Int.Constants.minValue); +Mocha.describe("Belt.Set.Dict.fromArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Int.clamp", () => { - Mocha.test("Int.clamp", () => { - Int.clamp(undefined, undefined, 42) === 42; - Int.clamp(50, undefined, 42) === 50; - Int.clamp(undefined, 40, 42) === 40; - Int.clamp(50, 40, 42) === 50; +Mocha.describe("Belt.Set.Dict.mergeMany", () => { + Mocha.test("Belt.Set.Dict.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.describe("Int.rangeWithOptions", () => { - Mocha.test("Int.rangeWithOptions", () => { - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2 - }), [ +Mocha.describe("Belt.Set.Dict.intersect", () => { + Mocha.test("Belt.Set.Dict.intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, + 2, 3, - 5 - ]); - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2, - inclusive: true - }), [ + 5, + 6 + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 5, + 2, 3, + 1, 5, - 7 - ]); - Int.rangeWithOptions(3, 6, { - step: -2 - }); + 4 + ], IntCmp.cmp); + let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); + Belt_SetDict.toArray(intersect); }); }); -Mocha.describe("Int.range", () => { - Mocha.test("Int.range", () => { - Primitive_object.equal(Int.range(3, 6, undefined), [ +Mocha.describe("Belt.Set.Dict.partition", () => { + Mocha.test("Belt.Set.Dict.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 - ]); - Primitive_object.equal(Int.range(-3, -1, undefined), [ - -3, - -2 - ]); - Primitive_object.equal(Int.range(3, 1, undefined), [ - 3, - 2 - ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2 - }), [ + ], IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); + }); +}); + +Mocha.describe("Belt_Array.mapWithIndex", () => { + Mocha.test("Belt_Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, 3, 5 ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Int.range(3, 6, { - step: -2 - }); }); }); -Mocha.describe("Int.mod", () => { - Mocha.test("Int.mod", () => {}); -}); - -Mocha.describe("Int.fromString", () => { - Mocha.test("Int.fromString", () => { - Primitive_object.equal(Int.fromString("0", undefined), 0); - Int.fromString("NaN", undefined) === undefined; - Int.fromString("6", 2) === undefined; +Mocha.describe("String.fromCodePointMany", () => { + Mocha.test("String.fromCodePointMany", () => { + String.fromCodePoint(54620, 44544, 128570) === "한글😺"; }); }); -Mocha.describe("Int.fromFloat", () => { - Mocha.test("Int.fromFloat", () => {}); -}); - -Mocha.describe("Int.toFloat", () => { - Mocha.test("Int.toFloat", () => {}); -}); - -Mocha.describe("Int.toLocaleString", () => { - Mocha.test("Int.toLocaleString", () => { - (1000).toLocaleString(); - (1000).toLocaleString(); +Mocha.describe("Pervasives.clearInterval", () => { + Mocha.test("Pervasives.clearInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints in 100 ms"); + }, 100); + setTimeout(() => { + clearInterval(intervalId); + }, 500); }); }); -Mocha.describe("Int.toStringWithRadix", () => { - Mocha.test("Int.toStringWithRadix", () => { - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); +Mocha.describe("Object.preventExtensions", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 14206, + 7 + ], + Error: new Error() + }; + } + + } }); }); -Mocha.describe("Int.toString", () => { - Mocha.test("Int.toString", () => { - (1000).toString(); - (-1000).toString(); - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); +Mocha.describe("JSON.parseExnWithReviver", () => { + Mocha.test("JSON.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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn; + } + } }); }); -Mocha.describe("Int.toPrecisionWithPrecision", () => { - Mocha.test("Int.toPrecisionWithPrecision", () => { - (100).toPrecision(2); - (1).toPrecision(2); +Mocha.describe("JSON.stringifyWithIndent", () => { + Mocha.test("JSON.stringifyWithIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, null, 2); }); }); -Mocha.describe("Int.toPrecision", () => { - Mocha.test("Int.toPrecision", () => { - (100).toPrecision(); - (1).toPrecision(); - (100).toPrecision(2); - (1).toPrecision(2); +Mocha.describe("JSON.stringifyWithFilter", () => { + Mocha.test("JSON.stringifyWithFilter", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ]); }); }); @@ -17996,1727 +17556,650 @@ Mocha.describe("Int.toFixedWithPrecision", () => { }); }); -Mocha.describe("Int.toFixed", () => { - Mocha.test("Int.toFixed", () => { - (123456).toFixed(); - (10).toFixed(); - (300).toFixed(4); - (300).toFixed(1); - }); +Mocha.describe("Float.Constants.minValue", () => { + Mocha.test("Float.Constants.minValue", () => {}); }); -Mocha.describe("Int.toExponentialWithPrecision", () => { - Mocha.test("Int.toExponentialWithPrecision", () => { - (77).toExponential(2); - (5678).toExponential(2); - }); +Mocha.describe("Float.Constants.maxValue", () => { + Mocha.test("Float.Constants.maxValue", () => {}); }); -Mocha.describe("Int.toExponential", () => { - Mocha.test("Int.toExponential", () => { - (1000).toExponential(); - (-1000).toExponential(); - (77).toExponential(2); - (5678).toExponential(2); +Mocha.describe("Date.UTC.makeWithYMDHMSM", () => { + Mocha.test("Date.UTC.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("Iterator.forEach", () => { - Mocha.test("Iterator.forEach", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - $$Iterator.forEach(iterator, v => { - if (v === undefined) { - return Pervasives.assertEqual(Option.isNone(v), true); - } - switch (v) { - case "a" : - case "b" : - case "c" : - return; - default: - return Pervasives.assertEqual(Option.isNone(v), true); - } - }); +Mocha.describe("Belt_internalMapInt.A.eq", () => { + Mocha.test("Belt_internalMapInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Iterator.toArrayWithMapper", () => { - Mocha.test("Iterator.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("Belt_internalSetInt.A.eq", () => { + Mocha.test("Belt_internalSetInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Iterator.toArray", () => { - Mocha.test("Iterator.toArray", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - let mapKeysAsArray = Array.from(map.keys()); - console.log(mapKeysAsArray); +Mocha.describe("Belt_Set.Dict.removeMany", () => { + Mocha.test("Belt_Set.Dict.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.describe("Iterator.next", () => { - Mocha.test("Iterator.next", () => { - let iterator = ((() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(iterator.next().done, false); - Pervasives.assertEqual(iterator.next().done, true); +Mocha.describe("Belt_MapDict.findFirstBy", () => { + Mocha.test("Belt_MapDict.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("JSON.Decode.array", () => { - Mocha.test("JSON.Decode.array", () => { - $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); - $$JSON.Decode.array(JSON.parse("\"hello world\"")); +Mocha.describe("Belt_Map.Int.findFirstBy", () => { + Mocha.test("Belt_Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("JSON.Decode.object", () => { - Mocha.test("JSON.Decode.object", () => { - $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); - $$JSON.Decode.object(JSON.parse("\"hello world\"")); +Mocha.describe("Belt_List.reduceReverse2", () => { + Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("JSON.Decode.float", () => { - Mocha.test("JSON.Decode.float", () => { - $$JSON.Decode.float(JSON.parse("42.0")); - $$JSON.Decode.float(JSON.parse("\"hello world\"")); +Mocha.describe("Belt.Array.keepWithIndex", () => { + Mocha.test("Belt.Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("JSON.Decode.string", () => { - Mocha.test("JSON.Decode.string", () => { - $$JSON.Decode.string(JSON.parse("\"hello world\"")); - $$JSON.Decode.string(JSON.parse("42")); +Mocha.describe("Belt.Array.reduceReverse", () => { + Mocha.test("Belt.Array.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("JSON.Decode.null", () => { - Mocha.test("JSON.Decode.null", () => { - $$JSON.Decode.$$null(JSON.parse("null")); - $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); +Mocha.describe("Belt.List.reduceReverse2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("JSON.Decode.bool", () => { - Mocha.test("JSON.Decode.bool", () => { - $$JSON.Decode.bool(JSON.parse("true")); - $$JSON.Decode.bool(JSON.parse("\"hello world\"")); +Mocha.describe("Belt.HashMap.keysToArray", () => { + Mocha.test("Belt.HashMap.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.describe("JSON.Encode.array", () => { - Mocha.test("JSON.Encode.array", () => {}); +Mocha.describe("Belt.Set.Dict.removeMany", () => { + Mocha.test("Belt.Set.Dict.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.describe("JSON.Encode.object", () => { - Mocha.test("JSON.Encode.object", () => { - Object.fromEntries([ +Mocha.describe("Belt.Map.Int.findFirstBy", () => { + Mocha.test("Belt.Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ [ - "foo", - "bar" + 1, + "one" ], [ - "hello", - "world" + 2, + "two" + ], + [ + 3, + "three" ] ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("JSON.Encode.float", () => { - Mocha.test("JSON.Encode.float", () => {}); +Mocha.describe("Belt_Array.keepWithIndex", () => { + Mocha.test("Belt_Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); + }); }); -Mocha.describe("JSON.Encode.int", () => { - Mocha.test("JSON.Encode.int", () => {}); -}); - -Mocha.describe("JSON.Encode.string", () => { - Mocha.test("JSON.Encode.string", () => {}); +Mocha.describe("Belt_Array.reduceReverse", () => { + Mocha.test("Belt_Array.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; + }); }); -Mocha.describe("JSON.Encode.null", () => { - Mocha.test("JSON.Encode.null", () => {}); +Mocha.describe("Belt_HashMap.keysToArray", () => { + Mocha.test("Belt_HashMap.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.describe("JSON.Encode.bool", () => { - Mocha.test("JSON.Encode.bool", () => {}); +Mocha.describe("Array.findIndexWithIndex", () => { + Mocha.test("Array.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; + } + }); + Pervasives.assertEqual(isReScriptFirst, 0); + Pervasives.assertEqual(isTypeScriptFirst, -1); + }); }); -Mocha.describe("JSON.Classify.classify", () => { - Mocha.test("JSON.Classify.classify", () => { - $$JSON.Classify.classify("hello world"); - $$JSON.Classify.classify(42); +Mocha.describe("Belt_internalMapInt.A.get", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("JSON.stringifyAnyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], +Mocha.describe("Belt_internalMapInt.A.zip", () => { + Mocha.test("Belt_internalMapInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ [ - "hello", - "world" + 1, + 3 ], [ - "someNumber", - 42 + 2, + 4 ] ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 13810, - 7 - ], - Error: new Error() - }; - } - }); }); -Mocha.describe("JSON.stringifyAnyWithFilter", () => { - Mocha.test("JSON.stringifyAnyWithFilter", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] +Mocha.describe("Belt_internalMapInt.A.map", () => { + Mocha.test("Belt_internalMapInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 ]); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 13834, - 7 - ], - Error: new Error() - }; - } - }); }); -Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], +Mocha.describe("Belt_internalMapInt.A.cmp", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalSetInt.A.get", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.zip", () => { + Mocha.test("Belt_internalSetInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ [ - "hello", - "world" + 1, + 3 ], [ - "someNumber", - 42 + 2, + 4 ] ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 13868, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithReplacer", () => { - Mocha.test("JSON.stringifyAnyWithReplacer", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 13902, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithIndent", () => { - Mocha.test("JSON.stringifyAnyWithIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.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", - 13931, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAny", () => { - Mocha.test("JSON.stringifyAny", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 13986, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyWithFilterAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ], 2); }); }); -Mocha.describe("JSON.stringifyWithFilter", () => { - Mocha.test("JSON.stringifyWithFilter", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ]); - }); -}); - -Mocha.describe("JSON.stringifyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] +Mocha.describe("Belt_internalSetInt.A.map", () => { + Mocha.test("Belt_internalSetInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer, 2); }); }); -Mocha.describe("JSON.stringifyWithReplacer", () => { - Mocha.test("JSON.stringifyWithReplacer", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); -}); - -Mocha.describe("JSON.stringifyWithIndent", () => { - Mocha.test("JSON.stringifyWithIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, null, 2); - }); -}); - -Mocha.describe("JSON.stringify", () => { - Mocha.test("JSON.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 = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); -}); - -Mocha.describe("JSON.parseExnWithReviver", () => { - Mocha.test("JSON.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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn; - } - } - }); -}); - -Mocha.describe("JSON.parseExn", () => { - Mocha.test("JSON.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 === 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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn$1; - } - } - }); -}); - -Mocha.describe("Map.entries", () => { - Mocha.test("Map.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.describe("Map.values", () => { - Mocha.test("Map.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("Map.keys", () => { - Mocha.test("Map.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.describe("Map.delete", () => { - Mocha.test("Map.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.describe("Map.set", () => { - Mocha.test("Map.set", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); -}); - -Mocha.describe("Map.has", () => { - Mocha.test("Map.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.describe("Map.get", () => { - Mocha.test("Map.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.describe("Map.forEachWithKey", () => { - Mocha.test("Map.forEachWithKey", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach((value, key) => { - console.log(value, key); - }); - }); -}); - -Mocha.describe("Map.forEach", () => { - Mocha.test("Map.forEach", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach(value => { - console.log(value); - }); - }); -}); - -Mocha.describe("Map.clear", () => { - Mocha.test("Map.clear", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.clear(); - }); -}); - -Mocha.describe("Map.size", () => { - Mocha.test("Map.size", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); -}); - -Mocha.describe("Map.fromIterator", () => { - Mocha.test("Map.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(new Map(iterator).size, 2); - }); -}); - -Mocha.describe("Map.fromArray", () => { - Mocha.test("Map.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.describe("Map.make", () => { - Mocha.test("Map.make", () => { - new Map(); - let map = new Map(); - map.set("lang", "ReScript"); - }); -}); - -Mocha.describe("List.sort", () => { - Mocha.test("List.sort", () => { - List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, Primitive_int.compare); - }); -}); - -Mocha.describe("List.setAssoc", () => { - Mocha.test("List.setAssoc", () => { - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); - }); -}); - -Mocha.describe("List.removeAssoc", () => { - Mocha.test("List.removeAssoc", () => { - List.removeAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - List.removeAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); - }); -}); - -Mocha.describe("List.hasAssoc", () => { - Mocha.test("List.hasAssoc", () => { - List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); - }); -}); - -Mocha.describe("List.getAssoc", () => { - Mocha.test("List.getAssoc", () => { - List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); - }); -}); - -Mocha.describe("List.unzip", () => { - Mocha.test("List.unzip", () => { - List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - 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.describe("List.partition", () => { - Mocha.test("List.partition", () => { - List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2); - }); -}); - -Mocha.describe("List.filterMap", () => { - Mocha.test("List.filterMap", () => { - let isEven = x => x % 2 === 0; - List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => { - if (isEven(x)) { - return x; - } - - }); - List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); -}); - -Mocha.describe("List.filterWithIndex", () => { - Mocha.test("List.filterWithIndex", () => { - List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("List.filter", () => { - Mocha.test("List.filter", () => { - let isEven = x => x % 2 === 0; - List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Option.isSome); - }); -}); - -Mocha.describe("List.find", () => { - Mocha.test("List.find", () => { - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); - }); -}); - -Mocha.describe("List.has", () => { - Mocha.test("List.has", () => { - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4, (a, b) => a === b); - List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); -}); - -Mocha.describe("List.equal", () => { - Mocha.test("List.equal", () => { - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - 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.describe("List.compare", () => { - Mocha.test("List.compare", () => { - List.compare({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - }, Primitive_int.compare); - List.compare({ - hd: 5, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - 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); - 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); - 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.describe("List.compareLength", () => { - Mocha.test("List.compareLength", () => { - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("List.some2", () => { - Mocha.test("List.some2", () => { - List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); -}); - -Mocha.describe("List.every2", () => { - Mocha.test("List.every2", () => { - List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); +Mocha.describe("Belt_internalSetInt.A.cmp", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("List.some", () => { - Mocha.test("List.some", () => { - let isAbove100 = value => value > 100; - List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - List.some({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isAbove100); +Mocha.describe("Belt_SetDict.minUndefined", () => { + Mocha.test("Belt_SetDict.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.describe("List.every", () => { - Mocha.test("List.every", () => { - let isBelow10 = value => value < 10; - List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); +Mocha.describe("Belt_SetDict.maxUndefined", () => { + Mocha.test("Belt_SetDict.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.describe("List.reduceReverse2", () => { - Mocha.test("List.reduceReverse2", () => { - List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Belt_MutableSet.fromArray", () => { + Mocha.test("Belt_MutableSet.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.describe("List.reduce2", () => { - Mocha.test("List.reduce2", () => { - List.reduce2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Belt_MutableSet.mergeMany", () => { + Mocha.test("Belt_MutableSet.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.describe("List.forEach2", () => { - Mocha.test("List.forEach2", () => { - 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.describe("Belt_MutableSet.intersect", () => { + Mocha.test("Belt_MutableSet.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.describe("List.mapReverse2", () => { - Mocha.test("List.mapReverse2", () => { - 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.describe("Belt_MutableSet.partition", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_Map.Dict.findFirstBy", () => { + Mocha.test("Belt_Map.Dict.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("List.reduceReverse", () => { - Mocha.test("List.reduceReverse", () => { - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduceReverse({ +Mocha.describe("Belt_List.reduceWithIndex", () => { + Mocha.test("Belt_List.reduceWithIndex", () => { + Belt_List.reduceWithIndex({ hd: 1, tl: { hd: 2, @@ -19728,8 +18211,13 @@ Mocha.describe("List.reduceReverse", () => { } } } - }, 10, (a, b) => a - b | 0); - List.reduceReverse({ + }, 0, (acc, item, index) => (acc + item | 0) + index | 0); + }); +}); + +Mocha.describe("Belt_List.filterWithIndex", () => { + Mocha.test("Belt_List.filterWithIndex", () => { + Belt_List.filterWithIndex({ hd: 1, tl: { hd: 2, @@ -19741,13 +18229,46 @@ Mocha.describe("List.reduceReverse", () => { } } } - }, /* [] */0, List.add); + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("List.reduceWithIndex", () => { - Mocha.test("List.reduceWithIndex", () => { - List.reduceWithIndex({ +Mocha.describe("Belt.Array.reverseInPlace", () => { + Mocha.test("Belt.Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt.Array.reduceReverse2", () => { + Mocha.test("Belt.Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt.List.reduceWithIndex", () => { + Mocha.test("Belt.List.reduceWithIndex", () => { + Belt_List.reduceWithIndex({ hd: 1, tl: { hd: 2, @@ -19763,22 +18284,9 @@ Mocha.describe("List.reduceWithIndex", () => { }); }); -Mocha.describe("List.reduce", () => { - Mocha.test("List.reduce", () => { - List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduce({ +Mocha.describe("Belt.List.filterWithIndex", () => { + Mocha.test("Belt.List.filterWithIndex", () => { + Belt_List.filterWithIndex({ hd: 1, tl: { hd: 2, @@ -19790,721 +18298,776 @@ Mocha.describe("List.reduce", () => { } } } - }, 0, (acc, item) => acc + item | 0); + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("List.forEachWithIndex", () => { - Mocha.test("List.forEachWithIndex", () => { - List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (x, index) => { - console.log("Item " + index.toString() + " is " + x); +Mocha.describe("Belt.MutableSet.fromArray", () => { + Mocha.test("Belt.MutableSet.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.describe("List.forEach", () => { - Mocha.test("List.forEach", () => { - List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); +Mocha.describe("Belt.MutableSet.mergeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("List.mapReverse", () => { - Mocha.test("List.mapReverse", () => { - let f = x => Math.imul(x, x); - let l = { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }; - let withMap = List.reverse(List.map(l, f)); - let withMapReverse = List.mapReverse(l, f); - console.log(Primitive_object.equal(withMap, withMapReverse)); +Mocha.describe("Belt.MutableSet.intersect", () => { + Mocha.test("Belt.MutableSet.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.describe("List.reverse", () => { - Mocha.test("List.reverse", () => { - List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.MutableSet.partition", () => { + Mocha.test("Belt.MutableSet.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.describe("List.toArray", () => { - Mocha.test("List.toArray", () => { - List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.Map.Dict.findFirstBy", () => { + Mocha.test("Belt.Map.Dict.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_Array.reverseInPlace", () => { + Mocha.test("Belt_Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("List.fromArray", () => { - Mocha.test("List.fromArray", () => { - List.fromArray([ +Mocha.describe("Belt_Array.reduceReverse2", () => { + Mocha.test("Belt_Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ 1, 2, 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("String.splitByRegExpAtMost", () => { + Mocha.test("String.splitByRegExpAtMost", () => { + Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ + "Hello", + "World.", + "How" ]); }); }); -Mocha.describe("List.mapWithIndex", () => { - Mocha.test("List.mapWithIndex", () => { - List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (x, index) => index + x | 0); +Mocha.describe("RegExp.fromStringWithFlags", () => { + Mocha.test("RegExp.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.describe("List.zipBy", () => { - Mocha.test("List.zipBy", () => { - 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("Pervasives.setTimeoutFloat", () => { + Mocha.test("Pervasives.setTimeoutFloat", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); }); }); -Mocha.describe("List.zip", () => { - Mocha.test("List.zip", () => { - List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } +Mocha.describe("JSON.stringifyWithReplacer", () => { + Mocha.test("JSON.stringifyWithReplacer", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; } - }); + }; + JSON.stringify(json, replacer); }); }); -Mocha.describe("List.map", () => { - Mocha.test("List.map", () => { - List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); +Mocha.describe("Iterator.toArrayWithMapper", () => { + Mocha.test("Iterator.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("List.flat", () => { - Mocha.test("List.flat", () => { - 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.describe("Float.toFixedWithPrecision", () => { + Mocha.test("Float.toFixedWithPrecision", () => { + (300.0).toFixed(4); + (300.0).toFixed(1); }); }); -Mocha.describe("List.reverseConcat", () => { - Mocha.test("List.reverseConcat", () => { - List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); +Mocha.describe("Belt_internalMapInt.A.fill", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("List.concatMany", () => { - Mocha.test("List.concatMany", () => { - List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Belt_internalMapInt.A.blit", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("List.concat", () => { - Mocha.test("List.concat", () => { - List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); +Mocha.describe("Belt_internalMapInt.A.some", () => { + Mocha.test("Belt_internalMapInt.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; + }); +}); + +Mocha.describe("Belt_internalSetInt.A.fill", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("List.splitAt", () => { - Mocha.test("List.splitAt", () => { - List.splitAt({ - hd: "Hello", - tl: { - hd: "World", - tl: /* [] */0 - } - }, 1); - List.splitAt({ - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - }, 2); +Mocha.describe("Belt_internalSetInt.A.blit", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("List.take", () => { - Mocha.test("List.take", () => { - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); +Mocha.describe("Belt_internalSetInt.A.some", () => { + Mocha.test("Belt_internalSetInt.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("List.drop", () => { - Mocha.test("List.drop", () => { - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); +Mocha.describe("Belt_Set.Dict.minUndefined", () => { + Mocha.test("Belt_Set.Dict.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.describe("List.toShuffled", () => { - Mocha.test("List.toShuffled", () => { - List.toShuffled({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.Dict.maxUndefined", () => { + Mocha.test("Belt_Set.Dict.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.describe("List.fromInitializer", () => { - Mocha.test("List.fromInitializer", () => { - List.fromInitializer(5, i => i); - List.fromInitializer(5, i => Math.imul(i, i)); +Mocha.describe("Belt_Result.mapWithDefault", () => { + Mocha.test("Belt_Result.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_Result.getWithDefault", () => { + Mocha.test("Belt_Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("List.make", () => { - Mocha.test("List.make", () => { - List.make(3, 1); +Mocha.describe("Belt_Option.mapWithDefault", () => { + Mocha.test("Belt_Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("List.getExn", () => { - Mocha.test("List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.assertEqual(List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = 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", - 14986, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_Option.getWithDefault", () => { + Mocha.test("Belt_Option.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.describe("List.get", () => { - Mocha.test("List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - List.get(abc, 1); - List.get(abc, 4); +Mocha.describe("Belt_MutableSet.removeMany", () => { + Mocha.test("Belt_MutableSet.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.describe("List.add", () => { - Mocha.test("List.add", () => { - List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 +Mocha.describe("Belt_MapString.findFirstBy", () => { + Mocha.test("Belt_MapString.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; } - }, "Hello"); + }), [ + "1", + "one" + ]); }); }); -Mocha.describe("List.tailExn", () => { - Mocha.test("List.tailExn", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, +Mocha.describe("Belt_List.forEachWithIndex", () => { + Mocha.test("Belt_List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", tl: { - hd: 2, + hd: "b", tl: { - hd: 3, + hd: "c", tl: /* [] */0 } } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); }); - let exit = 0; - let val; - try { - val = 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", - 15024, - 7 - ], - Error: new Error() - }; - } - }); }); -Mocha.describe("List.tail", () => { - Mocha.test("List.tail", () => { - List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - List.tail(/* [] */0); +Mocha.describe("Belt.Array.reduceWithIndex", () => { + Mocha.test("Belt.Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("List.headExn", () => { - Mocha.test("List.headExn", () => { - Pervasives.assertEqual(List.headExn({ - hd: 1, +Mocha.describe("Belt.List.forEachWithIndex", () => { + Mocha.test("Belt.List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", tl: { - hd: 2, + hd: "b", tl: { - hd: 3, + hd: "c", tl: /* [] */0 } } - }), 1); - let exit = 0; - let val; - try { - val = 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", - 15049, - 7 - ], - Error: new Error() - }; - } - + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); }); }); -Mocha.describe("List.head", () => { - Mocha.test("List.head", () => { - List.head(/* [] */0); - List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.MutableSet.removeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("List.size", () => { - Mocha.test("List.size", () => { - List.size({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.HashMap.valuesToArray", () => { + Mocha.test("Belt.HashMap.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("List.length", () => { - Mocha.test("List.length", () => { - List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt.Option.mapWithDefault", () => { + Mocha.test("Belt.Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("Nullable.flatMap", () => { - Mocha.test("Nullable.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; - } - }; - Nullable.flatMap(2, addIfAboveOne); - Nullable.flatMap(-4, addIfAboveOne); - Nullable.flatMap(null, addIfAboveOne); +Mocha.describe("Belt.Option.getWithDefault", () => { + Mocha.test("Belt.Option.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.describe("Nullable.mapOr", () => { - Mocha.test("Nullable.mapOr", () => { - Nullable.mapOr(3, 0, x => x + 5 | 0); - Nullable.mapOr(null, 0, x => x + 5 | 0); +Mocha.describe("Belt.Result.mapWithDefault", () => { + Mocha.test("Belt.Result.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("Nullable.map", () => { - Mocha.test("Nullable.map", () => { - Nullable.map(3, x => Math.imul(x, x)); - Nullable.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Belt.Result.getWithDefault", () => { + Mocha.test("Belt.Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("Nullable.forEach", () => { - Mocha.test("Nullable.forEach", () => { - Nullable.forEach("thing", x => { - console.log(x); +Mocha.describe("Belt.Set.Dict.minUndefined", () => { + Mocha.test("Belt.Set.Dict.minUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Nullable.forEach(null, x => { - console.log(x); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); + }); +}); + +Mocha.describe("Belt.Set.Dict.maxUndefined", () => { + Mocha.test("Belt.Set.Dict.maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Nullable.forEach(undefined, x => { - console.log(x); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.maxUndefined(undefined); + Belt_SetDict.maxUndefined(s1); + }); +}); + +Mocha.describe("Belt_Array.reduceWithIndex", () => { + Mocha.test("Belt_Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_HashMap.valuesToArray", () => { + Mocha.test("Belt_HashMap.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("Nullable.getUnsafe", () => { - Mocha.test("Nullable.getUnsafe", () => {}); +Mocha.describe("Array.reduceRightWithIndex", () => { + Mocha.test("Array.reduceRightWithIndex", () => { + Pervasives.assertEqual($$Array.reduceRightWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); + }); }); -Mocha.describe("Nullable.getExn", () => { - Mocha.test("Nullable.getExn", () => { - let exit = 0; - let value; - try { - value = 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", - 15150, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "Hello"); - } - let exit$1 = 0; - let val; - try { - val = 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", - 15156, - 7 - ], - Error: new Error() - }; - } - let exit$2 = 0; - let val$1; - try { - val$1 = 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; - } +Mocha.describe("Pervasives.setIntervalFloat", () => { + Mocha.test("Pervasives.setIntervalFloat", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms"); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500.0); + }); +}); + +Mocha.describe("JSON.stringifyAnyWithIndent", () => { + Mocha.test("JSON.stringifyAnyWithIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { } - if (exit$2 === 1) { + if (exit === 1) { throw { RE_EXN_ID: "Assert_failure", _1: [ "generated_mocha_test.res", - 15161, + 15451, 7 ], Error: new Error() @@ -20514,53 +19077,42 @@ Mocha.describe("Nullable.getExn", () => { }); }); -Mocha.describe("Nullable.getOr", () => { - Mocha.test("Nullable.getOr", () => { - Nullable.getOr(null, "Banana"); - Nullable.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNullable("Jane")); - greet(undefined); - }); -}); - -Mocha.describe("Nullable.fromOption", () => { - Mocha.test("Nullable.fromOption", () => { - Nullable.fromOption("Hello"); - }); -}); - -Mocha.describe("Nullable.toOption", () => { - Mocha.test("Nullable.toOption", () => { - let nullableString = "Hello"; - if (nullableString == null) { - console.log("Didn't have a value."); - } else { - console.log("Got string:", nullableString); - } - }); -}); - -Mocha.describe("Nullable.make", () => { - Mocha.test("Nullable.make", () => { - let myStr = "Hello"; - if ((myStr == null) || myStr !== myStr) { - console.log("Values did not match."); - } else { - console.log("Yay, values matched!"); +Mocha.describe("JSON.stringifyAnyWithFilter", () => { + Mocha.test("JSON.stringifyAnyWithFilter", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; + let val; + try { + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { + } - }); -}); - -Mocha.describe("Nullable.isNullable", () => { - Mocha.test("Nullable.isNullable", () => { - if ("Hello" == null) { + if (exit === 1) { throw { RE_EXN_ID: "Assert_failure", _1: [ "generated_mocha_test.res", - 15238, - 10 + 15475, + 7 ], Error: new Error() }; @@ -20569,512 +19121,1073 @@ Mocha.describe("Nullable.isNullable", () => { }); }); -Mocha.describe("Nullable.undefined", () => { - Mocha.test("Nullable.undefined", () => { - console.log(undefined); - }); -}); - -Mocha.describe("Nullable.null", () => { - Mocha.test("Nullable.null", () => { - console.log(null); - }); -}); - -Mocha.describe("Math.Int.random", () => { - Mocha.test("Math.Int.random", () => { - $$Math.Int.random(2, 5) === 4; - $$Math.Int.random(505, 2000) === 1276; - $$Math.Int.random(-7, -2) === -4; +Mocha.describe("Belt_internalSetString.A.eq", () => { + Mocha.test("Belt_internalSetString.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Math.Int.ceil", () => { - Mocha.test("Math.Int.ceil", () => { - $$Math.Int.ceil(3.7) === 4; - $$Math.Int.ceil(3.0) === 3; - $$Math.Int.ceil(-3.1) === -3; +Mocha.describe("Belt_internalMapString.A.eq", () => { + Mocha.test("Belt_internalMapString.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Math.Int.floor", () => { - Mocha.test("Math.Int.floor", () => { - $$Math.Int.floor(3.7) === 3; - $$Math.Int.floor(3.0) === 3; - $$Math.Int.floor(-3.1) === -4; +Mocha.describe("Belt_internalMapInt.A.range", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.sign", () => { - Mocha.test("Math.Int.sign", () => { - Math.sign(3); - Math.sign(-3); - Math.sign(0); +Mocha.describe("Belt_internalMapInt.A.zipBy", () => { + Mocha.test("Belt_internalMapInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Math.Int.pow", () => { - Mocha.test("Math.Int.pow", () => { - Math.pow(2, 4); - Math.pow(3, 4); +Mocha.describe("Belt_internalMapInt.A.unzip", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.maxMany", () => { - Mocha.test("Math.Int.maxMany", () => { - Math.max(1, 2); - Math.max(-1, -2); - isFinite(Math.max()); +Mocha.describe("Belt_internalMapInt.A.slice", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.max", () => { - Mocha.test("Math.Int.max", () => { - Math.max(1, 2); - Math.max(-1, -2); +Mocha.describe("Belt_internalMapInt.A.getBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.minMany", () => { - Mocha.test("Math.Int.minMany", () => { - Math.min(1, 2); - Math.min(-1, -2); - isFinite(Math.min()); +Mocha.describe("Belt_internalMapInt.A.every", () => { + Mocha.test("Belt_internalMapInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Math.Int.min", () => { - Mocha.test("Math.Int.min", () => { - Math.min(1, 2); - Math.min(-1, -2); +Mocha.describe("Belt_internalMapInt.A.some2", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.imul", () => { - Mocha.test("Math.Int.imul", () => { - Math.imul(3, 4); - Math.imul(-5, 12); +Mocha.describe("Belt_internalSetInt.A.range", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.Int.clz32", () => { - Mocha.test("Math.Int.clz32", () => { - Math.clz32(1); - Math.clz32(4); +Mocha.describe("Belt_internalSetInt.A.zipBy", () => { + Mocha.test("Belt_internalSetInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Math.Int.abs", () => { - Mocha.test("Math.Int.abs", () => { - Math.abs(-2); - Math.abs(3); +Mocha.describe("Belt_internalSetInt.A.unzip", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.Constants.sqrt2", () => { - Mocha.test("Math.Constants.sqrt2", () => {}); -}); - -Mocha.describe("Math.Constants.sqrt1_2", () => { - Mocha.test("Math.Constants.sqrt1_2", () => {}); -}); - -Mocha.describe("Math.Constants.pi", () => { - Mocha.test("Math.Constants.pi", () => {}); -}); - -Mocha.describe("Math.Constants.log10e", () => { - Mocha.test("Math.Constants.log10e", () => {}); -}); - -Mocha.describe("Math.Constants.log2e", () => { - Mocha.test("Math.Constants.log2e", () => {}); -}); - -Mocha.describe("Math.Constants.ln10", () => { - Mocha.test("Math.Constants.ln10", () => {}); -}); - -Mocha.describe("Math.Constants.ln2", () => { - Mocha.test("Math.Constants.ln2", () => {}); -}); - -Mocha.describe("Math.Constants.e", () => { - Mocha.test("Math.Constants.e", () => {}); +Mocha.describe("Belt_internalSetInt.A.slice", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.trunc", () => { - Mocha.test("Math.trunc", () => { - Math.trunc(0.123); - Math.trunc(1.999); - Math.trunc(13.37); - Math.trunc(42.84); +Mocha.describe("Belt_internalSetInt.A.getBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.tanh", () => { - Mocha.test("Math.tanh", () => { - Math.tanh(-0.0); - Math.tanh(0.0); - Math.tanh(1.0); +Mocha.describe("Belt_internalSetInt.A.every", () => { + Mocha.test("Belt_internalSetInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Math.tan", () => { - Mocha.test("Math.tan", () => { - Math.tan(-0.0); - Math.tan(0.0); - Math.tan(1.0); +Mocha.describe("Belt_internalSetInt.A.some2", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.sqrt", () => { - Mocha.test("Math.sqrt", () => { - isNaN(Math.sqrt(-1.0)); - Math.sqrt(-0.0); - Math.sqrt(0.0); - Math.sqrt(1.0); - Math.sqrt(9.0); +Mocha.describe("Belt_Map.String.findFirstBy", () => { + Mocha.test("Belt_Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); }); }); -Mocha.describe("Math.sinh", () => { - Mocha.test("Math.sinh", () => { - Math.sinh(-0.0); - Math.sinh(0.0); - Math.sinh(1.0); +Mocha.describe("Belt.Array.forEachWithIndex", () => { + Mocha.test("Belt.Array.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.describe("Math.sin", () => { - Mocha.test("Math.sin", () => { - Math.sin(-0.0); - Math.sin(0.0); - Math.sin(1.0); +Mocha.describe("Belt.HashMap.keepMapInPlace", () => { + Mocha.test("Belt.HashMap.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.describe("Math.sign", () => { - Mocha.test("Math.sign", () => { - Math.sign(3.0); - Math.sign(-3.0); - Math.sign(0.0); +Mocha.describe("Belt.Map.String.findFirstBy", () => { + Mocha.test("Belt.Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); }); }); -Mocha.describe("Math.round", () => { - Mocha.test("Math.round", () => { - Math.round(-20.5); - Math.round(-0.1); - Math.round(0.0); - Math.round(-0.0); +Mocha.describe("Belt_Array.forEachWithIndex", () => { + Mocha.test("Belt_Array.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.describe("Math.random", () => { - Mocha.test("Math.random", () => { - Math.random(); +Mocha.describe("Belt_HashMap.keepMapInPlace", () => { + Mocha.test("Belt_HashMap.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.describe("Math.pow", () => { - Mocha.test("Math.pow", () => { - Math.pow(2.0, 4.0); - Math.pow(3.0, 4.0); +Mocha.describe("Int.toPrecisionWithPrecision", () => { + Mocha.test("Int.toPrecisionWithPrecision", () => { + (100).toPrecision(2); + (1).toPrecision(2); }); }); -Mocha.describe("Math.maxMany", () => { - Mocha.test("Math.maxMany", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - isFinite(Math.max()); +Mocha.describe("Belt_internalSetString.A.get", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Math.max", () => { - Mocha.test("Math.max", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); +Mocha.describe("Belt_internalSetString.A.zip", () => { + Mocha.test("Belt_internalSetString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Math.minMany", () => { - Mocha.test("Math.minMany", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - isFinite(Math.min()); +Mocha.describe("Belt_internalSetString.A.map", () => { + Mocha.test("Belt_internalSetString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Math.min", () => { - Mocha.test("Math.min", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); +Mocha.describe("Belt_internalSetString.A.cmp", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Math.log2", () => { - Mocha.test("Math.log2", () => { - isNaN(Math.log2(-2.0)); - isFinite(Math.log2(-0.0)); - isFinite(Math.log2(0.0)); - Math.log2(1.0); +Mocha.describe("Belt_internalMapString.A.get", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Math.log10", () => { - Mocha.test("Math.log10", () => { - isNaN(Math.log10(-2.0)); - isFinite(Math.log10(-0.0)); - isFinite(Math.log10(0.0)); - Math.log10(1.0); +Mocha.describe("Belt_internalMapString.A.zip", () => { + Mocha.test("Belt_internalMapString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Math.log1p", () => { - Mocha.test("Math.log1p", () => { - isNaN(Math.log1p(-2.0)); - isFinite(Math.log1p(-1.0)); - Math.log1p(-0.0); +Mocha.describe("Belt_internalMapString.A.map", () => { + Mocha.test("Belt_internalMapString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Math.log", () => { - Mocha.test("Math.log", () => { - isNaN(Math.log(-1.0)); - isFinite(Math.log(-0.0)); - isFinite(Math.log(0.0)); - Math.log(1.0); +Mocha.describe("Belt_internalMapString.A.cmp", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Math.hypotMany", () => { - Mocha.test("Math.hypotMany", () => { - Math.hypot(3.0, 4.0, 5.0); - Math.hypot(); - }); +Mocha.describe("Belt_internalMapInt.A.length", () => { + Mocha.test("Belt_internalMapInt.A.length", () => {}); }); -Mocha.describe("Math.hypot", () => { - Mocha.test("Math.hypot", () => { - Math.hypot(3.0, 4.0); - Math.hypot(3.0, 5.0); +Mocha.describe("Belt_internalMapInt.A.makeBy", () => { + Mocha.test("Belt_internalMapInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Math.fround", () => { - Mocha.test("Math.fround", () => { - Math.fround(5.5) === 5.5; - Math.fround(5.05) === 5.050000190734863; +Mocha.describe("Belt_internalMapInt.A.concat", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.floor", () => { - Mocha.test("Math.floor", () => { - Math.floor(-45.95); - Math.floor(-45.05); - Math.floor(-0.0); +Mocha.describe("Belt_internalMapInt.A.reduce", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.expm1", () => { - Mocha.test("Math.expm1", () => { - Math.expm1(-1.0); - Math.expm1(-0.0); +Mocha.describe("Belt_internalMapInt.A.every2", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Math.exp", () => { - Mocha.test("Math.exp", () => { - Math.exp(-1.0); - Math.exp(0.0); - }); +Mocha.describe("Belt_internalSetInt.A.length", () => { + Mocha.test("Belt_internalSetInt.A.length", () => {}); }); -Mocha.describe("Math.cosh", () => { - Mocha.test("Math.cosh", () => { - Math.cosh(-1.0); - Math.cosh(-0.0); - Math.cosh(0.0); +Mocha.describe("Belt_internalSetInt.A.makeBy", () => { + Mocha.test("Belt_internalSetInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Math.cos", () => { - Mocha.test("Math.cos", () => { - Math.cos(-0.0); - Math.cos(0.0); - Math.cos(1.0); +Mocha.describe("Belt_internalSetInt.A.concat", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.ceil", () => { - Mocha.test("Math.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.describe("Belt_internalSetInt.A.reduce", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.cbrt", () => { - Mocha.test("Math.cbrt", () => { - Math.cbrt(-1.0); - Math.cbrt(-0.0); - Math.cbrt(0.0); +Mocha.describe("Belt_internalSetInt.A.every2", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.atan2", () => { - Mocha.test("Math.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.describe("Belt_MutableSet.minUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Math.atanh", () => { - Mocha.test("Math.atanh", () => { - isNaN(Math.atanh(-2.0)); - isFinite(Math.atanh(-1.0)); - Math.atanh(-0.0); - Math.atanh(0.0); - Math.atanh(0.5); +Mocha.describe("Belt_MutableSet.maxUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Math.atan", () => { - Mocha.test("Math.atan", () => { - Math.atan(-0.0); - Math.atan(0.0); - Math.atan(1.0); +Mocha.describe("Belt.Array.makeUninitialized", () => { + Mocha.test("Belt.Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Math.asinh", () => { - Mocha.test("Math.asinh", () => { - Math.asinh(-1.0); - Math.asinh(-0.0); +Mocha.describe("Belt.MutableSet.minUndefined", () => { + Mocha.test("Belt.MutableSet.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.describe("Math.asin", () => { - Mocha.test("Math.asin", () => { - Math.asin(-1.0); - isNaN(Math.asin(-2.0)); +Mocha.describe("Belt.MutableSet.maxUndefined", () => { + Mocha.test("Belt.MutableSet.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.describe("Math.acosh", () => { - Mocha.test("Math.acosh", () => { - Math.acosh(1.0); - isNaN(Math.acosh(0.5)); +Mocha.describe("Belt_Array.makeUninitialized", () => { + Mocha.test("Belt_Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Math.acos", () => { - Mocha.test("Math.acos", () => { - Math.acos(-1.0); - isNaN(Math.acos(-3.0)); +Mocha.describe("String.unsafeReplaceRegExpBy0", () => { + Mocha.test("String.unsafeReplaceRegExpBy0", () => { + let re = /[aeiou]/g; + let matchFn = (match, param, param$1) => match.toUpperCase(); + "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; }); }); -Mocha.describe("Math.abs", () => { - Mocha.test("Math.abs", () => { - Math.abs(-2.0); - Math.abs(3.0); +Mocha.describe("String.unsafeReplaceRegExpBy1", () => { + Mocha.test("String.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.describe("Null.flatMap", () => { - Mocha.test("Null.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; +Mocha.describe("String.unsafeReplaceRegExpBy2", () => { + Mocha.test("String.unsafeReplaceRegExpBy2", () => { + let re = /(\d+) times (\d+)/; + let matchFn = (param, group1, group2, param$1, param$2) => { + let match = Int.fromString(group1, undefined); + let match$1 = Int.fromString(group2, undefined); + if (match !== undefined && match$1 !== undefined) { + return Math.imul(match, match$1).toString(); } else { - return null; + return "???"; } }; - Null.flatMap(2, addIfAboveOne); - Null.flatMap(-4, addIfAboveOne); - Null.flatMap(null, addIfAboveOne); - }); -}); - -Mocha.describe("Null.mapOr", () => { - Mocha.test("Null.mapOr", () => { - Null.mapOr(3, 0, x => x + 5 | 0); - Null.mapOr(null, 0, x => x + 5 | 0); + "7 times 6".replace(re, matchFn) === "42"; }); }); -Mocha.describe("Null.map", () => { - Mocha.test("Null.map", () => { - Null.map(3, x => Math.imul(x, x)); - Null.map(null, x => Math.imul(x, x)); +Mocha.describe("Pervasives.encodeURIComponent", () => { + Mocha.test("Pervasives.encodeURIComponent", () => { + console.log(encodeURIComponent("array=[someValue]")); }); }); -Mocha.describe("Null.forEach", () => { - Mocha.test("Null.forEach", () => { - Null.forEach("thing", x => { - console.log(x); - }); - Null.forEach(null, x => { - console.log(x); - }); +Mocha.describe("Pervasives.decodeURIComponent", () => { + Mocha.test("Pervasives.decodeURIComponent", () => { + console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); }); -}); - -Mocha.describe("Null.getUnsafe", () => { - Mocha.test("Null.getUnsafe", () => {}); -}); - -Mocha.describe("Null.getExn", () => { - Mocha.test("Null.getExn", () => { - Pervasives.assertEqual(Null.getExn(3), 3); - let exit = 0; - let value; - try { - value = 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", - 15923, - 35 - ], - Error: new Error() - }; +}); + +Mocha.describe("JSON.stringifyAnyWithReplacer", () => { + Mocha.test("JSON.stringifyAnyWithReplacer", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "ReScript"); - } - let exit$1 = 0; + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(() => "hello world"), undefined); + let exit = 0; let val; try { - val = 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; - } + val = JSON.stringify(BigInt(0)); + exit = 1; + } catch (exn) { } - if (exit$1 === 1) { + if (exit === 1) { throw { RE_EXN_ID: "Assert_failure", _1: [ "generated_mocha_test.res", - 15929, + 16160, 7 ], Error: new Error() @@ -21084,1755 +20197,2642 @@ Mocha.describe("Null.getExn", () => { }); }); -Mocha.describe("Null.getOr", () => { - Mocha.test("Null.getOr", () => { - Null.getOr(null, "Banana"); - Null.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNull("Jane")); - greet(undefined); - }); -}); - -Mocha.describe("Null.fromOption", () => { - Mocha.test("Null.fromOption", () => { - let asNull = Null.fromOption(undefined); - console.log(asNull === null); - }); -}); - -Mocha.describe("Null.toOption", () => { - Mocha.test("Null.toOption", () => { - let nullStr = "Hello"; - if (nullStr !== null) { - console.log("Got string:", nullStr); - } else { - console.log("Didn't have a value."); - } +Mocha.describe("Date.toLocaleStringWithLocale", () => { + Mocha.test("Date.toLocaleStringWithLocale", () => { + console.log(new Date().toLocaleString("en-US")); }); }); -Mocha.describe("Null.make", () => { - Mocha.test("Null.make", () => {}); -}); - -Mocha.describe("Null.null", () => { - Mocha.test("Null.null", () => { - console.log(null); +Mocha.describe("Belt_internalSetString.A.fill", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Null.asNullable", () => { - Mocha.test("Null.asNullable", () => {}); -}); - -Mocha.describe("Object.isExtensible", () => { - Mocha.test("Object.isExtensible", () => { - let obj = { - a: 1 - }; - Object.isExtensible(obj); - Object.preventExtensions(obj); - Object.isExtensible(obj); +Mocha.describe("Belt_internalSetString.A.blit", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Object.isFrozen", () => { - Mocha.test("Object.isFrozen", () => { - let point = Object.freeze({ - x: 1, - y: 3 - }); - Object.isFrozen(point); - let fruit = { - name: "Apple" - }; - Object.isFrozen(fruit); +Mocha.describe("Belt_internalSetString.A.some", () => { + Mocha.test("Belt_internalSetString.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Object.isSealed", () => { - Mocha.test("Object.isSealed", () => { - let point = Object.seal({ - x: 1, - y: 3 - }); - Object.isSealed(point); - let fruit = { - name: "Apple" - }; - Object.isSealed(fruit); +Mocha.describe("Belt_internalMapString.A.fill", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Object.freeze", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16053, - 7 - ], - Error: new Error() - }; - } - - } +Mocha.describe("Belt_internalMapString.A.blit", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Object.preventExtensions", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16070, - 7 - ], - Error: new Error() - }; - } - - } +Mocha.describe("Belt_internalMapString.A.some", () => { + Mocha.test("Belt_internalMapString.A.some", () => { + Belt_Array.some([ + 2, + 3, + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Object.seal", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16088, - 7 - ], - Error: new Error() - }; - } - - } - point["x"] = 13; +Mocha.describe("Belt_internalMapInt.A.reverse", () => { + Mocha.test("Belt_internalMapInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Object.hasOwnProperty", () => { - Mocha.test("Object.hasOwnProperty", () => { - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "a"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "b"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "toString"); +Mocha.describe("Belt_internalMapInt.A.rangeBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Object.keysToArray", () => { - Mocha.test("Object.keysToArray", () => { - Object.keys({ - a: 1, - b: 2 +Mocha.describe("Belt_internalMapInt.A.forEach", () => { + Mocha.test("Belt_internalMapInt.A.forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); }); - Object.keys({ - a: undefined + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, + 2, + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; }); - Object.keys({}); - }); -}); - -Mocha.describe("Object.set", () => { - Mocha.test("Object.set", () => { - ({ - a: 1 - })["a"] = 2; - ({ - a: 1 - })["a"] = undefined; - ({ - a: 1 - })["b"] = 2; }); }); -Mocha.describe("Object.getSymbol", () => { - Mocha.test("Object.getSymbol", () => { - let fruit = Symbol("fruit"); - let x = {}; - x[fruit] = "banana"; +Mocha.describe("Belt_internalMapInt.A.flatMap", () => { + Mocha.test("Belt_internalMapInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Object.get", () => { - Mocha.test("Object.get", () => { - Option.isSome(({ - a: 1 - })["toString"]); +Mocha.describe("Belt_internalMapInt.A.keepMap", () => { + Mocha.test("Belt_internalMapInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Object.assign", () => { - Mocha.test("Object.assign", () => { - Object.assign({ - a: 1 - }, { - a: 2 - }); - Object.assign({ - a: 1, - b: 2 - }, { - a: 0 - }); - Object.assign({ - a: 1 - }, { - a: null - }); +Mocha.describe("Belt_internalSetInt.A.reverse", () => { + Mocha.test("Belt_internalSetInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Object.create", () => { - Mocha.test("Object.create", () => { - let x = { - fruit: "banana" - }; - Object.create(x); +Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Object.is", () => { - Mocha.test("Object.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 - } +Mocha.describe("Belt_internalSetInt.A.forEach", () => { + Mocha.test("Belt_internalSetInt.A.forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); }); - Object.is([ - 1, - 2, - 3 - ], [ - 1, - 2, - 3 - ]); - Primitive_object.equal([ - 1, - 2, - 3 - ], [ + let total = { + contents: 0 + }; + Belt_Array.forEach([ 1, 2, - 3 - ]); - let fruit = { - name: "Apple" - }; - Object.is(fruit, fruit); - Object.is(fruit, { - name: "Apple" - }); - Primitive_object.equal(fruit, { - name: "Apple" + 3, + 4 + ], x => { + total.contents = total.contents + x | 0; }); }); }); -Mocha.describe("Object.make", () => { - Mocha.test("Object.make", () => { - let x = {}; - Object.keys(x).length; - Option.isSome(x["toString"]); +Mocha.describe("Belt_internalSetInt.A.flatMap", () => { + Mocha.test("Belt_internalSetInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Option.all", () => { - Mocha.test("Option.all", () => { - Option.all([ +Mocha.describe("Belt_internalSetInt.A.keepMap", () => { + Mocha.test("Belt_internalSetInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ 1, 2, 3 - ]); - Option.all([ - 1, - undefined - ]); + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Option.compare", () => { - Mocha.test("Option.compare", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Option.compare(3, 15, clockCompare); - Option.compare(3, 14, clockCompare); - Option.compare(2, 15, clockCompare); - Option.compare(undefined, 15, clockCompare); - Option.compare(14, undefined, clockCompare); - Option.compare(undefined, undefined, clockCompare); +Mocha.describe("Belt_SortArray.binarySearchBy", () => { + Mocha.test("Belt_SortArray.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.describe("Option.equal", () => { - Mocha.test("Option.equal", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Option.equal(3, 15, clockEqual); - Option.equal(3, undefined, clockEqual); - Option.equal(undefined, 3, clockEqual); - Option.equal(undefined, undefined, clockEqual); +Mocha.describe("Belt.SortArray.binarySearchBy", () => { + Mocha.test("Belt.SortArray.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.describe("Option.isNone", () => { - Mocha.test("Option.isNone", () => { - Option.isNone(undefined); - Option.isNone(1); +Mocha.describe("Int.toExponentialWithPrecision", () => { + Mocha.test("Int.toExponentialWithPrecision", () => { + (77).toExponential(2); + (5678).toExponential(2); }); }); -Mocha.describe("Option.isSome", () => { - Mocha.test("Option.isSome", () => { - Option.isSome(undefined); - Option.isSome(1); +Mocha.describe("Float.toPrecisionWithPrecision", () => { + Mocha.test("Float.toPrecisionWithPrecision", () => { + (100.0).toPrecision(2); + (1.0).toPrecision(1); }); }); -Mocha.describe("Option.orElse", () => { - Mocha.test("Option.orElse", () => { - Primitive_object.equal(Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Option.orElse(undefined, 1066), 1066); - Option.orElse(undefined, undefined) === undefined; +Mocha.describe("Belt_internalSetString.A.range", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Option.getOr", () => { - Mocha.test("Option.getOr", () => { - Option.getOr(undefined, "Banana"); - Option.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); +Mocha.describe("Belt_internalSetString.A.zipBy", () => { + Mocha.test("Belt_internalSetString.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Option.flatMap", () => { - Mocha.test("Option.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Option.flatMap(2, addIfAboveOne); - Option.flatMap(-4, addIfAboveOne); - Option.flatMap(undefined, addIfAboveOne); +Mocha.describe("Belt_internalSetString.A.unzip", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Option.map", () => { - Mocha.test("Option.map", () => { - Option.map(3, x => Math.imul(x, x)); - Option.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Belt_internalSetString.A.slice", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Option.mapOr", () => { - Mocha.test("Option.mapOr", () => { - Option.mapOr(3, 0, x => x + 5 | 0); - Option.mapOr(undefined, 0, x => x + 5 | 0); +Mocha.describe("Belt_internalSetString.A.getBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Option.getUnsafe", () => { - Mocha.test("Option.getUnsafe", () => {}); -}); - -Mocha.describe("Option.getExn", () => { - Mocha.test("Option.getExn", () => { - Pervasives.assertEqual(Option.getExn(3, undefined), 3); - let exit = 0; - let val; - try { - val = Option.getExn(undefined, undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16360, - 7 - ], - Error: new Error() - }; - } - let exit$1 = 0; - let val$1; - try { - val$1 = 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", - 16365, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_internalSetString.A.every", () => { + Mocha.test("Belt_internalSetString.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Option.forEach", () => { - Mocha.test("Option.forEach", () => { - Option.forEach("thing", x => { - console.log(x); - }); - Option.forEach(undefined, x => { - console.log(x); - }); +Mocha.describe("Belt_internalSetString.A.some2", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Option.filter", () => { - Mocha.test("Option.filter", () => { - Option.filter(10, x => x > 5); - Option.filter(4, x => x > 5); - Option.filter(undefined, x => x > 5); +Mocha.describe("Belt_internalMapString.A.range", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.assertEqual", () => { - Mocha.test("Pervasives.assertEqual", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }), { - hd: 2, - tl: /* [] */0 - }); +Mocha.describe("Belt_internalMapString.A.zipBy", () => { + Mocha.test("Belt_internalMapString.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Pervasives.import", () => { - Mocha.test("Pervasives.import", () => {}); -}); - -Mocha.describe("Pervasives.decodeURIComponent", () => { - Mocha.test("Pervasives.decodeURIComponent", () => { - console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); +Mocha.describe("Belt_internalMapString.A.unzip", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.encodeURIComponent", () => { - Mocha.test("Pervasives.encodeURIComponent", () => { - console.log(encodeURIComponent("array=[someValue]")); +Mocha.describe("Belt_internalMapString.A.slice", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.decodeURI", () => { - Mocha.test("Pervasives.decodeURI", () => { - console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); +Mocha.describe("Belt_internalMapString.A.getBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.encodeURI", () => { - Mocha.test("Pervasives.encodeURI", () => { - console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); +Mocha.describe("Belt_internalMapString.A.every", () => { + Mocha.test("Belt_internalMapString.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Pervasives.clearInterval", () => { - Mocha.test("Pervasives.clearInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints in 100 ms"); - }, 100); - setTimeout(() => { - clearInterval(intervalId); - }, 500); +Mocha.describe("Belt_internalMapString.A.some2", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.setIntervalFloat", () => { - Mocha.test("Pervasives.setIntervalFloat", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms"); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500.0); +Mocha.describe("Belt_internalMapInt.A.joinWith", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Pervasives.setInterval", () => { - Mocha.test("Pervasives.setInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms."); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500); +Mocha.describe("Belt_internalSetInt.A.joinWith", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Pervasives.clearTimeout", () => { - Mocha.test("Pervasives.clearTimeout", () => { - let timeoutId = setTimeout(() => { - console.log("This prints in 2 seconds."); - }, 2000); - clearTimeout(timeoutId); - }); +Mocha.describe("Belt_internalSetString.A.length", () => { + Mocha.test("Belt_internalSetString.A.length", () => {}); }); -Mocha.describe("Pervasives.setTimeoutFloat", () => { - Mocha.test("Pervasives.setTimeoutFloat", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); +Mocha.describe("Belt_internalSetString.A.makeBy", () => { + Mocha.test("Belt_internalSetString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Pervasives.setTimeout", () => { - Mocha.test("Pervasives.setTimeout", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); +Mocha.describe("Belt_internalSetString.A.concat", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Promise.allSettled", () => { - Mocha.test("Promise.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.describe("Belt_internalSetString.A.reduce", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Promise.all", () => { - Mocha.test("Promise.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.describe("Belt_internalSetString.A.every2", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Promise.any", () => { - Mocha.test("Promise.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.describe("Belt_internalMapString.A.length", () => { + Mocha.test("Belt_internalMapString.A.length", () => {}); +}); + +Mocha.describe("Belt_internalMapString.A.makeBy", () => { + Mocha.test("Belt_internalMapString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Promise.race", () => { - Mocha.test("Promise.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.describe("Belt_internalMapString.A.concat", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Promise.finally", () => { - Mocha.test("Promise.finally", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - let isDone = { - contents: false - }; - $$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.describe("Belt_internalMapString.A.reduce", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Promise.thenResolve", () => { - Mocha.test("Promise.thenResolve", () => { - Promise.resolve("Anna").then(str => "Hello " + str).then(str => { - console.log(str); - }); +Mocha.describe("Belt_internalMapString.A.every2", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Promise.then", () => { - Mocha.test("Promise.then", () => { - Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { - console.log("Your lucky number is: ", num); - return Promise.resolve(); - }); +Mocha.describe("Belt_internalMapInt.A.partition", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Promise.catch", () => { - Mocha.test("Promise.catch", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - $$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 === 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.describe("Belt_internalSetInt.A.partition", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt.HashMap.getBucketHistogram", () => { + Mocha.test("Belt.HashMap.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.describe("Promise.make", () => { - Mocha.test("Promise.make", () => { - $$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.describe("Belt_HashMap.getBucketHistogram", () => { + Mocha.test("Belt_HashMap.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.describe("Promise.reject", () => { - Mocha.test("Promise.reject", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - $$Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }), v => { - if (v.RE_EXN_ID === TestError) { - Pervasives.assertEqual(v._1, "some rejected value"); - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16787, - 9 - ], - Error: new Error() - }; - } - return Promise.resolve(); - }); +Mocha.describe("Float.toExponentialWithPrecision", () => { + Mocha.test("Float.toExponentialWithPrecision", () => { + (77.0).toExponential(2); + (5678.0).toExponential(2); }); }); -Mocha.describe("Promise.resolve", () => { - Mocha.test("Promise.resolve", () => { - Promise.resolve(5); - }); +Mocha.describe("Float.Constants.positiveInfinity", () => { + Mocha.test("Float.Constants.positiveInfinity", () => {}); }); -Mocha.describe("RegExp.Result.input", () => { - Mocha.test("RegExp.Result.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.describe("Float.Constants.negativeInfinity", () => { + Mocha.test("Float.Constants.negativeInfinity", () => {}); }); -Mocha.describe("RegExp.Result.matches", () => { - Mocha.test("RegExp.Result.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("Belt_internalSetString.A.reverse", () => { + Mocha.test("Belt_internalSetString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("RegExp.Result.fullMatch", () => { - Mocha.test("RegExp.Result.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.describe("Belt_internalSetString.A.rangeBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("RegExp.unicode", () => { - Mocha.test("RegExp.unicode", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "mu"); - console.log(regexp2.unicode); +Mocha.describe("Belt_internalSetString.A.forEach", () => { + Mocha.test("Belt_internalSetString.A.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.describe("RegExp.sticky", () => { - Mocha.test("RegExp.sticky", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "my"); - console.log(regexp2.unicode); +Mocha.describe("Belt_internalSetString.A.flatMap", () => { + Mocha.test("Belt_internalSetString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("RegExp.source", () => { - Mocha.test("RegExp.source", () => { - let regexp = new RegExp("\\w+", "g"); - console.log(regexp.source); +Mocha.describe("Belt_internalSetString.A.keepMap", () => { + Mocha.test("Belt_internalSetString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("RegExp.multiline", () => { - Mocha.test("RegExp.multiline", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.multiline); - let regexp2 = new RegExp("\\w+", "mi"); - console.log(regexp2.multiline); +Mocha.describe("Belt_internalMapString.A.reverse", () => { + Mocha.test("Belt_internalMapString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("RegExp.global", () => { - Mocha.test("RegExp.global", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.global); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.global); +Mocha.describe("Belt_internalMapString.A.rangeBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("RegExp.ignoreCase", () => { - Mocha.test("RegExp.ignoreCase", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.ignoreCase); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.ignoreCase); +Mocha.describe("Belt_internalMapString.A.forEach", () => { + Mocha.test("Belt_internalMapString.A.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.describe("RegExp.setLastIndex", () => { - Mocha.test("RegExp.setLastIndex", () => { - let regexp = new RegExp("\\w+"); - regexp.lastIndex = 4; - regexp.exec("Many words here."); - console.log(regexp.lastIndex); +Mocha.describe("Belt_internalMapString.A.flatMap", () => { + Mocha.test("Belt_internalMapString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("RegExp.lastIndex", () => { - Mocha.test("RegExp.lastIndex", () => { - let regexp = new RegExp("\\w+"); - console.log(regexp.lastIndex); - regexp.exec("Many words here."); - console.log(regexp.lastIndex); +Mocha.describe("Belt_internalMapString.A.keepMap", () => { + Mocha.test("Belt_internalMapString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("RegExp.exec", () => { - Mocha.test("RegExp.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.describe("Belt_internalMapInt.A.concatMany", () => { + Mocha.test("Belt_internalMapInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("RegExp.test", () => { - Mocha.test("RegExp.test", () => { - let regexp = new RegExp("\\w+"); - if (regexp.test("ReScript is cool!")) { - console.log("Yay, there's a word in there."); - } - +Mocha.describe("Belt_internalMapInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("RegExp.fromStringWithFlags", () => { - Mocha.test("RegExp.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.describe("Belt_internalMapInt.A.getIndexBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("RegExp.fromString", () => { - Mocha.test("RegExp.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.describe("Belt_internalSetInt.A.concatMany", () => { + Mocha.test("Belt_internalSetInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Result.all", () => { - Mocha.test("Result.all", () => { - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Ok", - _0: 2 - }, - { - TAG: "Ok", - _0: 3 - } +Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetInt.A.sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 ]); - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Error", - _0: 1 - } + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 ]); }); }); -Mocha.describe("Result.mapError", () => { - Mocha.test("Result.mapError", () => { - let format = n => "Error code: " + n.toString(); - Result.mapError({ - TAG: "Error", - _0: 14 - }, format); - Result.mapError({ - TAG: "Ok", - _0: "abc" - }, format); - }); -}); - -Mocha.describe("Result.forEach", () => { - Mocha.test("Result.forEach", () => { - Result.forEach({ - TAG: "Ok", - _0: 3 - }, prim => { - console.log(prim); - }); - Result.forEach({ - TAG: "Error", - _0: "x" - }, prim => { - console.log(prim); - }); - }); -}); - -Mocha.describe("Result.compare", () => { - Mocha.test("Result.compare", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Result.compare({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; +Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Result.equal", () => { - Mocha.test("Result.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; - Result.equal(good1, good2, mod10equal) === true; - Result.equal(good1, bad1, mod10equal) === false; - Result.equal(bad2, good2, mod10equal) === false; - Result.equal(bad1, bad2, mod10equal) === true; +Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyWithFilterAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ], 2); }); }); -Mocha.describe("Result.getOr", () => { - Mocha.test("Result.getOr", () => { - Result.getOr({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Result.getOr({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; +Mocha.describe("Date.toLocaleDateStringWithLocale", () => { + Mocha.test("Date.toLocaleDateStringWithLocale", () => { + console.log(new Date().toLocaleDateString("en-US")); }); }); -Mocha.describe("Result.flatMap", () => { - Mocha.test("Result.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(Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 - }); - Primitive_object.equal(Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" - }); - Primitive_object.equal(Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" - }); +Mocha.describe("Date.toLocaleTimeStringWithLocale", () => { + Mocha.test("Date.toLocaleTimeStringWithLocale", () => { + console.log(new Date().toLocaleTimeString("en-US")); }); }); -Mocha.describe("Result.map", () => { - Mocha.test("Result.map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" - }); +Mocha.describe("Belt_internalSetString.A.joinWith", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Result.mapOr", () => { - Mocha.test("Result.mapOr", () => { - Result.mapOr({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Result.mapOr({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; +Mocha.describe("Belt_internalMapString.A.joinWith", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Set.toArray", () => { - Mocha.test("Set.toArray", () => { - let set = new Set([ - "apple", - "orange", - "apple", - "banana" +Mocha.describe("Belt.Array.truncateToLengthUnsafe", () => { + Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" ]); - Array.from(set); - }); -}); - -Mocha.describe("Set.values", () => { - Mocha.test("Set.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("Set.forEach", () => { - Mocha.test("Set.forEach", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue2"); - set.forEach(value => { - console.log(value); - }); +Mocha.describe("Belt_Array.truncateToLengthUnsafe", () => { + Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("Set.has", () => { - Mocha.test("Set.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.describe("Belt_internalSetString.A.partition", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Set.delete", () => { - Mocha.test("Set.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.describe("Belt_internalMapString.A.partition", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Set.add", () => { - Mocha.test("Set.add", () => { - let set = new Set(); - set.add("someValue"); +Mocha.describe("Belt_internalMapInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Set.clear", () => { - Mocha.test("Set.clear", () => { - let set = new Set(); - set.add("someKey"); - set.clear(); +Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Set.size", () => { - Mocha.test("Set.size", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue"); - set.add("someValue2"); +Mocha.describe("Belt.Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt.Array.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.describe("Set.fromIterator", () => { - Mocha.test("Set.fromIterator", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(new Set(iterator).size, 3); +Mocha.describe("Belt_Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt_Array.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.describe("Set.fromArray", () => { - Mocha.test("Set.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.describe("JSON.stringifyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer, 2); }); }); -Mocha.describe("Set.make", () => { - Mocha.test("Set.make", () => { - new Set(); - let set = new Set(); - set.add("Fine name"); +Mocha.describe("Belt_internalSetString.A.concatMany", () => { + Mocha.test("Belt_internalSetString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("String.localeCompare", () => { - Mocha.test("String.localeCompare", () => { - "a".localeCompare("c") < 0.0 === true; - "a".localeCompare("a") === 0.0; +Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetString.A.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.describe("String.padEnd", () => { - Mocha.test("String.padEnd", () => { - "Hello".padEnd(10, ".") === "Hello....."; - "abc".padEnd(1, "") === "abc"; +Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("String.padStart", () => { - Mocha.test("String.padStart", () => { - "abc".padStart(5, " ") === " abc"; - "abc".padStart(6, "123465") === "123abc"; +Mocha.describe("Belt_internalMapString.A.concatMany", () => { + Mocha.test("Belt_internalMapString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("String.trimEnd", () => { - Mocha.test("String.trimEnd", () => { - " Hello world! ".trimEnd() === " Hello world!"; - " Hello world! ".trimEnd() === " Hello world!"; +Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapString.A.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.describe("String.trimStart", () => { - Mocha.test("String.trimStart", () => { - " Hello world! ".trimStart() === "Hello world! "; - " Hello world! ".trimStart() === "Hello world! "; +Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("String.trim", () => { - Mocha.test("String.trim", () => { - " abc def ".trim() === "abc def"; - "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; +Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("String.toUpperCase", () => { - Mocha.test("String.toUpperCase", () => { - "abc".toUpperCase() === "ABC"; - "Straße".toUpperCase() === "STRASSE"; - "πς".toUpperCase() === "ΠΣ"; +Mocha.describe("Belt_internalMapInt.A.reduceReverse", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("String.toLowerCase", () => { - Mocha.test("String.toLowerCase", () => { - "ABC".toLowerCase() === "abc"; - "ΣΠ".toLowerCase() === "σπ"; - "ΠΣ".toLowerCase() === "πς"; +Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("String.substringToEnd", () => { - Mocha.test("String.substringToEnd", () => { - "playground".substring(4) === "ground"; - "playground".substring(-3) === "playground"; - "playground".substring(12) === ""; +Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("String.substring", () => { - Mocha.test("String.substring", () => { - "playground".substring(3, 6) === "ygr"; - "playground".substring(6, 3) === "ygr"; - "playground".substring(4, 12) === "ground"; +Mocha.describe("Belt_SortArray.strictlySortedLength", () => { + Mocha.test("Belt_SortArray.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("String.startsWithFrom", () => { - Mocha.test("String.startsWithFrom", () => { - "BuckleScript".startsWith("kle", 3) === true; - "BuckleScript".startsWith("", 3) === true; - "JavaScript".startsWith("Buckle", 2) === false; +Mocha.describe("Belt.SortArray.strictlySortedLength", () => { + Mocha.test("Belt.SortArray.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("String.startsWith", () => { - Mocha.test("String.startsWith", () => { - "BuckleScript".startsWith("Buckle") === true; - "BuckleScript".startsWith("") === true; - "JavaScript".startsWith("Buckle") === false; +Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.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", + 17399, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("String.splitByRegExpAtMost", () => { - Mocha.test("String.splitByRegExpAtMost", () => { - Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ - "Hello", - "World.", - "How" +Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 ]); }); }); -Mocha.describe("String.splitByRegExp", () => { - Mocha.test("String.splitByRegExp", () => { - Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ - "Jan", - "Feb", - "Mar" - ]); +Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; + }); +}); + +Mocha.describe("Belt_internalMapInt.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapInt.S.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.describe("String.splitAtMost", () => { - Mocha.test("String.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.describe("Belt_internalSetInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 ]); }); }); -Mocha.describe("String.split", () => { - Mocha.test("String.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.describe("Belt_internalSetInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("String.sliceToEnd", () => { - Mocha.test("String.sliceToEnd", () => { - "abcdefg".slice(4) === "efg"; - "abcdefg".slice(-2) === "fg"; - "abcdefg".slice(7) === ""; +Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("String.slice", () => { - Mocha.test("String.slice", () => { - "abcdefg".slice(2, 5) === "cde"; - "abcdefg".slice(2, 9) === "cdefg"; - "abcdefg".slice(-4, -2) === "de"; - "abcdefg".slice(5, 1) === ""; +Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("String.searchOpt", () => { - Mocha.test("String.searchOpt", () => { - Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); - $$String.searchOpt("no numbers", /\d+/) === undefined; +Mocha.describe("Belt_internalMapInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("String.search", () => { - Mocha.test("String.search", () => { - "testing 1 2 3".search(/\d+/) === 8; - "no numbers".search(/\d+/) === -1; +Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("String.unsafeReplaceRegExpBy2", () => { - Mocha.test("String.unsafeReplaceRegExpBy2", () => { - let re = /(\d+) times (\d+)/; - let matchFn = (param, group1, group2, param$1, param$2) => { - let match = Int.fromString(group1, undefined); - let match$1 = Int.fromString(group2, undefined); - if (match !== undefined && match$1 !== undefined) { - return Math.imul(match, match$1).toString(); +Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); } else { - return "???"; + return value; } }; - "7 times 6".replace(re, matchFn) === "42"; - }); -}); - -Mocha.describe("String.unsafeReplaceRegExpBy1", () => { - Mocha.test("String.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.describe("String.unsafeReplaceRegExpBy0", () => { - Mocha.test("String.unsafeReplaceRegExpBy0", () => { - let re = /[aeiou]/g; - let matchFn = (match, param, param$1) => match.toUpperCase(); - "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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", + 17524, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("String.replaceAllRegExp", () => { - Mocha.test("String.replaceAllRegExp", () => { - "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; +Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("String.replaceAll", () => { - Mocha.test("String.replaceAll", () => { - "old old string".replaceAll("old", "new") === "new new string"; - "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; +Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("String.replaceRegExp", () => { - Mocha.test("String.replaceRegExp", () => { - "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; +Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("String.replace", () => { - Mocha.test("String.replace", () => { - "old string".replace("old", "new") === "new string"; - "the cat and the dog".replace("the", "this") === "this cat and the dog"; +Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("String.repeat", () => { - Mocha.test("String.repeat", () => { - "ha".repeat(3) === "hahaha"; - "empty".repeat(0) === ""; +Mocha.describe("Belt_internalMapInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("String.normalizeForm", () => { - Mocha.test("String.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.describe("Belt_internalSetInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.normalize", () => { - Mocha.test("String.normalize", () => { - let string1 = "\u00F1"; - let string2 = "\u006E\u0303"; - if (string1 === string2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 17658, - 0 - ], - Error: new Error() - }; - } - Pervasives.assertEqual(string1.normalize(), string2.normalize()); +Mocha.describe("Date.toLocaleStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("String.match", () => { - Mocha.test("String.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" +Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 ]); - Primitive_option.fromNullable("The large container.".match(/b[aeiou]g/)) === undefined; }); }); -Mocha.describe("String.lastIndexOfFrom", () => { - Mocha.test("String.lastIndexOfFrom", () => { - "bookseller".lastIndexOf("ok", 6) === 2; - "beekeeper".lastIndexOf("ee", 8) === 4; - "beekeeper".lastIndexOf("ee", 3) === 1; - "abcdefg".lastIndexOf("xyz", 4) === -1; +Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("String.lastIndexOfOpt", () => { - Mocha.test("String.lastIndexOfOpt", () => { - Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); - Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); - $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; +Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("String.lastIndexOf", () => { - Mocha.test("String.lastIndexOf", () => { - "bookseller".lastIndexOf("ok") === 2; - "beekeeper".lastIndexOf("ee") === 4; - "abcdefg".lastIndexOf("xyz") === -1; +Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("String.indexOfFrom", () => { - Mocha.test("String.indexOfFrom", () => { - "bookseller".indexOf("ok", 1) === 2; - "bookseller".indexOf("sell", 2) === 4; - "bookseller".indexOf("sell", 5) === -1; +Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapString.S.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.describe("String.indexOfOpt", () => { - Mocha.test("String.indexOfOpt", () => { - Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); - $$String.indexOfOpt("bookseller", "xyz") === undefined; +Mocha.describe("Belt_internalMapInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("String.indexOf", () => { - Mocha.test("String.indexOf", () => { - "bookseller".indexOf("ok") === 2; - "bookseller".indexOf("sell") === 4; - "beekeeper".indexOf("ee") === 1; - "bookseller".indexOf("xyz") === -1; +Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("String.includesFrom", () => { - Mocha.test("String.includesFrom", () => { - "programmer".includes("gram", 1) === true; - "programmer".includes("gram", 4) === false; - "대한민국".includes("한", 1) === true; +Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("String.includes", () => { - Mocha.test("String.includes", () => { - "programmer".includes("gram") === true; - "programmer".includes("er") === true; - "programmer".includes("pro") === true; - "programmer.dat".includes("xyz") === false; +Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; + }); +}); + +Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetString.A.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.describe("String.endsWithFrom", () => { - Mocha.test("String.endsWithFrom", () => { - "abcd".endsWith("cd", 4) === true; - "abcde".endsWith("cd", 3) === false; - "abcde".endsWith("cde", 99) === true; - "example.dat".endsWith("ple", 7) === true; +Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapString.A.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.describe("String.endsWith", () => { - Mocha.test("String.endsWith", () => { - "BuckleScript".endsWith("Script") === true; - "BuckleShoes".endsWith("Script") === false; +Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("String.concatMany", () => { - Mocha.test("String.concatMany", () => { - "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; +Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("String.concat", () => { - Mocha.test("String.concat", () => { - "cow".concat("bell") === "cowbell"; - "Re".concat("Script") === "ReScript"; +Mocha.describe("Belt_internalMapInt.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapInt.S.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("String.codePointAt", () => { - Mocha.test("String.codePointAt", () => { - Primitive_object.equal("¿😺?".codePointAt(1), 128570); - "abc".codePointAt(5) === undefined; +Mocha.describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("String.charCodeAt", () => { - Mocha.test("String.charCodeAt", () => { - "😺".charCodeAt(0) === 55357; - Primitive_object.equal("😺".codePointAt(0), 128570); +Mocha.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleTimeString("en-US", { + timeStyle: "long" + })); + console.log(new Date().toLocaleTimeString("de", { + hour: "2-digit", + minute: "2-digit" + })); }); }); -Mocha.describe("String.charAt", () => { - Mocha.test("String.charAt", () => { - "ReScript".charAt(0) === "R"; - "Hello".charAt(12) === ""; - "JS".charAt(5) === ""; +Mocha.describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("String.getUnsafe", () => { - Mocha.test("String.getUnsafe", () => {}); -}); - -Mocha.describe("String.get", () => { - Mocha.test("String.get", () => { - Primitive_object.equal("ReScript"[0], "R"); - Primitive_object.equal("Hello"[4], "o"); +Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("String.length", () => { - Mocha.test("String.length", () => {}); -}); - -Mocha.describe("String.fromCodePointMany", () => { - Mocha.test("String.fromCodePointMany", () => { - String.fromCodePoint(54620, 44544, 128570) === "한글😺"; +Mocha.describe("Belt_internalMapString.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapString.S.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("String.fromCodePoint", () => { - Mocha.test("String.fromCodePoint", () => { - String.fromCodePoint(65) === "A"; - String.fromCodePoint(968) === "ψ"; - String.fromCodePoint(54620) === "한"; - String.fromCodePoint(128570) === "😺"; +Mocha.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("String.fromCharCodeMany", () => { - Mocha.test("String.fromCharCodeMany", () => { - String.fromCharCode(189, 43, 190, 61) === "½+¾="; - String.fromCharCode(65, 66, 67) === "ABC"; +Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.fromCharCode", () => { - Mocha.test("String.fromCharCode", () => { - String.fromCharCode(65) === "A"; - String.fromCharCode(968) === "ψ"; - String.fromCharCode(54620) === "한"; - String.fromCharCode(-64568) === "ψ"; +Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("String.make", () => { - Mocha.test("String.make", () => { - String(3.5) === "3.5"; - String([ - 1, - 2, - 3 - ]) === "1,2,3"; +Mocha.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("Type.Classify.classify", () => { - Mocha.test("Type.Classify.classify", () => { - let match = 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("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Type.typeof", () => { - Mocha.test("Type.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..."); - } +Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapString.A.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"); }); }); From 877b39b5f43200a19b8f4cc71a1c0abf51724e0e Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 23:01:04 -0300 Subject: [PATCH 09/13] fix order --- tests/docstrings_examples/DocTest.res | 2 +- tests/docstrings_examples/DocTest.res.mjs | 3 +- .../generated_mocha_test.res | 19274 ++++----- .../generated_mocha_test.res.mjs | 36086 ++++++++-------- 4 files changed, 27683 insertions(+), 27682 deletions(-) diff --git a/tests/docstrings_examples/DocTest.res b/tests/docstrings_examples/DocTest.res index 779825a748..e84dd80e50 100644 --- a/tests/docstrings_examples/DocTest.res +++ b/tests/docstrings_examples/DocTest.res @@ -156,7 +156,7 @@ let extractExamples = async () => { let main = async () => { let examples = await extractExamples() examples->Array.sort((a, b) => - String.length(a.id) > String.length(b.id) ? Ordering.fromInt(1) : Ordering.fromInt(-1) + Obj.magic(a.id) > Obj.magic(b.id) ? Ordering.fromInt(1) : Ordering.fromInt(-1) ) let testsContent = examples diff --git a/tests/docstrings_examples/DocTest.res.mjs b/tests/docstrings_examples/DocTest.res.mjs index 483d6080f3..e933248953 100644 --- a/tests/docstrings_examples/DocTest.res.mjs +++ b/tests/docstrings_examples/DocTest.res.mjs @@ -14,6 +14,7 @@ import * as ArrayUtils from "./ArrayUtils.res.mjs"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; import * as SpawnAsync from "./SpawnAsync.res.mjs"; +import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; import * as Promises from "node:fs/promises"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js"; @@ -216,7 +217,7 @@ async function extractExamples() { async function main() { let examples = await extractExamples(); examples.sort((a, b) => { - if (a.id.length > b.id.length) { + if (Primitive_object.greaterthan(a.id, b.id)) { return Ordering.fromInt(1); } else { return Ordering.fromInt(-1); diff --git a/tests/docstrings_examples/generated_mocha_test.res b/tests/docstrings_examples/generated_mocha_test.res index b5c0e9d814..42da231211 100644 --- a/tests/docstrings_examples/generated_mocha_test.res +++ b/tests/docstrings_examples/generated_mocha_test.res @@ -1,3781 +1,4254 @@ open Mocha @@warning("-32-34-60-37-109-3-44") -describe("Set.add", () => { - test("Set.add", () => { +describe("Array.at", () => { + test("Array.at", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") + ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(3)->assertEqual(None) + ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) + ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) + ["a", "b", "c"]->Array.at(-4)->assertEqual(None) } () }) }) -describe("Set.has", () => { - test("Set.has", () => { +describe("Array.concat", () => { + test("Array.concat", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") + let array1 = ["hi", "hello"] + let array2 = ["yay", "wehoo"] - switch set->Set.has("someValue") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } + let someArray = array1->Array.concat(array2) + + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) } () }) }) -describe("Map.get", () => { - test("Map.get", () => { +describe("Array.concatMany", () => { + test("Array.concatMany", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") + let array1 = ["hi", "hello"] + let array2 = ["yay"] + let array3 = ["wehoo"] - switch map->Map.get("someKey") { - | None => Console.log("Nope, didn't have it.") - | Some(value) => Console.log2("Yay, had the value, and it's:", value) - } + let someArray = array1->Array.concatMany([array2, array3]) + + Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] } () }) }) -describe("Map.has", () => { - test("Map.has", () => { +describe("Array.copy", () => { + test("Array.copy", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") + let myArray = [1, 2, 3] + let copyOfMyArray = myArray->Array.copy - switch map->Map.has("someKey") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } + copyOfMyArray->assertEqual([1, 2, 3]) + assertEqual(myArray === copyOfMyArray, false) } () }) }) -describe("Map.set", () => { - test("Map.set", () => { +describe("Array.every", () => { + test("Array.every", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") + let array = [1, 2, 3, 4] + + array + ->Array.every(num => num <= 4) + ->assertEqual(true) + + array + ->Array.every(num => num === 1) + ->assertEqual(false) } () }) }) -describe("Int.mod", () => { - test("Int.mod", () => { +describe("Array.everyWithIndex", () => { + test("Array.everyWithIndex", () => { module Test = { - Int.mod(7, 4) == 3 + let array = [1, 2, 3, 4] + + array + ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) + ->assertEqual(true) + + array + ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) + ->assertEqual(false) } () }) }) -describe("Set.make", () => { - test("Set.make", () => { +describe("Array.fill", () => { + test("Array.fill", () => { module Test = { - // You can annotate the type of your set if you want to - let mySet: Set.t = Set.make() + let myArray = [1, 2, 3, 4] - // Or you can let ReScript infer what's in your Set - let set = Set.make() - set->Set.add("Fine name") // Inferred as Set.t + myArray->Array.fill(9, ~start=1, ~end=3) + + myArray->assertEqual([1, 9, 9, 4]) } () }) }) -describe("Set.size", () => { - test("Set.size", () => { +describe("Array.fillAll", () => { + test("Array.fillAll", () => { module Test = { - let set = Set.make() - - set->Set.add("someValue") - set->Set.add("someValue") - set->Set.add("someValue2") - - let size = set->Set.size // 2 + let myArray = [1, 2, 3, 4] + myArray->Array.fillAll(9) + myArray->assertEqual([9, 9, 9, 9]) } () }) }) -describe("List.add", () => { - test("List.add", () => { +describe("Array.fillToEnd", () => { + test("Array.fillToEnd", () => { module Test = { - List.add(list{2, 3}, 1) // list{1, 2, 3} - - List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + let myArray = [1, 2, 3, 4] + myArray->Array.fillToEnd(9, ~start=1) + myArray->assertEqual([1, 9, 9, 9]) } () }) }) -describe("List.get", () => { - test("List.get", () => { +describe("Array.filter", () => { + test("Array.filter", () => { module Test = { - let abc = list{"A", "B", "C"} - - abc->List.get(1) // Some("B") - - abc->List.get(4) // None + [1, 2, 3, 4] + ->Array.filter(num => num > 2) + ->assertEqual([3, 4]) } () }) }) -describe("List.map", () => { - test("List.map", () => { +describe("Array.filterMap", () => { + test("Array.filterMap", () => { module Test = { - list{1, 2}->List.map(x => x + 1) // list{3, 4} + ["Hello", "Hi", "Good bye"] + ->Array.filterMap( + item => + switch item { + | "Hello" => Some(item->String.length) + | _ => None + }, + ) + ->assertEqual([5]) + + [1, 2, 3, 4, 5, 6] + ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) + ->assertEqual([4, 16, 36]) + + Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) + + Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) } () }) }) -describe("List.zip", () => { - test("List.zip", () => { +describe("Array.filterWithIndex", () => { + test("Array.filterWithIndex", () => { module Test = { - List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + [1, 2, 3, 4] + ->Array.filterWithIndex((num, index) => index === 0 || num === 2) + ->assertEqual([1, 2]) } () }) }) -describe("List.has", () => { - test("List.has", () => { +describe("Array.find", () => { + test("Array.find", () => { module Test = { - list{1, 2, 3}->List.has(2, (a, b) => a == b) // true + type languages = ReScript | TypeScript | JavaScript - list{1, 2, 3}->List.has(4, (a, b) => a == b) // false + let array = [ReScript, TypeScript, JavaScript] - list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true + array + ->Array.find(item => item == ReScript) + ->assertEqual(Some(ReScript)) } () }) }) -describe("Null.map", () => { - test("Null.map", () => { +describe("Array.findIndex", () => { + test("Array.findIndex", () => { module Test = { - Null.map(Null.make(3), x => x * x) // Null.make(9) - Null.map(Null.null, x => x * x) // null + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, JavaScript] + + array + ->Array.findIndex(item => item == ReScript) + ->assertEqual(0) + + array + ->Array.findIndex(item => item == TypeScript) + ->assertEqual(-1) } () }) }) -describe("Math.abs", () => { - test("Math.abs", () => { +describe("Array.findIndexOpt", () => { + test("Array.findIndexOpt", () => { module Test = { - Math.abs(-2.0) // 2.0 - Math.abs(3.0) // 3.0 + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.findIndexOpt(item => item == ReScript) + ->assertEqual(Some(0)) } () }) }) -describe("Math.cos", () => { - test("Math.cos", () => { +describe("Array.findIndexWithIndex", () => { + test("Array.findIndexWithIndex", () => { module Test = { - Math.cos(-0.0) // 1.0 - Math.cos(0.0) // 1.0 - Math.cos(1.0) // 0.5403023058681398 + type languages = ReScript | TypeScript | JavaScript + + let array = [ReScript, JavaScript] + + let isReScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) + let isTypeScriptFirst = + array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) + + assertEqual(isReScriptFirst, 0) + assertEqual(isTypeScriptFirst, -1) } () }) }) -describe("Math.exp", () => { - test("Math.exp", () => { +describe("Array.findMap", () => { + test("Array.findMap", () => { module Test = { - Math.exp(-1.0) // 0.36787944117144233 - Math.exp(0.0) // 1.0 + Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) + + Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( + Some(-6), + ) + + Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) + + Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) } () }) }) -describe("Math.log", () => { - test("Math.log", () => { +describe("Array.findWithIndex", () => { + test("Array.findWithIndex", () => { module Test = { - Math.log(-1.0)->Float.isNaN // true - Math.log(-0.0)->Float.isFinite // false - Math.log(0.0)->Float.isFinite // false - Math.log(1.0) // 0 + type languages = ReScript | TypeScript | JavaScript + + let array = [TypeScript, JavaScript, ReScript] + + array + ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) + ->assertEqual(Some(ReScript)) } () }) }) -describe("Math.min", () => { - test("Math.min", () => { +describe("Array.flat", () => { + test("Array.flat", () => { module Test = { - Math.min(1.0, 2.0) // 1.0 - Math.min(-1.0, -2.0) // -2.0 + [[1], [2], [3, 4]] + ->Array.flat + ->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Math.max", () => { - test("Math.max", () => { +describe("Array.flatMap", () => { + test("Array.flatMap", () => { module Test = { - Math.max(1.0, 2.0) // 2.0 - Math.max(-1.0, -2.0) // -1.0 + type language = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.flatMap( + item => + switch item { + | ReScript => [1, 2, 3] + | TypeScript => [4, 5, 6] + | JavaScript => [7, 8, 9] + }, + ) + ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) } () }) }) -describe("Math.pow", () => { - test("Math.pow", () => { +describe("Array.flatMapWithIndex", () => { + test("Array.flatMapWithIndex", () => { module Test = { - Math.pow(2.0, ~exp=4.0) // 16.0 - Math.pow(3.0, ~exp=4.0) // 81.0 + type language = ReScript | TypeScript | JavaScript + + let array = [ReScript, TypeScript, JavaScript] + + array + ->Array.flatMapWithIndex( + (item, index) => + switch item { + | ReScript => [index] + | TypeScript => [index, index + 1] + | JavaScript => [index, index + 1, index + 2] + }, + ) + ->assertEqual([0, 1, 2, 2, 3, 4]) } () }) }) -describe("Math.sin", () => { - test("Math.sin", () => { +describe("Array.forEach", () => { + test("Array.forEach", () => { module Test = { - Math.sin(-0.0) // -0.0 - Math.sin(0.0) // 0.0 - Math.sin(1.0) // 0.8414709848078965 + let array = ["Hello", "Hi", "Good bye"] + + array->Array.forEach( + item => { + Console.log(item) + }, + ) } () }) }) -describe("Math.tan", () => { - test("Math.tan", () => { +describe("Array.forEachWithIndex", () => { + test("Array.forEachWithIndex", () => { module Test = { - Math.tan(-0.0) // -0.0 - Math.tan(0.0) // 0.0 - Math.tan(1.0) // 1.5574077246549023 + let array = ["Hello", "Hi", "Good bye"] + + array->Array.forEachWithIndex( + (item, index) => { + Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) + }, + ) } () }) }) -describe("Map.make", () => { - test("Map.make", () => { +describe("Array.fromInitializer", () => { + test("Array.fromInitializer", () => { module Test = { - `make()` - // You can annotate the type of your map if you want to - let myMap: Map.t = Map.make() + Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) - // Or you can let ReScript infer what's in your map - let map = Map.make() - map->Map.set("lang", "ReScript") // Inferred as Map.t + Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) } () }) }) -describe("Map.size", () => { - test("Map.size", () => { +describe("Array.fromIterator", () => { + test("Array.fromIterator", () => { module Test = { - let map = Map.make() - - map->Map.set("someKey", "someValue") - - let size = map->Map.size // 1 + Map.fromArray([("foo", 1), ("bar", 2)]) + ->Map.values + ->Array.fromIterator + ->assertEqual([1, 2]) } () }) }) -describe("Map.keys", () => { - test("Map.keys", () => { +describe("Array.get", () => { + test("Array.get", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let keys = map->Map.keys + let array = ["Hello", "Hi", "Good bye"] - // Logs the first key - Console.log(Iterator.next(keys).value) + array + ->Array.get(0) + ->assertEqual(Some("Hello")) - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. - Console.log(map->Map.keys->Iterator.toArray) + array + ->Array.get(3) + ->assertEqual(None) } () }) }) -describe("Dict.get", () => { - test("Dict.get", () => { +describe("Array.getUnsafe", () => { + test("Array.getUnsafe", () => { module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - switch dict->Dict.get("someKey") { - | None => Console.log("Nope, didn't have the key.") - | Some(value) => Console.log(value) + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.getUnsafe(index) + Console.log(value) } } () }) }) -describe("Dict.set", () => { - test("Dict.set", () => { +describe("Array.includes", () => { + test("Array.includes", () => { module Test = { - let dict = Dict.make() + [1, 2]->Array.includes(1)->assertEqual(true) + [1, 2]->Array.includes(3)->assertEqual(false) - dict->Dict.set("someKey", "someValue") + [{"language": "ReScript"}] + ->Array.includes({"language": "ReScript"}) + ->assertEqual(false) // false, because of strict equality } () }) }) -describe("Belt.Set", () => { - test("Belt.Set", () => { +describe("Array.indexOf", () => { + test("Array.indexOf", () => { module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) - - let mySet = Belt.Set.make(~id=module(PairComparator)) - let mySet2 = Belt.Set.add(mySet, (1, 2)) + [1, 2]->Array.indexOf(2)->assertEqual(1) + [1, 2]->Array.indexOf(3)->assertEqual(-1) - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + [{"language": "ReScript"}] + ->Array.indexOf({"language": "ReScript"}) + ->assertEqual(-1) // -1, because of strict equality } () }) }) -describe("Array.at", () => { - test("Array.at", () => { +describe("Array.indexOfOpt", () => { + test("Array.indexOfOpt", () => { module Test = { - ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(3)->assertEqual(None) - ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(-4)->assertEqual(None) + [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) + [1, 2]->Array.indexOfOpt(3)->assertEqual(None) + [{"language": "ReScript"}] + ->Array.indexOfOpt({"language": "ReScript"}) + ->assertEqual(None) // None, because of strict equality } () }) }) -describe("Set.clear", () => { - test("Set.clear", () => { +describe("Array.join", () => { + test("Array.join", () => { module Test = { - let set = Set.make() - - set->Set.add("someKey") - set->Set.size // 1 - - set->Set.clear - set->Set.size // 0 + ["One", "Two", "Three"] + ->Array.join(" -- ") + ->assertEqual("One -- Two -- Three") } () }) }) -describe("Object.is", () => { - test("Object.is", () => { +describe("Array.joinUnsafe", () => { + test("Array.joinUnsafe", () => { module Test = { - Object.is(25, 13) // false - Object.is("abc", "abc") // true - Object.is(undefined, undefined) // true - Object.is(undefined, null) // false - Object.is(-0.0, 0.0) // false - Object.is(list{1, 2}, list{1, 2}) // false - - Object.is([1, 2, 3], [1, 2, 3]) // false - [1, 2, 3] == [1, 2, 3] // true - [1, 2, 3] === [1, 2, 3] // false - - let fruit = {"name": "Apple"} - Object.is(fruit, fruit) // true - Object.is(fruit, {"name": "Apple"}) // false - fruit == {"name": "Apple"} // true - fruit === {"name": "Apple"} // false + [1, 2, 3] + ->Array.joinUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") } () }) }) -describe("List.size", () => { - test("List.size", () => { +describe("Array.joinWith", () => { + test("Array.joinWith", () => { module Test = { - List.size(list{1, 2, 3}) // 3 + ["One", "Two", "Three"] + ->Array.joinWith(" -- ") + ->assertEqual("One -- Two -- Three") } () }) }) -describe("List.head", () => { - test("List.head", () => { +describe("Array.joinWithUnsafe", () => { + test("Array.joinWithUnsafe", () => { module Test = { - List.head(list{}) // None - List.head(list{1, 2, 3}) // Some(1) + [1, 2, 3] + ->Array.joinWithUnsafe(" -- ") + ->assertEqual("1 -- 2 -- 3") } () }) }) -describe("List.tail", () => { - test("List.tail", () => { +describe("Array.keepSome", () => { + test("Array.keepSome", () => { module Test = { - List.tail(list{1, 2, 3}) // Some(list{2, 3}) + Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) - List.tail(list{}) // None + Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) + + Array.keepSome([None, None, None])->assertEqual([]) + + Array.keepSome([])->assertEqual([]) } () }) }) -describe("List.make", () => { - test("List.make", () => { +describe("Array.last", () => { + test("Array.last", () => { module Test = { - List.make(~length=3, 1) // list{1, 1, 1} + ["Hello", "Hi", "Good bye"] + ->Array.last + ->assertEqual(Some("Good bye")) + + [] + ->Array.last + ->assertEqual(None) } () }) }) -describe("List.drop", () => { - test("List.drop", () => { +describe("Array.length", () => { + test("Array.length", () => { module Test = { - list{1, 2, 3}->List.drop(2) // Some(list{3}) - - list{1, 2, 3}->List.drop(3) // Some(list{}) + let someArray = ["hi", "hello"] - list{1, 2, 3}->List.drop(4) // None + someArray + ->Array.length + ->assertEqual(2) } () }) }) -describe("List.take", () => { - test("List.take", () => { +describe("Array.make", () => { + test("Array.make", () => { module Test = { - list{1, 2, 3}->List.take(1) // Some(list{1}) - - list{1, 2, 3}->List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->List.take(4) // None + Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) + Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) } () }) }) -describe("List.flat", () => { - test("List.flat", () => { +describe("Array.map", () => { + test("Array.map", () => { module Test = { - List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = array->Array.map(greeting => greeting ++ " to you") + + assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) } () }) }) -describe("List.some", () => { - test("List.some", () => { +describe("Array.mapWithIndex", () => { + test("Array.mapWithIndex", () => { module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->List.some(isAbove100) // true + let array = ["Hello", "Hi", "Good bye"] + let mappedArray = + array->Array.mapWithIndex( + (greeting, index) => greeting ++ " at position " ++ Int.toString(index), + ) - list{1, 2, 3, 4}->List.some(isAbove100) // false + assertEqual( + mappedArray, + ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], + ) } () }) }) -describe("List.find", () => { - test("List.find", () => { +describe("Array.pop", () => { + test("Array.pop", () => { module Test = { - List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) + let someArray = ["hi", "hello"] - List.find(list{1, 4, 3, 2}, x => x > 4) // None + someArray + ->Array.pop + ->assertEqual(Some("hello")) + + someArray->assertEqual(["hi"]) // Notice last item is gone. } () }) }) -describe("List.sort", () => { - test("List.sort", () => { +describe("Array.push", () => { + test("Array.push", () => { module Test = { - List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} + let someArray = ["hi", "hello"] + + someArray->Array.push("yay") + + someArray->assertEqual(["hi", "hello", "yay"]) } () }) }) -describe("Null.null", () => { - test("Null.null", () => { +describe("Array.pushMany", () => { + test("Array.pushMany", () => { module Test = { - Console.log(null) // Logs `null` to the console. + let someArray = ["hi", "hello"] + + someArray->Array.pushMany(["yay", "wehoo"]) + someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) } () }) }) -describe("Null.make", () => { - test("Null.make", () => { +describe("Array.reduce", () => { + test("Array.reduce", () => { module Test = { - let myStr = "Hello" - let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. + Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) + + Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") + + [1, 2, 3] + ->Array.reduce(list{}, List.add) + ->assertEqual(list{3, 2, 1}) + + Array.reduce([], list{}, List.add)->assertEqual(list{}) } () }) }) -describe("Math.acos", () => { - test("Math.acos", () => { +describe("Array.reduceRight", () => { + test("Array.reduceRight", () => { module Test = { - Math.acos(-1.0) // 3.141592653589793 - Math.acos(-3.0)->Float.isNaN // true + Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") + + Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) + + Array.reduceRight([], list{}, List.add)->assertEqual(list{}) } () }) }) -describe("Math.asin", () => { - test("Math.asin", () => { +describe("Array.reduceRightWithIndex", () => { + test("Array.reduceRightWithIndex", () => { module Test = { - Math.asin(-1.0) // -1.5707963267948966 - Math.asin(-2.0)->Float.isNaN // true + Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceRightWithIndex( + [], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{}) } () }) }) -describe("Math.atan", () => { - test("Math.atan", () => { +describe("Array.reduceWithIndex", () => { + test("Array.reduceWithIndex", () => { module Test = { - Math.atan(-0.0) // -0.0 - Math.atan(0.0) // 0.0 - Math.atan(1.0) // 0.7853981633974483 + Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) + + Array.reduceWithIndex( + [1, 2, 3], + list{}, + (acc, v, i) => list{v + i, ...acc}, + )->assertEqual(list{5, 3, 1}) + + Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) } () }) }) -describe("Math.cbrt", () => { - test("Math.cbrt", () => { +describe("Array.reverse", () => { + test("Array.reverse", () => { module Test = { - Math.cbrt(-1.0) // -1.0 - Math.cbrt(-0.0) // -0.0 - Math.cbrt(0.0) // 0.0 + let someArray = ["hi", "hello"] + someArray->Array.reverse + + someArray->assertEqual(["hello", "hi"]) } () }) }) -describe("Math.ceil", () => { - test("Math.ceil", () => { +describe("Array.set", () => { + test("Array.set", () => { module Test = { - Math.ceil(3.1) == 4.0 - Math.ceil(3.0) == 3.0 - Math.ceil(-3.1) == -3.0 - Math.ceil(2_150_000_000.3) == 2_150_000_001.0 + let array = ["Hello", "Hi", "Good bye"] + array->Array.set(1, "Hello") + + array[1]->assertEqual(Some("Hello")) } () }) }) -describe("Math.cosh", () => { - test("Math.cosh", () => { +describe("Array.setUnsafe", () => { + test("Array.setUnsafe", () => { module Test = { - Math.cosh(-1.0) // 1.5430806348152437 - Math.cosh(-0.0) // 1.0 - Math.cosh(0.0) // 1.0 + let array = ["Hello", "Hi", "Good bye"] + array->Array.setUnsafe(1, "Hello") + + assertEqual(array[1], Some("Hello")) } () }) }) -describe("Math.log2", () => { - test("Math.log2", () => { +describe("Array.shift", () => { + test("Array.shift", () => { module Test = { - Math.log2(-2.0)->Float.isNaN // true - Math.log2(-0.0)->Float.isFinite // false - Math.log2(0.0)->Float.isFinite // false - Math.log2(1.0) // 0.0 + let someArray = ["hi", "hello"] + + someArray + ->Array.shift + ->assertEqual(Some("hi")) + + someArray->assertEqual(["hello"]) // Notice first item is gone. } () }) }) -describe("Math.sign", () => { - test("Math.sign", () => { +describe("Array.shuffle", () => { + test("Array.shuffle", () => { module Test = { - Math.sign(3.0) // 1.0 - Math.sign(-3.0) // 1.0 - Math.sign(0.0) // 0.0 + let array = ["Hello", "Hi", "Good bye"] + array->Array.shuffle + Console.log(array) + + let array2 = [1, 2, 3] + array2->Array.shuffle + + array2 + ->Array.length + ->assertEqual(3) } () }) }) -describe("Math.sinh", () => { - test("Math.sinh", () => { +describe("Array.slice", () => { + test("Array.slice", () => { module Test = { - Math.sinh(-0.0) // -0.0 - Math.sinh(0.0) // 0.0 - Math.sinh(1.0) // 1.1752011936438014 + [1, 2, 3, 4] + ->Array.slice(~start=1, ~end=3) + ->assertEqual([2, 3]) } () }) }) -describe("Math.sqrt", () => { - test("Math.sqrt", () => { +describe("Array.sliceToEnd", () => { + test("Array.sliceToEnd", () => { module Test = { - Math.sqrt(-1.0)->Float.isNaN // true - Math.sqrt(-0.0) // -0.0 - Math.sqrt(0.0) // 0.0 - Math.sqrt(1.0) // 1.0 - Math.sqrt(9.0) // 3.0 + [1, 2, 3, 4] + ->Array.sliceToEnd(~start=1) + ->assertEqual([2, 3, 4]) } () }) }) -describe("Math.tanh", () => { - test("Math.tanh", () => { +describe("Array.some", () => { + test("Array.some", () => { module Test = { - Math.tanh(-0.0) // -0.0 - Math.tanh(0.0) // 0.0 - Math.tanh(1.0) // 0.7615941559557649 + let array = ["Hello", "Hi", "Good bye"] + + array + ->Array.some(greeting => greeting === "Hello") + ->assertEqual(true) } () }) }) -describe("Map.clear", () => { - test("Map.clear", () => { +describe("Array.someWithIndex", () => { + test("Array.someWithIndex", () => { module Test = { - let map = Map.make() - - map->Map.set("someKey", "someValue") - map->Map.size // 1 + let array = ["Hello", "Hi", "Good bye"] - map->Map.clear - map->Map.size // 0 + array + ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) + ->assertEqual(true) } () }) }) -describe("Int.range", () => { - test("Int.range", () => { +describe("Array.sort", () => { + test("Array.sort", () => { module Test = { - Int.range(3, 6) == [3, 4, 5] - Int.range(-3, -1) == [-3, -2] - Int.range(3, 1) == [3, 2] - Int.range(3, 7, ~options={step: 2}) == [3, 5] - Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] - Int.range(3, 6, ~options={step: -2}) // RangeError + let array = [3, 2, 1] + array->Array.sort((a, b) => float(a - b)) + array->assertEqual([1, 2, 3]) } () }) }) -describe("Int.clamp", () => { - test("Int.clamp", () => { +describe("Array.toShuffled", () => { + test("Array.toShuffled", () => { module Test = { - Int.clamp(42) == 42 - Int.clamp(42, ~min=50) == 50 - Int.clamp(42, ~max=40) == 40 - Int.clamp(42, ~min=50, ~max=40) == 50 + let array = ["Hello", "Hi", "Good bye"] + let shuffledArray = array->Array.toShuffled + Console.log(shuffledArray) + + Array.toShuffled([1, 2, 3]) + ->Array.length + ->assertEqual(3) } () }) }) -describe("Float.mod", () => { - test("Float.mod", () => { +describe("Array.toString", () => { + test("Array.toString", () => { module Test = { - Float.mod(7.0, 4.0) == 3.0 + [1, 2, 3, 4] + ->Array.toString + ->assertEqual("1,2,3,4") } () }) }) -describe("Date.make", () => { - test("Date.make", () => { +describe("Array.unsafe_get", () => { + test("Array.unsafe_get", () => { module Test = { - Date.make() + let array = [1, 2, 3] + for index in 0 to array->Array.length - 1 { + let value = array->Array.unsafe_get(index) + Console.log(value) + } } () }) }) -describe("Dict.make", () => { - test("Dict.make", () => { +describe("Array.unshift", () => { + test("Array.unshift", () => { module Test = { - let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want - - let dict2 = Dict.make() // Or you can let ReScript infer it via usage. - dict2->Dict.set("someKey", 12) + let someArray = ["hi", "hello"] + someArray->Array.unshift("yay") + someArray->assertEqual(["yay", "hi", "hello"]) } () }) }) -describe("Dict.copy", () => { - test("Dict.copy", () => { +describe("Array.unshiftMany", () => { + test("Array.unshiftMany", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let dict2 = dict->Dict.copy - - // Both log `["key1", "key2"]` here. - Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) + let someArray = ["hi", "hello"] + someArray->Array.unshiftMany(["yay", "wehoo"]) + someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) } () }) }) -describe("Array.pop", () => { - test("Array.pop", () => { +describe("AsyncIterator.done", () => { + test("AsyncIterator.done", () => { module Test = { - let someArray = ["hi", "hello"] + let context = ref(0) - someArray - ->Array.pop - ->assertEqual(Some("hello")) + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 - someArray->assertEqual(["hi"]) // Notice last item is gone. + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) } () }) }) -describe("Array.map", () => { - test("Array.map", () => { +describe("AsyncIterator.forEach", () => { + test("AsyncIterator.forEach", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = array->Array.map(greeting => greeting ++ " to you") + // Let's pretend we get an async iterator returning ints from somewhere. + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); - assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + let main = async () => + await asyncIterator->AsyncIterator.forEach( + v => { + switch v { + | Some(("second", value)) => assertEqual(value, "2") + | _ => () + } + }, + ) + + main()->ignore } () }) }) -describe("Array.get", () => { - test("Array.get", () => { +describe("AsyncIterator.make", () => { + test("AsyncIterator.make", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] + let context = ref(0) - array - ->Array.get(0) - ->assertEqual(Some("Hello")) + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 - array - ->Array.get(3) - ->assertEqual(None) + { + AsyncIterator.value: Some(currentValue), + done: currentValue >= 3, + } + }, + ) + + // This will log 1, 2, 3 + let main = async () => + await asyncIterator->AsyncIterator.forEach( + value => + switch value { + | Some(value) => Console.log(value) + | None => () + }, + ) + + main()->ignore } () }) }) -describe("Array.set", () => { - test("Array.set", () => { +describe("AsyncIterator.next", () => { + test("AsyncIterator.next", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.set(1, "Hello") + let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); - array[1]->assertEqual(Some("Hello")) + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + let processMyAsyncIterator = async () => { + // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. + let break = ref(false) + + while !break.contents { + // Await the next iterator value + let {value, done} = await asyncIterator->AsyncIterator.next + + // Exit the while loop if the iterator says it's done + break := done + + if done { + value + ->Option.isNone + ->assertEqual(true) + } + } + } + + processMyAsyncIterator()->ignore } () }) }) -describe("String.get", () => { - test("String.get", () => { +describe("AsyncIterator.value", () => { + test("AsyncIterator.value", () => { module Test = { - String.get("ReScript", 0) == Some("R") - String.get("Hello", 4) == Some("o") - String.get(`JS`, 4) == None + let context = ref(0) + + let asyncIterator = AsyncIterator.make( + async () => { + let currentValue = context.contents + // Increment current value + context := currentValue + 1 + + if currentValue >= 3 { + AsyncIterator.done() + } else { + AsyncIterator.value(currentValue) + } + }, + ) } () }) }) -describe("Set.delete", () => { - test("Set.delete", () => { +describe("Belt.Array.blit", () => { + test("Belt.Array.blit", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - let didDeleteValue = set->Set.delete("someValue") - Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - let didDeleteValue = set->Set.delete("someNonExistantKey") - Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Set.values", () => { - test("Set.values", () => { +describe("Belt.Array.cmp", () => { + test("Belt.Array.cmp", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("anotherValue") - - let values = set->Set.values + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - // Logs the first value - Console.log(Iterator.next(values).value) + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(set->Set.values->Iterator.toArray) + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Result.map", () => { - test("Result.map", () => { +describe("Belt.Array.concat", () => { + test("Belt.Array.concat", () => { module Test = { - let f = x => sqrt(Int.toFloat(x)) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - Result.map(Ok(64), f) == Ok(8.0) - - Result.map(Error("Invalid data"), f) == Error("Invalid data") + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Result.all", () => { - test("Result.all", () => { +describe("Belt.Array.concatMany", () => { + test("Belt.Array.concatMany", () => { module Test = { - Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) - Result.all([Ok(1), Error(1)]) // Error(1) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Option.map", () => { - test("Option.map", () => { +describe("Belt.Array.eq", () => { + test("Belt.Array.eq", () => { module Test = { - Option.map(Some(3), x => x * x) // Some(9) - Option.map(None, x => x * x) // None + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Option.all", () => { - test("Option.all", () => { +describe("Belt.Array.every", () => { + test("Belt.Array.every", () => { module Test = { - Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) - Option.all([Some(1), None]) // None - } - () - }) -}) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true -describe("Object.get", () => { - test("Object.get", () => { - module Test = { - {"a": 1}->Object.get("a") // Some(1) - {"a": 1}->Object.get("b") // None - {"a": undefined}->Object.get("a") // None - {"a": null}->Object.get("a") // Some(null) - {"a": 1}->Object.get("toString")->Option.isSome // true + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Object.set", () => { - test("Object.set", () => { +describe("Belt.Array.every2", () => { + test("Belt.Array.every2", () => { module Test = { - {"a": 1}->Object.set("a", 2) // {"a": 2} - {"a": 1}->Object.set("a", None) // {"a": None} - {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} + 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 } () }) }) -describe("List.zipBy", () => { - test("List.zipBy", () => { +describe("Belt.Array.fill", () => { + test("Belt.Array.fill", () => { module Test = { - List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("List.every", () => { - test("List.every", () => { +describe("Belt.Array.flatMap", () => { + test("Belt.Array.flatMap", () => { module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->List.every(isBelow10) // true - - list{1, 99, 8, 2}->List.every(isBelow10) // false + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("List.some2", () => { - test("List.some2", () => { +describe("Belt.Array.forEach", () => { + test("Belt.Array.forEach", () => { module Test = { - List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - List.some2(list{}, list{1}, (a, b) => a > b) // false + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("List.equal", () => { - test("List.equal", () => { +describe("Belt.Array.forEachWithIndex", () => { + test("Belt.Array.forEachWithIndex", () => { module Test = { - List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) - List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("List.unzip", () => { - test("List.unzip", () => { +describe("Belt.Array.get", () => { + test("Belt.Array.get", () => { module Test = { - List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) - - List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Null.getOr", () => { - test("Null.getOr", () => { +describe("Belt.Array.getBy", () => { + test("Belt.Array.getBy", () => { module Test = { - Null.getOr(Null.null, "Banana") // Banana - Null.getOr(Null.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Null.make("Jane")->Null.toOption->greet // "Greetings Jane" - Null.null->Null.toOption->greet // "Greetings Anonymous" + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Null.mapOr", () => { - test("Null.mapOr", () => { +describe("Belt.Array.getIndexBy", () => { + test("Belt.Array.getIndexBy", () => { module Test = { - let someValue = Null.make(3) - someValue->Null.mapOr(0, x => x + 5) // 8 - - let noneValue = Null.null - noneValue->Null.mapOr(0, x => x + 5) // 0 + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Math.acosh", () => { - test("Math.acosh", () => { +describe("Belt.Array.joinWith", () => { + test("Belt.Array.joinWith", () => { module Test = { - Math.acosh(1.0) // 0.0 - Math.acosh(0.5)->Float.isNaN // true + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Math.asinh", () => { - test("Math.asinh", () => { +describe("Belt.Array.keepMap", () => { + test("Belt.Array.keepMap", () => { module Test = { - Math.asinh(-1.0) // -0.881373587019543 - Math.asinh(-0.0) // -0.0 + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Math.atanh", () => { - test("Math.atanh", () => { +describe("Belt.Array.keepWithIndex", () => { + test("Belt.Array.keepWithIndex", () => { module Test = { - Math.atanh(-2.0)->Float.isNaN // true - Math.atanh(-1.0)->Float.isFinite // false - Math.atanh(-0.0) // -0.0 - Math.atanh(0.0) // 0.0 - Math.atanh(0.5) // 0.5493061443340548 + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Math.atan2", () => { - test("Math.atan2", () => { +describe("Belt.Array.length", () => { + test("Belt.Array.length", () => { module Test = { - Math.atan2(~y=0.0, ~x=10.0) == 0.0 - Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 - Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 - Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Math.expm1", () => { - test("Math.expm1", () => { +describe("Belt.Array.makeBy", () => { + test("Belt.Array.makeBy", () => { module Test = { - Math.expm1(-1.0) // -0.6321205588285577 - Math.expm1(-0.0) // -0 + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Math.floor", () => { - test("Math.floor", () => { +describe("Belt.Array.makeUninitialized", () => { + test("Belt.Array.makeUninitialized", () => { module Test = { - Math.floor(-45.95) // -46.0 - Math.floor(-45.05) // -46.0 - Math.floor(-0.0) // -0.0 + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Math.hypot", () => { - test("Math.hypot", () => { +describe("Belt.Array.makeUninitializedUnsafe", () => { + test("Belt.Array.makeUninitializedUnsafe", () => { module Test = { - Math.hypot(3.0, 4.0) // 5.0 - Math.hypot(3.0, 5.0) // 5.8309518948453 + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Math.log1p", () => { - test("Math.log1p", () => { +describe("Belt.Array.map", () => { + test("Belt.Array.map", () => { module Test = { - Math.log1p(-2.0)->Float.isNaN // true - Math.log1p(-1.0)->Float.isFinite // false - Math.log1p(-0.0) // -0 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Math.log10", () => { - test("Math.log10", () => { +describe("Belt.Array.mapWithIndex", () => { + test("Belt.Array.mapWithIndex", () => { module Test = { - Math.log10(-2.0)->Float.isNaN // true - Math.log10(-0.0)->Float.isFinite // false - Math.log10(0.0)->Float.isFinite // false - Math.log10(1.0) // 0 + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Math.round", () => { - test("Math.round", () => { +describe("Belt.Array.partition", () => { + test("Belt.Array.partition", () => { module Test = { - Math.round(-20.5) // -20.0 - Math.round(-0.1) // -0.0 - Math.round(0.0) // 0.0 - Math.round(-0.0) // -0.0 + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Math.trunc", () => { - test("Math.trunc", () => { +describe("Belt.Array.range", () => { + test("Belt.Array.range", () => { module Test = { - Math.trunc(0.123) // 0.0 - Math.trunc(1.999) // 1.0 - Math.trunc(13.37) // 13.0 - Math.trunc(42.84) // 42.0 - } - () - }) -}) + Belt.Array.range(0, 3) == [0, 1, 2, 3] -describe("Map.delete", () => { - test("Map.delete", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - let didDeleteKey = map->Map.delete("someKey") - Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted + Belt.Array.range(3, 0) == [] - let didDeleteKey = map->Map.delete("someNonExistantKey") - Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Map.values", () => { - test("Map.values", () => { +describe("Belt.Array.rangeBy", () => { + test("Belt.Array.rangeBy", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - let values = map->Map.values + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - // Logs the first value - Console.log(Iterator.next(values).value) + Belt.Array.rangeBy(33, 0, ~step=1) == [] - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(map->Map.values->Iterator.toArray) - } - () - }) -}) + Belt.Array.rangeBy(33, 0, ~step=-1) == [] -describe("Error.name", () => { - test("Error.name", () => { - module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.name) // Logs "SyntaxError" to the console + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Error.make", () => { - test("Error.make", () => { +describe("Belt.Array.reduce", () => { + test("Belt.Array.reduce", () => { module Test = { - let error = Error.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console - Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Belt_Int.+", () => { - test("Belt_Int.+", () => { +describe("Belt.Array.reduceReverse", () => { + test("Belt.Array.reduceReverse", () => { module Test = { - open Belt.Int - assertEqual(2 + 2, 4) + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Belt_Int.-", () => { - test("Belt_Int.-", () => { +describe("Belt.Array.reduceReverse2", () => { + test("Belt.Array.reduceReverse2", () => { module Test = { - open Belt.Int - assertEqual(2 - 1, 1) + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("Belt_Int.*", () => { - test("Belt_Int.*", () => { +describe("Belt.Array.reduceWithIndex", () => { + test("Belt.Array.reduceWithIndex", () => { module Test = { - open Belt.Int - assertEqual(2 * 2, 4) + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Belt_Int./", () => { - test("Belt_Int./", () => { +describe("Belt.Array.reverse", () => { + test("Belt.Array.reverse", () => { module Test = { - open Belt.Int - assertEqual(4 / 2, 2) + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Belt.Int.+", () => { - test("Belt.Int.+", () => { +describe("Belt.Array.reverseInPlace", () => { + test("Belt.Array.reverseInPlace", () => { module Test = { - open Belt.Int - assertEqual(2 + 2, 4) + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("Belt.Int.-", () => { - test("Belt.Int.-", () => { +describe("Belt.Array.slice", () => { + test("Belt.Array.slice", () => { module Test = { - open Belt.Int - assertEqual(2 - 1, 1) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Belt.Int.*", () => { - test("Belt.Int.*", () => { +describe("Belt.Array.sliceToEnd", () => { + test("Belt.Array.sliceToEnd", () => { module Test = { - open Belt.Int - assertEqual(2 * 2, 4) + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Belt.Int./", () => { - test("Belt.Int./", () => { +describe("Belt.Array.some", () => { + test("Belt.Array.some", () => { module Test = { - open Belt.Int - assertEqual(4 / 2, 2) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Array.make", () => { - test("Array.make", () => { +describe("Belt.Array.some2", () => { + test("Belt.Array.some2", () => { module Test = { - Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) - Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) + 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 } () }) }) -describe("Array.fill", () => { - test("Array.fill", () => { +describe("Belt.Array.truncateToLengthUnsafe", () => { + test("Belt.Array.truncateToLengthUnsafe", () => { module Test = { - let myArray = [1, 2, 3, 4] + let arr = ["ant", "bee", "cat", "dog", "elk"] - myArray->Array.fill(9, ~start=1, ~end=3) + Belt.Array.truncateToLengthUnsafe(arr, 3) - myArray->assertEqual([1, 9, 9, 4]) + arr == ["ant", "bee", "cat"] } () }) }) -describe("Array.push", () => { - test("Array.push", () => { +describe("Belt.Array.unzip", () => { + test("Belt.Array.unzip", () => { module Test = { - let someArray = ["hi", "hello"] - - someArray->Array.push("yay") + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - someArray->assertEqual(["hi", "hello", "yay"]) + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Array.sort", () => { - test("Array.sort", () => { +describe("Belt.Array.zip", () => { + test("Belt.Array.zip", () => { module Test = { - let array = [3, 2, 1] - array->Array.sort((a, b) => float(a - b)) - array->assertEqual([1, 2, 3]) + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Array.flat", () => { - test("Array.flat", () => { +describe("Belt.Array.zipBy", () => { + test("Belt.Array.zipBy", () => { module Test = { - [[1], [2], [3, 4]] - ->Array.flat - ->assertEqual([1, 2, 3, 4]) + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Array.join", () => { - test("Array.join", () => { +describe("Belt.Float.*", () => { + test("Belt.Float.*", () => { module Test = { - ["One", "Two", "Three"] - ->Array.join(" -- ") - ->assertEqual("One -- Two -- Three") + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) } () }) }) -describe("Array.copy", () => { - test("Array.copy", () => { +describe("Belt.Float.+", () => { + test("Belt.Float.+", () => { module Test = { - let myArray = [1, 2, 3] - let copyOfMyArray = myArray->Array.copy - - copyOfMyArray->assertEqual([1, 2, 3]) - assertEqual(myArray === copyOfMyArray, false) + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) } () }) }) -describe("Array.find", () => { - test("Array.find", () => { +describe("Belt.Float.-", () => { + test("Belt.Float.-", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.find(item => item == ReScript) - ->assertEqual(Some(ReScript)) + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) } () }) }) -describe("Array.some", () => { - test("Array.some", () => { +describe("Belt.Float./", () => { + test("Belt.Float./", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.some(greeting => greeting === "Hello") - ->assertEqual(true) + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) } () }) }) -describe("Array.last", () => { - test("Array.last", () => { +describe("Belt.Float.fromInt", () => { + test("Belt.Float.fromInt", () => { module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.last - ->assertEqual(Some("Good bye")) - - [] - ->Array.last - ->assertEqual(None) + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ } () }) }) -describe("Type.typeof", () => { - test("Type.typeof", () => { +describe("Belt.Float.fromString", () => { + test("Belt.Float.fromString", () => { module Test = { - Console.log(Type.typeof("Hello")) // Logs "string" to the console. - - let someVariable = true - - switch someVariable->Type.typeof { - | #boolean => Console.log("This is a bool, yay!") - | _ => Console.log("Oh, not a bool sadly...") - } + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ } () }) }) -describe("String.make", () => { - test("String.make", () => { +describe("Belt.Float.toInt", () => { + test("Belt.Float.toInt", () => { module Test = { - String.make(3.5) == "3.5" - String.make([1, 2, 3]) == "1,2,3" + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ } () }) }) -describe("String.trim", () => { - test("String.trim", () => { +describe("Belt.Float.toString", () => { + test("Belt.Float.toString", () => { module Test = { - String.trim(" abc def ") == "abc def" - String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ } () }) }) -describe("Set.forEach", () => { - test("Set.forEach", () => { +describe("Belt.HashMap", () => { + test("Belt.HashMap", () => { module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("someValue2") + type t = int + module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) + let s0: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I0), + ) - set->Set.forEach( - value => { - Console.log(value) - }, + module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) + let s1: Belt.HashMap.t = Belt.HashMap.make( + ~hintSize=40, + ~id=module(I1), ) + + let () = { + Belt.HashMap.set(s0, 0, 3) + Belt.HashMap.set(s1, 1, "3") + } } () }) }) -describe("Set.toArray", () => { - test("Set.toArray", () => { +describe("Belt.HashMap.clear", () => { + test("Belt.HashMap.clear", () => { module Test = { - let set = Set.fromArray(["apple", "orange", "apple", "banana"]) - set->Set.toArray // ["apple", "orange", "banana"] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true } () }) }) -describe("RegExp.test", () => { - test("RegExp.test", () => { +describe("Belt.HashMap.copy", () => { + test("Belt.HashMap.copy", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - if regexp->RegExp.test("ReScript is cool!") { - Console.log("Yay, there's a word in there.") - } + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) } () }) }) -describe("RegExp.exec", () => { - test("RegExp.exec", () => { +describe("Belt.HashMap.forEach", () => { + test("Belt.HashMap.forEach", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") } () }) }) -describe("Promise.any", () => { - test("Promise.any", () => { +describe("Belt.HashMap.fromArray", () => { + test("Belt.HashMap.fromArray", () => { module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - any(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Promise.all", () => { - test("Promise.all", () => { +describe("Belt.HashMap.get", () => { + test("Belt.HashMap.get", () => { module Test = { - open Promise - let promises = [resolve(1), resolve(2), resolve(3)] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - all(promises) - ->then( - results => { - results->Array.forEach( - num => { - Console.log2("Number: ", num) - }, - ) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - resolve() - }, - ) - ->ignore + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None } () }) }) -describe("Object.make", () => { - test("Object.make", () => { +describe("Belt.HashMap.getBucketHistogram", () => { + test("Belt.HashMap.getBucketHistogram", () => { module Test = { - let x = Object.make() - x->Object.keysToArray->Array.length // 0 - x->Object.get("toString")->Option.isSome // true + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.getBucketHistogram(hMap) } () }) }) -describe("Object.seal", () => { - test("Object.seal", () => { +describe("Belt.HashMap.has", () => { + test("Belt.HashMap.has", () => { module Test = { - let point = {"x": 1, "y": 2} - point->Object.set("x", -7) // succeeds - point->Object.seal->ignore + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - try { - point->Object.set("z", 9) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - point->Object.set("x", 13) // succeeds + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false } () }) }) -describe("List.length", () => { - test("List.length", () => { +describe("Belt.HashMap.isEmpty", () => { + test("Belt.HashMap.isEmpty", () => { module Test = { - List.length(list{1, 2, 3}) // 3 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false } () }) }) -describe("List.getExn", () => { - test("List.getExn", () => { +describe("Belt.HashMap.keepMapInPlace", () => { + test("Belt.HashMap.keepMapInPlace", () => { module Test = { - let abc = list{"A", "B", "C"} + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - abc - ->List.getExn(1) - ->assertEqual("B") + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - switch abc->List.getExn(4) { - | exception Not_found => assert(true) - | _ => assert(false) - } + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) } () }) }) -describe("List.concat", () => { - test("List.concat", () => { +describe("Belt.HashMap.keysToArray", () => { + test("Belt.HashMap.keysToArray", () => { module Test = { - List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.keysToArray(s0) == [1, 2] } () }) }) -describe("List.reduce", () => { - test("List.reduce", () => { +describe("Belt.HashMap.logStats", () => { + test("Belt.HashMap.logStats", () => { module Test = { - list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 - - // same as + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") - list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 + Belt.HashMap.logStats(hMap) } () }) }) -describe("List.every2", () => { - test("List.every2", () => { +describe("Belt.HashMap.make", () => { + test("Belt.HashMap.make", () => { module Test = { - List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - - List.every2(list{}, list{1}, (a, b) => a > b) // true + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false + Belt.HashMap.set(hMap, 0, "a") } () }) }) -describe("List.filter", () => { - test("List.filter", () => { +describe("Belt.HashMap.mergeMany", () => { + test("Belt.HashMap.mergeMany", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) } () }) }) -describe("Null.getExn", () => { - test("Null.getExn", () => { +describe("Belt.HashMap.reduce", () => { + test("Belt.HashMap.reduce", () => { module Test = { - Null.getExn(Null.make(3))->assertEqual(3) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - switch Null.getExn(%raw("'ReScript'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "ReScript") - } + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - switch Null.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") } () }) }) -describe("Math.fround", () => { - test("Math.fround", () => { +describe("Belt.HashMap.remove", () => { + test("Belt.HashMap.remove", () => { module Test = { - Math.fround(5.5) == 5.5 - Math.fround(5.05) == 5.050000190734863 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false } () }) }) -describe("Math.random", () => { - test("Math.random", () => { +describe("Belt.HashMap.set", () => { + test("Belt.HashMap.set", () => { module Test = { - Math.random() + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] } () }) }) -describe("Map.forEach", () => { - test("Map.forEach", () => { +describe("Belt.HashMap.size", () => { + test("Belt.HashMap.size", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - map->Map.forEach( - value => { - Console.log(value) - }, - ) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.size(s0) == 2 } () }) }) -describe("Map.entries", () => { - test("Map.entries", () => { +describe("Belt.HashMap.toArray", () => { + test("Belt.HashMap.toArray", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let entries = map->Map.entries + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - // Logs the first value - Console.log(Iterator.next(entries).value) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - // You can also turn the iterator into an array. - // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. - Console.log(map->Map.entries->Iterator.toArray) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Int.toFixed", () => { - test("Int.toFixed", () => { +describe("Belt.HashMap.valuesToArray", () => { + test("Belt.HashMap.valuesToArray", () => { module Test = { - Int.toFixed(123456) // "123456.00" - Int.toFixed(10) // "10.00" - Int.toFixed(300, ~digits=4) // "300.0000" - Int.toFixed(300, ~digits=1) // "300.0" + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") + + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] } () }) }) -describe("Int.toFloat", () => { - test("Int.toFloat", () => { +describe("Belt.HashSet", () => { + test("Belt.HashSet", () => { module Test = { - Int.toFloat(100) == 100.0 - Int.toFloat(2) == 2.0 + module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) + + let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) + + module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) + + let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) + + Belt.HashSet.add(s1, 0) + Belt.HashSet.add(s1, 1) } () }) }) -describe("Float.isNaN", () => { - test("Float.isNaN", () => { +describe("Belt.Int.*", () => { + test("Belt.Int.*", () => { module Test = { - Float.isNaN(3.0) // false - Float.isNaN(Float.Constants.nan) // true + open Belt.Int + assertEqual(2 * 2, 4) } () }) }) -describe("Float.toInt", () => { - test("Float.toInt", () => { +describe("Belt.Int.+", () => { + test("Belt.Int.+", () => { module Test = { - Float.toInt(2.0) == 2 - Float.toInt(1.0) == 1 - Float.toInt(1.1) == 1 - Float.toInt(1.6) == 1 + open Belt.Int + assertEqual(2 + 2, 4) } () }) }) -describe("Float.clamp", () => { - test("Float.clamp", () => { +describe("Belt.Int.-", () => { + test("Belt.Int.-", () => { module Test = { - Float.clamp(4.2) == 4.2 - Float.clamp(4.2, ~min=4.3) == 4.3 - Float.clamp(4.2, ~max=4.1) == 4.1 - Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 + open Belt.Int + assertEqual(2 - 1, 1) } () }) }) -describe("Error.stack", () => { - test("Error.stack", () => { +describe("Belt.Int./", () => { + test("Belt.Int./", () => { module Test = { - let error = Error.make("error") - Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` + open Belt.Int + assertEqual(4 / 2, 2) } () }) }) -describe("Error.raise", () => { - test("Error.raise", () => { +describe("Belt.Int.fromFloat", () => { + test("Belt.Int.fromFloat", () => { module Test = { - let error = Error.make("Everything is upside down.") - - if 5 > 10 { - error->Error.raise - } else { - Console.log("Phew, sanity still rules.") - } + Belt.Int.fromFloat(1.0)->assertEqual(1) } () }) }) -describe("Error.panic", () => { - test("Error.panic", () => { +describe("Belt.Int.fromString", () => { + test("Belt.Int.fromString", () => { module Test = { - try { - Error.panic("Uh oh. This was unexpected!") - } catch { - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") - | None => assert(false) - } - | _ => assert(false) - } + Belt.Int.fromString("1")->assertEqual(Some(1)) } () }) }) -describe("Date.getDay", () => { - test("Date.getDay", () => { +describe("Belt.Int.toFloat", () => { + test("Belt.Int.toFloat", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDay - // 1 + Belt.Int.toFloat(1)->assertEqual(1.0) } () }) }) -describe("Date.toJSON", () => { - test("Date.toJSON", () => { +describe("Belt.Int.toString", () => { + test("Belt.Int.toString", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON - // Some("2023-01-01T00:00:00.000Z") - - Date.fromString("")->Date.toJSON - // None + Belt.Int.toString(1)->assertEqual("1") } () }) }) -describe("Dict.delete", () => { - test("Dict.delete", () => { +describe("Belt.List.add", () => { + test("Belt.List.add", () => { module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - dict->Dict.delete("someKey") + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Dict.assign", () => { - test("Dict.assign", () => { +describe("Belt.List.cmp", () => { + test("Belt.List.cmp", () => { module Test = { - let dict1 = Dict.make() - dict1->Dict.set("firstKey", 1) - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - let dict2 = Dict.make() - dict2->Dict.set("someKey", 2) - dict2->Dict.set("someKey2", 3) + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - let dict1 = dict1->Dict.assign(dict2) + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ } () }) }) -describe("Console.dir", () => { - test("Console.dir", () => { +describe("Belt.List.cmpByLength", () => { + test("Belt.List.cmpByLength", () => { module Test = { - Console.dir({"language": "rescript", "version": "10.1.2"}) + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ + + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ + + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ } () }) }) -describe("Console.log", () => { - test("Console.log", () => { +describe("Belt.List.concat", () => { + test("Belt.List.concat", () => { module Test = { - Console.log("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.log(obj) + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("Belt_Set.eq", () => { - test("Belt_Set.eq", () => { +describe("Belt.List.concatMany", () => { + test("Belt.List.concatMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.Set.eq(s0, s1)->assertEqual(true) + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Belt.Option", () => { - test("Belt.Option", () => { +describe("Belt.List.drop", () => { + test("Belt.List.drop", () => { module Test = { - type option<'a> = None | Some('a) + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - let someString: option = Some("hello") + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + + list{1, 2, 3}->Belt.List.drop(4) // None } () }) }) -describe("Belt.Set.eq", () => { - test("Belt.Set.eq", () => { +describe("Belt.List.eq", () => { + test("Belt.List.eq", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - Belt.Set.eq(s0, s1)->assertEqual(true) + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Array.shift", () => { - test("Array.shift", () => { +describe("Belt.List.every", () => { + test("Belt.List.every", () => { module Test = { - let someArray = ["hi", "hello"] + let isBelow10 = value => value < 10 - someArray - ->Array.shift - ->assertEqual(Some("hi")) + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - someArray->assertEqual(["hello"]) // Notice first item is gone. + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ } () }) }) -describe("Array.slice", () => { - test("Array.slice", () => { +describe("Belt.List.every2", () => { + test("Belt.List.every2", () => { module Test = { - [1, 2, 3, 4] - ->Array.slice(~start=1, ~end=3) - ->assertEqual([2, 3]) + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ } () }) }) -describe("Array.every", () => { - test("Array.every", () => { +describe("Belt.List.filter", () => { + test("Belt.List.filter", () => { module Test = { - let array = [1, 2, 3, 4] + let isEven = x => mod(x, 2) == 0 - array - ->Array.every(num => num <= 4) - ->assertEqual(true) + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - array - ->Array.every(num => num === 1) - ->assertEqual(false) + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("String.match", () => { - test("String.match", () => { +describe("Belt.List.filterWithIndex", () => { + test("Belt.List.filterWithIndex", () => { module Test = { - String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) - String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) - String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == - Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) - String.match("The optional example", /(foo)?(example)/) == - Some([Some("example"), None, Some("example")]) - String.match("The large container.", /b[aeiou]g/) == None + let isEven = x => mod(x, 2) == 0 + + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("String.slice", () => { - test("String.slice", () => { +describe("Belt.List.flatten", () => { + test("Belt.List.flatten", () => { module Test = { - String.slice("abcdefg", ~start=2, ~end=5) == "cde" - String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" - String.slice("abcdefg", ~start=-4, ~end=-2) == "de" - String.slice("abcdefg", ~start=5, ~end=1) == "" + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("String.split", () => { - test("String.split", () => { +describe("Belt.List.forEach", () => { + test("Belt.List.forEach", () => { module Test = { - String.split("2018-01-02", "-") == ["2018", "01", "02"] - String.split("a,b,,c", ",") == ["a", "b", "", "c"] - String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] - String.split("has-no-delimiter", ";") == ["has-no-delimiter"] + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("Result.mapOr", () => { - test("Result.mapOr", () => { +describe("Belt.List.forEach2", () => { + test("Belt.List.forEach2", () => { module Test = { - let ok = Ok(42) - Result.mapOr(ok, 0, x => x / 2) == 21 + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - let error = Error("Invalid data") - Result.mapOr(error, 0, x => x / 2) == 0 + /* + prints: + "Z" "A" + "Y" "B" +*/ } () }) }) -describe("Result.getOr", () => { - test("Result.getOr", () => { +describe("Belt.List.forEachWithIndex", () => { + test("Belt.List.forEachWithIndex", () => { module Test = { - Result.getOr(Ok(42), 0) == 42 - - Result.getOr(Error("Invalid Data"), 0) == 0 + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ } () }) }) -describe("Result.equal", () => { - test("Result.equal", () => { +describe("Belt.List.fromArray", () => { + test("Belt.List.fromArray", () => { module Test = { - let good1 = Ok(42) - - let good2 = Ok(32) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + } + () + }) +}) - let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) +describe("Belt.List.get", () => { + test("Belt.List.get", () => { + module Test = { + let abc = list{"A", "B", "C"} - Result.equal(good1, good2, mod10equal) == true + abc->Belt.List.get(1) // Some("B") - Result.equal(good1, bad1, mod10equal) == false + abc->Belt.List.get(4) // None + } + () + }) +}) - Result.equal(bad2, good2, mod10equal) == false +describe("Belt.List.getAssoc", () => { + test("Belt.List.getAssoc", () => { + module Test = { + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - Result.equal(bad1, bad2, mod10equal) == true + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ } () }) }) -describe("Promise.make", () => { - test("Promise.make", () => { +describe("Belt.List.getBy", () => { + test("Belt.List.getBy", () => { module Test = { - open Promise + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ - let n = 4 - Promise.make( - (resolve, reject) => { - if n < 5 { - resolve("success") - } else { - reject("failed") - } - }, - ) - ->then( - str => { - Console.log(str)->resolve - }, - ) - ->catch( - _ => { - Console.log("Error occurred") - resolve() - }, - ) - ->ignore + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ } () }) }) -describe("Promise.then", () => { - test("Promise.then", () => { +describe("Belt.List.getExn", () => { + test("Belt.List.getExn", () => { module Test = { - open Promise - resolve(5) - ->then( - num => { - resolve(num + 5) - }, - ) - ->then( - num => { - Console.log2("Your lucky number is: ", num) - resolve() - }, - ) - ->ignore + let abc = list{"A", "B", "C"} + + abc->Belt.List.getExn(1)->assertEqual("B") + + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Promise.race", () => { - test("Promise.race", () => { +describe("Belt.List.has", () => { + test("Belt.List.has", () => { module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ - race(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Option.mapOr", () => { - test("Option.mapOr", () => { +describe("Belt.List.hasAssoc", () => { + test("Belt.List.hasAssoc", () => { module Test = { - let someValue = Some(3) - someValue->Option.mapOr(0, x => x + 5) // 8 + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ - let noneValue = None - noneValue->Option.mapOr(0, x => x + 5) // 0 + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ } () }) }) -describe("Option.getOr", () => { - test("Option.getOr", () => { +describe("Belt.List.head", () => { + test("Belt.List.head", () => { module Test = { - Option.getOr(None, "Banana") // Banana - Option.getOr(Some("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Some("Jane")->greet // "Greetings Jane" - None->greet // "Greetings Anonymous" + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Option.equal", () => { - test("Option.equal", () => { +describe("Belt.List.headExn", () => { + test("Belt.List.headExn", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Option + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - equal(Some(3), Some(15), clockEqual) // true - equal(Some(3), None, clockEqual) // false - equal(None, Some(3), clockEqual) // false - equal(None, None, clockEqual) // true + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Nullable.map", () => { - test("Nullable.map", () => { +describe("Belt.List.keep", () => { + test("Belt.List.keep", () => { module Test = { - Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) - Nullable.map(undefined, x => x * x) // undefined + let isEven = x => mod(x, 2) == 0 + + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("List.headExn", () => { - test("List.headExn", () => { +describe("Belt.List.keepMap", () => { + test("Belt.List.keepMap", () => { module Test = { - List.headExn(list{1, 2, 3})->assertEqual(1) + let isEven = x => mod(x, 2) == 0 - switch List.headExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ + + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ } () }) }) -describe("List.tailExn", () => { - test("List.tailExn", () => { +describe("Belt.List.keepWithIndex", () => { + test("Belt.List.keepWithIndex", () => { module Test = { - List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + let isEven = x => mod(x, 2) == 0 - switch List.tailExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("List.splitAt", () => { - test("List.splitAt", () => { +describe("Belt.List.length", () => { + test("Belt.List.length", () => { module Test = { - list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - - list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + Belt.List.length(list{1, 2, 3}) // 3 } () }) }) -describe("List.toArray", () => { - test("List.toArray", () => { +describe("Belt.List.make", () => { + test("Belt.List.make", () => { module Test = { - List.toArray(list{1, 2, 3}) // [1, 2, 3] + Belt.List.make(3, 1) // list{1, 1, 1} } () }) }) -describe("List.reverse", () => { - test("List.reverse", () => { +describe("Belt.List.makeBy", () => { + test("Belt.List.makeBy", () => { module Test = { - List.reverse(list{1, 2, 3}) // list{3, 2, 1} + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} } () }) }) -describe("List.forEach", () => { - test("List.forEach", () => { +describe("Belt.List.map", () => { + test("Belt.List.map", () => { module Test = { - List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} } () }) }) -describe("List.reduce2", () => { - test("List.reduce2", () => { +describe("Belt.List.mapReverse", () => { + test("Belt.List.mapReverse", () => { module Test = { - List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) } () }) }) -describe("List.compare", () => { - test("List.compare", () => { +describe("Belt.List.mapReverse2", () => { + test("Belt.List.mapReverse2", () => { module Test = { - List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Null.forEach", () => { - test("Null.forEach", () => { +describe("Belt.List.mapWithIndex", () => { + test("Belt.List.mapWithIndex", () => { module Test = { - Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" - Null.forEach(Null.null, x => Console.log(x)) // logs nothing + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} } () }) }) -describe("Null.flatMap", () => { - test("Null.flatMap", () => { +describe("Belt.List.partition", () => { + test("Belt.List.partition", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Null.make(value + 1) - } else { - Null.null - } - - Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) - Null.flatMap(Null.make(-4), addIfAboveOne) // null - Null.flatMap(Null.null, addIfAboveOne) // null + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) } () }) }) -describe("Math.minMany", () => { - test("Math.minMany", () => { +describe("Belt.List.reduce", () => { + test("Belt.List.reduce", () => { module Test = { - Math.minMany([1.0, 2.0]) // 1.0 - Math.minMany([-1.0, -2.0]) // -2.0 - Math.minMany([])->Float.isFinite // false + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + + /* same as */ + + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ } () }) }) -describe("Math.maxMany", () => { - test("Math.maxMany", () => { +describe("Belt.List.reduce2", () => { + test("Belt.List.reduce2", () => { module Test = { - Math.maxMany([1.0, 2.0]) // 2.0 - Math.maxMany([-1.0, -2.0]) // -1.0 - Math.maxMany([])->Float.isFinite // false + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("Math.Int.abs", () => { - test("Math.Int.abs", () => { +describe("Belt.List.reduceReverse", () => { + test("Belt.List.reduceReverse", () => { module Test = { - Math.Int.abs(-2) // 2 - Math.Int.abs(3) // 3 + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} } () }) }) -describe("Math.Int.min", () => { - test("Math.Int.min", () => { +describe("Belt.List.reduceReverse2", () => { + test("Belt.List.reduceReverse2", () => { module Test = { - Math.Int.min(1, 2) // 1 - Math.Int.min(-1, -2) // -2 + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("Math.Int.max", () => { - test("Math.Int.max", () => { +describe("Belt.List.reduceWithIndex", () => { + test("Belt.List.reduceWithIndex", () => { module Test = { - Math.Int.max(1, 2) // 2 - Math.Int.max(-1, -2) // -1 + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ } () }) }) -describe("Math.Int.pow", () => { - test("Math.Int.pow", () => { +describe("Belt.List.removeAssoc", () => { + test("Belt.List.removeAssoc", () => { module Test = { - Math.Int.pow(2, ~exp=4) // 16 - Math.Int.pow(3, ~exp=4) // 81 + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ } () }) }) -describe("Int.toString", () => { - test("Int.toString", () => { +describe("Belt.List.reverse", () => { + test("Belt.List.reverse", () => { module Test = { - Int.toString(1000) // "1000" - Int.toString(-1000) // "-1000" - Int.toString(6, ~radix=2) // "110" - Int.toString(373592855, ~radix=16) // "16449317" - Int.toString(123456, ~radix=36) // "2n9c" + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ } () }) }) -describe("Date.getTime", () => { - test("Date.getTime", () => { +describe("Belt.List.reverseConcat", () => { + test("Belt.List.reverseConcat", () => { module Test = { - Date.fromString("2023-02-20")->Date.getTime - // 1676851200000 + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("Date.getDate", () => { - test("Date.getDate", () => { +describe("Belt.List.setAssoc", () => { + test("Belt.List.setAssoc", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDate - // 20 + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ } () }) }) -describe("Date.setDate", () => { - test("Date.setDate", () => { +describe("Belt.List.shuffle", () => { + test("Belt.List.shuffle", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Dict.toArray", () => { - test("Dict.toArray", () => { +describe("Belt.List.some", () => { + test("Belt.List.some", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let asArray = dict->Dict.toArray - Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console + let isAbove100 = value => value > 100 + + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ } () }) }) -describe("Dict.forEach", () => { - test("Dict.forEach", () => { +describe("Belt.List.some2", () => { + test("Belt.List.some2", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - dict->Dict.forEach( - value => { - Console.log(value) - }, - ) + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ + + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ } () }) }) -describe("Console.info", () => { - test("Console.info", () => { +describe("Belt.List.sort", () => { + test("Belt.List.sort", () => { module Test = { - Console.info("Information") - Console.info(("Hello", "JS")) + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} } () }) }) -describe("Console.log2", () => { - test("Console.log2", () => { +describe("Belt.List.splitAt", () => { + test("Belt.List.splitAt", () => { module Test = { - Console.log2("Hello", "World") - Console.log2([1, 2, 3], '4') + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Console.log3", () => { - test("Console.log3", () => { +describe("Belt.List.tail", () => { + test("Belt.List.tail", () => { module Test = { - Console.log3("Hello", "World", "ReScript") - Console.log3("One", 2, #3) + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + Belt.List.tail(list{}) // None } () }) }) -describe("Console.log4", () => { - test("Console.log4", () => { +describe("Belt.List.tailExn", () => { + test("Belt.List.tailExn", () => { module Test = { - Console.log4("Hello", "World", "ReScript", "!!!") - Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Console.log5", () => { - test("Console.log5", () => { +describe("Belt.List.take", () => { + test("Belt.List.take", () => { module Test = { - Console.log5("Hello", "World", "JS", '!', '!') - Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) + + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) + + list{1, 2, 3}->Belt.List.take(4) // None } () }) }) -describe("Console.log6", () => { - test("Console.log6", () => { +describe("Belt.List.toArray", () => { + test("Belt.List.toArray", () => { module Test = { - Console.log6("Hello", "World", "JS", '!', '!', '?') - Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Console.time", () => { - test("Console.time", () => { +describe("Belt.List.unzip", () => { + test("Belt.List.unzip", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ } () }) }) -describe("Console.warn", () => { - test("Console.warn", () => { +describe("Belt.List.zip", () => { + test("Belt.List.zip", () => { module Test = { - Console.warn("Warning") - Console.warn(("Warning", "invalid number")) + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} } () }) }) -describe("Belt_Set.has", () => { - test("Belt_Set.has", () => { +describe("Belt.List.zipBy", () => { + test("Belt.List.zipBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) + Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} } () }) }) -describe("Belt_Set.add", () => { - test("Belt_Set.add", () => { +describe("Belt.Map.Dict.findFirstBy", () => { + test("Belt.Map.Dict.findFirstBy", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("Belt_Set.get", () => { - test("Belt_Set.get", () => { +describe("Belt.Map.Int", () => { + test("Belt.Map.Int", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + } + () + }) +}) - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) +describe("Belt.Map.Int.findFirstBy", () => { + test("Belt.Map.Int.findFirstBy", () => { + module Test = { + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("Belt_Map.Int", () => { - test("Belt_Map.Int", () => { +describe("Belt.Map.String.findFirstBy", () => { + test("Belt.Map.String.findFirstBy", () => { module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) + + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Belt_Map.has", () => { - test("Belt_Map.has", () => { +describe("Belt.Map.findFirstBy", () => { + test("Belt.Map.findFirstBy", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) } () }) }) -describe("Belt_Map.get", () => { - test("Belt_Map.get", () => { +describe("Belt.Map.forEach", () => { + test("Belt.Map.forEach", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None + let acc = ref(list{}) + + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} } () }) }) -describe("Belt_Map.set", () => { - test("Belt_Map.set", () => { +describe("Belt.Map.fromArray", () => { + test("Belt.Map.fromArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.set(s0, 2, "3") - - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt_List.eq", () => { - test("Belt_List.eq", () => { +describe("Belt.Map.get", () => { + test("Belt.Map.get", () => { module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None } () }) }) -describe("Belt.HashSet", () => { - test("Belt.HashSet", () => { +describe("Belt.Map.has", () => { + test("Belt.Map.has", () => { module Test = { - module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) - - let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) - - module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) - - let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.HashSet.add(s1, 0) - Belt.HashSet.add(s1, 1) + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true } () }) }) -describe("Belt.HashMap", () => { - test("Belt.HashMap", () => { +describe("Belt.Map.isEmpty", () => { + test("Belt.Map.isEmpty", () => { module Test = { - type t = int - module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) - let s0: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I0), - ) - - module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) - let s1: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I1), - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - let () = { - Belt.HashMap.set(s0, 0, 3) - Belt.HashMap.set(s1, 1, "3") - } + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false } () }) }) -describe("Belt.List.eq", () => { - test("Belt.List.eq", () => { +describe("Belt.Map.keysToArray", () => { + test("Belt.Map.keysToArray", () => { module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] } () }) }) -describe("Belt.Set.has", () => { - test("Belt.Set.has", () => { +describe("Belt.Map.make", () => { + test("Belt.Map.make", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + let m = Belt.Map.make(~id=module(IntCmp)) - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) + Belt.Map.set(m, 0, "a") } () }) }) -describe("Belt.Set.add", () => { - test("Belt.Set.add", () => { +describe("Belt.Map.reduce", () => { + test("Belt.Map.reduce", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ } () }) }) -describe("Belt.Set.get", () => { - test("Belt.Set.get", () => { +describe("Belt.Map.remove", () => { + test("Belt.Map.remove", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] } () }) }) -describe("Belt.Map.Int", () => { - test("Belt.Map.Int", () => { +describe("Belt.Map.set", () => { + test("Belt.Map.set", () => { module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) + + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) + + let s1 = Belt.Map.set(s0, 2, "3") + + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] } () }) }) -describe("Belt.Map.has", () => { - test("Belt.Map.has", () => { +describe("Belt.Map.size", () => { + test("Belt.Map.size", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 } () }) }) -describe("Belt.Map.get", () => { - test("Belt.Map.get", () => { +describe("Belt.Map.toArray", () => { + test("Belt.Map.toArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt.Map.set", () => { - test("Belt.Map.set", () => { +describe("Belt.Map.valuesToArray", () => { + test("Belt.Map.valuesToArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.set(s0, 2, "3") - - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] } () }) }) -describe("Belt.Float.+", () => { - test("Belt.Float.+", () => { +describe("Belt.MutableSet", () => { + test("Belt.MutableSet", () => { module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) + + let mySet = Belt.MutableSet.make(~id=module(PairComparator)) + mySet->Belt.MutableSet.add((1, 2)) } () }) }) -describe("Belt.Float.-", () => { - test("Belt.Float.-", () => { +describe("Belt.MutableSet.add", () => { + test("Belt.MutableSet.add", () => { module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) + + s0->Belt.MutableSet.toArray /* [1, 2] */ } () }) }) -describe("Belt.Float.*", () => { - test("Belt.Float.*", () => { +describe("Belt.MutableSet.copy", () => { + test("Belt.MutableSet.copy", () => { module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Belt.Float./", () => { - test("Belt.Float./", () => { +describe("Belt.MutableSet.diff", () => { + test("Belt.MutableSet.diff", () => { module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ } () }) }) -describe("Belt_Float.+", () => { - test("Belt_Float.+", () => { +describe("Belt.MutableSet.eq", () => { + test("Belt.MutableSet.eq", () => { module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.MutableSet.eq(s0, s1) /* true */ } () }) }) -describe("Belt_Float.-", () => { - test("Belt_Float.-", () => { +describe("Belt.MutableSet.every", () => { + test("Belt.MutableSet.every", () => { module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ } () }) }) -describe("Belt_Float.*", () => { - test("Belt_Float.*", () => { +describe("Belt.MutableSet.forEach", () => { + test("Belt.MutableSet.forEach", () => { module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Belt_Float./", () => { - test("Belt_Float./", () => { +describe("Belt.MutableSet.fromArray", () => { + test("Belt.MutableSet.fromArray", () => { module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Array.length", () => { - test("Array.length", () => { +describe("Belt.MutableSet.get", () => { + test("Belt.MutableSet.get", () => { module Test = { - let someArray = ["hi", "hello"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - someArray - ->Array.length - ->assertEqual(2) + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ } () }) }) -describe("Array.concat", () => { - test("Array.concat", () => { +describe("Belt.MutableSet.has", () => { + test("Belt.MutableSet.has", () => { module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay", "wehoo"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let someArray = array1->Array.concat(array2) + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ } () }) }) -describe("Array.filter", () => { - test("Array.filter", () => { +describe("Belt.MutableSet.intersect", () => { + test("Belt.MutableSet.intersect", () => { module Test = { - [1, 2, 3, 4] - ->Array.filter(num => num > 2) - ->assertEqual([3, 4]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ } () }) }) -describe("Array.reduce", () => { - test("Array.reduce", () => { +describe("Belt.MutableSet.isEmpty", () => { + test("Belt.MutableSet.isEmpty", () => { module Test = { - Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) - - Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - [1, 2, 3] - ->Array.reduce(list{}, List.add) - ->assertEqual(list{3, 2, 1}) + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - Array.reduce([], list{}, List.add)->assertEqual(list{}) + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ } () }) }) -describe("String.length", () => { - test("String.length", () => { +describe("Belt.MutableSet.keep", () => { + test("Belt.MutableSet.keep", () => { module Test = { - String.length("abcd") == 4 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ } () }) }) -describe("String.charAt", () => { - test("String.charAt", () => { +describe("Belt.MutableSet.maxUndefined", () => { + test("Belt.MutableSet.maxUndefined", () => { module Test = { - String.charAt("ReScript", 0) == "R" - String.charAt("Hello", 12) == "" - String.charAt(`JS`, 5) == "" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ } () }) }) -describe("String.concat", () => { - test("String.concat", () => { +describe("Belt.MutableSet.maximum", () => { + test("Belt.MutableSet.maximum", () => { module Test = { - String.concat("cow", "bell") == "cowbell" - String.concat("Re", "Script") == "ReScript" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ } () }) }) -describe("String.repeat", () => { - test("String.repeat", () => { +describe("Belt.MutableSet.mergeMany", () => { + test("Belt.MutableSet.mergeMany", () => { module Test = { - String.repeat("ha", 3) == "hahaha" - String.repeat("empty", 0) == "" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("String.search", () => { - test("String.search", () => { +describe("Belt.MutableSet.minUndefined", () => { + test("Belt.MutableSet.minUndefined", () => { module Test = { - String.search("testing 1 2 3", /\d+/) == 8 - String.search("no numbers", /\d+/) == -1 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ } () }) }) -describe("String.padEnd", () => { - test("String.padEnd", () => { +describe("Belt.MutableSet.minimum", () => { + test("Belt.MutableSet.minimum", () => { module Test = { - String.padEnd("Hello", 10, ".") == "Hello....." - String.padEnd("abc", 1, "") == "abc" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ } () }) }) -describe("Set.fromArray", () => { - test("Set.fromArray", () => { +describe("Belt.MutableSet.partition", () => { + test("Belt.MutableSet.partition", () => { module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [ReScript, JavaScript, TypeScript] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let set = Set.fromArray(languageRank) // Set.t + let isOdd = x => mod(x, 2) != 0 - switch set->Set.has(ReScript) { - | true => Console.log("Yay, ReScript is in there!") - | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ } () }) }) -describe("RegExp.global", () => { - test("RegExp.global", () => { +describe("Belt.MutableSet.reduce", () => { + test("Belt.MutableSet.reduce", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("RegExp.source", () => { - test("RegExp.source", () => { +describe("Belt.MutableSet.remove", () => { + test("Belt.MutableSet.remove", () => { module Test = { - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ } () }) }) -describe("RegExp.sticky", () => { - test("RegExp.sticky", () => { +describe("Belt.MutableSet.removeMany", () => { + test("Belt.MutableSet.removeMany", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ } () }) }) -describe("Promise.catch", () => { - test("Promise.catch", () => { +describe("Belt.MutableSet.size", () => { + test("Belt.MutableSet.size", () => { module Test = { - open Promise - - exception SomeError(string) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - reject(SomeError("this is an error")) - ->then( - _ => { - Ok("This result will never be returned")->resolve - }, - ) - ->catch( - e => { - let msg = switch e { - | SomeError(msg) => "ReScript error occurred: " ++ msg - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(msg) => "JS exception occurred: " ++ msg - | None => "Some other JS value has been thrown" - } - | _ => "Unexpected error occurred" - } + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - Error(msg)->resolve - }, - ) - ->then( - result => { - switch result { - | Ok(r) => Console.log2("Operation successful: ", r) - | Error(msg) => Console.log2("Operation failed: ", msg) - }->resolve - }, - ) - ->ignore // Ignore needed for side-effects + s0->Belt.MutableSet.size /* 4 */ } () }) }) -describe("Option.filter", () => { - test("Option.filter", () => { +describe("Belt.MutableSet.some", () => { + test("Belt.MutableSet.some", () => { module Test = { - Option.filter(Some(10), x => x > 5) // Some(10) - Option.filter(Some(4), x => x > 5) // None - Option.filter(None, x => x > 5) // None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ } () }) }) -describe("Option.getExn", () => { - test("Option.getExn", () => { +describe("Belt.MutableSet.split", () => { + test("Belt.MutableSet.split", () => { module Test = { - Option.getExn(Some(3))->assertEqual(3) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch Option.getExn(None) { - | exception _ => assert(true) - | _ => assert(false) - } + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - switch Option.getExn(None, ~message="was None!") { - | exception _ => assert(true) // Raises an Error with the message "was None!" - | _ => assert(false) - } + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ } () }) }) -describe("Option.orElse", () => { - test("Option.orElse", () => { +describe("Belt.MutableSet.subset", () => { + test("Belt.MutableSet.subset", () => { module Test = { - Option.orElse(Some(1812), Some(1066)) == Some(1812) - Option.orElse(None, Some(1066)) == Some(1066) - Option.orElse(None, None) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ } () }) }) -describe("Option.isSome", () => { - test("Option.isSome", () => { +describe("Belt.MutableSet.toArray", () => { + test("Belt.MutableSet.toArray", () => { module Test = { - Option.isSome(None) // false - Option.isSome(Some(1)) // true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ } () }) }) -describe("Option.isNone", () => { - test("Option.isNone", () => { +describe("Belt.MutableSet.toList", () => { + test("Belt.MutableSet.toList", () => { module Test = { - Option.isNone(None) // true - Option.isNone(Some(1)) // false + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ } () }) }) -describe("Object.create", () => { - test("Object.create", () => { +describe("Belt.MutableSet.union", () => { + test("Belt.MutableSet.union", () => { module Test = { - let x = {"fruit": "banana"} - let y = Object.create(x) - y->Object.get("fruit") // Some("banana") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Object.assign", () => { - test("Object.assign", () => { +describe("Belt.Option", () => { + test("Belt.Option", () => { module Test = { - Object.assign({"a": 1}, {"a": 2}) // {"a": 2} - Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} - Object.assign({"a": 1}, {"a": null}) // {"a": null} + type option<'a> = None | Some('a) + + let someString: option = Some("hello") } () }) }) -describe("Object.freeze", () => { - test("Object.freeze", () => { +describe("Belt.Option.cmp", () => { + test("Belt.Option.cmp", () => { module Test = { - let obj = {"a": 1} - obj->Object.set("a", 2) // succeeds - obj->Object.freeze->ignore + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - try { - obj->Object.set("a", 3) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } + open Belt.Option + + cmp(Some(3), Some(15), clockCompare) /* 0 */ + + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ } () }) }) -describe("Nullable.null", () => { - test("Nullable.null", () => { +describe("Belt.Option.eq", () => { + test("Belt.Option.eq", () => { module Test = { - Console.log(Nullable.null) // Logs `null` to the console. + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Belt.Option + + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ } () }) }) -describe("Nullable.make", () => { - test("Nullable.make", () => { +describe("Belt.Option.flatMap", () => { + test("Belt.Option.flatMap", () => { module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Need to do this - switch asNullable->Nullable.toOption { - | Some(value) if value == myStr => Console.log("Yay, values matched!") - | _ => Console.log("Values did not match.") - } - } - () - }) -}) + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } -describe("List.forEach2", () => { - test("List.forEach2", () => { - module Test = { - List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - /* - prints: - "Z" "A" - "Y" "B" -*/ + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ } () }) }) -describe("List.getAssoc", () => { - test("List.getAssoc", () => { +describe("Belt.Option.forEach", () => { + test("Belt.Option.forEach", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - // Some("afternoon") + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ } () }) }) -describe("List.hasAssoc", () => { - test("List.hasAssoc", () => { +describe("Belt.Option.getExn", () => { + test("Belt.Option.getExn", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) // false + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("List.setAssoc", () => { - test("List.setAssoc", () => { +describe("Belt.Option.getWithDefault", () => { + test("Belt.Option.getWithDefault", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} + Belt.Option.getWithDefault(None, "Banana") /* Banana */ - list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - // list{(9, "morning"), (15, "afternoon"), (22, "night")} + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ } () }) }) -describe("Null.toOption", () => { - test("Null.toOption", () => { +describe("Belt.Option.isNone", () => { + test("Belt.Option.isNone", () => { module Test = { - let nullStr = Null.make("Hello") + Belt.Option.isNone(None) /* true */ - switch nullStr->Null.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } + Belt.Option.isNone(Some(1)) /* false */ } () }) }) -describe("Math.Int.imul", () => { - test("Math.Int.imul", () => { +describe("Belt.Option.isSome", () => { + test("Belt.Option.isSome", () => { module Test = { - Math.Int.imul(3, 4) // 12 - Math.Int.imul(-5, 12) // 60 + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ } () }) }) -describe("Math.Int.sign", () => { - test("Math.Int.sign", () => { +describe("Belt.Option.keep", () => { + test("Belt.Option.keep", () => { module Test = { - Math.Int.sign(3) // 1 - Math.Int.sign(-3) // -1 - Math.Int.sign(0) // 0 + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ } () }) }) -describe("Math.Int.ceil", () => { - test("Math.Int.ceil", () => { +describe("Belt.Option.map", () => { + test("Belt.Option.map", () => { module Test = { - Math.Int.ceil(3.7) == 4 - Math.Int.ceil(3.0) == 3 - Math.Int.ceil(-3.1) == -3 + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + + Belt.Option.map(None, x => x * x) /* None */ } () }) }) -describe("Map.fromArray", () => { - test("Map.fromArray", () => { +describe("Belt.Option.mapWithDefault", () => { + test("Belt.Option.mapWithDefault", () => { module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] - - let map = Map.fromArray(languageRank) // Map.t + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - switch map->Map.get(ReScript) { - | Some(1) => Console.log("Yay, ReScript is #1!") - | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ } () }) }) -describe("JSON.parseExn", () => { - test("JSON.parseExn", () => { +describe("Belt.Option.orElse", () => { + test("Belt.Option.orElse", () => { module Test = { - try { - let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) - // { foo: 'bar', hello: 'world' } - - let _ = JSON.parseExn("") - // error - } catch { - | Exn.Error(_) => Console.log("error") - } - - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` - - try { - JSON.parseExn(jsonString, ~reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } - - JSON.parseExn("", ~reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None } () }) }) -describe("Iterator.next", () => { - test("Iterator.next", () => { +describe("Belt.Range.every", () => { + test("Belt.Range.every", () => { module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - (iterator->Iterator.next).done->assertEqual(false) - (iterator->Iterator.next).done->assertEqual(true) + Belt.Range.every(0, 4, i => i < 5) /* true */ + + Belt.Range.every(0, 4, i => i < 4) /* false */ } () }) }) -describe("Int.fromFloat", () => { - test("Int.fromFloat", () => { +describe("Belt.Range.everyBy", () => { + test("Belt.Range.everyBy", () => { module Test = { - Int.fromFloat(2.0) == 2 - Int.fromFloat(1.999) == 1 - Int.fromFloat(1.5) == 1 - Int.fromFloat(0.9999) == 0 + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Float.toFixed", () => { - test("Float.toFixed", () => { +describe("Belt.Range.forEach", () => { + test("Belt.Range.forEach", () => { module Test = { - Float.toFixed(123456.0) // "123456.00" - Float.toFixed(10.0) // "10.00" - Float.toFixed(300.0, ~digits=4) // "300.0000" - Float.toFixed(300.0, ~digits=1) // "300.0" + Belt.Range.forEach(0, 4, i => Js.log(i)) + + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 } () }) }) -describe("Float.fromInt", () => { - test("Float.fromInt", () => { +describe("Belt.Range.some", () => { + test("Belt.Range.some", () => { module Test = { - Float.fromInt(2) == 2.0 - Float.fromInt(1) == 1.0 + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ } () }) }) -describe("Error.message", () => { - test("Error.message", () => { +describe("Belt.Range.someBy", () => { + test("Belt.Range.someBy", () => { module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Date.fromTime", () => { - test("Date.fromTime", () => { +describe("Belt.Result.cmp", () => { + test("Belt.Result.cmp", () => { module Test = { - Date.fromTime(0.0) - // 1970-01-01T00:00:00.000Z + let good1 = Belt.Result.Ok(59) - Date.fromTime(-86_400_000.0) - // 1969-12-31T00:00:00.000Z + let good2 = Belt.Result.Ok(37) - Date.fromTime(86_400_000.0) - // 1970-01-02T00:00:00.000Z + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 } () }) }) -describe("Date.getMonth", () => { - test("Date.getMonth", () => { +describe("Belt.Result.eq", () => { + test("Belt.Result.eq", () => { module Test = { - Date.fromString("2023-01-01")->Date.getMonth - // 0 + let good1 = Belt.Result.Ok(42) + + let good2 = Belt.Result.Ok(32) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 } () }) }) -describe("Date.getHours", () => { - test("Date.getHours", () => { +describe("Belt.Result.flatMap", () => { + test("Belt.Result.flatMap", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getHours - // 16 + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Date.setMonth", () => { - test("Date.setMonth", () => { +describe("Belt.Result.getExn", () => { + test("Belt.Result.getExn", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) + + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Date.setHours", () => { - test("Date.setHours", () => { +describe("Belt.Result.getWithDefault", () => { + test("Belt.Result.getWithDefault", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) + Belt.Result.getWithDefault(Ok(42), 0) == 42 + + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 } () }) }) -describe("Date.toString", () => { - test("Date.toString", () => { +describe("Belt.Result.map", () => { + test("Belt.Result.map", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log - // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) + let f = x => sqrt(Belt.Int.toFloat(x)) - Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log - // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) + Belt.Result.map(Ok(64), f) == Ok(8.0) + + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Console.clear", () => { - test("Console.clear", () => { +describe("Belt.Result.mapWithDefault", () => { + test("Belt.Result.mapWithDefault", () => { module Test = { - Console.clear() + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 } () }) }) -describe("Console.count", () => { - test("Console.count", () => { +describe("Belt.Set", () => { + test("Belt.Set", () => { module Test = { - Console.count("rescript") + module PairComparator = Belt.Id.MakeComparable({ + type t = (int, int) + let cmp = ((a0, a1), (b0, b1)) => + switch Pervasives.compare(a0, b0) { + | 0 => Pervasives.compare(a1, b1) + | c => c + } + }) + + let mySet = Belt.Set.make(~id=module(PairComparator)) + let mySet2 = Belt.Set.add(mySet, (1, 2)) + + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) } () }) }) -describe("Console.debug", () => { - test("Console.debug", () => { +describe("Belt.Set.Dict.add", () => { + test("Belt.Set.Dict.add", () => { module Test = { - Console.debug("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.debug(obj) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Console.error", () => { - test("Console.error", () => { +describe("Belt.Set.Dict.diff", () => { + test("Belt.Set.Dict.diff", () => { module Test = { - Console.error("error message") - Console.error(("error", "invalid value")) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Console.group", () => { - test("Console.group", () => { +describe("Belt.Set.Dict.empty", () => { + test("Belt.Set.Dict.empty", () => { module Test = { - 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() + let s0 = Belt.Set.Dict.empty } () }) }) -describe("Console.info2", () => { - test("Console.info2", () => { +describe("Belt.Set.Dict.eq", () => { + test("Belt.Set.Dict.eq", () => { module Test = { - Console.info2("Info", "failed to download") - Console.info2(#info, {"name": "ReScript"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Console.info3", () => { - test("Console.info3", () => { +describe("Belt.Set.Dict.every", () => { + test("Belt.Set.Dict.every", () => { module Test = { - Console.info3("Hello", "World", "ReScript") - Console.info3([1, 2, 3], #4, #5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Console.info4", () => { - test("Console.info4", () => { +describe("Belt.Set.Dict.forEach", () => { + test("Belt.Set.Dict.forEach", () => { module Test = { - Console.info4("Hello", "World", "ReScript", '!') - Console.info4([1, 2, 3], #4, #5, #lastinfo) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Console.info5", () => { - test("Console.info5", () => { +describe("Belt.Set.Dict.fromArray", () => { + test("Belt.Set.Dict.fromArray", () => { module Test = { - Console.info5("Hello", "World", "from", "JS", "!!!") - Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Console.info6", () => { - test("Console.info6", () => { +describe("Belt.Set.Dict.get", () => { + test("Belt.Set.Dict.get", () => { module Test = { - Console.info6("Hello", "World", "from", "JS", "!!!", '!') - Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ } () }) }) -describe("Console.table", () => { - test("Console.table", () => { +describe("Belt.Set.Dict.has", () => { + test("Belt.Set.Dict.has", () => { module Test = { - Console.table({"language": "rescript", "version": "10.1.2"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Console.trace", () => { - test("Console.trace", () => { +describe("Belt.Set.Dict.intersect", () => { + test("Belt.Set.Dict.intersect", () => { module Test = { - let main = () => { - Console.trace() - } - main() - // In the console, the following trace will be displayed: - // main - // - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + } () }) }) -describe("Console.warn2", () => { - test("Console.warn2", () => { +describe("Belt.Set.Dict.isEmpty", () => { + test("Belt.Set.Dict.isEmpty", () => { module Test = { - Console.warn2("Hello", "World") - Console.warn2([1, 2, 3], 4) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("Console.warn3", () => { - test("Console.warn3", () => { +describe("Belt.Set.Dict.keep", () => { + test("Belt.Set.Dict.keep", () => { module Test = { - Console.warn3("Hello", "World", "ReScript") - Console.warn3([1, 2, 3], #4, #5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Console.warn4", () => { - test("Console.warn4", () => { +describe("Belt.Set.Dict.maxUndefined", () => { + test("Belt.Set.Dict.maxUndefined", () => { module Test = { - Console.warn4("Hello", "World", "ReScript", "!!!") - Console.warn4(#first, #second, #third, "fourth") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ } () }) }) -describe("Console.warn5", () => { - test("Console.warn5", () => { +describe("Belt.Set.Dict.maximum", () => { + test("Belt.Set.Dict.maximum", () => { module Test = { - Console.warn5("Hello", "World", "from", "JS", "!!!") - Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("Console.warn6", () => { - test("Console.warn6", () => { +describe("Belt.Set.Dict.mergeMany", () => { + test("Belt.Set.Dict.mergeMany", () => { module Test = { - Console.warn6("Hello", "World", "from", "JS", "!!!", '!') - Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("Belt_Set.make", () => { - test("Belt_Set.make", () => { +describe("Belt.Set.Dict.minUndefined", () => { + test("Belt.Set.Dict.minUndefined", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let set = Belt.Set.make(~id=module(IntCmp)) + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - Belt.Set.isEmpty(set)->assertEqual(true) + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("Belt_Set.diff", () => { - test("Belt_Set.diff", () => { +describe("Belt.Set.Dict.minimum", () => { + test("Belt.Set.Dict.minimum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - Belt.Set.diff(s0, s1) - ->Belt.Set.toArray - ->assertEqual([6]) + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - Belt.Set.diff(s1, s0) - ->Belt.Set.toArray - ->assertEqual([1, 4]) + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("Belt_Set.some", () => { - test("Belt_Set.some", () => { +describe("Belt.Set.Dict.partition", () => { + test("Belt.Set.Dict.partition", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -3784,249 +4257,350 @@ describe("Belt_Set.some", () => { let isOdd = x => mod(x, 2) != 0 - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_Set.keep", () => { - test("Belt_Set.keep", () => { +describe("Belt.Set.Dict.reduce", () => { + test("Belt.Set.Dict.reduce", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.keep(isEven) - - s1->Belt.Set.toArray->assertEqual([2, 4]) + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Belt_Set.size", () => { - test("Belt_Set.size", () => { +describe("Belt.Set.Dict.remove", () => { + test("Belt.Set.Dict.remove", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - s0->Belt.Set.size->assertEqual(4) + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_Map.make", () => { - test("Belt_Map.make", () => { +describe("Belt.Set.Dict.removeMany", () => { + test("Belt.Set.Dict.removeMany", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let m = Belt.Map.make(~id=module(IntCmp)) + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - Belt.Map.set(m, 0, "a") + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("Belt_Map.size", () => { - test("Belt_Map.size", () => { +describe("Belt.Set.Dict.size", () => { + test("Belt.Set.Dict.size", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Belt_List.add", () => { - test("Belt_List.add", () => { +describe("Belt.Set.Dict.some", () => { + test("Belt.Set.Dict.some", () => { module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("Belt_List.get", () => { - test("Belt_List.get", () => { +describe("Belt.Set.Dict.split", () => { + test("Belt.Set.Dict.split", () => { module Test = { - let abc = list{"A", "B", "C"} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - abc->Belt.List.get(1) // Some("B") + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - abc->Belt.List.get(4) // None + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("Belt_List.map", () => { - test("Belt_List.map", () => { +describe("Belt.Set.Dict.subset", () => { + test("Belt.Set.Dict.subset", () => { module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("Belt_List.zip", () => { - test("Belt_List.zip", () => { +describe("Belt.Set.Dict.toArray", () => { + test("Belt.Set.Dict.toArray", () => { module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("Belt_List.cmp", () => { - test("Belt_List.cmp", () => { +describe("Belt.Set.Dict.toList", () => { + test("Belt.Set.Dict.toList", () => { module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("Belt_List.has", () => { - test("Belt_List.has", () => { +describe("Belt.Set.Dict.union", () => { + test("Belt.Set.Dict.union", () => { module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Belt.Array.eq", () => { - test("Belt.Array.eq", () => { +describe("Belt.Set.add", () => { + test("Belt.Set.add", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) + + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) } () }) }) -describe("Belt.List.add", () => { - test("Belt.List.add", () => { +describe("Belt.Set.diff", () => { + test("Belt.Set.diff", () => { module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + Belt.Set.diff(s0, s1) + ->Belt.Set.toArray + ->assertEqual([6]) + + Belt.Set.diff(s1, s0) + ->Belt.Set.toArray + ->assertEqual([1, 4]) } () }) }) -describe("Belt.List.get", () => { - test("Belt.List.get", () => { +describe("Belt.Set.eq", () => { + test("Belt.Set.eq", () => { module Test = { - let abc = list{"A", "B", "C"} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - abc->Belt.List.get(1) // Some("B") + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - abc->Belt.List.get(4) // None + Belt.Set.eq(s0, s1)->assertEqual(true) } () }) }) -describe("Belt.List.map", () => { - test("Belt.List.map", () => { +describe("Belt.Set.every", () => { + test("Belt.Set.every", () => { module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) } () }) }) -describe("Belt.List.zip", () => { - test("Belt.List.zip", () => { +describe("Belt.Set.forEach", () => { + test("Belt.Set.forEach", () => { module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + + let acc = ref(list{}) + + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt.List.cmp", () => { - test("Belt.List.cmp", () => { +describe("Belt.Set.fromArray", () => { + test("Belt.Set.fromArray", () => { module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Belt.List.has", () => { - test("Belt.List.has", () => { +describe("Belt.Set.get", () => { + test("Belt.Set.get", () => { module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) } () }) }) -describe("Belt.Set.make", () => { - test("Belt.Set.make", () => { +describe("Belt.Set.has", () => { + test("Belt.Set.has", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let set = Belt.Set.make(~id=module(IntCmp)) + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - Belt.Set.isEmpty(set)->assertEqual(true) + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) } () }) }) -describe("Belt.Set.diff", () => { - test("Belt.Set.diff", () => { +describe("Belt.Set.intersect", () => { + test("Belt.Set.intersect", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -4036,30 +4610,29 @@ describe("Belt.Set.diff", () => { let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.Set.diff(s0, s1) - ->Belt.Set.toArray - ->assertEqual([6]) + let intersect = Belt.Set.intersect(s0, s1) - Belt.Set.diff(s1, s0) + intersect ->Belt.Set.toArray - ->assertEqual([1, 4]) + ->assertEqual([2, 3, 5]) } () }) }) -describe("Belt.Set.some", () => { - test("Belt.Set.some", () => { +describe("Belt.Set.isEmpty", () => { + test("Belt.Set.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let isOdd = x => mod(x, 2) != 0 + let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) + Belt.Set.isEmpty(empty)->assertEqual(true) + Belt.Set.isEmpty(notEmpty)->assertEqual(false) } () }) @@ -4084,1929 +4657,2022 @@ describe("Belt.Set.keep", () => { }) }) -describe("Belt.Set.size", () => { - test("Belt.Set.size", () => { +describe("Belt.Set.make", () => { + test("Belt.Set.make", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + let set = Belt.Set.make(~id=module(IntCmp)) - s0->Belt.Set.size->assertEqual(4) + Belt.Set.isEmpty(set)->assertEqual(true) } () }) }) -describe("Belt.Map.make", () => { - test("Belt.Map.make", () => { +describe("Belt.Set.maxUndefined", () => { + test("Belt.Set.maxUndefined", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let m = Belt.Map.make(~id=module(IntCmp)) + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - Belt.Map.set(m, 0, "a") + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) } () }) }) -describe("Belt.Map.size", () => { - test("Belt.Map.size", () => { +describe("Belt.Set.maximum", () => { + test("Belt.Set.maximum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.maximum->assertEqual(None) + s1->Belt.Set.maximum->assertEqual(Some(5)) } () }) }) -describe("Belt_Array.eq", () => { - test("Belt_Array.eq", () => { +describe("Belt.Set.mergeMany", () => { + test("Belt.Set.mergeMany", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.make(~id=module(IntCmp)) + + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) } () }) }) -describe("Array.fillAll", () => { - test("Array.fillAll", () => { +describe("Belt.Set.minUndefined", () => { + test("Belt.Set.minUndefined", () => { module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillAll(9) - myArray->assertEqual([9, 9, 9, 9]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) } () }) }) -describe("Array.reverse", () => { - test("Array.reverse", () => { +describe("Belt.Set.minimum", () => { + test("Belt.Set.minimum", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.reverse + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - someArray->assertEqual(["hello", "hi"]) + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) } () }) }) -describe("Array.unshift", () => { - test("Array.unshift", () => { +describe("Belt.Set.partition", () => { + test("Belt.Set.partition", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshift("yay") - someArray->assertEqual(["yay", "hi", "hello"]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) + + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Array.indexOf", () => { - test("Array.indexOf", () => { +describe("Belt.Set.reduce", () => { + test("Belt.Set.reduce", () => { module Test = { - [1, 2]->Array.indexOf(2)->assertEqual(1) - [1, 2]->Array.indexOf(3)->assertEqual(-1) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - [{"language": "ReScript"}] - ->Array.indexOf({"language": "ReScript"}) - ->assertEqual(-1) // -1, because of strict equality + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Array.forEach", () => { - test("Array.forEach", () => { +describe("Belt.Set.remove", () => { + test("Belt.Set.remove", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - array->Array.forEach( - item => { - Console.log(item) - }, - ) + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) + + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) } () }) }) -describe("Array.shuffle", () => { - test("Array.shuffle", () => { +describe("Belt.Set.removeMany", () => { + test("Belt.Set.removeMany", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.shuffle - Console.log(array) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let array2 = [1, 2, 3] - array2->Array.shuffle + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - array2 - ->Array.length - ->assertEqual(3) + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) } () }) }) -describe("Array.flatMap", () => { - test("Array.flatMap", () => { +describe("Belt.Set.size", () => { + test("Belt.Set.size", () => { module Test = { - type language = ReScript | TypeScript | JavaScript + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let array = [ReScript, TypeScript, JavaScript] + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - array - ->Array.flatMap( - item => - switch item { - | ReScript => [1, 2, 3] - | TypeScript => [4, 5, 6] - | JavaScript => [7, 8, 9] - }, - ) - ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) + s0->Belt.Set.size->assertEqual(4) } () }) }) -describe("Array.findMap", () => { - test("Array.findMap", () => { +describe("Belt.Set.some", () => { + test("Belt.Set.some", () => { module Test = { - Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) - - Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( - Some(-6), - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) + let isOdd = x => mod(x, 2) != 0 - Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) } () }) }) -describe("String.indexOf", () => { - test("String.indexOf", () => { +describe("Belt.Set.split", () => { + test("Belt.Set.split", () => { module Test = { - String.indexOf("bookseller", "ok") == 2 - String.indexOf("bookseller", "sell") == 4 - String.indexOf("beekeeper", "ee") == 1 - String.indexOf("bookseller", "xyz") == -1 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.Set.split(3) + + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) } () }) }) -describe("String.replace", () => { - test("String.replace", () => { +describe("Belt.Set.subset", () => { + test("Belt.Set.subset", () => { module Test = { - String.replace("old string", "old", "new") == "new string" - String.replace("the cat and the dog", "the", "this") == "this cat and the dog" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) + + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) } () }) }) -describe("String.trimEnd", () => { - test("String.trimEnd", () => { +describe("Belt.Set.toArray", () => { + test("Belt.Set.toArray", () => { module Test = { - String.trimEnd(" Hello world! ") == " Hello world!" - String.trimEnd(" Hello world! ") == " Hello world!" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) } () }) }) -describe("Result.flatMap", () => { - test("Result.flatMap", () => { +describe("Belt.Set.toList", () => { + test("Belt.Set.toList", () => { module Test = { - let recip = x => - if x !== 0.0 { - Ok(1.0 /. x) - } else { - Error("Divide by zero") - } - - Result.flatMap(Ok(2.0), recip) == Ok(0.5) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) } () }) }) -describe("Result.compare", () => { - test("Result.compare", () => { +describe("Belt.Set.union", () => { + test("Belt.Set.union", () => { module Test = { - let good1 = Ok(59) - - let good2 = Ok(37) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") - - let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) - - Result.compare(Ok(39), Ok(57), mod10cmp) == 1. - - Result.compare(Ok(57), Ok(39), mod10cmp) == -1. - - Result.compare(Ok(39), Error("y"), mod10cmp) == 1. + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Result.compare(Error("x"), Ok(57), mod10cmp) == -1. + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) - Result.compare(Error("x"), Error("y"), mod10cmp) == 0. + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) } () }) }) -describe("Result.forEach", () => { - test("Result.forEach", () => { +describe("Belt.SortArray.binarySearchBy", () => { + test("Belt.SortArray.binarySearchBy", () => { module Test = { - Result.forEach(Ok(3), Console.log) // Logs "3", returns () - Result.forEach(Error("x"), Console.log) // Does nothing, returns () + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("RegExp.unicode", () => { - test("RegExp.unicode", () => { +describe("Belt.SortArray.strictlySortedLength", () => { + test("Belt.SortArray.strictlySortedLength", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("Promise.reject", () => { - test("Promise.reject", () => { +describe("Belt_Array.blit", () => { + test("Belt_Array.blit", () => { module Test = { - exception TestError(string) + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - TestError("some rejected value") - ->Promise.reject - ->Promise.catch( - v => { - switch v { - | TestError(msg) => assertEqual(msg, "some rejected value") - | _ => assert(false) - } - Promise.resolve() - }, - ) - ->ignore + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Option.forEach", () => { - test("Option.forEach", () => { +describe("Belt_Array.cmp", () => { + test("Belt_Array.cmp", () => { module Test = { - Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" - Option.forEach(None, x => Console.log(x)) // returns () + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Option.flatMap", () => { - test("Option.flatMap", () => { +describe("Belt_Array.concat", () => { + test("Belt_Array.concat", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - Option.flatMap(Some(2), addIfAboveOne) // Some(3) - Option.flatMap(Some(-4), addIfAboveOne) // None - Option.flatMap(None, addIfAboveOne) // None + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Option.compare", () => { - test("Option.compare", () => { +describe("Belt_Array.concatMany", () => { + test("Belt_Array.concatMany", () => { module Test = { - let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + } + () + }) +}) - Option.compare(Some(3), Some(15), clockCompare) // 0. - Option.compare(Some(3), Some(14), clockCompare) // 1. - Option.compare(Some(2), Some(15), clockCompare) // (-1.) - Option.compare(None, Some(15), clockCompare) // (-1.) - Option.compare(Some(14), None, clockCompare) // 1. - Option.compare(None, None, clockCompare) // 0. +describe("Belt_Array.eq", () => { + test("Belt_Array.eq", () => { + module Test = { + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Nullable.getOr", () => { - test("Nullable.getOr", () => { +describe("Belt_Array.every", () => { + test("Belt_Array.every", () => { module Test = { - Nullable.getOr(Nullable.null, "Banana") // Banana - Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") + Belt.Array.every([1, -3, 5], x => x > 0) == false + } + () + }) +}) - Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" - Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" +describe("Belt_Array.every2", () => { + test("Belt_Array.every2", () => { + module Test = { + 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 } () }) }) -describe("Nullable.mapOr", () => { - test("Nullable.mapOr", () => { +describe("Belt_Array.fill", () => { + test("Belt_Array.fill", () => { module Test = { - let someValue = Nullable.make(3) - someValue->Nullable.mapOr(0, x => x + 5) // 8 + let arr = Belt.Array.makeBy(5, i => i) - let noneValue = Nullable.null - noneValue->Nullable.mapOr(0, x => x + 5) // 0 + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("List.fromArray", () => { - test("List.fromArray", () => { +describe("Belt_Array.flatMap", () => { + test("Belt_Array.flatMap", () => { module Test = { - List.fromArray([1, 2, 3]) // list{1, 2, 3} + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("List.filterMap", () => { - test("List.filterMap", () => { +describe("Belt_Array.forEach", () => { + test("Belt_Array.forEach", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - list{1, 2, 3, 4}->List.filterMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) // list{2, 4} + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("List.partition", () => { - test("List.partition", () => { +describe("Belt_Array.forEachWithIndex", () => { + test("Belt_Array.forEachWithIndex", () => { module Test = { - // (elementsThatSatisfies, elementsThatDoesNotSatisfy) + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Null.getUnsafe", () => { - test("Null.getUnsafe", () => { +describe("Belt_Array.get", () => { + test("Belt_Array.get", () => { module Test = { - Null.getUnsafe(Null.make(3)) == 3 - Null.getUnsafe(Null.null) // Raises an error + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Math.hypotMany", () => { - test("Math.hypotMany", () => { +describe("Belt_Array.getBy", () => { + test("Belt_Array.getBy", () => { module Test = { - Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 - Math.hypotMany([]) // 0.0 + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Math.Int.clz32", () => { - test("Math.Int.clz32", () => { +describe("Belt_Array.getIndexBy", () => { + test("Belt_Array.getIndexBy", () => { module Test = { - // 00000000000000000000000000000001 - Math.Int.clz32(1) // 31 - // 00000000000000000000000000000100 - Math.Int.clz32(4) // 29 + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Math.Int.floor", () => { - test("Math.Int.floor", () => { +describe("Belt_Array.joinWith", () => { + test("Belt_Array.joinWith", () => { module Test = { - Math.Int.floor(3.7) == 3 - Math.Int.floor(3.0) == 3 - Math.Int.floor(-3.1) == -4 + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("JSON.stringify", () => { - test("JSON.stringify", () => { +describe("Belt_Array.keepMap", () => { + test("Belt_Array.keepMap", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringify(json) - // {"foo":"bar","hello":"world","someNumber":42} - - JSON.stringify(json, ~space=2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } - - JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) - // {"foo":"bar","someNumber":42} - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) - - JSON.stringify(json, ~replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Int.fromString", () => { - test("Int.fromString", () => { +describe("Belt_Array.keepWithIndex", () => { + test("Belt_Array.keepWithIndex", () => { module Test = { - Int.fromString("0") == Some(0) - Int.fromString("NaN") == None - Int.fromString("6", ~radix=2) == None + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Float.isFinite", () => { - test("Float.isFinite", () => { +describe("Belt_Array.length", () => { + test("Belt_Array.length", () => { module Test = { - Float.isFinite(1.0) // true - Float.isFinite(Float.Constants.nan) // false - Float.isFinite(Float.Constants.positiveInfinity) // false + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Float.parseInt", () => { - test("Float.parseInt", () => { +describe("Belt_Array.makeBy", () => { + test("Belt_Array.makeBy", () => { module Test = { - Float.parseInt("1.0") // 1.0 - Float.parseInt(" 3.14 ") // 3.0 - Float.parseInt(3) // 3.0 - Float.parseInt("3.14some non-digit characters") // 3.0 - Float.parseInt("error")->Float.isNaN // true - Float.parseInt("10.0", ~radix=2) // 2.0 - Float.parseInt("15 * 3", ~radix=10) // 15.0 - Float.parseInt("12", ~radix=13) // 15.0 - Float.parseInt("17", ~radix=40)->Float.isNaN // true - } - () - }) -}) + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] -describe("Float.toString", () => { - test("Float.toString", () => { - module Test = { - Float.toString(1000.0) // "1000" - Float.toString(-1000.0) // "-1000" + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Date.setHoursM", () => { - test("Date.setHoursM", () => { +describe("Belt_Array.makeUninitialized", () => { + test("Belt_Array.makeUninitialized", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Date.getUTCDay", () => { - test("Date.getUTCDay", () => { +describe("Belt_Array.makeUninitializedUnsafe", () => { + test("Belt_Array.makeUninitializedUnsafe", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Dict.getUnsafe", () => { - test("Dict.getUnsafe", () => { +describe("Belt_Array.map", () => { + test("Belt_Array.map", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let value = dict->Dict.getUnsafe("key1") - Console.log(value) // value1 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Dict.fromArray", () => { - test("Dict.fromArray", () => { +describe("Belt_Array.mapWithIndex", () => { + test("Belt_Array.mapWithIndex", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Dict.mapValues", () => { - test("Dict.mapValues", () => { +describe("Belt_Array.partition", () => { + test("Belt_Array.partition", () => { module Test = { - let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] - dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Console.debug2", () => { - test("Console.debug2", () => { +describe("Belt_Array.range", () => { + test("Belt_Array.range", () => { module Test = { - Console.debug2("Hello", "World") - Console.debug2([1, 2, 3], '4') + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Console.debug3", () => { - test("Console.debug3", () => { +describe("Belt_Array.rangeBy", () => { + test("Belt_Array.rangeBy", () => { module Test = { - Console.debug3("Hello", "World", "ReScript") - Console.debug3("One", 2, #3) + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Console.debug4", () => { - test("Console.debug4", () => { +describe("Belt_Array.reduce", () => { + test("Belt_Array.reduce", () => { module Test = { - Console.debug4("Hello", "World", "ReScript", "!!!") - Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Console.debug5", () => { - test("Console.debug5", () => { +describe("Belt_Array.reduceReverse", () => { + test("Belt_Array.reduceReverse", () => { module Test = { - Console.debug5("Hello", "World", "JS", '!', '!') - Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Console.debug6", () => { - test("Console.debug6", () => { +describe("Belt_Array.reduceReverse2", () => { + test("Belt_Array.reduceReverse2", () => { module Test = { - Console.debug6("Hello", "World", "JS", '!', '!', '?') - Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("Console.error2", () => { - test("Console.error2", () => { +describe("Belt_Array.reduceWithIndex", () => { + test("Belt_Array.reduceWithIndex", () => { module Test = { - Console.error2("Error", "here") - Console.error2(("log", "error"), "message") + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Console.error3", () => { - test("Console.error3", () => { +describe("Belt_Array.reverse", () => { + test("Belt_Array.reverse", () => { module Test = { - Console.error3("Hello", "World", "!!!") - Console.error3(#first, #second, #third) + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Console.error4", () => { - test("Console.error4", () => { +describe("Belt_Array.reverseInPlace", () => { + test("Belt_Array.reverseInPlace", () => { module Test = { - Console.error4("Hello", "World", "ReScript", '!') - Console.error4(#first, #second, #third, "fourth") + let arr = [10, 11, 12, 13, 14] + + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("Console.error5", () => { - test("Console.error5", () => { +describe("Belt_Array.slice", () => { + test("Belt_Array.slice", () => { module Test = { - Console.error5('e', 'r', 'r', 'o', 'r') - Console.error5(1, #second, #third, "fourth", 'c') + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Console.error6", () => { - test("Console.error6", () => { +describe("Belt_Array.sliceToEnd", () => { + test("Belt_Array.sliceToEnd", () => { module Test = { - Console.error6("Hello", "World", "from", "JS", "!!!", '!') - Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Belt_Set.union", () => { - test("Belt_Set.union", () => { +describe("Belt_Array.some", () => { + test("Belt_Array.some", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Belt_Set.every", () => { - test("Belt_Set.every", () => { +describe("Belt_Array.some2", () => { + test("Belt_Array.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - let isEven = x => mod(x, 2) == 0 + Belt.Array.some2([], [1], (x, y) => x > y) == false - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Belt_Set.split", () => { - test("Belt_Set.split", () => { +describe("Belt_Array.truncateToLengthUnsafe", () => { + test("Belt_Array.truncateToLengthUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let arr = ["ant", "bee", "cat", "dog", "elk"] - let ((smaller, larger), present) = s0->Belt.Set.split(3) + Belt.Array.truncateToLengthUnsafe(arr, 3) - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) + arr == ["ant", "bee", "cat"] } () }) }) -describe("Belt_Result.eq", () => { - test("Belt_Result.eq", () => { +describe("Belt_Array.unzip", () => { + test("Belt_Array.unzip", () => { module Test = { - let good1 = Belt.Result.Ok(42) - - let good2 = Belt.Result.Ok(32) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) - - Belt.Result.eq(good1, good2, mod10equal) == true - - Belt.Result.eq(good1, bad1, mod10equal) == false - - Belt.Result.eq(bad2, good2, mod10equal) == false + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - Belt.Result.eq(bad1, bad2, mod10equal) == true + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Belt_Option.eq", () => { - test("Belt_Option.eq", () => { +describe("Belt_Array.zip", () => { + test("Belt_Array.zip", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Belt.Option - - eq(Some(3), Some(15), clockEqual) /* true */ - - eq(Some(3), None, clockEqual) /* false */ - - eq(None, Some(3), clockEqual) /* false */ - - eq(None, None, clockEqual) /* true */ + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Belt_List.head", () => { - test("Belt_List.head", () => { +describe("Belt_Array.zipBy", () => { + test("Belt_Array.zipBy", () => { module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Belt_List.tail", () => { - test("Belt_List.tail", () => { +describe("Belt_Float.*", () => { + test("Belt_Float.*", () => { module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - - Belt.List.tail(list{}) // None + open Belt.Float + assertEqual(2.0 * 2.0, 4.0) } () }) }) -describe("Belt_List.make", () => { - test("Belt_List.make", () => { +describe("Belt_Float.+", () => { + test("Belt_Float.+", () => { module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} + open Belt.Float + assertEqual(2.0 + 2.0, 4.0) } () }) }) -describe("Belt_List.drop", () => { - test("Belt_List.drop", () => { +describe("Belt_Float.-", () => { + test("Belt_Float.-", () => { module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) - - list{1, 2, 3}->Belt.List.drop(4) // None + open Belt.Float + assertEqual(2.0 - 1.0, 1.0) } () }) }) -describe("Belt_List.take", () => { - test("Belt_List.take", () => { +describe("Belt_Float./", () => { + test("Belt_Float./", () => { module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->Belt.List.take(4) // None + open Belt.Float + assertEqual(4.0 / 2.0, 2.0) } () }) }) -describe("Belt_List.some", () => { - test("Belt_List.some", () => { +describe("Belt_Float.fromInt", () => { + test("Belt_Float.fromInt", () => { module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ } () }) }) -describe("Belt_List.keep", () => { - test("Belt_List.keep", () => { +describe("Belt_Float.fromString", () => { + test("Belt_Float.fromString", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ } () }) }) -describe("Belt_List.sort", () => { - test("Belt_List.sort", () => { +describe("Belt_Float.toInt", () => { + test("Belt_Float.toInt", () => { module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + Js.log(Belt.Float.toInt(1.0) === 1) /* true */ } () }) }) -describe("Belt.Array.get", () => { - test("Belt.Array.get", () => { +describe("Belt_Float.toString", () => { + test("Belt_Float.toString", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ } () }) }) -describe("Belt.Array.zip", () => { - test("Belt.Array.zip", () => { +describe("Belt_HashMap.clear", () => { + test("Belt_HashMap.clear", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) + Belt.HashMap.clear(hMap) + Belt.HashMap.isEmpty(hMap) == true } () }) }) -describe("Belt.Array.map", () => { - test("Belt.Array.map", () => { +describe("Belt_HashMap.copy", () => { + test("Belt_HashMap.copy", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let s1 = Belt.HashMap.copy(s0) + + Belt.HashMap.set(s0, 2, "3") + + Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) } () }) }) -describe("Belt.Array.cmp", () => { - test("Belt.Array.cmp", () => { +describe("Belt_HashMap.forEach", () => { + test("Belt_HashMap.forEach", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) + // prints (1, "value1") } () }) }) -describe("Belt.List.head", () => { - test("Belt.List.head", () => { +describe("Belt_HashMap.fromArray", () => { + test("Belt_HashMap.fromArray", () => { module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + + let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] } () }) }) -describe("Belt.List.tail", () => { - test("Belt.List.tail", () => { +describe("Belt_HashMap.get", () => { + test("Belt_HashMap.get", () => { module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.List.tail(list{}) // None + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + + Belt.HashMap.get(s0, 1) == Some("value1") + Belt.HashMap.get(s0, 2) == None } () }) }) -describe("Belt.List.make", () => { - test("Belt.List.make", () => { +describe("Belt_HashMap.getBucketHistogram", () => { + test("Belt_HashMap.getBucketHistogram", () => { module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.getBucketHistogram(hMap) } () }) }) -describe("Belt.List.drop", () => { - test("Belt.List.drop", () => { +describe("Belt_HashMap.has", () => { + test("Belt_HashMap.has", () => { module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") - list{1, 2, 3}->Belt.List.drop(4) // None + Belt.HashMap.has(s0, 1) == true + Belt.HashMap.has(s0, 2) == false } () }) }) -describe("Belt.List.take", () => { - test("Belt.List.take", () => { +describe("Belt_HashMap.isEmpty", () => { + test("Belt_HashMap.isEmpty", () => { module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - list{1, 2, 3}->Belt.List.take(4) // None + Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false } () }) }) -describe("Belt.List.some", () => { - test("Belt.List.some", () => { +describe("Belt_HashMap.keepMapInPlace", () => { + test("Belt_HashMap.keepMapInPlace", () => { module Test = { - let isAbove100 = value => value > 100 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ + Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) } () }) }) -describe("Belt.List.keep", () => { - test("Belt.List.keep", () => { +describe("Belt_HashMap.keysToArray", () => { + test("Belt_HashMap.keysToArray", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + Belt.HashMap.keysToArray(s0) == [1, 2] } () }) }) -describe("Belt.List.sort", () => { - test("Belt.List.sort", () => { +describe("Belt_HashMap.logStats", () => { + test("Belt_HashMap.logStats", () => { module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(hMap, 1, "1") + + Belt.HashMap.logStats(hMap) } () }) }) -describe("Belt.Set.union", () => { - test("Belt.Set.union", () => { +describe("Belt_HashMap.make", () => { + test("Belt_HashMap.make", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) + Belt.HashMap.set(hMap, 0, "a") } () }) }) -describe("Belt.Set.every", () => { - test("Belt.Set.every", () => { +describe("Belt_HashMap.mergeMany", () => { + test("Belt_HashMap.mergeMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) + let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) } () }) }) -describe("Belt.Set.split", () => { - test("Belt.Set.split", () => { +describe("Belt_HashMap.reduce", () => { + test("Belt_HashMap.reduce", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ + module IntHash = Belt.Id.MakeHashable({ type t = int - let cmp = Pervasives.compare + let hash = a => a + let eq = (a, b) => a == b }) - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - let ((smaller, larger), present) = s0->Belt.Set.split(3) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) + s0 + ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) + ->assertEqual(", value1, value2") + + Console.log("lol") } () }) }) -describe("Belt.Option.eq", () => { - test("Belt.Option.eq", () => { +describe("Belt_HashMap.remove", () => { + test("Belt_HashMap.remove", () => { module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - open Belt.Option + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.remove(s0, 1) + Belt.HashMap.has(s0, 1) == false + } + () + }) +}) - eq(Some(3), Some(15), clockEqual) /* true */ +describe("Belt_HashMap.set", () => { + test("Belt_HashMap.set", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - eq(Some(3), None, clockEqual) /* false */ + let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - eq(None, Some(3), clockEqual) /* false */ + Belt.HashMap.set(s0, 2, "3") - eq(None, None, clockEqual) /* true */ + Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] } () }) }) -describe("Belt.Result.eq", () => { - test("Belt.Result.eq", () => { +describe("Belt_HashMap.size", () => { + test("Belt_HashMap.size", () => { module Test = { - let good1 = Belt.Result.Ok(42) + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - let good2 = Belt.Result.Ok(32) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - let bad1 = Belt.Result.Error("invalid") + Belt.HashMap.size(s0) == 2 + } + () + }) +}) - let bad2 = Belt.Result.Error("really invalid") +describe("Belt_HashMap.toArray", () => { + test("Belt_HashMap.toArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - Belt.Result.eq(good1, good2, mod10equal) == true + Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + } + () + }) +}) - Belt.Result.eq(good1, bad1, mod10equal) == false +describe("Belt_HashMap.valuesToArray", () => { + test("Belt_HashMap.valuesToArray", () => { + module Test = { + module IntHash = Belt.Id.MakeHashable({ + type t = int + let hash = a => a + let eq = (a, b) => a == b + }) - Belt.Result.eq(bad2, good2, mod10equal) == false + let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.HashMap.set(s0, 1, "value1") + Belt.HashMap.set(s0, 2, "value2") - Belt.Result.eq(bad1, bad2, mod10equal) == true + Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] } () }) }) -describe("Belt_Array.get", () => { - test("Belt_Array.get", () => { +describe("Belt_Int.*", () => { + test("Belt_Int.*", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + open Belt.Int + assertEqual(2 * 2, 4) } () }) }) -describe("Belt_Array.zip", () => { - test("Belt_Array.zip", () => { +describe("Belt_Int.+", () => { + test("Belt_Int.+", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + open Belt.Int + assertEqual(2 + 2, 4) } () }) }) -describe("Belt_Array.map", () => { - test("Belt_Array.map", () => { +describe("Belt_Int.-", () => { + test("Belt_Int.-", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + open Belt.Int + assertEqual(2 - 1, 1) } () }) }) -describe("Belt_Array.cmp", () => { - test("Belt_Array.cmp", () => { +describe("Belt_Int./", () => { + test("Belt_Int./", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + open Belt.Int + assertEqual(4 / 2, 2) } () }) }) -describe("Array.pushMany", () => { - test("Array.pushMany", () => { +describe("Belt_Int.fromFloat", () => { + test("Belt_Int.fromFloat", () => { module Test = { - let someArray = ["hi", "hello"] - - someArray->Array.pushMany(["yay", "wehoo"]) - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) + Belt.Int.fromFloat(1.0)->assertEqual(1) } () }) }) -describe("Array.includes", () => { - test("Array.includes", () => { +describe("Belt_Int.fromString", () => { + test("Belt_Int.fromString", () => { module Test = { - [1, 2]->Array.includes(1)->assertEqual(true) - [1, 2]->Array.includes(3)->assertEqual(false) + Belt.Int.fromString("1")->assertEqual(Some(1)) + } + () + }) +}) - [{"language": "ReScript"}] - ->Array.includes({"language": "ReScript"}) - ->assertEqual(false) // false, because of strict equality +describe("Belt_Int.toFloat", () => { + test("Belt_Int.toFloat", () => { + module Test = { + Belt.Int.toFloat(1)->assertEqual(1.0) } () }) }) -describe("Array.joinWith", () => { - test("Array.joinWith", () => { +describe("Belt_Int.toString", () => { + test("Belt_Int.toString", () => { module Test = { - ["One", "Two", "Three"] - ->Array.joinWith(" -- ") - ->assertEqual("One -- Two -- Three") + Belt.Int.toString(1)->assertEqual("1") } () }) }) -describe("Array.toString", () => { - test("Array.toString", () => { +describe("Belt_List.add", () => { + test("Belt_List.add", () => { module Test = { - [1, 2, 3, 4] - ->Array.toString - ->assertEqual("1,2,3,4") + Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} + + Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Array.keepSome", () => { - test("Array.keepSome", () => { +describe("Belt_List.cmp", () => { + test("Belt_List.cmp", () => { module Test = { - Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) + Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) + Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - Array.keepSome([None, None, None])->assertEqual([]) + Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - Array.keepSome([])->assertEqual([]) + Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ + + Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ } () }) }) -describe("String.endsWith", () => { - test("String.endsWith", () => { +describe("Belt_List.cmpByLength", () => { + test("Belt_List.cmpByLength", () => { module Test = { - String.endsWith("BuckleScript", "Script") == true - String.endsWith("BuckleShoes", "Script") == false + Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ + + Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ + + Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ } () }) }) -describe("String.includes", () => { - test("String.includes", () => { +describe("Belt_List.concat", () => { + test("Belt_List.concat", () => { module Test = { - String.includes("programmer", "gram") == true - String.includes("programmer", "er") == true - String.includes("programmer", "pro") == true - String.includes("programmer.dat", "xyz") == false + Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("String.padStart", () => { - test("String.padStart", () => { +describe("Belt_List.concatMany", () => { + test("Belt_List.concatMany", () => { module Test = { - String.padStart("abc", 5, " ") == " abc" - String.padStart("abc", 6, "123465") == "123abc" + Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Result.mapError", () => { - test("Result.mapError", () => { +describe("Belt_List.drop", () => { + test("Belt_List.drop", () => { module Test = { - let format = n => `Error code: ${n->Int.toString}` - Result.mapError(Error(14), format) // Error("Error code: 14") - Result.mapError(Ok("abc"), format) // Ok("abc") + list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) + + list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) + + list{1, 2, 3}->Belt.List.drop(4) // None } () }) }) -describe("Promise.resolve", () => { - test("Promise.resolve", () => { +describe("Belt_List.eq", () => { + test("Belt_List.eq", () => { module Test = { - let p = Promise.resolve(5) // promise + Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ + + Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ + + Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Promise.finally", () => { - test("Promise.finally", () => { +describe("Belt_List.every", () => { + test("Belt_List.every", () => { module Test = { - open Promise - exception SomeError(string) - let isDone = ref(false) + let isBelow10 = value => value < 10 - resolve(5) - ->then( - _ => { - reject(SomeError("test")) - }, - ) - ->then( - v => { - Console.log2("final result", v) - resolve() - }, - ) - ->catch( - _ => { - Console.log("Error handled") - resolve() - }, - ) - ->finally( - () => { - Console.log("finally") - isDone := true - }, - ) - ->then( - () => { - Console.log2("isDone:", isDone.contents) - resolve() - }, - ) - ->ignore + list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + + list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ } () }) }) -describe("Object.isSealed", () => { - test("Object.isSealed", () => { +describe("Belt_List.every2", () => { + test("Belt_List.every2", () => { module Test = { - let point = {"x": 1, "y": 3}->Object.seal - let pointIsSealed = point->Object.isSealed // true - let fruit = {"name": "Apple"} - let fruitIsSealed = fruit->Object.isSealed // false + Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ } () }) }) -describe("Object.isFrozen", () => { - test("Object.isFrozen", () => { +describe("Belt_List.filter", () => { + test("Belt_List.filter", () => { module Test = { - let point = {"x": 1, "y": 3}->Object.freeze - let pointIsFrozen = point->Object.isFrozen // true - let fruit = {"name": "Apple"} - let fruitIsFrozen = fruit->Object.isFrozen // false + let isEven = x => mod(x, 2) == 0 + + Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + + Belt.List.filter( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Nullable.getExn", () => { - test("Nullable.getExn", () => { +describe("Belt_List.filterWithIndex", () => { + test("Belt_List.filterWithIndex", () => { module Test = { - switch Nullable.getExn(%raw("'Hello'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "Hello") - } - - switch Nullable.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + let isEven = x => mod(x, 2) == 0 - switch Nullable.getExn(%raw("undefined")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } + Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("List.toShuffled", () => { - test("List.toShuffled", () => { +describe("Belt_List.flatten", () => { + test("Belt_List.flatten", () => { module Test = { - List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} + Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("List.concatMany", () => { - test("List.concatMany", () => { +describe("Belt_List.forEach", () => { + test("Belt_List.forEach", () => { module Test = { - List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("List.mapReverse", () => { - test("List.mapReverse", () => { +describe("Belt_List.forEach2", () => { + test("Belt_List.forEach2", () => { module Test = { - let f = x => x * x - let l = list{3, 4, 5} - - let withMap = List.map(l, f)->List.reverse - let withMapReverse = l->List.mapReverse(f) + Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - Console.log(withMap == withMapReverse) // true + /* + prints: + "Z" "A" + "Y" "B" +*/ } () }) }) -describe("Null.asNullable", () => { - test("Null.asNullable", () => { +describe("Belt_List.forEachWithIndex", () => { + test("Belt_List.forEachWithIndex", () => { module Test = { - let nullValue = Null.make("Hello") - let asNullable = nullValue->Null.asNullable // Nullable.t + Belt.List.forEachWithIndex( + list{"a", "b", "c"}, + (index, x) => { + Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ } () }) }) -describe("Null.fromOption", () => { - test("Null.fromOption", () => { +describe("Belt_List.fromArray", () => { + test("Belt_List.fromArray", () => { module Test = { - let optString: option = None - let asNull = optString->Null.fromOption // Null.t - Console.log(asNull == Null.null) // Logs `true` to the console. + Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} } () }) }) -describe("Math.Int.random", () => { - test("Math.Int.random", () => { +describe("Belt_List.get", () => { + test("Belt_List.get", () => { module Test = { - Math.Int.random(2, 5) == 4 - Math.Int.random(505, 2000) == 1276 - Math.Int.random(-7, -2) == -4 + let abc = list{"A", "B", "C"} + + abc->Belt.List.get(1) // Some("B") + + abc->Belt.List.get(4) // None } () }) }) -describe("JSON.Encode.int", () => { - test("JSON.Encode.int", () => { +describe("Belt_List.getAssoc", () => { + test("Belt_List.getAssoc", () => { module Test = { - JSON.Encode.int(42) + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + /* Some("afternoon") */ } () }) }) -describe("Int.toPrecision", () => { - test("Int.toPrecision", () => { +describe("Belt_List.getBy", () => { + test("Belt_List.getBy", () => { module Test = { - Int.toPrecision(100) // "100" - Int.toPrecision(1) // "1" - Int.toPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecision(1, ~digits=2) // "1.0" + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + + Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ } () }) }) -describe("Int.Bitwise.lor", () => { - test("Int.Bitwise.lor", () => { +describe("Belt_List.getExn", () => { + test("Belt_List.getExn", () => { module Test = { - Int.Bitwise.lor(7, 4) == 7 + let abc = list{"A", "B", "C"} + + abc->Belt.List.getExn(1)->assertEqual("B") + + switch abc->Belt.List.getExn(4) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Int.Bitwise.lsl", () => { - test("Int.Bitwise.lsl", () => { +describe("Belt_List.has", () => { + test("Belt_List.has", () => { module Test = { - Int.Bitwise.lsl(4, 1) == 8 + list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ + + list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ + + list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ } () }) }) -describe("Int.Bitwise.lsr", () => { - test("Int.Bitwise.lsr", () => { +describe("Belt_List.hasAssoc", () => { + test("Belt_List.hasAssoc", () => { module Test = { - Int.Bitwise.lsr(8, 1) == 4 + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) /* false */ } () }) }) -describe("Int.Bitwise.asr", () => { - test("Int.Bitwise.asr", () => { +describe("Belt_List.head", () => { + test("Belt_List.head", () => { module Test = { - Int.Bitwise.asr(4, 1) == 2 + Belt.List.head(list{}) // None + Belt.List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Date.fromString", () => { - test("Date.fromString", () => { +describe("Belt_List.headExn", () => { + test("Belt_List.headExn", () => { module Test = { - Date.fromString("2023") // 2023-01-01T00:00:00.000Z - - Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z + Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z - - Date.fromString("") // Invalid Date - - Date.fromString("")->Date.getTime // NaN + switch Belt.List.headExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Date.makeWithYM", () => { - test("Date.makeWithYM", () => { +describe("Belt_List.keep", () => { + test("Belt_List.keep", () => { module Test = { - Date.makeWithYM(~year=2023, ~month=0) - // 2023-01-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=11) - // 2023-12-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=12) - // 2024-01-01T00:00:00.000Z + let isEven = x => mod(x, 2) == 0 - Date.makeWithYM(~year=2023, ~month=-1) - // 2022-12-01T00:00:00.000Z + Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.List.keep( + list{None, Some(2), Some(3), None}, + Belt.Option.isSome, + ) /* list{Some(2), Some(3)} */ } () }) }) -describe("Date.getMinutes", () => { - test("Date.getMinutes", () => { +describe("Belt_List.keepMap", () => { + test("Belt_List.keepMap", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes - // 40 + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->Belt.List.keepMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) /* list{2, 4} */ + + list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ } () }) }) -describe("Date.getSeconds", () => { - test("Date.getSeconds", () => { +describe("Belt_List.keepWithIndex", () => { + test("Belt_List.keepWithIndex", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds - // 0 + let isEven = x => mod(x, 2) == 0 + + Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ } () }) }) -describe("Date.setHoursMS", () => { - test("Date.setHoursMS", () => { +describe("Belt_List.length", () => { + test("Belt_List.length", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) + Belt.List.length(list{1, 2, 3}) // 3 } () }) }) -describe("Date.setMinutes", () => { - test("Date.setMinutes", () => { +describe("Belt_List.make", () => { + test("Belt_List.make", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) + Belt.List.make(3, 1) // list{1, 1, 1} } () }) }) -describe("Date.setSeconds", () => { - test("Date.setSeconds", () => { +describe("Belt_List.makeBy", () => { + test("Belt_List.makeBy", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) + Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + + Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} } () }) }) -describe("Date.getUTCDate", () => { - test("Date.getUTCDate", () => { +describe("Belt_List.map", () => { + test("Belt_List.map", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 + list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} } () }) }) -describe("Date.setUTCDate", () => { - test("Date.setUTCDate", () => { +describe("Belt_List.mapReverse", () => { + test("Belt_List.mapReverse", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) + list{3, 4, 5} + ->Belt.List.mapReverse(x => x * x) + ->assertEqual(list{25, 16, 9}) } () }) }) -describe("Console.assert_", () => { - test("Console.assert_", () => { +describe("Belt_List.mapReverse2", () => { + test("Belt_List.mapReverse2", () => { module Test = { - Console.assert_(false, "Hello World!") - Console.assert_(42 == 42, "The answer") + Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Console.assert2", () => { - test("Console.assert2", () => { +describe("Belt_List.mapWithIndex", () => { + test("Belt_List.mapWithIndex", () => { module Test = { - Console.assert2(false, "Hello", "World") - Console.assert2(42 == 42, [1, 2, 3], '4') + list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} } () }) }) -describe("Console.assert3", () => { - test("Console.assert3", () => { +describe("Belt_List.partition", () => { + test("Belt_List.partition", () => { module Test = { - Console.assert3(false, "Hello", "World", "ReScript") - Console.assert3(42 == 42, "One", 2, #3) + list{1, 2, 3, 4} + ->Belt.List.partition(x => x > 2) + ->assertEqual((list{3, 4}, list{1, 2})) } () }) }) -describe("Console.assert4", () => { - test("Console.assert4", () => { +describe("Belt_List.reduce", () => { + test("Belt_List.reduce", () => { module Test = { - let value = 42 - Console.assert4(false, "Hello", "World", "ReScript", "!!!") - Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) + list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + + /* same as */ + + list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ } () }) }) -describe("Console.assert5", () => { - test("Console.assert5", () => { +describe("Belt_List.reduce2", () => { + test("Belt_List.reduce2", () => { module Test = { - let value = 42 - Console.assert5(false, "Hello", "World", "JS", '!', '!') - Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) + Belt.List.reduce2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("Console.assert6", () => { - test("Console.assert6", () => { +describe("Belt_List.reduceReverse", () => { + test("Belt_List.reduceReverse", () => { module Test = { - let value = 42 - Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') - Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) + list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + + list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} } () }) }) -describe("Console.logMany", () => { - test("Console.logMany", () => { +describe("Belt_List.reduceReverse2", () => { + test("Belt_List.reduceReverse2", () => { module Test = { - Console.logMany(["Hello", "World"]) - Console.logMany([1, 2, 3]) + Belt.List.reduceReverse2( + list{1, 2, 3}, + list{4, 5}, + 0, + (acc, x, y) => acc + x * x + y, + ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ } () }) }) -describe("Console.timeEnd", () => { - test("Console.timeEnd", () => { +describe("Belt_List.reduceWithIndex", () => { + test("Belt_List.reduceWithIndex", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + list{1, 2, 3, 4}->Belt.List.reduceWithIndex( + 0, + (acc, item, index) => acc + item + index, + ) /* 16 */ } () }) }) -describe("Console.timeLog", () => { - test("Console.timeLog", () => { +describe("Belt_List.removeAssoc", () => { + test("Belt_List.removeAssoc", () => { module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( + 1, + (a, b) => a == b, + ) /* list{(2, "b"), (3, "c")} */ + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + /* list{(15, "afternoon"), (22, "night")} */ } () }) }) -describe("BigInt.toString", () => { - test("BigInt.toString", () => { +describe("Belt_List.reverse", () => { + test("Belt_List.reverse", () => { module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log + Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ } () }) }) -describe("Belt_Set.remove", () => { - test("Belt_Set.remove", () => { +describe("Belt_List.reverseConcat", () => { + test("Belt_List.reverseConcat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) - - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) + Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("Belt_Set.subset", () => { - test("Belt_Set.subset", () => { +describe("Belt_List.setAssoc", () => { + test("Belt_List.setAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( + 2, + "x", + (a, b) => a == b, + ) /* list{(1, "a"), (2, "x"), (3, "c")} */ - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) + list{(1, "a"), (3, "c")}->Belt.List.setAssoc( + 2, + "b", + (a, b) => a == b, + ) /* list{(2, "b"), (1, "a"), (3, "c")} */ - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) + list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ } () }) }) -describe("Belt_Set.reduce", () => { - test("Belt_Set.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) +describe("Belt_List.shuffle", () => { + test("Belt_List.shuffle", () => { + module Test = { + Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Belt_Set.toList", () => { - test("Belt_Set.toList", () => { +describe("Belt_List.some", () => { + test("Belt_List.some", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let isAbove100 = value => value > 100 - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ } () }) }) -describe("Belt_SetDict.eq", () => { - test("Belt_SetDict.eq", () => { +describe("Belt_List.some2", () => { + test("Belt_List.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + + Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ } () }) }) -describe("Belt_Result.map", () => { - test("Belt_Result.map", () => { +describe("Belt_List.sort", () => { + test("Belt_List.sort", () => { module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) - - Belt.Result.map(Ok(64), f) == Ok(8.0) - - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} } () }) }) -describe("Belt_Result.cmp", () => { - test("Belt_Result.cmp", () => { +describe("Belt_List.splitAt", () => { + test("Belt_List.splitAt", () => { module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Belt_Range.some", () => { - test("Belt_Range.some", () => { +describe("Belt_List.tail", () => { + test("Belt_List.tail", () => { module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ + Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - Belt.Range.some(0, 4, i => i > 2) /* true */ + Belt.List.tail(list{}) // None } () }) }) -describe("Belt_Option.map", () => { - test("Belt_Option.map", () => { +describe("Belt_List.tailExn", () => { + test("Belt_List.tailExn", () => { module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - Belt.Option.map(None, x => x * x) /* None */ + switch Belt.List.tailExn(list{}) { + // Raises an Error + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_Option.cmp", () => { - test("Belt_Option.cmp", () => { +describe("Belt_List.take", () => { + test("Belt_List.take", () => { module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ + list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - cmp(Some(14), None, clockCompare) /* 1 */ + list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - cmp(None, None, clockCompare) /* 0 */ + list{1, 2, 3}->Belt.List.take(4) // None } () }) }) -describe("Belt_Map.reduce", () => { - test("Belt_Map.reduce", () => { +describe("Belt_List.toArray", () => { + test("Belt_List.toArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) - - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Belt_Map.remove", () => { - test("Belt_Map.remove", () => { +describe("Belt_List.unzip", () => { + test("Belt_List.unzip", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) + Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ - s1 === s2 + Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + } + () + }) +}) - Belt.Map.keysToArray(s1) == [2, 3] +describe("Belt_List.zip", () => { + test("Belt_List.zip", () => { + module Test = { + Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} } () }) @@ -6021,1130 +6687,1332 @@ describe("Belt_List.zipBy", () => { }) }) -describe("Belt_List.every", () => { - test("Belt_List.every", () => { +describe("Belt_Map.Dict.findFirstBy", () => { + test("Belt_Map.Dict.findFirstBy", () => { module Test = { - let isBelow10 = value => value < 10 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("Belt_List.some2", () => { - test("Belt_List.some2", () => { +describe("Belt_Map.Int", () => { + test("Belt_Map.Int", () => { module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + type t<'key, 'value, 'identity> + type id<'key, 'id> = Belt_Id.comparable<'key, 'id> } () }) }) -describe("Belt_List.getBy", () => { - test("Belt_List.getBy", () => { +describe("Belt_Map.Int.findFirstBy", () => { + test("Belt_Map.Int.findFirstBy", () => { module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("Belt_List.unzip", () => { - test("Belt_List.unzip", () => { +describe("Belt_Map.String.findFirstBy", () => { + test("Belt_Map.String.findFirstBy", () => { module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Belt.MutableSet", () => { - test("Belt.MutableSet", () => { +describe("Belt_Map.findFirstBy", () => { + test("Belt_Map.findFirstBy", () => { module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) }) - let mySet = Belt.MutableSet.make(~id=module(PairComparator)) - mySet->Belt.MutableSet.add((1, 2)) + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) + + s0 + ->Belt.Map.findFirstBy((k, _) => k == 4) + ->assertEqual(Some(4, "4")) } () }) }) -describe("Belt.Array.fill", () => { - test("Belt.Array.fill", () => { +describe("Belt_Map.forEach", () => { + test("Belt_Map.forEach", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - arr == [0, 1, 9, 9, 4] + let acc = ref(list{}) - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) - arr == [0, 1, 9, 9, 4] + acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} } () }) }) -describe("Belt.Array.blit", () => { - test("Belt.Array.blit", () => { +describe("Belt_Map.fromArray", () => { + test("Belt_Map.fromArray", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt.Array.some", () => { - test("Belt.Array.some", () => { +describe("Belt_Map.get", () => { + test("Belt_Map.get", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + Some("2") -describe("Belt.List.zipBy", () => { - test("Belt.List.zipBy", () => { - module Test = { - Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} + Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == + None } () }) }) -describe("Belt.List.every", () => { - test("Belt.List.every", () => { +describe("Belt_Map.has", () => { + test("Belt_Map.has", () => { module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ + Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true } () }) }) -describe("Belt.List.some2", () => { - test("Belt.List.some2", () => { +describe("Belt_Map.isEmpty", () => { + test("Belt_Map.isEmpty", () => { module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ + Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false } () }) }) -describe("Belt.List.getBy", () => { - test("Belt.List.getBy", () => { +describe("Belt_Map.keysToArray", () => { + test("Belt_Map.keysToArray", () => { module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ + Belt.Map.keysToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == [1, 2, 3] } () }) }) -describe("Belt.List.unzip", () => { - test("Belt.List.unzip", () => { +describe("Belt_Map.make", () => { + test("Belt_Map.make", () => { module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ + let m = Belt.Map.make(~id=module(IntCmp)) + + Belt.Map.set(m, 0, "a") } () }) }) -describe("Belt.Range.some", () => { - test("Belt.Range.some", () => { +describe("Belt_Map.reduce", () => { + test("Belt_Map.reduce", () => { module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = (a, b) => Pervasives.compare(a, b) + }) - Belt.Range.some(0, 4, i => i > 2) /* true */ + let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) + + Belt.Map.reduce( + s0, + list{}, + (acc, k, v) => list{(k, v), ...acc}, + ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ } () }) }) -describe("Belt.Set.remove", () => { - test("Belt.Set.remove", () => { +describe("Belt_Map.remove", () => { + test("Belt_Map.remove", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) + let s1 = Belt.Map.remove(s0, 1) + + let s2 = Belt.Map.remove(s1, 1) + + s1 === s2 + + Belt.Map.keysToArray(s1) == [2, 3] } () }) }) -describe("Belt.Set.subset", () => { - test("Belt.Set.subset", () => { +describe("Belt_Map.set", () => { + test("Belt_Map.set", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) + let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) + let s1 = Belt.Map.set(s0, 2, "3") + + Belt.Map.valuesToArray(s1) == ["1", "3", "3"] } () }) }) -describe("Belt.Set.reduce", () => { - test("Belt.Set.reduce", () => { +describe("Belt_Map.size", () => { + test("Belt_Map.size", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) + Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 } () }) }) -describe("Belt.Set.toList", () => { - test("Belt.Set.toList", () => { +describe("Belt_Map.toArray", () => { + test("Belt_Map.toArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = Pervasives.compare + let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) + Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ + (1, "1"), + (2, "2"), + (3, "3"), + ] } () }) }) -describe("Belt.Map.reduce", () => { - test("Belt.Map.reduce", () => { +describe("Belt_Map.valuesToArray", () => { + test("Belt_Map.valuesToArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) - - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ + Belt.Map.valuesToArray( + Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), + ) == ["1", "2", "3"] } () }) }) -describe("Belt.Map.remove", () => { - test("Belt.Map.remove", () => { +describe("Belt_MapDict.findFirstBy", () => { + test("Belt_MapDict.findFirstBy", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) - - s1 === s2 + let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - Belt.Map.keysToArray(s1) == [2, 3] + Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) } () }) }) -describe("Belt.Option.map", () => { - test("Belt.Option.map", () => { +describe("Belt_MapInt.findFirstBy", () => { + test("Belt_MapInt.findFirstBy", () => { module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - Belt.Option.map(None, x => x * x) /* None */ + mapInt + ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") + ->assertEqual(Some(1, "one")) } () }) }) -describe("Belt.Option.cmp", () => { - test("Belt.Option.cmp", () => { +describe("Belt_MapString.findFirstBy", () => { + test("Belt_MapString.findFirstBy", () => { module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ - - cmp(Some(14), None, clockCompare) /* 1 */ + let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - cmp(None, None, clockCompare) /* 0 */ + mapString + ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") + ->assertEqual(Some("1", "one")) } () }) }) -describe("Belt.Result.map", () => { - test("Belt.Result.map", () => { +describe("Belt_MutableSet.add", () => { + test("Belt_MutableSet.add", () => { module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Result.map(Ok(64), f) == Ok(8.0) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + s0->Belt.MutableSet.add(1) + s0->Belt.MutableSet.add(2) + s0->Belt.MutableSet.add(2) - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") + s0->Belt.MutableSet.toArray /* [1, 2] */ } () }) }) -describe("Belt.Result.cmp", () => { - test("Belt.Result.cmp", () => { +describe("Belt_MutableSet.copy", () => { + test("Belt_MutableSet.copy", () => { module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let bad1 = Belt.Result.Error("invalid") + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 - - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 + let copied = s0->Belt.MutableSet.copy + copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Belt_Array.fill", () => { - test("Belt_Array.fill", () => { +describe("Belt_MutableSet.diff", () => { + test("Belt_MutableSet.diff", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ + Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + } + () + }) +}) - arr == [0, 1, 9, 9, 4] +describe("Belt_MutableSet.eq", () => { + test("Belt_MutableSet.eq", () => { + module Test = { + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) - arr == [0, 1, 9, 9, 4] + Belt.MutableSet.eq(s0, s1) /* true */ } () }) }) -describe("Belt_Array.blit", () => { - test("Belt_Array.blit", () => { +describe("Belt_MutableSet.every", () => { + test("Belt_MutableSet.every", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + let isEven = x => mod(x, 2) == 0 - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.every(isEven) /* true */ } () }) }) -describe("Belt_Array.some", () => { - test("Belt_Array.some", () => { +describe("Belt_MutableSet.forEach", () => { + test("Belt_MutableSet.forEach", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some([-1, -3, -5], x => x > 0) == false + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let acc = ref(list{}) + s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Array.fillToEnd", () => { - test("Array.fillToEnd", () => { +describe("Belt_MutableSet.fromArray", () => { + test("Belt_MutableSet.fromArray", () => { module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillToEnd(9, ~start=1) - myArray->assertEqual([1, 9, 9, 9]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Array.findIndex", () => { - test("Array.findIndex", () => { +describe("Belt_MutableSet.get", () => { + test("Belt_MutableSet.get", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - array - ->Array.findIndex(item => item == ReScript) - ->assertEqual(0) + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - array - ->Array.findIndex(item => item == TypeScript) - ->assertEqual(-1) + s0->Belt.MutableSet.get(3) /* Some(3) */ + s0->Belt.MutableSet.get(20) /* None */ } () }) }) -describe("Array.getUnsafe", () => { - test("Array.getUnsafe", () => { +describe("Belt_MutableSet.has", () => { + test("Belt_MutableSet.has", () => { module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.getUnsafe(index) - Console.log(value) - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) + + set->Belt.MutableSet.has(3) /* false */ + set->Belt.MutableSet.has(1) /* true */ } () }) }) -describe("Array.setUnsafe", () => { - test("Array.setUnsafe", () => { +describe("Belt_MutableSet.intersect", () => { + test("Belt_MutableSet.intersect", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.setUnsafe(1, "Hello") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - assertEqual(array[1], Some("Hello")) + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let intersect = Belt.MutableSet.intersect(s0, s1) + intersect->Belt.MutableSet.toArray /* [2,3,5] */ } () }) }) -describe("Array.filterMap", () => { - test("Array.filterMap", () => { +describe("Belt_MutableSet.isEmpty", () => { + test("Belt_MutableSet.isEmpty", () => { module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.filterMap( - item => - switch item { - | "Hello" => Some(item->String.length) - | _ => None - }, - ) - ->assertEqual([5]) - - [1, 2, 3, 4, 5, 6] - ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) - ->assertEqual([4, 16, 36]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) + let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) + let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) + Belt.MutableSet.isEmpty(empty) /* true */ + Belt.MutableSet.isEmpty(notEmpty) /* false */ } () }) }) -describe("String.getUnsafe", () => { - test("String.getUnsafe", () => { +describe("Belt_MutableSet.keep", () => { + test("Belt_MutableSet.keep", () => { module Test = { - String.getUnsafe("ReScript", 0) == "R" - String.getUnsafe("Hello", 4) == "o" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.MutableSet.keep(isEven) + + s1->Belt.MutableSet.toArray /* [2, 4] */ } () }) }) -describe("String.normalize", () => { - test("String.normalize", () => { +describe("Belt_MutableSet.maxUndefined", () => { + test("Belt_MutableSet.maxUndefined", () => { module Test = { - let string1 = "\u00F1" - let string2 = "\u006E\u0303" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - assert(string1 != string2) // true - assertEqual(String.normalize(string1), String.normalize(string2)) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maxUndefined /* undefined */ + s1->Belt.MutableSet.maxUndefined /* 5 */ } () }) }) -describe("String.searchOpt", () => { - test("String.searchOpt", () => { +describe("Belt_MutableSet.maximum", () => { + test("Belt_MutableSet.maximum", () => { module Test = { - String.searchOpt("testing 1 2 3", /\d+/) == Some(8) - String.searchOpt("no numbers", /\d+/) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.maximum /* None */ + s1->Belt.MutableSet.maximum /* Some(5) */ } () }) }) -describe("String.substring", () => { - test("String.substring", () => { +describe("Belt_MutableSet.mergeMany", () => { + test("Belt_MutableSet.mergeMany", () => { module Test = { - String.substring("playground", ~start=3, ~end=6) == "ygr" - String.substring("playground", ~start=6, ~end=3) == "ygr" - String.substring("playground", ~start=4, ~end=12) == "ground" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.make(~id=module(IntCmp)) + + set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("String.trimStart", () => { - test("String.trimStart", () => { +describe("Belt_MutableSet.minUndefined", () => { + test("Belt_MutableSet.minUndefined", () => { module Test = { - String.trimStart(" Hello world! ") == "Hello world! " - String.trimStart(" Hello world! ") == "Hello world! " + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minUndefined /* undefined */ + s1->Belt.MutableSet.minUndefined /* 1 */ } () }) }) -describe("Set.fromIterator", () => { - test("Set.fromIterator", () => { +describe("Belt_MutableSet.minimum", () => { + test("Belt_MutableSet.minimum", () => { module Test = { - // Let's pretend we have an interator - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - iterator - ->Set.fromIterator - ->Set.size - ->assertEqual(3) + let s0 = Belt.MutableSet.make(~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.minimum /* None */ + s1->Belt.MutableSet.minimum /* Some(1) */ } () }) }) -describe("RegExp.lastIndex", () => { - test("RegExp.lastIndex", () => { +describe("Belt_MutableSet.partition", () => { + test("Belt_MutableSet.partition", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console + let isOdd = x => mod(x, 2) != 0 - regexp->RegExp.exec(someStr)->ignore + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console + s1->Belt.MutableSet.toArray /* [1,3,5] */ + s2->Belt.MutableSet.toArray /* [2,4] */ } () }) }) -describe("RegExp.multiline", () => { - test("RegExp.multiline", () => { +describe("Belt_MutableSet.reduce", () => { + test("Belt_MutableSet.reduce", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") - Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0->Belt.MutableSet.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Option.getUnsafe", () => { - test("Option.getUnsafe", () => { +describe("Belt_MutableSet.remove", () => { + test("Belt_MutableSet.remove", () => { module Test = { - Option.getUnsafe(Some(3)) == 3 - Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + s0->Belt.MutableSet.remove(1) + s0->Belt.MutableSet.remove(3) + s0->Belt.MutableSet.remove(3) + + s0->Belt.MutableSet.toArray /* [2,4,5] */ } () }) }) -describe("Object.getSymbol", () => { - test("Object.getSymbol", () => { +describe("Belt_MutableSet.removeMany", () => { + test("Belt_MutableSet.removeMany", () => { module Test = { - let fruit = Symbol.make("fruit") - let x = Object.make() - x->Object.setSymbol(fruit, "banana") - x->Object.getSymbol(fruit) // Some("banana") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) + set->Belt.MutableSet.toArray /* [] */ } () }) }) -describe("Nullable.forEach", () => { - test("Nullable.forEach", () => { +describe("Belt_MutableSet.size", () => { + test("Belt_MutableSet.size", () => { module Test = { - Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" - Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () - Nullable.forEach(undefined, x => Console.log(x)) // returns () + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.MutableSet.size /* 4 */ } () }) }) -describe("Nullable.flatMap", () => { - test("Nullable.flatMap", () => { +describe("Belt_MutableSet.some", () => { + test("Belt_MutableSet.some", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Nullable.make(value + 1) - } else { - Nullable.null - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) - Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined - Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.MutableSet.some(isOdd) /* true */ } () }) }) -describe("List.mapReverse2", () => { - test("List.mapReverse2", () => { +describe("Belt_MutableSet.split", () => { + test("Belt_MutableSet.split", () => { module Test = { - List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + + present /* true */ + smaller->Belt.MutableSet.toArray /* [1,2] */ + larger->Belt.MutableSet.toArray /* [4,5] */ } () }) }) -describe("List.removeAssoc", () => { - test("List.removeAssoc", () => { +describe("Belt_MutableSet.subset", () => { + test("Belt_MutableSet.subset", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - // list{(15, "afternoon"), (22, "night")} + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.MutableSet.intersect(s0, s1) + Belt.MutableSet.subset(s2, s0) /* true */ + Belt.MutableSet.subset(s2, s1) /* true */ + Belt.MutableSet.subset(s1, s0) /* false */ } () }) }) -describe("Math.Constants.e", () => { - test("Math.Constants.e", () => { +describe("Belt_MutableSet.toArray", () => { + test("Belt_MutableSet.toArray", () => { module Test = { - Math.Constants.e + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toArray /* [1,2,3,5] */ } () }) }) -describe("Math.Int.minMany", () => { - test("Math.Int.minMany", () => { +describe("Belt_MutableSet.toList", () => { + test("Belt_MutableSet.toList", () => { module Test = { - Math.Int.minMany([1, 2]) // 1 - Math.Int.minMany([-1, -2]) // -2 - Math.Int.minMany([])->Int.toFloat->Float.isFinite // false + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.MutableSet.toList /* [1,2,3,5] */ } () }) }) -describe("Math.Int.maxMany", () => { - test("Math.Int.maxMany", () => { +describe("Belt_MutableSet.union", () => { + test("Belt_MutableSet.union", () => { module Test = { - Math.Int.maxMany([1, 2]) // 2 - Math.Int.maxMany([-1, -2]) // -1 - Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.MutableSet.union(s0, s1) + union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Map.fromIterator", () => { - test("Map.fromIterator", () => { +describe("Belt_Option.cmp", () => { + test("Belt_Option.cmp", () => { module Test = { - // Let's pretend we have an interator in the correct shape - let iterator: Iterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); + let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - map1.set('first', '1'); - map1.set('second', '2'); + open Belt.Option - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) + cmp(Some(3), Some(15), clockCompare) /* 0 */ - iterator - ->Map.fromIterator - ->Map.size - ->assertEqual(2) + cmp(Some(3), Some(14), clockCompare) /* 1 */ + + cmp(Some(2), Some(15), clockCompare) /* (-1) */ + + cmp(None, Some(15), clockCompare) /* (-1) */ + + cmp(Some(14), None, clockCompare) /* 1 */ + + cmp(None, None, clockCompare) /* 0 */ } () }) }) -describe("JSON.Encode.bool", () => { - test("JSON.Encode.bool", () => { +describe("Belt_Option.eq", () => { + test("Belt_Option.eq", () => { module Test = { - JSON.Encode.bool(true) + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) + + open Belt.Option + + eq(Some(3), Some(15), clockEqual) /* true */ + + eq(Some(3), None, clockEqual) /* false */ + + eq(None, Some(3), clockEqual) /* false */ + + eq(None, None, clockEqual) /* true */ } () }) }) -describe("JSON.Encode.null", () => { - test("JSON.Encode.null", () => { +describe("Belt_Option.flatMap", () => { + test("Belt_Option.flatMap", () => { module Test = { - JSON.Encode.null + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ + + Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ + + Belt.Option.flatMap(None, addIfAboveOne) /* None */ } () }) }) -describe("JSON.Decode.bool", () => { - test("JSON.Decode.bool", () => { +describe("Belt_Option.forEach", () => { + test("Belt_Option.forEach", () => { module Test = { - JSON.parseExn(`true`)->JSON.Decode.bool - // Some(true) - - JSON.parseExn(`"hello world"`)->JSON.Decode.bool - // None + Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ + Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ } () }) }) -describe("JSON.Decode.null", () => { - test("JSON.Decode.null", () => { +describe("Belt_Option.getExn", () => { + test("Belt_Option.getExn", () => { module Test = { - JSON.parseExn(`null`)->JSON.Decode.null - // Some(null) + Some(3) + ->Belt.Option.getExn + ->assertEqual(3) - JSON.parseExn(`"hello world"`)->JSON.Decode.null - // None + switch Belt.Option.getExn(None) { + // Raises an exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Iterator.toArray", () => { - test("Iterator.toArray", () => { +describe("Belt_Option.getWithDefault", () => { + test("Belt_Option.getWithDefault", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") + Belt.Option.getWithDefault(None, "Banana") /* Banana */ - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = map->Map.keys->Iterator.toArray + Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. + let greet = (firstName: option) => + "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") + + Some("Jane")->greet /* "Greetings Jane" */ + + None->greet /* "Greetings Anonymous" */ } () }) }) -describe("Iterator.forEach", () => { - test("Iterator.forEach", () => { +describe("Belt_Option.isNone", () => { + test("Belt_Option.isNone", () => { module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - iterator->Iterator.forEach( - v => { - switch v { - | Some("a" | "b" | "c") => assert(true) - | other => - other - ->Option.isNone - ->assertEqual(true) - } - }, - ) + Belt.Option.isNone(None) /* true */ + + Belt.Option.isNone(Some(1)) /* false */ } () }) }) -describe("Int.Bitwise.land", () => { - test("Int.Bitwise.land", () => { +describe("Belt_Option.isSome", () => { + test("Belt_Option.isSome", () => { module Test = { - Int.Bitwise.land(7, 4) == 4 + Belt.Option.isSome(None) /* false */ + + Belt.Option.isSome(Some(1)) /* true */ } () }) }) -describe("Int.Bitwise.lxor", () => { - test("Int.Bitwise.lxor", () => { +describe("Belt_Option.keep", () => { + test("Belt_Option.keep", () => { module Test = { - Int.Bitwise.lxor(7, 4) == 3 + Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ + Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ + Belt.Option.keep(None, x => x > 5) /* returns `None` */ } () }) }) -describe("Int.Bitwise.lnot", () => { - test("Int.Bitwise.lnot", () => { +describe("Belt_Option.map", () => { + test("Belt_Option.map", () => { module Test = { - Int.Bitwise.lnot(2) == -3 + Belt.Option.map(Some(3), x => x * x) /* Some(9) */ + + Belt.Option.map(None, x => x * x) /* None */ } () }) }) -describe("Float.parseFloat", () => { - test("Float.parseFloat", () => { +describe("Belt_Option.mapWithDefault", () => { + test("Belt_Option.mapWithDefault", () => { module Test = { - Float.parseFloat("1.0") // 1.0 - Float.parseFloat(" 3.14 ") // 3.14 - Float.parseFloat("3.0") // 3.0 - Float.parseFloat("3.14some non-digit characters") // 3.14 - Float.parseFloat("error")->Float.isNaN // true + let someValue = Some(3) + someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ + + let noneValue = None + noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ } () }) }) -describe("Float.fromString", () => { - test("Float.fromString", () => { +describe("Belt_Option.orElse", () => { + test("Belt_Option.orElse", () => { module Test = { - Float.fromString("0") == Some(0.0) - Float.fromString("NaN") == None - Float.fromString("6") == Some(6.0) + Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) + Belt.Option.orElse(None, Some(1066)) == Some(1066) + Belt.Option.orElse(None, None) == None } () }) }) -describe("Date.makeWithYMD", () => { - test("Date.makeWithYMD", () => { +describe("Belt_Range.every", () => { + test("Belt_Range.every", () => { module Test = { - Date.makeWithYMD(~year=2023, ~month=1, ~date=20) - // 2023-02-20T00:00:00.000Z - - Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) - // 2022-11-29T00:00:00.000Z + Belt.Range.every(0, 4, i => i < 5) /* true */ - Date.makeWithYMD(~year=2023, ~month=1, ~date=29) - // 2023-03-01T00:00:00.000Z + Belt.Range.every(0, 4, i => i < 4) /* false */ } () }) }) -describe("Date.getFullYear", () => { - test("Date.getFullYear", () => { +describe("Belt_Range.everyBy", () => { + test("Belt_Range.everyBy", () => { module Test = { - Date.fromString("2023-02-20")->Date.getFullYear - // 2023 + Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ + + Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Date.setFullYear", () => { - test("Date.setFullYear", () => { +describe("Belt_Range.forEach", () => { + test("Belt_Range.forEach", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) + Belt.Range.forEach(0, 4, i => Js.log(i)) + + // Prints: + // 0 + // 1 + // 2 + // 3 + // 4 } () }) }) -describe("Date.setMinutesS", () => { - test("Date.setMinutesS", () => { +describe("Belt_Range.some", () => { + test("Belt_Range.some", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) + Belt.Range.some(0, 4, i => i > 5) /* false */ + + Belt.Range.some(0, 4, i => i > 2) /* true */ } () }) }) -describe("Date.getUTCMonth", () => { - test("Date.getUTCMonth", () => { +describe("Belt_Range.someBy", () => { + test("Belt_Range.someBy", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 + Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ + Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ } () }) }) -describe("Date.getUTCHours", () => { - test("Date.getUTCHours", () => { +describe("Belt_Result.cmp", () => { + test("Belt_Result.cmp", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 + let good1 = Belt.Result.Ok(59) + + let good2 = Belt.Result.Ok(37) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) + + Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 + + Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 + + Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 + + Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 + + Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 } () }) }) -describe("Date.setUTCMonth", () => { - test("Date.setUTCMonth", () => { +describe("Belt_Result.eq", () => { + test("Belt_Result.eq", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) + let good1 = Belt.Result.Ok(42) + + let good2 = Belt.Result.Ok(32) + + let bad1 = Belt.Result.Error("invalid") + + let bad2 = Belt.Result.Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(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 } () }) }) -describe("Date.setUTCHours", () => { - test("Date.setUTCHours", () => { +describe("Belt_Result.flatMap", () => { + test("Belt_Result.flatMap", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) + let recip = x => + if x !== 0.0 { + Belt.Result.Ok(1.0 /. x) + } else { + Belt.Result.Error("Divide by zero") + } + + Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Date.toISOString", () => { - test("Date.toISOString", () => { +describe("Belt_Result.getExn", () => { + test("Belt_Result.getExn", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log - // 2023-01-01T00:00:00.000Z - - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log - // 2022-12-31T16:00:00.000Z + Belt.Result.Ok(42) + ->Belt.Result.getExn + ->assertEqual(42) + + switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { + // raise a exception + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Date.toUTCString", () => { - test("Date.toUTCString", () => { +describe("Belt_Result.getWithDefault", () => { + test("Belt_Result.getWithDefault", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log - // Sun, 01 Jan 2023 00:00:00 GMT + Belt.Result.getWithDefault(Ok(42), 0) == 42 - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log - // Sat, 31 Dec 2022 16:00:00 GMT + Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 } () }) }) -describe("Dict.keysToArray", () => { - test("Dict.keysToArray", () => { +describe("Belt_Result.map", () => { + test("Belt_Result.map", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let keys = dict->Dict.keysToArray - Console.log(keys) // Logs `["someKey", "someKey2"]` to the console + let f = x => sqrt(Belt.Int.toFloat(x)) + + Belt.Result.map(Ok(64), f) == Ok(8.0) + + Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Console.infoMany", () => { - test("Console.infoMany", () => { +describe("Belt_Result.mapWithDefault", () => { + test("Belt_Result.mapWithDefault", () => { module Test = { - Console.infoMany(["Hello", "World"]) - Console.infoMany([1, 2, 3]) + let ok = Belt.Result.Ok(42) + Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 + + let error = Belt.Result.Error("Invalid data") + Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 } () }) }) -describe("Console.warnMany", () => { - test("Console.warnMany", () => { +describe("Belt_Set.Dict.add", () => { + test("Belt_Set.Dict.add", () => { module Test = { - Console.warnMany(["Hello", "World"]) - Console.warnMany([1, 2, 3]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_Set.isEmpty", () => { - test("Belt_Set.isEmpty", () => { +describe("Belt_Set.Dict.diff", () => { + test("Belt_Set.Dict.diff", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - Belt.Set.isEmpty(empty)->assertEqual(true) - Belt.Set.isEmpty(notEmpty)->assertEqual(false) + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Belt_Set.forEach", () => { - test("Belt_Set.forEach", () => { +describe("Belt_Set.Dict.empty", () => { + test("Belt_Set.Dict.empty", () => { + module Test = { + let s0 = Belt.Set.Dict.empty + } + () + }) +}) + +describe("Belt_Set.Dict.eq", () => { + test("Belt_Set.Dict.eq", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - - let acc = ref(list{}) - - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) - }, - ) + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - acc.contents->assertEqual(list{6, 5, 3, 2}) + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_Set.toArray", () => { - test("Belt_Set.toArray", () => { +describe("Belt_Set.Dict.every", () => { + test("Belt_Set.Dict.every", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let isEven = x => mod(x, 2) == 0 - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Belt_Set.minimum", () => { - test("Belt_Set.minimum", () => { +describe("Belt_Set.Dict.forEach", () => { + test("Belt_Set.Dict.forEach", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Belt_Set.maximum", () => { - test("Belt_Set.maximum", () => { +describe("Belt_Set.Dict.fromArray", () => { + test("Belt_Set.Dict.fromArray", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - s0->Belt.Set.maximum->assertEqual(None) - s1->Belt.Set.maximum->assertEqual(Some(5)) + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Belt_Set.Dict.eq", () => { - test("Belt_Set.Dict.eq", () => { +describe("Belt_Set.Dict.get", () => { + test("Belt_Set.Dict.get", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ } () }) }) -describe("Belt_SetDict.has", () => { - test("Belt_SetDict.has", () => { +describe("Belt_Set.Dict.has", () => { + test("Belt_Set.Dict.has", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -7160,401 +8028,524 @@ describe("Belt_SetDict.has", () => { }) }) -describe("Belt_SetDict.add", () => { - test("Belt_SetDict.add", () => { +describe("Belt_Set.Dict.intersect", () => { + test("Belt_Set.Dict.intersect", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ } () }) }) -describe("Belt_SetDict.get", () => { - test("Belt_SetDict.get", () => { +describe("Belt_Set.Dict.isEmpty", () => { + test("Belt_Set.Dict.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("Belt_Range.every", () => { - test("Belt_Range.every", () => { +describe("Belt_Set.Dict.keep", () => { + test("Belt_Set.Dict.keep", () => { module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Range.every(0, 4, i => i < 4) /* false */ + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_Option.keep", () => { - test("Belt_Option.keep", () => { +describe("Belt_Set.Dict.maxUndefined", () => { + test("Belt_Set.Dict.maxUndefined", () => { module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ } () }) }) -describe("Belt_Map.isEmpty", () => { - test("Belt_Map.isEmpty", () => { +describe("Belt_Set.Dict.maximum", () => { + test("Belt_Set.Dict.maximum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("Belt_Map.forEach", () => { - test("Belt_Map.forEach", () => { +describe("Belt_Set.Dict.mergeMany", () => { + test("Belt_Set.Dict.mergeMany", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - let acc = ref(list{}) - - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + let set = Belt.Set.Dict.empty - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("Belt_Map.toArray", () => { - test("Belt_Map.toArray", () => { +describe("Belt_Set.Dict.minUndefined", () => { + test("Belt_Set.Dict.minUndefined", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("Belt_Int.toFloat", () => { - test("Belt_Int.toFloat", () => { +describe("Belt_Set.Dict.minimum", () => { + test("Belt_Set.Dict.minimum", () => { module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) - } - () - }) -}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) -describe("Belt_List.length", () => { - test("Belt_List.length", () => { - module Test = { - Belt.List.length(list{1, 2, 3}) // 3 + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("Belt_List.getExn", () => { - test("Belt_List.getExn", () => { +describe("Belt_Set.Dict.partition", () => { + test("Belt_Set.Dict.partition", () => { module Test = { - let abc = list{"A", "B", "C"} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - abc->Belt.List.getExn(1)->assertEqual("B") + let isOdd = x => mod(x, 2) != 0 - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("Belt_List.makeBy", () => { - test("Belt_List.makeBy", () => { +describe("Belt_Set.Dict.reduce", () => { + test("Belt_Set.Dict.reduce", () => { module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Belt_List.concat", () => { - test("Belt_List.concat", () => { +describe("Belt_Set.Dict.remove", () => { + test("Belt_Set.Dict.remove", () => { module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_List.reduce", () => { - test("Belt_List.reduce", () => { +describe("Belt_Set.Dict.removeMany", () => { + test("Belt_Set.Dict.removeMany", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - /* same as */ + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("Belt_List.every2", () => { - test("Belt_List.every2", () => { +describe("Belt_Set.Dict.size", () => { + test("Belt_Set.Dict.size", () => { module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Belt_List.filter", () => { - test("Belt_List.filter", () => { +describe("Belt_Set.Dict.some", () => { + test("Belt_Set.Dict.some", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + let isOdd = x => mod(x, 2) != 0 - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("Belt.Array.range", () => { - test("Belt.Array.range", () => { +describe("Belt_Set.Dict.split", () => { + test("Belt_Set.Dict.split", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.range(3, 0) == [] + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - Belt.Array.range(3, 3) == [3] + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) + + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("Belt.Array.zipBy", () => { - test("Belt.Array.zipBy", () => { +describe("Belt_Set.Dict.subset", () => { + test("Belt_Set.Dict.subset", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("Belt.Array.unzip", () => { - test("Belt.Array.unzip", () => { +describe("Belt_Set.Dict.toArray", () => { + test("Belt_Set.Dict.toArray", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("Belt.Array.slice", () => { - test("Belt.Array.slice", () => { +describe("Belt_Set.Dict.toList", () => { + test("Belt_Set.Dict.toList", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("Belt.Array.getBy", () => { - test("Belt.Array.getBy", () => { +describe("Belt_Set.Dict.union", () => { + test("Belt_Set.Dict.union", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Belt.Array.every", () => { - test("Belt.Array.every", () => { +describe("Belt_Set.add", () => { + test("Belt_Set.add", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every([1, -3, 5], x => x > 0) == false + let s0 = Belt.Set.make(~id=module(IntCmp)) + + let s1 = s0->Belt.Set.add(1) + let s2 = s1->Belt.Set.add(2) + let s3 = s2->Belt.Set.add(2) + + s0->Belt.Set.toArray->assertEqual([]) + s1->Belt.Set.toArray->assertEqual([1]) + s2->Belt.Set.toArray->assertEqual([1, 2]) + s3->Belt.Set.toArray->assertEqual([1, 2]) + assertEqual(s2, s3) } () }) }) -describe("Belt.Array.some2", () => { - test("Belt.Array.some2", () => { +describe("Belt_Set.diff", () => { + test("Belt_Set.diff", () => { module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.some2([], [1], (x, y) => x > y) == false + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + Belt.Set.diff(s0, s1) + ->Belt.Set.toArray + ->assertEqual([6]) + + Belt.Set.diff(s1, s0) + ->Belt.Set.toArray + ->assertEqual([1, 4]) } () }) }) -describe("Belt.List.length", () => { - test("Belt.List.length", () => { +describe("Belt_Set.eq", () => { + test("Belt_Set.eq", () => { module Test = { - Belt.List.length(list{1, 2, 3}) // 3 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) + + Belt.Set.eq(s0, s1)->assertEqual(true) } () }) }) -describe("Belt.List.getExn", () => { - test("Belt.List.getExn", () => { +describe("Belt_Set.every", () => { + test("Belt_Set.every", () => { module Test = { - let abc = list{"A", "B", "C"} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - abc->Belt.List.getExn(1)->assertEqual("B") + let isEven = x => mod(x, 2) == 0 - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.every(isEven)->assertEqual(true) } () }) }) -describe("Belt.List.makeBy", () => { - test("Belt.List.makeBy", () => { +describe("Belt_Set.forEach", () => { + test("Belt_Set.forEach", () => { module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} - } - () - }) -}) + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) -describe("Belt.List.concat", () => { - test("Belt.List.concat", () => { - module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} + let acc = ref(list{}) + + s0->Belt.Set.forEach( + x => { + acc := Belt.List.add(acc.contents, x) + }, + ) + + acc.contents->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt.List.reduce", () => { - test("Belt.List.reduce", () => { +describe("Belt_Set.fromArray", () => { + test("Belt_Set.fromArray", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - /* same as */ + let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) } () }) }) -describe("Belt.List.every2", () => { - test("Belt.List.every2", () => { +describe("Belt_Set.get", () => { + test("Belt_Set.get", () => { module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ + s0->Belt.Set.get(3)->assertEqual(Some(3)) + s0->Belt.Set.get(20)->assertEqual(None) } () }) }) -describe("Belt.List.filter", () => { - test("Belt.List.filter", () => { +describe("Belt_Set.has", () => { + test("Belt_Set.has", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ + let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ + set->Belt.Set.has(3)->assertEqual(false) + set->Belt.Set.has(1)->assertEqual(true) } () }) }) -describe("Belt.Range.every", () => { - test("Belt.Range.every", () => { +describe("Belt_Set.intersect", () => { + test("Belt_Set.intersect", () => { module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Range.every(0, 4, i => i < 4) /* false */ + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + + let intersect = Belt.Set.intersect(s0, s1) + + intersect + ->Belt.Set.toArray + ->assertEqual([2, 3, 5]) } () }) }) -describe("Belt.Set.isEmpty", () => { - test("Belt.Set.isEmpty", () => { +describe("Belt_Set.isEmpty", () => { + test("Belt_Set.isEmpty", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -7571,48 +8562,43 @@ describe("Belt.Set.isEmpty", () => { }) }) -describe("Belt.Set.forEach", () => { - test("Belt.Set.forEach", () => { +describe("Belt_Set.keep", () => { + test("Belt_Set.keep", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - - let acc = ref(list{}) + let isEven = x => mod(x, 2) == 0 - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) - }, - ) + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.keep(isEven) - acc.contents->assertEqual(list{6, 5, 3, 2}) + s1->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt.Set.toArray", () => { - test("Belt.Set.toArray", () => { +describe("Belt_Set.make", () => { + test("Belt_Set.make", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let set = Belt.Set.make(~id=module(IntCmp)) - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) + Belt.Set.isEmpty(set)->assertEqual(true) } () }) }) -describe("Belt.Set.minimum", () => { - test("Belt.Set.minimum", () => { +describe("Belt_Set.maxUndefined", () => { + test("Belt_Set.maxUndefined", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -7622,15 +8608,22 @@ describe("Belt.Set.minimum", () => { let s0 = Belt.Set.make(~id=module(IntCmp)) let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) + s0 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(None) + + s1 + ->Belt.Set.maxUndefined + ->Js.Undefined.toOption + ->assertEqual(Some(5)) } () }) }) -describe("Belt.Set.maximum", () => { - test("Belt.Set.maximum", () => { +describe("Belt_Set.maximum", () => { + test("Belt_Set.maximum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int @@ -7647,2797 +8640,2599 @@ describe("Belt.Set.maximum", () => { }) }) -describe("Belt.Map.isEmpty", () => { - test("Belt.Map.isEmpty", () => { +describe("Belt_Set.mergeMany", () => { + test("Belt_Set.mergeMany", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false + let set = Belt.Set.make(~id=module(IntCmp)) + + let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5]) } () }) }) -describe("Belt.Map.forEach", () => { - test("Belt.Map.forEach", () => { +describe("Belt_Set.minUndefined", () => { + test("Belt_Set.minUndefined", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - let acc = ref(list{}) - - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} + s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) + s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) } () }) }) -describe("Belt.Map.toArray", () => { - test("Belt.Map.toArray", () => { +describe("Belt_Set.minimum", () => { + test("Belt_Set.minimum", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int - let cmp = (a, b) => Pervasives.compare(a, b) + let cmp = Pervasives.compare }) - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + let s0 = Belt.Set.make(~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.minimum->assertEqual(None) + s1->Belt.Set.minimum->assertEqual(Some(1)) } () }) }) -describe("Belt.HashMap.set", () => { - test("Belt.HashMap.set", () => { +describe("Belt_Set.partition", () => { + test("Belt_Set.partition", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) + let isOdd = x => mod(x, 2) != 0 - Belt.HashMap.set(s0, 2, "3") + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + let (s1, s2) = s0->Belt.Set.partition(isOdd) - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + s1->Belt.Set.toArray->assertEqual([1, 3, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4]) } () }) }) -describe("Belt.HashMap.get", () => { - test("Belt.HashMap.get", () => { +describe("Belt_Set.reduce", () => { + test("Belt_Set.reduce", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + s0 + ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) + ->assertEqual(list{6, 5, 3, 2}) } () }) }) -describe("Belt.HashMap.has", () => { - test("Belt.HashMap.has", () => { +describe("Belt_Set.remove", () => { + test("Belt_Set.remove", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") + let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) + let s1 = s0->Belt.Set.remove(1) + let s2 = s1->Belt.Set.remove(3) + let s3 = s2->Belt.Set.remove(3) - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false + s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) + s2->Belt.Set.toArray->assertEqual([2, 4, 5]) + assertEqual(s2, s3) } () }) }) -describe("Belt.Option.keep", () => { - test("Belt.Option.keep", () => { +describe("Belt_Set.removeMany", () => { + test("Belt_Set.removeMany", () => { module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ - } - () - }) -}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) -describe("Belt.Int.toFloat", () => { - test("Belt.Int.toFloat", () => { - module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) + let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) + + newSet + ->Belt.Set.toArray + ->assertEqual([]) } () }) }) -describe("Belt.Float.toInt", () => { - test("Belt.Float.toInt", () => { +describe("Belt_Set.size", () => { + test("Belt_Set.size", () => { module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) + + s0->Belt.Set.size->assertEqual(4) } () }) }) -describe("Belt.Set.Dict.eq", () => { - test("Belt.Set.Dict.eq", () => { +describe("Belt_Set.some", () => { + test("Belt_Set.some", () => { module Test = { module IntCmp = Belt.Id.MakeComparable({ type t = int let cmp = Pervasives.compare }) - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) + let isOdd = x => mod(x, 2) != 0 - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ + let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) + s0->Belt.Set.some(isOdd)->assertEqual(true) } () }) }) -describe("Belt_Float.toInt", () => { - test("Belt_Float.toInt", () => { +describe("Belt_Set.split", () => { + test("Belt_Set.split", () => { module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) + + let ((smaller, larger), present) = s0->Belt.Set.split(3) + + present->assertEqual(true) + smaller->Belt.Set.toArray->assertEqual([1, 2]) + larger->Belt.Set.toArray->assertEqual([4, 5]) } () }) }) -describe("Belt_Array.range", () => { - test("Belt_Array.range", () => { +describe("Belt_Set.subset", () => { + test("Belt_Set.subset", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.range(3, 0) == [] + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let s2 = Belt.Set.intersect(s0, s1) - Belt.Array.range(3, 3) == [3] + Belt.Set.subset(s2, s0)->assertEqual(true) + Belt.Set.subset(s2, s1)->assertEqual(true) + Belt.Set.subset(s1, s0)->assertEqual(false) } () }) }) -describe("Belt_Array.zipBy", () => { - test("Belt_Array.zipBy", () => { +describe("Belt_Set.toArray", () => { + test("Belt_Set.toArray", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) } () }) }) -describe("Belt_Array.unzip", () => { - test("Belt_Array.unzip", () => { +describe("Belt_Set.toList", () => { + test("Belt_Set.toList", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + + s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) } () }) }) -describe("Belt_Array.slice", () => { - test("Belt_Array.slice", () => { +describe("Belt_Set.union", () => { + test("Belt_Set.union", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) + let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + let union = Belt.Set.union(s0, s1) - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + union + ->Belt.Set.toArray + ->assertEqual([1, 2, 3, 4, 5, 6]) } () }) }) -describe("Belt_Array.getBy", () => { - test("Belt_Array.getBy", () => { +describe("Belt_SetDict.add", () => { + test("Belt_SetDict.add", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.toArray /* [] */ + s1->Belt.Set.Dict.toArray /* [1] */ + s2->Belt.Set.Dict.toArray /* [1, 2] */ + s3->Belt.Set.Dict.toArray /* [1,2 ] */ + s2 == s3 /* true */ } () }) }) -describe("Belt_Array.every", () => { - test("Belt_Array.every", () => { +describe("Belt_SetDict.diff", () => { + test("Belt_SetDict.diff", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Belt.Array.every([1, -3, 5], x => x > 0) == false + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + + let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) + let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + + diff1->Belt.Set.Dict.toArray /* [6] */ + diff2->Belt.Set.Dict.toArray /* [1,4] */ } () }) }) -describe("Belt_Array.some2", () => { - test("Belt_Array.some2", () => { +describe("Belt_SetDict.empty", () => { + test("Belt_SetDict.empty", () => { module Test = { - 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 + let s0 = Belt.Set.Dict.empty } () }) }) -describe("Belt_HashMap.set", () => { - test("Belt_HashMap.set", () => { +describe("Belt_SetDict.eq", () => { + test("Belt_SetDict.eq", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - - Belt.HashMap.set(s0, 2, "3") + let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] + Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Belt_HashMap.get", () => { - test("Belt_HashMap.get", () => { +describe("Belt_SetDict.every", () => { + test("Belt_SetDict.every", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") + let isEven = x => mod(x, 2) == 0 - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None + let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.every(isEven) /* true */ } () }) }) -describe("Belt_HashMap.has", () => { - test("Belt_HashMap.has", () => { +describe("Belt_SetDict.forEach", () => { + test("Belt_SetDict.forEach", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ + module IntCmp = Belt.Id.MakeComparable({ type t = int - let hash = a => a - let eq = (a, b) => a == b + let cmp = Pervasives.compare }) - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let acc = ref(list{}) + s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) + acc /* [6,5,3,2] */ } () }) }) -describe("Array.concatMany", () => { - test("Array.concatMany", () => { +describe("Belt_SetDict.fromArray", () => { + test("Belt_SetDict.fromArray", () => { module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay"] - let array3 = ["wehoo"] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let someArray = array1->Array.concatMany([array2, array3]) + let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] + s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ } () }) }) -describe("Array.indexOfOpt", () => { - test("Array.indexOfOpt", () => { +describe("Belt_SetDict.get", () => { + test("Belt_SetDict.get", () => { module Test = { - [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) - [1, 2]->Array.indexOfOpt(3)->assertEqual(None) - [{"language": "ReScript"}] - ->Array.indexOfOpt({"language": "ReScript"}) - ->assertEqual(None) // None, because of strict equality + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ + s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ } () }) }) -describe("Array.joinUnsafe", () => { - test("Array.joinUnsafe", () => { +describe("Belt_SetDict.has", () => { + test("Belt_SetDict.has", () => { module Test = { - [1, 2, 3] - ->Array.joinUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") - } - () - }) -}) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) -describe("Array.sliceToEnd", () => { - test("Array.sliceToEnd", () => { - module Test = { - [1, 2, 3, 4] - ->Array.sliceToEnd(~start=1) - ->assertEqual([2, 3, 4]) + let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + + set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ + set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ } () }) }) -describe("Array.unsafe_get", () => { - test("Array.unsafe_get", () => { +describe("Belt_SetDict.intersect", () => { + test("Belt_SetDict.intersect", () => { module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.unsafe_get(index) - Console.log(value) - } + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + intersect->Belt.Set.Dict.toArray /* [2,3,5] */ } () }) }) -describe("Array.toShuffled", () => { - test("Array.toShuffled", () => { +describe("Belt_SetDict.isEmpty", () => { + test("Belt_SetDict.isEmpty", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let shuffledArray = array->Array.toShuffled - Console.log(shuffledArray) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - Array.toShuffled([1, 2, 3]) - ->Array.length - ->assertEqual(3) + let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) + let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + + Belt.Set.Dict.isEmpty(empty) /* true */ + Belt.Set.Dict.isEmpty(notEmpty) /* false */ } () }) }) -describe("String.charCodeAt", () => { - test("String.charCodeAt", () => { +describe("Belt_SetDict.keep", () => { + test("Belt_SetDict.keep", () => { module Test = { - String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat - String.codePointAt(`😺`, 0) == Some(0x1f63a) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isEven = x => mod(x, 2) == 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.keep(isEven) + + s1->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("String.concatMany", () => { - test("String.concatMany", () => { +describe("Belt_SetDict.maxUndefined", () => { + test("Belt_SetDict.maxUndefined", () => { module Test = { - String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maxUndefined /* undefined */ + s1->Belt.Set.Dict.maxUndefined /* 5 */ } () }) }) -describe("String.indexOfOpt", () => { - test("String.indexOfOpt", () => { +describe("Belt_SetDict.maximum", () => { + test("Belt_SetDict.maximum", () => { module Test = { - String.indexOfOpt("bookseller", "ok") == Some(2) - String.indexOfOpt("bookseller", "xyz") == None + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.maximum /* None */ + s1->Belt.Set.Dict.maximum /* Some(5) */ } () }) }) -describe("String.replaceAll", () => { - test("String.replaceAll", () => { +describe("Belt_SetDict.mergeMany", () => { + test("Belt_SetDict.mergeMany", () => { module Test = { - String.replaceAll("old old string", "old", "new") == "new new string" - String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let set = Belt.Set.Dict.empty + + let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ } () }) }) -describe("String.sliceToEnd", () => { - test("String.sliceToEnd", () => { +describe("Belt_SetDict.minUndefined", () => { + test("Belt_SetDict.minUndefined", () => { module Test = { - String.sliceToEnd("abcdefg", ~start=4) == "efg" - String.sliceToEnd("abcdefg", ~start=-2) == "fg" - String.sliceToEnd("abcdefg", ~start=7) == "" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minUndefined /* undefined */ + s1->Belt.Set.Dict.minUndefined /* 1 */ } () }) }) -describe("String.startsWith", () => { - test("String.startsWith", () => { +describe("Belt_SetDict.minimum", () => { + test("Belt_SetDict.minimum", () => { module Test = { - String.startsWith("BuckleScript", "Buckle") == true - String.startsWith("BuckleScript", "") == true - String.startsWith("JavaScript", "Buckle") == false + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.empty + let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.minimum /* None */ + s1->Belt.Set.Dict.minimum /* Some(1) */ } () }) }) -describe("RegExp.fromString", () => { - test("RegExp.fromString", () => { +describe("Belt_SetDict.partition", () => { + test("Belt_SetDict.partition", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) + let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + + s1->Belt.Set.Dict.toArray /* [1,3,5] */ + s2->Belt.Set.Dict.toArray /* [2,4] */ } () }) }) -describe("RegExp.ignoreCase", () => { - test("RegExp.ignoreCase", () => { +describe("Belt_SetDict.reduce", () => { + test("Belt_SetDict.reduce", () => { module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.reduce( + list{}, + (acc, element) => acc->Belt.List.add(element), + ) /* [6,5,3,2] */ } () }) }) -describe("Pervasives.import", () => { - test("Pervasives.import", () => { +describe("Belt_SetDict.remove", () => { + test("Belt_SetDict.remove", () => { module Test = { - @send external indexOf: (array<'a>, 'a) => int = "indexOf" + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - let indexOfOpt = (arr, item) => - switch arr->indexOf(item) { - | -1 => None - | index => Some(index) - } + let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) + let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) + let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let main = async () => { - let indexOfOpt = await import(Array.indexOfOpt) - let index = indexOfOpt([1, 2], 2) - Console.log(index) - } + s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ + s2->Belt.Set.Dict.toArray /* [2,4,5] */ + s2 == s3 /* true */ } () }) }) -describe("Nullable.toOption", () => { - test("Nullable.toOption", () => { +describe("Belt_SetDict.removeMany", () => { + test("Belt_SetDict.removeMany", () => { module Test = { - let nullableString = Nullable.make("Hello") + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - switch nullableString->Nullable.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } + let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) + newSet->Belt.Set.Dict.toArray /* [] */ } () }) }) -describe("List.mapWithIndex", () => { - test("List.mapWithIndex", () => { +describe("Belt_SetDict.size", () => { + test("Belt_SetDict.size", () => { module Test = { - list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.size /* 4 */ } () }) }) -describe("Math.Constants.pi", () => { - test("Math.Constants.pi", () => { +describe("Belt_SetDict.some", () => { + test("Belt_SetDict.some", () => { module Test = { - Math.Constants.pi + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let isOdd = x => mod(x, 2) != 0 + + let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) + s0->Belt.Set.Dict.some(isOdd) /* true */ } () }) }) -describe("JSON.stringifyAny", () => { - test("JSON.stringifyAny", () => { +describe("Belt_SetDict.split", () => { + test("Belt_SetDict.split", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - dict - ->JSON.stringifyAny(~replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - // Raise a exception - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + present /* true */ + smaller->Belt.Set.Dict.toArray /* [1,2] */ + larger->Belt.Set.Dict.toArray /* [4,5] */ } () }) }) -describe("JSON.Encode.float", () => { - test("JSON.Encode.float", () => { +describe("Belt_SetDict.subset", () => { + test("Belt_SetDict.subset", () => { module Test = { - JSON.Encode.float(42.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) + + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) + Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ + Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ } () }) }) -describe("JSON.Encode.array", () => { - test("JSON.Encode.array", () => { +describe("Belt_SetDict.toArray", () => { + test("Belt_SetDict.toArray", () => { module Test = { - let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.Encode.array(array) + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ } () }) }) -describe("JSON.Decode.float", () => { - test("JSON.Decode.float", () => { +describe("Belt_SetDict.toList", () => { + test("Belt_SetDict.toList", () => { module Test = { - JSON.parseExn(`42.0`)->JSON.Decode.float - // Some(42.0) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.parseExn(`"hello world"`)->JSON.Decode.float - // None + let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + + s0->Belt.Set.Dict.toList /* [1,2,3,5] */ } () }) }) -describe("JSON.Decode.array", () => { - test("JSON.Decode.array", () => { +describe("Belt_SetDict.union", () => { + test("Belt_SetDict.union", () => { module Test = { - JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array - // Some([ 'foo', 'bar' ]) + module IntCmp = Belt.Id.MakeComparable({ + type t = int + let cmp = Pervasives.compare + }) - JSON.parseExn(`"hello world"`)->JSON.Decode.array - // None + let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) + let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) + let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) + union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ } () }) }) -describe("Int.toExponential", () => { - test("Int.toExponential", () => { +describe("Belt_SortArray.binarySearchBy", () => { + test("Belt_SortArray.binarySearchBy", () => { module Test = { - Int.toExponential(1000) // "1e+3" - Int.toExponential(-1000) // "-1e+3" - Int.toExponential(77, ~digits=2) // "7.70e+1" - Int.toExponential(5678, ~digits=2) // "5.68e+3" + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("Float.toPrecision", () => { - test("Float.toPrecision", () => { +describe("Belt_SortArray.strictlySortedLength", () => { + test("Belt_SortArray.strictlySortedLength", () => { module Test = { - Float.toPrecision(100.0) // "100" - Float.toPrecision(1.0) // "1" - Float.toPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecision(1.0, ~digits=1) // "1" + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("Error.toException", () => { - test("Error.toException", () => { +describe("Belt_internalMapInt.A.blit", () => { + test("Belt_internalMapInt.A.blit", () => { module Test = { - let error = Error.make("Something went wrong.") + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - let asExn = error->Error.toException // `asExn` is now type `exn` + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Date.makeWithYMDH", () => { - test("Date.makeWithYMDH", () => { +describe("Belt_internalMapInt.A.cmp", () => { + test("Belt_internalMapInt.A.cmp", () => { module Test = { - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 2023-02-20T16:00:00.000Z - - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 2023-02-21T00:00:00.000Z + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 2023-02-19T23:00:00.000Z + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Date.setFullYearM", () => { - test("Date.setFullYearM", () => { +describe("Belt_internalMapInt.A.concat", () => { + test("Belt_internalMapInt.A.concat", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Date.setHoursMSMs", () => { - test("Date.setHoursMSMs", () => { +describe("Belt_internalMapInt.A.concatMany", () => { + test("Belt_internalMapInt.A.concatMany", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Date.setSecondsMs", () => { - test("Date.setSecondsMs", () => { +describe("Belt_internalMapInt.A.eq", () => { + test("Belt_internalMapInt.A.eq", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Date.setUTCHoursM", () => { - test("Date.setUTCHoursM", () => { +describe("Belt_internalMapInt.A.every", () => { + test("Belt_internalMapInt.A.every", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Date.toDateString", () => { - test("Date.toDateString", () => { +describe("Belt_internalMapInt.A.every2", () => { + test("Belt_internalMapInt.A.every2", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log - // Sun Jan 01 2023 + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log - // Sat Dec 31 2022 + 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 } () }) }) -describe("Date.toTimeString", () => { - test("Date.toTimeString", () => { +describe("Belt_internalMapInt.A.fill", () => { + test("Belt_internalMapInt.A.fill", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log - // 00:00:00 GMT+0100 (Central European Standard Time) + let arr = Belt.Array.makeBy(5, i => i) - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log - // 17:00:00 GMT+0100 (Central European Standard Time) + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Dict.fromIterator", () => { - test("Dict.fromIterator", () => { +describe("Belt_internalMapInt.A.flatMap", () => { + test("Belt_internalMapInt.A.flatMap", () => { module Test = { - let iterator: Iterator.t<(string, int)> = %raw(` - (() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - iterator - ->Dict.fromIterator - ->Dict.valuesToArray - ->assertEqual([1, 2]) - } - () - }) -}) - -describe("Console.debugMany", () => { - test("Console.debugMany", () => { - module Test = { - Console.debugMany(["Hello", "World"]) - Console.debugMany([1, 2, 3]) + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Console.errorMany", () => { - test("Console.errorMany", () => { +describe("Belt_internalMapInt.A.forEach", () => { + test("Belt_internalMapInt.A.forEach", () => { module Test = { - Console.errorMany(["Hello", "World"]) - Console.errorMany([1, 2, 3]) - } - () - }) -}) + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) -describe("Belt_Set.Dict.has", () => { - test("Belt_Set.Dict.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Belt_Set.Dict.add", () => { - test("Belt_Set.Dict.add", () => { +describe("Belt_internalMapInt.A.forEachWithIndex", () => { + test("Belt_internalMapInt.A.forEachWithIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Belt_Set.Dict.get", () => { - test("Belt_Set.Dict.get", () => { +describe("Belt_internalMapInt.A.get", () => { + test("Belt_internalMapInt.A.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Belt_SetDict.diff", () => { - test("Belt_SetDict.diff", () => { +describe("Belt_internalMapInt.A.getBy", () => { + test("Belt_internalMapInt.A.getBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_SetDict.some", () => { - test("Belt_SetDict.some", () => { +describe("Belt_internalMapInt.A.getIndexBy", () => { + test("Belt_internalMapInt.A.getIndexBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_SetDict.keep", () => { - test("Belt_SetDict.keep", () => { +describe("Belt_internalMapInt.A.joinWith", () => { + test("Belt_internalMapInt.A.joinWith", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Belt_SetDict.size", () => { - test("Belt_SetDict.size", () => { +describe("Belt_internalMapInt.A.keepMap", () => { + test("Belt_internalMapInt.A.keepMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Belt_Range.someBy", () => { - test("Belt_Range.someBy", () => { +describe("Belt_internalMapInt.A.keepWithIndex", () => { + test("Belt_internalMapInt.A.keepWithIndex", () => { module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Belt_Int.toString", () => { - test("Belt_Int.toString", () => { +describe("Belt_internalMapInt.A.length", () => { + test("Belt_internalMapInt.A.length", () => { module Test = { - Belt.Int.toString(1)->assertEqual("1") + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Belt_List.headExn", () => { - test("Belt_List.headExn", () => { +describe("Belt_internalMapInt.A.makeBy", () => { + test("Belt_internalMapInt.A.makeBy", () => { module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Belt_List.tailExn", () => { - test("Belt_List.tailExn", () => { +describe("Belt_internalMapInt.A.makeUninitialized", () => { + test("Belt_internalMapInt.A.makeUninitialized", () => { module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + let arr: array> = Belt.Array.makeUninitialized(5) - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Belt_List.shuffle", () => { - test("Belt_List.shuffle", () => { +describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Belt_List.splitAt", () => { - test("Belt_List.splitAt", () => { +describe("Belt_internalMapInt.A.map", () => { + test("Belt_internalMapInt.A.map", () => { module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Belt_List.flatten", () => { - test("Belt_List.flatten", () => { +describe("Belt_internalMapInt.A.mapWithIndex", () => { + test("Belt_internalMapInt.A.mapWithIndex", () => { module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Belt_List.toArray", () => { - test("Belt_List.toArray", () => { +describe("Belt_internalMapInt.A.partition", () => { + test("Belt_internalMapInt.A.partition", () => { module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Belt_List.reverse", () => { - test("Belt_List.reverse", () => { +describe("Belt_internalMapInt.A.range", () => { + test("Belt_internalMapInt.A.range", () => { module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Belt_List.forEach", () => { - test("Belt_List.forEach", () => { +describe("Belt_internalMapInt.A.rangeBy", () => { + test("Belt_internalMapInt.A.rangeBy", () => { module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] + + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Belt_List.reduce2", () => { - test("Belt_List.reduce2", () => { +describe("Belt_internalMapInt.A.reduce", () => { + test("Belt_internalMapInt.A.reduce", () => { module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Belt_List.keepMap", () => { - test("Belt_List.keepMap", () => { +describe("Belt_internalMapInt.A.reduceReverse", () => { + test("Belt_internalMapInt.A.reduceReverse", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ - - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Belt.Array.length", () => { - test("Belt.Array.length", () => { +describe("Belt_internalMapInt.A.reduceReverse2", () => { + test("Belt_internalMapInt.A.reduceReverse2", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("Belt.Array.makeBy", () => { - test("Belt.Array.makeBy", () => { +describe("Belt_internalMapInt.A.reduceWithIndex", () => { + test("Belt_internalMapInt.A.reduceWithIndex", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Belt.Array.concat", () => { - test("Belt.Array.concat", () => { +describe("Belt_internalMapInt.A.reverse", () => { + test("Belt_internalMapInt.A.reverse", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Belt.Array.reduce", () => { - test("Belt.Array.reduce", () => { +describe("Belt_internalMapInt.A.reverseInPlace", () => { + test("Belt_internalMapInt.A.reverseInPlace", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + let arr = [10, 11, 12, 13, 14] - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("Belt.Array.every2", () => { - test("Belt.Array.every2", () => { +describe("Belt_internalMapInt.A.slice", () => { + test("Belt_internalMapInt.A.slice", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - - Belt.Array.every2([], [1], (x, y) => x > y) == true + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Belt.List.headExn", () => { - test("Belt.List.headExn", () => { +describe("Belt_internalMapInt.A.sliceToEnd", () => { + test("Belt_internalMapInt.A.sliceToEnd", () => { module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Belt.List.tailExn", () => { - test("Belt.List.tailExn", () => { +describe("Belt_internalMapInt.A.some", () => { + test("Belt_internalMapInt.A.some", () => { module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Belt.List.shuffle", () => { - test("Belt.List.shuffle", () => { +describe("Belt_internalMapInt.A.some2", () => { + test("Belt_internalMapInt.A.some2", () => { module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} + 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 } () }) }) -describe("Belt.List.splitAt", () => { - test("Belt.List.splitAt", () => { +describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) + let arr = ["ant", "bee", "cat", "dog", "elk"] - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("Belt.List.flatten", () => { - test("Belt.List.flatten", () => { +describe("Belt_internalMapInt.A.unzip", () => { + test("Belt_internalMapInt.A.unzip", () => { module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Belt.List.toArray", () => { - test("Belt.List.toArray", () => { +describe("Belt_internalMapInt.A.zip", () => { + test("Belt_internalMapInt.A.zip", () => { module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Belt.List.reverse", () => { - test("Belt.List.reverse", () => { +describe("Belt_internalMapInt.A.zipBy", () => { + test("Belt_internalMapInt.A.zipBy", () => { module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Belt.List.forEach", () => { - test("Belt.List.forEach", () => { +describe("Belt_internalMapInt.S.binarySearchBy", () => { + test("Belt_internalMapInt.S.binarySearchBy", () => { module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("Belt.List.reduce2", () => { - test("Belt.List.reduce2", () => { +describe("Belt_internalMapInt.S.strictlySortedLength", () => { + test("Belt_internalMapInt.S.strictlySortedLength", () => { module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("Belt.List.keepMap", () => { - test("Belt.List.keepMap", () => { +describe("Belt_internalMapString.A.blit", () => { + test("Belt_internalMapString.A.blit", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Belt.Range.someBy", () => { - test("Belt.Range.someBy", () => { +describe("Belt_internalMapString.A.cmp", () => { + test("Belt_internalMapString.A.cmp", () => { module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Belt.HashMap.make", () => { - test("Belt.HashMap.make", () => { +describe("Belt_internalMapString.A.concat", () => { + test("Belt_internalMapString.A.concat", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - Belt.HashMap.set(hMap, 0, "a") + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Belt.HashMap.copy", () => { - test("Belt.HashMap.copy", () => { +describe("Belt_internalMapString.A.concatMany", () => { + test("Belt_internalMapString.A.concatMany", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Belt.HashMap.size", () => { - test("Belt.HashMap.size", () => { +describe("Belt_internalMapString.A.eq", () => { + test("Belt_internalMapString.A.eq", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.size(s0) == 2 + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Belt.Int.toString", () => { - test("Belt.Int.toString", () => { +describe("Belt_internalMapString.A.every", () => { + test("Belt_internalMapString.A.every", () => { module Test = { - Belt.Int.toString(1)->assertEqual("1") + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Belt.Set.Dict.has", () => { - test("Belt.Set.Dict.has", () => { +describe("Belt_internalMapString.A.every2", () => { + test("Belt_internalMapString.A.every2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) + Belt.Array.every2([], [1], (x, y) => x > y) == true - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ + Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + + Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false } () }) }) -describe("Belt.Set.Dict.add", () => { - test("Belt.Set.Dict.add", () => { +describe("Belt_internalMapString.A.fill", () => { + test("Belt_internalMapString.A.fill", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let arr = Belt.Array.makeBy(5, i => i) - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Belt.Set.Dict.get", () => { - test("Belt.Set.Dict.get", () => { +describe("Belt_internalMapString.A.flatMap", () => { + test("Belt_internalMapString.A.flatMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Belt_Array.length", () => { - test("Belt_Array.length", () => { +describe("Belt_internalMapString.A.forEach", () => { + test("Belt_internalMapString.A.forEach", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) + + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Belt_Array.makeBy", () => { - test("Belt_Array.makeBy", () => { +describe("Belt_internalMapString.A.forEachWithIndex", () => { + test("Belt_internalMapString.A.forEachWithIndex", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Belt_Array.concat", () => { - test("Belt_Array.concat", () => { +describe("Belt_internalMapString.A.get", () => { + test("Belt_internalMapString.A.get", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Belt_Array.reduce", () => { - test("Belt_Array.reduce", () => { +describe("Belt_internalMapString.A.getBy", () => { + test("Belt_internalMapString.A.getBy", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_Array.every2", () => { - test("Belt_Array.every2", () => { +describe("Belt_internalMapString.A.getIndexBy", () => { + test("Belt_internalMapString.A.getIndexBy", () => { module Test = { - 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 + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_HashMap.make", () => { - test("Belt_HashMap.make", () => { +describe("Belt_internalMapString.A.joinWith", () => { + test("Belt_internalMapString.A.joinWith", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(hMap, 0, "a") + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Belt_HashMap.copy", () => { - test("Belt_HashMap.copy", () => { +describe("Belt_internalMapString.A.keepMap", () => { + test("Belt_internalMapString.A.keepMap", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Belt_HashMap.size", () => { - test("Belt_HashMap.size", () => { +describe("Belt_internalMapString.A.keepWithIndex", () => { + test("Belt_internalMapString.A.keepWithIndex", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.size(s0) == 2 + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Array.unshiftMany", () => { - test("Array.unshiftMany", () => { +describe("Belt_internalMapString.A.length", () => { + test("Belt_internalMapString.A.length", () => { module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshiftMany(["yay", "wehoo"]) - someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Array.reduceRight", () => { - test("Array.reduceRight", () => { +describe("Belt_internalMapString.A.makeBy", () => { + test("Belt_internalMapString.A.makeBy", () => { module Test = { - Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") - - Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - Array.reduceRight([], list{}, List.add)->assertEqual(list{}) + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("String.codePointAt", () => { - test("String.codePointAt", () => { +describe("Belt_internalMapString.A.makeUninitialized", () => { + test("Belt_internalMapString.A.makeUninitialized", () => { module Test = { - String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) - String.codePointAt("abc", 5) == None + let arr: array> = Belt.Array.makeUninitialized(5) + + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("String.indexOfFrom", () => { - test("String.indexOfFrom", () => { +describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { + test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { module Test = { - String.indexOfFrom("bookseller", "ok", 1) == 2 - String.indexOfFrom("bookseller", "sell", 2) == 4 - String.indexOfFrom("bookseller", "sell", 5) == -1 + let arr = Belt.Array.makeUninitializedUnsafe(5) + + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("String.lastIndexOf", () => { - test("String.lastIndexOf", () => { +describe("Belt_internalMapString.A.map", () => { + test("Belt_internalMapString.A.map", () => { module Test = { - String.lastIndexOf("bookseller", "ok") == 2 - String.lastIndexOf("beekeeper", "ee") == 4 - String.lastIndexOf("abcdefg", "xyz") == -1 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("String.splitAtMost", () => { - test("String.splitAtMost", () => { - module Test = { - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ - "ant", - "bee", - "cat", - "dog", - "elk", - ] +describe("Belt_internalMapString.A.mapWithIndex", () => { + test("Belt_internalMapString.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("String.toLowerCase", () => { - test("String.toLowerCase", () => { +describe("Belt_internalMapString.A.partition", () => { + test("Belt_internalMapString.A.partition", () => { module Test = { - String.toLowerCase("ABC") == "abc" - String.toLowerCase(`ΣΠ`) == `σπ` - String.toLowerCase(`ΠΣ`) == `πς` + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("String.toUpperCase", () => { - test("String.toUpperCase", () => { +describe("Belt_internalMapString.A.range", () => { + test("Belt_internalMapString.A.range", () => { module Test = { - String.toUpperCase("abc") == "ABC" - String.toUpperCase(`Straße`) == `STRASSE` - String.toUpperCase(`πς`) == `ΠΣ` + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Promise.allSettled", () => { - test("Promise.allSettled", () => { +describe("Belt_internalMapString.A.rangeBy", () => { + test("Belt_internalMapString.A.rangeBy", () => { module Test = { - open Promise + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - exception TestError(string) + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + Belt.Array.rangeBy(33, 0, ~step=1) == [] - allSettled(promises) - ->then( - results => { - results->Array.forEach( - result => { - switch result { - | Fulfilled({value: num}) => Console.log2("Number: ", num) - | Rejected({reason}) => Console.log(reason) - } - }, - ) + Belt.Array.rangeBy(33, 0, ~step=-1) == [] - resolve() - }, - ) - ->ignore + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Object.keysToArray", () => { - test("Object.keysToArray", () => { +describe("Belt_internalMapString.A.reduce", () => { + test("Belt_internalMapString.A.reduce", () => { module Test = { - {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] - {"a": None}->Object.keysToArray // ["a"] - Object.make()->Object.keysToArray // [] + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Nullable.undefined", () => { - test("Nullable.undefined", () => { +describe("Belt_internalMapString.A.reduceReverse", () => { + test("Belt_internalMapString.A.reduceReverse", () => { module Test = { - Console.log(undefined) // Logs `undefined` to the console. + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Nullable.getUnsafe", () => { - test("Nullable.getUnsafe", () => { +describe("Belt_internalMapString.A.reduceReverse2", () => { + test("Belt_internalMapString.A.reduceReverse2", () => { module Test = { - Nullable.getUnsafe(Nullable.make(3)) == 3 - Nullable.getUnsafe(Nullable.null) // Raises an error + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("List.reverseConcat", () => { - test("List.reverseConcat", () => { +describe("Belt_internalMapString.A.reduceWithIndex", () => { + test("Belt_internalMapString.A.reduceWithIndex", () => { module Test = { - List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("List.reduceReverse", () => { - test("List.reduceReverse", () => { +describe("Belt_internalMapString.A.reverse", () => { + test("Belt_internalMapString.A.reverse", () => { module Test = { - list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 - - list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 - - list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("List.compareLength", () => { - test("List.compareLength", () => { +describe("Belt_internalMapString.A.reverseInPlace", () => { + test("Belt_internalMapString.A.reverseInPlace", () => { module Test = { - List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. + let arr = [10, 11, 12, 13, 14] - List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. + let () = Belt.Array.reverseInPlace(arr) - List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. + arr == [14, 13, 12, 11, 10] } () }) }) -describe("Math.Constants.ln2", () => { - test("Math.Constants.ln2", () => { +describe("Belt_internalMapString.A.slice", () => { + test("Belt_internalMapString.A.slice", () => { module Test = { - Math.Constants.ln2 + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Map.forEachWithKey", () => { - test("Map.forEachWithKey", () => { +describe("Belt_internalMapString.A.sliceToEnd", () => { + test("Belt_internalMapString.A.sliceToEnd", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - map->Map.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("JSON.Encode.string", () => { - test("JSON.Encode.string", () => { +describe("Belt_internalMapString.A.some", () => { + test("Belt_internalMapString.A.some", () => { module Test = { - JSON.Encode.string("hello world") + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("JSON.Encode.object", () => { - test("JSON.Encode.object", () => { +describe("Belt_internalMapString.A.some2", () => { + test("Belt_internalMapString.A.some2", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ]) + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - JSON.Encode.object(dict) + Belt.Array.some2([], [1], (x, y) => x > y) == false + + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("JSON.Decode.string", () => { - test("JSON.Decode.string", () => { +describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { module Test = { - JSON.parseExn(`"hello world"`)->JSON.Decode.string - // Some("hello world") + let arr = ["ant", "bee", "cat", "dog", "elk"] - JSON.parseExn(`42`)->JSON.Decode.string - // None + Belt.Array.truncateToLengthUnsafe(arr, 3) + + arr == ["ant", "bee", "cat"] } () }) }) -describe("JSON.Decode.object", () => { - test("JSON.Decode.object", () => { +describe("Belt_internalMapString.A.unzip", () => { + test("Belt_internalMapString.A.unzip", () => { module Test = { - JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object - // Some({ foo: 'bar' }) + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - JSON.parseExn(`"hello world"`)->JSON.Decode.object - // None + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Int.toLocaleString", () => { - test("Int.toLocaleString", () => { +describe("Belt_internalMapString.A.zip", () => { + test("Belt_internalMapString.A.zip", () => { module Test = { - // If the application uses English as the default language - Int.toLocaleString(1000) // "1,000" - - // If the application uses Portuguese Brazil as the default language - Int.toLocaleString(1000) // "1.000" + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Date.makeWithYMDHM", () => { - test("Date.makeWithYMDHM", () => { +describe("Belt_internalMapString.A.zipBy", () => { + test("Belt_internalMapString.A.zipBy", () => { module Test = { - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 2023-02-20T17:00:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 2023-02-20T15:59:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Date.setFullYearMD", () => { - test("Date.setFullYearMD", () => { +describe("Belt_internalMapString.S.binarySearchBy", () => { + test("Belt_internalMapString.S.binarySearchBy", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) + Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + + lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 } () }) }) -describe("Date.setMinutesSMs", () => { - test("Date.setMinutesSMs", () => { +describe("Belt_internalMapString.S.strictlySortedLength", () => { + test("Belt_internalMapString.S.strictlySortedLength", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 + + Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 + + Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 + + Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 } () }) }) -describe("Date.getUTCMinutes", () => { - test("Date.getUTCMinutes", () => { +describe("Belt_internalSetInt.A.blit", () => { + test("Belt_internalSetInt.A.blit", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] + + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Date.getUTCSeconds", () => { - test("Date.getUTCSeconds", () => { +describe("Belt_internalSetInt.A.cmp", () => { + test("Belt_internalSetInt.A.cmp", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Date.setUTCHoursMS", () => { - test("Date.setUTCHoursMS", () => { +describe("Belt_internalSetInt.A.concat", () => { + test("Belt_internalSetInt.A.concat", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( - ~hours=0, - ~minutes=0, - ~seconds=0, - ) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Date.setUTCMinutes", () => { - test("Date.setUTCMinutes", () => { +describe("Belt_internalSetInt.A.concatMany", () => { + test("Belt_internalSetInt.A.concatMany", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Date.setUTCSeconds", () => { - test("Date.setUTCSeconds", () => { +describe("Belt_internalSetInt.A.eq", () => { + test("Belt_internalSetInt.A.eq", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Dict.valuesToArray", () => { - test("Dict.valuesToArray", () => { +describe("Belt_internalSetInt.A.every", () => { + test("Belt_internalSetInt.A.every", () => { module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let values = dict->Dict.valuesToArray - Console.log(values) // Logs `[1, 2]` to the console + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Console.assertMany", () => { - test("Console.assertMany", () => { +describe("Belt_internalSetInt.A.every2", () => { + test("Belt_internalSetInt.A.every2", () => { module Test = { - let value = 42 - Console.assertMany(false, ["Hello", "World"]) - Console.assertMany(value == 42, [1, 2, 3]) + 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 } () }) }) -describe("Console.countReset", () => { - test("Console.countReset", () => { +describe("Belt_internalSetInt.A.fill", () => { + test("Belt_internalSetInt.A.fill", () => { module Test = { - Console.countReset("rescript") + let arr = Belt.Array.makeBy(5, i => i) + + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) + + arr == [0, 1, 9, 9, 4] + + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Belt_Set.fromArray", () => { - test("Belt_Set.fromArray", () => { +describe("Belt_internalSetInt.A.flatMap", () => { + test("Belt_internalSetInt.A.flatMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Belt_Set.mergeMany", () => { - test("Belt_Set.mergeMany", () => { +describe("Belt_internalSetInt.A.forEach", () => { + test("Belt_internalSetInt.A.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - let set = Belt.Set.make(~id=module(IntCmp)) + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Belt_Set.intersect", () => { - test("Belt_Set.intersect", () => { +describe("Belt_internalSetInt.A.forEachWithIndex", () => { + test("Belt_internalSetInt.A.forEachWithIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) - let intersect = Belt.Set.intersect(s0, s1) + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Belt_Set.partition", () => { - test("Belt_Set.partition", () => { +describe("Belt_internalSetInt.A.get", () => { + test("Belt_internalSetInt.A.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) - - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Belt_Set.Dict.diff", () => { - test("Belt_Set.Dict.diff", () => { +describe("Belt_internalSetInt.A.getBy", () => { + test("Belt_internalSetInt.A.getBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_Set.Dict.some", () => { - test("Belt_Set.Dict.some", () => { +describe("Belt_internalSetInt.A.getIndexBy", () => { + test("Belt_internalSetInt.A.getIndexBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt_Set.Dict.keep", () => { - test("Belt_Set.Dict.keep", () => { +describe("Belt_internalSetInt.A.joinWith", () => { + test("Belt_internalSetInt.A.joinWith", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Belt_Set.Dict.size", () => { - test("Belt_Set.Dict.size", () => { +describe("Belt_internalSetInt.A.keepMap", () => { + test("Belt_internalSetInt.A.keepMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Belt_SetDict.empty", () => { - test("Belt_SetDict.empty", () => { +describe("Belt_internalSetInt.A.keepWithIndex", () => { + test("Belt_internalSetInt.A.keepWithIndex", () => { module Test = { - let s0 = Belt.Set.Dict.empty + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Belt_SetDict.union", () => { - test("Belt_SetDict.union", () => { +describe("Belt_internalSetInt.A.length", () => { + test("Belt_internalSetInt.A.length", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Belt_SetDict.every", () => { - test("Belt_SetDict.every", () => { +describe("Belt_internalSetInt.A.makeBy", () => { + test("Belt_internalSetInt.A.makeBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Belt_SetDict.split", () => { - test("Belt_SetDict.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) +describe("Belt_internalSetInt.A.makeUninitialized", () => { + test("Belt_internalSetInt.A.makeUninitialized", () => { + module Test = { + let arr: array> = Belt.Array.makeUninitialized(5) - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Belt_Result.getExn", () => { - test("Belt_Result.getExn", () => { +describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) + let arr = Belt.Array.makeUninitializedUnsafe(5) - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } + Js.log(Belt.Array.getExn(arr, 0)) // undefined + + Belt.Array.setExn(arr, 0, "example") + + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Belt_Range.forEach", () => { - test("Belt_Range.forEach", () => { +describe("Belt_internalSetInt.A.map", () => { + test("Belt_internalSetInt.A.map", () => { module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) - - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 + Belt.Array.map([1, 2], x => x + 1) == [3, 4] } () }) }) -describe("Belt_Range.everyBy", () => { - test("Belt_Range.everyBy", () => { +describe("Belt_internalSetInt.A.mapWithIndex", () => { + test("Belt_internalSetInt.A.mapWithIndex", () => { module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ - - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Belt_Option.getExn", () => { - test("Belt_Option.getExn", () => { +describe("Belt_internalSetInt.A.partition", () => { + test("Belt_internalSetInt.A.partition", () => { module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Belt_Option.orElse", () => { - test("Belt_Option.orElse", () => { +describe("Belt_internalSetInt.A.range", () => { + test("Belt_internalSetInt.A.range", () => { module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Belt_Option.isSome", () => { - test("Belt_Option.isSome", () => { +describe("Belt_internalSetInt.A.rangeBy", () => { + test("Belt_internalSetInt.A.rangeBy", () => { module Test = { - Belt.Option.isSome(None) /* false */ + Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - Belt.Option.isSome(Some(1)) /* true */ + Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] + + Belt.Array.rangeBy(33, 0, ~step=1) == [] + + Belt.Array.rangeBy(33, 0, ~step=-1) == [] + + Belt.Array.rangeBy(3, 12, ~step=-1) == [] + + Belt.Array.rangeBy(3, 3, ~step=0) == [] + + Belt.Array.rangeBy(3, 3, ~step=1) == [3] } () }) }) -describe("Belt_Option.isNone", () => { - test("Belt_Option.isNone", () => { +describe("Belt_internalSetInt.A.reduce", () => { + test("Belt_internalSetInt.A.reduce", () => { module Test = { - Belt.Option.isNone(None) /* true */ + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - Belt.Option.isNone(Some(1)) /* false */ + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Belt_MutableSet.eq", () => { - test("Belt_MutableSet.eq", () => { +describe("Belt_internalSetInt.A.reduceReverse", () => { + test("Belt_internalSetInt.A.reduceReverse", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.MutableSet.eq(s0, s1) /* true */ + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Belt_Map.fromArray", () => { - test("Belt_Map.fromArray", () => { +describe("Belt_internalSetInt.A.reduceReverse2", () => { + test("Belt_internalSetInt.A.reduceReverse2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("Belt_Int.fromFloat", () => { - test("Belt_Int.fromFloat", () => { +describe("Belt_internalSetInt.A.reduceWithIndex", () => { + test("Belt_internalSetInt.A.reduceWithIndex", () => { module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("Belt_List.forEach2", () => { - test("Belt_List.forEach2", () => { +describe("Belt_internalSetInt.A.reverse", () => { + test("Belt_internalSetInt.A.reverse", () => { module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] } () }) }) -describe("Belt_List.getAssoc", () => { - test("Belt_List.getAssoc", () => { +describe("Belt_internalSetInt.A.reverseInPlace", () => { + test("Belt_internalSetInt.A.reverseInPlace", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ + let arr = [10, 11, 12, 13, 14] - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ + let () = Belt.Array.reverseInPlace(arr) + + arr == [14, 13, 12, 11, 10] } () }) }) -describe("Belt_List.hasAssoc", () => { - test("Belt_List.hasAssoc", () => { +describe("Belt_internalSetInt.A.slice", () => { + test("Belt_internalSetInt.A.slice", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("Belt_List.setAssoc", () => { - test("Belt_List.setAssoc", () => { +describe("Belt_internalSetInt.A.sliceToEnd", () => { + test("Belt_internalSetInt.A.sliceToEnd", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ - - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Belt.Array.reverse", () => { - test("Belt.Array.reverse", () => { +describe("Belt_internalSetInt.A.some", () => { + test("Belt_internalSetInt.A.some", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Belt.Array.rangeBy", () => { - test("Belt.Array.rangeBy", () => { +describe("Belt_internalSetInt.A.some2", () => { + test("Belt_internalSetInt.A.some2", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - Belt.Array.rangeBy(3, 3, ~step=0) == [] + Belt.Array.some2([], [1], (x, y) => x > y) == false - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Belt.Array.forEach", () => { - test("Belt.Array.forEach", () => { +describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) + let arr = ["ant", "bee", "cat", "dog", "elk"] - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + Belt.Array.truncateToLengthUnsafe(arr, 3) - total.contents == 1 + 2 + 3 + 4 + arr == ["ant", "bee", "cat"] } () }) }) -describe("Belt.Array.flatMap", () => { - test("Belt.Array.flatMap", () => { +describe("Belt_internalSetInt.A.unzip", () => { + test("Belt_internalSetInt.A.unzip", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("Belt.Array.keepMap", () => { - test("Belt.Array.keepMap", () => { +describe("Belt_internalSetInt.A.zip", () => { + test("Belt_internalSetInt.A.zip", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("Belt.List.forEach2", () => { - test("Belt.List.forEach2", () => { +describe("Belt_internalSetInt.A.zipBy", () => { + test("Belt_internalSetInt.A.zipBy", () => { module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("Belt.List.getAssoc", () => { - test("Belt.List.getAssoc", () => { +describe("Belt_internalSetString.A.blit", () => { + test("Belt_internalSetString.A.blit", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ - } - () - }) -}) + let v1 = [10, 11, 12, 13, 14, 15, 16, 17] + let v2 = [20, 21, 22, 23, 24, 25, 26, 27] -describe("Belt.List.hasAssoc", () => { - test("Belt.List.hasAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) + v2 == [20, 21, 14, 15, 16, 25, 26, 27] - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ + Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) + v1 == [10, 11, 14, 15, 16, 15, 16, 17] } () }) }) -describe("Belt.List.setAssoc", () => { - test("Belt.List.setAssoc", () => { +describe("Belt_internalSetString.A.cmp", () => { + test("Belt_internalSetString.A.cmp", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ + Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ + Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ + Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 } () }) }) -describe("Belt.Range.forEach", () => { - test("Belt.Range.forEach", () => { +describe("Belt_internalSetString.A.concat", () => { + test("Belt_internalSetString.A.concat", () => { module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) + Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 + Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] } () }) }) -describe("Belt.Range.everyBy", () => { - test("Belt.Range.everyBy", () => { +describe("Belt_internalSetString.A.concatMany", () => { + test("Belt_internalSetString.A.concatMany", () => { module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ - - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ + Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] } () }) }) -describe("Belt.Set.fromArray", () => { - test("Belt.Set.fromArray", () => { +describe("Belt_internalSetString.A.eq", () => { + test("Belt_internalSetString.A.eq", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) + Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true } () }) }) -describe("Belt.Set.mergeMany", () => { - test("Belt.Set.mergeMany", () => { +describe("Belt_internalSetString.A.every", () => { + test("Belt_internalSetString.A.every", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) - - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) + Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) + Belt.Array.every([1, -3, 5], x => x > 0) == false } () }) }) -describe("Belt.Set.intersect", () => { - test("Belt.Set.intersect", () => { +describe("Belt_internalSetString.A.every2", () => { + test("Belt_internalSetString.A.every2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) + Belt.Array.every2([], [1], (x, y) => x > y) == true - let intersect = Belt.Set.intersect(s0, s1) + Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) + Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false } () }) }) -describe("Belt.Set.partition", () => { - test("Belt.Set.partition", () => { +describe("Belt_internalSetString.A.fill", () => { + test("Belt_internalSetString.A.fill", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let arr = Belt.Array.makeBy(5, i => i) - let isOdd = x => mod(x, 2) != 0 + Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) + arr == [0, 1, 9, 9, 4] - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) + Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + + arr == [0, 1, 9, 9, 4] } () }) }) -describe("Belt.Map.fromArray", () => { - test("Belt.Map.fromArray", () => { +describe("Belt_internalSetString.A.flatMap", () => { + test("Belt_internalSetString.A.flatMap", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] + Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] } () }) }) -describe("Belt.MutableSet.eq", () => { - test("Belt.MutableSet.eq", () => { +describe("Belt_internalSetString.A.forEach", () => { + test("Belt_internalSetString.A.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) + /* + prints: + Item: a + Item: b + Item: c +*/ + let total = ref(0) - Belt.MutableSet.eq(s0, s1) /* true */ + Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + + total.contents == 1 + 2 + 3 + 4 } () }) }) -describe("Belt.HashMap.clear", () => { - test("Belt.HashMap.clear", () => { +describe("Belt_internalSetString.A.forEachWithIndex", () => { + test("Belt_internalSetString.A.forEachWithIndex", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + Belt.Array.forEachWithIndex( + ["a", "b", "c"], + (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), + ) - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + let total = ref(0) + + Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + + total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 } () }) }) -describe("Belt.Option.getExn", () => { - test("Belt.Option.getExn", () => { +describe("Belt_internalSetString.A.get", () => { + test("Belt_internalSetString.A.get", () => { module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) - - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.get(["a", "b", "c"], 0) == Some("a") + Belt.Array.get(["a", "b", "c"], 3) == None + Belt.Array.get(["a", "b", "c"], -1) == None } () }) }) -describe("Belt.Option.orElse", () => { - test("Belt.Option.orElse", () => { +describe("Belt_internalSetString.A.getBy", () => { + test("Belt_internalSetString.A.getBy", () => { module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None + Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) + Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt.Option.isSome", () => { - test("Belt.Option.isSome", () => { +describe("Belt_internalSetString.A.getIndexBy", () => { + test("Belt_internalSetString.A.getIndexBy", () => { module Test = { - Belt.Option.isSome(None) /* false */ - - Belt.Option.isSome(Some(1)) /* true */ + Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) + Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None } () }) }) -describe("Belt.Option.isNone", () => { - test("Belt.Option.isNone", () => { +describe("Belt_internalSetString.A.joinWith", () => { + test("Belt_internalSetString.A.joinWith", () => { module Test = { - Belt.Option.isNone(None) /* true */ - - Belt.Option.isNone(Some(1)) /* false */ + Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" + Belt.Array.joinWith([], " ", Js.Int.toString) == "" + Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" } () }) }) -describe("Belt.Result.getExn", () => { - test("Belt.Result.getExn", () => { +describe("Belt_internalSetString.A.keepMap", () => { + test("Belt_internalSetString.A.keepMap", () => { module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) - - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } + Belt.Array.keepMap( + [1, 2, 3], + x => + if mod(x, 2) == 0 { + Some(x) + } else { + None + }, + ) == [2] } () }) }) -describe("Belt.Int.fromFloat", () => { - test("Belt.Int.fromFloat", () => { +describe("Belt_internalSetString.A.keepWithIndex", () => { + test("Belt_internalSetString.A.keepWithIndex", () => { module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) + Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] } () }) }) -describe("Belt.Float.fromInt", () => { - test("Belt.Float.fromInt", () => { +describe("Belt_internalSetString.A.length", () => { + test("Belt_internalSetString.A.length", () => { module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + // Returns 1 + Belt.Array.length(["test"]) } () }) }) -describe("Belt.Set.Dict.diff", () => { - test("Belt.Set.Dict.diff", () => { +describe("Belt_internalSetString.A.makeBy", () => { + test("Belt_internalSetString.A.makeBy", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) + Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ + Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] } () }) }) -describe("Belt.Set.Dict.some", () => { - test("Belt.Set.Dict.some", () => { +describe("Belt_internalSetString.A.makeUninitialized", () => { + test("Belt_internalSetString.A.makeUninitialized", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 + let arr: array> = Belt.Array.makeUninitialized(5) - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ + Belt.Array.getExn(arr, 0) == Js.undefined } () }) }) -describe("Belt.Set.Dict.keep", () => { - test("Belt.Set.Dict.keep", () => { +describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let arr = Belt.Array.makeUninitializedUnsafe(5) - let isEven = x => mod(x, 2) == 0 + Js.log(Belt.Array.getExn(arr, 0)) // undefined - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) + Belt.Array.setExn(arr, 0, "example") - s1->Belt.Set.Dict.toArray /* [2,4] */ + Js.log(Belt.Array.getExn(arr, 0) == "example") } () }) }) -describe("Belt.Set.Dict.size", () => { - test("Belt.Set.Dict.size", () => { +describe("Belt_internalSetString.A.map", () => { + test("Belt_internalSetString.A.map", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + Belt.Array.map([1, 2], x => x + 1) == [3, 4] + } + () + }) +}) - s0->Belt.Set.Dict.size /* 4 */ +describe("Belt_internalSetString.A.mapWithIndex", () => { + test("Belt_internalSetString.A.mapWithIndex", () => { + module Test = { + Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] } () }) }) -describe("Belt_Float.fromInt", () => { - test("Belt_Float.fromInt", () => { +describe("Belt_internalSetString.A.partition", () => { + test("Belt_internalSetString.A.partition", () => { module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + + Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) } () }) }) -describe("Belt_Array.reverse", () => { - test("Belt_Array.reverse", () => { +describe("Belt_internalSetString.A.range", () => { + test("Belt_internalSetString.A.range", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + Belt.Array.range(0, 3) == [0, 1, 2, 3] + + Belt.Array.range(3, 0) == [] + + Belt.Array.range(3, 3) == [3] } () }) }) -describe("Belt_Array.rangeBy", () => { - test("Belt_Array.rangeBy", () => { +describe("Belt_internalSetString.A.rangeBy", () => { + test("Belt_internalSetString.A.rangeBy", () => { module Test = { Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] @@ -10457,6029 +11252,5063 @@ describe("Belt_Array.rangeBy", () => { }) }) -describe("Belt_Array.forEach", () => { - test("Belt_Array.forEach", () => { +describe("Belt_internalSetString.A.reduce", () => { + test("Belt_internalSetString.A.reduce", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - total.contents == 1 + 2 + 3 + 4 + Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" } () }) }) -describe("Belt_Array.flatMap", () => { - test("Belt_Array.flatMap", () => { +describe("Belt_internalSetString.A.reduceReverse", () => { + test("Belt_internalSetString.A.reduceReverse", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" } () }) }) -describe("Belt_Array.keepMap", () => { - test("Belt_Array.keepMap", () => { +describe("Belt_internalSetString.A.reduceReverse2", () => { + test("Belt_internalSetString.A.reduceReverse2", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 } () }) }) -describe("Belt_HashMap.clear", () => { - test("Belt_HashMap.clear", () => { +describe("Belt_internalSetString.A.reduceWithIndex", () => { + test("Belt_internalSetString.A.reduceWithIndex", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true + Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 } () }) }) -describe("AsyncIterator.make", () => { - test("AsyncIterator.make", () => { +describe("Belt_internalSetString.A.reverse", () => { + test("Belt_internalSetString.A.reverse", () => { module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 + Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + } + () + }) +}) - { - AsyncIterator.value: Some(currentValue), - done: currentValue >= 3, - } - }, - ) +describe("Belt_internalSetString.A.reverseInPlace", () => { + test("Belt_internalSetString.A.reverseInPlace", () => { + module Test = { + let arr = [10, 11, 12, 13, 14] - // This will log 1, 2, 3 - let main = async () => - await asyncIterator->AsyncIterator.forEach( - value => - switch value { - | Some(value) => Console.log(value) - | None => () - }, - ) + let () = Belt.Array.reverseInPlace(arr) - main()->ignore + arr == [14, 13, 12, 11, 10] } () }) }) -describe("AsyncIterator.done", () => { - test("AsyncIterator.done", () => { +describe("Belt_internalSetString.A.slice", () => { + test("Belt_internalSetString.A.slice", () => { module Test = { - let context = ref(0) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) + Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] } () }) }) -describe("AsyncIterator.next", () => { - test("AsyncIterator.next", () => { - module Test = { - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let processMyAsyncIterator = async () => { - // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. - let break = ref(false) - - while !break.contents { - // Await the next iterator value - let {value, done} = await asyncIterator->AsyncIterator.next - - // Exit the while loop if the iterator says it's done - break := done - - if done { - value - ->Option.isNone - ->assertEqual(true) - } - } - } +describe("Belt_internalSetString.A.sliceToEnd", () => { + test("Belt_internalSetString.A.sliceToEnd", () => { + module Test = { + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - processMyAsyncIterator()->ignore + Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] } () }) }) -describe("Array.fromIterator", () => { - test("Array.fromIterator", () => { +describe("Belt_internalSetString.A.some", () => { + test("Belt_internalSetString.A.some", () => { module Test = { - Map.fromArray([("foo", 1), ("bar", 2)]) - ->Map.values - ->Array.fromIterator - ->assertEqual([1, 2]) + Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true + + Belt.Array.some([-1, -3, -5], x => x > 0) == false } () }) }) -describe("Array.mapWithIndex", () => { - test("Array.mapWithIndex", () => { +describe("Belt_internalSetString.A.some2", () => { + test("Belt_internalSetString.A.some2", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = - array->Array.mapWithIndex( - (greeting, index) => greeting ++ " at position " ++ Int.toString(index), - ) + Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - assertEqual( - mappedArray, - ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], - ) + Belt.Array.some2([], [1], (x, y) => x > y) == false + + Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true } () }) }) -describe("Array.findIndexOpt", () => { - test("Array.findIndexOpt", () => { +describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript + let arr = ["ant", "bee", "cat", "dog", "elk"] - let array = [ReScript, TypeScript, JavaScript] + Belt.Array.truncateToLengthUnsafe(arr, 3) - array - ->Array.findIndexOpt(item => item == ReScript) - ->assertEqual(Some(0)) + arr == ["ant", "bee", "cat"] } () }) }) -describe("String.fromCharCode", () => { - test("String.fromCharCode", () => { +describe("Belt_internalSetString.A.unzip", () => { + test("Belt_internalSetString.A.unzip", () => { module Test = { - String.fromCharCode(65) == "A" - String.fromCharCode(0x3c8) == `ψ` - String.fromCharCode(0xd55c) == `한` - String.fromCharCode(-64568) == `ψ` + Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) + + Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) } () }) }) -describe("String.endsWithFrom", () => { - test("String.endsWithFrom", () => { +describe("Belt_internalSetString.A.zip", () => { + test("Belt_internalSetString.A.zip", () => { module Test = { - String.endsWithFrom("abcd", "cd", 4) == true - String.endsWithFrom("abcde", "cd", 3) == false - String.endsWithFrom("abcde", "cde", 99) == true - String.endsWithFrom("example.dat", "ple", 7) == true + Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] } () }) }) -describe("String.includesFrom", () => { - test("String.includesFrom", () => { +describe("Belt_internalSetString.A.zipBy", () => { + test("Belt_internalSetString.A.zipBy", () => { module Test = { - String.includesFrom("programmer", "gram", 1) == true - String.includesFrom("programmer", "gram", 4) == false - String.includesFrom(`대한민국`, `한`, 1) == true + Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] } () }) }) -describe("RegExp.setLastIndex", () => { - test("RegExp.setLastIndex", () => { +describe("BigInt.fromStringExn", () => { + test("BigInt.fromStringExn", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." + /* returns 123n */ + BigInt.fromStringExn("123") - regexp->RegExp.setLastIndex(4) - regexp->RegExp.exec(someStr)->ignore + /* returns 0n */ + BigInt.fromStringExn("") - Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console - } - () - }) -}) + /* returns 17n */ + BigInt.fromStringExn("0x11") -describe("RegExp.Result.input", () => { - test("RegExp.Result.input", () => { - module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + /* returns 3n */ + BigInt.fromStringExn("0b11") - // This below will log the full input string "ReScript is pretty cool, right?" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.input) + /* returns 9n */ + BigInt.fromStringExn("0o11") + + /* catch exception */ + try { + BigInt.fromStringExn("a") + } catch { + | Exn.Error(_error) => 0n } } () }) }) -describe("Promise.thenResolve", () => { - test("Promise.thenResolve", () => { +describe("BigInt.toLocaleString", () => { + test("BigInt.toLocaleString", () => { module Test = { - open Promise - resolve("Anna") - ->thenResolve( - str => { - "Hello " ++ str - }, - ) - ->thenResolve( - str => { - Console.log(str) - }, - ) - ->ignore // Ignore needed for side-effects + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log } () }) }) -describe("Object.isExtensible", () => { - test("Object.isExtensible", () => { +describe("BigInt.toString", () => { + test("BigInt.toString", () => { module Test = { - let obj = {"a": 1} - obj->Object.isExtensible // true - obj->Object.preventExtensions->ignore - obj->Object.isExtensible // false + /* prints "123" */ + Js.BigInt.toString(123n)->Js.log } () }) }) -describe("Nullable.isNullable", () => { - test("Nullable.isNullable", () => { +describe("Console.assert2", () => { + test("Console.assert2", () => { module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Check if asNullable is not null or undefined - switch asNullable->Nullable.isNullable { - | true => assert(false) - | false => assert(true) - } + Console.assert2(false, "Hello", "World") + Console.assert2(42 == 42, [1, 2, 3], '4') } () }) }) -describe("Nullable.fromOption", () => { - test("Nullable.fromOption", () => { +describe("Console.assert3", () => { + test("Console.assert3", () => { module Test = { - let optString = Some("Hello") - let asNullable = optString->Nullable.fromOption // Nullable.t + Console.assert3(false, "Hello", "World", "ReScript") + Console.assert3(42 == 42, "One", 2, #3) } () }) }) -describe("List.reduceReverse2", () => { - test("List.reduceReverse2", () => { +describe("Console.assert4", () => { + test("Console.assert4", () => { module Test = { - List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) + let value = 42 + Console.assert4(false, "Hello", "World", "ReScript", "!!!") + Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Math.Constants.ln10", () => { - test("Math.Constants.ln10", () => { +describe("Console.assert5", () => { + test("Console.assert5", () => { module Test = { - Math.Constants.ln10 + let value = 42 + Console.assert5(false, "Hello", "World", "JS", '!', '!') + Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Float.toExponential", () => { - test("Float.toExponential", () => { +describe("Console.assert6", () => { + test("Console.assert6", () => { module Test = { - Float.toExponential(1000.0) // "1e+3" - Float.toExponential(-1000.0) // "-1e+3" - Float.toExponential(77.0, ~digits=2) // "7.70e+1" - Float.toExponential(5678.0, ~digits=2) // "5.68e+3" + let value = 42 + Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') + Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Float.Constants.nan", () => { - test("Float.Constants.nan", () => { +describe("Console.assertMany", () => { + test("Console.assertMany", () => { module Test = { - Float.Constants.nan + let value = 42 + Console.assertMany(false, ["Hello", "World"]) + Console.assertMany(value == 42, [1, 2, 3]) } () }) }) -describe("Date.makeWithYMDHMS", () => { - test("Date.makeWithYMDHMS", () => { +describe("Console.assert_", () => { + test("Console.assert_", () => { module Test = { - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 2023-02-20T16:41:00.000Z - - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 2023-02-20T16:39:59.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Console.assert_(false, "Hello World!") + Console.assert_(42 == 42, "The answer") } () }) }) -describe("Date.getUTCFullYear", () => { - test("Date.getUTCFullYear", () => { +describe("Console.clear", () => { + test("Console.clear", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 + Console.clear() } () }) }) -describe("Date.setUTCFullYear", () => { - test("Date.setUTCFullYear", () => { +describe("Console.count", () => { + test("Console.count", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) + Console.count("rescript") } () }) }) -describe("Date.setUTCMinutesS", () => { - test("Date.setUTCMinutesS", () => { +describe("Console.countReset", () => { + test("Console.countReset", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) + Console.countReset("rescript") } () }) }) -describe("Date.toLocaleString", () => { - test("Date.toLocaleString", () => { +describe("Console.debug", () => { + test("Console.debug", () => { module Test = { - Date.make()->Date.toLocaleString->Console.log - // 2/19/2023, 3:40:00 PM + Console.debug("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.debug(obj) } () }) }) -describe("Date.UTC.makeWithYM", () => { - test("Date.UTC.makeWithYM", () => { +describe("Console.debug2", () => { + test("Console.debug2", () => { module Test = { - Date.UTC.makeWithYM(~year=2023, ~month=0) - // 1672531200000 - - Date.UTC.makeWithYM(~year=2023, ~month=11) - // 1701388800000 - - Date.UTC.makeWithYM(~year=2023, ~month=12) - // 1704067200000 - - Date.UTC.makeWithYM(~year=2023, ~month=-1) - // 1669852800000 + Console.debug2("Hello", "World") + Console.debug2([1, 2, 3], '4') } () }) }) -describe("Dict.forEachWithKey", () => { - test("Dict.forEachWithKey", () => { +describe("Console.debug3", () => { + test("Console.debug3", () => { module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - - dict->Dict.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) + Console.debug3("Hello", "World", "ReScript") + Console.debug3("One", 2, #3) } () }) }) -describe("Belt_Set.removeMany", () => { - test("Belt_Set.removeMany", () => { +describe("Console.debug4", () => { + test("Console.debug4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([]) + Console.debug4("Hello", "World", "ReScript", "!!!") + Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Belt_Set.Dict.empty", () => { - test("Belt_Set.Dict.empty", () => { +describe("Console.debug5", () => { + test("Console.debug5", () => { module Test = { - let s0 = Belt.Set.Dict.empty + Console.debug5("Hello", "World", "JS", '!', '!') + Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt_Set.Dict.union", () => { - test("Belt_Set.Dict.union", () => { +describe("Console.debug6", () => { + test("Console.debug6", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + Console.debug6("Hello", "World", "JS", '!', '!', '?') + Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt_Set.Dict.every", () => { - test("Belt_Set.Dict.every", () => { +describe("Console.debugMany", () => { + test("Console.debugMany", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Console.debugMany(["Hello", "World"]) + Console.debugMany([1, 2, 3]) } () }) }) -describe("Belt_Set.Dict.split", () => { - test("Belt_Set.Dict.split", () => { +describe("Console.dir", () => { + test("Console.dir", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + Console.dir({"language": "rescript", "version": "10.1.2"}) } () }) }) -describe("Belt_SetDict.remove", () => { - test("Belt_SetDict.remove", () => { +describe("Console.error", () => { + test("Console.error", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ + Console.error("error message") + Console.error(("error", "invalid value")) } () }) }) -describe("Belt_SetDict.subset", () => { - test("Belt_SetDict.subset", () => { +describe("Console.error2", () => { + test("Console.error2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + Console.error2("Error", "here") + Console.error2(("log", "error"), "message") } () }) }) -describe("Belt_SetDict.reduce", () => { - test("Belt_SetDict.reduce", () => { +describe("Console.error3", () => { + test("Console.error3", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Console.error3("Hello", "World", "!!!") + Console.error3(#first, #second, #third) } () }) }) -describe("Belt_SetDict.toList", () => { - test("Belt_SetDict.toList", () => { +describe("Console.error4", () => { + test("Console.error4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + Console.error4("Hello", "World", "ReScript", '!') + Console.error4(#first, #second, #third, "fourth") } () }) }) -describe("Belt_Result.flatMap", () => { - test("Belt_Result.flatMap", () => { +describe("Console.error5", () => { + test("Console.error5", () => { module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } - - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + Console.error5('e', 'r', 'r', 'o', 'r') + Console.error5(1, #second, #third, "fourth", 'c') } () }) }) -describe("Belt_Option.forEach", () => { - test("Belt_Option.forEach", () => { +describe("Console.error6", () => { + test("Console.error6", () => { module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + Console.error6("Hello", "World", "from", "JS", "!!!", '!') + Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt_Option.flatMap", () => { - test("Belt_Option.flatMap", () => { +describe("Console.errorMany", () => { + test("Console.errorMany", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ + Console.errorMany(["Hello", "World"]) + Console.errorMany([1, 2, 3]) } () }) }) -describe("Belt_MutableSet.has", () => { - test("Belt_MutableSet.has", () => { +describe("Console.group", () => { + test("Console.group", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ + 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() } () }) }) -describe("Belt_MutableSet.add", () => { - test("Belt_MutableSet.add", () => { +describe("Console.info", () => { + test("Console.info", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ + Console.info("Information") + Console.info(("Hello", "JS")) } () }) }) -describe("Belt_MutableSet.get", () => { - test("Belt_MutableSet.get", () => { +describe("Console.info2", () => { + test("Console.info2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ + Console.info2("Info", "failed to download") + Console.info2(#info, {"name": "ReScript"}) } () }) }) -describe("Belt_Int.fromString", () => { - test("Belt_Int.fromString", () => { +describe("Console.info3", () => { + test("Console.info3", () => { module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) + Console.info3("Hello", "World", "ReScript") + Console.info3([1, 2, 3], #4, #5) } () }) }) -describe("Belt_List.fromArray", () => { - test("Belt_List.fromArray", () => { +describe("Console.info4", () => { + test("Console.info4", () => { module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + Console.info4("Hello", "World", "ReScript", '!') + Console.info4([1, 2, 3], #4, #5, #lastinfo) } () }) }) -describe("Belt_List.partition", () => { - test("Belt_List.partition", () => { +describe("Console.info5", () => { + test("Console.info5", () => { module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) + Console.info5("Hello", "World", "from", "JS", "!!!") + Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt.Array.joinWith", () => { - test("Belt.Array.joinWith", () => { +describe("Console.info6", () => { + test("Console.info6", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + Console.info6("Hello", "World", "from", "JS", "!!!", '!') + Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.List.fromArray", () => { - test("Belt.List.fromArray", () => { +describe("Console.infoMany", () => { + test("Console.infoMany", () => { module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} + Console.infoMany(["Hello", "World"]) + Console.infoMany([1, 2, 3]) } () }) }) -describe("Belt.List.partition", () => { - test("Belt.List.partition", () => { +describe("Console.log", () => { + test("Console.log", () => { module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) + Console.log("Hello") + let obj = {"name": "ReScript", "version": 10} + Console.log(obj) } () }) }) -describe("Belt.Set.removeMany", () => { - test("Belt.Set.removeMany", () => { +describe("Console.log2", () => { + test("Console.log2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([]) + Console.log2("Hello", "World") + Console.log2([1, 2, 3], '4') } () }) }) -describe("Belt.MutableSet.has", () => { - test("Belt.MutableSet.has", () => { +describe("Console.log3", () => { + test("Console.log3", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ + Console.log3("Hello", "World", "ReScript") + Console.log3("One", 2, #3) } () }) }) -describe("Belt.MutableSet.add", () => { - test("Belt.MutableSet.add", () => { +describe("Console.log4", () => { + test("Console.log4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ + Console.log4("Hello", "World", "ReScript", "!!!") + Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) } () }) }) -describe("Belt.MutableSet.get", () => { - test("Belt.MutableSet.get", () => { +describe("Console.log5", () => { + test("Console.log5", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ + Console.log5("Hello", "World", "JS", '!', '!') + Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt.HashMap.remove", () => { - test("Belt.HashMap.remove", () => { +describe("Console.log6", () => { + test("Console.log6", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false + Console.log6("Hello", "World", "JS", '!', '!', '?') + Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt.HashMap.reduce", () => { - test("Belt.HashMap.reduce", () => { +describe("Console.logMany", () => { + test("Console.logMany", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") - - Console.log("lol") + Console.logMany(["Hello", "World"]) + Console.logMany([1, 2, 3]) } () }) }) -describe("Belt.Option.forEach", () => { - test("Belt.Option.forEach", () => { +describe("Console.table", () => { + test("Console.table", () => { module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ + Console.table({"language": "rescript", "version": "10.1.2"}) } () }) }) -describe("Belt.Option.flatMap", () => { - test("Belt.Option.flatMap", () => { +describe("Console.time", () => { + test("Console.time", () => { module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt.Result.flatMap", () => { - test("Belt.Result.flatMap", () => { +describe("Console.timeEnd", () => { + test("Console.timeEnd", () => { module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } - - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt.Int.fromString", () => { - test("Belt.Int.fromString", () => { +describe("Console.timeLog", () => { + test("Console.timeLog", () => { module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) + Console.time("for_time") + for x in 3 downto 1 { + Console.log(x) + Console.timeLog("for_time") + } + Console.timeEnd("for_time") } () }) }) -describe("Belt.Float.toString", () => { - test("Belt.Float.toString", () => { +describe("Console.trace", () => { + test("Console.trace", () => { module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ + let main = () => { + Console.trace() + } + main() + // In the console, the following trace will be displayed: + // main + // } () }) }) -describe("Belt.Set.Dict.empty", () => { - test("Belt.Set.Dict.empty", () => { - module Test = { - let s0 = Belt.Set.Dict.empty +describe("Console.warn", () => { + test("Console.warn", () => { + module Test = { + Console.warn("Warning") + Console.warn(("Warning", "invalid number")) } () }) }) -describe("Belt.Set.Dict.union", () => { - test("Belt.Set.Dict.union", () => { +describe("Console.warn2", () => { + test("Console.warn2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ + Console.warn2("Hello", "World") + Console.warn2([1, 2, 3], 4) } () }) }) -describe("Belt.Set.Dict.every", () => { - test("Belt.Set.Dict.every", () => { +describe("Console.warn3", () => { + test("Console.warn3", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ + Console.warn3("Hello", "World", "ReScript") + Console.warn3([1, 2, 3], #4, #5) } () }) }) -describe("Belt.Set.Dict.split", () => { - test("Belt.Set.Dict.split", () => { +describe("Console.warn4", () => { + test("Console.warn4", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ + Console.warn4("Hello", "World", "ReScript", "!!!") + Console.warn4(#first, #second, #third, "fourth") } () }) }) -describe("Belt_Float.toString", () => { - test("Belt_Float.toString", () => { +describe("Console.warn5", () => { + test("Console.warn5", () => { module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ + Console.warn5("Hello", "World", "from", "JS", "!!!") + Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) } () }) }) -describe("Belt_Array.joinWith", () => { - test("Belt_Array.joinWith", () => { +describe("Console.warn6", () => { + test("Console.warn6", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + Console.warn6("Hello", "World", "from", "JS", "!!!", '!') + Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) } () }) }) -describe("Belt_HashMap.remove", () => { - test("Belt_HashMap.remove", () => { +describe("Console.warnMany", () => { + test("Console.warnMany", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false + Console.warnMany(["Hello", "World"]) + Console.warnMany([1, 2, 3]) } () }) }) -describe("Belt_HashMap.reduce", () => { - test("Belt_HashMap.reduce", () => { +describe("Date.UTC.makeWithYM", () => { + test("Date.UTC.makeWithYM", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) + Date.UTC.makeWithYM(~year=2023, ~month=0) + // 1672531200000 - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + Date.UTC.makeWithYM(~year=2023, ~month=11) + // 1701388800000 - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") + Date.UTC.makeWithYM(~year=2023, ~month=12) + // 1704067200000 - Console.log("lol") + Date.UTC.makeWithYM(~year=2023, ~month=-1) + // 1669852800000 } () }) }) -describe("AsyncIterator.value", () => { - test("AsyncIterator.value", () => { +describe("Date.UTC.makeWithYMD", () => { + test("Date.UTC.makeWithYMD", () => { module Test = { - let context = ref(0) + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20) + // 1676851200000 - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1) + // 1675036800000 - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) + Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29) + // 1677628800000 } () }) }) -describe("Array.findWithIndex", () => { - test("Array.findWithIndex", () => { +describe("Date.UTC.makeWithYMDH", () => { + test("Date.UTC.makeWithYMDH", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 1676908800000 - let array = [TypeScript, JavaScript, ReScript] + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 1676937600000 - array - ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) - ->assertEqual(Some(ReScript)) + Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 1676847600000 } () }) }) -describe("Array.someWithIndex", () => { - test("Array.someWithIndex", () => { +describe("Date.UTC.makeWithYMDHM", () => { + test("Date.UTC.makeWithYMDHM", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 1676911200000 - array - ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) - ->assertEqual(true) + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 1676912400000 + + Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 1676908740000 } () }) }) -describe("String.fromCodePoint", () => { - test("String.fromCodePoint", () => { +describe("Date.UTC.makeWithYMDHMS", () => { + test("Date.UTC.makeWithYMDHMS", () => { module Test = { - String.fromCodePoint(65) == "A" - String.fromCodePoint(0x3c8) == `ψ` - String.fromCodePoint(0xd55c) == `한` - String.fromCodePoint(0x1f63a) == `😺` + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 1676911200000 + + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 1676911260000 + + Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 1676911199000 } () }) }) -describe("String.normalizeForm", () => { - test("String.normalizeForm", () => { +describe("Date.UTC.makeWithYMDHMSM", () => { + test("Date.UTC.makeWithYMDHMSM", () => { module Test = { - let string1 = "\uFB00" - let string2 = "\u0066\u0066" - Console.log(string1 == string2) // false + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + )->Console.log + // 1676911200000 - let normalizeString1 = String.normalizeByForm(string1, #NFKD) - let normalizeString2 = String.normalizeByForm(string2, #NFKD) - Console.log(normalizeString1 == normalizeString2) // true + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + )->Console.log + // 1676911201000 + + Date.UTC.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + )->Console.log + // 1676911199999 } () }) }) -describe("String.replaceRegExp", () => { - test("String.replaceRegExp", () => { +describe("Date.fromString", () => { + test("Date.fromString", () => { module Test = { - String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" + Date.fromString("2023") // 2023-01-01T00:00:00.000Z + + Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z + + Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z + + Date.fromString("") // Invalid Date + + Date.fromString("")->Date.getTime // NaN } () }) }) -describe("String.splitByRegExp", () => { - test("String.splitByRegExp", () => { +describe("Date.fromTime", () => { + test("Date.fromTime", () => { module Test = { - String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] + Date.fromTime(0.0) + // 1970-01-01T00:00:00.000Z + + Date.fromTime(-86_400_000.0) + // 1969-12-31T00:00:00.000Z + + Date.fromTime(86_400_000.0) + // 1970-01-02T00:00:00.000Z } () }) }) -describe("String.localeCompare", () => { - test("String.localeCompare", () => { +describe("Date.getDate", () => { + test("Date.getDate", () => { module Test = { - String.localeCompare("a", "c") < 0.0 == true - String.localeCompare("a", "a") == 0.0 - } + Date.fromString("2023-02-20T16:40:00.00")->Date.getDate + // 20 + } () }) }) -describe("Pervasives.encodeURI", () => { - test("Pervasives.encodeURI", () => { +describe("Date.getDay", () => { + test("Date.getDay", () => { module Test = { - Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) - // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. + Date.fromString("2023-02-20T16:40:00.00")->Date.getDay + // 1 } () }) }) -describe("Pervasives.decodeURI", () => { - test("Pervasives.decodeURI", () => { +describe("Date.getFullYear", () => { + test("Date.getFullYear", () => { module Test = { - Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) - // Logs "https://rescript-lang.org?array=[someValue]" to the console. + Date.fromString("2023-02-20")->Date.getFullYear + // 2023 } () }) }) -describe("List.fromInitializer", () => { - test("List.fromInitializer", () => { +describe("Date.getHours", () => { + test("Date.getHours", () => { module Test = { - List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} - - List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} + Date.fromString("2023-02-20T16:40:00.00")->Date.getHours + // 16 } () }) }) -describe("List.reduceWithIndex", () => { - test("List.reduceWithIndex", () => { +describe("Date.getMilliseconds", () => { + test("Date.getMilliseconds", () => { module Test = { - list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 + Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds + // 0 } () }) }) -describe("List.filterWithIndex", () => { - test("List.filterWithIndex", () => { +describe("Date.getMinutes", () => { + test("Date.getMinutes", () => { module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} + Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes + // 40 } () }) }) -describe("Math.Constants.log2e", () => { - test("Math.Constants.log2e", () => { +describe("Date.getMonth", () => { + test("Date.getMonth", () => { module Test = { - Math.Constants.log2e + Date.fromString("2023-01-01")->Date.getMonth + // 0 } () }) }) -describe("Math.Constants.sqrt2", () => { - test("Math.Constants.sqrt2", () => { +describe("Date.getSeconds", () => { + test("Date.getSeconds", () => { module Test = { - Math.Constants.sqrt2 + Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds + // 0 } () }) }) -describe("Int.rangeWithOptions", () => { - test("Int.rangeWithOptions", () => { +describe("Date.getTime", () => { + test("Date.getTime", () => { module Test = { - Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] - Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] - Int.rangeWithOptions(3, 6, {step: -2}) // RangeError + Date.fromString("2023-02-20")->Date.getTime + // 1676851200000 } () }) }) -describe("Float.toLocaleString", () => { - test("Float.toLocaleString", () => { +describe("Date.getTimezoneOffset", () => { + test("Date.getTimezoneOffset", () => { module Test = { - // If the application uses English as the default language - Float.toLocaleString(1000.0) // "1,000" + Date.fromString("2023-01-01")->Date.getTimezoneOffset + // -60 with local time zone = Europe/Berlin - // If the application uses Portuguese Brazil as the default language - Float.toLocaleString(1000.0) // "1.000" + Date.fromString("2023-06-01")->Date.getTimezoneOffset + // -120 with local time zone = Europe/Berlin } () }) }) -describe("Date.makeWithYMDHMSM", () => { - test("Date.makeWithYMDHMSM", () => { +describe("Date.getUTCDate", () => { + test("Date.getUTCDate", () => { module Test = { - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - ) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - ) - // 2023-02-20T16:40:01.000Z - - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=-1, - ) - // 2023-02-20T16:39:59.999Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 } () }) }) -describe("Date.getMilliseconds", () => { - test("Date.getMilliseconds", () => { +describe("Date.getUTCDay", () => { + test("Date.getUTCDay", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds - // 0 + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 } () }) }) -describe("Date.setMilliseconds", () => { - test("Date.setMilliseconds", () => { +describe("Date.getUTCFullYear", () => { + test("Date.getUTCFullYear", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 } () }) }) -describe("Date.setUTCFullYearM", () => { - test("Date.setUTCFullYearM", () => { +describe("Date.getUTCHours", () => { + test("Date.getUTCHours", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 } () }) }) -describe("Date.setUTCHoursMSMs", () => { - test("Date.setUTCHoursMSMs", () => { +describe("Date.getUTCMilliseconds", () => { + test("Date.getUTCMilliseconds", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 } () }) }) -describe("Date.setUTCSecondsMs", () => { - test("Date.setUTCSecondsMs", () => { +describe("Date.getUTCMinutes", () => { + test("Date.getUTCMinutes", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 } () }) }) -describe("Date.UTC.makeWithYMD", () => { - test("Date.UTC.makeWithYMD", () => { +describe("Date.getUTCMonth", () => { + test("Date.getUTCMonth", () => { module Test = { - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20) - // 1676851200000 - - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1) - // 1675036800000 - - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29) - // 1677628800000 + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 } () }) }) -describe("BigInt.fromStringExn", () => { - test("BigInt.fromStringExn", () => { +describe("Date.getUTCSeconds", () => { + test("Date.getUTCSeconds", () => { module Test = { - /* returns 123n */ - BigInt.fromStringExn("123") - - /* returns 0n */ - BigInt.fromStringExn("") - - /* returns 17n */ - BigInt.fromStringExn("0x11") - - /* returns 3n */ - BigInt.fromStringExn("0b11") - - /* returns 9n */ - BigInt.fromStringExn("0o11") + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 + } + () + }) +}) - /* catch exception */ - try { - BigInt.fromStringExn("a") - } catch { - | Exn.Error(_error) => 0n - } +describe("Date.make", () => { + test("Date.make", () => { + module Test = { + Date.make() } () }) }) -describe("Belt_Set.Dict.remove", () => { - test("Belt_Set.Dict.remove", () => { +describe("Date.makeWithYM", () => { + test("Date.makeWithYM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYM(~year=2023, ~month=0) + // 2023-01-01T00:00:00.000Z - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) + Date.makeWithYM(~year=2023, ~month=11) + // 2023-12-01T00:00:00.000Z - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ + Date.makeWithYM(~year=2023, ~month=12) + // 2024-01-01T00:00:00.000Z + + Date.makeWithYM(~year=2023, ~month=-1) + // 2022-12-01T00:00:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_Set.Dict.subset", () => { - test("Belt_Set.Dict.subset", () => { +describe("Date.makeWithYMD", () => { + test("Date.makeWithYMD", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMD(~year=2023, ~month=1, ~date=20) + // 2023-02-20T00:00:00.000Z - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) + // 2022-11-29T00:00:00.000Z + + Date.makeWithYMD(~year=2023, ~month=1, ~date=29) + // 2023-03-01T00:00:00.000Z } () }) }) -describe("Belt_Set.Dict.reduce", () => { - test("Belt_Set.Dict.reduce", () => { +describe("Date.makeWithYMDH", () => { + test("Date.makeWithYMDH", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) + // 2023-02-20T16:00:00.000Z - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) + // 2023-02-21T00:00:00.000Z + + Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) + // 2023-02-19T23:00:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_Set.Dict.toList", () => { - test("Belt_Set.Dict.toList", () => { +describe("Date.makeWithYMDHM", () => { + test("Date.makeWithYMDHM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) + // 2023-02-20T16:40:00.000Z - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) + // 2023-02-20T17:00:00.000Z - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) + // 2023-02-20T15:59:00.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_SetDict.isEmpty", () => { - test("Belt_SetDict.isEmpty", () => { +describe("Date.makeWithYMDHMS", () => { + test("Date.makeWithYMDHMS", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) + // 2023-02-20T16:40:00.000Z - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) + // 2023-02-20T16:41:00.000Z - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) + // 2023-02-20T16:39:59.000Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_SetDict.forEach", () => { - test("Belt_SetDict.forEach", () => { +describe("Date.makeWithYMDHMSM", () => { + test("Date.makeWithYMDHMSM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=0, + ) + // 2023-02-20T16:40:00.000Z - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=1000, + ) + // 2023-02-20T16:40:01.000Z + + Date.makeWithYMDHMSM( + ~year=2023, + ~month=1, + ~date=20, + ~hours=16, + ~minutes=40, + ~seconds=0, + ~milliseconds=-1, + ) + // 2023-02-20T16:39:59.999Z + + // Note: The output depends on your local time zone. + // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) } () }) }) -describe("Belt_SetDict.toArray", () => { - test("Belt_SetDict.toArray", () => { +describe("Date.setDate", () => { + test("Date.setDate", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) } () }) }) -describe("Belt_SetDict.minimum", () => { - test("Belt_SetDict.minimum", () => { +describe("Date.setFullYear", () => { + test("Date.setFullYear", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) } () }) }) -describe("Belt_SetDict.maximum", () => { - test("Belt_SetDict.maximum", () => { +describe("Date.setFullYearM", () => { + test("Date.setFullYearM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) } () }) }) -describe("Belt_MutableSet.copy", () => { - test("Belt_MutableSet.copy", () => { +describe("Date.setFullYearMD", () => { + test("Date.setFullYearMD", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) } () }) }) -describe("Belt_MutableSet.diff", () => { - test("Belt_MutableSet.diff", () => { +describe("Date.setHours", () => { + test("Date.setHours", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) } () }) }) -describe("Belt_MutableSet.some", () => { - test("Belt_MutableSet.some", () => { +describe("Date.setHoursM", () => { + test("Date.setHoursM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) } () }) }) -describe("Belt_MutableSet.keep", () => { - test("Belt_MutableSet.keep", () => { +describe("Date.setHoursMS", () => { + test("Date.setHoursMS", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) } () }) }) -describe("Belt_MutableSet.size", () => { - test("Belt_MutableSet.size", () => { +describe("Date.setHoursMSMs", () => { + test("Date.setHoursMSMs", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt_Map.findFirstBy", () => { - test("Belt_Map.findFirstBy", () => { +describe("Date.setMilliseconds", () => { + test("Date.setMilliseconds", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) + Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) } () }) }) -describe("Belt_Map.keysToArray", () => { - test("Belt_Map.keysToArray", () => { +describe("Date.setMinutes", () => { + test("Date.setMinutes", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) } () }) }) -describe("Belt_List.concatMany", () => { - test("Belt_List.concatMany", () => { +describe("Date.setMinutesS", () => { + test("Date.setMinutesS", () => { module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) } () }) }) -describe("Belt_List.mapReverse", () => { - test("Belt_List.mapReverse", () => { +describe("Date.setMinutesSMs", () => { + test("Date.setMinutesSMs", () => { module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) + Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt.Array.partition", () => { - test("Belt.Array.partition", () => { +describe("Date.setMonth", () => { + test("Date.setMonth", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) } () }) }) -describe("Belt.List.concatMany", () => { - test("Belt.List.concatMany", () => { +describe("Date.setSeconds", () => { + test("Date.setSeconds", () => { module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} + Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) } () }) }) -describe("Belt.List.mapReverse", () => { - test("Belt.List.mapReverse", () => { +describe("Date.setSecondsMs", () => { + test("Date.setSecondsMs", () => { module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) + Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) } () }) }) -describe("Belt.Map.findFirstBy", () => { - test("Belt.Map.findFirstBy", () => { +describe("Date.setUTCDate", () => { + test("Date.setUTCDate", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) } () }) }) -describe("Belt.Map.keysToArray", () => { - test("Belt.Map.keysToArray", () => { +describe("Date.setUTCFullYear", () => { + test("Date.setUTCFullYear", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) } () }) }) -describe("Belt.MutableSet.copy", () => { - test("Belt.MutableSet.copy", () => { +describe("Date.setUTCFullYearM", () => { + test("Date.setUTCFullYearM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) } () }) }) -describe("Belt.MutableSet.diff", () => { - test("Belt.MutableSet.diff", () => { +describe("Date.setUTCFullYearMD", () => { + test("Date.setUTCFullYearMD", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( + ~year=2024, + ~month=0, + ~date=1, + ) } () }) }) -describe("Belt.MutableSet.some", () => { - test("Belt.MutableSet.some", () => { +describe("Date.setUTCHours", () => { + test("Date.setUTCHours", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) } () }) }) -describe("Belt.MutableSet.keep", () => { - test("Belt.MutableSet.keep", () => { +describe("Date.setUTCHoursM", () => { + test("Date.setUTCHoursM", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) } () }) }) -describe("Belt.MutableSet.size", () => { - test("Belt.MutableSet.size", () => { +describe("Date.setUTCHoursMS", () => { + test("Date.setUTCHoursMS", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( + ~hours=0, + ~minutes=0, + ~seconds=0, + ) } () }) }) -describe("Belt.HashMap.isEmpty", () => { - test("Belt.HashMap.isEmpty", () => { +describe("Date.setUTCHoursMSMs", () => { + test("Date.setUTCHoursMSMs", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( + ~hours=0, + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt.HashMap.forEach", () => { - test("Belt.HashMap.forEach", () => { +describe("Date.setUTCMilliseconds", () => { + test("Date.setUTCMilliseconds", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) } () }) }) -describe("Belt.HashMap.toArray", () => { - test("Belt.HashMap.toArray", () => { +describe("Date.setUTCMinutes", () => { + test("Date.setUTCMinutes", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) } () }) }) -describe("Belt.Set.Dict.remove", () => { - test("Belt.Set.Dict.remove", () => { +describe("Date.setUTCMinutesS", () => { + test("Date.setUTCMinutesS", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) } () }) }) -describe("Belt.Set.Dict.subset", () => { - test("Belt.Set.Dict.subset", () => { +describe("Date.setUTCMinutesSMs", () => { + test("Date.setUTCMinutesSMs", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( + ~minutes=0, + ~seconds=0, + ~milliseconds=0, + ) } () }) }) -describe("Belt.Set.Dict.reduce", () => { - test("Belt.Set.Dict.reduce", () => { +describe("Date.setUTCMonth", () => { + test("Date.setUTCMonth", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) } () }) }) -describe("Belt.Set.Dict.toList", () => { - test("Belt.Set.Dict.toList", () => { +describe("Date.setUTCSeconds", () => { + test("Date.setUTCSeconds", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) } () }) }) -describe("Belt_Array.partition", () => { - test("Belt_Array.partition", () => { +describe("Date.setUTCSecondsMs", () => { + test("Date.setUTCSecondsMs", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) } () }) }) -describe("Belt_HashMap.isEmpty", () => { - test("Belt_HashMap.isEmpty", () => { +describe("Date.toDateString", () => { + test("Date.toDateString", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log + // Sun Jan 01 2023 - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log + // Sat Dec 31 2022 } () }) }) -describe("Belt_HashMap.forEach", () => { - test("Belt_HashMap.forEach", () => { +describe("Date.toISOString", () => { + test("Date.toISOString", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log + // 2023-01-01T00:00:00.000Z - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log + // 2022-12-31T16:00:00.000Z } () }) }) -describe("Belt_HashMap.toArray", () => { - test("Belt_HashMap.toArray", () => { +describe("Date.toJSON", () => { + test("Date.toJSON", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON + // Some("2023-01-01T00:00:00.000Z") - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + Date.fromString("")->Date.toJSON + // None } () }) }) -describe("Array.joinWithUnsafe", () => { - test("Array.joinWithUnsafe", () => { +describe("Date.toLocaleDateString", () => { + test("Date.toLocaleDateString", () => { module Test = { - [1, 2, 3] - ->Array.joinWithUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") + Date.make()->Date.toLocaleDateString->Console.log + // 2/19/2023 } () }) }) -describe("Array.everyWithIndex", () => { - test("Array.everyWithIndex", () => { +describe("Date.toLocaleDateStringWithLocale", () => { + test("Date.toLocaleDateStringWithLocale", () => { module Test = { - let array = [1, 2, 3, 4] - - array - ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) - ->assertEqual(true) - - array - ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) - ->assertEqual(false) + Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log + // 2/19/2023 } () }) }) -describe("String.lastIndexOfOpt", () => { - test("String.lastIndexOfOpt", () => { +describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + test("Date.toLocaleDateStringWithLocaleAndOptions", () => { module Test = { - String.lastIndexOfOpt("bookseller", "ok") == Some(2) - String.lastIndexOfOpt("beekeeper", "ee") == Some(4) - String.lastIndexOfOpt("abcdefg", "xyz") == None + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) + ->Console.log + // February 19, 2023 + + Date.make() + ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 19.2.2023, 15:40 + + Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log + // 2023 } () }) }) -describe("String.startsWithFrom", () => { - test("String.startsWithFrom", () => { +describe("Date.toLocaleString", () => { + test("Date.toLocaleString", () => { module Test = { - String.startsWithFrom("BuckleScript", "kle", 3) == true - String.startsWithFrom("BuckleScript", "", 3) == true - String.startsWithFrom("JavaScript", "Buckle", 2) == false + Date.make()->Date.toLocaleString->Console.log + // 2/19/2023, 3:40:00 PM } () }) }) -describe("String.substringToEnd", () => { - test("String.substringToEnd", () => { +describe("Date.toLocaleStringWithLocale", () => { + test("Date.toLocaleStringWithLocale", () => { module Test = { - String.substringToEnd("playground", ~start=4) == "ground" - String.substringToEnd("playground", ~start=-3) == "playground" - String.substringToEnd("playground", ~start=12) == "" + Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log + // 2/19/2023, 3:40:00 PM } () }) }) -describe("RegExp.Result.matches", () => { - test("RegExp.Result.matches", () => { +describe("Date.toLocaleStringWithLocaleAndOptions", () => { + test("Date.toLocaleStringWithLocaleAndOptions", () => { module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) + ->Console.log + // 2/19/23, 3:40 PM - // This below will log "ReScript" and "is" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => - switch result->RegExp.Result.matches { - | [firstWord, secondWord] => Console.log2(firstWord, secondWord) - | _ => Console.log("Didn't find exactly two words...") - } - } + Date.make() + ->Date.toLocaleStringWithLocaleAndOptions( + "en", + { + era: #long, + year: #numeric, + month: #"2-digit", + day: #"2-digit", + hour: #numeric, + timeZoneName: #short, + }, + ) + ->Console.log + // 02/19/2023 Anno Domini, 3 PM GMT+1 } () }) }) -describe("Pervasives.setTimeout", () => { - test("Pervasives.setTimeout", () => { +describe("Date.toLocaleTimeString", () => { + test("Date.toLocaleTimeString", () => { module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeout( - () => { - Console.log("This prints in 200 ms.") - }, - 200, - ) + Date.make()->Date.toLocaleTimeString->Console.log + // 3:40:00 PM } () }) }) -describe("Object.hasOwnProperty", () => { - test("Object.hasOwnProperty", () => { +describe("Date.toLocaleTimeStringWithLocale", () => { + test("Date.toLocaleTimeStringWithLocale", () => { module Test = { - let point = {"x": 1, "y": 2} - {"a": 1}->Object.hasOwnProperty("a") // true - {"a": 1}->Object.hasOwnProperty("b") // false - {"a": 1}->Object.hasOwnProperty("toString") // false + Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log + // 3:40:00 PM } () }) }) -describe("List.forEachWithIndex", () => { - test("List.forEachWithIndex", () => { +describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { module Test = { - List.forEachWithIndex( - list{"a", "b", "c"}, - (x, index) => { - Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) + ->Console.log + // 3:40:00 PM GMT+1 + + Date.make() + ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) + ->Console.log + // 15:40 } () }) }) -describe("Math.Constants.log10e", () => { - test("Math.Constants.log10e", () => { +describe("Date.toString", () => { + test("Date.toString", () => { module Test = { - Math.Constants.log10e + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log + // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) + + Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log + // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) } () }) }) -describe("Int.toStringWithRadix", () => { - test("Int.toStringWithRadix", () => { +describe("Date.toTimeString", () => { + test("Date.toTimeString", () => { module Test = { - Int.toStringWithRadix(6, ~radix=2) // "110" - Int.toStringWithRadix(373592855, ~radix=16) // "16449317" - Int.toStringWithRadix(123456, ~radix=36) // "2n9c" + Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log + // 00:00:00 GMT+0100 (Central European Standard Time) + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log + // 17:00:00 GMT+0100 (Central European Standard Time) } () }) }) -describe("Date.setUTCFullYearMD", () => { - test("Date.setUTCFullYearMD", () => { +describe("Date.toUTCString", () => { + test("Date.toUTCString", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( - ~year=2024, - ~month=0, - ~date=1, - ) + Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log + // Sun, 01 Jan 2023 00:00:00 GMT + + Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log + // Sat, 31 Dec 2022 16:00:00 GMT } () }) }) -describe("Date.setUTCMinutesSMs", () => { - test("Date.setUTCMinutesSMs", () => { +describe("Dict.assign", () => { + test("Dict.assign", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) + let dict1 = Dict.make() + dict1->Dict.set("firstKey", 1) + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` + + let dict2 = Dict.make() + dict2->Dict.set("someKey", 2) + dict2->Dict.set("someKey2", 3) + + let dict1 = dict1->Dict.assign(dict2) + + Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` } () }) }) -describe("Date.UTC.makeWithYMDH", () => { - test("Date.UTC.makeWithYMDH", () => { - module Test = { - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 1676908800000 - - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 1676937600000 +describe("Dict.copy", () => { + test("Dict.copy", () => { + module Test = { + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let dict2 = dict->Dict.copy - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 1676847600000 + // Both log `["key1", "key2"]` here. + Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) } () }) }) -describe("BigInt.toLocaleString", () => { - test("BigInt.toLocaleString", () => { +describe("Dict.delete", () => { + test("Dict.delete", () => { module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log + let dict = Dict.fromArray([("someKey", "someValue")]) + + dict->Dict.delete("someKey") } () }) }) -describe("Belt_Set.minUndefined", () => { - test("Belt_Set.minUndefined", () => { +describe("Dict.forEach", () => { + test("Dict.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + dict->Dict.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt_Set.maxUndefined", () => { - test("Belt_Set.maxUndefined", () => { +describe("Dict.forEachWithKey", () => { + test("Dict.forEachWithKey", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) + dict->Dict.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) } () }) }) -describe("Belt_Set.Dict.isEmpty", () => { - test("Belt_Set.Dict.isEmpty", () => { +describe("Dict.fromArray", () => { + test("Dict.fromArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) } () }) }) -describe("Belt_Set.Dict.forEach", () => { - test("Belt_Set.Dict.forEach", () => { +describe("Dict.fromIterator", () => { + test("Dict.fromIterator", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + let iterator: Iterator.t<(string, int)> = %raw(` + (() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + iterator + ->Dict.fromIterator + ->Dict.valuesToArray + ->assertEqual([1, 2]) } () }) }) -describe("Belt_Set.Dict.toArray", () => { - test("Belt_Set.Dict.toArray", () => { +describe("Dict.get", () => { + test("Dict.get", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + let dict = Dict.fromArray([("someKey", "someValue")]) - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + switch dict->Dict.get("someKey") { + | None => Console.log("Nope, didn't have the key.") + | Some(value) => Console.log(value) + } } () }) }) -describe("Belt_Set.Dict.minimum", () => { - test("Belt_Set.Dict.minimum", () => { +describe("Dict.getUnsafe", () => { + test("Dict.getUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) + let value = dict->Dict.getUnsafe("key1") + Console.log(value) // value1 } () }) }) -describe("Belt_Set.Dict.maximum", () => { - test("Belt_Set.Dict.maximum", () => { +describe("Dict.keysToArray", () => { + test("Dict.keysToArray", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let keys = dict->Dict.keysToArray + Console.log(keys) // Logs `["someKey", "someKey2"]` to the console } () }) }) -describe("Belt_MutableSet.union", () => { - test("Belt_MutableSet.union", () => { +describe("Dict.make", () => { + test("Dict.make", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + let dict2 = Dict.make() // Or you can let ReScript infer it via usage. + dict2->Dict.set("someKey", 12) } () }) }) -describe("Belt_MutableSet.every", () => { - test("Belt_MutableSet.every", () => { +describe("Dict.mapValues", () => { + test("Dict.mapValues", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 + let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ + dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] + dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] } () }) }) -describe("Belt_MutableSet.split", () => { - test("Belt_MutableSet.split", () => { +describe("Dict.set", () => { + test("Dict.set", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) + let dict = Dict.make() - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ + dict->Dict.set("someKey", "someValue") } () }) }) -describe("Belt_List.mapReverse2", () => { - test("Belt_List.mapReverse2", () => { +describe("Dict.toArray", () => { + test("Dict.toArray", () => { module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let asArray = dict->Dict.toArray + Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console } () }) }) -describe("Belt_List.cmpByLength", () => { - test("Belt_List.cmpByLength", () => { +describe("Dict.valuesToArray", () => { + test("Dict.valuesToArray", () => { module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + let dict = Dict.make() + dict->Dict.set("someKey", 1) + dict->Dict.set("someKey2", 2) + let values = dict->Dict.valuesToArray + Console.log(values) // Logs `[1, 2]` to the console } () }) }) -describe("Belt_List.removeAssoc", () => { - test("Belt_List.removeAssoc", () => { +describe("Error.make", () => { + test("Error.make", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ + let error = Error.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console + Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error } () }) }) -describe("Belt.Array.concatMany", () => { - test("Belt.Array.concatMany", () => { +describe("Error.message", () => { + test("Error.message", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.message) // Logs "Some message here" to the console } () }) }) -describe("Belt.Array.sliceToEnd", () => { - test("Belt.Array.sliceToEnd", () => { +describe("Error.name", () => { + test("Error.name", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + let error = Error.SyntaxError.make("Some message here") + Console.log(error->Error.name) // Logs "SyntaxError" to the console } () }) }) -describe("Belt.Array.getIndexBy", () => { - test("Belt.Array.getIndexBy", () => { +describe("Error.panic", () => { + test("Error.panic", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + try { + Error.panic("Uh oh. This was unexpected!") + } catch { + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") + | None => assert(false) + } + | _ => assert(false) + } } () }) }) -describe("Belt.List.mapReverse2", () => { - test("Belt.List.mapReverse2", () => { +describe("Error.raise", () => { + test("Error.raise", () => { module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} + let error = Error.make("Everything is upside down.") + + if 5 > 10 { + error->Error.raise + } else { + Console.log("Phew, sanity still rules.") + } } () }) }) -describe("Belt.List.cmpByLength", () => { - test("Belt.List.cmpByLength", () => { +describe("Error.stack", () => { + test("Error.stack", () => { module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ + let error = Error.make("error") + Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` } () }) }) -describe("Belt.List.removeAssoc", () => { - test("Belt.List.removeAssoc", () => { +describe("Error.toException", () => { + test("Error.toException", () => { module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ + let error = Error.make("Something went wrong.") - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ + let asExn = error->Error.toException // `asExn` is now type `exn` } () }) }) -describe("Belt.Set.minUndefined", () => { - test("Belt.Set.minUndefined", () => { +describe("Float.Constants.epsilon", () => { + test("Float.Constants.epsilon", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) + Float.Constants.epsilon } () }) }) -describe("Belt.Set.maxUndefined", () => { - test("Belt.Set.maxUndefined", () => { +describe("Float.Constants.maxValue", () => { + test("Float.Constants.maxValue", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) - - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) + Float.Constants.minValue } () }) }) -describe("Belt.MutableSet.union", () => { - test("Belt.MutableSet.union", () => { +describe("Float.Constants.minValue", () => { + test("Float.Constants.minValue", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ + Float.Constants.minValue } () }) }) -describe("Belt.MutableSet.every", () => { - test("Belt.MutableSet.every", () => { +describe("Float.Constants.nan", () => { + test("Float.Constants.nan", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ + Float.Constants.nan } () }) }) -describe("Belt.MutableSet.split", () => { - test("Belt.MutableSet.split", () => { +describe("Float.Constants.negativeInfinity", () => { + test("Float.Constants.negativeInfinity", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) - - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ + Float.Constants.negativeInfinity } () }) }) -describe("Belt.HashMap.logStats", () => { - test("Belt.HashMap.logStats", () => { +describe("Float.Constants.positiveInfinity", () => { + test("Float.Constants.positiveInfinity", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.logStats(hMap) + Float.Constants.positiveInfinity } () }) }) -describe("Belt.Float.fromString", () => { - test("Belt.Float.fromString", () => { +describe("Float.clamp", () => { + test("Float.clamp", () => { module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + Float.clamp(4.2) == 4.2 + Float.clamp(4.2, ~min=4.3) == 4.3 + Float.clamp(4.2, ~max=4.1) == 4.1 + Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 } () }) }) -describe("Belt.Set.Dict.isEmpty", () => { - test("Belt.Set.Dict.isEmpty", () => { +describe("Float.fromInt", () => { + test("Float.fromInt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ + Float.fromInt(2) == 2.0 + Float.fromInt(1) == 1.0 } () }) }) -describe("Belt.Set.Dict.forEach", () => { - test("Belt.Set.Dict.forEach", () => { +describe("Float.fromString", () => { + test("Float.fromString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + Float.fromString("0") == Some(0.0) + Float.fromString("NaN") == None + Float.fromString("6") == Some(6.0) } () }) }) -describe("Belt.Set.Dict.toArray", () => { - test("Belt.Set.Dict.toArray", () => { +describe("Float.isFinite", () => { + test("Float.isFinite", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ + Float.isFinite(1.0) // true + Float.isFinite(Float.Constants.nan) // false + Float.isFinite(Float.Constants.positiveInfinity) // false } () }) }) -describe("Belt.Set.Dict.minimum", () => { - test("Belt.Set.Dict.minimum", () => { +describe("Float.isNaN", () => { + test("Float.isNaN", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ + Float.isNaN(3.0) // false + Float.isNaN(Float.Constants.nan) // true } () }) }) -describe("Belt.Set.Dict.maximum", () => { - test("Belt.Set.Dict.maximum", () => { +describe("Float.mod", () => { + test("Float.mod", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ + Float.mod(7.0, 4.0) == 3.0 } () }) }) -describe("Belt_Float.fromString", () => { - test("Belt_Float.fromString", () => { +describe("Float.parseFloat", () => { + test("Float.parseFloat", () => { module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ + Float.parseFloat("1.0") // 1.0 + Float.parseFloat(" 3.14 ") // 3.14 + Float.parseFloat("3.0") // 3.0 + Float.parseFloat("3.14some non-digit characters") // 3.14 + Float.parseFloat("error")->Float.isNaN // true } () }) }) -describe("Belt_Array.concatMany", () => { - test("Belt_Array.concatMany", () => { +describe("Float.parseInt", () => { + test("Float.parseInt", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + Float.parseInt("1.0") // 1.0 + Float.parseInt(" 3.14 ") // 3.0 + Float.parseInt(3) // 3.0 + Float.parseInt("3.14some non-digit characters") // 3.0 + Float.parseInt("error")->Float.isNaN // true + Float.parseInt("10.0", ~radix=2) // 2.0 + Float.parseInt("15 * 3", ~radix=10) // 15.0 + Float.parseInt("12", ~radix=13) // 15.0 + Float.parseInt("17", ~radix=40)->Float.isNaN // true } () }) }) -describe("Belt_Array.sliceToEnd", () => { - test("Belt_Array.sliceToEnd", () => { +describe("Float.parseIntWithRadix", () => { + test("Float.parseIntWithRadix", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 + Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 + Float.parseIntWithRadix("12", ~radix=13) // 15.0 + Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true } () }) }) -describe("Belt_Array.getIndexBy", () => { - test("Belt_Array.getIndexBy", () => { +describe("Float.toExponential", () => { + test("Float.toExponential", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + Float.toExponential(1000.0) // "1e+3" + Float.toExponential(-1000.0) // "-1e+3" + Float.toExponential(77.0, ~digits=2) // "7.70e+1" + Float.toExponential(5678.0, ~digits=2) // "5.68e+3" } () }) }) -describe("Belt_HashMap.logStats", () => { - test("Belt_HashMap.logStats", () => { +describe("Float.toExponentialWithPrecision", () => { + test("Float.toExponentialWithPrecision", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.logStats(hMap) + Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" + Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" } () }) }) -describe("AsyncIterator.forEach", () => { - test("AsyncIterator.forEach", () => { +describe("Float.toFixed", () => { + test("Float.toFixed", () => { module Test = { - // Let's pretend we get an async iterator returning ints from somewhere. - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let main = async () => - await asyncIterator->AsyncIterator.forEach( - v => { - switch v { - | Some(("second", value)) => assertEqual(value, "2") - | _ => () - } - }, - ) - - main()->ignore + Float.toFixed(123456.0) // "123456.00" + Float.toFixed(10.0) // "10.00" + Float.toFixed(300.0, ~digits=4) // "300.0000" + Float.toFixed(300.0, ~digits=1) // "300.0" } () }) }) -describe("Array.fromInitializer", () => { - test("Array.fromInitializer", () => { +describe("Float.toFixedWithPrecision", () => { + test("Float.toFixedWithPrecision", () => { module Test = { - Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) - - Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) + Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" + Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" } () }) }) -describe("Array.filterWithIndex", () => { - test("Array.filterWithIndex", () => { +describe("Float.toInt", () => { + test("Float.toInt", () => { module Test = { - [1, 2, 3, 4] - ->Array.filterWithIndex((num, index) => index === 0 || num === 2) - ->assertEqual([1, 2]) + Float.toInt(2.0) == 2 + Float.toInt(1.0) == 1 + Float.toInt(1.1) == 1 + Float.toInt(1.6) == 1 } () }) }) -describe("Array.reduceWithIndex", () => { - test("Array.reduceWithIndex", () => { +describe("Float.toLocaleString", () => { + test("Float.toLocaleString", () => { module Test = { - Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) - - Array.reduceWithIndex( - [1, 2, 3], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{5, 3, 1}) + // If the application uses English as the default language + Float.toLocaleString(1000.0) // "1,000" - Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) + // If the application uses Portuguese Brazil as the default language + Float.toLocaleString(1000.0) // "1.000" } () }) }) -describe("Type.Classify.classify", () => { - test("Type.Classify.classify", () => { +describe("Float.toPrecision", () => { + test("Float.toPrecision", () => { module Test = { - switch %raw(`null`)->Type.Classify.classify { - | Null => Console.log("Yup, that's null.") - | _ => Console.log("This doesn't actually appear to be null...") - } + Float.toPrecision(100.0) // "100" + Float.toPrecision(1.0) // "1" + Float.toPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecision(1.0, ~digits=1) // "1" } () }) }) -describe("String.lastIndexOfFrom", () => { - test("String.lastIndexOfFrom", () => { +describe("Float.toPrecisionWithPrecision", () => { + test("Float.toPrecisionWithPrecision", () => { module Test = { - String.lastIndexOfFrom("bookseller", "ok", 6) == 2 - String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 - String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 - String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 + Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" + Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" } () }) }) -describe("Pervasives.setInterval", () => { - test("Pervasives.setInterval", () => { +describe("Float.toString", () => { + test("Float.toString", () => { module Test = { - // Log to the console ever 200 ms (200 milliseconds). - let intervalId = setInterval( - () => { - Console.log("This prints every 200 ms.") - }, - 200, - ) - - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) + Float.toString(1000.0) // "1000" + Float.toString(-1000.0) // "-1000" } () }) }) -describe("Pervasives.assertEqual", () => { - test("Pervasives.assertEqual", () => { +describe("Float.toStringWithRadix", () => { + test("Float.toStringWithRadix", () => { module Test = { - list{1, 2} - ->List.tailExn - ->assertEqual(list{2}) + Float.toStringWithRadix(6.0, ~radix=2) // "110" + Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" + Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" } () }) }) -describe("Math.Constants.sqrt1_2", () => { - test("Math.Constants.sqrt1_2", () => { +describe("Int.Bitwise.asr", () => { + test("Int.Bitwise.asr", () => { module Test = { - Math.Constants.sqrt1_2 + Int.Bitwise.asr(4, 1) == 2 } () }) }) -describe("JSON.Classify.classify", () => { - test("JSON.Classify.classify", () => { +describe("Int.Bitwise.land", () => { + test("Int.Bitwise.land", () => { module Test = { - JSON.Classify.classify("hello world") - // String("hello world") - - JSON.Classify.classify(42) - // Number(42) + Int.Bitwise.land(7, 4) == 4 } () }) }) -describe("Int.Constants.minValue", () => { - test("Int.Constants.minValue", () => { +describe("Int.Bitwise.lnot", () => { + test("Int.Bitwise.lnot", () => { module Test = { - Console.log(Int.Constants.minValue) + Int.Bitwise.lnot(2) == -3 } () }) }) -describe("Int.Constants.maxValue", () => { - test("Int.Constants.maxValue", () => { +describe("Int.Bitwise.lor", () => { + test("Int.Bitwise.lor", () => { module Test = { - Console.log(Int.Constants.maxValue) + Int.Bitwise.lor(7, 4) == 7 } () }) }) -describe("Date.getTimezoneOffset", () => { - test("Date.getTimezoneOffset", () => { +describe("Int.Bitwise.lsl", () => { + test("Int.Bitwise.lsl", () => { module Test = { - Date.fromString("2023-01-01")->Date.getTimezoneOffset - // -60 with local time zone = Europe/Berlin - - Date.fromString("2023-06-01")->Date.getTimezoneOffset - // -120 with local time zone = Europe/Berlin + Int.Bitwise.lsl(4, 1) == 8 } () }) }) -describe("Date.UTC.makeWithYMDHM", () => { - test("Date.UTC.makeWithYMDHM", () => { +describe("Int.Bitwise.lsr", () => { + test("Int.Bitwise.lsr", () => { module Test = { - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 1676911200000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 1676912400000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 1676908740000 + Int.Bitwise.lsr(8, 1) == 4 } () }) }) -describe("Belt_SetDict.fromArray", () => { - test("Belt_SetDict.fromArray", () => { +describe("Int.Bitwise.lxor", () => { + test("Int.Bitwise.lxor", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + Int.Bitwise.lxor(7, 4) == 3 } () }) }) -describe("Belt_SetDict.mergeMany", () => { - test("Belt_SetDict.mergeMany", () => { +describe("Int.Constants.maxValue", () => { + test("Int.Constants.maxValue", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty - - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + Console.log(Int.Constants.maxValue) } () }) }) -describe("Belt_SetDict.intersect", () => { - test("Belt_SetDict.intersect", () => { +describe("Int.Constants.minValue", () => { + test("Int.Constants.minValue", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + Console.log(Int.Constants.minValue) } () }) }) -describe("Belt_SetDict.partition", () => { - test("Belt_SetDict.partition", () => { +describe("Int.clamp", () => { + test("Int.clamp", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) - - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ + Int.clamp(42) == 42 + Int.clamp(42, ~min=50) == 50 + Int.clamp(42, ~max=40) == 40 + Int.clamp(42, ~min=50, ~max=40) == 50 } () }) }) -describe("Belt_MutableSet.remove", () => { - test("Belt_MutableSet.remove", () => { +describe("Int.fromFloat", () => { + test("Int.fromFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) - - s0->Belt.MutableSet.toArray /* [2,4,5] */ + Int.fromFloat(2.0) == 2 + Int.fromFloat(1.999) == 1 + Int.fromFloat(1.5) == 1 + Int.fromFloat(0.9999) == 0 } () }) }) -describe("Belt_MutableSet.subset", () => { - test("Belt_MutableSet.subset", () => { +describe("Int.fromString", () => { + test("Int.fromString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ + Int.fromString("0") == Some(0) + Int.fromString("NaN") == None + Int.fromString("6", ~radix=2) == None } () }) }) -describe("Belt_MutableSet.reduce", () => { - test("Belt_MutableSet.reduce", () => { +describe("Int.mod", () => { + test("Int.mod", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + Int.mod(7, 4) == 3 } () }) }) -describe("Belt_MutableSet.toList", () => { - test("Belt_MutableSet.toList", () => { +describe("Int.range", () => { + test("Int.range", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toList /* [1,2,3,5] */ + Int.range(3, 6) == [3, 4, 5] + Int.range(-3, -1) == [-3, -2] + Int.range(3, 1) == [3, 2] + Int.range(3, 7, ~options={step: 2}) == [3, 5] + Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] + Int.range(3, 6, ~options={step: -2}) // RangeError } () }) }) -describe("Belt_Map.valuesToArray", () => { - test("Belt_Map.valuesToArray", () => { +describe("Int.rangeWithOptions", () => { + test("Int.rangeWithOptions", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] + Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] + Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] + Int.rangeWithOptions(3, 6, {step: -2}) // RangeError } () }) }) -describe("Belt_List.mapWithIndex", () => { - test("Belt_List.mapWithIndex", () => { +describe("Int.toExponential", () => { + test("Int.toExponential", () => { module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + Int.toExponential(1000) // "1e+3" + Int.toExponential(-1000) // "-1e+3" + Int.toExponential(77, ~digits=2) // "7.70e+1" + Int.toExponential(5678, ~digits=2) // "5.68e+3" } () }) }) -describe("Belt.List.mapWithIndex", () => { - test("Belt.List.mapWithIndex", () => { +describe("Int.toExponentialWithPrecision", () => { + test("Int.toExponentialWithPrecision", () => { module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} + Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" + Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" } () }) }) -describe("Belt.Map.valuesToArray", () => { - test("Belt.Map.valuesToArray", () => { +describe("Int.toFixed", () => { + test("Int.toFixed", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] + Int.toFixed(123456) // "123456.00" + Int.toFixed(10) // "10.00" + Int.toFixed(300, ~digits=4) // "300.0000" + Int.toFixed(300, ~digits=1) // "300.0" } () }) }) -describe("Belt.MutableSet.remove", () => { - test("Belt.MutableSet.remove", () => { +describe("Int.toFixedWithPrecision", () => { + test("Int.toFixedWithPrecision", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) - - s0->Belt.MutableSet.toArray /* [2,4,5] */ + Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" + Int.toFixedWithPrecision(300, ~digits=1) // "300.0" } () }) }) -describe("Belt.MutableSet.subset", () => { - test("Belt.MutableSet.subset", () => { +describe("Int.toFloat", () => { + test("Int.toFloat", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ + Int.toFloat(100) == 100.0 + Int.toFloat(2) == 2.0 } () }) }) -describe("Belt.MutableSet.reduce", () => { - test("Belt.MutableSet.reduce", () => { +describe("Int.toLocaleString", () => { + test("Int.toLocaleString", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + // If the application uses English as the default language + Int.toLocaleString(1000) // "1,000" - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ + // If the application uses Portuguese Brazil as the default language + Int.toLocaleString(1000) // "1.000" } () }) }) -describe("Belt.MutableSet.toList", () => { - test("Belt.MutableSet.toList", () => { +describe("Int.toPrecision", () => { + test("Int.toPrecision", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toList /* [1,2,3,5] */ + Int.toPrecision(100) // "100" + Int.toPrecision(1) // "1" + Int.toPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecision(1, ~digits=2) // "1.0" } () }) }) -describe("Belt.HashMap.fromArray", () => { - test("Belt.HashMap.fromArray", () => { +describe("Int.toPrecisionWithPrecision", () => { + test("Int.toPrecisionWithPrecision", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" + Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" } () }) }) -describe("Belt.HashMap.mergeMany", () => { - test("Belt.HashMap.mergeMany", () => { +describe("Int.toString", () => { + test("Int.toString", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + Int.toString(1000) // "1000" + Int.toString(-1000) // "-1000" + Int.toString(6, ~radix=2) // "110" + Int.toString(373592855, ~radix=16) // "16449317" + Int.toString(123456, ~radix=36) // "2n9c" } () }) }) -describe("Belt_HashMap.fromArray", () => { - test("Belt_HashMap.fromArray", () => { +describe("Int.toStringWithRadix", () => { + test("Int.toStringWithRadix", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] + Int.toStringWithRadix(6, ~radix=2) // "110" + Int.toStringWithRadix(373592855, ~radix=16) // "16449317" + Int.toStringWithRadix(123456, ~radix=36) // "2n9c" } () }) }) -describe("Belt_HashMap.mergeMany", () => { - test("Belt_HashMap.mergeMany", () => { +describe("Iterator.forEach", () => { + test("Iterator.forEach", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + iterator->Iterator.forEach( + v => { + switch v { + | Some("a" | "b" | "c") => assert(true) + | other => + other + ->Option.isNone + ->assertEqual(true) + } + }, + ) } () }) }) -describe("Array.forEachWithIndex", () => { - test("Array.forEachWithIndex", () => { +describe("Iterator.next", () => { + test("Iterator.next", () => { module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array->Array.forEachWithIndex( - (item, index) => { - Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) - }, - ) + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) + (iterator->Iterator.next).done->assertEqual(false) + (iterator->Iterator.next).done->assertEqual(true) } () }) }) -describe("Array.flatMapWithIndex", () => { - test("Array.flatMapWithIndex", () => { +describe("Iterator.toArray", () => { + test("Iterator.toArray", () => { module Test = { - type language = ReScript | TypeScript | JavaScript + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - let array = [ReScript, TypeScript, JavaScript] + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = map->Map.keys->Iterator.toArray - array - ->Array.flatMapWithIndex( - (item, index) => - switch item { - | ReScript => [index] - | TypeScript => [index, index + 1] - | JavaScript => [index, index + 1, index + 2] - }, - ) - ->assertEqual([0, 1, 2, 2, 3, 4]) + Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. } () }) }) -describe("String.fromCharCodeMany", () => { - test("String.fromCharCodeMany", () => { +describe("Iterator.toArrayWithMapper", () => { + test("Iterator.toArrayWithMapper", () => { module Test = { - String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" - String.fromCharCodeMany([65, 66, 67]) == "ABC" + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") + + // `Map.keys` returns all keys of the map as an iterator. + let mapKeysAsArray = + map + ->Map.keys + ->Iterator.toArrayWithMapper(key => key->String.length) + + Console.log(mapKeysAsArray) // Logs [7, 8] to the console. } () }) }) -describe("String.replaceAllRegExp", () => { - test("String.replaceAllRegExp", () => { +describe("JSON.Classify.classify", () => { + test("JSON.Classify.classify", () => { module Test = { - String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" + JSON.Classify.classify("hello world") + // String("hello world") + + JSON.Classify.classify(42) + // Number(42) } () }) }) -describe("RegExp.Result.fullMatch", () => { - test("RegExp.Result.fullMatch", () => { +describe("JSON.Decode.array", () => { + test("JSON.Decode.array", () => { module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") + JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array + // Some([ 'foo', 'bar' ]) - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" - } + JSON.parseExn(`"hello world"`)->JSON.Decode.array + // None } () }) }) -describe("Pervasives.clearTimeout", () => { - test("Pervasives.clearTimeout", () => { +describe("JSON.Decode.bool", () => { + test("JSON.Decode.bool", () => { module Test = { - let timeoutId = setTimeout( - () => { - Console.log("This prints in 2 seconds.") - }, - 2000, - ) + JSON.parseExn(`true`)->JSON.Decode.bool + // Some(true) - // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. - clearTimeout(timeoutId) + JSON.parseExn(`"hello world"`)->JSON.Decode.bool + // None } () }) }) -describe("Float.parseIntWithRadix", () => { - test("Float.parseIntWithRadix", () => { +describe("JSON.Decode.float", () => { + test("JSON.Decode.float", () => { module Test = { - Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 - Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 - Float.parseIntWithRadix("12", ~radix=13) // 15.0 - Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true + JSON.parseExn(`42.0`)->JSON.Decode.float + // Some(42.0) + + JSON.parseExn(`"hello world"`)->JSON.Decode.float + // None } () }) }) -describe("Float.toStringWithRadix", () => { - test("Float.toStringWithRadix", () => { +describe("JSON.Decode.null", () => { + test("JSON.Decode.null", () => { module Test = { - Float.toStringWithRadix(6.0, ~radix=2) // "110" - Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" - Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" + JSON.parseExn(`null`)->JSON.Decode.null + // Some(null) + + JSON.parseExn(`"hello world"`)->JSON.Decode.null + // None } () }) }) -describe("Float.Constants.epsilon", () => { - test("Float.Constants.epsilon", () => { +describe("JSON.Decode.object", () => { + test("JSON.Decode.object", () => { module Test = { - Float.Constants.epsilon + JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object + // Some({ foo: 'bar' }) + + JSON.parseExn(`"hello world"`)->JSON.Decode.object + // None } () }) }) -describe("Date.getUTCMilliseconds", () => { - test("Date.getUTCMilliseconds", () => { +describe("JSON.Decode.string", () => { + test("JSON.Decode.string", () => { module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 + JSON.parseExn(`"hello world"`)->JSON.Decode.string + // Some("hello world") + + JSON.parseExn(`42`)->JSON.Decode.string + // None } () }) }) -describe("Date.setUTCMilliseconds", () => { - test("Date.setUTCMilliseconds", () => { +describe("JSON.Encode.array", () => { + test("JSON.Encode.array", () => { module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) + let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] + + JSON.Encode.array(array) } () }) }) -describe("Date.toLocaleDateString", () => { - test("Date.toLocaleDateString", () => { +describe("JSON.Encode.bool", () => { + test("JSON.Encode.bool", () => { module Test = { - Date.make()->Date.toLocaleDateString->Console.log - // 2/19/2023 + JSON.Encode.bool(true) } () }) }) -describe("Date.toLocaleTimeString", () => { - test("Date.toLocaleTimeString", () => { +describe("JSON.Encode.float", () => { + test("JSON.Encode.float", () => { module Test = { - Date.make()->Date.toLocaleTimeString->Console.log - // 3:40:00 PM + JSON.Encode.float(42.0) } () }) }) -describe("Date.UTC.makeWithYMDHMS", () => { - test("Date.UTC.makeWithYMDHMS", () => { +describe("JSON.Encode.int", () => { + test("JSON.Encode.int", () => { module Test = { - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 1676911200000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 1676911260000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 1676911199000 + JSON.Encode.int(42) } () }) }) -describe("Belt_Set.Dict.fromArray", () => { - test("Belt_Set.Dict.fromArray", () => { +describe("JSON.Encode.null", () => { + test("JSON.Encode.null", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + JSON.Encode.null } () }) }) -describe("Belt_Set.Dict.mergeMany", () => { - test("Belt_Set.Dict.mergeMany", () => { +describe("JSON.Encode.object", () => { + test("JSON.Encode.object", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ]) - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + JSON.Encode.object(dict) } () }) }) -describe("Belt_Set.Dict.intersect", () => { - test("Belt_Set.Dict.intersect", () => { +describe("JSON.Encode.string", () => { + test("JSON.Encode.string", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + JSON.Encode.string("hello world") } () }) }) -describe("Belt_Set.Dict.partition", () => { - test("Belt_Set.Dict.partition", () => { +describe("JSON.parseExn", () => { + test("JSON.parseExn", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + try { + let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) + // { foo: 'bar', hello: 'world' } - let isOdd = x => mod(x, 2) != 0 + let _ = JSON.parseExn("") + // error + } catch { + | Exn.Error(_) => Console.log("error") + } - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ + let jsonString = `{"hello":"world","someNumber":21}` + + try { + JSON.parseExn(jsonString, ~reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExn("", ~reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } } () }) }) -describe("Belt_SetDict.removeMany", () => { - test("Belt_SetDict.removeMany", () => { +describe("JSON.parseExnWithReviver", () => { + test("JSON.parseExnWithReviver", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let reviver = (_, value: JSON.t) => + switch value { + | String(string) => string->String.toUpperCase->JSON.Encode.string + | Number(number) => (number *. 2.0)->JSON.Encode.float + | _ => value + } - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + let jsonString = `{"hello":"world","someNumber":21}` - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + try { + JSON.parseExnWithReviver(jsonString, reviver)->Console.log + // { hello: 'WORLD', someNumber: 42 } + + JSON.parseExnWithReviver("", reviver)->Console.log + // error + } catch { + | Exn.Error(_) => Console.log("error") + } } () }) }) -describe("Belt_MutableSet.isEmpty", () => { - test("Belt_MutableSet.isEmpty", () => { +describe("JSON.stringify", () => { + test("JSON.stringify", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + JSON.stringify(json) + // {"foo":"bar","hello":"world","someNumber":42} - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ - } - () - }) -}) + JSON.stringify(json, ~space=2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } -describe("Belt_MutableSet.forEach", () => { - test("Belt_MutableSet.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) + // {"foo":"bar","someNumber":42} - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, + ) + + JSON.stringify(json, ~replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} } () }) }) -describe("Belt_MutableSet.toArray", () => { - test("Belt_MutableSet.toArray", () => { +describe("JSON.stringifyAny", () => { + test("JSON.stringifyAny", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ - } - () - }) -}) + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) -describe("Belt_MutableSet.minimum", () => { - test("Belt_MutableSet.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let replacer = JSON.Replacer( + (_, value) => { + let decodedValue = value->JSON.Decode.string - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ - } - () - }) -}) + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + }, + ) -describe("Belt_MutableSet.maximum", () => { - test("Belt_MutableSet.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + dict + ->JSON.stringifyAny(~replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + JSON.stringifyAny(() => "hello world")->assertEqual(None) - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ + // Raise a exception + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_MapInt.findFirstBy", () => { - test("Belt_MapInt.findFirstBy", () => { +describe("JSON.stringifyAnyWithFilter", () => { + test("JSON.stringifyAnyWithFilter", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) - } - () - }) -}) + dict + ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) + ->assertEqual(`{"foo":"bar","someNumber":42}`) -describe("Belt_List.reverseConcat", () => { - test("Belt_List.reverseConcat", () => { - module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_List.reduceReverse", () => { - test("Belt_List.reduceReverse", () => { +describe("JSON.stringifyAnyWithFilterAndIndent", () => { + test("JSON.stringifyAnyWithFilterAndIndent", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + dict + ->JSON.stringifyAny + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} - } - () - }) -}) + dict + ->JSON.stringifyAny(~space=2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) -describe("Belt_List.keepWithIndex", () => { - test("Belt_List.keepWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 + dict + ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) + ->Option.getUnsafe + ->assertEqual(`{"foo":"bar","someNumber":42}`) - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) + JSON.stringifyAny(() => "hello world")->assertEqual(None) -describe("Belt.Array.mapWithIndex", () => { - test("Belt.Array.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.List.reverseConcat", () => { - test("Belt.List.reverseConcat", () => { +describe("JSON.stringifyAnyWithIndent", () => { + test("JSON.stringifyAnyWithIndent", () => { module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) + + dict + ->JSON.stringifyAnyWithIndent(2) + ->Option.getUnsafe + ->assertEqual(`{ + "foo": "bar", + "hello": "world", + "someNumber": 42 +}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.List.reduceReverse", () => { - test("Belt.List.reduceReverse", () => { +describe("JSON.stringifyAnyWithReplacer", () => { + test("JSON.stringifyAnyWithReplacer", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string + + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) + + JSON.stringifyAny(() => "hello world")->assertEqual(None) - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.List.keepWithIndex", () => { - test("Belt.List.keepWithIndex", () => { +describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + test("JSON.stringifyAnyWithReplacerAndIndent", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + let dict = Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ]) - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string -describe("Belt.MutableSet.isEmpty", () => { - test("Belt.MutableSet.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) + dict + ->JSON.stringifyAnyWithReplacer(replacer) + ->Option.getUnsafe + ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ + JSON.stringifyAny(() => "hello world")->assertEqual(None) + + switch BigInt.fromInt(0)->JSON.stringifyAny { + | exception _ => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.MutableSet.forEach", () => { - test("Belt.MutableSet.forEach", () => { +describe("JSON.stringifyWithFilter", () => { + test("JSON.stringifyWithFilter", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ + JSON.stringifyWithFilter(json, ["foo", "someNumber"]) + // {"foo":"bar","someNumber":42} } () }) }) -describe("Belt.MutableSet.toArray", () => { - test("Belt.MutableSet.toArray", () => { +describe("JSON.stringifyWithFilterAndIndent", () => { + test("JSON.stringifyWithFilterAndIndent", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ + JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) + // { + // "foo": "bar", + // "someNumber": 42 + // } } () }) }) -describe("Belt.MutableSet.minimum", () => { - test("Belt.MutableSet.minimum", () => { +describe("JSON.stringifyWithIndent", () => { + test("JSON.stringifyWithIndent", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ + JSON.stringifyWithIndent(json, 2) + // { + // "foo": "bar", + // "hello": "world", + // "someNumber": 42 + // } } () }) }) -describe("Belt.MutableSet.maximum", () => { - test("Belt.MutableSet.maximum", () => { +describe("JSON.stringifyWithReplacer", () => { + test("JSON.stringifyWithReplacer", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + JSON.stringifyWithReplacer(json, replacer) + // {"foo":"BAR","hello":"WORLD","someNumber":42} } () }) }) -describe("Belt.Set.Dict.fromArray", () => { - test("Belt.Set.Dict.fromArray", () => { +describe("JSON.stringifyWithReplacerAndIndent", () => { + test("JSON.stringifyWithReplacerAndIndent", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let json = + Dict.fromArray([ + ("foo", JSON.Encode.string("bar")), + ("hello", JSON.Encode.string("world")), + ("someNumber", JSON.Encode.int(42)), + ])->JSON.Encode.object - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) + let replacer = (_, value) => { + let decodedValue = value->JSON.Decode.string - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ + switch decodedValue { + | Some(string) => string->String.toUpperCase->JSON.Encode.string + | None => value + } + } + + JSON.stringifyWithReplacerAndIndent(json, replacer, 2) + // { + // "foo": "BAR", + // "hello": "WORLD", + // "someNumber": 42 + // } } () }) }) -describe("Belt.Set.Dict.mergeMany", () => { - test("Belt.Set.Dict.mergeMany", () => { +describe("List.add", () => { + test("List.add", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty + List.add(list{2, 3}, 1) // list{1, 2, 3} - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ + List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} } () }) }) -describe("Belt.Set.Dict.intersect", () => { - test("Belt.Set.Dict.intersect", () => { +describe("List.compare", () => { + test("List.compare", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ + List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. + List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. + List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. } () }) }) -describe("Belt.Set.Dict.partition", () => { - test("Belt.Set.Dict.partition", () => { +describe("List.compareLength", () => { + test("List.compareLength", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) + List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) + List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. -describe("Belt_Array.mapWithIndex", () => { - test("Belt_Array.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. } () }) }) -describe("String.fromCodePointMany", () => { - test("String.fromCodePointMany", () => { +describe("List.concat", () => { + test("List.concat", () => { module Test = { - String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` + List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} } () }) }) -describe("Pervasives.clearInterval", () => { - test("Pervasives.clearInterval", () => { +describe("List.concatMany", () => { + test("List.concatMany", () => { module Test = { - let intervalId = setInterval( - () => { - Console.log("This prints in 100 ms") - }, - 100, - ) - - // Stop the interval after 500 ms - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) + List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} } () }) }) -describe("Object.preventExtensions", () => { - test("Object.preventExtensions", () => { +describe("List.drop", () => { + test("List.drop", () => { module Test = { - let obj = {"a": 1} - obj->Object.set("b", 2) // succeeds - obj->Object.preventExtensions->ignore - try { - obj->Object.set("c", 3) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } + list{1, 2, 3}->List.drop(2) // Some(list{3}) + + list{1, 2, 3}->List.drop(3) // Some(list{}) + + list{1, 2, 3}->List.drop(4) // None } () }) }) -describe("JSON.parseExnWithReviver", () => { - test("JSON.parseExnWithReviver", () => { +describe("List.equal", () => { + test("List.equal", () => { module Test = { - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` + List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false - try { - JSON.parseExnWithReviver(jsonString, reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } + List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true - JSON.parseExnWithReviver("", reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } + List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true } () }) }) -describe("JSON.stringifyWithIndent", () => { - test("JSON.stringifyWithIndent", () => { +describe("List.every", () => { + test("List.every", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + let isBelow10 = value => value < 10 - JSON.stringifyWithIndent(json, 2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } + list{1, 9, 8, 2}->List.every(isBelow10) // true + + list{1, 99, 8, 2}->List.every(isBelow10) // false } () }) }) -describe("JSON.stringifyWithFilter", () => { - test("JSON.stringifyWithFilter", () => { +describe("List.every2", () => { + test("List.every2", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - JSON.stringifyWithFilter(json, ["foo", "someNumber"]) - // {"foo":"bar","someNumber":42} + List.every2(list{}, list{1}, (a, b) => a > b) // true + + List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false } () }) }) -describe("Int.toFixedWithPrecision", () => { - test("Int.toFixedWithPrecision", () => { +describe("List.filter", () => { + test("List.filter", () => { module Test = { - Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" - Int.toFixedWithPrecision(300, ~digits=1) // "300.0" + let isEven = x => mod(x, 2) == 0 + + List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} + + List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} } () }) }) -describe("Float.Constants.minValue", () => { - test("Float.Constants.minValue", () => { +describe("List.filterMap", () => { + test("List.filterMap", () => { module Test = { - Float.Constants.minValue + let isEven = x => mod(x, 2) == 0 + + list{1, 2, 3, 4}->List.filterMap( + x => + if isEven(x) { + Some(x) + } else { + None + }, + ) // list{2, 4} + + list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} } () }) }) -describe("Float.Constants.maxValue", () => { - test("Float.Constants.maxValue", () => { +describe("List.filterWithIndex", () => { + test("List.filterWithIndex", () => { module Test = { - Float.Constants.minValue + let isEven = x => mod(x, 2) == 0 + + List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} } () }) }) -describe("Date.UTC.makeWithYMDHMSM", () => { - test("Date.UTC.makeWithYMDHMSM", () => { +describe("List.find", () => { + test("List.find", () => { module Test = { - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - )->Console.log - // 1676911200000 - - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - )->Console.log - // 1676911201000 + List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=-1, - )->Console.log - // 1676911199999 + List.find(list{1, 4, 3, 2}, x => x > 4) // None } () }) }) -describe("Belt_internalMapInt.A.eq", () => { - test("Belt_internalMapInt.A.eq", () => { +describe("List.flat", () => { + test("List.flat", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} } () }) }) -describe("Belt_internalSetInt.A.eq", () => { - test("Belt_internalSetInt.A.eq", () => { +describe("List.forEach", () => { + test("List.forEach", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) + /* + prints: + Item: a + Item: b + Item: c +*/ } () }) }) -describe("Belt_Set.Dict.removeMany", () => { - test("Belt_Set.Dict.removeMany", () => { +describe("List.forEach2", () => { + test("List.forEach2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) + List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + /* + prints: + "Z" "A" + "Y" "B" +*/ } () }) }) -describe("Belt_MapDict.findFirstBy", () => { - test("Belt_MapDict.findFirstBy", () => { +describe("List.forEachWithIndex", () => { + test("List.forEachWithIndex", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + List.forEachWithIndex( + list{"a", "b", "c"}, + (x, index) => { + Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) + }, + ) + /* + prints: + Item 0 is a + Item 1 is b + Item 2 is cc +*/ + } + () + }) +}) - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) +describe("List.fromArray", () => { + test("List.fromArray", () => { + module Test = { + List.fromArray([1, 2, 3]) // list{1, 2, 3} } () }) }) -describe("Belt_Map.Int.findFirstBy", () => { - test("Belt_Map.Int.findFirstBy", () => { +describe("List.fromInitializer", () => { + test("List.fromInitializer", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) + List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} } () }) }) -describe("Belt_List.reduceReverse2", () => { - test("Belt_List.reduceReverse2", () => { +describe("List.get", () => { + test("List.get", () => { module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + let abc = list{"A", "B", "C"} + + abc->List.get(1) // Some("B") + + abc->List.get(4) // None } () }) }) -describe("Belt.Array.keepWithIndex", () => { - test("Belt.Array.keepWithIndex", () => { +describe("List.getAssoc", () => { + test("List.getAssoc", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") + + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( + 15, + (k, item) => k /* 15 */ == item /* 9, 5, 22 */, + ) + // Some("afternoon") } () }) }) -describe("Belt.Array.reduceReverse", () => { - test("Belt.Array.reduceReverse", () => { +describe("List.getExn", () => { + test("List.getExn", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + let abc = list{"A", "B", "C"} + + abc + ->List.getExn(1) + ->assertEqual("B") + + switch abc->List.getExn(4) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.List.reduceReverse2", () => { - test("Belt.List.reduceReverse2", () => { +describe("List.has", () => { + test("List.has", () => { module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ + list{1, 2, 3}->List.has(2, (a, b) => a == b) // true + + list{1, 2, 3}->List.has(4, (a, b) => a == b) // false + + list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true } () }) }) -describe("Belt.HashMap.keysToArray", () => { - test("Belt.HashMap.keysToArray", () => { +describe("List.hasAssoc", () => { + test("List.hasAssoc", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") + list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true - Belt.HashMap.keysToArray(s0) == [1, 2] + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( + 25, + (k, item) => k /* 25 */ == item /* 9, 5, 22 */, + ) // false } () }) }) -describe("Belt.Set.Dict.removeMany", () => { - test("Belt.Set.Dict.removeMany", () => { +describe("List.head", () => { + test("List.head", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ + List.head(list{}) // None + List.head(list{1, 2, 3}) // Some(1) } () }) }) -describe("Belt.Map.Int.findFirstBy", () => { - test("Belt.Map.Int.findFirstBy", () => { +describe("List.headExn", () => { + test("List.headExn", () => { module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) + List.headExn(list{1, 2, 3})->assertEqual(1) - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) + switch List.headExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_Array.keepWithIndex", () => { - test("Belt_Array.keepWithIndex", () => { +describe("List.length", () => { + test("List.length", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + List.length(list{1, 2, 3}) // 3 } () }) }) -describe("Belt_Array.reduceReverse", () => { - test("Belt_Array.reduceReverse", () => { +describe("List.make", () => { + test("List.make", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + List.make(~length=3, 1) // list{1, 1, 1} } () }) }) -describe("Belt_HashMap.keysToArray", () => { - test("Belt_HashMap.keysToArray", () => { +describe("List.map", () => { + test("List.map", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keysToArray(s0) == [1, 2] + list{1, 2}->List.map(x => x + 1) // list{3, 4} } () }) }) -describe("Array.findIndexWithIndex", () => { - test("Array.findIndexWithIndex", () => { +describe("List.mapReverse", () => { + test("List.mapReverse", () => { module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] + let f = x => x * x + let l = list{3, 4, 5} - let isReScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) - let isTypeScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) + let withMap = List.map(l, f)->List.reverse + let withMapReverse = l->List.mapReverse(f) - assertEqual(isReScriptFirst, 0) - assertEqual(isTypeScriptFirst, -1) + Console.log(withMap == withMapReverse) // true } () }) }) -describe("Belt_internalMapInt.A.get", () => { - test("Belt_internalMapInt.A.get", () => { +describe("List.mapReverse2", () => { + test("List.mapReverse2", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} } () }) }) -describe("Belt_internalMapInt.A.zip", () => { - test("Belt_internalMapInt.A.zip", () => { +describe("List.mapWithIndex", () => { + test("List.mapWithIndex", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} } () }) }) -describe("Belt_internalMapInt.A.map", () => { - test("Belt_internalMapInt.A.map", () => { +describe("List.partition", () => { + test("List.partition", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + // (elementsThatSatisfies, elementsThatDoesNotSatisfy) + + List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) } () }) }) -describe("Belt_internalMapInt.A.cmp", () => { - test("Belt_internalMapInt.A.cmp", () => { +describe("List.reduce", () => { + test("List.reduce", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + // same as - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 } () }) }) -describe("Belt_internalSetInt.A.get", () => { - test("Belt_internalSetInt.A.get", () => { +describe("List.reduce2", () => { + test("List.reduce2", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) } () }) }) -describe("Belt_internalSetInt.A.zip", () => { - test("Belt_internalSetInt.A.zip", () => { +describe("List.reduceReverse", () => { + test("List.reduceReverse", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 + + list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 + + list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} } () }) }) -describe("Belt_internalSetInt.A.map", () => { - test("Belt_internalSetInt.A.map", () => { +describe("List.reduceReverse2", () => { + test("List.reduceReverse2", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) } () }) }) -describe("Belt_internalSetInt.A.cmp", () => { - test("Belt_internalSetInt.A.cmp", () => { +describe("List.reduceWithIndex", () => { + test("List.reduceWithIndex", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 } () }) }) -describe("Belt_SetDict.minUndefined", () => { - test("Belt_SetDict.minUndefined", () => { +describe("List.removeAssoc", () => { + test("List.removeAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( + 9, + (k, item) => k /* 9 */ == item /* 9, 5, 22 */, + ) + // list{(15, "afternoon"), (22, "night")} } () }) }) -describe("Belt_SetDict.maxUndefined", () => { - test("Belt_SetDict.maxUndefined", () => { +describe("List.reverse", () => { + test("List.reverse", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) + List.reverse(list{1, 2, 3}) // list{3, 2, 1} + } + () + }) +}) - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ +describe("List.reverseConcat", () => { + test("List.reverseConcat", () => { + module Test = { + List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} } () }) }) -describe("Belt_MutableSet.fromArray", () => { - test("Belt_MutableSet.fromArray", () => { +describe("List.setAssoc", () => { + test("List.setAssoc", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ + list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( + 15, + "afternoon", + (a, b) => mod(a, 12) == mod(b, 12), + ) + // list{(9, "morning"), (15, "afternoon"), (22, "night")} + } + () + }) +}) + +describe("List.size", () => { + test("List.size", () => { + module Test = { + List.size(list{1, 2, 3}) // 3 } () }) }) -describe("Belt_MutableSet.mergeMany", () => { - test("Belt_MutableSet.mergeMany", () => { +describe("List.some", () => { + test("List.some", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let isAbove100 = value => value > 100 - let set = Belt.MutableSet.make(~id=module(IntCmp)) + list{101, 1, 2, 3}->List.some(isAbove100) // true - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + list{1, 2, 3, 4}->List.some(isAbove100) // false } () }) }) -describe("Belt_MutableSet.intersect", () => { - test("Belt_MutableSet.intersect", () => { +describe("List.some2", () => { + test("List.some2", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ + List.some2(list{}, list{1}, (a, b) => a > b) // false + + List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true + + List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true } () }) }) -describe("Belt_MutableSet.partition", () => { - test("Belt_MutableSet.partition", () => { +describe("List.sort", () => { + test("List.sort", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ + List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} } () }) }) -describe("Belt_Map.Dict.findFirstBy", () => { - test("Belt_Map.Dict.findFirstBy", () => { +describe("List.splitAt", () => { + test("List.splitAt", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) } () }) }) -describe("Belt_List.reduceWithIndex", () => { - test("Belt_List.reduceWithIndex", () => { +describe("List.tail", () => { + test("List.tail", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ + List.tail(list{1, 2, 3}) // Some(list{2, 3}) + + List.tail(list{}) // None } () }) }) -describe("Belt_List.filterWithIndex", () => { - test("Belt_List.filterWithIndex", () => { +describe("List.tailExn", () => { + test("List.tailExn", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + switch List.tailExn(list{}) { + | exception Not_found => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt.Array.reverseInPlace", () => { - test("Belt.Array.reverseInPlace", () => { +describe("List.take", () => { + test("List.take", () => { module Test = { - let arr = [10, 11, 12, 13, 14] + list{1, 2, 3}->List.take(1) // Some(list{1}) - let () = Belt.Array.reverseInPlace(arr) + list{1, 2, 3}->List.take(2) // Some(list{1, 2}) - arr == [14, 13, 12, 11, 10] + list{1, 2, 3}->List.take(4) // None } () }) }) -describe("Belt.Array.reduceReverse2", () => { - test("Belt.Array.reduceReverse2", () => { +describe("List.toArray", () => { + test("List.toArray", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + List.toArray(list{1, 2, 3}) // [1, 2, 3] } () }) }) -describe("Belt.List.reduceWithIndex", () => { - test("Belt.List.reduceWithIndex", () => { +describe("List.toShuffled", () => { + test("List.toShuffled", () => { module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ + List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} } () }) }) -describe("Belt.List.filterWithIndex", () => { - test("Belt.List.filterWithIndex", () => { +describe("List.unzip", () => { + test("List.unzip", () => { module Test = { - let isEven = x => mod(x, 2) == 0 + List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ + List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) + // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) } () }) }) -describe("Belt.MutableSet.fromArray", () => { - test("Belt.MutableSet.fromArray", () => { +describe("List.zip", () => { + test("List.zip", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) + List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} + } + () + }) +}) - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ +describe("List.zipBy", () => { + test("List.zipBy", () => { + module Test = { + List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} } () }) }) -describe("Belt.MutableSet.mergeMany", () => { - test("Belt.MutableSet.mergeMany", () => { +describe("Map.clear", () => { + test("Map.clear", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let map = Map.make() - let set = Belt.MutableSet.make(~id=module(IntCmp)) + map->Map.set("someKey", "someValue") + map->Map.size // 1 - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ + map->Map.clear + map->Map.size // 0 } () }) }) -describe("Belt.MutableSet.intersect", () => { - test("Belt.MutableSet.intersect", () => { +describe("Map.delete", () => { + test("Map.delete", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let map = Map.make() + map->Map.set("someKey", "someValue") + let didDeleteKey = map->Map.delete("someKey") + Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ + let didDeleteKey = map->Map.delete("someNonExistantKey") + Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist } () }) }) -describe("Belt.MutableSet.partition", () => { - test("Belt.MutableSet.partition", () => { +describe("Map.entries", () => { + test("Map.entries", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") - let isOdd = x => mod(x, 2) != 0 + let entries = map->Map.entries - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) + // Logs the first value + Console.log(Iterator.next(entries).value) - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ + // You can also turn the iterator into an array. + // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. + Console.log(map->Map.entries->Iterator.toArray) } () }) }) -describe("Belt.Map.Dict.findFirstBy", () => { - test("Belt.Map.Dict.findFirstBy", () => { +describe("Map.forEach", () => { + test("Map.forEach", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) + map->Map.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt_Array.reverseInPlace", () => { - test("Belt_Array.reverseInPlace", () => { +describe("Map.forEachWithKey", () => { + test("Map.forEachWithKey", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("someKey2", "someValue2") - arr == [14, 13, 12, 11, 10] + map->Map.forEachWithKey( + (value, key) => { + Console.log2(value, key) + }, + ) } () }) }) -describe("Belt_Array.reduceReverse2", () => { - test("Belt_Array.reduceReverse2", () => { +describe("Map.fromArray", () => { + test("Map.fromArray", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + type languages = ReScript | JavaScript | TypeScript + let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] + + let map = Map.fromArray(languageRank) // Map.t + + switch map->Map.get(ReScript) { + | Some(1) => Console.log("Yay, ReScript is #1!") + | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } } () }) }) -describe("String.splitByRegExpAtMost", () => { - test("String.splitByRegExpAtMost", () => { - module Test = { - String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ - Some("Hello"), - Some("World."), - Some("How"), - ] +describe("Map.fromIterator", () => { + test("Map.fromIterator", () => { + module Test = { + // Let's pretend we have an interator in the correct shape + let iterator: Iterator.t<(string, string)> = %raw(` + (() => { + var map1 = new Map(); + + map1.set('first', '1'); + map1.set('second', '2'); + + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })() +`) + + iterator + ->Map.fromIterator + ->Map.size + ->assertEqual(2) } () }) }) -describe("RegExp.fromStringWithFlags", () => { - test("RegExp.fromStringWithFlags", () => { +describe("Map.get", () => { + test("Map.get", () => { module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + let map = Map.make() + map->Map.set("someKey", "someValue") - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + switch map->Map.get("someKey") { + | None => Console.log("Nope, didn't have it.") + | Some(value) => Console.log2("Yay, had the value, and it's:", value) } } () }) }) -describe("Pervasives.setTimeoutFloat", () => { - test("Pervasives.setTimeoutFloat", () => { +describe("Map.has", () => { + test("Map.has", () => { module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeoutFloat( - () => { - Console.log("This prints in 200 ms.") - }, - 200., - ) + let map = Map.make() + map->Map.set("someKey", "someValue") + + switch map->Map.has("someKey") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") + } } () }) }) -describe("JSON.stringifyWithReplacer", () => { - test("JSON.stringifyWithReplacer", () => { +describe("Map.keys", () => { + test("Map.keys", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string + let keys = map->Map.keys - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } + // Logs the first key + Console.log(Iterator.next(keys).value) - JSON.stringifyWithReplacer(json, replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. + Console.log(map->Map.keys->Iterator.toArray) } () }) }) -describe("Iterator.toArrayWithMapper", () => { - test("Iterator.toArrayWithMapper", () => { +describe("Map.make", () => { + test("Map.make", () => { module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = - map - ->Map.keys - ->Iterator.toArrayWithMapper(key => key->String.length) + `make()` + // You can annotate the type of your map if you want to + let myMap: Map.t = Map.make() - Console.log(mapKeysAsArray) // Logs [7, 8] to the console. + // Or you can let ReScript infer what's in your map + let map = Map.make() + map->Map.set("lang", "ReScript") // Inferred as Map.t } () }) }) -describe("Float.toFixedWithPrecision", () => { - test("Float.toFixedWithPrecision", () => { +describe("Map.set", () => { + test("Map.set", () => { module Test = { - Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" - Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" + let map = Map.make() + map->Map.set("someKey", "someValue") } () }) }) -describe("Belt_internalMapInt.A.fill", () => { - test("Belt_internalMapInt.A.fill", () => { +describe("Map.size", () => { + test("Map.size", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] + let map = Map.make() - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + map->Map.set("someKey", "someValue") - arr == [0, 1, 9, 9, 4] + let size = map->Map.size // 1 } () }) }) -describe("Belt_internalMapInt.A.blit", () => { - test("Belt_internalMapInt.A.blit", () => { +describe("Map.values", () => { + test("Map.values", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + let map = Map.make() + map->Map.set("someKey", "someValue") + map->Map.set("anotherKey", "anotherValue") - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + let values = map->Map.values - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + // Logs the first value + Console.log(Iterator.next(values).value) + + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(map->Map.values->Iterator.toArray) } () }) }) -describe("Belt_internalMapInt.A.some", () => { - test("Belt_internalMapInt.A.some", () => { +describe("Math.Constants.e", () => { + test("Math.Constants.e", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + Math.Constants.e } () }) }) -describe("Belt_internalSetInt.A.fill", () => { - test("Belt_internalSetInt.A.fill", () => { +describe("Math.Constants.ln10", () => { + test("Math.Constants.ln10", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + Math.Constants.ln10 } () }) }) -describe("Belt_internalSetInt.A.blit", () => { - test("Belt_internalSetInt.A.blit", () => { +describe("Math.Constants.ln2", () => { + test("Math.Constants.ln2", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + Math.Constants.ln2 } () }) }) -describe("Belt_internalSetInt.A.some", () => { - test("Belt_internalSetInt.A.some", () => { +describe("Math.Constants.log10e", () => { + test("Math.Constants.log10e", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + Math.Constants.log10e } () }) }) -describe("Belt_Set.Dict.minUndefined", () => { - test("Belt_Set.Dict.minUndefined", () => { +describe("Math.Constants.log2e", () => { + test("Math.Constants.log2e", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + Math.Constants.log2e } () }) }) -describe("Belt_Set.Dict.maxUndefined", () => { - test("Belt_Set.Dict.maxUndefined", () => { +describe("Math.Constants.pi", () => { + test("Math.Constants.pi", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ + Math.Constants.pi } () }) }) -describe("Belt_Result.mapWithDefault", () => { - test("Belt_Result.mapWithDefault", () => { +describe("Math.Constants.sqrt1_2", () => { + test("Math.Constants.sqrt1_2", () => { module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + Math.Constants.sqrt1_2 } () }) }) -describe("Belt_Result.getWithDefault", () => { - test("Belt_Result.getWithDefault", () => { +describe("Math.Constants.sqrt2", () => { + test("Math.Constants.sqrt2", () => { module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 - - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + Math.Constants.sqrt2 } () }) }) -describe("Belt_Option.mapWithDefault", () => { - test("Belt_Option.mapWithDefault", () => { +describe("Math.Int.abs", () => { + test("Math.Int.abs", () => { module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + Math.Int.abs(-2) // 2 + Math.Int.abs(3) // 3 } () }) }) -describe("Belt_Option.getWithDefault", () => { - test("Belt_Option.getWithDefault", () => { - module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ +describe("Math.Int.ceil", () => { + test("Math.Int.ceil", () => { + module Test = { + Math.Int.ceil(3.7) == 4 + Math.Int.ceil(3.0) == 3 + Math.Int.ceil(-3.1) == -3 } () }) }) -describe("Belt_MutableSet.removeMany", () => { - test("Belt_MutableSet.removeMany", () => { +describe("Math.Int.clz32", () => { + test("Math.Int.clz32", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ + // 00000000000000000000000000000001 + Math.Int.clz32(1) // 31 + // 00000000000000000000000000000100 + Math.Int.clz32(4) // 29 } () }) }) -describe("Belt_MapString.findFirstBy", () => { - test("Belt_MapString.findFirstBy", () => { +describe("Math.Int.floor", () => { + test("Math.Int.floor", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + Math.Int.floor(3.7) == 3 + Math.Int.floor(3.0) == 3 + Math.Int.floor(-3.1) == -4 } () }) }) -describe("Belt_List.forEachWithIndex", () => { - test("Belt_List.forEachWithIndex", () => { +describe("Math.Int.imul", () => { + test("Math.Int.imul", () => { module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + Math.Int.imul(3, 4) // 12 + Math.Int.imul(-5, 12) // 60 } () }) }) -describe("Belt.Array.reduceWithIndex", () => { - test("Belt.Array.reduceWithIndex", () => { +describe("Math.Int.max", () => { + test("Math.Int.max", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Math.Int.max(1, 2) // 2 + Math.Int.max(-1, -2) // -1 } () }) }) -describe("Belt.List.forEachWithIndex", () => { - test("Belt.List.forEachWithIndex", () => { +describe("Math.Int.maxMany", () => { + test("Math.Int.maxMany", () => { module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ + Math.Int.maxMany([1, 2]) // 2 + Math.Int.maxMany([-1, -2]) // -1 + Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false } () }) }) -describe("Belt.MutableSet.removeMany", () => { - test("Belt.MutableSet.removeMany", () => { +describe("Math.Int.min", () => { + test("Math.Int.min", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ + Math.Int.min(1, 2) // 1 + Math.Int.min(-1, -2) // -2 } () }) }) -describe("Belt.HashMap.valuesToArray", () => { - test("Belt.HashMap.valuesToArray", () => { +describe("Math.Int.minMany", () => { + test("Math.Int.minMany", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + Math.Int.minMany([1, 2]) // 1 + Math.Int.minMany([-1, -2]) // -2 + Math.Int.minMany([])->Int.toFloat->Float.isFinite // false } () }) }) -describe("Belt.Option.mapWithDefault", () => { - test("Belt.Option.mapWithDefault", () => { +describe("Math.Int.pow", () => { + test("Math.Int.pow", () => { module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ + Math.Int.pow(2, ~exp=4) // 16 + Math.Int.pow(3, ~exp=4) // 81 } () }) }) -describe("Belt.Option.getWithDefault", () => { - test("Belt.Option.getWithDefault", () => { +describe("Math.Int.random", () => { + test("Math.Int.random", () => { module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ + Math.Int.random(2, 5) == 4 + Math.Int.random(505, 2000) == 1276 + Math.Int.random(-7, -2) == -4 } () }) }) -describe("Belt.Result.mapWithDefault", () => { - test("Belt.Result.mapWithDefault", () => { +describe("Math.Int.sign", () => { + test("Math.Int.sign", () => { module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 + Math.Int.sign(3) // 1 + Math.Int.sign(-3) // -1 + Math.Int.sign(0) // 0 } () }) }) -describe("Belt.Result.getWithDefault", () => { - test("Belt.Result.getWithDefault", () => { +describe("Math.abs", () => { + test("Math.abs", () => { module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 - - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 + Math.abs(-2.0) // 2.0 + Math.abs(3.0) // 3.0 } () }) }) -describe("Belt.Set.Dict.minUndefined", () => { - test("Belt.Set.Dict.minUndefined", () => { +describe("Math.acos", () => { + test("Math.acos", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ + Math.acos(-1.0) // 3.141592653589793 + Math.acos(-3.0)->Float.isNaN // true } () }) }) -describe("Belt.Set.Dict.maxUndefined", () => { - test("Belt.Set.Dict.maxUndefined", () => { +describe("Math.acosh", () => { + test("Math.acosh", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ + Math.acosh(1.0) // 0.0 + Math.acosh(0.5)->Float.isNaN // true } () }) }) -describe("Belt_Array.reduceWithIndex", () => { - test("Belt_Array.reduceWithIndex", () => { +describe("Math.asin", () => { + test("Math.asin", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + Math.asin(-1.0) // -1.5707963267948966 + Math.asin(-2.0)->Float.isNaN // true } () }) }) -describe("Belt_HashMap.valuesToArray", () => { - test("Belt_HashMap.valuesToArray", () => { +describe("Math.asinh", () => { + test("Math.asinh", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] + Math.asinh(-1.0) // -0.881373587019543 + Math.asinh(-0.0) // -0.0 } () }) }) -describe("Array.reduceRightWithIndex", () => { - test("Array.reduceRightWithIndex", () => { +describe("Math.atan", () => { + test("Math.atan", () => { module Test = { - Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) - - Array.reduceRightWithIndex( - [], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{}) + Math.atan(-0.0) // -0.0 + Math.atan(0.0) // 0.0 + Math.atan(1.0) // 0.7853981633974483 } () }) }) -describe("Pervasives.setIntervalFloat", () => { - test("Pervasives.setIntervalFloat", () => { +describe("Math.atan2", () => { + test("Math.atan2", () => { module Test = { - // Log to the console ever 2 seconds (200 milliseconds). - let intervalId = setIntervalFloat( - () => { - Console.log("This prints every 200 ms") - }, - 200., - ) - - // Stop the interval after 500 ms - let timeoutId = setTimeoutFloat( - () => { - clearInterval(intervalId) - }, - 500.0, - ) + Math.atan2(~y=0.0, ~x=10.0) == 0.0 + Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 + Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 + Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 + } + () + }) +}) + +describe("Math.atanh", () => { + test("Math.atanh", () => { + module Test = { + Math.atanh(-2.0)->Float.isNaN // true + Math.atanh(-1.0)->Float.isFinite // false + Math.atanh(-0.0) // -0.0 + Math.atanh(0.0) // 0.0 + Math.atanh(0.5) // 0.5493061443340548 } () }) }) -describe("JSON.stringifyAnyWithIndent", () => { - test("JSON.stringifyAnyWithIndent", () => { +describe("Math.cbrt", () => { + test("Math.cbrt", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithIndent(2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + Math.cbrt(-1.0) // -1.0 + Math.cbrt(-0.0) // -0.0 + Math.cbrt(0.0) // 0.0 } () }) }) -describe("JSON.stringifyAnyWithFilter", () => { - test("JSON.stringifyAnyWithFilter", () => { +describe("Math.ceil", () => { + test("Math.ceil", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + Math.ceil(3.1) == 4.0 + Math.ceil(3.0) == 3.0 + Math.ceil(-3.1) == -3.0 + Math.ceil(2_150_000_000.3) == 2_150_000_001.0 } () }) }) -describe("Belt_internalSetString.A.eq", () => { - test("Belt_internalSetString.A.eq", () => { +describe("Math.cos", () => { + test("Math.cos", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + Math.cos(-0.0) // 1.0 + Math.cos(0.0) // 1.0 + Math.cos(1.0) // 0.5403023058681398 } () }) }) -describe("Belt_internalMapString.A.eq", () => { - test("Belt_internalMapString.A.eq", () => { +describe("Math.cosh", () => { + test("Math.cosh", () => { module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true + Math.cosh(-1.0) // 1.5430806348152437 + Math.cosh(-0.0) // 1.0 + Math.cosh(0.0) // 1.0 } () }) }) -describe("Belt_internalMapInt.A.range", () => { - test("Belt_internalMapInt.A.range", () => { +describe("Math.exp", () => { + test("Math.exp", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] + Math.exp(-1.0) // 0.36787944117144233 + Math.exp(0.0) // 1.0 } () }) }) -describe("Belt_internalMapInt.A.zipBy", () => { - test("Belt_internalMapInt.A.zipBy", () => { +describe("Math.expm1", () => { + test("Math.expm1", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Math.expm1(-1.0) // -0.6321205588285577 + Math.expm1(-0.0) // -0 } () }) }) -describe("Belt_internalMapInt.A.unzip", () => { - test("Belt_internalMapInt.A.unzip", () => { +describe("Math.floor", () => { + test("Math.floor", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Math.floor(-45.95) // -46.0 + Math.floor(-45.05) // -46.0 + Math.floor(-0.0) // -0.0 } () }) }) -describe("Belt_internalMapInt.A.slice", () => { - test("Belt_internalMapInt.A.slice", () => { +describe("Math.fround", () => { + test("Math.fround", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + Math.fround(5.5) == 5.5 + Math.fround(5.05) == 5.050000190734863 } () }) }) -describe("Belt_internalMapInt.A.getBy", () => { - test("Belt_internalMapInt.A.getBy", () => { +describe("Math.hypot", () => { + test("Math.hypot", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + Math.hypot(3.0, 4.0) // 5.0 + Math.hypot(3.0, 5.0) // 5.8309518948453 } () }) }) -describe("Belt_internalMapInt.A.every", () => { - test("Belt_internalMapInt.A.every", () => { +describe("Math.hypotMany", () => { + test("Math.hypotMany", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false + Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 + Math.hypotMany([]) // 0.0 } () }) }) -describe("Belt_internalMapInt.A.some2", () => { - test("Belt_internalMapInt.A.some2", () => { +describe("Math.log", () => { + test("Math.log", () => { module Test = { - 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 + Math.log(-1.0)->Float.isNaN // true + Math.log(-0.0)->Float.isFinite // false + Math.log(0.0)->Float.isFinite // false + Math.log(1.0) // 0 } () }) }) -describe("Belt_internalSetInt.A.range", () => { - test("Belt_internalSetInt.A.range", () => { +describe("Math.log10", () => { + test("Math.log10", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] + Math.log10(-2.0)->Float.isNaN // true + Math.log10(-0.0)->Float.isFinite // false + Math.log10(0.0)->Float.isFinite // false + Math.log10(1.0) // 0 } () }) }) -describe("Belt_internalSetInt.A.zipBy", () => { - test("Belt_internalSetInt.A.zipBy", () => { +describe("Math.log1p", () => { + test("Math.log1p", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Math.log1p(-2.0)->Float.isNaN // true + Math.log1p(-1.0)->Float.isFinite // false + Math.log1p(-0.0) // -0 } () }) }) -describe("Belt_internalSetInt.A.unzip", () => { - test("Belt_internalSetInt.A.unzip", () => { +describe("Math.log2", () => { + test("Math.log2", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Math.log2(-2.0)->Float.isNaN // true + Math.log2(-0.0)->Float.isFinite // false + Math.log2(0.0)->Float.isFinite // false + Math.log2(1.0) // 0.0 } () }) }) -describe("Belt_internalSetInt.A.slice", () => { - test("Belt_internalSetInt.A.slice", () => { +describe("Math.max", () => { + test("Math.max", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + Math.max(1.0, 2.0) // 2.0 + Math.max(-1.0, -2.0) // -1.0 } () }) }) -describe("Belt_internalSetInt.A.getBy", () => { - test("Belt_internalSetInt.A.getBy", () => { +describe("Math.maxMany", () => { + test("Math.maxMany", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + Math.maxMany([1.0, 2.0]) // 2.0 + Math.maxMany([-1.0, -2.0]) // -1.0 + Math.maxMany([])->Float.isFinite // false } () }) }) -describe("Belt_internalSetInt.A.every", () => { - test("Belt_internalSetInt.A.every", () => { +describe("Math.min", () => { + test("Math.min", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false + Math.min(1.0, 2.0) // 1.0 + Math.min(-1.0, -2.0) // -2.0 } () }) }) -describe("Belt_internalSetInt.A.some2", () => { - test("Belt_internalSetInt.A.some2", () => { +describe("Math.minMany", () => { + test("Math.minMany", () => { module Test = { - 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 + Math.minMany([1.0, 2.0]) // 1.0 + Math.minMany([-1.0, -2.0]) // -2.0 + Math.minMany([])->Float.isFinite // false } () }) }) -describe("Belt_Map.String.findFirstBy", () => { - test("Belt_Map.String.findFirstBy", () => { +describe("Math.pow", () => { + test("Math.pow", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + Math.pow(2.0, ~exp=4.0) // 16.0 + Math.pow(3.0, ~exp=4.0) // 81.0 } () }) }) -describe("Belt.Array.forEachWithIndex", () => { - test("Belt.Array.forEachWithIndex", () => { +describe("Math.random", () => { + test("Math.random", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) + Math.random() + } + () + }) +}) - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 +describe("Math.round", () => { + test("Math.round", () => { + module Test = { + Math.round(-20.5) // -20.0 + Math.round(-0.1) // -0.0 + Math.round(0.0) // 0.0 + Math.round(-0.0) // -0.0 } () }) }) -describe("Belt.HashMap.keepMapInPlace", () => { - test("Belt.HashMap.keepMapInPlace", () => { +describe("Math.sign", () => { + test("Math.sign", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + Math.sign(3.0) // 1.0 + Math.sign(-3.0) // 1.0 + Math.sign(0.0) // 0.0 } () }) }) -describe("Belt.Map.String.findFirstBy", () => { - test("Belt.Map.String.findFirstBy", () => { +describe("Math.sin", () => { + test("Math.sin", () => { module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) + Math.sin(-0.0) // -0.0 + Math.sin(0.0) // 0.0 + Math.sin(1.0) // 0.8414709848078965 } () }) }) -describe("Belt_Array.forEachWithIndex", () => { - test("Belt_Array.forEachWithIndex", () => { +describe("Math.sinh", () => { + test("Math.sinh", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + Math.sinh(-0.0) // -0.0 + Math.sinh(0.0) // 0.0 + Math.sinh(1.0) // 1.1752011936438014 } () }) }) -describe("Belt_HashMap.keepMapInPlace", () => { - test("Belt_HashMap.keepMapInPlace", () => { +describe("Math.sqrt", () => { + test("Math.sqrt", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) + Math.sqrt(-1.0)->Float.isNaN // true + Math.sqrt(-0.0) // -0.0 + Math.sqrt(0.0) // 0.0 + Math.sqrt(1.0) // 1.0 + Math.sqrt(9.0) // 3.0 } () }) }) -describe("Int.toPrecisionWithPrecision", () => { - test("Int.toPrecisionWithPrecision", () => { +describe("Math.tan", () => { + test("Math.tan", () => { module Test = { - Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" + Math.tan(-0.0) // -0.0 + Math.tan(0.0) // 0.0 + Math.tan(1.0) // 1.5574077246549023 } () }) }) -describe("Belt_internalSetString.A.get", () => { - test("Belt_internalSetString.A.get", () => { +describe("Math.tanh", () => { + test("Math.tanh", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + Math.tanh(-0.0) // -0.0 + Math.tanh(0.0) // 0.0 + Math.tanh(1.0) // 0.7615941559557649 } () }) }) -describe("Belt_internalSetString.A.zip", () => { - test("Belt_internalSetString.A.zip", () => { +describe("Math.trunc", () => { + test("Math.trunc", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + Math.trunc(0.123) // 0.0 + Math.trunc(1.999) // 1.0 + Math.trunc(13.37) // 13.0 + Math.trunc(42.84) // 42.0 } () }) }) -describe("Belt_internalSetString.A.map", () => { - test("Belt_internalSetString.A.map", () => { +describe("Null.asNullable", () => { + test("Null.asNullable", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + let nullValue = Null.make("Hello") + let asNullable = nullValue->Null.asNullable // Nullable.t } () }) }) -describe("Belt_internalSetString.A.cmp", () => { - test("Belt_internalSetString.A.cmp", () => { +describe("Null.flatMap", () => { + test("Null.flatMap", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + let addIfAboveOne = value => + if value > 1 { + Null.make(value + 1) + } else { + Null.null + } - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) + Null.flatMap(Null.make(-4), addIfAboveOne) // null + Null.flatMap(Null.null, addIfAboveOne) // null } () }) }) -describe("Belt_internalMapString.A.get", () => { - test("Belt_internalMapString.A.get", () => { +describe("Null.forEach", () => { + test("Null.forEach", () => { module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None + Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" + Null.forEach(Null.null, x => Console.log(x)) // logs nothing } () }) }) -describe("Belt_internalMapString.A.zip", () => { - test("Belt_internalMapString.A.zip", () => { +describe("Null.fromOption", () => { + test("Null.fromOption", () => { module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] + let optString: option = None + let asNull = optString->Null.fromOption // Null.t + Console.log(asNull == Null.null) // Logs `true` to the console. } () }) }) -describe("Belt_internalMapString.A.map", () => { - test("Belt_internalMapString.A.map", () => { +describe("Null.getExn", () => { + test("Null.getExn", () => { module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] + Null.getExn(Null.make(3))->assertEqual(3) + + switch Null.getExn(%raw("'ReScript'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "ReScript") + } + + switch Null.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapString.A.cmp", () => { - test("Belt_internalMapString.A.cmp", () => { +describe("Null.getOr", () => { + test("Null.getOr", () => { module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 + Null.getOr(Null.null, "Banana") // Banana + Null.getOr(Null.make("Apple"), "Banana") // Apple - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 + Null.make("Jane")->Null.toOption->greet // "Greetings Jane" + Null.null->Null.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Belt_internalMapInt.A.length", () => { - test("Belt_internalMapInt.A.length", () => { +describe("Null.getUnsafe", () => { + test("Null.getUnsafe", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + Null.getUnsafe(Null.make(3)) == 3 + Null.getUnsafe(Null.null) // Raises an error } () }) }) -describe("Belt_internalMapInt.A.makeBy", () => { - test("Belt_internalMapInt.A.makeBy", () => { +describe("Null.make", () => { + test("Null.make", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + let myStr = "Hello" + let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. } () }) }) -describe("Belt_internalMapInt.A.concat", () => { - test("Belt_internalMapInt.A.concat", () => { +describe("Null.map", () => { + test("Null.map", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + Null.map(Null.make(3), x => x * x) // Null.make(9) + Null.map(Null.null, x => x * x) // null } () }) }) -describe("Belt_internalMapInt.A.reduce", () => { - test("Belt_internalMapInt.A.reduce", () => { +describe("Null.mapOr", () => { + test("Null.mapOr", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + let someValue = Null.make(3) + someValue->Null.mapOr(0, x => x + 5) // 8 - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + let noneValue = Null.null + noneValue->Null.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Belt_internalMapInt.A.every2", () => { - test("Belt_internalMapInt.A.every2", () => { +describe("Null.null", () => { + test("Null.null", () => { module Test = { - 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 + Console.log(null) // Logs `null` to the console. } () }) }) -describe("Belt_internalSetInt.A.length", () => { - test("Belt_internalSetInt.A.length", () => { +describe("Null.toOption", () => { + test("Null.toOption", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + let nullStr = Null.make("Hello") + + switch nullStr->Null.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") + } } () }) }) -describe("Belt_internalSetInt.A.makeBy", () => { - test("Belt_internalSetInt.A.makeBy", () => { +describe("Nullable.flatMap", () => { + test("Nullable.flatMap", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + let addIfAboveOne = value => + if value > 1 { + Nullable.make(value + 1) + } else { + Nullable.null + } - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) + Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined + Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined } () }) }) -describe("Belt_internalSetInt.A.concat", () => { - test("Belt_internalSetInt.A.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] +describe("Nullable.forEach", () => { + test("Nullable.forEach", () => { + module Test = { + Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" + Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () + Nullable.forEach(undefined, x => Console.log(x)) // returns () } () }) }) -describe("Belt_internalSetInt.A.reduce", () => { - test("Belt_internalSetInt.A.reduce", () => { +describe("Nullable.fromOption", () => { + test("Nullable.fromOption", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + let optString = Some("Hello") + let asNullable = optString->Nullable.fromOption // Nullable.t } () }) }) -describe("Belt_internalSetInt.A.every2", () => { - test("Belt_internalSetInt.A.every2", () => { +describe("Nullable.getExn", () => { + test("Nullable.getExn", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true - - Belt.Array.every2([], [1], (x, y) => x > y) == true + switch Nullable.getExn(%raw("'Hello'")) { + | exception Invalid_argument(_) => assert(false) + | value => assertEqual(value, "Hello") + } - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + switch Nullable.getExn(%raw("null")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + switch Nullable.getExn(%raw("undefined")) { + | exception Invalid_argument(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_MutableSet.minUndefined", () => { - test("Belt_MutableSet.minUndefined", () => { +describe("Nullable.getOr", () => { + test("Nullable.getOr", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + Nullable.getOr(Nullable.null, "Banana") // Banana + Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ + Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" + Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" } () }) }) -describe("Belt_MutableSet.maxUndefined", () => { - test("Belt_MutableSet.maxUndefined", () => { +describe("Nullable.getUnsafe", () => { + test("Nullable.getUnsafe", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ + Nullable.getUnsafe(Nullable.make(3)) == 3 + Nullable.getUnsafe(Nullable.null) // Raises an error } () }) }) -describe("Belt.Array.makeUninitialized", () => { - test("Belt.Array.makeUninitialized", () => { +describe("Nullable.isNullable", () => { + test("Nullable.isNullable", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + let myStr = "Hello" + let asNullable = myStr->Nullable.make - Belt.Array.getExn(arr, 0) == Js.undefined + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable + + // Check if asNullable is not null or undefined + switch asNullable->Nullable.isNullable { + | true => assert(false) + | false => assert(true) + } } () }) }) -describe("Belt.MutableSet.minUndefined", () => { - test("Belt.MutableSet.minUndefined", () => { +describe("Nullable.make", () => { + test("Nullable.make", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) + let myStr = "Hello" + let asNullable = myStr->Nullable.make - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) + // Can't do the below because we're now forced to check for nullability + // myStr == asNullable - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ + // Need to do this + switch asNullable->Nullable.toOption { + | Some(value) if value == myStr => Console.log("Yay, values matched!") + | _ => Console.log("Values did not match.") + } } () }) }) -describe("Belt.MutableSet.maxUndefined", () => { - test("Belt.MutableSet.maxUndefined", () => { +describe("Nullable.map", () => { + test("Nullable.map", () => { module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ + Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) + Nullable.map(undefined, x => x * x) // undefined } () }) }) -describe("Belt_Array.makeUninitialized", () => { - test("Belt_Array.makeUninitialized", () => { +describe("Nullable.mapOr", () => { + test("Nullable.mapOr", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) + let someValue = Nullable.make(3) + someValue->Nullable.mapOr(0, x => x + 5) // 8 - Belt.Array.getExn(arr, 0) == Js.undefined + let noneValue = Nullable.null + noneValue->Nullable.mapOr(0, x => x + 5) // 0 } () }) }) -describe("String.unsafeReplaceRegExpBy0", () => { - test("String.unsafeReplaceRegExpBy0", () => { +describe("Nullable.null", () => { + test("Nullable.null", () => { module Test = { - let str = "beautiful vowels" - let re = /[aeiou]/g - let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) - String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" + Console.log(Nullable.null) // Logs `null` to the console. } () }) }) -describe("String.unsafeReplaceRegExpBy1", () => { - test("String.unsafeReplaceRegExpBy1", () => { +describe("Nullable.toOption", () => { + test("Nullable.toOption", () => { module Test = { - let str = "Jony is 40" - let re = /(Jony is )\d+/g - let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { - group1 ++ "41" + let nullableString = Nullable.make("Hello") + + switch nullableString->Nullable.toOption { + | Some(str) => Console.log2("Got string:", str) + | None => Console.log("Didn't have a value.") } - String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" } () }) }) -describe("String.unsafeReplaceRegExpBy2", () => { - test("String.unsafeReplaceRegExpBy2", () => { +describe("Nullable.undefined", () => { + test("Nullable.undefined", () => { module Test = { - let str = "7 times 6" - let re = /(\d+) times (\d+)/ - let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { - switch (Int.fromString(group1), Int.fromString(group2)) { - | (Some(x), Some(y)) => Int.toString(x * y) - | _ => "???" - } - } - String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" + Console.log(undefined) // Logs `undefined` to the console. } () }) }) -describe("Pervasives.encodeURIComponent", () => { - test("Pervasives.encodeURIComponent", () => { +describe("Object.assign", () => { + test("Object.assign", () => { module Test = { - Console.log(encodeURIComponent("array=[someValue]")) - // Logs "array%3D%5BsomeValue%5D" to the console. + Object.assign({"a": 1}, {"a": 2}) // {"a": 2} + Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} + Object.assign({"a": 1}, {"a": null}) // {"a": null} } () }) }) -describe("Pervasives.decodeURIComponent", () => { - test("Pervasives.decodeURIComponent", () => { +describe("Object.create", () => { + test("Object.create", () => { module Test = { - Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) - // Logs "array=[someValue]" to the console. + let x = {"fruit": "banana"} + let y = Object.create(x) + y->Object.get("fruit") // Some("banana") } () }) }) -describe("JSON.stringifyAnyWithReplacer", () => { - test("JSON.stringifyAnyWithReplacer", () => { +describe("Object.freeze", () => { + test("Object.freeze", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) + let obj = {"a": 1} + obj->Object.set("a", 2) // succeeds + obj->Object.freeze->ignore - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) + try { + obj->Object.set("a", 3) // fails + } catch { + | Exn.Error(_) => assert(true) | _ => assert(false) } } @@ -16487,1824 +16316,1995 @@ describe("JSON.stringifyAnyWithReplacer", () => { }) }) -describe("Date.toLocaleStringWithLocale", () => { - test("Date.toLocaleStringWithLocale", () => { +describe("Object.get", () => { + test("Object.get", () => { module Test = { - Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log - // 2/19/2023, 3:40:00 PM + {"a": 1}->Object.get("a") // Some(1) + {"a": 1}->Object.get("b") // None + {"a": undefined}->Object.get("a") // None + {"a": null}->Object.get("a") // Some(null) + {"a": 1}->Object.get("toString")->Option.isSome // true } () }) }) -describe("Belt_internalSetString.A.fill", () => { - test("Belt_internalSetString.A.fill", () => { +describe("Object.getSymbol", () => { + test("Object.getSymbol", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) + let fruit = Symbol.make("fruit") + let x = Object.make() + x->Object.setSymbol(fruit, "banana") + x->Object.getSymbol(fruit) // Some("banana") + } + () + }) +}) - arr == [0, 1, 9, 9, 4] +describe("Object.hasOwnProperty", () => { + test("Object.hasOwnProperty", () => { + module Test = { + let point = {"x": 1, "y": 2} + {"a": 1}->Object.hasOwnProperty("a") // true + {"a": 1}->Object.hasOwnProperty("b") // false + {"a": 1}->Object.hasOwnProperty("toString") // false } () }) }) -describe("Belt_internalSetString.A.blit", () => { - test("Belt_internalSetString.A.blit", () => { +describe("Object.is", () => { + test("Object.is", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] + Object.is(25, 13) // false + Object.is("abc", "abc") // true + Object.is(undefined, undefined) // true + Object.is(undefined, null) // false + Object.is(-0.0, 0.0) // false + Object.is(list{1, 2}, list{1, 2}) // false - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] + Object.is([1, 2, 3], [1, 2, 3]) // false + [1, 2, 3] == [1, 2, 3] // true + [1, 2, 3] === [1, 2, 3] // false - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + let fruit = {"name": "Apple"} + Object.is(fruit, fruit) // true + Object.is(fruit, {"name": "Apple"}) // false + fruit == {"name": "Apple"} // true + fruit === {"name": "Apple"} // false } () }) }) -describe("Belt_internalSetString.A.some", () => { - test("Belt_internalSetString.A.some", () => { +describe("Object.isExtensible", () => { + test("Object.isExtensible", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + let obj = {"a": 1} + obj->Object.isExtensible // true + obj->Object.preventExtensions->ignore + obj->Object.isExtensible // false } () }) }) -describe("Belt_internalMapString.A.fill", () => { - test("Belt_internalMapString.A.fill", () => { +describe("Object.isFrozen", () => { + test("Object.isFrozen", () => { module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] + let point = {"x": 1, "y": 3}->Object.freeze + let pointIsFrozen = point->Object.isFrozen // true + let fruit = {"name": "Apple"} + let fruitIsFrozen = fruit->Object.isFrozen // false } () }) }) -describe("Belt_internalMapString.A.blit", () => { - test("Belt_internalMapString.A.blit", () => { +describe("Object.isSealed", () => { + test("Object.isSealed", () => { module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] + let point = {"x": 1, "y": 3}->Object.seal + let pointIsSealed = point->Object.isSealed // true + let fruit = {"name": "Apple"} + let fruitIsSealed = fruit->Object.isSealed // false } () }) }) -describe("Belt_internalMapString.A.some", () => { - test("Belt_internalMapString.A.some", () => { +describe("Object.keysToArray", () => { + test("Object.keysToArray", () => { module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false + {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] + {"a": None}->Object.keysToArray // ["a"] + Object.make()->Object.keysToArray // [] } () }) }) -describe("Belt_internalMapInt.A.reverse", () => { - test("Belt_internalMapInt.A.reverse", () => { +describe("Object.make", () => { + test("Object.make", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + let x = Object.make() + x->Object.keysToArray->Array.length // 0 + x->Object.get("toString")->Option.isSome // true } () }) }) -describe("Belt_internalMapInt.A.rangeBy", () => { - test("Belt_internalMapInt.A.rangeBy", () => { +describe("Object.preventExtensions", () => { + test("Object.preventExtensions", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + let obj = {"a": 1} + obj->Object.set("b", 2) // succeeds + obj->Object.preventExtensions->ignore + try { + obj->Object.set("c", 3) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } } () }) }) -describe("Belt_internalMapInt.A.forEach", () => { - test("Belt_internalMapInt.A.forEach", () => { +describe("Object.seal", () => { + test("Object.seal", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + let point = {"x": 1, "y": 2} + point->Object.set("x", -7) // succeeds + point->Object.seal->ignore - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) + try { + point->Object.set("z", 9) // fails + } catch { + | Exn.Error(_) => assert(true) + | _ => assert(false) + } -describe("Belt_internalMapInt.A.flatMap", () => { - test("Belt_internalMapInt.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + point->Object.set("x", 13) // succeeds } () }) }) -describe("Belt_internalMapInt.A.keepMap", () => { - test("Belt_internalMapInt.A.keepMap", () => { +describe("Object.set", () => { + test("Object.set", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + {"a": 1}->Object.set("a", 2) // {"a": 2} + {"a": 1}->Object.set("a", None) // {"a": None} + {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} } () }) }) -describe("Belt_internalSetInt.A.reverse", () => { - test("Belt_internalSetInt.A.reverse", () => { +describe("Option.all", () => { + test("Option.all", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) + Option.all([Some(1), None]) // None } () }) }) -describe("Belt_internalSetInt.A.rangeBy", () => { - test("Belt_internalSetInt.A.rangeBy", () => { +describe("Option.compare", () => { + test("Option.compare", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] + let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + Option.compare(Some(3), Some(15), clockCompare) // 0. + Option.compare(Some(3), Some(14), clockCompare) // 1. + Option.compare(Some(2), Some(15), clockCompare) // (-1.) + Option.compare(None, Some(15), clockCompare) // (-1.) + Option.compare(Some(14), None, clockCompare) // 1. + Option.compare(None, None, clockCompare) // 0. } () }) }) -describe("Belt_internalSetInt.A.forEach", () => { - test("Belt_internalSetInt.A.forEach", () => { +describe("Option.equal", () => { + test("Option.equal", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) + let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + open Option - total.contents == 1 + 2 + 3 + 4 + equal(Some(3), Some(15), clockEqual) // true + equal(Some(3), None, clockEqual) // false + equal(None, Some(3), clockEqual) // false + equal(None, None, clockEqual) // true } () }) }) -describe("Belt_internalSetInt.A.flatMap", () => { - test("Belt_internalSetInt.A.flatMap", () => { +describe("Option.filter", () => { + test("Option.filter", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + Option.filter(Some(10), x => x > 5) // Some(10) + Option.filter(Some(4), x => x > 5) // None + Option.filter(None, x => x > 5) // None } () }) }) -describe("Belt_internalSetInt.A.keepMap", () => { - test("Belt_internalSetInt.A.keepMap", () => { +describe("Option.flatMap", () => { + test("Option.flatMap", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + let addIfAboveOne = value => + if value > 1 { + Some(value + 1) + } else { + None + } + + Option.flatMap(Some(2), addIfAboveOne) // Some(3) + Option.flatMap(Some(-4), addIfAboveOne) // None + Option.flatMap(None, addIfAboveOne) // None } () }) }) -describe("Belt_SortArray.binarySearchBy", () => { - test("Belt_SortArray.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 +describe("Option.forEach", () => { + test("Option.forEach", () => { + module Test = { + Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" + Option.forEach(None, x => Console.log(x)) // returns () } () }) }) -describe("Belt.SortArray.binarySearchBy", () => { - test("Belt.SortArray.binarySearchBy", () => { +describe("Option.getExn", () => { + test("Option.getExn", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 + Option.getExn(Some(3))->assertEqual(3) - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + switch Option.getExn(None) { + | exception _ => assert(true) + | _ => assert(false) + } + + switch Option.getExn(None, ~message="was None!") { + | exception _ => assert(true) // Raises an Error with the message "was None!" + | _ => assert(false) + } } () }) }) -describe("Int.toExponentialWithPrecision", () => { - test("Int.toExponentialWithPrecision", () => { +describe("Option.getOr", () => { + test("Option.getOr", () => { module Test = { - Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" - Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" + Option.getOr(None, "Banana") // Banana + Option.getOr(Some("Apple"), "Banana") // Apple + + let greet = (firstName: option) => + "Greetings " ++ firstName->Option.getOr("Anonymous") + + Some("Jane")->greet // "Greetings Jane" + None->greet // "Greetings Anonymous" } () }) }) -describe("Float.toPrecisionWithPrecision", () => { - test("Float.toPrecisionWithPrecision", () => { +describe("Option.getUnsafe", () => { + test("Option.getUnsafe", () => { module Test = { - Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" + Option.getUnsafe(Some(3)) == 3 + Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` } () }) }) -describe("Belt_internalSetString.A.range", () => { - test("Belt_internalSetString.A.range", () => { +describe("Option.isNone", () => { + test("Option.isNone", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] + Option.isNone(None) // true + Option.isNone(Some(1)) // false } () }) }) -describe("Belt_internalSetString.A.zipBy", () => { - test("Belt_internalSetString.A.zipBy", () => { +describe("Option.isSome", () => { + test("Option.isSome", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Option.isSome(None) // false + Option.isSome(Some(1)) // true } () }) }) -describe("Belt_internalSetString.A.unzip", () => { - test("Belt_internalSetString.A.unzip", () => { +describe("Option.map", () => { + test("Option.map", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Option.map(Some(3), x => x * x) // Some(9) + Option.map(None, x => x * x) // None } () }) }) -describe("Belt_internalSetString.A.slice", () => { - test("Belt_internalSetString.A.slice", () => { +describe("Option.mapOr", () => { + test("Option.mapOr", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] + let someValue = Some(3) + someValue->Option.mapOr(0, x => x + 5) // 8 - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + let noneValue = None + noneValue->Option.mapOr(0, x => x + 5) // 0 } () }) }) -describe("Belt_internalSetString.A.getBy", () => { - test("Belt_internalSetString.A.getBy", () => { +describe("Option.orElse", () => { + test("Option.orElse", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + Option.orElse(Some(1812), Some(1066)) == Some(1812) + Option.orElse(None, Some(1066)) == Some(1066) + Option.orElse(None, None) == None } () }) }) -describe("Belt_internalSetString.A.every", () => { - test("Belt_internalSetString.A.every", () => { +describe("Pervasives.assertEqual", () => { + test("Pervasives.assertEqual", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false + list{1, 2} + ->List.tailExn + ->assertEqual(list{2}) } () }) }) -describe("Belt_internalSetString.A.some2", () => { - test("Belt_internalSetString.A.some2", () => { +describe("Pervasives.clearInterval", () => { + test("Pervasives.clearInterval", () => { module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - - Belt.Array.some2([], [1], (x, y) => x > y) == false + let intervalId = setInterval( + () => { + Console.log("This prints in 100 ms") + }, + 100, + ) - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + // Stop the interval after 500 ms + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) + }, + 500, + ) } () }) }) -describe("Belt_internalMapString.A.range", () => { - test("Belt_internalMapString.A.range", () => { +describe("Pervasives.clearTimeout", () => { + test("Pervasives.clearTimeout", () => { module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] + let timeoutId = setTimeout( + () => { + Console.log("This prints in 2 seconds.") + }, + 2000, + ) - Belt.Array.range(3, 3) == [3] + // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. + clearTimeout(timeoutId) } () }) }) -describe("Belt_internalMapString.A.zipBy", () => { - test("Belt_internalMapString.A.zipBy", () => { +describe("Pervasives.decodeURI", () => { + test("Pervasives.decodeURI", () => { module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] + Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) + // Logs "https://rescript-lang.org?array=[someValue]" to the console. } () }) }) -describe("Belt_internalMapString.A.unzip", () => { - test("Belt_internalMapString.A.unzip", () => { +describe("Pervasives.decodeURIComponent", () => { + test("Pervasives.decodeURIComponent", () => { module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) + Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) + // Logs "array=[someValue]" to the console. } () }) }) -describe("Belt_internalMapString.A.slice", () => { - test("Belt_internalMapString.A.slice", () => { +describe("Pervasives.encodeURI", () => { + test("Pervasives.encodeURI", () => { module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] + Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) + // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. } () }) }) -describe("Belt_internalMapString.A.getBy", () => { - test("Belt_internalMapString.A.getBy", () => { +describe("Pervasives.encodeURIComponent", () => { + test("Pervasives.encodeURIComponent", () => { module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None + Console.log(encodeURIComponent("array=[someValue]")) + // Logs "array%3D%5BsomeValue%5D" to the console. } () }) }) -describe("Belt_internalMapString.A.every", () => { - test("Belt_internalMapString.A.every", () => { +describe("Pervasives.import", () => { + test("Pervasives.import", () => { module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true + @send external indexOf: (array<'a>, 'a) => int = "indexOf" - Belt.Array.every([1, -3, 5], x => x > 0) == false + let indexOfOpt = (arr, item) => + switch arr->indexOf(item) { + | -1 => None + | index => Some(index) + } + + let main = async () => { + let indexOfOpt = await import(Array.indexOfOpt) + let index = indexOfOpt([1, 2], 2) + Console.log(index) + } } () }) }) -describe("Belt_internalMapString.A.some2", () => { - test("Belt_internalMapString.A.some2", () => { +describe("Pervasives.setInterval", () => { + test("Pervasives.setInterval", () => { module Test = { - Belt.Array.some2([0, 2], [1, 0, 3], (a, b) => a > b) == true - - Belt.Array.some2([], [1], (x, y) => x > y) == false + // Log to the console ever 200 ms (200 milliseconds). + let intervalId = setInterval( + () => { + Console.log("This prints every 200 ms.") + }, + 200, + ) - Belt.Array.some2([2, 3], [1, 4], (x, y) => x > y) == true + let timeoutId = setTimeout( + () => { + clearInterval(intervalId) + }, + 500, + ) } () }) }) -describe("Belt_internalMapInt.A.joinWith", () => { - test("Belt_internalMapInt.A.joinWith", () => { +describe("Pervasives.setIntervalFloat", () => { + test("Pervasives.setIntervalFloat", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + // Log to the console ever 2 seconds (200 milliseconds). + let intervalId = setIntervalFloat( + () => { + Console.log("This prints every 200 ms") + }, + 200., + ) + + // Stop the interval after 500 ms + let timeoutId = setTimeoutFloat( + () => { + clearInterval(intervalId) + }, + 500.0, + ) } () }) }) -describe("Belt_internalSetInt.A.joinWith", () => { - test("Belt_internalSetInt.A.joinWith", () => { +describe("Pervasives.setTimeout", () => { + test("Pervasives.setTimeout", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + // Log to the console after 200 milliseconds. + let timeoutId = setTimeout( + () => { + Console.log("This prints in 200 ms.") + }, + 200, + ) } () }) }) -describe("Belt_internalSetString.A.length", () => { - test("Belt_internalSetString.A.length", () => { +describe("Pervasives.setTimeoutFloat", () => { + test("Pervasives.setTimeoutFloat", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + // Log to the console after 200 milliseconds. + let timeoutId = setTimeoutFloat( + () => { + Console.log("This prints in 200 ms.") + }, + 200., + ) } () }) }) -describe("Belt_internalSetString.A.makeBy", () => { - test("Belt_internalSetString.A.makeBy", () => { +describe("Promise.all", () => { + test("Promise.all", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + open Promise + let promises = [resolve(1), resolve(2), resolve(3)] - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + all(promises) + ->then( + results => { + results->Array.forEach( + num => { + Console.log2("Number: ", num) + }, + ) + + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalSetString.A.concat", () => { - test("Belt_internalSetString.A.concat", () => { +describe("Promise.allSettled", () => { + test("Promise.allSettled", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + open Promise - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + exception TestError(string) + + let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] + + allSettled(promises) + ->then( + results => { + results->Array.forEach( + result => { + switch result { + | Fulfilled({value: num}) => Console.log2("Number: ", num) + | Rejected({reason}) => Console.log(reason) + } + }, + ) + + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalSetString.A.reduce", () => { - test("Belt_internalSetString.A.reduce", () => { +describe("Promise.any", () => { + test("Promise.any", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + + any(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Belt_internalSetString.A.every2", () => { - test("Belt_internalSetString.A.every2", () => { +describe("Promise.catch", () => { + test("Promise.catch", () => { module Test = { - Belt.Array.every2([1, 2, 3], [0, 1], (a, b) => a > b) == true + open Promise - Belt.Array.every2([], [1], (x, y) => x > y) == true + exception SomeError(string) - Belt.Array.every2([2, 3], [1], (x, y) => x > y) == true + reject(SomeError("this is an error")) + ->then( + _ => { + Ok("This result will never be returned")->resolve + }, + ) + ->catch( + e => { + let msg = switch e { + | SomeError(msg) => "ReScript error occurred: " ++ msg + | Exn.Error(obj) => + switch Exn.message(obj) { + | Some(msg) => "JS exception occurred: " ++ msg + | None => "Some other JS value has been thrown" + } + | _ => "Unexpected error occurred" + } - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false + Error(msg)->resolve + }, + ) + ->then( + result => { + switch result { + | Ok(r) => Console.log2("Operation successful: ", r) + | Error(msg) => Console.log2("Operation failed: ", msg) + }->resolve + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Belt_internalMapString.A.length", () => { - test("Belt_internalMapString.A.length", () => { +describe("Promise.finally", () => { + test("Promise.finally", () => { module Test = { - // Returns 1 - Belt.Array.length(["test"]) + open Promise + exception SomeError(string) + let isDone = ref(false) + + resolve(5) + ->then( + _ => { + reject(SomeError("test")) + }, + ) + ->then( + v => { + Console.log2("final result", v) + resolve() + }, + ) + ->catch( + _ => { + Console.log("Error handled") + resolve() + }, + ) + ->finally( + () => { + Console.log("finally") + isDone := true + }, + ) + ->then( + () => { + Console.log2("isDone:", isDone.contents) + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalMapString.A.makeBy", () => { - test("Belt_internalMapString.A.makeBy", () => { +describe("Promise.make", () => { + test("Promise.make", () => { module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] + open Promise - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] + let n = 4 + Promise.make( + (resolve, reject) => { + if n < 5 { + resolve("success") + } else { + reject("failed") + } + }, + ) + ->then( + str => { + Console.log(str)->resolve + }, + ) + ->catch( + _ => { + Console.log("Error occurred") + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalMapString.A.concat", () => { - test("Belt_internalMapString.A.concat", () => { +describe("Promise.race", () => { + test("Promise.race", () => { module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] + open Promise + let racer = (ms, name) => { + Promise.make( + (resolve, _) => { + setTimeout( + () => { + resolve(name) + }, + ms, + )->ignore + }, + ) + } - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] + let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] + + race(promises)->then( + winner => { + Console.log("The winner is " ++ winner) + resolve() + }, + ) } () }) }) -describe("Belt_internalMapString.A.reduce", () => { - test("Belt_internalMapString.A.reduce", () => { +describe("Promise.reject", () => { + test("Promise.reject", () => { module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 + exception TestError(string) - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" + TestError("some rejected value") + ->Promise.reject + ->Promise.catch( + v => { + switch v { + | TestError(msg) => assertEqual(msg, "some rejected value") + | _ => assert(false) + } + Promise.resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalMapString.A.every2", () => { - test("Belt_internalMapString.A.every2", () => { +describe("Promise.resolve", () => { + test("Promise.resolve", () => { module Test = { - 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 + let p = Promise.resolve(5) // promise + } + () + }) +}) - Belt.Array.every2([0, 1], [5, 0], (x, y) => x > y) == false +describe("Promise.then", () => { + test("Promise.then", () => { + module Test = { + open Promise + resolve(5) + ->then( + num => { + resolve(num + 5) + }, + ) + ->then( + num => { + Console.log2("Your lucky number is: ", num) + resolve() + }, + ) + ->ignore } () }) }) -describe("Belt_internalMapInt.A.partition", () => { - test("Belt_internalMapInt.A.partition", () => { +describe("Promise.thenResolve", () => { + test("Promise.thenResolve", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + open Promise + resolve("Anna") + ->thenResolve( + str => { + "Hello " ++ str + }, + ) + ->thenResolve( + str => { + Console.log(str) + }, + ) + ->ignore // Ignore needed for side-effects } () }) }) -describe("Belt_internalSetInt.A.partition", () => { - test("Belt_internalSetInt.A.partition", () => { +describe("RegExp.Result.fullMatch", () => { + test("RegExp.Result.fullMatch", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" + } } () }) }) -describe("Belt.HashMap.getBucketHistogram", () => { - test("Belt.HashMap.getBucketHistogram", () => { +describe("RegExp.Result.input", () => { + test("RegExp.Result.input", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") - Belt.HashMap.getBucketHistogram(hMap) + // This below will log the full input string "ReScript is pretty cool, right?" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.input) + } } () }) }) -describe("Belt_HashMap.getBucketHistogram", () => { - test("Belt_HashMap.getBucketHistogram", () => { +describe("RegExp.Result.matches", () => { + test("RegExp.Result.matches", () => { module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") + // Match the first two words separated by a space + let regexp = RegExp.fromString("(\\w+) (\\w+)") - Belt.HashMap.getBucketHistogram(hMap) + // This below will log "ReScript" and "is" to the console. + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => + switch result->RegExp.Result.matches { + | [firstWord, secondWord] => Console.log2(firstWord, secondWord) + | _ => Console.log("Didn't find exactly two words...") + } + } } () }) }) -describe("Float.toExponentialWithPrecision", () => { - test("Float.toExponentialWithPrecision", () => { +describe("RegExp.exec", () => { + test("RegExp.exec", () => { module Test = { - Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" - Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("Float.Constants.positiveInfinity", () => { - test("Float.Constants.positiveInfinity", () => { +describe("RegExp.fromString", () => { + test("RegExp.fromString", () => { module Test = { - Float.Constants.positiveInfinity + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("Float.Constants.negativeInfinity", () => { - test("Float.Constants.negativeInfinity", () => { +describe("RegExp.fromStringWithFlags", () => { + test("RegExp.fromStringWithFlags", () => { module Test = { - Float.Constants.negativeInfinity + // Match the first word in a sentence + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + + switch regexp->RegExp.exec("ReScript is pretty cool, right?") { + | None => Console.log("Nope, no match...") + | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" + } } () }) }) -describe("Belt_internalSetString.A.reverse", () => { - test("Belt_internalSetString.A.reverse", () => { +describe("RegExp.global", () => { + test("RegExp.global", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set } () }) }) -describe("Belt_internalSetString.A.rangeBy", () => { - test("Belt_internalSetString.A.rangeBy", () => { +describe("RegExp.ignoreCase", () => { + test("RegExp.ignoreCase", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") + Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set } () }) }) -describe("Belt_internalSetString.A.forEach", () => { - test("Belt_internalSetString.A.forEach", () => { +describe("RegExp.lastIndex", () => { + test("RegExp.lastIndex", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) + Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + regexp->RegExp.exec(someStr)->ignore - total.contents == 1 + 2 + 3 + 4 + Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console } () }) }) -describe("Belt_internalSetString.A.flatMap", () => { - test("Belt_internalSetString.A.flatMap", () => { +describe("RegExp.multiline", () => { + test("RegExp.multiline", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set -describe("Belt_internalSetString.A.keepMap", () => { - test("Belt_internalSetString.A.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") + Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set } () }) }) -describe("Belt_internalMapString.A.reverse", () => { - test("Belt_internalMapString.A.reverse", () => { +describe("RegExp.setLastIndex", () => { + test("RegExp.setLastIndex", () => { module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + let someStr = "Many words here." + + regexp->RegExp.setLastIndex(4) + regexp->RegExp.exec(someStr)->ignore + + Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console } () }) }) -describe("Belt_internalMapString.A.rangeBy", () => { - test("Belt_internalMapString.A.rangeBy", () => { +describe("RegExp.source", () => { + test("RegExp.source", () => { module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] + let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` } () }) }) -describe("Belt_internalMapString.A.forEach", () => { - test("Belt_internalMapString.A.forEach", () => { +describe("RegExp.sticky", () => { + test("RegExp.sticky", () => { module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set - total.contents == 1 + 2 + 3 + 4 + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set } () }) }) -describe("Belt_internalMapString.A.flatMap", () => { - test("Belt_internalMapString.A.flatMap", () => { +describe("RegExp.test", () => { + test("RegExp.test", () => { module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] + // Match the first word in a sentence + let regexp = RegExp.fromString("\\w+") + + if regexp->RegExp.test("ReScript is cool!") { + Console.log("Yay, there's a word in there.") + } } () }) }) -describe("Belt_internalMapString.A.keepMap", () => { - test("Belt_internalMapString.A.keepMap", () => { +describe("RegExp.unicode", () => { + test("RegExp.unicode", () => { module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] + let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") + Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set + + let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") + Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set } () }) }) -describe("Belt_internalMapInt.A.concatMany", () => { - test("Belt_internalMapInt.A.concatMany", () => { +describe("Result.all", () => { + test("Result.all", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) + Result.all([Ok(1), Error(1)]) // Error(1) } () }) }) -describe("Belt_internalMapInt.A.sliceToEnd", () => { - test("Belt_internalMapInt.A.sliceToEnd", () => { +describe("Result.compare", () => { + test("Result.compare", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] + let good1 = Ok(59) - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + let good2 = Ok(37) + + let bad1 = Error("invalid") + + let bad2 = Error("really invalid") + + let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) + + Result.compare(Ok(39), Ok(57), mod10cmp) == 1. + + Result.compare(Ok(57), Ok(39), mod10cmp) == -1. + + Result.compare(Ok(39), Error("y"), mod10cmp) == 1. + + Result.compare(Error("x"), Ok(57), mod10cmp) == -1. + + Result.compare(Error("x"), Error("y"), mod10cmp) == 0. } () }) }) -describe("Belt_internalMapInt.A.getIndexBy", () => { - test("Belt_internalMapInt.A.getIndexBy", () => { +describe("Result.equal", () => { + test("Result.equal", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + let good1 = Ok(42) + + let good2 = Ok(32) + + let bad1 = Error("invalid") + + let bad2 = Error("really invalid") + + let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) + + Result.equal(good1, good2, mod10equal) == true + + Result.equal(good1, bad1, mod10equal) == false + + Result.equal(bad2, good2, mod10equal) == false + + Result.equal(bad1, bad2, mod10equal) == true } () }) }) -describe("Belt_internalSetInt.A.concatMany", () => { - test("Belt_internalSetInt.A.concatMany", () => { +describe("Result.flatMap", () => { + test("Result.flatMap", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + let recip = x => + if x !== 0.0 { + Ok(1.0 /. x) + } else { + Error("Divide by zero") + } + + Result.flatMap(Ok(2.0), recip) == Ok(0.5) + + Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") + + Result.flatMap(Error("Already bad"), recip) == Error("Already bad") } () }) }) -describe("Belt_internalSetInt.A.sliceToEnd", () => { - test("Belt_internalSetInt.A.sliceToEnd", () => { +describe("Result.forEach", () => { + test("Result.forEach", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + Result.forEach(Ok(3), Console.log) // Logs "3", returns () + Result.forEach(Error("x"), Console.log) // Does nothing, returns () } () }) }) -describe("Belt_internalSetInt.A.getIndexBy", () => { - test("Belt_internalSetInt.A.getIndexBy", () => { +describe("Result.getOr", () => { + test("Result.getOr", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + Result.getOr(Ok(42), 0) == 42 + + Result.getOr(Error("Invalid Data"), 0) == 0 } () }) }) -describe("JSON.stringifyWithFilterAndIndent", () => { - test("JSON.stringifyWithFilterAndIndent", () => { +describe("Result.map", () => { + test("Result.map", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + let f = x => sqrt(Int.toFloat(x)) - JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) - // { - // "foo": "bar", - // "someNumber": 42 - // } + Result.map(Ok(64), f) == Ok(8.0) + + Result.map(Error("Invalid data"), f) == Error("Invalid data") } () }) }) -describe("Date.toLocaleDateStringWithLocale", () => { - test("Date.toLocaleDateStringWithLocale", () => { +describe("Result.mapError", () => { + test("Result.mapError", () => { module Test = { - Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log - // 2/19/2023 + let format = n => `Error code: ${n->Int.toString}` + Result.mapError(Error(14), format) // Error("Error code: 14") + Result.mapError(Ok("abc"), format) // Ok("abc") } () }) }) -describe("Date.toLocaleTimeStringWithLocale", () => { - test("Date.toLocaleTimeStringWithLocale", () => { +describe("Result.mapOr", () => { + test("Result.mapOr", () => { module Test = { - Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log - // 3:40:00 PM + let ok = Ok(42) + Result.mapOr(ok, 0, x => x / 2) == 21 + + let error = Error("Invalid data") + Result.mapOr(error, 0, x => x / 2) == 0 } () }) }) -describe("Belt_internalSetString.A.joinWith", () => { - test("Belt_internalSetString.A.joinWith", () => { +describe("Set.add", () => { + test("Set.add", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + let set = Set.make() + set->Set.add("someValue") } () }) }) -describe("Belt_internalMapString.A.joinWith", () => { - test("Belt_internalMapString.A.joinWith", () => { +describe("Set.clear", () => { + test("Set.clear", () => { module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" + let set = Set.make() + + set->Set.add("someKey") + set->Set.size // 1 + + set->Set.clear + set->Set.size // 0 } () }) }) -describe("Belt.Array.truncateToLengthUnsafe", () => { - test("Belt.Array.truncateToLengthUnsafe", () => { +describe("Set.delete", () => { + test("Set.delete", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) + let set = Set.make() + set->Set.add("someValue") + let didDeleteValue = set->Set.delete("someValue") + Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted - arr == ["ant", "bee", "cat"] + let didDeleteValue = set->Set.delete("someNonExistantKey") + Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set } () }) }) -describe("Belt_Array.truncateToLengthUnsafe", () => { - test("Belt_Array.truncateToLengthUnsafe", () => { +describe("Set.forEach", () => { + test("Set.forEach", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) + let set = Set.make() + set->Set.add("someValue") + set->Set.add("someValue2") - arr == ["ant", "bee", "cat"] + set->Set.forEach( + value => { + Console.log(value) + }, + ) } () }) }) -describe("Belt_internalSetString.A.partition", () => { - test("Belt_internalSetString.A.partition", () => { +describe("Set.fromArray", () => { + test("Set.fromArray", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + type languages = ReScript | JavaScript | TypeScript + let languageRank = [ReScript, JavaScript, TypeScript] - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + let set = Set.fromArray(languageRank) // Set.t + + switch set->Set.has(ReScript) { + | true => Console.log("Yay, ReScript is in there!") + | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") + } } () }) }) -describe("Belt_internalMapString.A.partition", () => { - test("Belt_internalMapString.A.partition", () => { +describe("Set.fromIterator", () => { + test("Set.fromIterator", () => { module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) + // Let's pretend we have an interator + let iterator: Iterator.t = %raw(` + (() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })() +`) - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) + iterator + ->Set.fromIterator + ->Set.size + ->assertEqual(3) } () }) }) -describe("Belt_internalMapInt.A.mapWithIndex", () => { - test("Belt_internalMapInt.A.mapWithIndex", () => { +describe("Set.has", () => { + test("Set.has", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + let set = Set.make() + set->Set.add("someValue") + + switch set->Set.has("someValue") { + | false => Console.log("Nope, didn't have it.") + | true => Console.log("Yay, we have the value!") + } } () }) }) -describe("Belt_internalSetInt.A.mapWithIndex", () => { - test("Belt_internalSetInt.A.mapWithIndex", () => { +describe("Set.make", () => { + test("Set.make", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + // You can annotate the type of your set if you want to + let mySet: Set.t = Set.make() + + // Or you can let ReScript infer what's in your Set + let set = Set.make() + set->Set.add("Fine name") // Inferred as Set.t } () }) }) -describe("Belt.Array.makeUninitializedUnsafe", () => { - test("Belt.Array.makeUninitializedUnsafe", () => { +describe("Set.size", () => { + test("Set.size", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined + let set = Set.make() - Belt.Array.setExn(arr, 0, "example") + set->Set.add("someValue") + set->Set.add("someValue") + set->Set.add("someValue2") - Js.log(Belt.Array.getExn(arr, 0) == "example") + let size = set->Set.size // 2 } () }) }) -describe("Belt_Array.makeUninitializedUnsafe", () => { - test("Belt_Array.makeUninitializedUnsafe", () => { +describe("Set.toArray", () => { + test("Set.toArray", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") + let set = Set.fromArray(["apple", "orange", "apple", "banana"]) + set->Set.toArray // ["apple", "orange", "banana"] } () }) }) -describe("JSON.stringifyWithReplacerAndIndent", () => { - test("JSON.stringifyWithReplacerAndIndent", () => { +describe("Set.values", () => { + test("Set.values", () => { module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object + let set = Set.make() + set->Set.add("someValue") + set->Set.add("anotherValue") - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string + let values = set->Set.values - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } + // Logs the first value + Console.log(Iterator.next(values).value) - JSON.stringifyWithReplacerAndIndent(json, replacer, 2) - // { - // "foo": "BAR", - // "hello": "WORLD", - // "someNumber": 42 - // } + // You can also turn the iterator into an array. + // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. + Console.log(set->Set.values->Iterator.toArray) } () }) }) -describe("Belt_internalSetString.A.concatMany", () => { - test("Belt_internalSetString.A.concatMany", () => { +describe("String.charAt", () => { + test("String.charAt", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + String.charAt("ReScript", 0) == "R" + String.charAt("Hello", 12) == "" + String.charAt(`JS`, 5) == "" } () }) }) -describe("Belt_internalSetString.A.sliceToEnd", () => { - test("Belt_internalSetString.A.sliceToEnd", () => { +describe("String.charCodeAt", () => { + test("String.charCodeAt", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat + String.codePointAt(`😺`, 0) == Some(0x1f63a) } () }) }) -describe("Belt_internalSetString.A.getIndexBy", () => { - test("Belt_internalSetString.A.getIndexBy", () => { +describe("String.codePointAt", () => { + test("String.codePointAt", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) + String.codePointAt("abc", 5) == None } () }) }) -describe("Belt_internalMapString.A.concatMany", () => { - test("Belt_internalMapString.A.concatMany", () => { +describe("String.concat", () => { + test("String.concat", () => { module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] + String.concat("cow", "bell") == "cowbell" + String.concat("Re", "Script") == "ReScript" } () }) }) -describe("Belt_internalMapString.A.sliceToEnd", () => { - test("Belt_internalMapString.A.sliceToEnd", () => { +describe("String.concatMany", () => { + test("String.concatMany", () => { module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] + String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" } () }) }) -describe("Belt_internalMapString.A.getIndexBy", () => { - test("Belt_internalMapString.A.getIndexBy", () => { +describe("String.endsWith", () => { + test("String.endsWith", () => { module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None + String.endsWith("BuckleScript", "Script") == true + String.endsWith("BuckleShoes", "Script") == false } () }) }) -describe("Belt_internalMapInt.A.keepWithIndex", () => { - test("Belt_internalMapInt.A.keepWithIndex", () => { +describe("String.endsWithFrom", () => { + test("String.endsWithFrom", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + String.endsWithFrom("abcd", "cd", 4) == true + String.endsWithFrom("abcde", "cd", 3) == false + String.endsWithFrom("abcde", "cde", 99) == true + String.endsWithFrom("example.dat", "ple", 7) == true } () }) }) -describe("Belt_internalMapInt.A.reduceReverse", () => { - test("Belt_internalMapInt.A.reduceReverse", () => { +describe("String.fromCharCode", () => { + test("String.fromCharCode", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + String.fromCharCode(65) == "A" + String.fromCharCode(0x3c8) == `ψ` + String.fromCharCode(0xd55c) == `한` + String.fromCharCode(-64568) == `ψ` } () }) }) -describe("Belt_internalSetInt.A.keepWithIndex", () => { - test("Belt_internalSetInt.A.keepWithIndex", () => { +describe("String.fromCharCodeMany", () => { + test("String.fromCharCodeMany", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" + String.fromCharCodeMany([65, 66, 67]) == "ABC" } () }) }) -describe("Belt_internalSetInt.A.reduceReverse", () => { - test("Belt_internalSetInt.A.reduceReverse", () => { +describe("String.fromCodePoint", () => { + test("String.fromCodePoint", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + String.fromCodePoint(65) == "A" + String.fromCodePoint(0x3c8) == `ψ` + String.fromCodePoint(0xd55c) == `한` + String.fromCodePoint(0x1f63a) == `😺` } () }) }) -describe("Belt_SortArray.strictlySortedLength", () => { - test("Belt_SortArray.strictlySortedLength", () => { +describe("String.fromCodePointMany", () => { + test("String.fromCodePointMany", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` } () }) }) -describe("Belt.SortArray.strictlySortedLength", () => { - test("Belt.SortArray.strictlySortedLength", () => { +describe("String.get", () => { + test("String.get", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + String.get("ReScript", 0) == Some("R") + String.get("Hello", 4) == Some("o") + String.get(`JS`, 4) == None } () }) }) -describe("JSON.stringifyAnyWithFilterAndIndent", () => { - test("JSON.stringifyAnyWithFilterAndIndent", () => { +describe("String.getUnsafe", () => { + test("String.getUnsafe", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + String.getUnsafe("ReScript", 0) == "R" + String.getUnsafe("Hello", 4) == "o" } () }) }) -describe("Belt_internalMapInt.A.reverseInPlace", () => { - test("Belt_internalMapInt.A.reverseInPlace", () => { +describe("String.includes", () => { + test("String.includes", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] + String.includes("programmer", "gram") == true + String.includes("programmer", "er") == true + String.includes("programmer", "pro") == true + String.includes("programmer.dat", "xyz") == false } () }) }) -describe("Belt_internalMapInt.A.reduceReverse2", () => { - test("Belt_internalMapInt.A.reduceReverse2", () => { +describe("String.includesFrom", () => { + test("String.includesFrom", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + String.includesFrom("programmer", "gram", 1) == true + String.includesFrom("programmer", "gram", 4) == false + String.includesFrom(`대한민국`, `한`, 1) == true } () }) }) -describe("Belt_internalMapInt.S.binarySearchBy", () => { - test("Belt_internalMapInt.S.binarySearchBy", () => { +describe("String.indexOf", () => { + test("String.indexOf", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + String.indexOf("bookseller", "ok") == 2 + String.indexOf("bookseller", "sell") == 4 + String.indexOf("beekeeper", "ee") == 1 + String.indexOf("bookseller", "xyz") == -1 } () }) }) -describe("Belt_internalSetInt.A.reverseInPlace", () => { - test("Belt_internalSetInt.A.reverseInPlace", () => { +describe("String.indexOfFrom", () => { + test("String.indexOfFrom", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) + String.indexOfFrom("bookseller", "ok", 1) == 2 + String.indexOfFrom("bookseller", "sell", 2) == 4 + String.indexOfFrom("bookseller", "sell", 5) == -1 + } + () + }) +}) - arr == [14, 13, 12, 11, 10] +describe("String.indexOfOpt", () => { + test("String.indexOfOpt", () => { + module Test = { + String.indexOfOpt("bookseller", "ok") == Some(2) + String.indexOfOpt("bookseller", "xyz") == None } () }) }) -describe("Belt_internalSetInt.A.reduceReverse2", () => { - test("Belt_internalSetInt.A.reduceReverse2", () => { +describe("String.lastIndexOf", () => { + test("String.lastIndexOf", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + String.lastIndexOf("bookseller", "ok") == 2 + String.lastIndexOf("beekeeper", "ee") == 4 + String.lastIndexOf("abcdefg", "xyz") == -1 } () }) }) -describe("Belt_internalSetString.A.mapWithIndex", () => { - test("Belt_internalSetString.A.mapWithIndex", () => { +describe("String.lastIndexOfFrom", () => { + test("String.lastIndexOfFrom", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + String.lastIndexOfFrom("bookseller", "ok", 6) == 2 + String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 + String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 + String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 } () }) }) -describe("Belt_internalMapString.A.mapWithIndex", () => { - test("Belt_internalMapString.A.mapWithIndex", () => { +describe("String.lastIndexOfOpt", () => { + test("String.lastIndexOfOpt", () => { module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] + String.lastIndexOfOpt("bookseller", "ok") == Some(2) + String.lastIndexOfOpt("beekeeper", "ee") == Some(4) + String.lastIndexOfOpt("abcdefg", "xyz") == None } () }) }) -describe("Belt_internalMapInt.A.reduceWithIndex", () => { - test("Belt_internalMapInt.A.reduceWithIndex", () => { +describe("String.length", () => { + test("String.length", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + String.length("abcd") == 4 } () }) }) -describe("Belt_internalSetInt.A.reduceWithIndex", () => { - test("Belt_internalSetInt.A.reduceWithIndex", () => { +describe("String.localeCompare", () => { + test("String.localeCompare", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + String.localeCompare("a", "c") < 0.0 == true + String.localeCompare("a", "a") == 0.0 } () }) }) -describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - test("JSON.stringifyAnyWithReplacerAndIndent", () => { +describe("String.make", () => { + test("String.make", () => { module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } + String.make(3.5) == "3.5" + String.make([1, 2, 3]) == "1,2,3" } () }) }) -describe("Belt_internalSetString.A.keepWithIndex", () => { - test("Belt_internalSetString.A.keepWithIndex", () => { +describe("String.match", () => { + test("String.match", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) + String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) + String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == + Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) + String.match("The optional example", /(foo)?(example)/) == + Some([Some("example"), None, Some("example")]) + String.match("The large container.", /b[aeiou]g/) == None } () }) }) -describe("Belt_internalSetString.A.reduceReverse", () => { - test("Belt_internalSetString.A.reduceReverse", () => { +describe("String.normalize", () => { + test("String.normalize", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + let string1 = "\u00F1" + let string2 = "\u006E\u0303" + + assert(string1 != string2) // true + assertEqual(String.normalize(string1), String.normalize(string2)) } () }) }) -describe("Belt_internalMapString.A.keepWithIndex", () => { - test("Belt_internalMapString.A.keepWithIndex", () => { +describe("String.normalizeForm", () => { + test("String.normalizeForm", () => { module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] + let string1 = "\uFB00" + let string2 = "\u0066\u0066" + Console.log(string1 == string2) // false + + let normalizeString1 = String.normalizeByForm(string1, #NFKD) + let normalizeString2 = String.normalizeByForm(string2, #NFKD) + Console.log(normalizeString1 == normalizeString2) // true } () }) }) -describe("Belt_internalMapString.A.reduceReverse", () => { - test("Belt_internalMapString.A.reduceReverse", () => { +describe("String.padEnd", () => { + test("String.padEnd", () => { module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" + String.padEnd("Hello", 10, ".") == "Hello....." + String.padEnd("abc", 1, "") == "abc" } () }) }) -describe("Belt_internalMapInt.A.forEachWithIndex", () => { - test("Belt_internalMapInt.A.forEachWithIndex", () => { +describe("String.padStart", () => { + test("String.padStart", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + String.padStart("abc", 5, " ") == " abc" + String.padStart("abc", 6, "123465") == "123abc" } () }) }) -describe("Belt_internalSetInt.A.forEachWithIndex", () => { - test("Belt_internalSetInt.A.forEachWithIndex", () => { +describe("String.repeat", () => { + test("String.repeat", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + String.repeat("ha", 3) == "hahaha" + String.repeat("empty", 0) == "" } () }) }) -describe("Date.toLocaleStringWithLocaleAndOptions", () => { - test("Date.toLocaleStringWithLocaleAndOptions", () => { +describe("String.replace", () => { + test("String.replace", () => { module Test = { - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) - ->Console.log - // 2/19/23, 3:40 PM - - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions( - "en", - { - era: #long, - year: #numeric, - month: #"2-digit", - day: #"2-digit", - hour: #numeric, - timeZoneName: #short, - }, - ) - ->Console.log - // 02/19/2023 Anno Domini, 3 PM GMT+1 + String.replace("old string", "old", "new") == "new string" + String.replace("the cat and the dog", "the", "this") == "this cat and the dog" } () }) }) -describe("Belt_internalSetString.A.reverseInPlace", () => { - test("Belt_internalSetString.A.reverseInPlace", () => { +describe("String.replaceAll", () => { + test("String.replaceAll", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] + String.replaceAll("old old string", "old", "new") == "new new string" + String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" } () }) }) -describe("Belt_internalSetString.A.reduceReverse2", () => { - test("Belt_internalSetString.A.reduceReverse2", () => { +describe("String.replaceAllRegExp", () => { + test("String.replaceAllRegExp", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" } () }) }) -describe("Belt_internalMapString.A.reverseInPlace", () => { - test("Belt_internalMapString.A.reverseInPlace", () => { +describe("String.replaceRegExp", () => { + test("String.replaceRegExp", () => { module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] + String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" + String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" } () }) }) -describe("Belt_internalMapString.A.reduceReverse2", () => { - test("Belt_internalMapString.A.reduceReverse2", () => { +describe("String.search", () => { + test("String.search", () => { module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 + String.search("testing 1 2 3", /\d+/) == 8 + String.search("no numbers", /\d+/) == -1 } () }) }) -describe("Belt_internalMapString.S.binarySearchBy", () => { - test("Belt_internalMapString.S.binarySearchBy", () => { +describe("String.searchOpt", () => { + test("String.searchOpt", () => { module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 + String.searchOpt("testing 1 2 3", /\d+/) == Some(8) + String.searchOpt("no numbers", /\d+/) == None } () }) }) -describe("Belt_internalMapInt.A.makeUninitialized", () => { - test("Belt_internalMapInt.A.makeUninitialized", () => { +describe("String.slice", () => { + test("String.slice", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined + String.slice("abcdefg", ~start=2, ~end=5) == "cde" + String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" + String.slice("abcdefg", ~start=-4, ~end=-2) == "de" + String.slice("abcdefg", ~start=5, ~end=1) == "" } () }) }) -describe("Belt_internalSetInt.A.makeUninitialized", () => { - test("Belt_internalSetInt.A.makeUninitialized", () => { +describe("String.sliceToEnd", () => { + test("String.sliceToEnd", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined + String.sliceToEnd("abcdefg", ~start=4) == "efg" + String.sliceToEnd("abcdefg", ~start=-2) == "fg" + String.sliceToEnd("abcdefg", ~start=7) == "" } () }) }) -describe("Belt_internalSetString.A.reduceWithIndex", () => { - test("Belt_internalSetString.A.reduceWithIndex", () => { +describe("String.split", () => { + test("String.split", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + String.split("2018-01-02", "-") == ["2018", "01", "02"] + String.split("a,b,,c", ",") == ["a", "b", "", "c"] + String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] + String.split("has-no-delimiter", ";") == ["has-no-delimiter"] } () }) }) -describe("Belt_internalMapString.A.reduceWithIndex", () => { - test("Belt_internalMapString.A.reduceWithIndex", () => { +describe("String.splitAtMost", () => { + test("String.splitAtMost", () => { module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] + String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ + "ant", + "bee", + "cat", + "dog", + "elk", + ] } () }) }) -describe("Belt_internalSetString.A.forEachWithIndex", () => { - test("Belt_internalSetString.A.forEachWithIndex", () => { +describe("String.splitByRegExp", () => { + test("String.splitByRegExp", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] } () }) }) -describe("Belt_internalMapString.A.forEachWithIndex", () => { - test("Belt_internalMapString.A.forEachWithIndex", () => { +describe("String.splitByRegExpAtMost", () => { + test("String.splitByRegExpAtMost", () => { module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 + String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ + Some("Hello"), + Some("World."), + Some("How"), + ] } () }) }) -describe("Belt_internalSetString.A.makeUninitialized", () => { - test("Belt_internalSetString.A.makeUninitialized", () => { +describe("String.startsWith", () => { + test("String.startsWith", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined + String.startsWith("BuckleScript", "Buckle") == true + String.startsWith("BuckleScript", "") == true + String.startsWith("JavaScript", "Buckle") == false } () }) }) -describe("Belt_internalMapString.A.makeUninitialized", () => { - test("Belt_internalMapString.A.makeUninitialized", () => { +describe("String.startsWithFrom", () => { + test("String.startsWithFrom", () => { module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined + String.startsWithFrom("BuckleScript", "kle", 3) == true + String.startsWithFrom("BuckleScript", "", 3) == true + String.startsWithFrom("JavaScript", "Buckle", 2) == false } () }) }) -describe("Belt_internalMapInt.S.strictlySortedLength", () => { - test("Belt_internalMapInt.S.strictlySortedLength", () => { +describe("String.substring", () => { + test("String.substring", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + String.substring("playground", ~start=3, ~end=6) == "ygr" + String.substring("playground", ~start=6, ~end=3) == "ygr" + String.substring("playground", ~start=4, ~end=12) == "ground" } () }) }) -describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { - test("Date.toLocaleDateStringWithLocaleAndOptions", () => { +describe("String.substringToEnd", () => { + test("String.substringToEnd", () => { module Test = { - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) - ->Console.log - // February 19, 2023 - - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 19.2.2023, 15:40 - - Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log - // 2023 + String.substringToEnd("playground", ~start=4) == "ground" + String.substringToEnd("playground", ~start=-3) == "playground" + String.substringToEnd("playground", ~start=12) == "" } () }) }) -describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { +describe("String.toLowerCase", () => { + test("String.toLowerCase", () => { module Test = { - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) - ->Console.log - // 3:40:00 PM GMT+1 - - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 15:40 + String.toLowerCase("ABC") == "abc" + String.toLowerCase(`ΣΠ`) == `σπ` + String.toLowerCase(`ΠΣ`) == `πς` } () }) }) -describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { +describe("String.toUpperCase", () => { + test("String.toUpperCase", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] + String.toUpperCase("abc") == "ABC" + String.toUpperCase(`Straße`) == `STRASSE` + String.toUpperCase(`πς`) == `ΠΣ` } () }) }) -describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { +describe("String.trim", () => { + test("String.trim", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] + String.trim(" abc def ") == "abc def" + String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" } () }) }) -describe("Belt_internalMapString.S.strictlySortedLength", () => { - test("Belt_internalMapString.S.strictlySortedLength", () => { +describe("String.trimEnd", () => { + test("String.trimEnd", () => { module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 + String.trimEnd(" Hello world! ") == " Hello world!" + String.trimEnd(" Hello world! ") == " Hello world!" } () }) }) -describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { +describe("String.trimStart", () => { + test("String.trimStart", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") + String.trimStart(" Hello world! ") == "Hello world! " + String.trimStart(" Hello world! ") == "Hello world! " } () }) }) -describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { +describe("String.unsafeReplaceRegExpBy0", () => { + test("String.unsafeReplaceRegExpBy0", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") + let str = "beautiful vowels" + let re = /[aeiou]/g + let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) + String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" } () }) }) -describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { +describe("String.unsafeReplaceRegExpBy1", () => { + test("String.unsafeReplaceRegExpBy1", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] + let str = "Jony is 40" + let re = /(Jony is )\d+/g + let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { + group1 ++ "41" + } + String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" } () }) }) -describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { +describe("String.unsafeReplaceRegExpBy2", () => { + test("String.unsafeReplaceRegExpBy2", () => { module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] + let str = "7 times 6" + let re = /(\d+) times (\d+)/ + let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { + switch (Int.fromString(group1), Int.fromString(group2)) { + | (Some(x), Some(y)) => Int.toString(x * y) + | _ => "???" + } + } + String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" } () }) }) -describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { +describe("Type.Classify.classify", () => { + test("Type.Classify.classify", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") + switch %raw(`null`)->Type.Classify.classify { + | Null => Console.log("Yup, that's null.") + | _ => Console.log("This doesn't actually appear to be null...") + } } () }) }) -describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { +describe("Type.typeof", () => { + test("Type.typeof", () => { module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined + Console.log(Type.typeof("Hello")) // Logs "string" to the console. - Belt.Array.setExn(arr, 0, "example") + let someVariable = true - Js.log(Belt.Array.getExn(arr, 0) == "example") + switch someVariable->Type.typeof { + | #boolean => Console.log("This is a bool, yay!") + | _ => Console.log("Oh, not a bool sadly...") + } } () }) diff --git a/tests/docstrings_examples/generated_mocha_test.res.mjs b/tests/docstrings_examples/generated_mocha_test.res.mjs index a973421718..bdf8d22d0b 100644 --- a/tests/docstrings_examples/generated_mocha_test.res.mjs +++ b/tests/docstrings_examples/generated_mocha_test.res.mjs @@ -43,2391 +43,2845 @@ 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"; -Mocha.describe("Set.add", () => { - Mocha.test("Set.add", () => { - let set = new Set(); - set.add("someValue"); +Mocha.describe("Array.at", () => { + Mocha.test("Array.at", () => { + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(0), "a"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(2), "c"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(3), undefined); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-1), "c"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-3), "a"); + Pervasives.assertEqual([ + "a", + "b", + "c" + ].at(-4), undefined); }); }); -Mocha.describe("Set.has", () => { - Mocha.test("Set.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.describe("Array.concat", () => { + Mocha.test("Array.concat", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = [ + "yay", + "wehoo" + ]; + let someArray = array1.concat(array2); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); }); }); -Mocha.describe("Map.get", () => { - Mocha.test("Map.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.describe("Array.concatMany", () => { + Mocha.test("Array.concatMany", () => { + let array1 = [ + "hi", + "hello" + ]; + let array2 = ["yay"]; + let array3 = ["wehoo"]; + let someArray = array1.concat(array2, array3); + console.log(someArray); }); }); -Mocha.describe("Map.has", () => { - Mocha.test("Map.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.describe("Array.copy", () => { + Mocha.test("Array.copy", () => { + let myArray = [ + 1, + 2, + 3 + ]; + let copyOfMyArray = myArray.slice(); + Pervasives.assertEqual(copyOfMyArray, [ + 1, + 2, + 3 + ]); + Pervasives.assertEqual(myArray === copyOfMyArray, false); }); }); -Mocha.describe("Map.set", () => { - Mocha.test("Map.set", () => { - let map = new Map(); - map.set("someKey", "someValue"); +Mocha.describe("Array.every", () => { + Mocha.test("Array.every", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every(num => num <= 4), true); + Pervasives.assertEqual(array.every(num => num === 1), false); }); }); -Mocha.describe("Int.mod", () => { - Mocha.test("Int.mod", () => {}); -}); - -Mocha.describe("Set.make", () => { - Mocha.test("Set.make", () => { - new Set(); - let set = new Set(); - set.add("Fine name"); +Mocha.describe("Array.everyWithIndex", () => { + Mocha.test("Array.everyWithIndex", () => { + let array = [ + 1, + 2, + 3, + 4 + ]; + Pervasives.assertEqual(array.every((num, index) => { + if (index < 5) { + return num <= 4; + } else { + return false; + } + }), true); + Pervasives.assertEqual(array.every((num, index) => { + if (index < 2) { + return num >= 2; + } else { + return false; + } + }), false); }); }); -Mocha.describe("Set.size", () => { - Mocha.test("Set.size", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue"); - set.add("someValue2"); +Mocha.describe("Array.fill", () => { + Mocha.test("Array.fill", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1, 3); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 4 + ]); }); }); -Mocha.describe("List.add", () => { - Mocha.test("List.add", () => { - List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); +Mocha.describe("Array.fillAll", () => { + Mocha.test("Array.fillAll", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9); + Pervasives.assertEqual(myArray, [ + 9, + 9, + 9, + 9 + ]); }); }); -Mocha.describe("List.get", () => { - Mocha.test("List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - List.get(abc, 1); - List.get(abc, 4); +Mocha.describe("Array.fillToEnd", () => { + Mocha.test("Array.fillToEnd", () => { + let myArray = [ + 1, + 2, + 3, + 4 + ]; + myArray.fill(9, 1); + Pervasives.assertEqual(myArray, [ + 1, + 9, + 9, + 9 + ]); }); }); -Mocha.describe("List.map", () => { - Mocha.test("List.map", () => { - List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); +Mocha.describe("Array.filter", () => { + Mocha.test("Array.filter", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].filter(num => num > 2), [ + 3, + 4 + ]); }); }); -Mocha.describe("List.zip", () => { - Mocha.test("List.zip", () => { - List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.has", () => { - Mocha.test("List.has", () => { - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Array.filterMap", () => { + Mocha.test("Array.filterMap", () => { + Pervasives.assertEqual($$Array.filterMap([ + "Hello", + "Hi", + "Good bye" + ], item => { + if (item === "Hello") { + return item.length; } - }, 2, (a, b) => a === b); - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + + }), [5]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return Math.imul(n, n); } - }, 4, (a, b) => a === b); - List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } + + }), [ + 4, + 16, + 36 + ]); + Pervasives.assertEqual($$Array.filterMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), []); + Pervasives.assertEqual($$Array.filterMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + + }), []); }); }); -Mocha.describe("Null.map", () => { - Mocha.test("Null.map", () => { - Null.map(3, x => Math.imul(x, x)); - Null.map(null, x => Math.imul(x, x)); +Mocha.describe("Array.filterWithIndex", () => { + Mocha.test("Array.filterWithIndex", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].filter((num, index) => { + if (index === 0) { + return true; + } else { + return num === 2; + } + }), [ + 1, + 2 + ]); }); }); -Mocha.describe("Math.abs", () => { - Mocha.test("Math.abs", () => { - Math.abs(-2.0); - Math.abs(3.0); +Mocha.describe("Array.find", () => { + Mocha.test("Array.find", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); }); }); -Mocha.describe("Math.cos", () => { - Mocha.test("Math.cos", () => { - Math.cos(-0.0); - Math.cos(0.0); - Math.cos(1.0); +Mocha.describe("Array.findIndex", () => { + Mocha.test("Array.findIndex", () => { + let array = [ + "ReScript", + "JavaScript" + ]; + Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); + Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); }); }); -Mocha.describe("Math.exp", () => { - Mocha.test("Math.exp", () => { - Math.exp(-1.0); - Math.exp(0.0); +Mocha.describe("Array.findIndexOpt", () => { + Mocha.test("Array.findIndexOpt", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); }); }); -Mocha.describe("Math.log", () => { - Mocha.test("Math.log", () => { - isNaN(Math.log(-1.0)); - isFinite(Math.log(-0.0)); - isFinite(Math.log(0.0)); - Math.log(1.0); +Mocha.describe("Array.findIndexWithIndex", () => { + Mocha.test("Array.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; + } + }); + Pervasives.assertEqual(isReScriptFirst, 0); + Pervasives.assertEqual(isTypeScriptFirst, -1); }); }); -Mocha.describe("Math.min", () => { - Mocha.test("Math.min", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); +Mocha.describe("Array.findMap", () => { + Mocha.test("Array.findMap", () => { + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3 + ], n => { + if (n % 2 === 0) { + return n - 2 | 0; + } + + }), 0); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], n => { + if (n % 2 === 0) { + return n - 8 | 0; + } + + }), -6); + Pervasives.assertEqual($$Array.findMap([ + 1, + 2, + 3, + 4, + 5, + 6 + ], param => {}), undefined); + Pervasives.assertEqual($$Array.findMap([], n => { + if (n % 2 === 0) { + return Math.imul(n, n); + } + + }), undefined); }); }); -Mocha.describe("Math.max", () => { - Mocha.test("Math.max", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); +Mocha.describe("Array.findWithIndex", () => { + Mocha.test("Array.findWithIndex", () => { + let array = [ + "TypeScript", + "JavaScript", + "ReScript" + ]; + Pervasives.assertEqual(array.find((item, index) => { + if (index > 1) { + return item === "ReScript"; + } else { + return false; + } + }), "ReScript"); }); }); -Mocha.describe("Math.pow", () => { - Mocha.test("Math.pow", () => { - Math.pow(2.0, 4.0); - Math.pow(3.0, 4.0); +Mocha.describe("Array.flat", () => { + Mocha.test("Array.flat", () => { + Pervasives.assertEqual([ + [1], + [2], + [ + 3, + 4 + ] + ].flat(), [ + 1, + 2, + 3, + 4 + ]); }); }); -Mocha.describe("Math.sin", () => { - Mocha.test("Math.sin", () => { - Math.sin(-0.0); - Math.sin(0.0); - Math.sin(1.0); +Mocha.describe("Array.flatMap", () => { + Mocha.test("Array.flatMap", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.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.describe("Math.tan", () => { - Mocha.test("Math.tan", () => { - Math.tan(-0.0); - Math.tan(0.0); - Math.tan(1.0); +Mocha.describe("Array.flatMapWithIndex", () => { + Mocha.test("Array.flatMapWithIndex", () => { + let array = [ + "ReScript", + "TypeScript", + "JavaScript" + ]; + Pervasives.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.describe("Map.make", () => { - Mocha.test("Map.make", () => { - new Map(); - let map = new Map(); - map.set("lang", "ReScript"); +Mocha.describe("Array.forEach", () => { + Mocha.test("Array.forEach", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach(item => { + console.log(item); + }); }); }); -Mocha.describe("Map.size", () => { - Mocha.test("Map.size", () => { - let map = new Map(); - map.set("someKey", "someValue"); +Mocha.describe("Array.forEachWithIndex", () => { + Mocha.test("Array.forEachWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array.forEach((item, index) => { + console.log("At item " + index.toString() + ": " + item); + }); }); }); -Mocha.describe("Map.keys", () => { - Mocha.test("Map.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.describe("Array.fromInitializer", () => { + Mocha.test("Array.fromInitializer", () => { + Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ + 3, + 4, + 5 + ]); + Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ + 3, + 4, + 5, + 6, + 7, + 8, + 9 + ]); }); }); -Mocha.describe("Dict.get", () => { - Mocha.test("Dict.get", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - let value = dict["someKey"]; - if (value !== undefined) { - console.log(value); - } else { - console.log("Nope, didn't have the key."); - } +Mocha.describe("Array.fromIterator", () => { + Mocha.test("Array.fromIterator", () => { + Pervasives.assertEqual(Array.from(new Map([ + [ + "foo", + 1 + ], + [ + "bar", + 2 + ] + ]).values()), [ + 1, + 2 + ]); }); }); -Mocha.describe("Dict.set", () => { - Mocha.test("Dict.set", () => { - let dict = {}; - dict["someKey"] = "someValue"; +Mocha.describe("Array.get", () => { + Mocha.test("Array.get", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array[0], "Hello"); + Pervasives.assertEqual(array[3], undefined); }); }); -Mocha.describe("Belt.Set", () => { - Mocha.test("Belt.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, [ +Mocha.describe("Array.getUnsafe", () => { + Mocha.test("Array.getUnsafe", () => { + let array = [ 1, - 2 - ]); - let cmp$1 = Primitive_object.compare; - Belt_Id.MakeComparable({ - cmp: cmp$1 - }); + 2, + 3 + ]; + for (let index = 0, index_finish = array.length; index < index_finish; ++index) { + let value = array[index]; + console.log(value); + } }); }); -Mocha.describe("Array.at", () => { - Mocha.test("Array.at", () => { - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(0), "a"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(2), "c"); +Mocha.describe("Array.includes", () => { + Mocha.test("Array.includes", () => { Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(3), undefined); + 1, + 2 + ].includes(1), true); Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-1), "c"); + 1, + 2 + ].includes(3), false); + Pervasives.assertEqual([{ + language: "ReScript" + }].includes({ + language: "ReScript" + }), false); + }); +}); + +Mocha.describe("Array.indexOf", () => { + Mocha.test("Array.indexOf", () => { Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-3), "a"); + 1, + 2 + ].indexOf(2), 1); Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-4), undefined); + 1, + 2 + ].indexOf(3), -1); + Pervasives.assertEqual([{ + language: "ReScript" + }].indexOf({ + language: "ReScript" + }), -1); }); }); -Mocha.describe("Set.clear", () => { - Mocha.test("Set.clear", () => { - let set = new Set(); - set.add("someKey"); - set.clear(); +Mocha.describe("Array.indexOfOpt", () => { + Mocha.test("Array.indexOfOpt", () => { + Pervasives.assertEqual($$Array.indexOfOpt([ + 1, + 2 + ], 2), 1); + Pervasives.assertEqual($$Array.indexOfOpt([ + 1, + 2 + ], 3), undefined); + Pervasives.assertEqual($$Array.indexOfOpt([{ + language: "ReScript" + }], { + language: "ReScript" + }), undefined); }); }); -Mocha.describe("Object.is", () => { - Mocha.test("Object.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([ +Mocha.describe("Array.join", () => { + Mocha.test("Array.join", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); +}); + +Mocha.describe("Array.joinUnsafe", () => { + Mocha.test("Array.joinUnsafe", () => { + Pervasives.assertEqual([ 1, 2, 3 - ], [ + ].join(" -- "), "1 -- 2 -- 3"); + }); +}); + +Mocha.describe("Array.joinWith", () => { + Mocha.test("Array.joinWith", () => { + Pervasives.assertEqual([ + "One", + "Two", + "Three" + ].join(" -- "), "One -- Two -- Three"); + }); +}); + +Mocha.describe("Array.joinWithUnsafe", () => { + Mocha.test("Array.joinWithUnsafe", () => { + Pervasives.assertEqual([ 1, 2, 3 + ].join(" -- "), "1 -- 2 -- 3"); + }); +}); + +Mocha.describe("Array.keepSome", () => { + Mocha.test("Array.keepSome", () => { + Pervasives.assertEqual($$Array.keepSome([ + 1, + undefined, + 3 + ]), [ + 1, + 3 ]); - Primitive_object.equal([ + Pervasives.assertEqual($$Array.keepSome([ 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" - }); + Pervasives.assertEqual($$Array.keepSome([ + undefined, + undefined, + undefined + ]), []); + Pervasives.assertEqual($$Array.keepSome([]), []); }); }); -Mocha.describe("List.size", () => { - Mocha.test("List.size", () => { - List.size({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Array.last", () => { + Mocha.test("Array.last", () => { + Pervasives.assertEqual($$Array.last([ + "Hello", + "Hi", + "Good bye" + ]), "Good bye"); + Pervasives.assertEqual($$Array.last([]), undefined); }); }); -Mocha.describe("List.head", () => { - Mocha.test("List.head", () => { - List.head(/* [] */0); - List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Array.length", () => { + Mocha.test("Array.length", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.length, 2); }); }); -Mocha.describe("List.tail", () => { - Mocha.test("List.tail", () => { - List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - List.tail(/* [] */0); +Mocha.describe("Array.make", () => { + Mocha.test("Array.make", () => { + Pervasives.assertEqual($$Array.make(3, "apple"), [ + "apple", + "apple", + "apple" + ]); + Pervasives.assertEqual($$Array.make(6, 7), [ + 7, + 7, + 7, + 7, + 7, + 7 + ]); }); }); -Mocha.describe("List.make", () => { - Mocha.test("List.make", () => { - List.make(3, 1); +Mocha.describe("Array.map", () => { + Mocha.test("Array.map", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map(greeting => greeting + " to you"); + Pervasives.assertEqual(mappedArray, [ + "Hello to you", + "Hi to you", + "Good bye to you" + ]); }); }); -Mocha.describe("List.drop", () => { - Mocha.test("List.drop", () => { - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); +Mocha.describe("Array.mapWithIndex", () => { + Mocha.test("Array.mapWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); + Pervasives.assertEqual(mappedArray, [ + "Hello at position 0", + "Hi at position 1", + "Good bye at position 2" + ]); }); }); -Mocha.describe("List.take", () => { - Mocha.test("List.take", () => { - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); +Mocha.describe("Array.pop", () => { + Mocha.test("Array.pop", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.pop(), "hello"); + Pervasives.assertEqual(someArray, ["hi"]); }); }); -Mocha.describe("List.flat", () => { - Mocha.test("List.flat", () => { - List.flat({ - hd: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, +Mocha.describe("Array.push", () => { + Mocha.test("Array.push", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay" + ]); + }); +}); + +Mocha.describe("Array.pushMany", () => { + Mocha.test("Array.pushMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.push("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "hi", + "hello", + "yay", + "wehoo" + ]); + }); +}); + +Mocha.describe("Array.reduce", () => { + Mocha.test("Array.reduce", () => { + Pervasives.assertEqual($$Array.reduce([ + 2, + 3, + 4 + ], 1, (a, b) => a + b | 0), 10); + Pervasives.assertEqual($$Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "abcd"); + Pervasives.assertEqual($$Array.reduce([ + 1, + 2, + 3 + ], /* [] */0, List.add), { + hd: 3, tl: { - hd: /* [] */0, + hd: 2, tl: { - hd: { - hd: 3, - tl: /* [] */0 - }, + hd: 1, tl: /* [] */0 } } }); + Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); }); }); -Mocha.describe("List.some", () => { - Mocha.test("List.some", () => { - let isAbove100 = value => value > 100; - List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - List.some({ +Mocha.describe("Array.reduceRight", () => { + Mocha.test("Array.reduceRight", () => { + Pervasives.assertEqual($$Array.reduceRight([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b), "dcba"); + Pervasives.assertEqual($$Array.reduceRight([ + 1, + 2, + 3 + ], /* [] */0, List.add), { hd: 1, tl: { hd: 2, tl: { hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } + tl: /* [] */0 } } - }, isAbove100); + }); + Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); }); }); -Mocha.describe("List.find", () => { - Mocha.test("List.find", () => { - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); +Mocha.describe("Array.reduceRightWithIndex", () => { + Mocha.test("Array.reduceRightWithIndex", () => { + Pervasives.assertEqual($$Array.reduceRightWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); }); }); -Mocha.describe("List.sort", () => { - Mocha.test("List.sort", () => { - List.sort({ +Mocha.describe("Array.reduceWithIndex", () => { + Mocha.test("Array.reduceWithIndex", () => { + Pervasives.assertEqual($$Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); + Pervasives.assertEqual($$Array.reduceWithIndex([ + 1, + 2, + 3 + ], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), { hd: 5, tl: { - hd: 4, + hd: 3, tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } + hd: 1, + tl: /* [] */0 } } - }, Primitive_int.compare); + }); + Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ + hd: v + i | 0, + tl: acc + })), /* [] */0); }); }); -Mocha.describe("Null.null", () => { - Mocha.test("Null.null", () => { - console.log(null); +Mocha.describe("Array.reverse", () => { + Mocha.test("Array.reverse", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.reverse(); + Pervasives.assertEqual(someArray, [ + "hello", + "hi" + ]); }); }); -Mocha.describe("Null.make", () => { - Mocha.test("Null.make", () => {}); +Mocha.describe("Array.set", () => { + Mocha.test("Array.set", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); + }); }); -Mocha.describe("Math.acos", () => { - Mocha.test("Math.acos", () => { - Math.acos(-1.0); - isNaN(Math.acos(-3.0)); +Mocha.describe("Array.setUnsafe", () => { + Mocha.test("Array.setUnsafe", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + array[1] = "Hello"; + Pervasives.assertEqual(array[1], "Hello"); }); }); -Mocha.describe("Math.asin", () => { - Mocha.test("Math.asin", () => { - Math.asin(-1.0); - isNaN(Math.asin(-2.0)); +Mocha.describe("Array.shift", () => { + Mocha.test("Array.shift", () => { + let someArray = [ + "hi", + "hello" + ]; + Pervasives.assertEqual(someArray.shift(), "hi"); + Pervasives.assertEqual(someArray, ["hello"]); }); }); -Mocha.describe("Math.atan", () => { - Mocha.test("Math.atan", () => { - Math.atan(-0.0); - Math.atan(0.0); - Math.atan(1.0); +Mocha.describe("Array.shuffle", () => { + Mocha.test("Array.shuffle", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + $$Array.shuffle(array); + console.log(array); + let array2 = [ + 1, + 2, + 3 + ]; + $$Array.shuffle(array2); + Pervasives.assertEqual(array2.length, 3); }); }); -Mocha.describe("Math.cbrt", () => { - Mocha.test("Math.cbrt", () => { - Math.cbrt(-1.0); - Math.cbrt(-0.0); - Math.cbrt(0.0); +Mocha.describe("Array.slice", () => { + Mocha.test("Array.slice", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1, 3), [ + 2, + 3 + ]); }); }); -Mocha.describe("Math.ceil", () => { - Mocha.test("Math.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.describe("Array.sliceToEnd", () => { + Mocha.test("Array.sliceToEnd", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].slice(1), [ + 2, + 3, + 4 + ]); }); }); -Mocha.describe("Math.cosh", () => { - Mocha.test("Math.cosh", () => { - Math.cosh(-1.0); - Math.cosh(-0.0); - Math.cosh(0.0); +Mocha.describe("Array.some", () => { + Mocha.test("Array.some", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); }); }); -Mocha.describe("Math.log2", () => { - Mocha.test("Math.log2", () => { - isNaN(Math.log2(-2.0)); - isFinite(Math.log2(-0.0)); - isFinite(Math.log2(0.0)); - Math.log2(1.0); +Mocha.describe("Array.someWithIndex", () => { + Mocha.test("Array.someWithIndex", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + Pervasives.assertEqual(array.some((greeting, index) => { + if (greeting === "Hello") { + return index === 0; + } else { + return false; + } + }), true); }); }); -Mocha.describe("Math.sign", () => { - Mocha.test("Math.sign", () => { - Math.sign(3.0); - Math.sign(-3.0); - Math.sign(0.0); +Mocha.describe("Array.sort", () => { + Mocha.test("Array.sort", () => { + let array = [ + 3, + 2, + 1 + ]; + array.sort((a, b) => a - b | 0); + Pervasives.assertEqual(array, [ + 1, + 2, + 3 + ]); }); }); -Mocha.describe("Math.sinh", () => { - Mocha.test("Math.sinh", () => { - Math.sinh(-0.0); - Math.sinh(0.0); - Math.sinh(1.0); +Mocha.describe("Array.toShuffled", () => { + Mocha.test("Array.toShuffled", () => { + let array = [ + "Hello", + "Hi", + "Good bye" + ]; + let shuffledArray = $$Array.toShuffled(array); + console.log(shuffledArray); + Pervasives.assertEqual($$Array.toShuffled([ + 1, + 2, + 3 + ]).length, 3); }); }); -Mocha.describe("Math.sqrt", () => { - Mocha.test("Math.sqrt", () => { - isNaN(Math.sqrt(-1.0)); - Math.sqrt(-0.0); - Math.sqrt(0.0); - Math.sqrt(1.0); - Math.sqrt(9.0); +Mocha.describe("Array.toString", () => { + Mocha.test("Array.toString", () => { + Pervasives.assertEqual([ + 1, + 2, + 3, + 4 + ].toString(), "1,2,3,4"); }); }); -Mocha.describe("Math.tanh", () => { - Mocha.test("Math.tanh", () => { - Math.tanh(-0.0); - Math.tanh(0.0); - Math.tanh(1.0); +Mocha.describe("Array.unsafe_get", () => { + Mocha.test("Array.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.describe("Map.clear", () => { - Mocha.test("Map.clear", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.clear(); +Mocha.describe("Array.unshift", () => { + Mocha.test("Array.unshift", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay"); + Pervasives.assertEqual(someArray, [ + "yay", + "hi", + "hello" + ]); }); }); -Mocha.describe("Int.range", () => { - Mocha.test("Int.range", () => { - Primitive_object.equal(Int.range(3, 6, undefined), [ - 3, - 4, - 5 - ]); - Primitive_object.equal(Int.range(-3, -1, undefined), [ - -3, - -2 - ]); - Primitive_object.equal(Int.range(3, 1, undefined), [ - 3, - 2 - ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2 - }), [ - 3, - 5 - ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 +Mocha.describe("Array.unshiftMany", () => { + Mocha.test("Array.unshiftMany", () => { + let someArray = [ + "hi", + "hello" + ]; + someArray.unshift("yay", "wehoo"); + Pervasives.assertEqual(someArray, [ + "yay", + "wehoo", + "hi", + "hello" ]); - Int.range(3, 6, { - step: -2 - }); }); }); -Mocha.describe("Int.clamp", () => { - Mocha.test("Int.clamp", () => { - Int.clamp(undefined, undefined, 42) === 42; - Int.clamp(50, undefined, 42) === 50; - Int.clamp(undefined, 40, 42) === 40; - Int.clamp(50, 40, 42) === 50; +Mocha.describe("AsyncIterator.done", () => { + Mocha.test("AsyncIterator.done", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } + }); }); }); -Mocha.describe("Float.mod", () => { - Mocha.test("Float.mod", () => {}); -}); - -Mocha.describe("Date.make", () => { - Mocha.test("Date.make", () => { - new Date(); - }); -}); +Mocha.describe("AsyncIterator.forEach", () => { + Mocha.test("AsyncIterator.forEach", () => { + let asyncIterator = ((() => { + var map1 = new Map(); -Mocha.describe("Dict.make", () => { - Mocha.test("Dict.make", () => { - let dict2 = {}; - dict2["someKey"] = 12; - }); -}); + map1.set('first', '1'); + map1.set('second', '2'); -Mocha.describe("Dict.copy", () => { - Mocha.test("Dict.copy", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let dict2 = Object.assign({}, dict); - console.log(Object.keys(dict), Object.keys(dict2)); - }); -}); - -Mocha.describe("Array.pop", () => { - Mocha.test("Array.pop", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.pop(), "hello"); - Pervasives.assertEqual(someArray, ["hi"]); - }); -}); - -Mocha.describe("Array.map", () => { - Mocha.test("Array.map", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map(greeting => greeting + " to you"); - Pervasives.assertEqual(mappedArray, [ - "Hello to you", - "Hi to you", - "Good bye to you" - ]); - }); -}); - -Mocha.describe("Array.get", () => { - Mocha.test("Array.get", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array[0], "Hello"); - Pervasives.assertEqual(array[3], undefined); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + let main = async () => await $$AsyncIterator.forEach(asyncIterator, v => { + if (v !== undefined && v[0] === "second") { + return Pervasives.assertEqual(v[1], "2"); + } + + }); + main(); }); }); -Mocha.describe("Array.set", () => { - Mocha.test("Array.set", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); +Mocha.describe("AsyncIterator.make", () => { + Mocha.test("AsyncIterator.make", () => { + let context = { + contents: 0 + }; + let asyncIterator = $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + return { + done: currentValue >= 3, + value: currentValue + }; + }); + let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { + if (value !== undefined) { + console.log(value); + return; + } + + }); + main(); }); }); -Mocha.describe("String.get", () => { - Mocha.test("String.get", () => { - Primitive_object.equal("ReScript"[0], "R"); - Primitive_object.equal("Hello"[4], "o"); - }); -}); +Mocha.describe("AsyncIterator.next", () => { + Mocha.test("AsyncIterator.next", () => { + let asyncIterator = ((() => { + var map1 = new Map(); -Mocha.describe("Set.delete", () => { - Mocha.test("Set.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); - }); -}); + map1.set('first', '1'); + map1.set('second', '2'); -Mocha.describe("Set.values", () => { - Mocha.test("Set.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())); + 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) { + Pervasives.assertEqual(Option.isNone(match.value), true); + } + + }; + }; + processMyAsyncIterator(); }); }); -Mocha.describe("Result.map", () => { - Mocha.test("Result.map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" +Mocha.describe("AsyncIterator.value", () => { + Mocha.test("AsyncIterator.value", () => { + let context = { + contents: 0 + }; + $$AsyncIterator.make(async () => { + let currentValue = context.contents; + context.contents = currentValue + 1 | 0; + if (currentValue >= 3) { + return $$AsyncIterator.done(undefined); + } else { + return $$AsyncIterator.value(currentValue); + } }); }); }); -Mocha.describe("Result.all", () => { - Mocha.test("Result.all", () => { - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Ok", - _0: 2 - }, - { - TAG: "Ok", - _0: 3 - } +Mocha.describe("Belt.Array.blit", () => { + Mocha.test("Belt.Array.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 ]); - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Error", - _0: 1 - } + Belt_Array.blit(v1, 4, v1, 2, 3); + Primitive_object.equal(v1, [ + 10, + 11, + 14, + 15, + 16, + 15, + 16, + 17 ]); }); }); -Mocha.describe("Option.map", () => { - Mocha.test("Option.map", () => { - Option.map(3, x => Math.imul(x, x)); - Option.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Option.all", () => { - Mocha.test("Option.all", () => { - Option.all([ +Mocha.describe("Belt.Array.cmp", () => { + Mocha.test("Belt.Array.cmp", () => { + Belt_Array.cmp([ 1, - 2, - 3 - ]); - Option.all([ + 3, + 5 + ], [ 1, - undefined - ]); + 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.describe("Object.get", () => { - Mocha.test("Object.get", () => { - Option.isSome(({ - a: 1 - })["toString"]); +Mocha.describe("Belt.Array.concat", () => { + Mocha.test("Belt.Array.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.describe("Object.set", () => { - Mocha.test("Object.set", () => { - ({ - a: 1 - })["a"] = 2; - ({ - a: 1 - })["a"] = undefined; - ({ - a: 1 - })["b"] = 2; +Mocha.describe("Belt.Array.concatMany", () => { + Mocha.test("Belt.Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("List.zipBy", () => { - Mocha.test("List.zipBy", () => { - 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.Array.eq", () => { + Mocha.test("Belt.Array.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("List.every", () => { - Mocha.test("List.every", () => { - let isBelow10 = value => value < 10; - List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); +Mocha.describe("Belt.Array.every", () => { + Mocha.test("Belt.Array.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("List.some2", () => { - Mocha.test("List.some2", () => { - List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); +Mocha.describe("Belt.Array.every2", () => { + Mocha.test("Belt.Array.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.describe("List.equal", () => { - Mocha.test("List.equal", () => { - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - 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.describe("Belt.Array.fill", () => { + Mocha.test("Belt.Array.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.describe("List.unzip", () => { - Mocha.test("List.unzip", () => { - List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - 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.describe("Belt.Array.flatMap", () => { + Mocha.test("Belt.Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Null.getOr", () => { - Mocha.test("Null.getOr", () => { - Null.getOr(null, "Banana"); - Null.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNull("Jane")); - greet(undefined); +Mocha.describe("Belt.Array.forEach", () => { + Mocha.test("Belt.Array.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.describe("Null.mapOr", () => { - Mocha.test("Null.mapOr", () => { - Null.mapOr(3, 0, x => x + 5 | 0); - Null.mapOr(null, 0, x => x + 5 | 0); +Mocha.describe("Belt.Array.forEachWithIndex", () => { + Mocha.test("Belt.Array.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.describe("Math.acosh", () => { - Mocha.test("Math.acosh", () => { - Math.acosh(1.0); - isNaN(Math.acosh(0.5)); +Mocha.describe("Belt.Array.get", () => { + Mocha.test("Belt.Array.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.describe("Math.asinh", () => { - Mocha.test("Math.asinh", () => { - Math.asinh(-1.0); - Math.asinh(-0.0); +Mocha.describe("Belt.Array.getBy", () => { + Mocha.test("Belt.Array.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.describe("Math.atanh", () => { - Mocha.test("Math.atanh", () => { - isNaN(Math.atanh(-2.0)); - isFinite(Math.atanh(-1.0)); - Math.atanh(-0.0); - Math.atanh(0.0); - Math.atanh(0.5); +Mocha.describe("Belt.Array.getIndexBy", () => { + Mocha.test("Belt.Array.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.describe("Math.atan2", () => { - Mocha.test("Math.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.describe("Belt.Array.joinWith", () => { + Mocha.test("Belt.Array.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.describe("Math.expm1", () => { - Mocha.test("Math.expm1", () => { - Math.expm1(-1.0); - Math.expm1(-0.0); +Mocha.describe("Belt.Array.keepMap", () => { + Mocha.test("Belt.Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Math.floor", () => { - Mocha.test("Math.floor", () => { - Math.floor(-45.95); - Math.floor(-45.05); - Math.floor(-0.0); +Mocha.describe("Belt.Array.keepWithIndex", () => { + Mocha.test("Belt.Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("Math.hypot", () => { - Mocha.test("Math.hypot", () => { - Math.hypot(3.0, 4.0); - Math.hypot(3.0, 5.0); - }); +Mocha.describe("Belt.Array.length", () => { + Mocha.test("Belt.Array.length", () => {}); }); -Mocha.describe("Math.log1p", () => { - Mocha.test("Math.log1p", () => { - isNaN(Math.log1p(-2.0)); - isFinite(Math.log1p(-1.0)); - Math.log1p(-0.0); +Mocha.describe("Belt.Array.makeBy", () => { + Mocha.test("Belt.Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Math.log10", () => { - Mocha.test("Math.log10", () => { - isNaN(Math.log10(-2.0)); - isFinite(Math.log10(-0.0)); - isFinite(Math.log10(0.0)); - Math.log10(1.0); +Mocha.describe("Belt.Array.makeUninitialized", () => { + Mocha.test("Belt.Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Math.round", () => { - Mocha.test("Math.round", () => { - Math.round(-20.5); - Math.round(-0.1); - Math.round(0.0); - Math.round(-0.0); +Mocha.describe("Belt.Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt.Array.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.describe("Math.trunc", () => { - Mocha.test("Math.trunc", () => { - Math.trunc(0.123); - Math.trunc(1.999); - Math.trunc(13.37); - Math.trunc(42.84); +Mocha.describe("Belt.Array.map", () => { + Mocha.test("Belt.Array.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Map.delete", () => { - Mocha.test("Map.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.describe("Belt.Array.mapWithIndex", () => { + Mocha.test("Belt.Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Map.values", () => { - Mocha.test("Map.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("Belt.Array.partition", () => { + Mocha.test("Belt.Array.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.describe("Error.name", () => { - Mocha.test("Error.name", () => { - let error = new SyntaxError("Some message here"); - console.log(error.name); +Mocha.describe("Belt.Array.range", () => { + Mocha.test("Belt.Array.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.describe("Error.make", () => { - Mocha.test("Error.make", () => { - let error = new Error("Some message here"); - console.log(error.message); - console.log(error.name); +Mocha.describe("Belt.Array.rangeBy", () => { + Mocha.test("Belt.Array.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.describe("Belt_Int.+", () => { - Mocha.test("Belt_Int.+", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Belt.Array.reduce", () => { + Mocha.test("Belt.Array.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.describe("Belt_Int.-", () => { - Mocha.test("Belt_Int.-", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Belt.Array.reduceReverse", () => { + Mocha.test("Belt.Array.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt_Int.*", () => { - Mocha.test("Belt_Int.*", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Belt.Array.reduceReverse2", () => { + Mocha.test("Belt.Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt_Int./", () => { - Mocha.test("Belt_Int./", () => { - Pervasives.assertEqual(2, 2); +Mocha.describe("Belt.Array.reduceWithIndex", () => { + Mocha.test("Belt.Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Belt.Int.+", () => { - Mocha.test("Belt.Int.+", () => { - Pervasives.assertEqual(4, 4); +Mocha.describe("Belt.Array.reverse", () => { + Mocha.test("Belt.Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt.Int.-", () => { - Mocha.test("Belt.Int.-", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Belt.Array.reverseInPlace", () => { + Mocha.test("Belt.Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt.Int.*", () => { - Mocha.test("Belt.Int.*", () => { - Pervasives.assertEqual(4, 4); - }); -}); - -Mocha.describe("Belt.Int./", () => { - Mocha.test("Belt.Int./", () => { - Pervasives.assertEqual(2, 2); +Mocha.describe("Belt.Array.slice", () => { + Mocha.test("Belt.Array.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.describe("Array.make", () => { - Mocha.test("Array.make", () => { - Pervasives.assertEqual($$Array.make(3, "apple"), [ - "apple", - "apple", - "apple" +Mocha.describe("Belt.Array.sliceToEnd", () => { + Mocha.test("Belt.Array.sliceToEnd", () => { + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2), [ + 12, + 13, + 14, + 15, + 16 ]); - Pervasives.assertEqual($$Array.make(6, 7), [ - 7, - 7, - 7, - 7, - 7, - 7 + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 ]); }); }); -Mocha.describe("Array.fill", () => { - Mocha.test("Array.fill", () => { - let myArray = [ - 1, +Mocha.describe("Belt.Array.some", () => { + Mocha.test("Belt.Array.some", () => { + Belt_Array.some([ 2, 3, 4 - ]; - myArray.fill(9, 1, 3); - Pervasives.assertEqual(myArray, [ - 1, - 9, - 9, - 4 - ]); + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Array.push", () => { - Mocha.test("Array.push", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay" - ]); +Mocha.describe("Belt.Array.some2", () => { + Mocha.test("Belt.Array.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.describe("Array.sort", () => { - Mocha.test("Array.sort", () => { - let array = [ - 3, - 2, - 1 +Mocha.describe("Belt.Array.truncateToLengthUnsafe", () => { + Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" ]; - array.sort((a, b) => a - b | 0); - Pervasives.assertEqual(array, [ - 1, - 2, - 3 + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" ]); }); }); -Mocha.describe("Array.flat", () => { - Mocha.test("Array.flat", () => { - Pervasives.assertEqual([ - [1], - [2], +Mocha.describe("Belt.Array.unzip", () => { + Mocha.test("Belt.Array.unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, + 2 + ], [ 3, 4 ] - ].flat(), [ - 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.describe("Array.join", () => { - Mocha.test("Array.join", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); +Mocha.describe("Belt.Array.zip", () => { + Mocha.test("Belt.Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Array.copy", () => { - Mocha.test("Array.copy", () => { - let myArray = [ - 1, - 2, - 3 - ]; - let copyOfMyArray = myArray.slice(); - Pervasives.assertEqual(copyOfMyArray, [ +Mocha.describe("Belt.Array.zipBy", () => { + Mocha.test("Belt.Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ 1, 2, 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 ]); - Pervasives.assertEqual(myArray === copyOfMyArray, false); }); }); -Mocha.describe("Array.find", () => { - Mocha.test("Array.find", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); +Mocha.describe("Belt.Float.*", () => { + Mocha.test("Belt.Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); }); }); -Mocha.describe("Array.some", () => { - Mocha.test("Array.some", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); +Mocha.describe("Belt.Float.+", () => { + Mocha.test("Belt.Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); }); }); -Mocha.describe("Array.last", () => { - Mocha.test("Array.last", () => { - Pervasives.assertEqual($$Array.last([ - "Hello", - "Hi", - "Good bye" - ]), "Good bye"); - Pervasives.assertEqual($$Array.last([]), undefined); +Mocha.describe("Belt.Float.-", () => { + Mocha.test("Belt.Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); }); }); -Mocha.describe("Type.typeof", () => { - Mocha.test("Type.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..."); - } +Mocha.describe("Belt.Float./", () => { + Mocha.test("Belt.Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); }); }); -Mocha.describe("String.make", () => { - Mocha.test("String.make", () => { - String(3.5) === "3.5"; - String([ - 1, - 2, - 3 - ]) === "1,2,3"; +Mocha.describe("Belt.Float.fromInt", () => { + Mocha.test("Belt.Float.fromInt", () => { + console.log(1 === 1.0); }); }); -Mocha.describe("String.trim", () => { - Mocha.test("String.trim", () => { - " abc def ".trim() === "abc def"; - "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; +Mocha.describe("Belt.Float.fromString", () => { + Mocha.test("Belt.Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); }); }); -Mocha.describe("Set.forEach", () => { - Mocha.test("Set.forEach", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue2"); - set.forEach(value => { - console.log(value); - }); +Mocha.describe("Belt.Float.toInt", () => { + Mocha.test("Belt.Float.toInt", () => { + console.log(true); }); }); -Mocha.describe("Set.toArray", () => { - Mocha.test("Set.toArray", () => { - let set = new Set([ - "apple", - "orange", - "apple", - "banana" - ]); - Array.from(set); +Mocha.describe("Belt.Float.toString", () => { + Mocha.test("Belt.Float.toString", () => { + console.log(String(1.0) === "1.0"); }); }); -Mocha.describe("RegExp.test", () => { - Mocha.test("RegExp.test", () => { - let regexp = new RegExp("\\w+"); - if (regexp.test("ReScript is cool!")) { - console.log("Yay, there's a word in there."); - } - +Mocha.describe("Belt.HashMap", () => { + Mocha.test("Belt.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.describe("RegExp.exec", () => { - Mocha.test("RegExp.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.describe("Belt.HashMap.clear", () => { + Mocha.test("Belt.HashMap.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.describe("Promise.any", () => { - Mocha.test("Promise.any", () => { - let racer = (ms, name) => new Promise((resolve, param) => { - setTimeout(() => resolve(name), ms); +Mocha.describe("Belt.HashMap.copy", () => { + Mocha.test("Belt.HashMap.copy", () => { + let hash = a => a; + let eq = Primitive_object.equal; + let IntHash = Belt_Id.MakeHashable({ + hash: hash, + eq: eq }); - 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(); + 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.describe("Belt.HashMap.forEach", () => { + Mocha.test("Belt.HashMap.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.describe("Promise.all", () => { - Mocha.test("Promise.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.describe("Belt.HashMap.fromArray", () => { + Mocha.test("Belt.HashMap.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.describe("Object.make", () => { - Mocha.test("Object.make", () => { - let x = {}; - Object.keys(x).length; - Option.isSome(x["toString"]); +Mocha.describe("Belt.HashMap.get", () => { + Mocha.test("Belt.HashMap.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.describe("Object.seal", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1551, - 7 - ], - Error: new Error() - }; - } - - } - point["x"] = 13; +Mocha.describe("Belt.HashMap.getBucketHistogram", () => { + Mocha.test("Belt.HashMap.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.describe("List.length", () => { - Mocha.test("List.length", () => { - List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt.HashMap.has", () => { + Mocha.test("Belt.HashMap.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.describe("List.getExn", () => { - Mocha.test("List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.assertEqual(List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = 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", - 1580, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt.HashMap.isEmpty", () => { + Mocha.test("Belt.HashMap.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.describe("List.concat", () => { - Mocha.test("List.concat", () => { - List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 +Mocha.describe("Belt.HashMap.keepMapInPlace", () => { + Mocha.test("Belt.HashMap.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.describe("List.reduce", () => { - Mocha.test("List.reduce", () => { - List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item) => acc + item | 0); +Mocha.describe("Belt.HashMap.keysToArray", () => { + Mocha.test("Belt.HashMap.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.describe("List.every2", () => { - Mocha.test("List.every2", () => { - List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); +Mocha.describe("Belt.HashMap.logStats", () => { + Mocha.test("Belt.HashMap.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.describe("List.filter", () => { - Mocha.test("List.filter", () => { - let isEven = x => x % 2 === 0; - List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Option.isSome); - }); -}); +Mocha.describe("Belt.HashMap.make", () => { + Mocha.test("Belt.HashMap.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.describe("Null.getExn", () => { - Mocha.test("Null.getExn", () => { - Pervasives.assertEqual(Null.getExn(3), 3); - let exit = 0; - let value; - try { - value = 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", - 1643, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "ReScript"); - } - let exit$1 = 0; - let val; - try { - val = 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", - 1649, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt.HashMap.mergeMany", () => { + Mocha.test("Belt.HashMap.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.describe("Math.fround", () => { - Mocha.test("Math.fround", () => { - Math.fround(5.5) === 5.5; - Math.fround(5.05) === 5.050000190734863; +Mocha.describe("Belt.HashMap.reduce", () => { + Mocha.test("Belt.HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); }); }); -Mocha.describe("Math.random", () => { - Mocha.test("Math.random", () => { - Math.random(); +Mocha.describe("Belt.HashMap.remove", () => { + Mocha.test("Belt.HashMap.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.describe("Map.forEach", () => { - Mocha.test("Map.forEach", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach(value => { - console.log(value); +Mocha.describe("Belt.HashMap.set", () => { + Mocha.test("Belt.HashMap.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.describe("Map.entries", () => { - Mocha.test("Map.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.describe("Belt.HashMap.size", () => { + Mocha.test("Belt.HashMap.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.describe("Int.toFixed", () => { - Mocha.test("Int.toFixed", () => { - (123456).toFixed(); - (10).toFixed(); - (300).toFixed(4); - (300).toFixed(1); +Mocha.describe("Belt.HashMap.toArray", () => { + Mocha.test("Belt.HashMap.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.describe("Int.toFloat", () => { - Mocha.test("Int.toFloat", () => {}); +Mocha.describe("Belt.HashMap.valuesToArray", () => { + Mocha.test("Belt.HashMap.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("Float.isNaN", () => { - Mocha.test("Float.isNaN", () => { - isNaN(3.0); - isNaN(NaN); +Mocha.describe("Belt.HashSet", () => { + Mocha.test("Belt.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.describe("Float.toInt", () => { - Mocha.test("Float.toInt", () => {}); +Mocha.describe("Belt.Int.*", () => { + Mocha.test("Belt.Int.*", () => { + Pervasives.assertEqual(4, 4); + }); }); -Mocha.describe("Float.clamp", () => { - Mocha.test("Float.clamp", () => { - Float.clamp(undefined, undefined, 4.2) === 4.2; - Float.clamp(4.3, undefined, 4.2) === 4.3; - Float.clamp(undefined, 4.1, 4.2) === 4.1; - Float.clamp(4.3, 4.1, 4.2) === 4.3; +Mocha.describe("Belt.Int.+", () => { + Mocha.test("Belt.Int.+", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Error.stack", () => { - Mocha.test("Error.stack", () => { - let error = new Error("error"); - console.log(error.stack); +Mocha.describe("Belt.Int.-", () => { + Mocha.test("Belt.Int.-", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Error.raise", () => { - Mocha.test("Error.raise", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); +Mocha.describe("Belt.Int./", () => { + Mocha.test("Belt.Int./", () => { + Pervasives.assertEqual(2, 2); }); }); -Mocha.describe("Error.panic", () => { - Mocha.test("Error.panic", () => { - try { - $$Error.panic("Uh oh. This was unexpected!"); - } catch (raw_obj) { - let obj = Primitive_exceptions.internalToException(raw_obj); - if (obj.RE_EXN_ID === 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", - 1799, - 15 - ], - Error: new Error() - }; - } - - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1800, - 12 - ], - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 1802, - 7 - ], - Error: new Error() - }; - } - } +Mocha.describe("Belt.Int.fromFloat", () => { + Mocha.test("Belt.Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Date.getDay", () => { - Mocha.test("Date.getDay", () => { - new Date("2023-02-20T16:40:00.00").getDay(); +Mocha.describe("Belt.Int.fromString", () => { + Mocha.test("Belt.Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); }); }); -Mocha.describe("Date.toJSON", () => { - Mocha.test("Date.toJSON", () => { - new Date("2023-01-01T00:00:00.00+00:00").toJSON(); - new Date("").toJSON(); +Mocha.describe("Belt.Int.toFloat", () => { + Mocha.test("Belt.Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); }); }); -Mocha.describe("Dict.delete", () => { - Mocha.test("Dict.delete", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - Dict.$$delete(dict, "someKey"); +Mocha.describe("Belt.Int.toString", () => { + Mocha.test("Belt.Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); }); }); -Mocha.describe("Dict.assign", () => { - Mocha.test("Dict.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.describe("Belt.List.add", () => { + Mocha.test("Belt.List.add", () => { + Belt_List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); }); }); -Mocha.describe("Console.dir", () => { - Mocha.test("Console.dir", () => { - console.dir({ - language: "rescript", - version: "10.1.2" - }); +Mocha.describe("Belt.List.cmp", () => { + Mocha.test("Belt.List.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.describe("Console.log", () => { - Mocha.test("Console.log", () => { - console.log("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.log(obj); +Mocha.describe("Belt.List.cmpByLength", () => { + Mocha.test("Belt.List.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.describe("Belt_Set.eq", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); - }); -}); - -Mocha.describe("Belt.Option", () => { - Mocha.test("Belt.Option", () => {}); -}); - -Mocha.describe("Belt.Set.eq", () => { - Mocha.test("Belt.Set.eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.concat", () => { + Mocha.test("Belt.List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); - }); -}); - -Mocha.describe("Array.shift", () => { - Mocha.test("Array.shift", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.shift(), "hi"); - Pervasives.assertEqual(someArray, ["hello"]); }); }); -Mocha.describe("Array.slice", () => { - Mocha.test("Array.slice", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1, 3), [ - 2, - 3 +Mocha.describe("Belt.List.concatMany", () => { + Mocha.test("Belt.List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } ]); }); }); -Mocha.describe("Array.every", () => { - Mocha.test("Array.every", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Pervasives.assertEqual(array.every(num => num <= 4), true); - Pervasives.assertEqual(array.every(num => num === 1), false); - }); -}); - -Mocha.describe("String.match", () => { - Mocha.test("String.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.describe("Belt.List.drop", () => { + Mocha.test("Belt.List.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.describe("String.slice", () => { - Mocha.test("String.slice", () => { - "abcdefg".slice(2, 5) === "cde"; - "abcdefg".slice(2, 9) === "cdefg"; - "abcdefg".slice(-4, -2) === "de"; - "abcdefg".slice(5, 1) === ""; +Mocha.describe("Belt.List.eq", () => { + Mocha.test("Belt.List.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.describe("String.split", () => { - Mocha.test("String.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.describe("Belt.List.every", () => { + Mocha.test("Belt.List.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.describe("Result.mapOr", () => { - Mocha.test("Result.mapOr", () => { - Result.mapOr({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Result.mapOr({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; - }); -}); - -Mocha.describe("Result.getOr", () => { - Mocha.test("Result.getOr", () => { - Result.getOr({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Result.getOr({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); -}); - -Mocha.describe("Result.equal", () => { - Mocha.test("Result.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; - Result.equal(good1, good2, mod10equal) === true; - Result.equal(good1, bad1, mod10equal) === false; - Result.equal(bad2, good2, mod10equal) === false; - Result.equal(bad1, bad2, mod10equal) === true; - }); -}); - -Mocha.describe("Promise.make", () => { - Mocha.test("Promise.make", () => { - $$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.describe("Promise.then", () => { - Mocha.test("Promise.then", () => { - Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { - console.log("Your lucky number is: ", num); - return Promise.resolve(); - }); - }); -}); - -Mocha.describe("Promise.race", () => { - Mocha.test("Promise.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.describe("Option.mapOr", () => { - Mocha.test("Option.mapOr", () => { - Option.mapOr(3, 0, x => x + 5 | 0); - Option.mapOr(undefined, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Option.getOr", () => { - Mocha.test("Option.getOr", () => { - Option.getOr(undefined, "Banana"); - Option.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); - }); -}); - -Mocha.describe("Option.equal", () => { - Mocha.test("Option.equal", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Option.equal(3, 15, clockEqual); - Option.equal(3, undefined, clockEqual); - Option.equal(undefined, 3, clockEqual); - Option.equal(undefined, undefined, clockEqual); - }); -}); - -Mocha.describe("Nullable.map", () => { - Mocha.test("Nullable.map", () => { - Nullable.map(3, x => Math.imul(x, x)); - Nullable.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("List.headExn", () => { - Mocha.test("List.headExn", () => { - Pervasives.assertEqual(List.headExn({ +Mocha.describe("Belt.List.every2", () => { + Mocha.test("Belt.List.every2", () => { + Belt_List.every2({ hd: 1, tl: { hd: 2, @@ -2436,130 +2890,113 @@ Mocha.describe("List.headExn", () => { tl: /* [] */0 } } - }), 1); - let exit = 0; - let val; - try { - val = 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", - 2188, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("List.tailExn", () => { - Mocha.test("List.tailExn", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, + }, { + hd: 0, tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } + 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 } - }); - let exit = 0; - let val; - try { - val = List.tailExn(/* [] */0); - exit = 1; - } catch (raw_exn) { - let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID !== "Not_found") { - throw exn; + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 } - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 2202, - 7 - ], - Error: new Error() - }; - } - + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); }); }); -Mocha.describe("List.splitAt", () => { - Mocha.test("List.splitAt", () => { - List.splitAt({ - hd: "Hello", +Mocha.describe("Belt.List.filter", () => { + Mocha.test("Belt.List.filter", () => { + let isEven = x => x % 2 === 0; + Belt_List.filter({ + hd: 1, tl: { - hd: "World", - tl: /* [] */0 + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - }, 1); - List.splitAt({ - hd: 0, + }, isEven); + Belt_List.filter({ + hd: undefined, tl: { - hd: 1, + hd: 2, tl: { - hd: 2, + hd: 3, tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } + hd: undefined, + tl: /* [] */0 } } } - }, 2); + }, Belt_Option.isSome); }); }); -Mocha.describe("List.toArray", () => { - Mocha.test("List.toArray", () => { - List.toArray({ +Mocha.describe("Belt.List.filterWithIndex", () => { + Mocha.test("Belt.List.filterWithIndex", () => { + Belt_List.filterWithIndex({ hd: 1, tl: { hd: 2, tl: { hd: 3, - tl: /* [] */0 + tl: { + hd: 4, + tl: /* [] */0 + } } } - }); + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("List.reverse", () => { - Mocha.test("List.reverse", () => { - List.reverse({ - hd: 1, +Mocha.describe("Belt.List.flatten", () => { + Mocha.test("Belt.List.flatten", () => { + Belt_List.flatten({ + hd: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, tl: { - hd: 2, + hd: /* [] */0, tl: { - hd: 3, + hd: { + hd: 3, + tl: /* [] */0 + }, tl: /* [] */0 } } @@ -2567,9 +3004,9 @@ Mocha.describe("List.reverse", () => { }); }); -Mocha.describe("List.forEach", () => { - Mocha.test("List.forEach", () => { - List.forEach({ +Mocha.describe("Belt.List.forEach", () => { + Mocha.test("Belt.List.forEach", () => { + Belt_List.forEach({ hd: "a", tl: { hd: "b", @@ -2584,78 +3021,186 @@ Mocha.describe("List.forEach", () => { }); }); -Mocha.describe("List.reduce2", () => { - Mocha.test("List.reduce2", () => { - List.reduce2({ - hd: 1, +Mocha.describe("Belt.List.forEach2", () => { + Mocha.test("Belt.List.forEach2", () => { + Belt_List.forEach2({ + hd: "Z", tl: { - hd: 2, + hd: "Y", + tl: /* [] */0 + } + }, { + hd: "A", + tl: { + hd: "B", tl: { - hd: 3, + hd: "C", tl: /* [] */0 } } - }, { - hd: 4, + }, (x, y) => { + console.log(x, y); + }); + }); +}); + +Mocha.describe("Belt.List.forEachWithIndex", () => { + Mocha.test("Belt.List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", tl: { - hd: 5, - tl: /* [] */0 + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); }); }); -Mocha.describe("List.compare", () => { - Mocha.test("List.compare", () => { - List.compare({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, +Mocha.describe("Belt.List.fromArray", () => { + Mocha.test("Belt.List.fromArray", () => { + Belt_List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("Belt.List.get", () => { + Mocha.test("Belt.List.get", () => { + let abc = { + hd: "A", tl: { - hd: 7, - tl: /* [] */0 + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } } - }, Primitive_int.compare); - List.compare({ - hd: 5, + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); + }); +}); + +Mocha.describe("Belt.List.getAssoc", () => { + Mocha.test("Belt.List.getAssoc", () => { + Belt_List.getAssoc({ + hd: [ + 1, + "a" + ], tl: { - hd: 3, - tl: /* [] */0 + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - List.compare({ - hd: 1, + }, 3, (a, b) => a === b); + Belt_List.getAssoc({ + hd: [ + 9, + "morning" + ], tl: { - hd: 3, + hd: [ + 15, + "afternoon" + ], tl: { - hd: 5, + hd: [ + 22, + "night" + ], tl: /* [] */0 } } - }, { + }, 15, (k, item) => k === item); + }); +}); + +Mocha.describe("Belt.List.getBy", () => { + Mocha.test("Belt.List.getBy", () => { + Belt_List.getBy({ hd: 1, tl: { hd: 4, tl: { - hd: 2, - tl: /* [] */0 + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } } } - }, Primitive_int.compare); - List.compare({ + }, x => x > 3); + Belt_List.getBy({ hd: 1, tl: { - hd: 3, + hd: 4, tl: { - hd: 5, + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); +}); + +Mocha.describe("Belt.List.getExn", () => { + Mocha.test("Belt.List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", tl: /* [] */0 } } - }, { + }; + Pervasives.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", + 2266, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt.List.has", () => { + Mocha.test("Belt.List.has", () => { + Belt_List.has({ hd: 1, tl: { hd: 2, @@ -2664,401 +3209,522 @@ Mocha.describe("List.compare", () => { tl: /* [] */0 } } - }, Primitive_int.compare); - List.compare({ + }, 2, (a, b) => a === b); + Belt_List.has({ hd: 1, tl: { - hd: 3, + hd: 2, tl: { - hd: 5, + hd: 3, tl: /* [] */0 } } - }, { - hd: 1, + }, 4, (a, b) => a === b); + Belt_List.has({ + hd: -1, tl: { - hd: 3, + hd: -2, tl: { - hd: 5, + hd: -3, tl: /* [] */0 } } - }, Primitive_int.compare); - }); -}); - -Mocha.describe("Null.forEach", () => { - Mocha.test("Null.forEach", () => { - Null.forEach("thing", x => { - console.log(x); - }); - Null.forEach(null, x => { - console.log(x); - }); + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); }); }); -Mocha.describe("Null.flatMap", () => { - Mocha.test("Null.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; +Mocha.describe("Belt.List.hasAssoc", () => { + Mocha.test("Belt.List.hasAssoc", () => { + Belt_List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } } - }; - Null.flatMap(2, addIfAboveOne); - Null.flatMap(-4, addIfAboveOne); - Null.flatMap(null, addIfAboveOne); + }, 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.describe("Math.minMany", () => { - Mocha.test("Math.minMany", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - isFinite(Math.min()); +Mocha.describe("Belt.List.head", () => { + Mocha.test("Belt.List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Math.maxMany", () => { - Mocha.test("Math.maxMany", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - isFinite(Math.max()); +Mocha.describe("Belt.List.headExn", () => { + Mocha.test("Belt.List.headExn", () => { + Pervasives.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", + 2315, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Math.Int.abs", () => { - Mocha.test("Math.Int.abs", () => { - Math.abs(-2); - Math.abs(3); +Mocha.describe("Belt.List.keep", () => { + Mocha.test("Belt.List.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.describe("Math.Int.min", () => { - Mocha.test("Math.Int.min", () => { - Math.min(1, 2); - Math.min(-1, -2); +Mocha.describe("Belt.List.keepMap", () => { + Mocha.test("Belt.List.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.describe("Math.Int.max", () => { - Mocha.test("Math.Int.max", () => { - Math.max(1, 2); - Math.max(-1, -2); +Mocha.describe("Belt.List.keepWithIndex", () => { + Mocha.test("Belt.List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("Math.Int.pow", () => { - Mocha.test("Math.Int.pow", () => { - Math.pow(2, 4); - Math.pow(3, 4); +Mocha.describe("Belt.List.length", () => { + Mocha.test("Belt.List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Int.toString", () => { - Mocha.test("Int.toString", () => { - (1000).toString(); - (-1000).toString(); - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); +Mocha.describe("Belt.List.make", () => { + Mocha.test("Belt.List.make", () => { + Belt_List.make(3, 1); }); }); -Mocha.describe("Date.getTime", () => { - Mocha.test("Date.getTime", () => { - new Date("2023-02-20").getTime(); +Mocha.describe("Belt.List.makeBy", () => { + Mocha.test("Belt.List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); }); }); -Mocha.describe("Date.getDate", () => { - Mocha.test("Date.getDate", () => { - new Date("2023-02-20T16:40:00.00").getDate(); +Mocha.describe("Belt.List.map", () => { + Mocha.test("Belt.List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); }); }); -Mocha.describe("Date.setDate", () => { - Mocha.test("Date.setDate", () => { - new Date("2023-02-20T16:40:00.00").setDate(1); +Mocha.describe("Belt.List.mapReverse", () => { + Mocha.test("Belt.List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Dict.toArray", () => { - Mocha.test("Dict.toArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let asArray = Object.entries(dict); - console.log(asArray); +Mocha.describe("Belt.List.mapReverse2", () => { + Mocha.test("Belt.List.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.describe("Dict.forEach", () => { - Mocha.test("Dict.forEach", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEach(dict, value => { - console.log(value); - }); +Mocha.describe("Belt.List.mapWithIndex", () => { + Mocha.test("Belt.List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); }); }); -Mocha.describe("Console.info", () => { - Mocha.test("Console.info", () => { - console.info("Information"); - console.info([ - "Hello", - "JS" +Mocha.describe("Belt.List.partition", () => { + Mocha.test("Belt.List.partition", () => { + Pervasives.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.describe("Console.log2", () => { - Mocha.test("Console.log2", () => { - console.log("Hello", "World"); - console.log([ - 1, - 2, - 3 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.log3", () => { - Mocha.test("Console.log3", () => { - console.log("Hello", "World", "ReScript"); - console.log("One", 2, 3); +Mocha.describe("Belt.List.reduce", () => { + Mocha.test("Belt.List.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.describe("Console.log4", () => { - Mocha.test("Console.log4", () => { - console.log("Hello", "World", "ReScript", "!!!"); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); +Mocha.describe("Belt.List.reduce2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Console.log5", () => { - Mocha.test("Console.log5", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); +Mocha.describe("Belt.List.reduceReverse", () => { + Mocha.test("Belt.List.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.describe("Console.log6", () => { - Mocha.test("Console.log6", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); +Mocha.describe("Belt.List.reduceReverse2", () => { + Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Console.time", () => { - Mocha.test("Console.time", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); -}); - -Mocha.describe("Console.warn", () => { - Mocha.test("Console.warn", () => { - console.warn("Warning"); - console.warn([ - "Warning", - "invalid number" - ]); - }); -}); - -Mocha.describe("Belt_Set.has", () => { - Mocha.test("Belt_Set.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); - }); -}); - -Mocha.describe("Belt_Set.add", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); - }); -}); - -Mocha.describe("Belt_Set.get", () => { - Mocha.test("Belt_Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); - }); -}); - -Mocha.describe("Belt_Map.Int", () => { - Mocha.test("Belt_Map.Int", () => {}); -}); - -Mocha.describe("Belt_Map.has", () => { - Mocha.test("Belt_Map.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.describe("Belt.List.reduceWithIndex", () => { + Mocha.test("Belt.List.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.describe("Belt_Map.get", () => { - Mocha.test("Belt_Map.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" - ], - [ +Mocha.describe("Belt.List.removeAssoc", () => { + Mocha.test("Belt.List.removeAssoc", () => { + Belt_List.removeAssoc({ + hd: [ 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp), 2) === undefined; - }); -}); - -Mocha.describe("Belt_Map.set", () => { - Mocha.test("Belt_Map.set", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ - [ - 2, - "2" + "a" ], - [ - 1, - "1" + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + Belt_List.removeAssoc({ + hd: [ + 9, + "morning" ], - [ - 3, - "3" - ] - ], IntCmp); - let s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" - ]); + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); }); }); -Mocha.describe("Belt_List.eq", () => { - Mocha.test("Belt_List.eq", () => { - Belt_List.eq({ +Mocha.describe("Belt.List.reverse", () => { + Mocha.test("Belt.List.reverse", () => { + Belt_List.reverse({ hd: 1, tl: { hd: 2, @@ -3067,73 +3733,134 @@ Mocha.describe("Belt_List.eq", () => { tl: /* [] */0 } } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - Belt_List.eq({ + }); + }); +}); + +Mocha.describe("Belt.List.reverseConcat", () => { + Mocha.test("Belt.List.reverseConcat", () => { + Belt_List.reverseConcat({ hd: 1, tl: { hd: 2, tl: /* [] */0 } }, { - hd: 1, + hd: 3, tl: { - hd: 2, + hd: 4, tl: /* [] */0 } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, + }); + }); +}); + +Mocha.describe("Belt.List.setAssoc", () => { + Mocha.test("Belt.List.setAssoc", () => { + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], tl: { - hd: 2, + hd: [ + 2, + "b" + ], tl: { - hd: 3, + hd: [ + 3, + "c" + ], tl: /* [] */0 } } - }, { - hd: -1, + }, 2, "x", (a, b) => a === b); + Belt_List.setAssoc({ + hd: [ + 1, + "a" + ], tl: { - hd: -2, - tl: { - hd: -3, + 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 } } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }, 15, "afternoon", (a, b) => a % 12 === b % 12); }); }); -Mocha.describe("Belt.HashSet", () => { - Mocha.test("Belt.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.describe("Belt.List.shuffle", () => { + Mocha.test("Belt.List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt.HashMap", () => { - Mocha.test("Belt.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.describe("Belt.List.some", () => { + Mocha.test("Belt.List.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.describe("Belt.List.eq", () => { - Mocha.test("Belt.List.eq", () => { - Belt_List.eq({ +Mocha.describe("Belt.List.some2", () => { + Mocha.test("Belt.List.some2", () => { + Belt_List.some2({ hd: 1, tl: { hd: 2, @@ -3143,2497 +3870,2857 @@ Mocha.describe("Belt.List.eq", () => { } } }, { - hd: 1, + hd: 0, tl: { - hd: 2, + hd: 1, tl: /* [] */0 } - }, (a, b) => a === b); - Belt_List.eq({ + }, (a, b) => a > b); + Belt_List.some2(/* [] */0, { hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 2, tl: { - hd: 2, + hd: 3, tl: /* [] */0 } }, { hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + Belt_List.some2({ + hd: 0, tl: { - hd: 2, + hd: 1, tl: /* [] */0 } - }, (a, b) => a === b); - Belt_List.eq({ - hd: 1, + }, { + hd: 5, tl: { - hd: 2, + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); +}); + +Mocha.describe("Belt.List.sort", () => { + Mocha.test("Belt.List.sort", () => { + Belt_List.sort({ + hd: 5, + tl: { + hd: 4, tl: { - hd: 3, - tl: /* [] */0 + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } } } - }, { - hd: -1, + }, (a, b) => a - b | 0); + }); +}); + +Mocha.describe("Belt.List.splitAt", () => { + Mocha.test("Belt.List.splitAt", () => { + Belt_List.splitAt({ + hd: "Hello", tl: { - hd: -2, + hd: "World", + tl: /* [] */0 + } + }, 1); + Belt_List.splitAt({ + hd: 0, + tl: { + hd: 1, tl: { - hd: -3, - tl: /* [] */0 + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } } - }, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }, 2); }); }); -Mocha.describe("Belt.Set.has", () => { - Mocha.test("Belt.Set.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.tail", () => { + Mocha.test("Belt.List.tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); + Belt_List.tail(/* [] */0); }); }); -Mocha.describe("Belt.Set.add", () => { - Mocha.test("Belt.Set.add", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt.List.tailExn", () => { + Mocha.test("Belt.List.tailExn", () => { + Pervasives.assertEqual(Belt_List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } }); - 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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); + 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", + 2619, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Set.get", () => { - Mocha.test("Belt.Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); +Mocha.describe("Belt.List.take", () => { + Mocha.test("Belt.List.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.describe("Belt.Map.Int", () => { - Mocha.test("Belt.Map.Int", () => {}); +Mocha.describe("Belt.List.toArray", () => { + Mocha.test("Belt.List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); }); -Mocha.describe("Belt.Map.has", () => { - Mocha.test("Belt.Map.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.has(Belt_Map.fromArray([[ +Mocha.describe("Belt.List.unzip", () => { + Mocha.test("Belt.List.unzip", () => { + Belt_List.unzip({ + hd: [ 1, - "1" - ]], IntCmp), 1) === true; + 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.describe("Belt.Map.get", () => { - Mocha.test("Belt.Map.get", () => { +Mocha.describe("Belt.List.zip", () => { + Mocha.test("Belt.List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("Belt.List.zipBy", () => { + Mocha.test("Belt.List.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.Dict.findFirstBy", () => { + Mocha.test("Belt.Map.Dict.findFirstBy", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - Primitive_object.equal(Belt_Map.get(Belt_Map.fromArray([ + let s0 = Belt_MapDict.fromArray([ [ - 2, - "2" + 4, + "4" ], [ 1, "1" ], + [ + 2, + "2" + ], [ 3, "3" ] - ], IntCmp), 2), "2"); - Belt_Map.get(Belt_Map.fromArray([ + ], IntCmp.cmp); + Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); + }); +}); + +Mocha.describe("Belt.Map.Int", () => { + Mocha.test("Belt.Map.Int", () => {}); +}); + +Mocha.describe("Belt.Map.Int.findFirstBy", () => { + Mocha.test("Belt.Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ [ - 2, - "2" + 1, + "one" ], [ - 1, - "1" + 2, + "two" ], [ 3, - "3" + "three" ] - ], IntCmp), 2) === undefined; + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("Belt.Map.set", () => { - Mocha.test("Belt.Map.set", () => { +Mocha.describe("Belt.Map.String.findFirstBy", () => { + Mocha.test("Belt.Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); + }); +}); + +Mocha.describe("Belt.Map.findFirstBy", () => { + Mocha.test("Belt.Map.findFirstBy", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); let s0 = Belt_Map.fromArray([ [ - 2, - "2" + 4, + "4" ], [ 1, "1" ], + [ + 2, + "2" + ], [ 3, - "3" + "" ] ], IntCmp); - let s1 = Belt_Map.set(s0, 2, "3"); - Primitive_object.equal(Belt_Map.valuesToArray(s1), [ - "1", - "3", - "3" + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" ]); }); }); -Mocha.describe("Belt.Float.+", () => { - Mocha.test("Belt.Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); - }); -}); - -Mocha.describe("Belt.Float.-", () => { - Mocha.test("Belt.Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); +Mocha.describe("Belt.Map.forEach", () => { + Mocha.test("Belt.Map.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.describe("Belt.Float.*", () => { - Mocha.test("Belt.Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); +Mocha.describe("Belt.Map.fromArray", () => { + Mocha.test("Belt.Map.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.describe("Belt.Float./", () => { - Mocha.test("Belt.Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); +Mocha.describe("Belt.Map.get", () => { + Mocha.test("Belt.Map.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.describe("Belt_Float.+", () => { - Mocha.test("Belt_Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); +Mocha.describe("Belt.Map.has", () => { + Mocha.test("Belt.Map.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.describe("Belt_Float.-", () => { - Mocha.test("Belt_Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); +Mocha.describe("Belt.Map.isEmpty", () => { + Mocha.test("Belt.Map.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; }); }); -Mocha.describe("Belt_Float.*", () => { - Mocha.test("Belt_Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); +Mocha.describe("Belt.Map.keysToArray", () => { + Mocha.test("Belt.Map.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.describe("Belt_Float./", () => { - Mocha.test("Belt_Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); +Mocha.describe("Belt.Map.make", () => { + Mocha.test("Belt.Map.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.describe("Array.length", () => { - Mocha.test("Array.length", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.length, 2); +Mocha.describe("Belt.Map.reduce", () => { + Mocha.test("Belt.Map.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.describe("Array.concat", () => { - Mocha.test("Array.concat", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = [ - "yay", - "wehoo" - ]; - let someArray = array1.concat(array2); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" +Mocha.describe("Belt.Map.remove", () => { + Mocha.test("Belt.Map.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.describe("Array.filter", () => { - Mocha.test("Array.filter", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].filter(num => num > 2), [ - 3, - 4 +Mocha.describe("Belt.Map.set", () => { + Mocha.test("Belt.Map.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.describe("Array.reduce", () => { - Mocha.test("Array.reduce", () => { - Pervasives.assertEqual($$Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0), 10); - Pervasives.assertEqual($$Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "abcd"); - Pervasives.assertEqual($$Array.reduce([ - 1, - 2, - 3 - ], /* [] */0, List.add), { - hd: 3, - tl: { - hd: 2, - tl: { - hd: 1, - tl: /* [] */0 - } - } +Mocha.describe("Belt.Map.size", () => { + Mocha.test("Belt.Map.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; }); }); -Mocha.describe("String.length", () => { - Mocha.test("String.length", () => {}); -}); - -Mocha.describe("String.charAt", () => { - Mocha.test("String.charAt", () => { - "ReScript".charAt(0) === "R"; - "Hello".charAt(12) === ""; - "JS".charAt(5) === ""; +Mocha.describe("Belt.Map.toArray", () => { + Mocha.test("Belt.Map.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.describe("String.concat", () => { - Mocha.test("String.concat", () => { - "cow".concat("bell") === "cowbell"; - "Re".concat("Script") === "ReScript"; +Mocha.describe("Belt.Map.valuesToArray", () => { + Mocha.test("Belt.Map.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("String.repeat", () => { - Mocha.test("String.repeat", () => { - "ha".repeat(3) === "hahaha"; - "empty".repeat(0) === ""; +Mocha.describe("Belt.MutableSet", () => { + Mocha.test("Belt.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.describe("String.search", () => { - Mocha.test("String.search", () => { - "testing 1 2 3".search(/\d+/) === 8; - "no numbers".search(/\d+/) === -1; +Mocha.describe("Belt.MutableSet.add", () => { + Mocha.test("Belt.MutableSet.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.describe("String.padEnd", () => { - Mocha.test("String.padEnd", () => { - "Hello".padEnd(10, ".") === "Hello....."; - "abc".padEnd(1, "") === "abc"; +Mocha.describe("Belt.MutableSet.copy", () => { + Mocha.test("Belt.MutableSet.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.describe("Set.fromArray", () => { - Mocha.test("Set.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.describe("RegExp.global", () => { - Mocha.test("RegExp.global", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.global); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.global); +Mocha.describe("Belt.MutableSet.diff", () => { + Mocha.test("Belt.MutableSet.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.describe("RegExp.source", () => { - Mocha.test("RegExp.source", () => { - let regexp = new RegExp("\\w+", "g"); - console.log(regexp.source); +Mocha.describe("Belt.MutableSet.eq", () => { + Mocha.test("Belt.MutableSet.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.describe("RegExp.sticky", () => { - Mocha.test("RegExp.sticky", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "my"); - console.log(regexp2.unicode); +Mocha.describe("Belt.MutableSet.every", () => { + Mocha.test("Belt.MutableSet.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.describe("Promise.catch", () => { - Mocha.test("Promise.catch", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - $$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 === 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.describe("Belt.MutableSet.forEach", () => { + Mocha.test("Belt.MutableSet.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.describe("Option.filter", () => { - Mocha.test("Option.filter", () => { - Option.filter(10, x => x > 5); - Option.filter(4, x => x > 5); - Option.filter(undefined, x => x > 5); +Mocha.describe("Belt.MutableSet.fromArray", () => { + Mocha.test("Belt.MutableSet.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.describe("Option.getExn", () => { - Mocha.test("Option.getExn", () => { - Pervasives.assertEqual(Option.getExn(3, undefined), 3); - let exit = 0; - let val; - try { - val = Option.getExn(undefined, undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 3126, - 7 - ], - Error: new Error() - }; - } - let exit$1 = 0; - let val$1; - try { - val$1 = 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", - 3131, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt.MutableSet.get", () => { + Mocha.test("Belt.MutableSet.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.describe("Option.orElse", () => { - Mocha.test("Option.orElse", () => { - Primitive_object.equal(Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Option.orElse(undefined, 1066), 1066); - Option.orElse(undefined, undefined) === undefined; +Mocha.describe("Belt.MutableSet.has", () => { + Mocha.test("Belt.MutableSet.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.describe("Option.isSome", () => { - Mocha.test("Option.isSome", () => { - Option.isSome(undefined); - Option.isSome(1); +Mocha.describe("Belt.MutableSet.intersect", () => { + Mocha.test("Belt.MutableSet.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.describe("Option.isNone", () => { - Mocha.test("Option.isNone", () => { - Option.isNone(undefined); - Option.isNone(1); +Mocha.describe("Belt.MutableSet.isEmpty", () => { + Mocha.test("Belt.MutableSet.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.describe("Object.create", () => { - Mocha.test("Object.create", () => { - let x = { - fruit: "banana" - }; - Object.create(x); +Mocha.describe("Belt.MutableSet.keep", () => { + Mocha.test("Belt.MutableSet.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.describe("Object.assign", () => { - Mocha.test("Object.assign", () => { - Object.assign({ - a: 1 - }, { - a: 2 +Mocha.describe("Belt.MutableSet.maxUndefined", () => { + Mocha.test("Belt.MutableSet.maxUndefined", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Object.assign({ - a: 1, - b: 2 - }, { - a: 0 + 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.describe("Belt.MutableSet.maximum", () => { + Mocha.test("Belt.MutableSet.maximum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Object.assign({ - a: 1 - }, { - a: null + 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.describe("Belt.MutableSet.mergeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("Object.freeze", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 3202, - 7 - ], - Error: new Error() - }; - } - - } +Mocha.describe("Belt.MutableSet.minUndefined", () => { + Mocha.test("Belt.MutableSet.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.describe("Nullable.null", () => { - Mocha.test("Nullable.null", () => { - console.log(null); +Mocha.describe("Belt.MutableSet.minimum", () => { + Mocha.test("Belt.MutableSet.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.describe("Nullable.make", () => { - Mocha.test("Nullable.make", () => { - let myStr = "Hello"; - if ((myStr == null) || myStr !== myStr) { - console.log("Values did not match."); - } else { - console.log("Yay, values matched!"); - } +Mocha.describe("Belt.MutableSet.partition", () => { + Mocha.test("Belt.MutableSet.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.describe("List.forEach2", () => { - Mocha.test("List.forEach2", () => { - 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.describe("Belt.MutableSet.reduce", () => { + Mocha.test("Belt.MutableSet.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.describe("List.getAssoc", () => { - Mocha.test("List.getAssoc", () => { - List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); +Mocha.describe("Belt.MutableSet.remove", () => { + Mocha.test("Belt.MutableSet.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.describe("List.hasAssoc", () => { - Mocha.test("List.hasAssoc", () => { - List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); +Mocha.describe("Belt.MutableSet.removeMany", () => { + Mocha.test("Belt.MutableSet.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.describe("List.setAssoc", () => { - Mocha.test("List.setAssoc", () => { - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); +Mocha.describe("Belt.MutableSet.size", () => { + Mocha.test("Belt.MutableSet.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.describe("Null.toOption", () => { - Mocha.test("Null.toOption", () => { - let nullStr = "Hello"; - if (nullStr !== null) { - console.log("Got string:", nullStr); - } else { - console.log("Didn't have a value."); - } +Mocha.describe("Belt.MutableSet.some", () => { + Mocha.test("Belt.MutableSet.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.describe("Math.Int.imul", () => { - Mocha.test("Math.Int.imul", () => { - Math.imul(3, 4); - Math.imul(-5, 12); +Mocha.describe("Belt.MutableSet.split", () => { + Mocha.test("Belt.MutableSet.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.describe("Math.Int.sign", () => { - Mocha.test("Math.Int.sign", () => { - Math.sign(3); - Math.sign(-3); - Math.sign(0); +Mocha.describe("Belt.MutableSet.subset", () => { + Mocha.test("Belt.MutableSet.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.describe("Math.Int.ceil", () => { - Mocha.test("Math.Int.ceil", () => { - $$Math.Int.ceil(3.7) === 4; - $$Math.Int.ceil(3.0) === 3; - $$Math.Int.ceil(-3.1) === -3; +Mocha.describe("Belt.MutableSet.toArray", () => { + Mocha.test("Belt.MutableSet.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.describe("Map.fromArray", () => { - Mocha.test("Map.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.describe("Belt.MutableSet.toList", () => { + Mocha.test("Belt.MutableSet.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.describe("JSON.parseExn", () => { - Mocha.test("JSON.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 === 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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn$1; - } - } +Mocha.describe("Belt.MutableSet.union", () => { + Mocha.test("Belt.MutableSet.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("Iterator.next", () => { - Mocha.test("Iterator.next", () => { - let iterator = ((() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(iterator.next().done, false); - Pervasives.assertEqual(iterator.next().done, true); - }); +Mocha.describe("Belt.Option", () => { + Mocha.test("Belt.Option", () => {}); }); -Mocha.describe("Int.fromFloat", () => { - Mocha.test("Int.fromFloat", () => {}); +Mocha.describe("Belt.Option.cmp", () => { + Mocha.test("Belt.Option.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.describe("Float.toFixed", () => { - Mocha.test("Float.toFixed", () => { - (123456.0).toFixed(); - (10.0).toFixed(); - (300.0).toFixed(4); - (300.0).toFixed(1); +Mocha.describe("Belt.Option.eq", () => { + Mocha.test("Belt.Option.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.describe("Float.fromInt", () => { - Mocha.test("Float.fromInt", () => {}); +Mocha.describe("Belt.Option.flatMap", () => { + Mocha.test("Belt.Option.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.describe("Error.message", () => { - Mocha.test("Error.message", () => { - let error = new SyntaxError("Some message here"); - console.log(error.message); +Mocha.describe("Belt.Option.forEach", () => { + Mocha.test("Belt.Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); + }); + Belt_Option.forEach(undefined, x => { + console.log(x); + }); }); }); -Mocha.describe("Date.fromTime", () => { - Mocha.test("Date.fromTime", () => { - new Date(0.0); - new Date(-86400000.0); - new Date(86400000.0); +Mocha.describe("Belt.Option.getExn", () => { + Mocha.test("Belt.Option.getExn", () => { + Pervasives.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", + 3572, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Date.getMonth", () => { - Mocha.test("Date.getMonth", () => { - new Date("2023-01-01").getMonth(); +Mocha.describe("Belt.Option.getWithDefault", () => { + Mocha.test("Belt.Option.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.describe("Date.getHours", () => { - Mocha.test("Date.getHours", () => { - new Date("2023-02-20T16:40:00.00").getHours(); +Mocha.describe("Belt.Option.isNone", () => { + Mocha.test("Belt.Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); }); }); -Mocha.describe("Date.setMonth", () => { - Mocha.test("Date.setMonth", () => { - new Date("2023-02-20T16:40:00.00").setMonth(0); +Mocha.describe("Belt.Option.isSome", () => { + Mocha.test("Belt.Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); }); }); -Mocha.describe("Date.setHours", () => { - Mocha.test("Date.setHours", () => { - new Date("2023-02-20T16:40:00.00").setHours(0); +Mocha.describe("Belt.Option.keep", () => { + Mocha.test("Belt.Option.keep", () => { + Belt_Option.keep(10, x => x > 5); + Belt_Option.keep(4, x => x > 5); + Belt_Option.keep(undefined, x => x > 5); }); }); -Mocha.describe("Date.toString", () => { - Mocha.test("Date.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.describe("Belt.Option.map", () => { + Mocha.test("Belt.Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Console.clear", () => { - Mocha.test("Console.clear", () => { - console.clear(); +Mocha.describe("Belt.Option.mapWithDefault", () => { + Mocha.test("Belt.Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("Console.count", () => { - Mocha.test("Console.count", () => { - console.count("rescript"); +Mocha.describe("Belt.Option.orElse", () => { + Mocha.test("Belt.Option.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("Console.debug", () => { - Mocha.test("Console.debug", () => { - console.debug("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.debug(obj); +Mocha.describe("Belt.Range.every", () => { + Mocha.test("Belt.Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); }); }); -Mocha.describe("Console.error", () => { - Mocha.test("Console.error", () => { - console.error("error message"); - console.error([ - "error", - "invalid value" - ]); +Mocha.describe("Belt.Range.everyBy", () => { + Mocha.test("Belt.Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Console.group", () => { - Mocha.test("Console.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.describe("Belt.Range.forEach", () => { + Mocha.test("Belt.Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); }); }); -Mocha.describe("Console.info2", () => { - Mocha.test("Console.info2", () => { - console.info("Info", "failed to download"); - console.info("info", { - name: "ReScript" - }); +Mocha.describe("Belt.Range.some", () => { + Mocha.test("Belt.Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); }); }); -Mocha.describe("Console.info3", () => { - Mocha.test("Console.info3", () => { - console.info("Hello", "World", "ReScript"); - console.info([ - 1, - 2, - 3 - ], 4, 5); +Mocha.describe("Belt.Range.someBy", () => { + Mocha.test("Belt.Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Console.info4", () => { - Mocha.test("Console.info4", () => { - console.info("Hello", "World", "ReScript", /* '!' */33); - console.info([ - 1, - 2, - 3 - ], 4, 5, "lastinfo"); - }); -}); - -Mocha.describe("Console.info5", () => { - Mocha.test("Console.info5", () => { - console.info("Hello", "World", "from", "JS", "!!!"); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); +Mocha.describe("Belt.Result.cmp", () => { + Mocha.test("Belt.Result.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.describe("Console.info6", () => { - Mocha.test("Console.info6", () => { - console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); +Mocha.describe("Belt.Result.eq", () => { + Mocha.test("Belt.Result.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.describe("Console.table", () => { - Mocha.test("Console.table", () => { - console.table({ - language: "rescript", - version: "10.1.2" +Mocha.describe("Belt.Result.flatMap", () => { + Mocha.test("Belt.Result.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.describe("Console.trace", () => { - Mocha.test("Console.trace", () => { - console.trace(); +Mocha.describe("Belt.Result.getExn", () => { + Mocha.test("Belt.Result.getExn", () => { + Pervasives.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", + 3806, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Console.warn2", () => { - Mocha.test("Console.warn2", () => { - console.warn("Hello", "World"); - console.warn([ - 1, - 2, - 3 - ], 4); +Mocha.describe("Belt.Result.getWithDefault", () => { + Mocha.test("Belt.Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("Console.warn3", () => { - Mocha.test("Console.warn3", () => { - console.warn("Hello", "World", "ReScript"); - console.warn([ - 1, - 2, - 3 - ], 4, 5); +Mocha.describe("Belt.Result.map", () => { + Mocha.test("Belt.Result.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.describe("Console.warn4", () => { - Mocha.test("Console.warn4", () => { - console.warn("Hello", "World", "ReScript", "!!!"); - console.warn("first", "second", "third", "fourth"); +Mocha.describe("Belt.Result.mapWithDefault", () => { + Mocha.test("Belt.Result.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("Console.warn5", () => { - Mocha.test("Console.warn5", () => { - console.warn("Hello", "World", "from", "JS", "!!!"); - console.warn([ +Mocha.describe("Belt.Set", () => { + Mocha.test("Belt.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 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" + ]); + let cmp$1 = Primitive_object.compare; + Belt_Id.MakeComparable({ + cmp: cmp$1 }); }); }); -Mocha.describe("Console.warn6", () => { - Mocha.test("Console.warn6", () => { - console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.warn([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Belt_Set.make", () => { - Mocha.test("Belt_Set.make", () => { +Mocha.describe("Belt.Set.Dict.add", () => { + Mocha.test("Belt.Set.Dict.add", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); + 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.describe("Belt_Set.diff", () => { - Mocha.test("Belt_Set.diff", () => { +Mocha.describe("Belt.Set.Dict.diff", () => { + Mocha.test("Belt.Set.Dict.diff", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ + let s0 = Belt_SetDict.fromArray([ 5, 2, 3, 5, 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ 5, 2, 3, 1, 5, 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 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.describe("Belt_Set.some", () => { - Mocha.test("Belt_Set.some", () => { +Mocha.describe("Belt.Set.Dict.empty", () => { + Mocha.test("Belt.Set.Dict.empty", () => {}); +}); + +Mocha.describe("Belt.Set.Dict.eq", () => { + Mocha.test("Belt.Set.Dict.eq", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, + 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.describe("Belt.Set.Dict.every", () => { + Mocha.test("Belt.Set.Dict.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); - Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); + ], IntCmp.cmp); + Belt_SetDict.every(s0, isEven); }); }); -Mocha.describe("Belt_Set.keep", () => { - Mocha.test("Belt_Set.keep", () => { +Mocha.describe("Belt.Set.Dict.forEach", () => { + Mocha.test("Belt.Set.Dict.forEach", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ - 1, + let s0 = Belt_SetDict.fromArray([ + 5, 2, 3, - 4, - 5 - ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 5, + 6 + ], IntCmp.cmp); + let acc = { + contents: /* [] */0 + }; + Belt_SetDict.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + }); +}); + +Mocha.describe("Belt.Set.Dict.fromArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_Set.size", () => { - Mocha.test("Belt_Set.size", () => { +Mocha.describe("Belt.Set.Dict.get", () => { + Mocha.test("Belt.Set.Dict.get", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ + let s0 = Belt_SetDict.fromArray([ 1, 2, 3, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); + 4, + 5 + ], IntCmp.cmp); + Belt_SetDict.get(s0, 3, IntCmp.cmp); + Belt_SetDict.get(s0, 20, IntCmp.cmp); }); }); -Mocha.describe("Belt_Map.make", () => { - Mocha.test("Belt_Map.make", () => { +Mocha.describe("Belt.Set.Dict.has", () => { + Mocha.test("Belt.Set.Dict.has", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let m = Belt_Map.make(IntCmp); - Belt_Map.set(m, 0, "a"); + 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.describe("Belt_Map.size", () => { - Mocha.test("Belt_Map.size", () => { +Mocha.describe("Belt.Set.Dict.intersect", () => { + Mocha.test("Belt.Set.Dict.intersect", () => { 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; + 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.describe("Belt_List.add", () => { - Mocha.test("Belt_List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); +Mocha.describe("Belt.Set.Dict.isEmpty", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_List.get", () => { - Mocha.test("Belt_List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); +Mocha.describe("Belt.Set.Dict.keep", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_List.map", () => { - Mocha.test("Belt_List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); +Mocha.describe("Belt.Set.Dict.maxUndefined", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_List.zip", () => { - Mocha.test("Belt_List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } +Mocha.describe("Belt.Set.Dict.maximum", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_List.cmp", () => { - Mocha.test("Belt_List.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.describe("Belt.Set.Dict.mergeMany", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt_List.has", () => { - Mocha.test("Belt_List.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.describe("Belt.Set.Dict.minUndefined", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.Array.eq", () => { - Mocha.test("Belt.Array.eq", () => { - Belt_Array.eq([ - 1, +Mocha.describe("Belt.Set.Dict.minimum", () => { + Mocha.test("Belt.Set.Dict.minimum", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s1 = Belt_SetDict.fromArray([ + 3, 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); }); }); -Mocha.describe("Belt.List.add", () => { - Mocha.test("Belt.List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); +Mocha.describe("Belt.Set.Dict.partition", () => { + Mocha.test("Belt.Set.Dict.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.describe("Belt.List.get", () => { - Mocha.test("Belt.List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); - }); -}); - -Mocha.describe("Belt.List.map", () => { - Mocha.test("Belt.List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); -}); - -Mocha.describe("Belt.List.zip", () => { - Mocha.test("Belt.List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.cmp", () => { - Mocha.test("Belt.List.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.describe("Belt.List.has", () => { - Mocha.test("Belt.List.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.describe("Belt.Set.make", () => { - Mocha.test("Belt.Set.make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); - }); -}); - -Mocha.describe("Belt.Set.diff", () => { - Mocha.test("Belt.Set.diff", () => { +Mocha.describe("Belt.Set.Dict.reduce", () => { + Mocha.test("Belt.Set.Dict.reduce", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ + let s0 = Belt_SetDict.fromArray([ 5, 2, 3, 5, 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, - 2, - 3, - 1, - 5, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); + ], IntCmp.cmp); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); }); }); -Mocha.describe("Belt.Set.some", () => { - Mocha.test("Belt.Set.some", () => { +Mocha.describe("Belt.Set.Dict.remove", () => { + Mocha.test("Belt.Set.Dict.remove", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ - 1, + let s0 = Belt_SetDict.fromArray([ 2, + 3, + 1, 4, - 6, - 8 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); + 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.describe("Belt.Set.keep", () => { - Mocha.test("Belt.Set.keep", () => { +Mocha.describe("Belt.Set.Dict.removeMany", () => { + Mocha.test("Belt.Set.Dict.removeMany", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ + let set = Belt_SetDict.fromArray([ 1, 2, 3, + 4 + ], IntCmp.cmp); + let newSet = Belt_SetDict.removeMany(set, [ + 5, 4, - 5 - ], IntCmp); - let s1 = Belt_Set.keep(s0, isEven); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 3, 2, - 4 - ]); + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); }); }); -Mocha.describe("Belt.Set.size", () => { - Mocha.test("Belt.Set.size", () => { +Mocha.describe("Belt.Set.Dict.size", () => { + Mocha.test("Belt.Set.Dict.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ + let s0 = Belt_SetDict.fromArray([ 1, 2, 3, 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); + ], IntCmp.cmp); + Belt_SetDict.size(s0); }); }); -Mocha.describe("Belt.Map.make", () => { - Mocha.test("Belt.Map.make", () => { +Mocha.describe("Belt.Set.Dict.some", () => { + Mocha.test("Belt.Set.Dict.some", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let m = Belt_Map.make(IntCmp); - Belt_Map.set(m, 0, "a"); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_SetDict.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp.cmp); + Belt_SetDict.some(s0, isOdd); }); }); -Mocha.describe("Belt.Map.size", () => { - Mocha.test("Belt.Map.size", () => { +Mocha.describe("Belt.Set.Dict.split", () => { + Mocha.test("Belt.Set.Dict.split", () => { 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.describe("Belt_Array.eq", () => { - Mocha.test("Belt_Array.eq", () => { - Belt_Array.eq([ + let s0 = Belt_SetDict.fromArray([ 1, 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + 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.describe("Array.fillAll", () => { - Mocha.test("Array.fillAll", () => { - let myArray = [ - 1, +Mocha.describe("Belt.Set.Dict.subset", () => { + Mocha.test("Belt.Set.Dict.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 - ]; - myArray.fill(9); - Pervasives.assertEqual(myArray, [ - 9, - 9, - 9, - 9 - ]); + ], 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.describe("Array.reverse", () => { - Mocha.test("Array.reverse", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.reverse(); - Pervasives.assertEqual(someArray, [ - "hello", - "hi" - ]); +Mocha.describe("Belt.Set.Dict.toArray", () => { + Mocha.test("Belt.Set.Dict.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.describe("Array.unshift", () => { - Mocha.test("Array.unshift", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay"); - Pervasives.assertEqual(someArray, [ - "yay", - "hi", - "hello" - ]); +Mocha.describe("Belt.Set.Dict.toList", () => { + Mocha.test("Belt.Set.Dict.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.describe("Array.indexOf", () => { - Mocha.test("Array.indexOf", () => { - Pervasives.assertEqual([ +Mocha.describe("Belt.Set.Dict.union", () => { + Mocha.test("Belt.Set.Dict.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.Set.add", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ 1, 2 - ].indexOf(2), 1); - Pervasives.assertEqual([ + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ 1, 2 - ].indexOf(3), -1); - Pervasives.assertEqual([{ - language: "ReScript" - }].indexOf({ - language: "ReScript" - }), -1); + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Array.forEach", () => { - Mocha.test("Array.forEach", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach(item => { - console.log(item); +Mocha.describe("Belt.Set.diff", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); }); }); -Mocha.describe("Array.shuffle", () => { - Mocha.test("Array.shuffle", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - $$Array.shuffle(array); - console.log(array); - let array2 = [ - 1, +Mocha.describe("Belt.Set.eq", () => { + Mocha.test("Belt.Set.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, 3 - ]; - $$Array.shuffle(array2); - Pervasives.assertEqual(array2.length, 3); + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); }); }); -Mocha.describe("Array.flatMap", () => { - Mocha.test("Array.flatMap", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.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, +Mocha.describe("Belt.Set.every", () => { + Mocha.test("Belt.Set.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, - 3, 4, - 5, 6, - 7, - 8, - 9 - ]); + 8 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); }); }); -Mocha.describe("Array.findMap", () => { - Mocha.test("Array.findMap", () => { - Pervasives.assertEqual($$Array.findMap([ - 1, - 2, - 3 - ], n => { - if (n % 2 === 0) { - return n - 2 | 0; - } - - }), 0); - Pervasives.assertEqual($$Array.findMap([ - 1, +Mocha.describe("Belt.Set.forEach", () => { + Mocha.test("Belt.Set.forEach", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, 3, - 4, 5, 6 - ], n => { - if (n % 2 === 0) { - return n - 8 | 0; + ], IntCmp); + let acc = { + contents: /* [] */0 + }; + Belt_Set.forEach(s0, x => { + acc.contents = Belt_List.add(acc.contents, x); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } } - - }), -6); - Pervasives.assertEqual($$Array.findMap([ + }); + }); +}); + +Mocha.describe("Belt.Set.fromArray", () => { + Mocha.test("Belt.Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 3, + 2, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ 1, 2, 3, - 4, - 5, - 6 - ], param => {}), undefined); - Pervasives.assertEqual($$Array.findMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - }), undefined); + 4 + ]); }); }); -Mocha.describe("String.indexOf", () => { - Mocha.test("String.indexOf", () => { - "bookseller".indexOf("ok") === 2; - "bookseller".indexOf("sell") === 4; - "beekeeper".indexOf("ee") === 1; - "bookseller".indexOf("xyz") === -1; +Mocha.describe("Belt.Set.get", () => { + Mocha.test("Belt.Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); }); }); -Mocha.describe("String.replace", () => { - Mocha.test("String.replace", () => { - "old string".replace("old", "new") === "new string"; - "the cat and the dog".replace("the", "this") === "this cat and the dog"; +Mocha.describe("Belt.Set.has", () => { + Mocha.test("Belt.Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, + 2, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); }); }); -Mocha.describe("String.trimEnd", () => { - Mocha.test("String.trimEnd", () => { - " Hello world! ".trimEnd() === " Hello world!"; - " Hello world! ".trimEnd() === " Hello world!"; +Mocha.describe("Belt.Set.intersect", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); }); }); -Mocha.describe("Result.flatMap", () => { - Mocha.test("Result.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(Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 +Mocha.describe("Belt.Set.isEmpty", () => { + Mocha.test("Belt.Set.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Primitive_object.equal(Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + }); +}); + +Mocha.describe("Belt.Set.keep", () => { + Mocha.test("Belt.Set.keep", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Primitive_object.equal(Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" + let isEven = x => x % 2 === 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4, + 5 + ], IntCmp); + let s1 = Belt_Set.keep(s0, isEven); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); + }); +}); + +Mocha.describe("Belt.Set.make", () => { + Mocha.test("Belt.Set.make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); }); }); -Mocha.describe("Result.compare", () => { - Mocha.test("Result.compare", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Result.compare({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; - }); -}); - -Mocha.describe("Result.forEach", () => { - Mocha.test("Result.forEach", () => { - Result.forEach({ - TAG: "Ok", - _0: 3 - }, prim => { - console.log(prim); - }); - Result.forEach({ - TAG: "Error", - _0: "x" - }, prim => { - console.log(prim); +Mocha.describe("Belt.Set.maxUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); }); }); -Mocha.describe("RegExp.unicode", () => { - Mocha.test("RegExp.unicode", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "mu"); - console.log(regexp2.unicode); - }); -}); - -Mocha.describe("Promise.reject", () => { - Mocha.test("Promise.reject", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - $$Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }), v => { - if (v.RE_EXN_ID === TestError) { - Pervasives.assertEqual(v._1, "some rejected value"); - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 4327, - 9 - ], - Error: new Error() - }; - } - return Promise.resolve(); +Mocha.describe("Belt.Set.maximum", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); }); }); -Mocha.describe("Option.forEach", () => { - Mocha.test("Option.forEach", () => { - Option.forEach("thing", x => { - console.log(x); - }); - Option.forEach(undefined, x => { - console.log(x); +Mocha.describe("Belt.Set.mergeMany", () => { + Mocha.test("Belt.Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + 1, + 2, + 3, + 4, + 5 + ]); }); }); -Mocha.describe("Option.flatMap", () => { - Mocha.test("Option.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Option.flatMap(2, addIfAboveOne); - Option.flatMap(-4, addIfAboveOne); - Option.flatMap(undefined, addIfAboveOne); - }); -}); - -Mocha.describe("Option.compare", () => { - Mocha.test("Option.compare", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Option.compare(3, 15, clockCompare); - Option.compare(3, 14, clockCompare); - Option.compare(2, 15, clockCompare); - Option.compare(undefined, 15, clockCompare); - Option.compare(14, undefined, clockCompare); - Option.compare(undefined, undefined, clockCompare); - }); -}); - -Mocha.describe("Nullable.getOr", () => { - Mocha.test("Nullable.getOr", () => { - Nullable.getOr(null, "Banana"); - Nullable.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNullable("Jane")); - greet(undefined); +Mocha.describe("Belt.Set.minUndefined", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); }); }); -Mocha.describe("Nullable.mapOr", () => { - Mocha.test("Nullable.mapOr", () => { - Nullable.mapOr(3, 0, x => x + 5 | 0); - Nullable.mapOr(null, 0, x => x + 5 | 0); +Mocha.describe("Belt.Set.minimum", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); }); }); -Mocha.describe("List.fromArray", () => { - Mocha.test("List.fromArray", () => { - List.fromArray([ +Mocha.describe("Belt.Set.partition", () => { + Mocha.test("Belt.Set.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 + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ + 1, + 3, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 ]); }); }); -Mocha.describe("List.filterMap", () => { - Mocha.test("List.filterMap", () => { - let isEven = x => x % 2 === 0; - List.filterMap({ - hd: 1, +Mocha.describe("Belt.Set.reduce", () => { + Mocha.test("Belt.Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, + 2, + 3, + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, tl: { - hd: 2, + hd: 5, tl: { hd: 3, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, x => { - if (isEven(x)) { - return x; - } - }); - List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); }); }); -Mocha.describe("List.partition", () => { - Mocha.test("List.partition", () => { - List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2); +Mocha.describe("Belt.Set.remove", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 2, + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Null.getUnsafe", () => { - Mocha.test("Null.getUnsafe", () => {}); -}); - -Mocha.describe("Math.hypotMany", () => { - Mocha.test("Math.hypotMany", () => { - Math.hypot(3.0, 4.0, 5.0); - Math.hypot(); +Mocha.describe("Belt.Set.removeMany", () => { + Mocha.test("Belt.Set.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 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); }); }); -Mocha.describe("Math.Int.clz32", () => { - Mocha.test("Math.Int.clz32", () => { - Math.clz32(1); - Math.clz32(4); +Mocha.describe("Belt.Set.size", () => { + Mocha.test("Belt.Set.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.size(s0), 4); }); }); -Mocha.describe("Math.Int.floor", () => { - Mocha.test("Math.Int.floor", () => { - $$Math.Int.floor(3.7) === 3; - $$Math.Int.floor(3.0) === 3; - $$Math.Int.floor(-3.1) === -4; +Mocha.describe("Belt.Set.some", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); }); }); -Mocha.describe("JSON.stringify", () => { - Mocha.test("JSON.stringify", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] +Mocha.describe("Belt.Set.split", () => { + Mocha.test("Belt.Set.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]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 ]); - JSON.stringify(json); - JSON.stringify(json, undefined, 2); - JSON.stringify(json, [ - "foo", - "someNumber" + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); }); }); -Mocha.describe("Int.fromString", () => { - Mocha.test("Int.fromString", () => { - Primitive_object.equal(Int.fromString("0", undefined), 0); - Int.fromString("NaN", undefined) === undefined; - Int.fromString("6", 2) === undefined; +Mocha.describe("Belt.Set.subset", () => { + Mocha.test("Belt.Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); }); }); -Mocha.describe("Float.isFinite", () => { - Mocha.test("Float.isFinite", () => { - isFinite(1.0); - isFinite(NaN); - isFinite(Number.POSITIVE_INFINITY); +Mocha.describe("Belt.Set.toArray", () => { + Mocha.test("Belt.Set.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); }); }); -Mocha.describe("Float.parseInt", () => { - Mocha.test("Float.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.describe("Belt.Set.toList", () => { + Mocha.test("Belt.Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); }); }); -Mocha.describe("Float.toString", () => { - Mocha.test("Float.toString", () => { - (1000.0).toString(); - (-1000.0).toString(); - }); -}); - -Mocha.describe("Date.setHoursM", () => { - Mocha.test("Date.setHoursM", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0); - }); -}); - -Mocha.describe("Date.getUTCDay", () => { - Mocha.test("Date.getUTCDay", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); - }); -}); - -Mocha.describe("Dict.getUnsafe", () => { - Mocha.test("Dict.getUnsafe", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let value = dict["key1"]; - console.log(value); - }); -}); - -Mocha.describe("Dict.fromArray", () => { - Mocha.test("Dict.fromArray", () => { - Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - }); -}); - -Mocha.describe("Dict.mapValues", () => { - Mocha.test("Dict.mapValues", () => { - let dict = Object.fromEntries([ - [ - "key1", - 1 - ], - [ - "key2", - 2 - ] - ]); - Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); - Object.entries(Dict.mapValues(dict, v => v.toString())); - }); -}); - -Mocha.describe("Console.debug2", () => { - Mocha.test("Console.debug2", () => { - console.debug("Hello", "World"); - console.debug([ - 1, - 2, - 3 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.debug3", () => { - Mocha.test("Console.debug3", () => { - console.debug("Hello", "World", "ReScript"); - console.debug("One", 2, 3); - }); -}); - -Mocha.describe("Console.debug4", () => { - Mocha.test("Console.debug4", () => { - console.debug("Hello", "World", "ReScript", "!!!"); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); -}); - -Mocha.describe("Console.debug5", () => { - Mocha.test("Console.debug5", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.debug6", () => { - Mocha.test("Console.debug6", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.error2", () => { - Mocha.test("Console.error2", () => { - console.error("Error", "here"); - console.error([ - "log", - "error" - ], "message"); - }); -}); - -Mocha.describe("Console.error3", () => { - Mocha.test("Console.error3", () => { - console.error("Hello", "World", "!!!"); - console.error("first", "second", "third"); - }); -}); - -Mocha.describe("Console.error4", () => { - Mocha.test("Console.error4", () => { - console.error("Hello", "World", "ReScript", /* '!' */33); - console.error("first", "second", "third", "fourth"); - }); -}); - -Mocha.describe("Console.error5", () => { - Mocha.test("Console.error5", () => { - console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); - console.error(1, "second", "third", "fourth", /* 'c' */99); - }); -}); - -Mocha.describe("Console.error6", () => { - Mocha.test("Console.error6", () => { - console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.error([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Belt_Set.union", () => { - Mocha.test("Belt_Set.union", () => { +Mocha.describe("Belt.Set.union", () => { + Mocha.test("Belt.Set.union", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -5665,281 +6752,324 @@ Mocha.describe("Belt_Set.union", () => { }); }); -Mocha.describe("Belt_Set.every", () => { - Mocha.test("Belt_Set.every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt.SortArray.binarySearchBy", () => { + Mocha.test("Belt.SortArray.binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, 2, + 3, 4, - 6, - 8 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ + 1, + 3, + 5, + 7 + ], 4, Primitive_int.compare)) === 2; }); }); -Mocha.describe("Belt_Set.split", () => { - Mocha.test("Belt_Set.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt.SortArray.strictlySortedLength", () => { + Mocha.test("Belt.SortArray.strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ 1, 2, 3, 4, - 5 - ], IntCmp); - let match = Belt_Set.split(s0, 3); - let match$1 = match[0]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 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, - 5 - ]); + 3, + 2, + 1 + ], (x, y) => x < y) === -4; }); }); -Mocha.describe("Belt_Result.eq", () => { - Mocha.test("Belt_Result.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.describe("Belt_Array.blit", () => { + Mocha.test("Belt_Array.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.describe("Belt_Option.eq", () => { - Mocha.test("Belt_Option.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.describe("Belt_Array.cmp", () => { + Mocha.test("Belt_Array.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.describe("Belt_List.head", () => { - Mocha.test("Belt_List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt_Array.concat", () => { + Mocha.test("Belt_Array.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.describe("Belt_List.tail", () => { - Mocha.test("Belt_List.tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); +Mocha.describe("Belt_Array.concatMany", () => { + Mocha.test("Belt_Array.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Belt_List.make", () => { - Mocha.test("Belt_List.make", () => { - Belt_List.make(3, 1); +Mocha.describe("Belt_Array.eq", () => { + Mocha.test("Belt_Array.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Belt_List.drop", () => { - Mocha.test("Belt_List.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.describe("Belt_Array.every", () => { + Mocha.test("Belt_Array.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_List.take", () => { - Mocha.test("Belt_List.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.describe("Belt_Array.every2", () => { + Mocha.test("Belt_Array.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.describe("Belt_List.some", () => { - Mocha.test("Belt_List.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.describe("Belt_Array.fill", () => { + Mocha.test("Belt_Array.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.describe("Belt_List.keep", () => { - Mocha.test("Belt_List.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.describe("Belt_Array.flatMap", () => { + Mocha.test("Belt_Array.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Belt_List.sort", () => { - Mocha.test("Belt_List.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.describe("Belt_Array.forEach", () => { + Mocha.test("Belt_Array.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.describe("Belt.Array.get", () => { - Mocha.test("Belt.Array.get", () => { +Mocha.describe("Belt_Array.forEachWithIndex", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.get", () => { + Mocha.test("Belt_Array.get", () => { Primitive_object.equal(Belt_Array.get([ "a", "b", @@ -5958,1284 +7088,1226 @@ Mocha.describe("Belt.Array.get", () => { }); }); -Mocha.describe("Belt.Array.zip", () => { - Mocha.test("Belt.Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ +Mocha.describe("Belt_Array.getBy", () => { + Mocha.test("Belt_Array.getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ 1, - 2 - ], [ - 3, 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; }); }); -Mocha.describe("Belt.Array.map", () => { - Mocha.test("Belt.Array.map", () => { - Primitive_object.equal(Belt_Array.map([ +Mocha.describe("Belt_Array.getIndexBy", () => { + Mocha.test("Belt_Array.getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ 1, - 2 - ], x => x + 1 | 0), [ + 4, 3, - 4 - ]); + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; }); }); -Mocha.describe("Belt.Array.cmp", () => { - Mocha.test("Belt.Array.cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ +Mocha.describe("Belt_Array.joinWith", () => { + Mocha.test("Belt_Array.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.describe("Belt_Array.keepMap", () => { + Mocha.test("Belt_Array.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ 1, - 3, - 5 - ], [ + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); + }); +}); + +Mocha.describe("Belt_Array.keepWithIndex", () => { + Mocha.test("Belt_Array.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ 1, 2, 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_Array.length", () => { + Mocha.test("Belt_Array.length", () => {}); +}); + +Mocha.describe("Belt_Array.makeBy", () => { + Mocha.test("Belt_Array.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, 1, + 2, 3, - 5 - ], [ + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, 1, - 3, - 5 - ], Primitive_int.compare) === 0; + 4, + 9, + 16 + ]); }); }); -Mocha.describe("Belt.List.head", () => { - Mocha.test("Belt.List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt_Array.makeUninitialized", () => { + Mocha.test("Belt_Array.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Belt.List.tail", () => { - Mocha.test("Belt.List.tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); +Mocha.describe("Belt_Array.makeUninitializedUnsafe", () => { + Mocha.test("Belt_Array.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.describe("Belt.List.make", () => { - Mocha.test("Belt.List.make", () => { - Belt_List.make(3, 1); +Mocha.describe("Belt_Array.map", () => { + Mocha.test("Belt_Array.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Belt.List.drop", () => { - Mocha.test("Belt.List.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.describe("Belt_Array.mapWithIndex", () => { + Mocha.test("Belt_Array.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Belt.List.take", () => { - Mocha.test("Belt.List.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.describe("Belt_Array.partition", () => { + Mocha.test("Belt_Array.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.describe("Belt.List.some", () => { - Mocha.test("Belt.List.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.describe("Belt_Array.range", () => { + Mocha.test("Belt_Array.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.describe("Belt.List.keep", () => { - Mocha.test("Belt.List.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.describe("Belt.List.sort", () => { - Mocha.test("Belt.List.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.describe("Belt.Set.union", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, +Mocha.describe("Belt_Array.rangeBy", () => { + Mocha.test("Belt_Array.rangeBy", () => { + Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ + 0, 3, - 4, - 5, - 6 + 6, + 9 ]); - }); -}); - -Mocha.describe("Belt.Set.every", () => { - Mocha.test("Belt.Set.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, + Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ + 0, + 3, 6, - 8 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); + 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.describe("Belt.Set.split", () => { - Mocha.test("Belt.Set.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, +Mocha.describe("Belt_Array.reduce", () => { + Mocha.test("Belt_Array.reduce", () => { + Belt_Array.reduce([ 2, 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.split(s0, 3); - let match$1 = match[0]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Option.eq", () => { - Mocha.test("Belt.Option.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.describe("Belt.Result.eq", () => { - Mocha.test("Belt.Result.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; + 4 + ], 1, (a, b) => a + b | 0) === 10; + Belt_Array.reduce([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "abcd"; }); }); -Mocha.describe("Belt_Array.get", () => { - Mocha.test("Belt_Array.get", () => { - Primitive_object.equal(Belt_Array.get([ - "a", - "b", - "c" - ], 0), "a"); - Belt_Array.get([ - "a", - "b", - "c" - ], 3) === undefined; - Belt_Array.get([ +Mocha.describe("Belt_Array.reduceReverse", () => { + Mocha.test("Belt_Array.reduceReverse", () => { + Belt_Array.reduceReverse([ "a", "b", - "c" - ], -1) === undefined; + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt_Array.zip", () => { - Mocha.test("Belt_Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ +Mocha.describe("Belt_Array.reduceReverse2", () => { + Mocha.test("Belt_Array.reduceReverse2", () => { + Belt_Array.reduceReverse2([ 1, - 2 + 2, + 3 ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_Array.map", () => { - Mocha.test("Belt_Array.map", () => { - Primitive_object.equal(Belt_Array.map([ 1, 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt_Array.cmp", () => { - Mocha.test("Belt_Array.cmp", () => { - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, - 4, - 2 - ], Primitive_int.compare) === -1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ +Mocha.describe("Belt_Array.reduceWithIndex", () => { + Mocha.test("Belt_Array.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ 1, 2, - 3 - ], Primitive_int.compare) === 1; - Belt_Array.cmp([ - 1, - 3, - 5 - ], [ - 1, 3, - 5 - ], Primitive_int.compare) === 0; + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Array.pushMany", () => { - Mocha.test("Array.pushMany", () => { - let someArray = [ - "hi", - "hello" +Mocha.describe("Belt_Array.reverse", () => { + Mocha.test("Belt_Array.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); + }); +}); + +Mocha.describe("Belt_Array.reverseInPlace", () => { + Mocha.test("Belt_Array.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 ]; - someArray.push("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 ]); }); }); -Mocha.describe("Array.includes", () => { - Mocha.test("Array.includes", () => { - Pervasives.assertEqual([ - 1, - 2 - ].includes(1), true); - Pervasives.assertEqual([ - 1, - 2 - ].includes(3), false); - Pervasives.assertEqual([{ - language: "ReScript" - }].includes({ - language: "ReScript" - }), false); +Mocha.describe("Belt_Array.slice", () => { + Mocha.test("Belt_Array.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.describe("Array.joinWith", () => { - Mocha.test("Array.joinWith", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); +Mocha.describe("Belt_Array.sliceToEnd", () => { + Mocha.test("Belt_Array.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.describe("Array.toString", () => { - Mocha.test("Array.toString", () => { - Pervasives.assertEqual([ - 1, +Mocha.describe("Belt_Array.some", () => { + Mocha.test("Belt_Array.some", () => { + Belt_Array.some([ 2, 3, 4 - ].toString(), "1,2,3,4"); + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Array.keepSome", () => { - Mocha.test("Array.keepSome", () => { - Pervasives.assertEqual($$Array.keepSome([ - 1, - undefined, - 3 - ]), [ +Mocha.describe("Belt_Array.some2", () => { + Mocha.test("Belt_Array.some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ 1, + 0, 3 - ]); - Pervasives.assertEqual($$Array.keepSome([ - 1, + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ 2, 3 - ]), [ + ], [ 1, - 2, - 3 + 4 + ], (x, y) => x > y) === true; + }); +}); + +Mocha.describe("Belt_Array.truncateToLengthUnsafe", () => { + Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" ]); - Pervasives.assertEqual($$Array.keepSome([ - undefined, - undefined, - undefined - ]), []); - Pervasives.assertEqual($$Array.keepSome([]), []); }); }); -Mocha.describe("String.endsWith", () => { - Mocha.test("String.endsWith", () => { - "BuckleScript".endsWith("Script") === true; - "BuckleShoes".endsWith("Script") === false; +Mocha.describe("Belt_Array.unzip", () => { + Mocha.test("Belt_Array.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.describe("String.includes", () => { - Mocha.test("String.includes", () => { - "programmer".includes("gram") === true; - "programmer".includes("er") === true; - "programmer".includes("pro") === true; - "programmer.dat".includes("xyz") === false; +Mocha.describe("Belt_Array.zip", () => { + Mocha.test("Belt_Array.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("String.padStart", () => { - Mocha.test("String.padStart", () => { - "abc".padStart(5, " ") === " abc"; - "abc".padStart(6, "123465") === "123abc"; +Mocha.describe("Belt_Array.zipBy", () => { + Mocha.test("Belt_Array.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Result.mapError", () => { - Mocha.test("Result.mapError", () => { - let format = n => "Error code: " + n.toString(); - Result.mapError({ - TAG: "Error", - _0: 14 - }, format); - Result.mapError({ - TAG: "Ok", - _0: "abc" - }, format); +Mocha.describe("Belt_Float.*", () => { + Mocha.test("Belt_Float.*", () => { + Pervasives.assertEqual(2.0 * 2.0, 4.0); }); }); -Mocha.describe("Promise.resolve", () => { - Mocha.test("Promise.resolve", () => { - Promise.resolve(5); +Mocha.describe("Belt_Float.+", () => { + Mocha.test("Belt_Float.+", () => { + Pervasives.assertEqual(2.0 + 2.0, 4.0); }); }); -Mocha.describe("Promise.finally", () => { - Mocha.test("Promise.finally", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - let isDone = { - contents: false - }; - $$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.describe("Belt_Float.-", () => { + Mocha.test("Belt_Float.-", () => { + Pervasives.assertEqual(2.0 - 1.0, 1.0); }); }); -Mocha.describe("Object.isSealed", () => { - Mocha.test("Object.isSealed", () => { - let point = Object.seal({ - x: 1, - y: 3 - }); - Object.isSealed(point); - let fruit = { - name: "Apple" - }; - Object.isSealed(fruit); +Mocha.describe("Belt_Float./", () => { + Mocha.test("Belt_Float./", () => { + Pervasives.assertEqual(4.0 / 2.0, 2.0); }); }); -Mocha.describe("Object.isFrozen", () => { - Mocha.test("Object.isFrozen", () => { - let point = Object.freeze({ - x: 1, - y: 3 - }); - Object.isFrozen(point); - let fruit = { - name: "Apple" - }; - Object.isFrozen(fruit); +Mocha.describe("Belt_Float.fromInt", () => { + Mocha.test("Belt_Float.fromInt", () => { + console.log(1 === 1.0); }); }); -Mocha.describe("Nullable.getExn", () => { - Mocha.test("Nullable.getExn", () => { - let exit = 0; - let value; - try { - value = 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", - 5375, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "Hello"); - } - let exit$1 = 0; - let val; - try { - val = 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", - 5381, - 7 - ], - Error: new Error() - }; - } - let exit$2 = 0; - let val$1; - try { - val$1 = 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", - 5386, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_Float.fromString", () => { + Mocha.test("Belt_Float.fromString", () => { + console.log(Belt_Float.fromString("1.0") === 1.0); }); }); -Mocha.describe("List.toShuffled", () => { - Mocha.test("List.toShuffled", () => { - List.toShuffled({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); +Mocha.describe("Belt_Float.toInt", () => { + Mocha.test("Belt_Float.toInt", () => { + console.log(true); }); }); -Mocha.describe("List.concatMany", () => { - Mocha.test("List.concatMany", () => { - List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); +Mocha.describe("Belt_Float.toString", () => { + Mocha.test("Belt_Float.toString", () => { + console.log(String(1.0) === "1.0"); }); }); -Mocha.describe("List.mapReverse", () => { - Mocha.test("List.mapReverse", () => { - let f = x => Math.imul(x, x); - let l = { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }; - let withMap = List.reverse(List.map(l, f)); - let withMapReverse = List.mapReverse(l, f); - console.log(Primitive_object.equal(withMap, withMapReverse)); +Mocha.describe("Belt_HashMap.clear", () => { + Mocha.test("Belt_HashMap.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.describe("Null.asNullable", () => { - Mocha.test("Null.asNullable", () => {}); -}); - -Mocha.describe("Null.fromOption", () => { - Mocha.test("Null.fromOption", () => { - let asNull = Null.fromOption(undefined); - console.log(asNull === null); +Mocha.describe("Belt_HashMap.copy", () => { + Mocha.test("Belt_HashMap.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.describe("Math.Int.random", () => { - Mocha.test("Math.Int.random", () => { - $$Math.Int.random(2, 5) === 4; - $$Math.Int.random(505, 2000) === 1276; - $$Math.Int.random(-7, -2) === -4; +Mocha.describe("Belt_HashMap.forEach", () => { + Mocha.test("Belt_HashMap.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.describe("JSON.Encode.int", () => { - Mocha.test("JSON.Encode.int", () => {}); -}); - -Mocha.describe("Int.toPrecision", () => { - Mocha.test("Int.toPrecision", () => { - (100).toPrecision(); - (1).toPrecision(); - (100).toPrecision(2); - (1).toPrecision(2); +Mocha.describe("Belt_HashMap.fromArray", () => { + Mocha.test("Belt_HashMap.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.describe("Int.Bitwise.lor", () => { - Mocha.test("Int.Bitwise.lor", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsl", () => { - Mocha.test("Int.Bitwise.lsl", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsr", () => { - Mocha.test("Int.Bitwise.lsr", () => {}); -}); - -Mocha.describe("Int.Bitwise.asr", () => { - Mocha.test("Int.Bitwise.asr", () => {}); +Mocha.describe("Belt_HashMap.get", () => { + Mocha.test("Belt_HashMap.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.describe("Date.fromString", () => { - Mocha.test("Date.fromString", () => { - new Date("2023"); - new Date("2023-02-20"); - new Date("2023-02-20T16:40:00.00Z"); - new Date(""); - new Date("").getTime(); +Mocha.describe("Belt_HashMap.getBucketHistogram", () => { + Mocha.test("Belt_HashMap.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.describe("Date.makeWithYM", () => { - Mocha.test("Date.makeWithYM", () => { - new Date(2023, 0); - new Date(2023, 11); - new Date(2023, 12); - new Date(2023, -1); +Mocha.describe("Belt_HashMap.has", () => { + Mocha.test("Belt_HashMap.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.describe("Date.getMinutes", () => { - Mocha.test("Date.getMinutes", () => { - new Date("2023-02-20T16:40:00.00").getMinutes(); +Mocha.describe("Belt_HashMap.isEmpty", () => { + Mocha.test("Belt_HashMap.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.describe("Date.getSeconds", () => { - Mocha.test("Date.getSeconds", () => { - new Date("2023-02-20T16:40:00.00").getSeconds(); +Mocha.describe("Belt_HashMap.keepMapInPlace", () => { + Mocha.test("Belt_HashMap.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.describe("Date.setHoursMS", () => { - Mocha.test("Date.setHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); +Mocha.describe("Belt_HashMap.keysToArray", () => { + Mocha.test("Belt_HashMap.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.describe("Date.setMinutes", () => { - Mocha.test("Date.setMinutes", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0); +Mocha.describe("Belt_HashMap.logStats", () => { + Mocha.test("Belt_HashMap.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.describe("Date.setSeconds", () => { - Mocha.test("Date.setSeconds", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0); +Mocha.describe("Belt_HashMap.make", () => { + Mocha.test("Belt_HashMap.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.describe("Date.getUTCDate", () => { - Mocha.test("Date.getUTCDate", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); +Mocha.describe("Belt_HashMap.mergeMany", () => { + Mocha.test("Belt_HashMap.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.describe("Date.setUTCDate", () => { - Mocha.test("Date.setUTCDate", () => { - new Date("2023-02-20T16:40:00.00").setUTCDate(1); +Mocha.describe("Belt_HashMap.reduce", () => { + Mocha.test("Belt_HashMap.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"); + Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); + console.log("lol"); }); }); -Mocha.describe("Console.assert_", () => { - Mocha.test("Console.assert_", () => { - console.assert(false, "Hello World!"); - console.assert(true, "The answer"); +Mocha.describe("Belt_HashMap.remove", () => { + Mocha.test("Belt_HashMap.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.describe("Console.assert2", () => { - Mocha.test("Console.assert2", () => { - console.assert(false, "Hello", "World"); - console.assert(true, [ - 1, - 2, - 3 - ], /* '4' */52); +Mocha.describe("Belt_HashMap.set", () => { + Mocha.test("Belt_HashMap.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.describe("Console.assert3", () => { - Mocha.test("Console.assert3", () => { - console.assert(false, "Hello", "World", "ReScript"); - console.assert(true, "One", 2, 3); +Mocha.describe("Belt_HashMap.size", () => { + Mocha.test("Belt_HashMap.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.describe("Console.assert4", () => { - Mocha.test("Console.assert4", () => { - console.assert(false, "Hello", "World", "ReScript", "!!!"); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); +Mocha.describe("Belt_HashMap.toArray", () => { + Mocha.test("Belt_HashMap.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.describe("Console.assert5", () => { - Mocha.test("Console.assert5", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" +Mocha.describe("Belt_HashMap.valuesToArray", () => { + Mocha.test("Belt_HashMap.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("Console.assert6", () => { - Mocha.test("Console.assert6", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); +Mocha.describe("Belt_Int.*", () => { + Mocha.test("Belt_Int.*", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Console.logMany", () => { - Mocha.test("Console.logMany", () => { - console.log("Hello", "World"); - console.log(1, 2, 3); +Mocha.describe("Belt_Int.+", () => { + Mocha.test("Belt_Int.+", () => { + Pervasives.assertEqual(4, 4); }); }); -Mocha.describe("Console.timeEnd", () => { - Mocha.test("Console.timeEnd", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); +Mocha.describe("Belt_Int.-", () => { + Mocha.test("Belt_Int.-", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Console.timeLog", () => { - Mocha.test("Console.timeLog", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); +Mocha.describe("Belt_Int./", () => { + Mocha.test("Belt_Int./", () => { + Pervasives.assertEqual(2, 2); }); }); -Mocha.describe("BigInt.toString", () => { - Mocha.test("BigInt.toString", () => { - console.log((123n).toString()); +Mocha.describe("Belt_Int.fromFloat", () => { + Mocha.test("Belt_Int.fromFloat", () => { + Pervasives.assertEqual(1, 1); }); }); -Mocha.describe("Belt_Set.remove", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Pervasives.assertEqual(s2, s3); +Mocha.describe("Belt_Int.fromString", () => { + Mocha.test("Belt_Int.fromString", () => { + Pervasives.assertEqual(Belt_Int.fromString("1"), 1); }); }); -Mocha.describe("Belt_Set.subset", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); +Mocha.describe("Belt_Int.toFloat", () => { + Mocha.test("Belt_Int.toFloat", () => { + Pervasives.assertEqual(1, 1.0); }); }); -Mocha.describe("Belt_Set.reduce", () => { - Mocha.test("Belt_Set.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, +Mocha.describe("Belt_Int.toString", () => { + Mocha.test("Belt_Int.toString", () => { + Pervasives.assertEqual(String(1), "1"); + }); +}); + +Mocha.describe("Belt_List.add", () => { + Mocha.test("Belt_List.add", () => { + Belt_List.add({ + hd: 2, tl: { - hd: 5, + hd: 3, + tl: /* [] */0 + } + }, 1); + Belt_List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("Belt_List.cmp", () => { + Mocha.test("Belt_List.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.describe("Belt_List.cmpByLength", () => { + Mocha.test("Belt_List.cmpByLength", () => { + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, tl: { - hd: 2, + hd: 6, tl: /* [] */0 } } } }); - }); -}); - -Mocha.describe("Belt_Set.toList", () => { - Mocha.test("Belt_Set.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp + Belt_List.cmpByLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { + Belt_List.cmpByLength({ hd: 1, tl: { hd: 2, tl: { hd: 3, tl: { - hd: 5, + hd: 4, tl: /* [] */0 } } } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } }); }); }); -Mocha.describe("Belt_SetDict.eq", () => { - Mocha.test("Belt_SetDict.eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.concat", () => { + Mocha.test("Belt_List.concat", () => { + Belt_List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } }); - 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.describe("Belt_Result.map", () => { - Mocha.test("Belt_Result.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.describe("Belt_List.concatMany", () => { + Mocha.test("Belt_List.concatMany", () => { + Belt_List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); }); }); -Mocha.describe("Belt_Result.cmp", () => { - Mocha.test("Belt_Result.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.describe("Belt_Range.some", () => { - Mocha.test("Belt_Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); -}); - -Mocha.describe("Belt_Option.map", () => { - Mocha.test("Belt_Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Belt_Option.cmp", () => { - Mocha.test("Belt_Option.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.describe("Belt_Map.reduce", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.remove", () => { - Mocha.test("Belt_Map.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.describe("Belt_List.drop", () => { + Mocha.test("Belt_List.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.describe("Belt_List.zipBy", () => { - Mocha.test("Belt_List.zipBy", () => { - Belt_List.zipBy({ +Mocha.describe("Belt_List.eq", () => { + Mocha.test("Belt_List.eq", () => { + Belt_List.eq({ hd: 1, tl: { hd: 2, @@ -7245,12 +8317,44 @@ Mocha.describe("Belt_List.zipBy", () => { } } }, { - hd: 4, + hd: 1, tl: { - hd: 5, + hd: 2, tl: /* [] */0 } - }, (a, b) => (a << 1) + b | 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)); }); }); @@ -7286,9 +8390,9 @@ Mocha.describe("Belt_List.every", () => { }); }); -Mocha.describe("Belt_List.some2", () => { - Mocha.test("Belt_List.some2", () => { - Belt_List.some2({ +Mocha.describe("Belt_List.every2", () => { + Mocha.test("Belt_List.every2", () => { + Belt_List.every2({ hd: 1, tl: { hd: 2, @@ -7304,11 +8408,11 @@ Mocha.describe("Belt_List.some2", () => { tl: /* [] */0 } }, (a, b) => a > b); - Belt_List.some2(/* [] */0, { + Belt_List.every2(/* [] */0, { hd: 1, tl: /* [] */0 }, (a, b) => a > b); - Belt_List.some2({ + Belt_List.every2({ hd: 2, tl: { hd: 3, @@ -7318,7 +8422,7 @@ Mocha.describe("Belt_List.some2", () => { hd: 1, tl: /* [] */0 }, (a, b) => a > b); - Belt_List.some2({ + Belt_List.every2({ hd: 0, tl: { hd: 1, @@ -7334,300 +8438,212 @@ Mocha.describe("Belt_List.some2", () => { }); }); -Mocha.describe("Belt_List.getBy", () => { - Mocha.test("Belt_List.getBy", () => { - Belt_List.getBy({ +Mocha.describe("Belt_List.filter", () => { + Mocha.test("Belt_List.filter", () => { + let isEven = x => x % 2 === 0; + Belt_List.filter({ hd: 1, tl: { - hd: 4, + hd: 2, tl: { hd: 3, tl: { - hd: 2, + hd: 4, tl: /* [] */0 } } } - }, x => x > 3); - Belt_List.getBy({ - hd: 1, + }, isEven); + Belt_List.filter({ + hd: undefined, tl: { - hd: 4, + hd: 2, tl: { hd: 3, tl: { - hd: 2, + hd: undefined, tl: /* [] */0 } } } - }, x => x > 4); + }, Belt_Option.isSome); }); }); -Mocha.describe("Belt_List.unzip", () => { - Mocha.test("Belt_List.unzip", () => { - Belt_List.unzip({ - hd: [ - 1, - 2 - ], +Mocha.describe("Belt_List.filterWithIndex", () => { + Mocha.test("Belt_List.filterWithIndex", () => { + Belt_List.filterWithIndex({ + hd: 1, tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - }); - Belt_List.unzip({ - hd: [ - "H", - "W" - ], - tl: { - hd: [ - "e", - "o" - ], + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("Belt_List.flatten", () => { + Mocha.test("Belt_List.flatten", () => { + Belt_List.flatten({ + hd: { + hd: 1, tl: { - hd: [ - "l", - "r" - ], + hd: 2, tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } + hd: 3, + tl: /* [] */0 } } + }, + tl: { + hd: /* [] */0, + tl: { + hd: { + hd: 3, + tl: /* [] */0 + }, + tl: /* [] */0 + } } }); }); }); -Mocha.describe("Belt.MutableSet", () => { - Mocha.test("Belt.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]); +Mocha.describe("Belt_List.forEach", () => { + Mocha.test("Belt_List.forEach", () => { + Belt_List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } } - }; - let PairComparator = Belt_Id.MakeComparable({ - cmp: cmp + }, x => { + console.log("Item: " + x); }); - let mySet = Belt_MutableSet.make(PairComparator); - Belt_MutableSet.add(mySet, [ - 1, - 2 - ]); }); }); -Mocha.describe("Belt.Array.fill", () => { - Mocha.test("Belt.Array.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.describe("Belt_List.forEach2", () => { + Mocha.test("Belt_List.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.describe("Belt.Array.blit", () => { - Mocha.test("Belt.Array.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.describe("Belt_List.forEachWithIndex", () => { + Mocha.test("Belt_List.forEachWithIndex", () => { + Belt_List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (index, x) => { + console.log("Item " + String(index) + " is " + x); + }); }); }); -Mocha.describe("Belt.Array.some", () => { - Mocha.test("Belt.Array.some", () => { - Belt_Array.some([ +Mocha.describe("Belt_List.fromArray", () => { + Mocha.test("Belt_List.fromArray", () => { + Belt_List.fromArray([ + 1, 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; + 3 + ]); }); }); -Mocha.describe("Belt.List.zipBy", () => { - Mocha.test("Belt.List.zipBy", () => { - Belt_List.zipBy({ - hd: 1, +Mocha.describe("Belt_List.get", () => { + Mocha.test("Belt_List.get", () => { + let abc = { + hd: "A", tl: { - hd: 2, + hd: "B", tl: { - hd: 3, + hd: "C", tl: /* [] */0 } } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, (a, b) => (a << 1) + b | 0); + }; + Belt_List.get(abc, 1); + Belt_List.get(abc, 4); }); }); -Mocha.describe("Belt.List.every", () => { - Mocha.test("Belt.List.every", () => { - let isBelow10 = value => value < 10; - Belt_List.every({ - hd: 1, +Mocha.describe("Belt_List.getAssoc", () => { + Mocha.test("Belt_List.getAssoc", () => { + Belt_List.getAssoc({ + hd: [ + 1, + "a" + ], tl: { - hd: 9, + hd: [ + 2, + "b" + ], tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } + hd: [ + 3, + "c" + ], + tl: /* [] */0 } } - }, isBelow10); - Belt_List.every({ - hd: 1, + }, 3, (a, b) => a === b); + Belt_List.getAssoc({ + hd: [ + 9, + "morning" + ], tl: { - hd: 99, + hd: [ + 15, + "afternoon" + ], tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - }); -}); - -Mocha.describe("Belt.List.some2", () => { - Mocha.test("Belt.List.some2", () => { - Belt_List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, + hd: [ + 22, + "night" + ], 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); + }, 15, (k, item) => k === item); }); }); -Mocha.describe("Belt.List.getBy", () => { - Mocha.test("Belt.List.getBy", () => { +Mocha.describe("Belt_List.getBy", () => { + Mocha.test("Belt_List.getBy", () => { Belt_List.getBy({ hd: 1, tl: { @@ -7657,630 +8673,487 @@ Mocha.describe("Belt.List.getBy", () => { }); }); -Mocha.describe("Belt.List.unzip", () => { - Mocha.test("Belt.List.unzip", () => { - Belt_List.unzip({ +Mocha.describe("Belt_List.getExn", () => { + Mocha.test("Belt_List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.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", + 6148, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("Belt_List.has", () => { + Mocha.test("Belt_List.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.describe("Belt_List.hasAssoc", () => { + Mocha.test("Belt_List.hasAssoc", () => { + Belt_List.hasAssoc({ hd: [ 1, - 2 + "a" ], tl: { hd: [ - 3, - 4 + 2, + "b" ], - tl: /* [] */0 + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } } - }); - Belt_List.unzip({ + }, 1, (a, b) => a === b); + Belt_List.hasAssoc({ hd: [ - "H", - "W" + 9, + "morning" ], tl: { hd: [ - "e", - "o" + 15, + "afternoon" ], tl: { hd: [ - "l", - "r" + 22, + "night" ], - tl: { - hd: [ - "l", - "l" - ], - tl: { - hd: [ - "o", - "d" - ], - tl: { - hd: [ - " ", - "!" - ], - tl: /* [] */0 - } - } - } + tl: /* [] */0 } } - }); - }); -}); - -Mocha.describe("Belt.Range.some", () => { - Mocha.test("Belt.Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); + }, 25, (k, item) => k === item); }); }); -Mocha.describe("Belt.Set.remove", () => { - Mocha.test("Belt.Set.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.head", () => { + Mocha.test("Belt_List.head", () => { + Belt_List.head(/* [] */0); + Belt_List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt.Set.subset", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); +Mocha.describe("Belt_List.headExn", () => { + Mocha.test("Belt_List.headExn", () => { + Pervasives.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", + 6197, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Set.reduce", () => { - Mocha.test("Belt.Set.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, +Mocha.describe("Belt_List.keep", () => { + Mocha.test("Belt_List.keep", () => { + let isEven = x => x % 2 === 0; + Belt_List.keep({ + hd: 1, tl: { - hd: 5, + hd: 2, tl: { hd: 3, tl: { - hd: 2, + 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.describe("Belt.Set.toList", () => { - Mocha.test("Belt.Set.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { +Mocha.describe("Belt_List.keepMap", () => { + Mocha.test("Belt_List.keepMap", () => { + let isEven = x => x % 2 === 0; + Belt_List.keepMap({ hd: 1, tl: { hd: 2, tl: { hd: 3, tl: { - hd: 5, + 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.describe("Belt.Map.reduce", () => { - Mocha.test("Belt.Map.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.describe("Belt_List.keepWithIndex", () => { + Mocha.test("Belt_List.keepWithIndex", () => { + Belt_List.keepWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); }); }); -Mocha.describe("Belt.Map.remove", () => { - Mocha.test("Belt.Map.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_List.length", () => { + Mocha.test("Belt_List.length", () => { + Belt_List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } }); - 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.describe("Belt.Option.map", () => { - Mocha.test("Belt.Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); +Mocha.describe("Belt_List.make", () => { + Mocha.test("Belt_List.make", () => { + Belt_List.make(3, 1); }); }); -Mocha.describe("Belt.Option.cmp", () => { - Mocha.test("Belt.Option.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.describe("Belt_List.makeBy", () => { + Mocha.test("Belt_List.makeBy", () => { + Belt_List.makeBy(5, i => i); + Belt_List.makeBy(5, i => Math.imul(i, i)); }); }); -Mocha.describe("Belt.Result.map", () => { - Mocha.test("Belt.Result.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.describe("Belt_List.map", () => { + Mocha.test("Belt_List.map", () => { + Belt_List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); }); }); -Mocha.describe("Belt.Result.cmp", () => { - Mocha.test("Belt.Result.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.describe("Belt_Array.fill", () => { - Mocha.test("Belt_Array.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.describe("Belt_List.mapReverse", () => { + Mocha.test("Belt_List.mapReverse", () => { + Pervasives.assertEqual(Belt_List.mapReverse({ + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }, x => Math.imul(x, x)), { + hd: 25, + tl: { + hd: 16, + tl: { + hd: 9, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt_Array.blit", () => { - Mocha.test("Belt_Array.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.describe("Belt_List.mapReverse2", () => { + Mocha.test("Belt_List.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.describe("Belt_Array.some", () => { - Mocha.test("Belt_Array.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Belt_List.mapWithIndex", () => { + Mocha.test("Belt_List.mapWithIndex", () => { + Belt_List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (index, x) => index + x | 0); }); }); -Mocha.describe("Array.fillToEnd", () => { - Mocha.test("Array.fillToEnd", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1); - Pervasives.assertEqual(myArray, [ - 1, - 9, - 9, - 9 +Mocha.describe("Belt_List.partition", () => { + Mocha.test("Belt_List.partition", () => { + Pervasives.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.describe("Array.findIndex", () => { - Mocha.test("Array.findIndex", () => { - let array = [ - "ReScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); - Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); +Mocha.describe("Belt_List.reduce", () => { + Mocha.test("Belt_List.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.describe("Array.getUnsafe", () => { - Mocha.test("Array.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.describe("Belt_List.reduce2", () => { + Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); }); }); -Mocha.describe("Array.setUnsafe", () => { - Mocha.test("Array.setUnsafe", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); - }); -}); - -Mocha.describe("Array.filterMap", () => { - Mocha.test("Array.filterMap", () => { - Pervasives.assertEqual($$Array.filterMap([ - "Hello", - "Hi", - "Good bye" - ], item => { - if (item === "Hello") { - return item.length; - } - - }), [5]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return Math.imul(n, n); +Mocha.describe("Belt_List.reduceReverse", () => { + Mocha.test("Belt_List.reduceReverse", () => { + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - - }), [ - 4, - 16, - 36 - ]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), []); - Pervasives.assertEqual($$Array.filterMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); + }, 0, (a, b) => a + b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - - }), []); - }); -}); - -Mocha.describe("String.getUnsafe", () => { - Mocha.test("String.getUnsafe", () => {}); -}); - -Mocha.describe("String.normalize", () => { - Mocha.test("String.normalize", () => { - let string1 = "\u00F1"; - let string2 = "\u006E\u0303"; - if (string1 === string2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 6471, - 0 - ], - Error: new Error() - }; - } - Pervasives.assertEqual(string1.normalize(), string2.normalize()); - }); -}); - -Mocha.describe("String.searchOpt", () => { - Mocha.test("String.searchOpt", () => { - Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); - $$String.searchOpt("no numbers", /\d+/) === undefined; - }); -}); - -Mocha.describe("String.substring", () => { - Mocha.test("String.substring", () => { - "playground".substring(3, 6) === "ygr"; - "playground".substring(6, 3) === "ygr"; - "playground".substring(4, 12) === "ground"; - }); -}); - -Mocha.describe("String.trimStart", () => { - Mocha.test("String.trimStart", () => { - " Hello world! ".trimStart() === "Hello world! "; - " Hello world! ".trimStart() === "Hello world! "; - }); -}); - -Mocha.describe("Set.fromIterator", () => { - Mocha.test("Set.fromIterator", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(new Set(iterator).size, 3); - }); -}); - -Mocha.describe("RegExp.lastIndex", () => { - Mocha.test("RegExp.lastIndex", () => { - let regexp = new RegExp("\\w+"); - console.log(regexp.lastIndex); - regexp.exec("Many words here."); - console.log(regexp.lastIndex); - }); -}); - -Mocha.describe("RegExp.multiline", () => { - Mocha.test("RegExp.multiline", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.multiline); - let regexp2 = new RegExp("\\w+", "mi"); - console.log(regexp2.multiline); - }); -}); - -Mocha.describe("Option.getUnsafe", () => { - Mocha.test("Option.getUnsafe", () => {}); -}); - -Mocha.describe("Object.getSymbol", () => { - Mocha.test("Object.getSymbol", () => { - let fruit = Symbol("fruit"); - let x = {}; - x[fruit] = "banana"; - }); -}); - -Mocha.describe("Nullable.forEach", () => { - Mocha.test("Nullable.forEach", () => { - Nullable.forEach("thing", x => { - console.log(x); - }); - Nullable.forEach(null, x => { - console.log(x); - }); - Nullable.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Nullable.flatMap", () => { - Mocha.test("Nullable.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; + }, 10, (a, b) => a - b | 0); + Belt_List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - }; - Nullable.flatMap(2, addIfAboveOne); - Nullable.flatMap(-4, addIfAboveOne); - Nullable.flatMap(null, addIfAboveOne); + }, /* [] */0, Belt_List.add); }); }); -Mocha.describe("List.mapReverse2", () => { - Mocha.test("List.mapReverse2", () => { - List.mapReverse2({ +Mocha.describe("Belt_List.reduceReverse2", () => { + Mocha.test("Belt_List.reduceReverse2", () => { + Belt_List.reduceReverse2({ hd: 1, tl: { hd: 2, @@ -8290,18 +9163,36 @@ Mocha.describe("List.mapReverse2", () => { } } }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("Belt_List.reduceWithIndex", () => { + Mocha.test("Belt_List.reduceWithIndex", () => { + Belt_List.reduceWithIndex({ hd: 1, tl: { hd: 2, - tl: /* [] */0 + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } } - }, (a, b) => a + b | 0); + }, 0, (acc, item, index) => (acc + item | 0) + index | 0); }); }); -Mocha.describe("List.removeAssoc", () => { - Mocha.test("List.removeAssoc", () => { - List.removeAssoc({ +Mocha.describe("Belt_List.removeAssoc", () => { + Mocha.test("Belt_List.removeAssoc", () => { + Belt_List.removeAssoc({ hd: [ 1, "a" @@ -8320,7 +9211,7 @@ Mocha.describe("List.removeAssoc", () => { } } }, 1, (a, b) => a === b); - List.removeAssoc({ + Belt_List.removeAssoc({ hd: [ 9, "morning" @@ -8342,256 +9233,623 @@ Mocha.describe("List.removeAssoc", () => { }); }); -Mocha.describe("Math.Constants.e", () => { - Mocha.test("Math.Constants.e", () => {}); +Mocha.describe("Belt_List.reverse", () => { + Mocha.test("Belt_List.reverse", () => { + Belt_List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); }); -Mocha.describe("Math.Int.minMany", () => { - Mocha.test("Math.Int.minMany", () => { - Math.min(1, 2); - Math.min(-1, -2); - isFinite(Math.min()); +Mocha.describe("Belt_List.reverseConcat", () => { + Mocha.test("Belt_List.reverseConcat", () => { + Belt_List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); }); }); -Mocha.describe("Math.Int.maxMany", () => { - Mocha.test("Math.Int.maxMany", () => { - Math.max(1, 2); - Math.max(-1, -2); - isFinite(Math.max()); +Mocha.describe("Belt_List.setAssoc", () => { + Mocha.test("Belt_List.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.describe("Map.fromIterator", () => { - Mocha.test("Map.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(new Map(iterator).size, 2); +Mocha.describe("Belt_List.shuffle", () => { + Mocha.test("Belt_List.shuffle", () => { + Belt_List.shuffle({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("JSON.Encode.bool", () => { - Mocha.test("JSON.Encode.bool", () => {}); -}); - -Mocha.describe("JSON.Encode.null", () => { - Mocha.test("JSON.Encode.null", () => {}); -}); - -Mocha.describe("JSON.Decode.bool", () => { - Mocha.test("JSON.Decode.bool", () => { - $$JSON.Decode.bool(JSON.parse("true")); - $$JSON.Decode.bool(JSON.parse("\"hello world\"")); +Mocha.describe("Belt_List.some", () => { + Mocha.test("Belt_List.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.describe("JSON.Decode.null", () => { - Mocha.test("JSON.Decode.null", () => { - $$JSON.Decode.$$null(JSON.parse("null")); - $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); +Mocha.describe("Belt_List.some2", () => { + Mocha.test("Belt_List.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.describe("Iterator.toArray", () => { - Mocha.test("Iterator.toArray", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - let mapKeysAsArray = Array.from(map.keys()); - console.log(mapKeysAsArray); +Mocha.describe("Belt_List.sort", () => { + Mocha.test("Belt_List.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.describe("Iterator.forEach", () => { - Mocha.test("Iterator.forEach", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - $$Iterator.forEach(iterator, v => { - if (v === undefined) { - return Pervasives.assertEqual(Option.isNone(v), true); +Mocha.describe("Belt_List.splitAt", () => { + Mocha.test("Belt_List.splitAt", () => { + Belt_List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 } - switch (v) { - case "a" : - case "b" : - case "c" : - return; - default: - return Pervasives.assertEqual(Option.isNone(v), true); + }, 1); + Belt_List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } } - }); + }, 2); }); }); -Mocha.describe("Int.Bitwise.land", () => { - Mocha.test("Int.Bitwise.land", () => {}); -}); - -Mocha.describe("Int.Bitwise.lxor", () => { - Mocha.test("Int.Bitwise.lxor", () => {}); -}); - -Mocha.describe("Int.Bitwise.lnot", () => { - Mocha.test("Int.Bitwise.lnot", () => { - Int.Bitwise.lnot(2) === -3; +Mocha.describe("Belt_List.tail", () => { + Mocha.test("Belt_List.tail", () => { + Belt_List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + Belt_List.tail(/* [] */0); }); }); -Mocha.describe("Float.parseFloat", () => { - Mocha.test("Float.parseFloat", () => { - parseFloat("1.0"); - parseFloat(" 3.14 "); - parseFloat("3.0"); - parseFloat("3.14some non-digit characters"); - isNaN(parseFloat("error")); +Mocha.describe("Belt_List.tailExn", () => { + Mocha.test("Belt_List.tailExn", () => { + Pervasives.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", + 6501, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Float.fromString", () => { - Mocha.test("Float.fromString", () => { - Primitive_object.equal(Float.fromString("0"), 0.0); - Float.fromString("NaN") === undefined; - Primitive_object.equal(Float.fromString("6"), 6.0); +Mocha.describe("Belt_List.take", () => { + Mocha.test("Belt_List.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.describe("Date.makeWithYMD", () => { - Mocha.test("Date.makeWithYMD", () => { - new Date(2023, 1, 20); - new Date(2023, 1, -1); - new Date(2023, 1, 29); +Mocha.describe("Belt_List.toArray", () => { + Mocha.test("Belt_List.toArray", () => { + Belt_List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Date.getFullYear", () => { - Mocha.test("Date.getFullYear", () => { - new Date("2023-02-20").getFullYear(); +Mocha.describe("Belt_List.unzip", () => { + Mocha.test("Belt_List.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.describe("Date.setFullYear", () => { - Mocha.test("Date.setFullYear", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024); +Mocha.describe("Belt_List.zip", () => { + Mocha.test("Belt_List.zip", () => { + Belt_List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Date.setMinutesS", () => { - Mocha.test("Date.setMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); +Mocha.describe("Belt_List.zipBy", () => { + Mocha.test("Belt_List.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("Date.getUTCMonth", () => { - Mocha.test("Date.getUTCMonth", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); +Mocha.describe("Belt_Map.Dict.findFirstBy", () => { + Mocha.test("Belt_Map.Dict.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("Date.getUTCHours", () => { - Mocha.test("Date.getUTCHours", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); - }); +Mocha.describe("Belt_Map.Int", () => { + Mocha.test("Belt_Map.Int", () => {}); }); -Mocha.describe("Date.setUTCMonth", () => { - Mocha.test("Date.setUTCMonth", () => { - new Date("2023-02-20T16:40:00.00").setUTCMonth(0); - }); -}); - -Mocha.describe("Date.setUTCHours", () => { - Mocha.test("Date.setUTCHours", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0); - }); -}); - -Mocha.describe("Date.toISOString", () => { - Mocha.test("Date.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.describe("Date.toUTCString", () => { - Mocha.test("Date.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("Dict.keysToArray", () => { - Mocha.test("Dict.keysToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let keys = Object.keys(dict); - console.log(keys); - }); -}); - -Mocha.describe("Console.infoMany", () => { - Mocha.test("Console.infoMany", () => { - console.info("Hello", "World"); - console.info(1, 2, 3); +Mocha.describe("Belt_Map.Int.findFirstBy", () => { + Mocha.test("Belt_Map.Int.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; + } + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("Console.warnMany", () => { - Mocha.test("Console.warnMany", () => { - console.warn("Hello", "World"); - console.warn(1, 2, 3); +Mocha.describe("Belt_Map.String.findFirstBy", () => { + Mocha.test("Belt_Map.String.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; + } + }), [ + "1", + "one" + ]); }); }); -Mocha.describe("Belt_Set.isEmpty", () => { - Mocha.test("Belt_Set.isEmpty", () => { +Mocha.describe("Belt_Map.findFirstBy", () => { + Mocha.test("Belt_Map.findFirstBy", () => { 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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] + ], IntCmp); + Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ + 4, + "4" + ]); }); }); -Mocha.describe("Belt_Set.forEach", () => { - Mocha.test("Belt_Set.forEach", () => { +Mocha.describe("Belt_Map.forEach", () => { + Mocha.test("Belt_Map.forEach", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "" + ] ], IntCmp); let acc = { contents: /* [] */0 }; - Belt_Set.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); + Belt_Map.forEach(s0, (k, v) => { + acc.contents = { + hd: [ + k, + v + ], + tl: acc.contents + }; }); - Pervasives.assertEqual(acc.contents, { - hd: 6, + Primitive_object.equal(acc.contents, { + hd: [ + 4, + "4" + ], tl: { - hd: 5, + hd: [ + 3, + "3" + ], tl: { - hd: 3, + hd: [ + 2, + "2" + ], tl: { - hd: 2, + hd: [ + 1, + "1" + ], tl: /* [] */0 } } @@ -8600,224 +9858,255 @@ Mocha.describe("Belt_Set.forEach", () => { }); }); -Mocha.describe("Belt_Set.toArray", () => { - Mocha.test("Belt_Set.toArray", () => { +Mocha.describe("Belt_Map.fromArray", () => { + Mocha.test("Belt_Map.fromArray", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 + Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + [ + 1, + "1" + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] ]); }); }); -Mocha.describe("Belt_Set.minimum", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); - }); -}); - -Mocha.describe("Belt_Set.maximum", () => { - Mocha.test("Belt_Set.maximum", () => { +Mocha.describe("Belt_Map.get", () => { + Mocha.test("Belt_Map.get", () => { 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); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + 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.describe("Belt_Set.Dict.eq", () => { - Mocha.test("Belt_Set.Dict.eq", () => { +Mocha.describe("Belt_Map.has", () => { + Mocha.test("Belt_Map.has", () => { 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); + Belt_Map.has(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp), 1) === true; }); }); -Mocha.describe("Belt_SetDict.has", () => { - Mocha.test("Belt_SetDict.has", () => { +Mocha.describe("Belt_Map.isEmpty", () => { + Mocha.test("Belt_Map.isEmpty", () => { 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); + Belt_Map.isEmpty(Belt_Map.fromArray([[ + 1, + "1" + ]], IntCmp)) === false; }); }); -Mocha.describe("Belt_SetDict.add", () => { - Mocha.test("Belt_SetDict.add", () => { +Mocha.describe("Belt_Map.keysToArray", () => { + Mocha.test("Belt_Map.keysToArray", () => { 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); + Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ + [ + 2, + "2" + ], + [ + 1, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)), [ + 1, + 2, + 3 + ]); }); }); -Mocha.describe("Belt_SetDict.get", () => { - Mocha.test("Belt_SetDict.get", () => { +Mocha.describe("Belt_Map.make", () => { + Mocha.test("Belt_Map.make", () => { 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.describe("Belt_Range.every", () => { - Mocha.test("Belt_Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); -}); - -Mocha.describe("Belt_Option.keep", () => { - Mocha.test("Belt_Option.keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); + let m = Belt_Map.make(IntCmp); + Belt_Map.set(m, 0, "a"); }); }); -Mocha.describe("Belt_Map.isEmpty", () => { - Mocha.test("Belt_Map.isEmpty", () => { +Mocha.describe("Belt_Map.reduce", () => { + Mocha.test("Belt_Map.reduce", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ + let s0 = Belt_Map.fromArray([ + [ + 4, + "4" + ], + [ 1, "1" - ]], IntCmp)) === false; + ], + [ + 2, + "2" + ], + [ + 3, + "3" + ] + ], IntCmp); + Belt_Map.reduce(s0, /* [] */0, (acc, k, v) => ({ + hd: [ + k, + v + ], + tl: acc + })); }); }); -Mocha.describe("Belt_Map.forEach", () => { - Mocha.test("Belt_Map.forEach", () => { +Mocha.describe("Belt_Map.remove", () => { + Mocha.test("Belt_Map.remove", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); let s0 = Belt_Map.fromArray([ [ - 4, - "4" + 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.describe("Belt_Map.set", () => { + Mocha.test("Belt_Map.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 acc = { - contents: /* [] */0 - }; - Belt_Map.forEach(s0, (k, v) => { - acc.contents = { - hd: [ - k, - v - ], - tl: acc.contents - }; + let s1 = Belt_Map.set(s0, 2, "3"); + Primitive_object.equal(Belt_Map.valuesToArray(s1), [ + "1", + "3", + "3" + ]); + }); +}); + +Mocha.describe("Belt_Map.size", () => { + Mocha.test("Belt_Map.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Primitive_object.equal(acc.contents, { - hd: [ - 4, - "4" + Belt_Map.size(Belt_Map.fromArray([ + [ + 2, + "2" ], - tl: { - hd: [ - 3, - "3" - ], - tl: { - hd: [ - 2, - "2" - ], - tl: { - hd: [ - 1, - "1" - ], - tl: /* [] */0 - } - } - } - }); + [ + 2, + "1" + ], + [ + 3, + "3" + ] + ], IntCmp)) === 2; }); }); @@ -8857,1547 +10146,1313 @@ Mocha.describe("Belt_Map.toArray", () => { }); }); -Mocha.describe("Belt_Int.toFloat", () => { - Mocha.test("Belt_Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); - }); -}); - -Mocha.describe("Belt_List.length", () => { - Mocha.test("Belt_List.length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Map.valuesToArray", () => { + Mocha.test("Belt_Map.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_List.getExn", () => { - Mocha.test("Belt_List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.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", - 7229, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_List.makeBy", () => { - Mocha.test("Belt_List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); +Mocha.describe("Belt_MapDict.findFirstBy", () => { + Mocha.test("Belt_MapDict.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_List.concat", () => { - Mocha.test("Belt_List.concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 +Mocha.describe("Belt_MapInt.findFirstBy", () => { + Mocha.test("Belt_MapInt.findFirstBy", () => { + let mapInt = Belt_MapInt.fromArray([ + [ + 1, + "one" + ], + [ + 2, + "two" + ], + [ + 3, + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { + if (k === 1) { + return v === "one"; + } else { + return false; } - }); + }), [ + 1, + "one" + ]); }); }); -Mocha.describe("Belt_List.reduce", () => { - Mocha.test("Belt_List.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 - } - } +Mocha.describe("Belt_MapString.findFirstBy", () => { + Mocha.test("Belt_MapString.findFirstBy", () => { + let mapString = Belt_MapString.fromArray([ + [ + "1", + "one" + ], + [ + "2", + "two" + ], + [ + "3", + "three" + ] + ]); + Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { + if (k === "1") { + return v === "one"; + } else { + return false; } - }, 0, (acc, item) => acc + item | 0); + }), [ + "1", + "one" + ]); }); }); -Mocha.describe("Belt_List.every2", () => { - Mocha.test("Belt_List.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.describe("Belt_MutableSet.add", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_List.filter", () => { - Mocha.test("Belt_List.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.describe("Belt_MutableSet.copy", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.Array.range", () => { - Mocha.test("Belt.Array.range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, - 1, +Mocha.describe("Belt_MutableSet.diff", () => { + Mocha.test("Belt_MutableSet.diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, 2, - 3 - ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); + 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.describe("Belt.Array.zipBy", () => { - Mocha.test("Belt.Array.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, +Mocha.describe("Belt_MutableSet.eq", () => { + Mocha.test("Belt_MutableSet.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ + 5, 2, 3 - ], [ - 4, + ], IntCmp); + let s1 = Belt_MutableSet.fromArray([ + 3, + 2, 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); + ], IntCmp); + Belt_MutableSet.eq(s0, s1); }); }); -Mocha.describe("Belt.Array.unzip", () => { - Mocha.test("Belt.Array.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.describe("Belt_MutableSet.every", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.Array.slice", () => { - Mocha.test("Belt.Array.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.describe("Belt_MutableSet.forEach", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.Array.getBy", () => { - Mocha.test("Belt.Array.getBy", () => { - Primitive_object.equal(Belt_Array.getBy([ +Mocha.describe("Belt_MutableSet.fromArray", () => { + Mocha.test("Belt_MutableSet.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, - 4, 3, - 2 - ], x => x % 2 === 0), 4); - Belt_Array.getBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 2, + 4 + ], IntCmp); + Belt_MutableSet.toArray(s0); }); }); -Mocha.describe("Belt.Array.every", () => { - Mocha.test("Belt.Array.every", () => { - Belt_Array.every([ +Mocha.describe("Belt_MutableSet.get", () => { + Mocha.test("Belt_MutableSet.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, + 2, 3, + 4, 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; + ], IntCmp); + Belt_MutableSet.get(s0, 3); + Belt_MutableSet.get(s0, 20); }); }); -Mocha.describe("Belt.Array.some2", () => { - Mocha.test("Belt.Array.some2", () => { - Belt_Array.some2([ - 0, - 2 - ], [ +Mocha.describe("Belt_MutableSet.has", () => { + Mocha.test("Belt_MutableSet.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ 1, - 0, - 3 - ], (a, b) => a > b) === true; - Belt_Array.some2([], [1], (x, y) => x > y) === false; - Belt_Array.some2([ + 4, 2, - 3 - ], [ + 5 + ], IntCmp); + Belt_MutableSet.has(set, 3); + Belt_MutableSet.has(set, 1); + }); +}); + +Mocha.describe("Belt_MutableSet.intersect", () => { + Mocha.test("Belt_MutableSet.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 - ], (x, y) => x > y) === true; + ], IntCmp); + let intersect = Belt_MutableSet.intersect(s0, s1); + Belt_MutableSet.toArray(intersect); }); }); -Mocha.describe("Belt.List.length", () => { - Mocha.test("Belt.List.length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_MutableSet.isEmpty", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.List.getExn", () => { - Mocha.test("Belt.List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.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", - 7395, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_MutableSet.keep", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.List.makeBy", () => { - Mocha.test("Belt.List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); +Mocha.describe("Belt_MutableSet.maxUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.List.concat", () => { - Mocha.test("Belt.List.concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } +Mocha.describe("Belt_MutableSet.maximum", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.List.reduce", () => { - Mocha.test("Belt.List.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.describe("Belt_MutableSet.mergeMany", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.List.every2", () => { - Mocha.test("Belt.List.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.describe("Belt.List.filter", () => { - Mocha.test("Belt.List.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.describe("Belt_MutableSet.minUndefined", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.Range.every", () => { - Mocha.test("Belt.Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); +Mocha.describe("Belt_MutableSet.minimum", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt.Set.isEmpty", () => { - Mocha.test("Belt.Set.isEmpty", () => { +Mocha.describe("Belt_MutableSet.partition", () => { + Mocha.test("Belt_MutableSet.partition", () => { 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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); + 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.describe("Belt.Set.forEach", () => { - Mocha.test("Belt.Set.forEach", () => { +Mocha.describe("Belt_MutableSet.reduce", () => { + Mocha.test("Belt_MutableSet.reduce", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ + let s0 = Belt_MutableSet.fromArray([ 5, 2, 3, 5, 6 ], IntCmp); - let acc = { - contents: /* [] */0 - }; - Belt_Set.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); - Pervasives.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); + Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); }); }); -Mocha.describe("Belt.Set.toArray", () => { - Mocha.test("Belt.Set.toArray", () => { +Mocha.describe("Belt_MutableSet.remove", () => { + Mocha.test("Belt_MutableSet.remove", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 3, + let s0 = Belt_MutableSet.fromArray([ 2, + 3, 1, + 4, 5 ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ + Belt_MutableSet.remove(s0, 1); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.remove(s0, 3); + Belt_MutableSet.toArray(s0); + }); +}); + +Mocha.describe("Belt_MutableSet.removeMany", () => { + Mocha.test("Belt_MutableSet.removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_MutableSet.fromArray([ 1, 2, 3, - 5 + 4 + ], IntCmp); + Belt_MutableSet.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 ]); + Belt_MutableSet.toArray(set); }); }); -Mocha.describe("Belt.Set.minimum", () => { - Mocha.test("Belt.Set.minimum", () => { +Mocha.describe("Belt_MutableSet.size", () => { + Mocha.test("Belt_MutableSet.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ + let s0 = Belt_MutableSet.fromArray([ + 1, + 2, 3, + 4 + ], IntCmp); + Belt_MutableSet.size(s0); + }); +}); + +Mocha.describe("Belt_MutableSet.some", () => { + Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.split", () => { + Mocha.test("Belt_MutableSet.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 1, + 2, + 3, + 4, 5 ], IntCmp); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); + 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.describe("Belt.Set.maximum", () => { - Mocha.test("Belt.Set.maximum", () => { +Mocha.describe("Belt_MutableSet.subset", () => { + Mocha.test("Belt_MutableSet.subset", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.make(IntCmp); - let s1 = Belt_Set.fromArray([ + 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.describe("Belt_MutableSet.toArray", () => { + Mocha.test("Belt_MutableSet.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_MutableSet.fromArray([ 3, 2, 1, 5 ], IntCmp); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); + Belt_MutableSet.toArray(s0); }); }); -Mocha.describe("Belt.Map.isEmpty", () => { - Mocha.test("Belt.Map.isEmpty", () => { +Mocha.describe("Belt_MutableSet.toList", () => { + Mocha.test("Belt_MutableSet.toList", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; + let s0 = Belt_MutableSet.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Belt_MutableSet.toList(s0); }); }); -Mocha.describe("Belt.Map.forEach", () => { - Mocha.test("Belt.Map.forEach", () => { +Mocha.describe("Belt_MutableSet.union", () => { + Mocha.test("Belt_MutableSet.union", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Map.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], - [ - 2, - "2" - ], - [ - 3, - "" - ] + let s0 = Belt_MutableSet.fromArray([ + 5, + 2, + 3, + 5, + 6 ], IntCmp); - let acc = { - contents: /* [] */0 + 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.cmp", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.eq", () => { + Mocha.test("Belt_Option.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.describe("Belt_Option.flatMap", () => { + Mocha.test("Belt_Option.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + }; - Belt_Map.forEach(s0, (k, v) => { - acc.contents = { - hd: [ - k, - v - ], - tl: acc.contents - }; + Belt_Option.flatMap(2, addIfAboveOne); + Belt_Option.flatMap(-4, addIfAboveOne); + Belt_Option.flatMap(undefined, addIfAboveOne); + }); +}); + +Mocha.describe("Belt_Option.forEach", () => { + Mocha.test("Belt_Option.forEach", () => { + Belt_Option.forEach("thing", x => { + console.log(x); }); - Primitive_object.equal(acc.contents, { - hd: [ - 4, - "4" - ], - tl: { - hd: [ - 3, - "3" - ], - tl: { - hd: [ - 2, - "2" - ], - tl: { - hd: [ - 1, - "1" - ], - tl: /* [] */0 - } - } - } + Belt_Option.forEach(undefined, x => { + console.log(x); }); }); }); -Mocha.describe("Belt.Map.toArray", () => { - Mocha.test("Belt.Map.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.describe("Belt_Option.getExn", () => { + Mocha.test("Belt_Option.getExn", () => { + Pervasives.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", + 7466, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.HashMap.set", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Option.getWithDefault", () => { + Mocha.test("Belt_Option.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.describe("Belt.HashMap.get", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Option.isNone", () => { + Mocha.test("Belt_Option.isNone", () => { + Belt_Option.isNone(undefined); + Belt_Option.isNone(1); }); }); -Mocha.describe("Belt.HashMap.has", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_Option.isSome", () => { + Mocha.test("Belt_Option.isSome", () => { + Belt_Option.isSome(undefined); + Belt_Option.isSome(1); }); }); -Mocha.describe("Belt.Option.keep", () => { - Mocha.test("Belt.Option.keep", () => { +Mocha.describe("Belt_Option.keep", () => { + Mocha.test("Belt_Option.keep", () => { Belt_Option.keep(10, x => x > 5); Belt_Option.keep(4, x => x > 5); Belt_Option.keep(undefined, x => x > 5); }); }); -Mocha.describe("Belt.Int.toFloat", () => { - Mocha.test("Belt.Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); +Mocha.describe("Belt_Option.map", () => { + Mocha.test("Belt_Option.map", () => { + Belt_Option.map(3, x => Math.imul(x, x)); + Belt_Option.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt.Float.toInt", () => { - Mocha.test("Belt.Float.toInt", () => { - console.log(true); +Mocha.describe("Belt_Option.mapWithDefault", () => { + Mocha.test("Belt_Option.mapWithDefault", () => { + Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); + Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("Belt.Set.Dict.eq", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt_Option.orElse", () => { + Mocha.test("Belt_Option.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_Float.toInt", () => { - Mocha.test("Belt_Float.toInt", () => { - console.log(true); +Mocha.describe("Belt_Range.every", () => { + Mocha.test("Belt_Range.every", () => { + Belt_Range.every(0, 4, i => i < 5); + Belt_Range.every(0, 4, i => i < 4); }); }); -Mocha.describe("Belt_Array.range", () => { - Mocha.test("Belt_Array.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.describe("Belt_Range.everyBy", () => { + Mocha.test("Belt_Range.everyBy", () => { + Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); + Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Belt_Array.zipBy", () => { - Mocha.test("Belt_Array.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Belt_Range.forEach", () => { + Mocha.test("Belt_Range.forEach", () => { + Belt_Range.forEach(0, 4, i => { + console.log(i); + }); }); }); -Mocha.describe("Belt_Array.unzip", () => { - Mocha.test("Belt_Array.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.describe("Belt_Range.some", () => { + Mocha.test("Belt_Range.some", () => { + Belt_Range.some(0, 4, i => i > 5); + Belt_Range.some(0, 4, i => i > 2); }); }); -Mocha.describe("Belt_Array.slice", () => { - Mocha.test("Belt_Array.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.describe("Belt_Range.someBy", () => { + Mocha.test("Belt_Range.someBy", () => { + Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); + Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); }); }); -Mocha.describe("Belt_Array.getBy", () => { - Mocha.test("Belt_Array.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.describe("Belt_Result.cmp", () => { + Mocha.test("Belt_Result.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.describe("Belt_Array.every", () => { - Mocha.test("Belt_Array.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Belt_Result.eq", () => { + Mocha.test("Belt_Result.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.describe("Belt_Array.some2", () => { - Mocha.test("Belt_Array.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.describe("Belt_HashMap.set", () => { - Mocha.test("Belt_HashMap.set", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt_Result.flatMap", () => { + Mocha.test("Belt_Result.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" }); - 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.describe("Belt_HashMap.get", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_Result.getExn", () => { + Mocha.test("Belt_Result.getExn", () => { + Pervasives.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", + 7700, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_HashMap.has", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_Result.getWithDefault", () => { + Mocha.test("Belt_Result.getWithDefault", () => { + Belt_Result.getWithDefault({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Belt_Result.getWithDefault({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("Array.concatMany", () => { - Mocha.test("Array.concatMany", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = ["yay"]; - let array3 = ["wehoo"]; - let someArray = array1.concat(array2, array3); - console.log(someArray); +Mocha.describe("Belt_Result.map", () => { + Mocha.test("Belt_Result.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.describe("Array.indexOfOpt", () => { - Mocha.test("Array.indexOfOpt", () => { - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 2), 1); - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 3), undefined); - Pervasives.assertEqual($$Array.indexOfOpt([{ - language: "ReScript" - }], { - language: "ReScript" - }), undefined); +Mocha.describe("Belt_Result.mapWithDefault", () => { + Mocha.test("Belt_Result.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("Array.joinUnsafe", () => { - Mocha.test("Array.joinUnsafe", () => { - Pervasives.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); +Mocha.describe("Belt_Set.Dict.add", () => { + Mocha.test("Belt_Set.Dict.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.describe("Array.sliceToEnd", () => { - Mocha.test("Array.sliceToEnd", () => { - Pervasives.assertEqual([ - 1, +Mocha.describe("Belt_Set.Dict.diff", () => { + Mocha.test("Belt_Set.Dict.diff", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, 2, 3, - 4 - ].slice(1), [ + 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.describe("Array.unsafe_get", () => { - Mocha.test("Array.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.describe("Belt_Set.Dict.empty", () => { + Mocha.test("Belt_Set.Dict.empty", () => {}); }); -Mocha.describe("Array.toShuffled", () => { - Mocha.test("Array.toShuffled", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let shuffledArray = $$Array.toShuffled(array); - console.log(shuffledArray); - Pervasives.assertEqual($$Array.toShuffled([ - 1, +Mocha.describe("Belt_Set.Dict.eq", () => { + Mocha.test("Belt_Set.Dict.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_SetDict.fromArray([ + 5, 2, 3 - ]).length, 3); + ], IntCmp.cmp); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 5 + ], IntCmp.cmp); + Belt_SetDict.eq(s0, s1, IntCmp.cmp); }); }); -Mocha.describe("String.charCodeAt", () => { - Mocha.test("String.charCodeAt", () => { - "😺".charCodeAt(0) === 55357; - Primitive_object.equal("😺".codePointAt(0), 128570); +Mocha.describe("Belt_Set.Dict.every", () => { + Mocha.test("Belt_Set.Dict.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.describe("String.concatMany", () => { - Mocha.test("String.concatMany", () => { - "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; +Mocha.describe("Belt_Set.Dict.forEach", () => { + Mocha.test("Belt_Set.Dict.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.describe("String.indexOfOpt", () => { - Mocha.test("String.indexOfOpt", () => { - Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); - $$String.indexOfOpt("bookseller", "xyz") === undefined; +Mocha.describe("Belt_Set.Dict.fromArray", () => { + Mocha.test("Belt_Set.Dict.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.describe("String.replaceAll", () => { - Mocha.test("String.replaceAll", () => { - "old old string".replaceAll("old", "new") === "new new string"; - "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; +Mocha.describe("Belt_Set.Dict.get", () => { + Mocha.test("Belt_Set.Dict.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.describe("String.sliceToEnd", () => { - Mocha.test("String.sliceToEnd", () => { - "abcdefg".slice(4) === "efg"; - "abcdefg".slice(-2) === "fg"; - "abcdefg".slice(7) === ""; +Mocha.describe("Belt_Set.Dict.has", () => { + Mocha.test("Belt_Set.Dict.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.describe("String.startsWith", () => { - Mocha.test("String.startsWith", () => { - "BuckleScript".startsWith("Buckle") === true; - "BuckleScript".startsWith("") === true; - "JavaScript".startsWith("Buckle") === false; +Mocha.describe("Belt_Set.Dict.intersect", () => { + Mocha.test("Belt_Set.Dict.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.describe("RegExp.fromString", () => { - Mocha.test("RegExp.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.describe("Belt_Set.Dict.isEmpty", () => { + Mocha.test("Belt_Set.Dict.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.describe("RegExp.ignoreCase", () => { - Mocha.test("RegExp.ignoreCase", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.ignoreCase); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.ignoreCase); +Mocha.describe("Belt_Set.Dict.keep", () => { + Mocha.test("Belt_Set.Dict.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.describe("Pervasives.import", () => { - Mocha.test("Pervasives.import", () => {}); -}); - -Mocha.describe("Nullable.toOption", () => { - Mocha.test("Nullable.toOption", () => { - let nullableString = "Hello"; - if (nullableString == null) { - console.log("Didn't have a value."); - } else { - console.log("Got string:", nullableString); - } +Mocha.describe("Belt_Set.Dict.maxUndefined", () => { + Mocha.test("Belt_Set.Dict.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.describe("List.mapWithIndex", () => { - Mocha.test("List.mapWithIndex", () => { - List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (x, index) => index + x | 0); +Mocha.describe("Belt_Set.Dict.maximum", () => { + Mocha.test("Belt_Set.Dict.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.describe("Math.Constants.pi", () => { - Mocha.test("Math.Constants.pi", () => {}); +Mocha.describe("Belt_Set.Dict.mergeMany", () => { + Mocha.test("Belt_Set.Dict.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.describe("JSON.stringifyAny", () => { - Mocha.test("JSON.stringifyAny", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 8135, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.Encode.float", () => { - Mocha.test("JSON.Encode.float", () => {}); -}); - -Mocha.describe("JSON.Encode.array", () => { - Mocha.test("JSON.Encode.array", () => {}); -}); - -Mocha.describe("JSON.Decode.float", () => { - Mocha.test("JSON.Decode.float", () => { - $$JSON.Decode.float(JSON.parse("42.0")); - $$JSON.Decode.float(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.array", () => { - Mocha.test("JSON.Decode.array", () => { - $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); - $$JSON.Decode.array(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("Int.toExponential", () => { - Mocha.test("Int.toExponential", () => { - (1000).toExponential(); - (-1000).toExponential(); - (77).toExponential(2); - (5678).toExponential(2); - }); -}); - -Mocha.describe("Float.toPrecision", () => { - Mocha.test("Float.toPrecision", () => { - (100.0).toPrecision(); - (1.0).toPrecision(); - (100.0).toPrecision(2); - (1.0).toPrecision(1); - }); -}); - -Mocha.describe("Error.toException", () => { - Mocha.test("Error.toException", () => { - new Error("Something went wrong."); - }); -}); - -Mocha.describe("Date.makeWithYMDH", () => { - Mocha.test("Date.makeWithYMDH", () => { - new Date(2023, 1, 20, 16); - new Date(2023, 1, 20, 24); - new Date(2023, 1, 20, -1); - }); -}); - -Mocha.describe("Date.setFullYearM", () => { - Mocha.test("Date.setFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); - }); -}); - -Mocha.describe("Date.setHoursMSMs", () => { - Mocha.test("Date.setHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); - }); -}); - -Mocha.describe("Date.setSecondsMs", () => { - Mocha.test("Date.setSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); - }); -}); - -Mocha.describe("Date.setUTCHoursM", () => { - Mocha.test("Date.setUTCHoursM", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); - }); -}); - -Mocha.describe("Date.toDateString", () => { - Mocha.test("Date.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.describe("Date.toTimeString", () => { - Mocha.test("Date.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.describe("Dict.fromIterator", () => { - Mocha.test("Dict.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ - 1, - 2 - ]); - }); -}); - -Mocha.describe("Console.debugMany", () => { - Mocha.test("Console.debugMany", () => { - console.debug("Hello", "World"); - console.debug(1, 2, 3); - }); -}); - -Mocha.describe("Console.errorMany", () => { - Mocha.test("Console.errorMany", () => { - console.error("Hello", "World"); - console.error(1, 2, 3); - }); -}); - -Mocha.describe("Belt_Set.Dict.has", () => { - Mocha.test("Belt_Set.Dict.has", () => { +Mocha.describe("Belt_Set.Dict.minUndefined", () => { + Mocha.test("Belt_Set.Dict.minUndefined", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_SetDict.fromArray([ - 1, - 4, + let s1 = Belt_SetDict.fromArray([ + 3, 2, + 1, 5 ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); }); }); -Mocha.describe("Belt_Set.Dict.add", () => { - Mocha.test("Belt_Set.Dict.add", () => { +Mocha.describe("Belt_Set.Dict.minimum", () => { + Mocha.test("Belt_Set.Dict.minimum", () => { 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); + let s1 = Belt_SetDict.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); }); }); -Mocha.describe("Belt_Set.Dict.get", () => { - Mocha.test("Belt_Set.Dict.get", () => { +Mocha.describe("Belt_Set.Dict.partition", () => { + Mocha.test("Belt_Set.Dict.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, @@ -10405,13 +11460,14 @@ Mocha.describe("Belt_Set.Dict.get", () => { 4, 5 ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); }); }); -Mocha.describe("Belt_SetDict.diff", () => { - Mocha.test("Belt_SetDict.diff", () => { +Mocha.describe("Belt_Set.Dict.reduce", () => { + Mocha.test("Belt_Set.Dict.reduce", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -10423,60 +11479,57 @@ Mocha.describe("Belt_SetDict.diff", () => { 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); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); }); }); -Mocha.describe("Belt_SetDict.some", () => { - Mocha.test("Belt_SetDict.some", () => { +Mocha.describe("Belt_Set.Dict.remove", () => { + Mocha.test("Belt_Set.Dict.remove", () => { 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, + 1, 4, - 6, - 8 + 5 ], IntCmp.cmp); - Belt_SetDict.some(s0, isOdd); + 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.describe("Belt_SetDict.keep", () => { - Mocha.test("Belt_SetDict.keep", () => { +Mocha.describe("Belt_Set.Dict.removeMany", () => { + Mocha.test("Belt_Set.Dict.removeMany", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ + let set = Belt_SetDict.fromArray([ 1, 2, 3, + 4 + ], IntCmp.cmp); + let newSet = Belt_SetDict.removeMany(set, [ + 5, 4, - 5 + 3, + 2, + 1 ], IntCmp.cmp); - let s1 = Belt_SetDict.keep(s0, isEven); - Belt_SetDict.toArray(s1); + Belt_SetDict.toArray(newSet); }); }); -Mocha.describe("Belt_SetDict.size", () => { - Mocha.test("Belt_SetDict.size", () => { +Mocha.describe("Belt_Set.Dict.size", () => { + Mocha.test("Belt_Set.Dict.size", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -10491,1378 +11544,1088 @@ Mocha.describe("Belt_SetDict.size", () => { }); }); -Mocha.describe("Belt_Range.someBy", () => { - Mocha.test("Belt_Range.someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Int.toString", () => { - Mocha.test("Belt_Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); +Mocha.describe("Belt_Set.Dict.some", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_List.headExn", () => { - Mocha.test("Belt_List.headExn", () => { - Pervasives.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", - 8501, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_Set.Dict.split", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_List.tailExn", () => { - Mocha.test("Belt_List.tailExn", () => { - Pervasives.assertEqual(Belt_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Belt_Set.Dict.subset", () => { + Mocha.test("Belt_Set.Dict.subset", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - 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", - 8515, - 7 - ], - Error: new Error() - }; - } - + 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.describe("Belt_List.shuffle", () => { - Mocha.test("Belt_List.shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.Dict.toArray", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_List.splitAt", () => { - Mocha.test("Belt_List.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.describe("Belt_Set.Dict.toList", () => { + Mocha.test("Belt_Set.Dict.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.describe("Belt_List.flatten", () => { - Mocha.test("Belt_List.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.describe("Belt_Set.Dict.union", () => { + Mocha.test("Belt_Set.Dict.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_List.toArray", () => { - Mocha.test("Belt_List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.add", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s0), []); + Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s3), [ + 1, + 2 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt_List.reverse", () => { - Mocha.test("Belt_List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.diff", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); + Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ + 1, + 4 + ]); }); }); -Mocha.describe("Belt_List.forEach", () => { - Mocha.test("Belt_List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); +Mocha.describe("Belt_Set.eq", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); }); }); -Mocha.describe("Belt_List.reduce2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Belt_Set.every", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); }); }); -Mocha.describe("Belt_List.keepMap", () => { - Mocha.test("Belt_List.keepMap", () => { - let isEven = x => x % 2 === 0; - Belt_List.keepMap({ - hd: 1, +Mocha.describe("Belt_Set.forEach", () => { + Mocha.test("Belt_Set.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); + }); + Pervasives.assertEqual(acc.contents, { + hd: 6, tl: { - hd: 2, + hd: 5, tl: { hd: 3, tl: { - hd: 4, + hd: 2, tl: /* [] */0 } } } - }, x => { - if (isEven(x)) { - return x; - } - }); - Belt_List.keepMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); }); }); -Mocha.describe("Belt.Array.length", () => { - Mocha.test("Belt.Array.length", () => {}); -}); - -Mocha.describe("Belt.Array.makeBy", () => { - Mocha.test("Belt.Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, +Mocha.describe("Belt_Set.fromArray", () => { + Mocha.test("Belt_Set.fromArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ 1, - 2, 3, + 2, 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ 1, - 4, - 9, - 16 + 2, + 3, + 4 ]); }); }); -Mocha.describe("Belt.Array.concat", () => { - Mocha.test("Belt.Array.concat", () => { - Primitive_object.equal(Belt_Array.concat([ - 1, - 2, - 3 - ], [ - 4, - 5 - ]), [ +Mocha.describe("Belt_Set.get", () => { + Mocha.test("Belt_Set.get", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ 1, 2, 3, 4, 5 - ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" - ]); + ], IntCmp); + Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); + Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); }); }); -Mocha.describe("Belt.Array.reduce", () => { - Mocha.test("Belt.Array.reduce", () => { - Belt_Array.reduce([ +Mocha.describe("Belt_Set.has", () => { + Mocha.test("Belt_Set.has", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.fromArray([ + 1, + 4, 2, - 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.has(set, 3), false); + Pervasives.assertEqual(Belt_Set.has(set, 1), true); }); }); -Mocha.describe("Belt.Array.every2", () => { - Mocha.test("Belt.Array.every2", () => { - Belt_Array.every2([ - 1, +Mocha.describe("Belt_Set.intersect", () => { + Mocha.test("Belt_Set.intersect", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ + 3, + 5, + 6 + ], IntCmp); + let s1 = Belt_Set.fromArray([ + 5, 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ + 3, + 1, 5, - 0 - ], (x, y) => x > y) === false; - }); -}); - -Mocha.describe("Belt.List.headExn", () => { - Mocha.test("Belt.List.headExn", () => { - Pervasives.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", - 8678, - 7 - ], - Error: new Error() - }; - } - + 4 + ], IntCmp); + let intersect = Belt_Set.intersect(s0, s1); + Pervasives.assertEqual(Belt_Set.toArray(intersect), [ + 2, + 3, + 5 + ]); }); }); -Mocha.describe("Belt.List.tailExn", () => { - Mocha.test("Belt.List.tailExn", () => { - Pervasives.assertEqual(Belt_List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Belt_Set.isEmpty", () => { + Mocha.test("Belt_Set.isEmpty", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - 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", - 8692, - 7 - ], - Error: new Error() - }; - } - + let empty = Belt_Set.fromArray([], IntCmp); + let notEmpty = Belt_Set.fromArray([1], IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); + Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); }); }); -Mocha.describe("Belt.List.shuffle", () => { - Mocha.test("Belt.List.shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.keep", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ + 2, + 4 + ]); }); }); -Mocha.describe("Belt.List.splitAt", () => { - Mocha.test("Belt.List.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.describe("Belt_Set.make", () => { + Mocha.test("Belt_Set.make", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let set = Belt_Set.make(IntCmp); + Pervasives.assertEqual(Belt_Set.isEmpty(set), true); }); }); -Mocha.describe("Belt.List.flatten", () => { - Mocha.test("Belt.List.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.describe("Belt_Set.maxUndefined", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); }); }); -Mocha.describe("Belt.List.toArray", () => { - Mocha.test("Belt.List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } +Mocha.describe("Belt_Set.maximum", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); + Pervasives.assertEqual(Belt_Set.maximum(s1), 5); }); }); -Mocha.describe("Belt.List.reverse", () => { - Mocha.test("Belt.List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.forEach", () => { - Mocha.test("Belt.List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); -}); - -Mocha.describe("Belt.List.reduce2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("Belt.List.keepMap", () => { - Mocha.test("Belt.List.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.describe("Belt.Range.someBy", () => { - Mocha.test("Belt.Range.someBy", () => { - Belt_Range.someBy(1, 5, 2, i => i % 2 === 0); - Belt_Range.someBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt.HashMap.make", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.copy", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.size", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.Int.toString", () => { - Mocha.test("Belt.Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); - }); -}); - -Mocha.describe("Belt.Set.Dict.has", () => { - Mocha.test("Belt.Set.Dict.has", () => { +Mocha.describe("Belt_Set.mergeMany", () => { + Mocha.test("Belt_Set.mergeMany", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let set = Belt_SetDict.fromArray([ - 1, + let set = Belt_Set.make(IntCmp); + let newSet = Belt_Set.mergeMany(set, [ + 5, 4, + 3, + 2, + 1 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + 1, 2, + 3, + 4, 5 - ], IntCmp.cmp); - Belt_SetDict.has(set, 3, IntCmp.cmp); - Belt_SetDict.has(set, 1, IntCmp.cmp); + ]); }); }); -Mocha.describe("Belt.Set.Dict.add", () => { - Mocha.test("Belt.Set.Dict.add", () => { +Mocha.describe("Belt_Set.minUndefined", () => { + Mocha.test("Belt_Set.minUndefined", () => { 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); + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); + Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); }); }); -Mocha.describe("Belt.Set.Dict.get", () => { - Mocha.test("Belt.Set.Dict.get", () => { +Mocha.describe("Belt_Set.minimum", () => { + Mocha.test("Belt_Set.minimum", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_SetDict.fromArray([ - 1, - 2, + let s0 = Belt_Set.make(IntCmp); + let s1 = Belt_Set.fromArray([ 3, - 4, - 5 - ], IntCmp.cmp); - Belt_SetDict.get(s0, 3, IntCmp.cmp); - Belt_SetDict.get(s0, 20, IntCmp.cmp); - }); -}); - -Mocha.describe("Belt_Array.length", () => { - Mocha.test("Belt_Array.length", () => {}); -}); - -Mocha.describe("Belt_Array.makeBy", () => { - Mocha.test("Belt_Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, 1, - 4, - 9, - 16 - ]); + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); + Pervasives.assertEqual(Belt_Set.minimum(s1), 1); }); }); -Mocha.describe("Belt_Array.concat", () => { - Mocha.test("Belt_Array.concat", () => { - Primitive_object.equal(Belt_Array.concat([ +Mocha.describe("Belt_Set.partition", () => { + Mocha.test("Belt_Set.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 - ], [ + 3, 4, 5 - ]), [ + ], IntCmp); + let match = Belt_Set.partition(s0, isOdd); + Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ 1, - 2, 3, - 4, 5 ]); - Primitive_object.equal(Belt_Array.concat([], [ - "a", - "b", - "c" - ]), [ - "a", - "b", - "c" + Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ + 2, + 4 ]); }); }); -Mocha.describe("Belt_Array.reduce", () => { - Mocha.test("Belt_Array.reduce", () => { - Belt_Array.reduce([ +Mocha.describe("Belt_Set.reduce", () => { + Mocha.test("Belt_Set.reduce", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 5, 2, 3, - 4 - ], 1, (a, b) => a + b | 0) === 10; - Belt_Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "abcd"; + 5, + 6 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { + hd: 6, + tl: { + hd: 5, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }); }); }); -Mocha.describe("Belt_Array.every2", () => { - Mocha.test("Belt_Array.every2", () => { - Belt_Array.every2([ +Mocha.describe("Belt_Set.remove", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(s1), [ 2, - 3 - ], [ - 0, - 1 - ], (a, b) => a > b) === true; - Belt_Array.every2([], [1], (x, y) => x > y) === true; - Belt_Array.every2([ + 3, + 4, + 5 + ]); + Pervasives.assertEqual(Belt_Set.toArray(s2), [ 2, - 3 - ], [1], (x, y) => x > y) === true; - Belt_Array.every2([ - 0, - 1 - ], [ - 5, - 0 - ], (x, y) => x > y) === false; + 4, + 5 + ]); + Pervasives.assertEqual(s2, s3); }); }); -Mocha.describe("Belt_HashMap.make", () => { - Mocha.test("Belt_HashMap.make", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt_Set.removeMany", () => { + Mocha.test("Belt_Set.removeMany", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 0, "a"); + let set = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + let newSet = Belt_Set.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ]); + Pervasives.assertEqual(Belt_Set.toArray(newSet), []); }); }); -Mocha.describe("Belt_HashMap.copy", () => { - Mocha.test("Belt_HashMap.copy", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt_Set.size", () => { + Mocha.test("Belt_Set.size", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - 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)); + let s0 = Belt_Set.fromArray([ + 1, + 2, + 3, + 4 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.size(s0), 4); }); }); -Mocha.describe("Belt_HashMap.size", () => { - Mocha.test("Belt_HashMap.size", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Belt_Set.some", () => { + Mocha.test("Belt_Set.some", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - 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.describe("Array.unshiftMany", () => { - Mocha.test("Array.unshiftMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "yay", - "wehoo", - "hi", - "hello" - ]); + let isOdd = x => x % 2 !== 0; + let s0 = Belt_Set.fromArray([ + 1, + 2, + 4, + 6, + 8 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); }); }); -Mocha.describe("Array.reduceRight", () => { - Mocha.test("Array.reduceRight", () => { - Pervasives.assertEqual($$Array.reduceRight([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "dcba"); - Pervasives.assertEqual($$Array.reduceRight([ +Mocha.describe("Belt_Set.split", () => { + Mocha.test("Belt_Set.split", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ 1, 2, - 3 - ], /* [] */0, List.add), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); + 3, + 4, + 5 + ], IntCmp); + let match = Belt_Set.split(s0, 3); + let match$1 = match[0]; + Pervasives.assertEqual(match[1], true); + Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ + 1, + 2 + ]); + Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ + 4, + 5 + ]); }); }); -Mocha.describe("String.codePointAt", () => { - Mocha.test("String.codePointAt", () => { - Primitive_object.equal("¿😺?".codePointAt(1), 128570); - "abc".codePointAt(5) === undefined; +Mocha.describe("Belt_Set.subset", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); + Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); + Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); }); }); -Mocha.describe("String.indexOfFrom", () => { - Mocha.test("String.indexOfFrom", () => { - "bookseller".indexOf("ok", 1) === 2; - "bookseller".indexOf("sell", 2) === 4; - "bookseller".indexOf("sell", 5) === -1; +Mocha.describe("Belt_Set.toArray", () => { + Mocha.test("Belt_Set.toArray", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toArray(s0), [ + 1, + 2, + 3, + 5 + ]); }); }); -Mocha.describe("String.lastIndexOf", () => { - Mocha.test("String.lastIndexOf", () => { - "bookseller".lastIndexOf("ok") === 2; - "beekeeper".lastIndexOf("ee") === 4; - "abcdefg".lastIndexOf("xyz") === -1; +Mocha.describe("Belt_Set.toList", () => { + Mocha.test("Belt_Set.toList", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp + }); + let s0 = Belt_Set.fromArray([ + 3, + 2, + 1, + 5 + ], IntCmp); + Pervasives.assertEqual(Belt_Set.toList(s0), { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 5, + tl: /* [] */0 + } + } + } + }); }); }); -Mocha.describe("String.splitAtMost", () => { - Mocha.test("String.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.describe("Belt_Set.union", () => { + Mocha.test("Belt_Set.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); + Pervasives.assertEqual(Belt_Set.toArray(union), [ + 1, + 2, + 3, + 4, + 5, + 6 ]); }); }); -Mocha.describe("String.toLowerCase", () => { - Mocha.test("String.toLowerCase", () => { - "ABC".toLowerCase() === "abc"; - "ΣΠ".toLowerCase() === "σπ"; - "ΠΣ".toLowerCase() === "πς"; +Mocha.describe("Belt_SetDict.add", () => { + Mocha.test("Belt_SetDict.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.describe("String.toUpperCase", () => { - Mocha.test("String.toUpperCase", () => { - "abc".toUpperCase() === "ABC"; - "Straße".toUpperCase() === "STRASSE"; - "πς".toUpperCase() === "ΠΣ"; +Mocha.describe("Belt_SetDict.diff", () => { + Mocha.test("Belt_SetDict.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.describe("Promise.allSettled", () => { - Mocha.test("Promise.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.describe("Belt_SetDict.empty", () => { + Mocha.test("Belt_SetDict.empty", () => {}); }); -Mocha.describe("Object.keysToArray", () => { - Mocha.test("Object.keysToArray", () => { - Object.keys({ - a: 1, - b: 2 - }); - Object.keys({ - a: undefined +Mocha.describe("Belt_SetDict.eq", () => { + Mocha.test("Belt_SetDict.eq", () => { + let cmp = Primitive_object.compare; + let IntCmp = Belt_Id.MakeComparable({ + cmp: cmp }); - Object.keys({}); + 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.describe("Nullable.undefined", () => { - Mocha.test("Nullable.undefined", () => { - console.log(undefined); +Mocha.describe("Belt_SetDict.every", () => { + Mocha.test("Belt_SetDict.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.describe("Nullable.getUnsafe", () => { - Mocha.test("Nullable.getUnsafe", () => {}); -}); - -Mocha.describe("List.reverseConcat", () => { - Mocha.test("List.reverseConcat", () => { - List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } +Mocha.describe("Belt_SetDict.forEach", () => { + Mocha.test("Belt_SetDict.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.describe("List.reduceReverse", () => { - Mocha.test("List.reduceReverse", () => { - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 10, (a, b) => a - b | 0); - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, /* [] */0, List.add); +Mocha.describe("Belt_SetDict.fromArray", () => { + Mocha.test("Belt_SetDict.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.describe("List.compareLength", () => { - Mocha.test("List.compareLength", () => { - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } +Mocha.describe("Belt_SetDict.get", () => { + Mocha.test("Belt_SetDict.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.describe("Math.Constants.ln2", () => { - Mocha.test("Math.Constants.ln2", () => {}); -}); - -Mocha.describe("Map.forEachWithKey", () => { - Mocha.test("Map.forEachWithKey", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach((value, key) => { - console.log(value, key); +Mocha.describe("Belt_SetDict.has", () => { + Mocha.test("Belt_SetDict.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.describe("JSON.Encode.string", () => { - Mocha.test("JSON.Encode.string", () => {}); -}); - -Mocha.describe("JSON.Encode.object", () => { - Mocha.test("JSON.Encode.object", () => { - Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ] - ]); +Mocha.describe("Belt_SetDict.intersect", () => { + Mocha.test("Belt_SetDict.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.describe("JSON.Decode.string", () => { - Mocha.test("JSON.Decode.string", () => { - $$JSON.Decode.string(JSON.parse("\"hello world\"")); - $$JSON.Decode.string(JSON.parse("42")); +Mocha.describe("Belt_SetDict.isEmpty", () => { + Mocha.test("Belt_SetDict.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.describe("JSON.Decode.object", () => { - Mocha.test("JSON.Decode.object", () => { - $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); - $$JSON.Decode.object(JSON.parse("\"hello world\"")); +Mocha.describe("Belt_SetDict.keep", () => { + Mocha.test("Belt_SetDict.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.describe("Int.toLocaleString", () => { - Mocha.test("Int.toLocaleString", () => { - (1000).toLocaleString(); - (1000).toLocaleString(); +Mocha.describe("Belt_SetDict.maxUndefined", () => { + Mocha.test("Belt_SetDict.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.describe("Date.makeWithYMDHM", () => { - Mocha.test("Date.makeWithYMDHM", () => { - new Date(2023, 1, 20, 16, 40); - new Date(2023, 1, 20, 16, 60); - new Date(2023, 1, 20, 16, -1); +Mocha.describe("Belt_SetDict.maximum", () => { + Mocha.test("Belt_SetDict.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.describe("Date.setFullYearMD", () => { - Mocha.test("Date.setFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); - }); -}); - -Mocha.describe("Date.setMinutesSMs", () => { - Mocha.test("Date.setMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); - }); -}); - -Mocha.describe("Date.getUTCMinutes", () => { - Mocha.test("Date.getUTCMinutes", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); - }); -}); - -Mocha.describe("Date.getUTCSeconds", () => { - Mocha.test("Date.getUTCSeconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); - }); -}); - -Mocha.describe("Date.setUTCHoursMS", () => { - Mocha.test("Date.setUTCHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); - }); -}); - -Mocha.describe("Date.setUTCMinutes", () => { - Mocha.test("Date.setUTCMinutes", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); - }); -}); - -Mocha.describe("Date.setUTCSeconds", () => { - Mocha.test("Date.setUTCSeconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); - }); -}); - -Mocha.describe("Dict.valuesToArray", () => { - Mocha.test("Dict.valuesToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let values = Object.values(dict); - console.log(values); - }); -}); - -Mocha.describe("Console.assertMany", () => { - Mocha.test("Console.assertMany", () => { - console.assert(false, "Hello", "World"); - console.assert(true, 1, 2, 3); - }); -}); - -Mocha.describe("Console.countReset", () => { - Mocha.test("Console.countReset", () => { - console.countReset("rescript"); - }); -}); - -Mocha.describe("Belt_Set.fromArray", () => { - Mocha.test("Belt_Set.fromArray", () => { +Mocha.describe("Belt_SetDict.mergeMany", () => { + Mocha.test("Belt_SetDict.mergeMany", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 1, + let newSet = Belt_SetDict.mergeMany(undefined, [ + 5, + 4, 3, 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); }); }); -Mocha.describe("Belt_Set.mergeMany", () => { - Mocha.test("Belt_Set.mergeMany", () => { +Mocha.describe("Belt_SetDict.minUndefined", () => { + Mocha.test("Belt_SetDict.minUndefined", () => { 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, + let s1 = Belt_SetDict.fromArray([ 3, 2, - 1 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ 1, - 2, - 3, - 4, 5 - ]); + ], IntCmp.cmp); + Belt_SetDict.minUndefined(undefined); + Belt_SetDict.minUndefined(s1); }); }); -Mocha.describe("Belt_Set.intersect", () => { - Mocha.test("Belt_Set.intersect", () => { +Mocha.describe("Belt_SetDict.minimum", () => { + Mocha.test("Belt_SetDict.minimum", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_Set.fromArray([ - 5, - 2, + let s1 = Belt_SetDict.fromArray([ 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, 2, - 3, 1, - 5, - 4 - ], IntCmp); - let intersect = Belt_Set.intersect(s0, s1); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, 5 - ]); + ], IntCmp.cmp); + Belt_SetDict.minimum(undefined); + Belt_SetDict.minimum(s1); }); }); -Mocha.describe("Belt_Set.partition", () => { - Mocha.test("Belt_Set.partition", () => { +Mocha.describe("Belt_SetDict.partition", () => { + Mocha.test("Belt_SetDict.partition", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ + let s0 = Belt_SetDict.fromArray([ 1, 2, 3, 4, 5 - ], IntCmp); - let match = Belt_Set.partition(s0, isOdd); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); + ], IntCmp.cmp); + let match = Belt_SetDict.partition(s0, isOdd); + Belt_SetDict.toArray(match[0]); + Belt_SetDict.toArray(match[1]); }); }); -Mocha.describe("Belt_Set.Dict.diff", () => { - Mocha.test("Belt_Set.Dict.diff", () => { +Mocha.describe("Belt_SetDict.reduce", () => { + Mocha.test("Belt_SetDict.reduce", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp @@ -11874,118 +12637,86 @@ Mocha.describe("Belt_Set.Dict.diff", () => { 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.describe("Belt_Set.Dict.some", () => { - Mocha.test("Belt_Set.Dict.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); + Belt_SetDict.reduce(s0, /* [] */0, Belt_List.add); }); }); -Mocha.describe("Belt_Set.Dict.keep", () => { - Mocha.test("Belt_Set.Dict.keep", () => { +Mocha.describe("Belt_SetDict.remove", () => { + Mocha.test("Belt_SetDict.remove", () => { 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, + 1, 4, 5 ], IntCmp.cmp); - let s1 = Belt_SetDict.keep(s0, isEven); + 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.describe("Belt_Set.Dict.size", () => { - Mocha.test("Belt_Set.Dict.size", () => { +Mocha.describe("Belt_SetDict.removeMany", () => { + Mocha.test("Belt_SetDict.removeMany", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let s0 = Belt_SetDict.fromArray([ + let set = Belt_SetDict.fromArray([ 1, 2, 3, 4 ], IntCmp.cmp); - Belt_SetDict.size(s0); + let newSet = Belt_SetDict.removeMany(set, [ + 5, + 4, + 3, + 2, + 1 + ], IntCmp.cmp); + Belt_SetDict.toArray(newSet); }); }); -Mocha.describe("Belt_SetDict.empty", () => { - Mocha.test("Belt_SetDict.empty", () => {}); -}); - -Mocha.describe("Belt_SetDict.union", () => { - Mocha.test("Belt_SetDict.union", () => { +Mocha.describe("Belt_SetDict.size", () => { + Mocha.test("Belt_SetDict.size", () => { 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, + 1, 2, 3, - 1, - 5, 4 ], IntCmp.cmp); - let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(union); + Belt_SetDict.size(s0); }); }); -Mocha.describe("Belt_SetDict.every", () => { - Mocha.test("Belt_SetDict.every", () => { +Mocha.describe("Belt_SetDict.some", () => { + Mocha.test("Belt_SetDict.some", () => { let cmp = Primitive_object.compare; let IntCmp = Belt_Id.MakeComparable({ cmp: cmp }); - let isEven = x => x % 2 === 0; + let isOdd = x => x % 2 !== 0; let s0 = Belt_SetDict.fromArray([ + 1, 2, 4, 6, 8 ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); + Belt_SetDict.some(s0, isOdd); }); }); @@ -12009,2703 +12740,2641 @@ Mocha.describe("Belt_SetDict.split", () => { }); }); -Mocha.describe("Belt_Result.getExn", () => { - Mocha.test("Belt_Result.getExn", () => { - Pervasives.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", - 9642, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_Range.forEach", () => { - Mocha.test("Belt_Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); +Mocha.describe("Belt_SetDict.subset", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_Range.everyBy", () => { - Mocha.test("Belt_Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Option.getExn", () => { - Mocha.test("Belt_Option.getExn", () => { - Pervasives.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", - 9685, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_Option.orElse", () => { - Mocha.test("Belt_Option.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_Option.isSome", () => { - Mocha.test("Belt_Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); - }); -}); - -Mocha.describe("Belt_Option.isNone", () => { - Mocha.test("Belt_Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); +Mocha.describe("Belt_SetDict.toArray", () => { + Mocha.test("Belt_SetDict.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.describe("Belt_MutableSet.eq", () => { - Mocha.test("Belt_MutableSet.eq", () => { +Mocha.describe("Belt_SetDict.toList", () => { + Mocha.test("Belt_SetDict.toList", () => { 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([ + let s0 = Belt_SetDict.fromArray([ 3, 2, + 1, 5 - ], IntCmp); - Belt_MutableSet.eq(s0, s1); + ], IntCmp.cmp); + Belt_SetDict.toList(s0); }); }); -Mocha.describe("Belt_Map.fromArray", () => { - Mocha.test("Belt_Map.fromArray", () => { +Mocha.describe("Belt_SetDict.union", () => { + Mocha.test("Belt_SetDict.union", () => { 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" - ] - ]); + 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_Int.fromFloat", () => { - Mocha.test("Belt_Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Belt_SortArray.binarySearchBy", () => { + Mocha.test("Belt_SortArray.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.describe("Belt_List.forEach2", () => { - Mocha.test("Belt_List.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.describe("Belt_SortArray.strictlySortedLength", () => { + Mocha.test("Belt_SortArray.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_List.getAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.hasAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.setAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt.Array.reverse", () => { - Mocha.test("Belt.Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ +Mocha.describe("Belt_internalMapInt.A.blit", () => { + Mocha.test("Belt_internalMapInt.A.blit", () => { + let v1 = [ 10, 11, 12, 13, - 14 - ]), [ 14, - 13, - 12, + 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, - 10 + 14, + 15, + 16, + 15, + 16, + 17 ]); }); }); -Mocha.describe("Belt.Array.rangeBy", () => { - Mocha.test("Belt.Array.rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, +Mocha.describe("Belt_internalMapInt.A.cmp", () => { + Mocha.test("Belt_internalMapInt.A.cmp", () => { + Belt_Array.cmp([ + 1, 3, - 6, - 9 - ]); - Primitive_object.equal(Belt_Array.rangeBy(0, 12, 3), [ - 0, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, 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.describe("Belt.Array.forEach", () => { - Mocha.test("Belt.Array.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ + 5 + ], [ 1, 2, + 3 + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ + 1, 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; }); }); -Mocha.describe("Belt.Array.flatMap", () => { - Mocha.test("Belt.Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ +Mocha.describe("Belt_internalMapInt.A.concat", () => { + Mocha.test("Belt_internalMapInt.A.concat", () => { + Primitive_object.equal(Belt_Array.concat([ 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 + 2, + 3 + ], [ + 4, + 5 ]), [ - 11, - 21, - 12, - 22 + 1, + 2, + 3, + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" ]); }); }); -Mocha.describe("Belt.Array.keepMap", () => { - Mocha.test("Belt.Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ +Mocha.describe("Belt_internalMapInt.A.concatMany", () => { + Mocha.test("Belt_internalMapInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ 1, 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Belt.List.forEach2", () => { - Mocha.test("Belt.List.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.describe("Belt_internalMapInt.A.eq", () => { + Mocha.test("Belt_internalMapInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Belt.List.getAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt_internalMapInt.A.every", () => { + Mocha.test("Belt_internalMapInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt.List.hasAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt_internalMapInt.A.every2", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt.List.setAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt_internalMapInt.A.fill", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt.Range.forEach", () => { - Mocha.test("Belt.Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); -}); - -Mocha.describe("Belt.Range.everyBy", () => { - Mocha.test("Belt.Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); +Mocha.describe("Belt_internalMapInt.A.flatMap", () => { + Mocha.test("Belt_internalMapInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Belt.Set.fromArray", () => { - Mocha.test("Belt.Set.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_internalMapInt.A.forEach", () => { + Mocha.test("Belt_internalMapInt.A.forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ + let total = { + contents: 0 + }; + Belt_Array.forEach([ 1, 2, 3, 4 - ]); + ], x => { + total.contents = total.contents + x | 0; + }); }); }); -Mocha.describe("Belt.Set.mergeMany", () => { - Mocha.test("Belt.Set.mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_internalMapInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.forEachWithIndex", () => { + Belt_Array.forEachWithIndex([ + "a", + "b", + "c" + ], (i, x) => { + console.log("Item " + String(i) + " is " + x); }); - let set = Belt_Set.make(IntCmp); - let newSet = Belt_Set.mergeMany(set, [ - 5, + let total = { + contents: 0 + }; + Belt_Array.forEachWithIndex([ + 10, + 11, + 12, + 13 + ], (i, x) => { + total.contents = (total.contents + x | 0) + i | 0; + }); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.get", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.getBy", () => { + Mocha.test("Belt_internalMapInt.A.getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ + 1, 4, 3, - 2, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.getIndexBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.joinWith", () => { + Mocha.test("Belt_internalMapInt.A.joinWith", () => { + Belt_Array.joinWith([ + 0, 1 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ + ], ", ", prim => prim.toString()) === "0, 1"; + Belt_Array.joinWith([], " ", prim => prim.toString()) === ""; + Belt_Array.joinWith([1], " ", prim => prim.toString()) === "1"; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.keepMap", () => { + Mocha.test("Belt_internalMapInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ 1, 2, - 3, - 4, - 5 - ]); + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Belt.Set.intersect", () => { - Mocha.test("Belt.Set.intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, +Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_Set.fromArray([ - 5, + 3 + ], (_x, i) => i === 1), [2]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.length", () => { + Mocha.test("Belt_internalMapInt.A.length", () => {}); +}); + +Mocha.describe("Belt_internalMapInt.A.makeBy", () => { + Mocha.test("Belt_internalMapInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, 2, 3, - 1, - 5, 4 - ], IntCmp); - let intersect = Belt_Set.intersect(s0, s1); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ - 2, + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); +}); + +Mocha.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.map", () => { + Mocha.test("Belt_internalMapInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ 3, - 5 + 4 ]); }); }); -Mocha.describe("Belt.Set.partition", () => { - Mocha.test("Belt.Set.partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_Set.fromArray([ +Mocha.describe("Belt_internalMapInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ 1, 2, - 3, - 4, - 5 - ], IntCmp); - let match = Belt_Set.partition(s0, isOdd); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ + 3 + ], (i, x) => i + x | 0), [ 1, 3, 5 ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); }); }); -Mocha.describe("Belt.Map.fromArray", () => { - Mocha.test("Belt.Map.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.toArray(Belt_Map.fromArray([ +Mocha.describe("Belt_internalMapInt.A.partition", () => { + Mocha.test("Belt_internalMapInt.A.partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 === 0), [ [ 2, - "2" + 4 ], [ 1, - "1" - ], - [ 3, - "3" + 5 ] - ], IntCmp)), [ + ]); + Primitive_object.equal(Belt_Array.partition([ + 1, + 2, + 3, + 4, + 5 + ], x => x % 2 !== 0), [ [ 1, - "1" + 3, + 5 ], [ 2, - "2" - ], - [ - 3, - "3" + 4 ] ]); }); }); -Mocha.describe("Belt.MutableSet.eq", () => { - Mocha.test("Belt.MutableSet.eq", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, +Mocha.describe("Belt_internalMapInt.A.range", () => { + Mocha.test("Belt_internalMapInt.A.range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, + 1, 2, 3 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 5 - ], IntCmp); - Belt_MutableSet.eq(s0, s1); - }); -}); - -Mocha.describe("Belt.HashMap.clear", () => { - Mocha.test("Belt.HashMap.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; + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); }); }); -Mocha.describe("Belt.Option.getExn", () => { - Mocha.test("Belt.Option.getExn", () => { - Pervasives.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", - 10120, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_internalMapInt.A.rangeBy", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt.Option.orElse", () => { - Mocha.test("Belt.Option.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_internalMapInt.A.reduce", () => { + Mocha.test("Belt_internalMapInt.A.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.describe("Belt.Option.isSome", () => { - Mocha.test("Belt.Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); +Mocha.describe("Belt_internalMapInt.A.reduceReverse", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt.Option.isNone", () => { - Mocha.test("Belt.Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); +Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, + 2, + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt.Result.getExn", () => { - Mocha.test("Belt.Result.getExn", () => { - Pervasives.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", - 10170, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_internalMapInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, + 2, + 3, + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Belt.Int.fromFloat", () => { - Mocha.test("Belt.Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); +Mocha.describe("Belt_internalMapInt.A.reverse", () => { + Mocha.test("Belt_internalMapInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt.Float.fromInt", () => { - Mocha.test("Belt.Float.fromInt", () => { - console.log(1 === 1.0); +Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt.Set.Dict.diff", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.some", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.keep", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.size", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt_Float.fromInt", () => { - Mocha.test("Belt_Float.fromInt", () => { - console.log(1 === 1.0); - }); -}); - -Mocha.describe("Belt_Array.reverse", () => { - Mocha.test("Belt_Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ +Mocha.describe("Belt_internalMapInt.A.slice", () => { + Mocha.test("Belt_internalMapInt.A.slice", () => { + Primitive_object.equal(Belt_Array.slice([ 10, 11, 12, 13, - 14 - ]), [ 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, - 10 + 12, + 13, + 14, + 15, + 16 + ], 4, 9), [ + 14, + 15, + 16 ]); }); }); -Mocha.describe("Belt_Array.rangeBy", () => { - Mocha.test("Belt_Array.rangeBy", () => { - Primitive_object.equal(Belt_Array.rangeBy(0, 10, 3), [ - 0, - 3, - 6, - 9 +Mocha.describe("Belt_internalMapInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapInt.A.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.rangeBy(0, 12, 3), [ - 0, - 3, - 6, - 9, - 12 + Primitive_object.equal(Belt_Array.sliceToEnd([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], -4), [ + 13, + 14, + 15, + 16 ]); - 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.describe("Belt_Array.forEach", () => { - Mocha.test("Belt_Array.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); - }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ - 1, +Mocha.describe("Belt_internalMapInt.A.some", () => { + Mocha.test("Belt_internalMapInt.A.some", () => { + Belt_Array.some([ 2, 3, 4 - ], x => { - total.contents = total.contents + x | 0; - }); + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_Array.flatMap", () => { - Mocha.test("Belt_Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, +Mocha.describe("Belt_internalMapInt.A.some2", () => { + Mocha.test("Belt_internalMapInt.A.some2", () => { + Belt_Array.some2([ + 0, 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_Array.keepMap", () => { - Mocha.test("Belt_Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ + ], [ 1, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ 2, 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); + ], [ + 1, + 4 + ], (x, y) => x > y) === true; }); }); -Mocha.describe("Belt_HashMap.clear", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("AsyncIterator.make", () => { - Mocha.test("AsyncIterator.make", () => { - let context = { - contents: 0 - }; - let asyncIterator = $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - return { - done: currentValue >= 3, - value: currentValue - }; - }); - let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { - if (value !== undefined) { - console.log(value); - return; - } - - }); - main(); - }); -}); - -Mocha.describe("AsyncIterator.done", () => { - Mocha.test("AsyncIterator.done", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); - } - }); - }); -}); - -Mocha.describe("AsyncIterator.next", () => { - Mocha.test("AsyncIterator.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) { - Pervasives.assertEqual(Option.isNone(match.value), true); - } - - }; - }; - processMyAsyncIterator(); - }); -}); - -Mocha.describe("Array.fromIterator", () => { - Mocha.test("Array.fromIterator", () => { - Pervasives.assertEqual(Array.from(new Map([ +Mocha.describe("Belt_internalMapInt.A.unzip", () => { + Mocha.test("Belt_internalMapInt.A.unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ [ - "foo", - 1 + 1, + 2 ], [ - "bar", + 3, + 4 + ] + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); + Primitive_object.equal(Belt_Array.unzip([ + [ + 1, 2 + ], + [ + 3, + 4 + ], + [ + 5, + 6 + ], + [ + 7, + 8 ] - ]).values()), [ + ]), [ + [ + 1, + 3, + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 + ] + ]); + }); +}); + +Mocha.describe("Belt_internalMapInt.A.zip", () => { + Mocha.test("Belt_internalMapInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ 1, 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] ]); }); }); -Mocha.describe("Array.mapWithIndex", () => { - Mocha.test("Array.mapWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); - Pervasives.assertEqual(mappedArray, [ - "Hello at position 0", - "Hi at position 1", - "Good bye at position 2" +Mocha.describe("Belt_internalMapInt.A.zipBy", () => { + Mocha.test("Belt_internalMapInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 ]); }); }); -Mocha.describe("Array.findIndexOpt", () => { - Mocha.test("Array.findIndexOpt", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); +Mocha.describe("Belt_internalMapInt.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapInt.S.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.describe("String.fromCharCode", () => { - Mocha.test("String.fromCharCode", () => { - String.fromCharCode(65) === "A"; - String.fromCharCode(968) === "ψ"; - String.fromCharCode(54620) === "한"; - String.fromCharCode(-64568) === "ψ"; +Mocha.describe("Belt_internalMapInt.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapInt.S.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("String.endsWithFrom", () => { - Mocha.test("String.endsWithFrom", () => { - "abcd".endsWith("cd", 4) === true; - "abcde".endsWith("cd", 3) === false; - "abcde".endsWith("cde", 99) === true; - "example.dat".endsWith("ple", 7) === true; +Mocha.describe("Belt_internalMapString.A.blit", () => { + Mocha.test("Belt_internalMapString.A.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.describe("String.includesFrom", () => { - Mocha.test("String.includesFrom", () => { - "programmer".includes("gram", 1) === true; - "programmer".includes("gram", 4) === false; - "대한민국".includes("한", 1) === true; +Mocha.describe("Belt_internalMapString.A.cmp", () => { + Mocha.test("Belt_internalMapString.A.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.describe("RegExp.setLastIndex", () => { - Mocha.test("RegExp.setLastIndex", () => { - let regexp = new RegExp("\\w+"); - regexp.lastIndex = 4; - regexp.exec("Many words here."); - console.log(regexp.lastIndex); +Mocha.describe("Belt_internalMapString.A.concat", () => { + Mocha.test("Belt_internalMapString.A.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.describe("RegExp.Result.input", () => { - Mocha.test("RegExp.Result.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.describe("Belt_internalMapString.A.concatMany", () => { + Mocha.test("Belt_internalMapString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Promise.thenResolve", () => { - Mocha.test("Promise.thenResolve", () => { - Promise.resolve("Anna").then(str => "Hello " + str).then(str => { - console.log(str); - }); +Mocha.describe("Belt_internalMapString.A.eq", () => { + Mocha.test("Belt_internalMapString.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Object.isExtensible", () => { - Mocha.test("Object.isExtensible", () => { - let obj = { - a: 1 - }; - Object.isExtensible(obj); - Object.preventExtensions(obj); - Object.isExtensible(obj); +Mocha.describe("Belt_internalMapString.A.every", () => { + Mocha.test("Belt_internalMapString.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Nullable.isNullable", () => { - Mocha.test("Nullable.isNullable", () => { - if ("Hello" == null) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 10610, - 10 - ], - Error: new Error() - }; - } - +Mocha.describe("Belt_internalMapString.A.every2", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Nullable.fromOption", () => { - Mocha.test("Nullable.fromOption", () => { - Nullable.fromOption("Hello"); +Mocha.describe("Belt_internalMapString.A.fill", () => { + Mocha.test("Belt_internalMapString.A.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.describe("List.reduceReverse2", () => { - Mocha.test("List.reduceReverse2", () => { - List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Belt_internalMapString.A.flatMap", () => { + Mocha.test("Belt_internalMapString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Math.Constants.ln10", () => { - Mocha.test("Math.Constants.ln10", () => {}); -}); - -Mocha.describe("Float.toExponential", () => { - Mocha.test("Float.toExponential", () => { - (1000.0).toExponential(); - (-1000.0).toExponential(); - (77.0).toExponential(2); - (5678.0).toExponential(2); +Mocha.describe("Belt_internalMapString.A.forEach", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Float.Constants.nan", () => { - Mocha.test("Float.Constants.nan", () => {}); -}); - -Mocha.describe("Date.makeWithYMDHMS", () => { - Mocha.test("Date.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.describe("Belt_internalMapString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Date.getUTCFullYear", () => { - Mocha.test("Date.getUTCFullYear", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); +Mocha.describe("Belt_internalMapString.A.get", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Date.setUTCFullYear", () => { - Mocha.test("Date.setUTCFullYear", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); +Mocha.describe("Belt_internalMapString.A.getBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Date.setUTCMinutesS", () => { - Mocha.test("Date.setUTCMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); +Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Date.toLocaleString", () => { - Mocha.test("Date.toLocaleString", () => { - console.log(new Date().toLocaleString()); +Mocha.describe("Belt_internalMapString.A.joinWith", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Date.UTC.makeWithYM", () => { - Mocha.test("Date.UTC.makeWithYM", () => { - Date.UTC(2023, 0); - Date.UTC(2023, 11); - Date.UTC(2023, 12); - Date.UTC(2023, -1); +Mocha.describe("Belt_internalMapString.A.keepMap", () => { + Mocha.test("Belt_internalMapString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Dict.forEachWithKey", () => { - Mocha.test("Dict.forEachWithKey", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEachWithKey(dict, (value, key) => { - console.log(value, key); - }); +Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { + Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("Belt_Set.removeMany", () => { - Mocha.test("Belt_Set.removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ +Mocha.describe("Belt_internalMapString.A.length", () => { + Mocha.test("Belt_internalMapString.A.length", () => {}); +}); + +Mocha.describe("Belt_internalMapString.A.makeBy", () => { + Mocha.test("Belt_internalMapString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, 1, 2, 3, 4 - ], IntCmp); - let newSet = Belt_Set.removeMany(set, [ - 5, + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, 4, - 3, - 2, - 1 + 9, + 16 ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); }); }); -Mocha.describe("Belt_Set.Dict.empty", () => { - Mocha.test("Belt_Set.Dict.empty", () => {}); +Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { + Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; + }); }); -Mocha.describe("Belt_Set.Dict.union", () => { - Mocha.test("Belt_Set.Dict.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_internalMapString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_Set.Dict.every", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_internalMapString.A.map", () => { + Mocha.test("Belt_internalMapString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Belt_Set.Dict.split", () => { - Mocha.test("Belt_Set.Dict.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { + Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ 1, 2, + 3 + ], (i, x) => i + x | 0), [ + 1, 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.describe("Belt_SetDict.remove", () => { - Mocha.test("Belt_SetDict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Belt_internalMapString.A.partition", () => { + Mocha.test("Belt_internalMapString.A.partition", () => { + Primitive_object.equal(Belt_Array.partition([ + 1, 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.describe("Belt_SetDict.subset", () => { - Mocha.test("Belt_SetDict.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, + ], x => x % 2 === 0), [ + [ + 2, + 4 + ], + [ + 1, + 3, + 5 + ] + ]); + Primitive_object.equal(Belt_Array.partition([ 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.describe("Belt_SetDict.reduce", () => { - Mocha.test("Belt_SetDict.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); + 4, + 5 + ], x => x % 2 !== 0), [ + [ + 1, + 3, + 5 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Belt_SetDict.toList", () => { - Mocha.test("Belt_SetDict.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, +Mocha.describe("Belt_internalMapString.A.range", () => { + Mocha.test("Belt_internalMapString.A.range", () => { + Primitive_object.equal(Belt_Array.range(0, 3), [ + 0, 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); + 2, + 3 + ]); + Primitive_object.equal(Belt_Array.range(3, 0), []); + Primitive_object.equal(Belt_Array.range(3, 3), [3]); }); }); -Mocha.describe("Belt_Result.flatMap", () => { - Mocha.test("Belt_Result.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.describe("Belt_internalMapString.A.rangeBy", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_Option.forEach", () => { - Mocha.test("Belt_Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); +Mocha.describe("Belt_internalMapString.A.reduce", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt_Option.flatMap", () => { - Mocha.test("Belt_Option.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.describe("Belt_internalMapString.A.reduceReverse", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt_MutableSet.has", () => { - Mocha.test("Belt_MutableSet.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { + Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ 1, - 4, 2, - 5 - ], IntCmp); - Belt_MutableSet.has(set, 3); - Belt_MutableSet.has(set, 1); - }); -}); - -Mocha.describe("Belt_MutableSet.add", () => { - Mocha.test("Belt_MutableSet.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); + 3 + ], [ + 1, + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt_MutableSet.get", () => { - Mocha.test("Belt_MutableSet.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ 1, 2, 3, - 4, - 5 - ], IntCmp); - Belt_MutableSet.get(s0, 3); - Belt_MutableSet.get(s0, 20); + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Belt_Int.fromString", () => { - Mocha.test("Belt_Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); +Mocha.describe("Belt_internalMapString.A.reverse", () => { + Mocha.test("Belt_internalMapString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt_List.fromArray", () => { - Mocha.test("Belt_List.fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 +Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { + Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 ]); }); }); -Mocha.describe("Belt_List.partition", () => { - Mocha.test("Belt_List.partition", () => { - Pervasives.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.describe("Belt_internalMapString.A.slice", () => { + Mocha.test("Belt_internalMapString.A.slice", () => { + Primitive_object.equal(Belt_Array.slice([ + 10, + 11, + 12, + 13, + 14, + 15, + 16 + ], 2, 3), [ + 12, + 13, + 14 ]); - }); -}); - -Mocha.describe("Belt.Array.joinWith", () => { - Mocha.test("Belt.Array.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.describe("Belt.List.fromArray", () => { - Mocha.test("Belt.List.fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 + 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.describe("Belt.List.partition", () => { - Mocha.test("Belt.List.partition", () => { - Pervasives.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.describe("Belt_internalMapString.A.sliceToEnd", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt.Set.removeMany", () => { - Mocha.test("Belt.Set.removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, +Mocha.describe("Belt_internalMapString.A.some", () => { + Mocha.test("Belt_internalMapString.A.some", () => { + Belt_Array.some([ 2, 3, 4 - ], IntCmp); - let newSet = Belt_Set.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt.MutableSet.has", () => { - Mocha.test("Belt.MutableSet.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalMapString.A.some2", () => { + Mocha.test("Belt_internalMapString.A.some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ 1, - 4, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ 2, - 5 - ], IntCmp); - Belt_MutableSet.has(set, 3); - Belt_MutableSet.has(set, 1); + 3 + ], [ + 1, + 4 + ], (x, y) => x > y) === true; }); }); -Mocha.describe("Belt.MutableSet.add", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("Belt.MutableSet.get", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.HashMap.remove", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.reduce", () => { - Mocha.test("Belt.HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); - }); -}); - -Mocha.describe("Belt.Option.forEach", () => { - Mocha.test("Belt.Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Belt.Option.flatMap", () => { - Mocha.test("Belt.Option.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.describe("Belt.Result.flatMap", () => { - Mocha.test("Belt.Result.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.describe("Belt_internalMapString.A.unzip", () => { + Mocha.test("Belt_internalMapString.A.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.describe("Belt.Int.fromString", () => { - Mocha.test("Belt.Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); +Mocha.describe("Belt_internalMapString.A.zip", () => { + Mocha.test("Belt_internalMapString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ + 1, + 2 + ], [ + 3, + 4, + 5 + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Belt.Float.toString", () => { - Mocha.test("Belt.Float.toString", () => { - console.log(String(1.0) === "1.0"); +Mocha.describe("Belt_internalMapString.A.zipBy", () => { + Mocha.test("Belt_internalMapString.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Belt.Set.Dict.empty", () => { - Mocha.test("Belt.Set.Dict.empty", () => {}); -}); - -Mocha.describe("Belt.Set.Dict.union", () => { - Mocha.test("Belt.Set.Dict.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, +Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { + Mocha.test("Belt_internalMapString.S.binarySearchBy", () => { + Belt_SortArray.binarySearchBy([ + 1, 2, 3, + 4, + 33, + 35, + 36 + ], 33, Primitive_int.compare) === 4; + Pervasives.lnot(Belt_SortArray.binarySearchBy([ 1, + 3, 5, - 4 - ], IntCmp.cmp); - let union = Belt_SetDict.union(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(union); + 7 + ], 4, Primitive_int.compare)) === 2; }); }); -Mocha.describe("Belt.Set.Dict.every", () => { - Mocha.test("Belt.Set.Dict.every", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Belt_internalMapString.S.strictlySortedLength", () => { + Mocha.test("Belt_internalMapString.S.strictlySortedLength", () => { + Belt_SortArray.strictlySortedLength([ + 1, 2, + 3, 4, - 6, - 8 - ], IntCmp.cmp); - Belt_SetDict.every(s0, isEven); + 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.Set.Dict.split", () => { - Mocha.test("Belt.Set.Dict.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Belt_internalSetInt.A.blit", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.cmp", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.concat", () => { + Mocha.test("Belt_internalSetInt.A.concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, + 2, + 3 + ], [ + 4, + 5 + ]), [ 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]); + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); }); }); -Mocha.describe("Belt_Float.toString", () => { - Mocha.test("Belt_Float.toString", () => { - console.log(String(1.0) === "1.0"); +Mocha.describe("Belt_internalSetInt.A.concatMany", () => { + Mocha.test("Belt_internalSetInt.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + ]); }); }); -Mocha.describe("Belt_Array.joinWith", () => { - Mocha.test("Belt_Array.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.describe("Belt_internalSetInt.A.eq", () => { + Mocha.test("Belt_internalSetInt.A.eq", () => { + Belt_Array.eq([ + 1, + 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; }); }); -Mocha.describe("Belt_HashMap.remove", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_internalSetInt.A.every", () => { + Mocha.test("Belt_internalSetInt.A.every", () => { + Belt_Array.every([ + 1, + 3, + 5 + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_HashMap.reduce", () => { - Mocha.test("Belt_HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); +Mocha.describe("Belt_internalSetInt.A.every2", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("AsyncIterator.value", () => { - Mocha.test("AsyncIterator.value", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); - } - }); +Mocha.describe("Belt_internalSetInt.A.fill", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Array.findWithIndex", () => { - Mocha.test("Array.findWithIndex", () => { - let array = [ - "TypeScript", - "JavaScript", - "ReScript" - ]; - Pervasives.assertEqual(array.find((item, index) => { - if (index > 1) { - return item === "ReScript"; - } else { - return false; - } - }), "ReScript"); +Mocha.describe("Belt_internalSetInt.A.flatMap", () => { + Mocha.test("Belt_internalSetInt.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 + ]); }); }); -Mocha.describe("Array.someWithIndex", () => { - Mocha.test("Array.someWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some((greeting, index) => { - if (greeting === "Hello") { - return index === 0; - } else { - return false; - } - }), true); +Mocha.describe("Belt_internalSetInt.A.forEach", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.fromCodePoint", () => { - Mocha.test("String.fromCodePoint", () => { - String.fromCodePoint(65) === "A"; - String.fromCodePoint(968) === "ψ"; - String.fromCodePoint(54620) === "한"; - String.fromCodePoint(128570) === "😺"; +Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.normalizeForm", () => { - Mocha.test("String.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.describe("Belt_internalSetInt.A.get", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.replaceRegExp", () => { - Mocha.test("String.replaceRegExp", () => { - "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; +Mocha.describe("Belt_internalSetInt.A.getBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.splitByRegExp", () => { - Mocha.test("String.splitByRegExp", () => { - Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ - "Jan", - "Feb", - "Mar" - ]); +Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("String.localeCompare", () => { - Mocha.test("String.localeCompare", () => { - "a".localeCompare("c") < 0.0 === true; - "a".localeCompare("a") === 0.0; +Mocha.describe("Belt_internalSetInt.A.joinWith", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Pervasives.encodeURI", () => { - Mocha.test("Pervasives.encodeURI", () => { - console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); +Mocha.describe("Belt_internalSetInt.A.keepMap", () => { + Mocha.test("Belt_internalSetInt.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Pervasives.decodeURI", () => { - Mocha.test("Pervasives.decodeURI", () => { - console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); +Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ + 1, + 2, + 3 + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("List.fromInitializer", () => { - Mocha.test("List.fromInitializer", () => { - List.fromInitializer(5, i => i); - List.fromInitializer(5, i => Math.imul(i, i)); - }); +Mocha.describe("Belt_internalSetInt.A.length", () => { + Mocha.test("Belt_internalSetInt.A.length", () => {}); }); -Mocha.describe("List.reduceWithIndex", () => { - Mocha.test("List.reduceWithIndex", () => { - 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.describe("Belt_internalSetInt.A.makeBy", () => { + Mocha.test("Belt_internalSetInt.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, + 1, + 2, + 3, + 4 + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("List.filterWithIndex", () => { - Mocha.test("List.filterWithIndex", () => { - List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); +Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("Math.Constants.log2e", () => { - Mocha.test("Math.Constants.log2e", () => {}); +Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Math.Constants.sqrt2", () => { - Mocha.test("Math.Constants.sqrt2", () => {}); +Mocha.describe("Belt_internalSetInt.A.map", () => { + Mocha.test("Belt_internalSetInt.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); + }); }); -Mocha.describe("Int.rangeWithOptions", () => { - Mocha.test("Int.rangeWithOptions", () => { - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2 - }), [ +Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, 3, 5 ]); - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Int.rangeWithOptions(3, 6, { - step: -2 - }); - }); -}); - -Mocha.describe("Float.toLocaleString", () => { - Mocha.test("Float.toLocaleString", () => { - (1000.0).toLocaleString(); - (1000.0).toLocaleString(); - }); -}); - -Mocha.describe("Date.makeWithYMDHMSM", () => { - Mocha.test("Date.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.describe("Date.getMilliseconds", () => { - Mocha.test("Date.getMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").getMilliseconds(); - }); -}); - -Mocha.describe("Date.setMilliseconds", () => { - Mocha.test("Date.setMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setMilliseconds(0); }); }); -Mocha.describe("Date.setUTCFullYearM", () => { - Mocha.test("Date.setUTCFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); +Mocha.describe("Belt_internalSetInt.A.partition", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Date.setUTCHoursMSMs", () => { - Mocha.test("Date.setUTCHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); +Mocha.describe("Belt_internalSetInt.A.range", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Date.setUTCSecondsMs", () => { - Mocha.test("Date.setUTCSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); +Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Date.UTC.makeWithYMD", () => { - Mocha.test("Date.UTC.makeWithYMD", () => { - Date.UTC(2023, 1, 20); - Date.UTC(2023, 1, -1); - Date.UTC(2023, 1, 29); +Mocha.describe("Belt_internalSetInt.A.reduce", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("BigInt.fromStringExn", () => { - Mocha.test("BigInt.fromStringExn", () => { - BigInt("123"); - BigInt(""); - BigInt("0x11"); - BigInt("0b11"); - BigInt("0o11"); - try { - BigInt("a"); - } catch (raw__error) { - let _error = Primitive_exceptions.internalToException(raw__error); - if (_error.RE_EXN_ID !== Exn.$$Error) { - throw _error; - } - - } +Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt_Set.Dict.remove", () => { - Mocha.test("Belt_Set.Dict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ + 1, 2, - 3, + 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); + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt_Set.Dict.subset", () => { - Mocha.test("Belt_Set.Dict.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, +Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, 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); + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Belt_Set.Dict.reduce", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetInt.A.reverse", () => { + Mocha.test("Belt_internalSetInt.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt_Set.Dict.toList", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_SetDict.isEmpty", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_internalSetInt.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt_SetDict.forEach", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_internalSetInt.A.slice", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_SetDict.toArray", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_internalSetInt.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetInt.A.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.describe("Belt_SetDict.minimum", () => { - Mocha.test("Belt_SetDict.minimum", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s1 = Belt_SetDict.fromArray([ - 3, +Mocha.describe("Belt_internalSetInt.A.some", () => { + Mocha.test("Belt_internalSetInt.A.some", () => { + Belt_Array.some([ 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minimum(undefined); - Belt_SetDict.minimum(s1); - }); -}); - -Mocha.describe("Belt_SetDict.maximum", () => { - Mocha.test("Belt_SetDict.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); + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt_MutableSet.copy", () => { - Mocha.test("Belt_MutableSet.copy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalSetInt.A.some2", () => { + Mocha.test("Belt_internalSetInt.A.some2", () => { + Belt_Array.some2([ + 0, + 2 + ], [ 1, - 3, + 0, + 3 + ], (a, b) => a > b) === true; + Belt_Array.some2([], [1], (x, y) => x > y) === false; + Belt_Array.some2([ 2, + 3 + ], [ + 1, 4 - ], IntCmp); - let copied = Belt_MutableSet.copy(s0); - Belt_MutableSet.toArray(copied); + ], (x, y) => x > y) === true; }); }); -Mocha.describe("Belt_MutableSet.diff", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("Belt_MutableSet.some", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.keep", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.size", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_Map.findFirstBy", () => { - Mocha.test("Belt_Map.findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Map.fromArray([ +Mocha.describe("Belt_internalSetInt.A.unzip", () => { + Mocha.test("Belt_internalSetInt.A.unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ [ - 4, - "4" + 1, + 2 ], + [ + 3, + 4 + ] + ]), [ [ 1, - "1" + 3 ], [ 2, - "2" - ], - [ - 3, - "" + 4 ] - ], IntCmp); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" ]); - }); -}); - -Mocha.describe("Belt_Map.keysToArray", () => { - Mocha.test("Belt_Map.keysToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Primitive_object.equal(Belt_Map.keysToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], + Primitive_object.equal(Belt_Array.unzip([ [ 1, - "1" + 2 ], [ 3, - "3" - ] - ], IntCmp)), [ - 1, - 2, - 3 - ]); - }); -}); - -Mocha.describe("Belt_List.concatMany", () => { - Mocha.test("Belt_List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); -}); - -Mocha.describe("Belt_List.mapReverse", () => { - Mocha.test("Belt_List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.Array.partition", () => { - Mocha.test("Belt.Array.partition", () => { - Primitive_object.equal(Belt_Array.partition([ - 1, - 2, - 3, - 4, - 5 - ], x => x % 2 === 0), [ - [ - 2, 4 ], + [ + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ [ 1, 3, - 5 + 5, + 7 + ], + [ + 2, + 4, + 6, + 8 ] ]); - Primitive_object.equal(Belt_Array.partition([ + }); +}); + +Mocha.describe("Belt_internalSetInt.A.zip", () => { + Mocha.test("Belt_internalSetInt.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ 1, - 2, + 2 + ], [ 3, 4, 5 - ], x => x % 2 !== 0), [ + ]), [ [ 1, - 3, - 5 + 3 ], [ 2, @@ -14715,935 +15384,661 @@ Mocha.describe("Belt.Array.partition", () => { }); }); -Mocha.describe("Belt.List.concatMany", () => { - Mocha.test("Belt.List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } +Mocha.describe("Belt_internalSetInt.A.zipBy", () => { + Mocha.test("Belt_internalSetInt.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ + 1, + 2, + 3 + ], [ + 4, + 5 + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 ]); }); }); -Mocha.describe("Belt.List.mapReverse", () => { - Mocha.test("Belt.List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.Map.findFirstBy", () => { - Mocha.test("Belt.Map.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); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" +Mocha.describe("Belt_internalSetString.A.blit", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt.Map.keysToArray", () => { - Mocha.test("Belt.Map.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)), [ +Mocha.describe("Belt_internalSetString.A.cmp", () => { + Mocha.test("Belt_internalSetString.A.cmp", () => { + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ + 1, + 4, + 2 + ], Primitive_int.compare) === -1; + Belt_Array.cmp([ + 1, + 3, + 5 + ], [ 1, 2, 3 - ]); - }); -}); - -Mocha.describe("Belt.MutableSet.copy", () => { - Mocha.test("Belt.MutableSet.copy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ + ], Primitive_int.compare) === 1; + Belt_Array.cmp([ 1, 3, - 2, - 4 - ], IntCmp); - let copied = Belt_MutableSet.copy(s0); - Belt_MutableSet.toArray(copied); + 5 + ], [ + 1, + 3, + 5 + ], Primitive_int.compare) === 0; }); }); -Mocha.describe("Belt.MutableSet.diff", () => { - Mocha.test("Belt.MutableSet.diff", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, +Mocha.describe("Belt_internalSetString.A.concat", () => { + Mocha.test("Belt_internalSetString.A.concat", () => { + Primitive_object.equal(Belt_Array.concat([ + 1, 2, - 3, - 5, - 6 - ], IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 5, + 3 + ], [ + 4, + 5 + ]), [ + 1, 2, 3, - 1, - 5, - 4 - ], IntCmp); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s0, s1)); - Belt_MutableSet.toArray(Belt_MutableSet.diff(s1, s0)); + 4, + 5 + ]); + Primitive_object.equal(Belt_Array.concat([], [ + "a", + "b", + "c" + ]), [ + "a", + "b", + "c" + ]); }); }); -Mocha.describe("Belt.MutableSet.some", () => { - Mocha.test("Belt.MutableSet.some", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalSetString.A.concatMany", () => { + Mocha.test("Belt_internalSetString.A.concatMany", () => { + Primitive_object.equal(Belt_Array.concatMany([ + [ + 1, + 2, + 3 + ], + [ + 4, + 5, + 6 + ], + [ + 7, + 8 + ] + ]), [ 1, 2, + 3, 4, + 5, 6, + 7, 8 - ], IntCmp); - Belt_MutableSet.some(s0, isOdd); + ]); }); }); -Mocha.describe("Belt.MutableSet.keep", () => { - Mocha.test("Belt.MutableSet.keep", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isEven = x => x % 2 === 0; - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalSetString.A.eq", () => { + Mocha.test("Belt_internalSetString.A.eq", () => { + Belt_Array.eq([ 1, 2, + 3 + ], [ + -1, + -2, + -3 + ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; + }); +}); + +Mocha.describe("Belt_internalSetString.A.every", () => { + Mocha.test("Belt_internalSetString.A.every", () => { + Belt_Array.every([ + 1, 3, - 4, 5 - ], IntCmp); - let s1 = Belt_MutableSet.keep(s0, isEven); - Belt_MutableSet.toArray(s1); + ], x => x % 2 === 1) === true; + Belt_Array.every([ + 1, + -3, + 5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt.MutableSet.size", () => { - Mocha.test("Belt.MutableSet.size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Belt_internalSetString.A.every2", () => { + Mocha.test("Belt_internalSetString.A.every2", () => { + Belt_Array.every2([ 1, 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.size(s0); + 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.describe("Belt.HashMap.isEmpty", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.forEach", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_internalSetString.A.fill", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt.HashMap.toArray", () => { - Mocha.test("Belt.HashMap.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.describe("Belt_internalSetString.A.flatMap", () => { + Mocha.test("Belt_internalSetString.A.flatMap", () => { + Primitive_object.equal(Belt_Array.flatMap([ + 1, + 2 + ], x => [ + x + 10 | 0, + x + 20 | 0 + ]), [ + 11, + 21, + 12, + 22 ]); }); }); -Mocha.describe("Belt.Set.Dict.remove", () => { - Mocha.test("Belt.Set.Dict.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_internalSetString.A.forEach", () => { + Mocha.test("Belt_internalSetString.A.forEach", () => { + Belt_Array.forEach([ + "a", + "b", + "c" + ], x => { + console.log("Item: " + x); }); - let s0 = Belt_SetDict.fromArray([ + let total = { + contents: 0 + }; + Belt_Array.forEach([ + 1, 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); + 4 + ], x => { + total.contents = total.contents + x | 0; + }); }); }); -Mocha.describe("Belt.Set.Dict.subset", () => { - Mocha.test("Belt.Set.Dict.subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { + Mocha.test("Belt_internalSetString.A.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; }); - 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.describe("Belt.Set.Dict.reduce", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt_internalSetString.A.get", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt.Set.Dict.toList", () => { - Mocha.test("Belt.Set.Dict.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 3, - 2, +Mocha.describe("Belt_internalSetString.A.getBy", () => { + Mocha.test("Belt_internalSetString.A.getBy", () => { + Primitive_object.equal(Belt_Array.getBy([ 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.toList(s0); + 4, + 3, + 2 + ], x => x % 2 === 0), 4); + Belt_Array.getBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; }); }); -Mocha.describe("Belt_Array.partition", () => { - Mocha.test("Belt_Array.partition", () => { - Primitive_object.equal(Belt_Array.partition([ +Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { + Mocha.test("Belt_internalSetString.A.getIndexBy", () => { + Primitive_object.equal(Belt_Array.getIndexBy([ 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 - ] - ]); + 2 + ], x => x % 2 === 0), 1); + Belt_Array.getIndexBy([ + 15, + 13, + 11 + ], x => x % 2 === 0) === undefined; }); }); -Mocha.describe("Belt_HashMap.isEmpty", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.forEach", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_internalSetString.A.joinWith", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_HashMap.toArray", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_internalSetString.A.keepMap", () => { + Mocha.test("Belt_internalSetString.A.keepMap", () => { + Primitive_object.equal(Belt_Array.keepMap([ + 1, + 2, + 3 + ], x => { + if (x % 2 === 0) { + return x; + } + + }), [2]); }); }); -Mocha.describe("Array.joinWithUnsafe", () => { - Mocha.test("Array.joinWithUnsafe", () => { - Pervasives.assertEqual([ +Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { + Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { + Primitive_object.equal(Belt_Array.keepWithIndex([ 1, 2, 3 - ].join(" -- "), "1 -- 2 -- 3"); + ], (_x, i) => i === 1), [2]); }); }); -Mocha.describe("Array.everyWithIndex", () => { - Mocha.test("Array.everyWithIndex", () => { - let array = [ +Mocha.describe("Belt_internalSetString.A.length", () => { + Mocha.test("Belt_internalSetString.A.length", () => {}); +}); + +Mocha.describe("Belt_internalSetString.A.makeBy", () => { + Mocha.test("Belt_internalSetString.A.makeBy", () => { + Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ + 0, 1, 2, 3, 4 - ]; - Pervasives.assertEqual(array.every((num, index) => { - if (index < 5) { - return num <= 4; - } else { - return false; - } - }), true); - Pervasives.assertEqual(array.every((num, index) => { - if (index < 2) { - return num >= 2; - } else { - return false; - } - }), false); - }); -}); - -Mocha.describe("String.lastIndexOfOpt", () => { - Mocha.test("String.lastIndexOfOpt", () => { - Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); - Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); - $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; + ]); + Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ + 0, + 1, + 4, + 9, + 16 + ]); }); }); -Mocha.describe("String.startsWithFrom", () => { - Mocha.test("String.startsWithFrom", () => { - "BuckleScript".startsWith("kle", 3) === true; - "BuckleScript".startsWith("", 3) === true; - "JavaScript".startsWith("Buckle", 2) === false; +Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { + Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { + let arr = new Array(5); + Belt_Array.getExn(arr, 0) === undefined; }); }); -Mocha.describe("String.substringToEnd", () => { - Mocha.test("String.substringToEnd", () => { - "playground".substring(4) === "ground"; - "playground".substring(-3) === "playground"; - "playground".substring(12) === ""; +Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { + Mocha.test("Belt_internalSetString.A.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.describe("RegExp.Result.matches", () => { - Mocha.test("RegExp.Result.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("Belt_internalSetString.A.map", () => { + Mocha.test("Belt_internalSetString.A.map", () => { + Primitive_object.equal(Belt_Array.map([ + 1, + 2 + ], x => x + 1 | 0), [ + 3, + 4 + ]); }); }); -Mocha.describe("Pervasives.setTimeout", () => { - Mocha.test("Pervasives.setTimeout", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); +Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { + Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { + Primitive_object.equal(Belt_Array.mapWithIndex([ + 1, + 2, + 3 + ], (i, x) => i + x | 0), [ + 1, + 3, + 5 + ]); }); }); -Mocha.describe("Object.hasOwnProperty", () => { - Mocha.test("Object.hasOwnProperty", () => { - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "a"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "b"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "toString"); +Mocha.describe("Belt_internalSetString.A.partition", () => { + Mocha.test("Belt_internalSetString.A.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.describe("List.forEachWithIndex", () => { - Mocha.test("List.forEachWithIndex", () => { - List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (x, index) => { - console.log("Item " + index.toString() + " is " + x); - }); +Mocha.describe("Belt_internalSetString.A.range", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Math.Constants.log10e", () => { - Mocha.test("Math.Constants.log10e", () => {}); -}); - -Mocha.describe("Int.toStringWithRadix", () => { - Mocha.test("Int.toStringWithRadix", () => { - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); - }); -}); - -Mocha.describe("Date.setUTCFullYearMD", () => { - Mocha.test("Date.setUTCFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); - }); -}); - -Mocha.describe("Date.setUTCMinutesSMs", () => { - Mocha.test("Date.setUTCMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); +Mocha.describe("Belt_internalSetString.A.rangeBy", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Date.UTC.makeWithYMDH", () => { - Mocha.test("Date.UTC.makeWithYMDH", () => { - Date.UTC(2023, 1, 20, 16); - Date.UTC(2023, 1, 20, 24); - Date.UTC(2023, 1, 20, -1); +Mocha.describe("Belt_internalSetString.A.reduce", () => { + Mocha.test("Belt_internalSetString.A.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.describe("BigInt.toLocaleString", () => { - Mocha.test("BigInt.toLocaleString", () => { - console.log((123n).toString()); +Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse", () => { + Belt_Array.reduceReverse([ + "a", + "b", + "c", + "d" + ], "", (a, b) => a + b) === "dcba"; }); }); -Mocha.describe("Belt_Set.minUndefined", () => { - Mocha.test("Belt_Set.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, +Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { + Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { + Belt_Array.reduceReverse2([ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); - }); -}); - -Mocha.describe("Belt_Set.maxUndefined", () => { - Mocha.test("Belt_Set.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, + 3 + ], [ 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); - }); -}); - -Mocha.describe("Belt_Set.Dict.isEmpty", () => { - Mocha.test("Belt_Set.Dict.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); + 2 + ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; }); }); -Mocha.describe("Belt_Set.Dict.forEach", () => { - Mocha.test("Belt_Set.Dict.forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, +Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { + Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { + Belt_Array.reduceWithIndex([ + 1, 2, 3, - 5, - 6 - ], IntCmp.cmp); - let acc = { - contents: /* [] */0 - }; - Belt_SetDict.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); + 4 + ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; }); }); -Mocha.describe("Belt_Set.Dict.toArray", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetString.A.reverse", () => { + Mocha.test("Belt_internalSetString.A.reverse", () => { + Primitive_object.equal(Belt_Array.reverse([ + 10, + 11, + 12, + 13, + 14 + ]), [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt_Set.Dict.minimum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetString.A.reverseInPlace", () => { + Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { + let arr = [ + 10, + 11, + 12, + 13, + 14 + ]; + Belt_Array.reverseInPlace(arr); + Primitive_object.equal(arr, [ + 14, + 13, + 12, + 11, + 10 + ]); }); }); -Mocha.describe("Belt_Set.Dict.maximum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_internalSetString.A.slice", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt_MutableSet.union", () => { - Mocha.test("Belt_MutableSet.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_MutableSet.every", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.split", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_List.mapReverse2", () => { - Mocha.test("Belt_List.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.describe("Belt_List.cmpByLength", () => { - Mocha.test("Belt_List.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.describe("Belt_List.removeAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt.Array.concatMany", () => { - Mocha.test("Belt.Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt.Array.sliceToEnd", () => { - Mocha.test("Belt.Array.sliceToEnd", () => { +Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { + Mocha.test("Belt_internalSetString.A.sliceToEnd", () => { Primitive_object.equal(Belt_Array.sliceToEnd([ 10, 11, @@ -15676,2841 +16071,1703 @@ Mocha.describe("Belt.Array.sliceToEnd", () => { }); }); -Mocha.describe("Belt.Array.getIndexBy", () => { - Mocha.test("Belt.Array.getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ - 1, - 4, +Mocha.describe("Belt_internalSetString.A.some", () => { + Mocha.test("Belt_internalSetString.A.some", () => { + Belt_Array.some([ + 2, 3, - 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; + 4 + ], x => x % 2 === 1) === true; + Belt_Array.some([ + -1, + -3, + -5 + ], x => x > 0) === false; }); }); -Mocha.describe("Belt.List.mapReverse2", () => { - Mocha.test("Belt.List.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.describe("Belt_internalSetString.A.some2", () => { + Mocha.test("Belt_internalSetString.A.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.describe("Belt.List.cmpByLength", () => { - Mocha.test("Belt.List.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.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { + let arr = [ + "ant", + "bee", + "cat", + "dog", + "elk" + ]; + arr.length = 3; + Primitive_object.equal(arr, [ + "ant", + "bee", + "cat" + ]); }); }); -Mocha.describe("Belt.List.removeAssoc", () => { - Mocha.test("Belt.List.removeAssoc", () => { - Belt_List.removeAssoc({ - hd: [ +Mocha.describe("Belt_internalSetString.A.unzip", () => { + Mocha.test("Belt_internalSetString.A.unzip", () => { + Primitive_object.equal(Belt_Array.unzip([ + [ 1, - "a" + 2 ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - Belt_List.removeAssoc({ - hd: [ - 9, - "morning" + [ + 3, + 4 + ] + ]), [ + [ + 1, + 3 ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); + [ + 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.describe("Belt.Set.minUndefined", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Belt_internalSetString.A.zip", () => { + Mocha.test("Belt_internalSetString.A.zip", () => { + Primitive_object.equal(Belt_Array.zip([ 1, + 2 + ], [ + 3, + 4, 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); + ]), [ + [ + 1, + 3 + ], + [ + 2, + 4 + ] + ]); }); }); -Mocha.describe("Belt.Set.maxUndefined", () => { - Mocha.test("Belt.Set.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, +Mocha.describe("Belt_internalSetString.A.zipBy", () => { + Mocha.test("Belt_internalSetString.A.zipBy", () => { + Primitive_object.equal(Belt_Array.zipBy([ 1, + 2, + 3 + ], [ + 4, 5 - ], IntCmp); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); + ], (a, b) => (a << 1) + b | 0), [ + 6, + 9 + ]); }); }); -Mocha.describe("Belt.MutableSet.union", () => { - Mocha.test("Belt.MutableSet.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("BigInt.fromStringExn", () => { + Mocha.test("BigInt.fromStringExn", () => { + BigInt("123"); + BigInt(""); + BigInt("0x11"); + BigInt("0b11"); + BigInt("0o11"); + try { + BigInt("a"); + } catch (raw__error) { + let _error = Primitive_exceptions.internalToException(raw__error); + if (_error.RE_EXN_ID !== Exn.$$Error) { + throw _error; + } + + } }); }); -Mocha.describe("Belt.MutableSet.every", () => { - Mocha.test("Belt.MutableSet.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.describe("BigInt.toLocaleString", () => { + Mocha.test("BigInt.toLocaleString", () => { + console.log((123n).toString()); }); }); -Mocha.describe("Belt.MutableSet.split", () => { - Mocha.test("Belt.MutableSet.split", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("BigInt.toString", () => { + Mocha.test("BigInt.toString", () => { + console.log((123n).toString()); + }); +}); + +Mocha.describe("Console.assert2", () => { + Mocha.test("Console.assert2", () => { + console.assert(false, "Hello", "World"); + console.assert(true, [ 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]); + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt.HashMap.logStats", () => { - Mocha.test("Belt.HashMap.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.describe("Console.assert3", () => { + Mocha.test("Console.assert3", () => { + console.assert(false, "Hello", "World", "ReScript"); + console.assert(true, "One", 2, 3); }); }); -Mocha.describe("Belt.Float.fromString", () => { - Mocha.test("Belt.Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); +Mocha.describe("Console.assert4", () => { + Mocha.test("Console.assert4", () => { + console.assert(false, "Hello", "World", "ReScript", "!!!"); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar"); }); }); -Mocha.describe("Belt.Set.Dict.isEmpty", () => { - Mocha.test("Belt.Set.Dict.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.assert5", () => { + Mocha.test("Console.assert5", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.assert(true, [ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" }); - let empty = Belt_SetDict.fromArray([], IntCmp.cmp); - let notEmpty = Belt_SetDict.fromArray([1], IntCmp.cmp); - Belt_SetDict.isEmpty(empty); - Belt_SetDict.isEmpty(notEmpty); }); }); -Mocha.describe("Belt.Set.Dict.forEach", () => { - Mocha.test("Belt.Set.Dict.forEach", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, +Mocha.describe("Console.assert6", () => { + Mocha.test("Console.assert6", () => { + console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.assert(true, [ + 1, + 2 + ], [ 3, + 4 + ], [ 5, 6 - ], IntCmp.cmp); - let acc = { - contents: /* [] */0 - }; - Belt_SetDict.forEach(s0, x => { - acc.contents = Belt_List.add(acc.contents, x); - }); + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.Set.Dict.toArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("Console.assertMany", () => { + Mocha.test("Console.assertMany", () => { + console.assert(false, "Hello", "World"); + console.assert(true, 1, 2, 3); }); }); -Mocha.describe("Belt.Set.Dict.minimum", () => { - Mocha.test("Belt.Set.Dict.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.describe("Console.assert_", () => { + Mocha.test("Console.assert_", () => { + console.assert(false, "Hello World!"); + console.assert(true, "The answer"); }); }); -Mocha.describe("Belt.Set.Dict.maximum", () => { - Mocha.test("Belt.Set.Dict.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.describe("Console.clear", () => { + Mocha.test("Console.clear", () => { + console.clear(); }); }); -Mocha.describe("Belt_Float.fromString", () => { - Mocha.test("Belt_Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); +Mocha.describe("Console.count", () => { + Mocha.test("Console.count", () => { + console.count("rescript"); }); }); -Mocha.describe("Belt_Array.concatMany", () => { - Mocha.test("Belt_Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ +Mocha.describe("Console.countReset", () => { + Mocha.test("Console.countReset", () => { + console.countReset("rescript"); + }); +}); + +Mocha.describe("Console.debug", () => { + Mocha.test("Console.debug", () => { + console.debug("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.debug(obj); + }); +}); + +Mocha.describe("Console.debug2", () => { + Mocha.test("Console.debug2", () => { + console.debug("Hello", "World"); + console.debug([ 1, 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt_Array.sliceToEnd", () => { - Mocha.test("Belt_Array.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.describe("Console.debug3", () => { + Mocha.test("Console.debug3", () => { + console.debug("Hello", "World", "ReScript"); + console.debug("One", 2, 3); }); }); -Mocha.describe("Belt_Array.getIndexBy", () => { - Mocha.test("Belt_Array.getIndexBy", () => { - Primitive_object.equal(Belt_Array.getIndexBy([ +Mocha.describe("Console.debug4", () => { + Mocha.test("Console.debug4", () => { + console.debug("Hello", "World", "ReScript", "!!!"); + console.debug([ 1, - 4, - 3, 2 - ], x => x % 2 === 0), 1); - Belt_Array.getIndexBy([ - 15, - 13, - 11 - ], x => x % 2 === 0) === undefined; - }); -}); - -Mocha.describe("Belt_HashMap.logStats", () => { - Mocha.test("Belt_HashMap.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.describe("AsyncIterator.forEach", () => { - Mocha.test("AsyncIterator.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 $$AsyncIterator.forEach(asyncIterator, v => { - if (v !== undefined && v[0] === "second") { - return Pervasives.assertEqual(v[1], "2"); - } - - }); - main(); - }); -}); - -Mocha.describe("Array.fromInitializer", () => { - Mocha.test("Array.fromInitializer", () => { - Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ - 3, - 4, - 5 - ]); - Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ + ], [ 3, - 4, + 4 + ], [ 5, - 6, - 7, - 8, - 9 - ]); + 6 + ], "polyvar"); }); }); -Mocha.describe("Array.filterWithIndex", () => { - Mocha.test("Array.filterWithIndex", () => { - Pervasives.assertEqual([ +Mocha.describe("Console.debug5", () => { + Mocha.test("Console.debug5", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.debug([ 1, - 2, + 2 + ], [ 3, 4 - ].filter((num, index) => { - if (index === 0) { - return true; - } else { - return num === 2; - } - }), [ - 1, - 2 - ]); + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }); }); }); -Mocha.describe("Array.reduceWithIndex", () => { - Mocha.test("Array.reduceWithIndex", () => { - Pervasives.assertEqual($$Array.reduceWithIndex([ +Mocha.describe("Console.debug6", () => { + Mocha.test("Console.debug6", () => { + console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.debug([ 1, - 2, + 2 + ], [ 3, 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$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 - } - } - }); - Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); -}); - -Mocha.describe("Type.Classify.classify", () => { - Mocha.test("Type.Classify.classify", () => { - let match = 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("String.lastIndexOfFrom", () => { - Mocha.test("String.lastIndexOfFrom", () => { - "bookseller".lastIndexOf("ok", 6) === 2; - "beekeeper".lastIndexOf("ee", 8) === 4; - "beekeeper".lastIndexOf("ee", 3) === 1; - "abcdefg".lastIndexOf("xyz", 4) === -1; + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Pervasives.setInterval", () => { - Mocha.test("Pervasives.setInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms."); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500); +Mocha.describe("Console.debugMany", () => { + Mocha.test("Console.debugMany", () => { + console.debug("Hello", "World"); + console.debug(1, 2, 3); }); }); -Mocha.describe("Pervasives.assertEqual", () => { - Mocha.test("Pervasives.assertEqual", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }), { - hd: 2, - tl: /* [] */0 +Mocha.describe("Console.dir", () => { + Mocha.test("Console.dir", () => { + console.dir({ + language: "rescript", + version: "10.1.2" }); }); }); -Mocha.describe("Math.Constants.sqrt1_2", () => { - Mocha.test("Math.Constants.sqrt1_2", () => {}); +Mocha.describe("Console.error", () => { + Mocha.test("Console.error", () => { + console.error("error message"); + console.error([ + "error", + "invalid value" + ]); + }); }); -Mocha.describe("JSON.Classify.classify", () => { - Mocha.test("JSON.Classify.classify", () => { - $$JSON.Classify.classify("hello world"); - $$JSON.Classify.classify(42); +Mocha.describe("Console.error2", () => { + Mocha.test("Console.error2", () => { + console.error("Error", "here"); + console.error([ + "log", + "error" + ], "message"); }); }); -Mocha.describe("Int.Constants.minValue", () => { - Mocha.test("Int.Constants.minValue", () => { - console.log(Int.Constants.minValue); +Mocha.describe("Console.error3", () => { + Mocha.test("Console.error3", () => { + console.error("Hello", "World", "!!!"); + console.error("first", "second", "third"); }); }); -Mocha.describe("Int.Constants.maxValue", () => { - Mocha.test("Int.Constants.maxValue", () => { - console.log(Int.Constants.maxValue); +Mocha.describe("Console.error4", () => { + Mocha.test("Console.error4", () => { + console.error("Hello", "World", "ReScript", /* '!' */33); + console.error("first", "second", "third", "fourth"); }); }); -Mocha.describe("Date.getTimezoneOffset", () => { - Mocha.test("Date.getTimezoneOffset", () => { - new Date("2023-01-01").getTimezoneOffset(); - new Date("2023-06-01").getTimezoneOffset(); +Mocha.describe("Console.error5", () => { + Mocha.test("Console.error5", () => { + console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); + console.error(1, "second", "third", "fourth", /* 'c' */99); }); }); -Mocha.describe("Date.UTC.makeWithYMDHM", () => { - Mocha.test("Date.UTC.makeWithYMDHM", () => { - Date.UTC(2023, 1, 20, 16, 40); - Date.UTC(2023, 1, 20, 16, 60); - Date.UTC(2023, 1, 20, 16, -1); +Mocha.describe("Console.error6", () => { + Mocha.test("Console.error6", () => { + console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.error([ + 1, + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt_SetDict.fromArray", () => { - Mocha.test("Belt_SetDict.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.errorMany", () => { + Mocha.test("Console.errorMany", () => { + console.error("Hello", "World"); + console.error(1, 2, 3); + }); +}); + +Mocha.describe("Console.group", () => { + Mocha.test("Console.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.describe("Console.info", () => { + Mocha.test("Console.info", () => { + console.info("Information"); + console.info([ + "Hello", + "JS" + ]); + }); +}); + +Mocha.describe("Console.info2", () => { + Mocha.test("Console.info2", () => { + console.info("Info", "failed to download"); + console.info("info", { + name: "ReScript" }); - let s0 = Belt_SetDict.fromArray([ + }); +}); + +Mocha.describe("Console.info3", () => { + Mocha.test("Console.info3", () => { + console.info("Hello", "World", "ReScript"); + console.info([ 1, - 3, 2, - 4 - ], IntCmp.cmp); - Belt_SetDict.toArray(s0); + 3 + ], 4, 5); }); }); -Mocha.describe("Belt_SetDict.mergeMany", () => { - Mocha.test("Belt_SetDict.mergeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let newSet = Belt_SetDict.mergeMany(undefined, [ - 5, - 4, - 3, +Mocha.describe("Console.info4", () => { + Mocha.test("Console.info4", () => { + console.info("Hello", "World", "ReScript", /* '!' */33); + console.info([ + 1, 2, - 1 - ], IntCmp.cmp); - Belt_SetDict.toArray(newSet); + 3 + ], 4, 5, "lastinfo"); }); }); -Mocha.describe("Belt_SetDict.intersect", () => { - Mocha.test("Belt_SetDict.intersect", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_SetDict.fromArray([ - 5, - 2, +Mocha.describe("Console.info5", () => { + Mocha.test("Console.info5", () => { + console.info("Hello", "World", "from", "JS", "!!!"); + console.info([ + 1, + 2 + ], [ 3, + 4 + ], [ 5, 6 - ], IntCmp.cmp); - let s1 = Belt_SetDict.fromArray([ - 5, - 2, - 3, + ], "polyvar", { + name: "ReScript" + }); + }); +}); + +Mocha.describe("Console.info6", () => { + Mocha.test("Console.info6", () => { + console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.info([ 1, - 5, + 2 + ], [ + 3, 4 - ], IntCmp.cmp); - let intersect = Belt_SetDict.intersect(s0, s1, IntCmp.cmp); - Belt_SetDict.toArray(intersect); + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt_SetDict.partition", () => { - Mocha.test("Belt_SetDict.partition", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let isOdd = x => x % 2 !== 0; - let s0 = Belt_SetDict.fromArray([ +Mocha.describe("Console.infoMany", () => { + Mocha.test("Console.infoMany", () => { + console.info("Hello", "World"); + console.info(1, 2, 3); + }); +}); + +Mocha.describe("Console.log", () => { + Mocha.test("Console.log", () => { + console.log("Hello"); + let obj = { + name: "ReScript", + version: 10 + }; + console.log(obj); + }); +}); + +Mocha.describe("Console.log2", () => { + Mocha.test("Console.log2", () => { + console.log("Hello", "World"); + console.log([ 1, 2, - 3, - 4, - 5 - ], IntCmp.cmp); - let match = Belt_SetDict.partition(s0, isOdd); - Belt_SetDict.toArray(match[0]); - Belt_SetDict.toArray(match[1]); + 3 + ], /* '4' */52); }); }); -Mocha.describe("Belt_MutableSet.remove", () => { - Mocha.test("Belt_MutableSet.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.describe("Console.log3", () => { + Mocha.test("Console.log3", () => { + console.log("Hello", "World", "ReScript"); + console.log("One", 2, 3); }); }); -Mocha.describe("Belt_MutableSet.subset", () => { - Mocha.test("Belt_MutableSet.subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, +Mocha.describe("Console.log4", () => { + Mocha.test("Console.log4", () => { + console.log("Hello", "World", "ReScript", "!!!"); + console.log([ + 1, + 2 + ], [ 3, + 4 + ], [ 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); + ], "polyvar"); }); }); -Mocha.describe("Belt_MutableSet.reduce", () => { - Mocha.test("Belt_MutableSet.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, +Mocha.describe("Console.log5", () => { + Mocha.test("Console.log5", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); + console.log([ + 1, + 2 + ], [ 3, + 4 + ], [ 5, 6 - ], IntCmp); - Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); + ], "polyvar", { + name: "ReScript" + }); }); }); -Mocha.describe("Belt_MutableSet.toList", () => { - Mocha.test("Belt_MutableSet.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 3, - 2, +Mocha.describe("Console.log6", () => { + Mocha.test("Console.log6", () => { + console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); + console.log([ 1, - 5 - ], IntCmp); - Belt_MutableSet.toList(s0); + 2 + ], [ + 3, + 4 + ], [ + 5, + 6 + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt_Map.valuesToArray", () => { - Mocha.test("Belt_Map.valuesToArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Console.logMany", () => { + Mocha.test("Console.logMany", () => { + console.log("Hello", "World"); + console.log(1, 2, 3); + }); +}); + +Mocha.describe("Console.table", () => { + Mocha.test("Console.table", () => { + console.table({ + language: "rescript", + version: "10.1.2" }); - Primitive_object.equal(Belt_Map.valuesToArray(Belt_Map.fromArray([ - [ - 2, - "2" - ], - [ - 1, - "1" - ], - [ - 3, - "3" - ] - ], IntCmp)), [ - "1", - "2", - "3" - ]); }); }); -Mocha.describe("Belt_List.mapWithIndex", () => { - Mocha.test("Belt_List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); +Mocha.describe("Console.time", () => { + Mocha.test("Console.time", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); }); }); -Mocha.describe("Belt.List.mapWithIndex", () => { - Mocha.test("Belt.List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); +Mocha.describe("Console.timeEnd", () => { + Mocha.test("Console.timeEnd", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); }); }); -Mocha.describe("Belt.Map.valuesToArray", () => { - Mocha.test("Belt.Map.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("Console.timeLog", () => { + Mocha.test("Console.timeLog", () => { + console.time("for_time"); + for (let x = 3; x >= 1; --x) { + console.log(x); + console.timeLog("for_time"); + } + console.timeEnd("for_time"); + }); +}); + +Mocha.describe("Console.trace", () => { + Mocha.test("Console.trace", () => { + console.trace(); + }); +}); + +Mocha.describe("Console.warn", () => { + Mocha.test("Console.warn", () => { + console.warn("Warning"); + console.warn([ + "Warning", + "invalid number" ]); }); }); -Mocha.describe("Belt.MutableSet.remove", () => { - Mocha.test("Belt.MutableSet.remove", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 2, - 3, +Mocha.describe("Console.warn2", () => { + Mocha.test("Console.warn2", () => { + console.warn("Hello", "World"); + console.warn([ 1, - 4, - 5 - ], IntCmp); - Belt_MutableSet.remove(s0, 1); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.remove(s0, 3); - Belt_MutableSet.toArray(s0); + 2, + 3 + ], 4); }); }); -Mocha.describe("Belt.MutableSet.subset", () => { - Mocha.test("Belt.MutableSet.subset", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, +Mocha.describe("Console.warn3", () => { + Mocha.test("Console.warn3", () => { + console.warn("Hello", "World", "ReScript"); + console.warn([ + 1, 2, + 3 + ], 4, 5); + }); +}); + +Mocha.describe("Console.warn4", () => { + Mocha.test("Console.warn4", () => { + console.warn("Hello", "World", "ReScript", "!!!"); + console.warn("first", "second", "third", "fourth"); + }); +}); + +Mocha.describe("Console.warn5", () => { + Mocha.test("Console.warn5", () => { + console.warn("Hello", "World", "from", "JS", "!!!"); + console.warn([ + 1, + 2 + ], [ 3, + 4 + ], [ 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); + ], "polyvar", { + name: "ReScript" + }); }); }); -Mocha.describe("Belt.MutableSet.reduce", () => { - Mocha.test("Belt.MutableSet.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ - 5, - 2, +Mocha.describe("Console.warn6", () => { + Mocha.test("Console.warn6", () => { + console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); + console.warn([ + 1, + 2 + ], [ 3, + 4 + ], [ 5, 6 - ], IntCmp); - Belt_MutableSet.reduce(s0, /* [] */0, Belt_List.add); + ], "polyvar", { + name: "ReScript" + }, 42); }); }); -Mocha.describe("Belt.MutableSet.toList", () => { - Mocha.test("Belt.MutableSet.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.describe("Console.warnMany", () => { + Mocha.test("Console.warnMany", () => { + console.warn("Hello", "World"); + console.warn(1, 2, 3); }); }); -Mocha.describe("Belt.HashMap.fromArray", () => { - Mocha.test("Belt.HashMap.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.describe("Date.UTC.makeWithYM", () => { + Mocha.test("Date.UTC.makeWithYM", () => { + Date.UTC(2023, 0); + Date.UTC(2023, 11); + Date.UTC(2023, 12); + Date.UTC(2023, -1); }); }); -Mocha.describe("Belt.HashMap.mergeMany", () => { - Mocha.test("Belt.HashMap.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.describe("Date.UTC.makeWithYMD", () => { + Mocha.test("Date.UTC.makeWithYMD", () => { + Date.UTC(2023, 1, 20); + Date.UTC(2023, 1, -1); + Date.UTC(2023, 1, 29); }); }); -Mocha.describe("Belt_HashMap.fromArray", () => { - Mocha.test("Belt_HashMap.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.describe("Date.UTC.makeWithYMDH", () => { + Mocha.test("Date.UTC.makeWithYMDH", () => { + Date.UTC(2023, 1, 20, 16); + Date.UTC(2023, 1, 20, 24); + Date.UTC(2023, 1, 20, -1); }); }); -Mocha.describe("Belt_HashMap.mergeMany", () => { - Mocha.test("Belt_HashMap.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.describe("Date.UTC.makeWithYMDHM", () => { + Mocha.test("Date.UTC.makeWithYMDHM", () => { + Date.UTC(2023, 1, 20, 16, 40); + Date.UTC(2023, 1, 20, 16, 60); + Date.UTC(2023, 1, 20, 16, -1); }); }); -Mocha.describe("Array.forEachWithIndex", () => { - Mocha.test("Array.forEachWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach((item, index) => { - console.log("At item " + index.toString() + ": " + item); - }); +Mocha.describe("Date.UTC.makeWithYMDHMS", () => { + Mocha.test("Date.UTC.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.describe("Array.flatMapWithIndex", () => { - Mocha.test("Array.flatMapWithIndex", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.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.describe("Date.UTC.makeWithYMDHMSM", () => { + Mocha.test("Date.UTC.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("String.fromCharCodeMany", () => { - Mocha.test("String.fromCharCodeMany", () => { - String.fromCharCode(189, 43, 190, 61) === "½+¾="; - String.fromCharCode(65, 66, 67) === "ABC"; +Mocha.describe("Date.fromString", () => { + Mocha.test("Date.fromString", () => { + new Date("2023"); + new Date("2023-02-20"); + new Date("2023-02-20T16:40:00.00Z"); + new Date(""); + new Date("").getTime(); }); }); -Mocha.describe("String.replaceAllRegExp", () => { - Mocha.test("String.replaceAllRegExp", () => { - "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; +Mocha.describe("Date.fromTime", () => { + Mocha.test("Date.fromTime", () => { + new Date(0.0); + new Date(-86400000.0); + new Date(86400000.0); }); }); -Mocha.describe("RegExp.Result.fullMatch", () => { - Mocha.test("RegExp.Result.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.describe("Date.getDate", () => { + Mocha.test("Date.getDate", () => { + new Date("2023-02-20T16:40:00.00").getDate(); }); }); -Mocha.describe("Pervasives.clearTimeout", () => { - Mocha.test("Pervasives.clearTimeout", () => { - let timeoutId = setTimeout(() => { - console.log("This prints in 2 seconds."); - }, 2000); - clearTimeout(timeoutId); +Mocha.describe("Date.getDay", () => { + Mocha.test("Date.getDay", () => { + new Date("2023-02-20T16:40:00.00").getDay(); }); }); -Mocha.describe("Float.parseIntWithRadix", () => { - Mocha.test("Float.parseIntWithRadix", () => { - parseInt("10.0", 2); - parseInt("15 * 3", 10); - parseInt("12", 13); - isNaN(parseInt("17", 40)); +Mocha.describe("Date.getFullYear", () => { + Mocha.test("Date.getFullYear", () => { + new Date("2023-02-20").getFullYear(); }); }); -Mocha.describe("Float.toStringWithRadix", () => { - Mocha.test("Float.toStringWithRadix", () => { - (6.0).toString(2); - (3735928559.0).toString(16); - (123456.0).toString(36); +Mocha.describe("Date.getHours", () => { + Mocha.test("Date.getHours", () => { + new Date("2023-02-20T16:40:00.00").getHours(); }); }); -Mocha.describe("Float.Constants.epsilon", () => { - Mocha.test("Float.Constants.epsilon", () => {}); +Mocha.describe("Date.getMilliseconds", () => { + Mocha.test("Date.getMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").getMilliseconds(); + }); }); -Mocha.describe("Date.getUTCMilliseconds", () => { - Mocha.test("Date.getUTCMilliseconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); +Mocha.describe("Date.getMinutes", () => { + Mocha.test("Date.getMinutes", () => { + new Date("2023-02-20T16:40:00.00").getMinutes(); }); }); -Mocha.describe("Date.setUTCMilliseconds", () => { - Mocha.test("Date.setUTCMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); +Mocha.describe("Date.getMonth", () => { + Mocha.test("Date.getMonth", () => { + new Date("2023-01-01").getMonth(); }); }); -Mocha.describe("Date.toLocaleDateString", () => { - Mocha.test("Date.toLocaleDateString", () => { - console.log(new Date().toLocaleDateString()); +Mocha.describe("Date.getSeconds", () => { + Mocha.test("Date.getSeconds", () => { + new Date("2023-02-20T16:40:00.00").getSeconds(); }); }); -Mocha.describe("Date.toLocaleTimeString", () => { - Mocha.test("Date.toLocaleTimeString", () => { - console.log(new Date().toLocaleTimeString()); +Mocha.describe("Date.getTime", () => { + Mocha.test("Date.getTime", () => { + new Date("2023-02-20").getTime(); }); }); -Mocha.describe("Date.UTC.makeWithYMDHMS", () => { - Mocha.test("Date.UTC.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.describe("Date.getTimezoneOffset", () => { + Mocha.test("Date.getTimezoneOffset", () => { + new Date("2023-01-01").getTimezoneOffset(); + new Date("2023-06-01").getTimezoneOffset(); }); }); -Mocha.describe("Belt_Set.Dict.fromArray", () => { - Mocha.test("Belt_Set.Dict.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.describe("Date.getUTCDate", () => { + Mocha.test("Date.getUTCDate", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); }); }); -Mocha.describe("Belt_Set.Dict.mergeMany", () => { - Mocha.test("Belt_Set.Dict.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.describe("Date.getUTCDay", () => { + Mocha.test("Date.getUTCDay", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); }); }); -Mocha.describe("Belt_Set.Dict.intersect", () => { - Mocha.test("Belt_Set.Dict.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.describe("Date.getUTCFullYear", () => { + Mocha.test("Date.getUTCFullYear", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); }); }); -Mocha.describe("Belt_Set.Dict.partition", () => { - Mocha.test("Belt_Set.Dict.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.describe("Date.getUTCHours", () => { + Mocha.test("Date.getUTCHours", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); }); }); -Mocha.describe("Belt_SetDict.removeMany", () => { - Mocha.test("Belt_SetDict.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.describe("Date.getUTCMilliseconds", () => { + Mocha.test("Date.getUTCMilliseconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); }); }); -Mocha.describe("Belt_MutableSet.isEmpty", () => { - Mocha.test("Belt_MutableSet.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.describe("Date.getUTCMinutes", () => { + Mocha.test("Date.getUTCMinutes", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); }); }); -Mocha.describe("Belt_MutableSet.forEach", () => { - Mocha.test("Belt_MutableSet.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.describe("Date.getUTCMonth", () => { + Mocha.test("Date.getUTCMonth", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); }); }); -Mocha.describe("Belt_MutableSet.toArray", () => { - Mocha.test("Belt_MutableSet.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.describe("Date.getUTCSeconds", () => { + Mocha.test("Date.getUTCSeconds", () => { + new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); }); }); -Mocha.describe("Belt_MutableSet.minimum", () => { - Mocha.test("Belt_MutableSet.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.describe("Date.make", () => { + Mocha.test("Date.make", () => { + new Date(); }); }); -Mocha.describe("Belt_MutableSet.maximum", () => { - Mocha.test("Belt_MutableSet.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.describe("Date.makeWithYM", () => { + Mocha.test("Date.makeWithYM", () => { + new Date(2023, 0); + new Date(2023, 11); + new Date(2023, 12); + new Date(2023, -1); }); }); -Mocha.describe("Belt_MapInt.findFirstBy", () => { - Mocha.test("Belt_MapInt.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Date.makeWithYMD", () => { + Mocha.test("Date.makeWithYMD", () => { + new Date(2023, 1, 20); + new Date(2023, 1, -1); + new Date(2023, 1, 29); }); }); -Mocha.describe("Belt_List.reverseConcat", () => { - Mocha.test("Belt_List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); +Mocha.describe("Date.makeWithYMDH", () => { + Mocha.test("Date.makeWithYMDH", () => { + new Date(2023, 1, 20, 16); + new Date(2023, 1, 20, 24); + new Date(2023, 1, 20, -1); }); }); -Mocha.describe("Belt_List.reduceReverse", () => { - Mocha.test("Belt_List.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.describe("Date.makeWithYMDHM", () => { + Mocha.test("Date.makeWithYMDHM", () => { + new Date(2023, 1, 20, 16, 40); + new Date(2023, 1, 20, 16, 60); + new Date(2023, 1, 20, 16, -1); }); }); -Mocha.describe("Belt_List.keepWithIndex", () => { - Mocha.test("Belt_List.keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); +Mocha.describe("Date.makeWithYMDHMS", () => { + Mocha.test("Date.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.describe("Belt.Array.mapWithIndex", () => { - Mocha.test("Belt.Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Date.makeWithYMDHMSM", () => { + Mocha.test("Date.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.describe("Belt.List.reverseConcat", () => { - Mocha.test("Belt.List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); +Mocha.describe("Date.setDate", () => { + Mocha.test("Date.setDate", () => { + new Date("2023-02-20T16:40:00.00").setDate(1); }); }); -Mocha.describe("Belt.List.reduceReverse", () => { - Mocha.test("Belt.List.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.describe("Date.setFullYear", () => { + Mocha.test("Date.setFullYear", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024); }); }); -Mocha.describe("Belt.List.keepWithIndex", () => { - Mocha.test("Belt.List.keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); +Mocha.describe("Date.setFullYearM", () => { + Mocha.test("Date.setFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); }); }); -Mocha.describe("Belt.MutableSet.isEmpty", () => { - Mocha.test("Belt.MutableSet.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.describe("Date.setFullYearMD", () => { + Mocha.test("Date.setFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); }); }); -Mocha.describe("Belt.MutableSet.forEach", () => { - Mocha.test("Belt.MutableSet.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.describe("Date.setHours", () => { + Mocha.test("Date.setHours", () => { + new Date("2023-02-20T16:40:00.00").setHours(0); }); }); -Mocha.describe("Belt.MutableSet.toArray", () => { - Mocha.test("Belt.MutableSet.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.describe("Date.setHoursM", () => { + Mocha.test("Date.setHoursM", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0); }); }); -Mocha.describe("Belt.MutableSet.minimum", () => { - Mocha.test("Belt.MutableSet.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.describe("Date.setHoursMS", () => { + Mocha.test("Date.setHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); }); }); -Mocha.describe("Belt.MutableSet.maximum", () => { - Mocha.test("Belt.MutableSet.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.describe("Date.setHoursMSMs", () => { + Mocha.test("Date.setHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); }); }); -Mocha.describe("Belt.Set.Dict.fromArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("Date.setMilliseconds", () => { + Mocha.test("Date.setMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setMilliseconds(0); + }); }); -Mocha.describe("Belt.Set.Dict.mergeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("Date.setMinutes", () => { + Mocha.test("Date.setMinutes", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0); }); }); -Mocha.describe("Belt.Set.Dict.intersect", () => { - Mocha.test("Belt.Set.Dict.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.describe("Date.setMinutesS", () => { + Mocha.test("Date.setMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); }); }); -Mocha.describe("Belt.Set.Dict.partition", () => { - Mocha.test("Belt.Set.Dict.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.describe("Date.setMinutesSMs", () => { + Mocha.test("Date.setMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); }); }); -Mocha.describe("Belt_Array.mapWithIndex", () => { - Mocha.test("Belt_Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Date.setMonth", () => { + Mocha.test("Date.setMonth", () => { + new Date("2023-02-20T16:40:00.00").setMonth(0); }); }); -Mocha.describe("String.fromCodePointMany", () => { - Mocha.test("String.fromCodePointMany", () => { - String.fromCodePoint(54620, 44544, 128570) === "한글😺"; +Mocha.describe("Date.setSeconds", () => { + Mocha.test("Date.setSeconds", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0); }); }); -Mocha.describe("Pervasives.clearInterval", () => { - Mocha.test("Pervasives.clearInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints in 100 ms"); - }, 100); - setTimeout(() => { - clearInterval(intervalId); - }, 500); +Mocha.describe("Date.setSecondsMs", () => { + Mocha.test("Date.setSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); }); }); -Mocha.describe("Object.preventExtensions", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 14206, - 7 - ], - Error: new Error() - }; - } - - } +Mocha.describe("Date.setUTCDate", () => { + Mocha.test("Date.setUTCDate", () => { + new Date("2023-02-20T16:40:00.00").setUTCDate(1); }); }); -Mocha.describe("JSON.parseExnWithReviver", () => { - Mocha.test("JSON.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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn; - } - } +Mocha.describe("Date.setUTCFullYear", () => { + Mocha.test("Date.setUTCFullYear", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); }); }); -Mocha.describe("JSON.stringifyWithIndent", () => { - Mocha.test("JSON.stringifyWithIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, null, 2); +Mocha.describe("Date.setUTCFullYearM", () => { + Mocha.test("Date.setUTCFullYearM", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); }); }); -Mocha.describe("JSON.stringifyWithFilter", () => { - Mocha.test("JSON.stringifyWithFilter", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ]); +Mocha.describe("Date.setUTCFullYearMD", () => { + Mocha.test("Date.setUTCFullYearMD", () => { + new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); }); }); -Mocha.describe("Int.toFixedWithPrecision", () => { - Mocha.test("Int.toFixedWithPrecision", () => { - (300).toFixed(4); - (300).toFixed(1); +Mocha.describe("Date.setUTCHours", () => { + Mocha.test("Date.setUTCHours", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0); }); }); -Mocha.describe("Float.Constants.minValue", () => { - Mocha.test("Float.Constants.minValue", () => {}); +Mocha.describe("Date.setUTCHoursM", () => { + Mocha.test("Date.setUTCHoursM", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); + }); }); -Mocha.describe("Float.Constants.maxValue", () => { - Mocha.test("Float.Constants.maxValue", () => {}); +Mocha.describe("Date.setUTCHoursMS", () => { + Mocha.test("Date.setUTCHoursMS", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); + }); }); -Mocha.describe("Date.UTC.makeWithYMDHMSM", () => { - Mocha.test("Date.UTC.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("Date.setUTCHoursMSMs", () => { + Mocha.test("Date.setUTCHoursMSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); }); }); -Mocha.describe("Belt_internalMapInt.A.eq", () => { - Mocha.test("Belt_internalMapInt.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Date.setUTCMilliseconds", () => { + Mocha.test("Date.setUTCMilliseconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); }); }); -Mocha.describe("Belt_internalSetInt.A.eq", () => { - Mocha.test("Belt_internalSetInt.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Date.setUTCMinutes", () => { + Mocha.test("Date.setUTCMinutes", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); }); }); -Mocha.describe("Belt_Set.Dict.removeMany", () => { - Mocha.test("Belt_Set.Dict.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.describe("Date.setUTCMinutesS", () => { + Mocha.test("Date.setUTCMinutesS", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); }); }); -Mocha.describe("Belt_MapDict.findFirstBy", () => { - Mocha.test("Belt_MapDict.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("Date.setUTCMinutesSMs", () => { + Mocha.test("Date.setUTCMinutesSMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); }); }); -Mocha.describe("Belt_Map.Int.findFirstBy", () => { - Mocha.test("Belt_Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Date.setUTCMonth", () => { + Mocha.test("Date.setUTCMonth", () => { + new Date("2023-02-20T16:40:00.00").setUTCMonth(0); }); }); -Mocha.describe("Belt_List.reduceReverse2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Date.setUTCSeconds", () => { + Mocha.test("Date.setUTCSeconds", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); }); }); -Mocha.describe("Belt.Array.keepWithIndex", () => { - Mocha.test("Belt.Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("Date.setUTCSecondsMs", () => { + Mocha.test("Date.setUTCSecondsMs", () => { + new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); }); }); -Mocha.describe("Belt.Array.reduceReverse", () => { - Mocha.test("Belt.Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("Date.toDateString", () => { + Mocha.test("Date.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.describe("Belt.List.reduceReverse2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); +Mocha.describe("Date.toISOString", () => { + Mocha.test("Date.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.describe("Belt.HashMap.keysToArray", () => { - Mocha.test("Belt.HashMap.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.describe("Date.toJSON", () => { + Mocha.test("Date.toJSON", () => { + new Date("2023-01-01T00:00:00.00+00:00").toJSON(); + new Date("").toJSON(); }); }); -Mocha.describe("Belt.Set.Dict.removeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("Date.toLocaleDateString", () => { + Mocha.test("Date.toLocaleDateString", () => { + console.log(new Date().toLocaleDateString()); }); }); -Mocha.describe("Belt.Map.Int.findFirstBy", () => { - Mocha.test("Belt.Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); +Mocha.describe("Date.toLocaleDateStringWithLocale", () => { + Mocha.test("Date.toLocaleDateStringWithLocale", () => { + console.log(new Date().toLocaleDateString("en-US")); }); }); -Mocha.describe("Belt_Array.keepWithIndex", () => { - Mocha.test("Belt_Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("Belt_Array.reduceReverse", () => { - Mocha.test("Belt_Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("Date.toLocaleString", () => { + Mocha.test("Date.toLocaleString", () => { + console.log(new Date().toLocaleString()); }); }); -Mocha.describe("Belt_HashMap.keysToArray", () => { - Mocha.test("Belt_HashMap.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.describe("Date.toLocaleStringWithLocale", () => { + Mocha.test("Date.toLocaleStringWithLocale", () => { + console.log(new Date().toLocaleString("en-US")); }); }); -Mocha.describe("Array.findIndexWithIndex", () => { - Mocha.test("Array.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; - } - }); - Pervasives.assertEqual(isReScriptFirst, 0); - Pervasives.assertEqual(isTypeScriptFirst, -1); +Mocha.describe("Date.toLocaleStringWithLocaleAndOptions", () => { + Mocha.test("Date.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.describe("Belt_internalMapInt.A.get", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Date.toLocaleTimeString", () => { + Mocha.test("Date.toLocaleTimeString", () => { + console.log(new Date().toLocaleTimeString()); }); }); -Mocha.describe("Belt_internalMapInt.A.zip", () => { - Mocha.test("Belt_internalMapInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); +Mocha.describe("Date.toLocaleTimeStringWithLocale", () => { + Mocha.test("Date.toLocaleTimeStringWithLocale", () => { + console.log(new Date().toLocaleTimeString("en-US")); }); }); -Mocha.describe("Belt_internalMapInt.A.map", () => { - Mocha.test("Belt_internalMapInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { + console.log(new Date().toLocaleTimeString("en-US", { + timeStyle: "long" + })); + console.log(new Date().toLocaleTimeString("de", { + hour: "2-digit", + minute: "2-digit" + })); }); }); -Mocha.describe("Belt_internalMapInt.A.cmp", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Date.toString", () => { + Mocha.test("Date.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.describe("Belt_internalSetInt.A.get", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Date.toTimeString", () => { + Mocha.test("Date.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.describe("Belt_internalSetInt.A.zip", () => { - Mocha.test("Belt_internalSetInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ +Mocha.describe("Date.toUTCString", () => { + Mocha.test("Date.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("Dict.assign", () => { + Mocha.test("Dict.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.describe("Dict.copy", () => { + Mocha.test("Dict.copy", () => { + let dict = Object.fromEntries([ [ - 1, - 3 + "key1", + "value1" ], [ - 2, - 4 + "key2", + "value2" ] ]); + let dict2 = Object.assign({}, dict); + console.log(Object.keys(dict), Object.keys(dict2)); }); }); -Mocha.describe("Belt_internalSetInt.A.map", () => { - Mocha.test("Belt_internalSetInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("Dict.delete", () => { + Mocha.test("Dict.delete", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + Dict.$$delete(dict, "someKey"); }); }); -Mocha.describe("Belt_internalSetInt.A.cmp", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Dict.forEach", () => { + Mocha.test("Dict.forEach", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEach(dict, value => { + console.log(value); + }); }); }); -Mocha.describe("Belt_SetDict.minUndefined", () => { - Mocha.test("Belt_SetDict.minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Dict.forEachWithKey", () => { + Mocha.test("Dict.forEachWithKey", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); + Dict.forEachWithKey(dict, (value, key) => { + console.log(value, key); }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); }); }); -Mocha.describe("Belt_SetDict.maxUndefined", () => { - Mocha.test("Belt_SetDict.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.describe("Dict.fromArray", () => { + Mocha.test("Dict.fromArray", () => { + Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] + ]); }); }); -Mocha.describe("Belt_MutableSet.fromArray", () => { - Mocha.test("Belt_MutableSet.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MutableSet.fromArray([ +Mocha.describe("Dict.fromIterator", () => { + Mocha.test("Dict.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); + map1.set('first', 1); + map1.set('second', 2); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ 1, - 3, - 2, - 4 - ], IntCmp); - Belt_MutableSet.toArray(s0); + 2 + ]); }); }); -Mocha.describe("Belt_MutableSet.mergeMany", () => { - Mocha.test("Belt_MutableSet.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 +Mocha.describe("Dict.get", () => { + Mocha.test("Dict.get", () => { + let dict = Object.fromEntries([[ + "someKey", + "someValue" + ]]); + let value = dict["someKey"]; + if (value !== undefined) { + console.log(value); + } else { + console.log("Nope, didn't have the key."); + } + }); +}); + +Mocha.describe("Dict.getUnsafe", () => { + Mocha.test("Dict.getUnsafe", () => { + let dict = Object.fromEntries([ + [ + "key1", + "value1" + ], + [ + "key2", + "value2" + ] ]); - Belt_MutableSet.toArray(set); + let value = dict["key1"]; + console.log(value); }); }); -Mocha.describe("Belt_MutableSet.intersect", () => { - Mocha.test("Belt_MutableSet.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.describe("Dict.keysToArray", () => { + Mocha.test("Dict.keysToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let keys = Object.keys(dict); + console.log(keys); }); }); -Mocha.describe("Belt_MutableSet.partition", () => { - Mocha.test("Belt_MutableSet.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.describe("Dict.make", () => { + Mocha.test("Dict.make", () => { + let dict2 = {}; + dict2["someKey"] = 12; }); }); -Mocha.describe("Belt_Map.Dict.findFirstBy", () => { - Mocha.test("Belt_Map.Dict.findFirstBy", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_MapDict.fromArray([ - [ - 4, - "4" - ], - [ - 1, - "1" - ], +Mocha.describe("Dict.mapValues", () => { + Mocha.test("Dict.mapValues", () => { + let dict = Object.fromEntries([ [ - 2, - "2" + "key1", + 1 ], [ - 3, - "3" + "key2", + 2 ] - ], IntCmp.cmp); - Primitive_object.equal(Belt_MapDict.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" ]); + Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); + Object.entries(Dict.mapValues(dict, v => v.toString())); }); }); -Mocha.describe("Belt_List.reduceWithIndex", () => { - Mocha.test("Belt_List.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.describe("Dict.set", () => { + Mocha.test("Dict.set", () => { + let dict = {}; + dict["someKey"] = "someValue"; }); }); -Mocha.describe("Belt_List.filterWithIndex", () => { - Mocha.test("Belt_List.filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); +Mocha.describe("Dict.toArray", () => { + Mocha.test("Dict.toArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let asArray = Object.entries(dict); + console.log(asArray); }); }); -Mocha.describe("Belt.Array.reverseInPlace", () => { - Mocha.test("Belt.Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Dict.valuesToArray", () => { + Mocha.test("Dict.valuesToArray", () => { + let dict = {}; + dict["someKey"] = 1; + dict["someKey2"] = 2; + let values = Object.values(dict); + console.log(values); }); }); -Mocha.describe("Belt.Array.reduceReverse2", () => { - Mocha.test("Belt.Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("Error.make", () => { + Mocha.test("Error.make", () => { + let error = new Error("Some message here"); + console.log(error.message); + console.log(error.name); }); }); -Mocha.describe("Belt.List.reduceWithIndex", () => { - Mocha.test("Belt.List.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.describe("Error.message", () => { + Mocha.test("Error.message", () => { + let error = new SyntaxError("Some message here"); + console.log(error.message); }); }); -Mocha.describe("Belt.List.filterWithIndex", () => { - Mocha.test("Belt.List.filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 +Mocha.describe("Error.name", () => { + Mocha.test("Error.name", () => { + let error = new SyntaxError("Some message here"); + console.log(error.name); + }); +}); + +Mocha.describe("Error.panic", () => { + Mocha.test("Error.panic", () => { + try { + $$Error.panic("Uh oh. This was unexpected!"); + } catch (raw_obj) { + let obj = Primitive_exceptions.internalToException(raw_obj); + if (obj.RE_EXN_ID === 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", + 12962, + 15 + ], + Error: new Error() + }; } + + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12963, + 12 + ], + Error: new Error() + }; } + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 12965, + 7 + ], + Error: new Error() + }; } - }, (_x, index) => index % 2 === 0); + } }); }); -Mocha.describe("Belt.MutableSet.fromArray", () => { - Mocha.test("Belt.MutableSet.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.describe("Error.raise", () => { + Mocha.test("Error.raise", () => { + new Error("Everything is upside down."); + console.log("Phew, sanity still rules."); }); }); -Mocha.describe("Belt.MutableSet.mergeMany", () => { - Mocha.test("Belt.MutableSet.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.describe("Error.stack", () => { + Mocha.test("Error.stack", () => { + let error = new Error("error"); + console.log(error.stack); }); }); -Mocha.describe("Belt.MutableSet.intersect", () => { - Mocha.test("Belt.MutableSet.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.describe("Error.toException", () => { + Mocha.test("Error.toException", () => { + new Error("Something went wrong."); }); }); -Mocha.describe("Belt.MutableSet.partition", () => { - Mocha.test("Belt.MutableSet.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.describe("Float.Constants.epsilon", () => { + Mocha.test("Float.Constants.epsilon", () => {}); }); -Mocha.describe("Belt.Map.Dict.findFirstBy", () => { - Mocha.test("Belt.Map.Dict.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("Float.Constants.maxValue", () => { + Mocha.test("Float.Constants.maxValue", () => {}); }); -Mocha.describe("Belt_Array.reverseInPlace", () => { - Mocha.test("Belt_Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); +Mocha.describe("Float.Constants.minValue", () => { + Mocha.test("Float.Constants.minValue", () => {}); }); -Mocha.describe("Belt_Array.reduceReverse2", () => { - Mocha.test("Belt_Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); +Mocha.describe("Float.Constants.nan", () => { + Mocha.test("Float.Constants.nan", () => {}); }); -Mocha.describe("String.splitByRegExpAtMost", () => { - Mocha.test("String.splitByRegExpAtMost", () => { - Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ - "Hello", - "World.", - "How" - ]); - }); +Mocha.describe("Float.Constants.negativeInfinity", () => { + Mocha.test("Float.Constants.negativeInfinity", () => {}); }); -Mocha.describe("RegExp.fromStringWithFlags", () => { - Mocha.test("RegExp.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.describe("Float.Constants.positiveInfinity", () => { + Mocha.test("Float.Constants.positiveInfinity", () => {}); +}); + +Mocha.describe("Float.clamp", () => { + Mocha.test("Float.clamp", () => { + Float.clamp(undefined, undefined, 4.2) === 4.2; + Float.clamp(4.3, undefined, 4.2) === 4.3; + Float.clamp(undefined, 4.1, 4.2) === 4.1; + Float.clamp(4.3, 4.1, 4.2) === 4.3; }); }); -Mocha.describe("Pervasives.setTimeoutFloat", () => { - Mocha.test("Pervasives.setTimeoutFloat", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); +Mocha.describe("Float.fromInt", () => { + Mocha.test("Float.fromInt", () => {}); +}); + +Mocha.describe("Float.fromString", () => { + Mocha.test("Float.fromString", () => { + Primitive_object.equal(Float.fromString("0"), 0.0); + Float.fromString("NaN") === undefined; + Primitive_object.equal(Float.fromString("6"), 6.0); }); }); -Mocha.describe("JSON.stringifyWithReplacer", () => { - Mocha.test("JSON.stringifyWithReplacer", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); +Mocha.describe("Float.isFinite", () => { + Mocha.test("Float.isFinite", () => { + isFinite(1.0); + isFinite(NaN); + isFinite(Number.POSITIVE_INFINITY); }); }); -Mocha.describe("Iterator.toArrayWithMapper", () => { - Mocha.test("Iterator.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("Float.isNaN", () => { + Mocha.test("Float.isNaN", () => { + isNaN(3.0); + isNaN(NaN); + }); +}); + +Mocha.describe("Float.mod", () => { + Mocha.test("Float.mod", () => {}); +}); + +Mocha.describe("Float.parseFloat", () => { + Mocha.test("Float.parseFloat", () => { + parseFloat("1.0"); + parseFloat(" 3.14 "); + parseFloat("3.0"); + parseFloat("3.14some non-digit characters"); + isNaN(parseFloat("error")); + }); +}); + +Mocha.describe("Float.parseInt", () => { + Mocha.test("Float.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.describe("Float.parseIntWithRadix", () => { + Mocha.test("Float.parseIntWithRadix", () => { + parseInt("10.0", 2); + parseInt("15 * 3", 10); + parseInt("12", 13); + isNaN(parseInt("17", 40)); + }); +}); + +Mocha.describe("Float.toExponential", () => { + Mocha.test("Float.toExponential", () => { + (1000.0).toExponential(); + (-1000.0).toExponential(); + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); +}); + +Mocha.describe("Float.toExponentialWithPrecision", () => { + Mocha.test("Float.toExponentialWithPrecision", () => { + (77.0).toExponential(2); + (5678.0).toExponential(2); + }); +}); + +Mocha.describe("Float.toFixed", () => { + Mocha.test("Float.toFixed", () => { + (123456.0).toFixed(); + (10.0).toFixed(); + (300.0).toFixed(4); + (300.0).toFixed(1); }); }); @@ -18521,1673 +17778,3266 @@ Mocha.describe("Float.toFixedWithPrecision", () => { }); }); -Mocha.describe("Belt_internalMapInt.A.fill", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Float.toInt", () => { + Mocha.test("Float.toInt", () => {}); +}); + +Mocha.describe("Float.toLocaleString", () => { + Mocha.test("Float.toLocaleString", () => { + (1000.0).toLocaleString(); + (1000.0).toLocaleString(); }); }); -Mocha.describe("Belt_internalMapInt.A.blit", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Float.toPrecision", () => { + Mocha.test("Float.toPrecision", () => { + (100.0).toPrecision(); + (1.0).toPrecision(); + (100.0).toPrecision(2); + (1.0).toPrecision(1); }); }); -Mocha.describe("Belt_internalMapInt.A.some", () => { - Mocha.test("Belt_internalMapInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Float.toPrecisionWithPrecision", () => { + Mocha.test("Float.toPrecisionWithPrecision", () => { + (100.0).toPrecision(2); + (1.0).toPrecision(1); + }); +}); + +Mocha.describe("Float.toString", () => { + Mocha.test("Float.toString", () => { + (1000.0).toString(); + (-1000.0).toString(); + }); +}); + +Mocha.describe("Float.toStringWithRadix", () => { + Mocha.test("Float.toStringWithRadix", () => { + (6.0).toString(2); + (3735928559.0).toString(16); + (123456.0).toString(36); + }); +}); + +Mocha.describe("Int.Bitwise.asr", () => { + Mocha.test("Int.Bitwise.asr", () => {}); +}); + +Mocha.describe("Int.Bitwise.land", () => { + Mocha.test("Int.Bitwise.land", () => {}); +}); + +Mocha.describe("Int.Bitwise.lnot", () => { + Mocha.test("Int.Bitwise.lnot", () => { + Int.Bitwise.lnot(2) === -3; + }); +}); + +Mocha.describe("Int.Bitwise.lor", () => { + Mocha.test("Int.Bitwise.lor", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsl", () => { + Mocha.test("Int.Bitwise.lsl", () => {}); +}); + +Mocha.describe("Int.Bitwise.lsr", () => { + Mocha.test("Int.Bitwise.lsr", () => {}); +}); + +Mocha.describe("Int.Bitwise.lxor", () => { + Mocha.test("Int.Bitwise.lxor", () => {}); +}); + +Mocha.describe("Int.Constants.maxValue", () => { + Mocha.test("Int.Constants.maxValue", () => { + console.log(Int.Constants.maxValue); + }); +}); + +Mocha.describe("Int.Constants.minValue", () => { + Mocha.test("Int.Constants.minValue", () => { + console.log(Int.Constants.minValue); + }); +}); + +Mocha.describe("Int.clamp", () => { + Mocha.test("Int.clamp", () => { + Int.clamp(undefined, undefined, 42) === 42; + Int.clamp(50, undefined, 42) === 50; + Int.clamp(undefined, 40, 42) === 40; + Int.clamp(50, 40, 42) === 50; + }); +}); + +Mocha.describe("Int.fromFloat", () => { + Mocha.test("Int.fromFloat", () => {}); +}); + +Mocha.describe("Int.fromString", () => { + Mocha.test("Int.fromString", () => { + Primitive_object.equal(Int.fromString("0", undefined), 0); + Int.fromString("NaN", undefined) === undefined; + Int.fromString("6", 2) === undefined; + }); +}); + +Mocha.describe("Int.mod", () => { + Mocha.test("Int.mod", () => {}); +}); + +Mocha.describe("Int.range", () => { + Mocha.test("Int.range", () => { + Primitive_object.equal(Int.range(3, 6, undefined), [ + 3, + 4, + 5 + ]); + Primitive_object.equal(Int.range(-3, -1, undefined), [ + -3, + -2 + ]); + Primitive_object.equal(Int.range(3, 1, undefined), [ + 3, + 2 + ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Int.range(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Int.range(3, 6, { + step: -2 + }); + }); +}); + +Mocha.describe("Int.rangeWithOptions", () => { + Mocha.test("Int.rangeWithOptions", () => { + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2 + }), [ + 3, + 5 + ]); + Primitive_object.equal(Int.rangeWithOptions(3, 7, { + step: 2, + inclusive: true + }), [ + 3, + 5, + 7 + ]); + Int.rangeWithOptions(3, 6, { + step: -2 + }); + }); +}); + +Mocha.describe("Int.toExponential", () => { + Mocha.test("Int.toExponential", () => { + (1000).toExponential(); + (-1000).toExponential(); + (77).toExponential(2); + (5678).toExponential(2); + }); +}); + +Mocha.describe("Int.toExponentialWithPrecision", () => { + Mocha.test("Int.toExponentialWithPrecision", () => { + (77).toExponential(2); + (5678).toExponential(2); + }); +}); + +Mocha.describe("Int.toFixed", () => { + Mocha.test("Int.toFixed", () => { + (123456).toFixed(); + (10).toFixed(); + (300).toFixed(4); + (300).toFixed(1); + }); +}); + +Mocha.describe("Int.toFixedWithPrecision", () => { + Mocha.test("Int.toFixedWithPrecision", () => { + (300).toFixed(4); + (300).toFixed(1); + }); +}); + +Mocha.describe("Int.toFloat", () => { + Mocha.test("Int.toFloat", () => {}); +}); + +Mocha.describe("Int.toLocaleString", () => { + Mocha.test("Int.toLocaleString", () => { + (1000).toLocaleString(); + (1000).toLocaleString(); + }); +}); + +Mocha.describe("Int.toPrecision", () => { + Mocha.test("Int.toPrecision", () => { + (100).toPrecision(); + (1).toPrecision(); + (100).toPrecision(2); + (1).toPrecision(2); + }); +}); + +Mocha.describe("Int.toPrecisionWithPrecision", () => { + Mocha.test("Int.toPrecisionWithPrecision", () => { + (100).toPrecision(2); + (1).toPrecision(2); + }); +}); + +Mocha.describe("Int.toString", () => { + Mocha.test("Int.toString", () => { + (1000).toString(); + (-1000).toString(); + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); +}); + +Mocha.describe("Int.toStringWithRadix", () => { + Mocha.test("Int.toStringWithRadix", () => { + (6).toString(2); + (373592855).toString(16); + (123456).toString(36); + }); +}); + +Mocha.describe("Iterator.forEach", () => { + Mocha.test("Iterator.forEach", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + $$Iterator.forEach(iterator, v => { + if (v === undefined) { + return Pervasives.assertEqual(Option.isNone(v), true); + } + switch (v) { + case "a" : + case "b" : + case "c" : + return; + default: + return Pervasives.assertEqual(Option.isNone(v), true); + } + }); + }); +}); + +Mocha.describe("Iterator.next", () => { + Mocha.test("Iterator.next", () => { + let iterator = ((() => { + var array1 = ['a']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(iterator.next().done, false); + Pervasives.assertEqual(iterator.next().done, true); + }); +}); + +Mocha.describe("Iterator.toArray", () => { + Mocha.test("Iterator.toArray", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + let mapKeysAsArray = Array.from(map.keys()); + console.log(mapKeysAsArray); + }); +}); + +Mocha.describe("Iterator.toArrayWithMapper", () => { + Mocha.test("Iterator.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("JSON.Classify.classify", () => { + Mocha.test("JSON.Classify.classify", () => { + $$JSON.Classify.classify("hello world"); + $$JSON.Classify.classify(42); + }); +}); + +Mocha.describe("JSON.Decode.array", () => { + Mocha.test("JSON.Decode.array", () => { + $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); + $$JSON.Decode.array(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.bool", () => { + Mocha.test("JSON.Decode.bool", () => { + $$JSON.Decode.bool(JSON.parse("true")); + $$JSON.Decode.bool(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.float", () => { + Mocha.test("JSON.Decode.float", () => { + $$JSON.Decode.float(JSON.parse("42.0")); + $$JSON.Decode.float(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.null", () => { + Mocha.test("JSON.Decode.null", () => { + $$JSON.Decode.$$null(JSON.parse("null")); + $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.object", () => { + Mocha.test("JSON.Decode.object", () => { + $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); + $$JSON.Decode.object(JSON.parse("\"hello world\"")); + }); +}); + +Mocha.describe("JSON.Decode.string", () => { + Mocha.test("JSON.Decode.string", () => { + $$JSON.Decode.string(JSON.parse("\"hello world\"")); + $$JSON.Decode.string(JSON.parse("42")); + }); +}); + +Mocha.describe("JSON.Encode.array", () => { + Mocha.test("JSON.Encode.array", () => {}); +}); + +Mocha.describe("JSON.Encode.bool", () => { + Mocha.test("JSON.Encode.bool", () => {}); +}); + +Mocha.describe("JSON.Encode.float", () => { + Mocha.test("JSON.Encode.float", () => {}); +}); + +Mocha.describe("JSON.Encode.int", () => { + Mocha.test("JSON.Encode.int", () => {}); +}); + +Mocha.describe("JSON.Encode.null", () => { + Mocha.test("JSON.Encode.null", () => {}); +}); + +Mocha.describe("JSON.Encode.object", () => { + Mocha.test("JSON.Encode.object", () => { + Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ] + ]); + }); +}); + +Mocha.describe("JSON.Encode.string", () => { + Mocha.test("JSON.Encode.string", () => {}); +}); + +Mocha.describe("JSON.parseExn", () => { + Mocha.test("JSON.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 === 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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn$1; + } + } + }); +}); + +Mocha.describe("JSON.parseExnWithReviver", () => { + Mocha.test("JSON.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 === Exn.$$Error) { + console.log("error"); + } else { + throw exn; + } + } + }); +}); + +Mocha.describe("JSON.stringify", () => { + Mocha.test("JSON.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 = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); +}); + +Mocha.describe("JSON.stringifyAny", () => { + Mocha.test("JSON.stringifyAny", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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", + 13927, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithFilter", () => { + Mocha.test("JSON.stringifyAnyWithFilter", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.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", + 13951, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); + Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.assertEqual(JSON.stringify(dict, [ + "foo", + "someNumber" + ]), "{\"foo\":\"bar\",\"someNumber\":42}"); + Pervasives.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", + 13990, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithIndent", () => { + Mocha.test("JSON.stringifyAnyWithIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); + Pervasives.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", + 14019, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithReplacer", () => { + Mocha.test("JSON.stringifyAnyWithReplacer", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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", + 14053, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { + let dict = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); + Pervasives.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", + 14087, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("JSON.stringifyWithFilter", () => { + Mocha.test("JSON.stringifyWithFilter", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ]); + }); +}); + +Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { + Mocha.test("JSON.stringifyWithFilterAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, [ + "foo", + "someNumber" + ], 2); + }); +}); + +Mocha.describe("JSON.stringifyWithIndent", () => { + Mocha.test("JSON.stringifyWithIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + JSON.stringify(json, null, 2); + }); +}); + +Mocha.describe("JSON.stringifyWithReplacer", () => { + Mocha.test("JSON.stringifyWithReplacer", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer); + }); +}); + +Mocha.describe("JSON.stringifyWithReplacerAndIndent", () => { + Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { + let json = Object.fromEntries([ + [ + "foo", + "bar" + ], + [ + "hello", + "world" + ], + [ + "someNumber", + 42 + ] + ]); + let replacer = (param, value) => { + let decodedValue = $$JSON.Decode.string(value); + if (decodedValue !== undefined) { + return decodedValue.toUpperCase(); + } else { + return value; + } + }; + JSON.stringify(json, replacer, 2); + }); +}); + +Mocha.describe("List.add", () => { + Mocha.test("List.add", () => { + List.add({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, 1); + List.add({ + hd: "World", + tl: { + hd: "!", + tl: /* [] */0 + } + }, "Hello"); + }); +}); + +Mocha.describe("List.compare", () => { + Mocha.test("List.compare", () => { + List.compare({ + hd: 3, + tl: /* [] */0 + }, { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + }, Primitive_int.compare); + List.compare({ + hd: 5, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 5, + tl: /* [] */0 + }, Primitive_int.compare); + 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); + 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); + 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.describe("List.compareLength", () => { + Mocha.test("List.compareLength", () => { + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + } + }); + List.compareLength({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, { + hd: 5, + tl: { + hd: 6, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.concat", () => { + Mocha.test("List.concat", () => { + List.concat({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.concatMany", () => { + Mocha.test("List.concatMany", () => { + List.concatMany([ + { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, + /* [] */0, + { + hd: 3, + tl: /* [] */0 + } + ]); + }); +}); + +Mocha.describe("List.drop", () => { + Mocha.test("List.drop", () => { + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 3); + List.drop({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); + }); +}); + +Mocha.describe("List.equal", () => { + Mocha.test("List.equal", () => { + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + List.equal({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, (a, b) => a === b); + 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.describe("List.every", () => { + Mocha.test("List.every", () => { + let isBelow10 = value => value < 10; + List.every({ + hd: 1, + tl: { + hd: 9, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + List.every({ + hd: 1, + tl: { + hd: 99, + tl: { + hd: 8, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, isBelow10); + }); +}); + +Mocha.describe("List.every2", () => { + Mocha.test("List.every2", () => { + List.every2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.every2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.every2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); +}); + +Mocha.describe("List.filter", () => { + Mocha.test("List.filter", () => { + let isEven = x => x % 2 === 0; + List.filter({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isEven); + List.filter({ + hd: undefined, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + } + }, Option.isSome); + }); +}); + +Mocha.describe("List.filterMap", () => { + Mocha.test("List.filterMap", () => { + let isEven = x => x % 2 === 0; + List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => { + if (isEven(x)) { + return x; + } + + }); + List.filterMap({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: undefined, + tl: /* [] */0 + } + } + }, x => x); + }); +}); + +Mocha.describe("List.filterWithIndex", () => { + Mocha.test("List.filterWithIndex", () => { + List.filterWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, (_x, index) => index % 2 === 0); + }); +}); + +Mocha.describe("List.find", () => { + Mocha.test("List.find", () => { + List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 3); + List.find({ + hd: 1, + tl: { + hd: 4, + tl: { + hd: 3, + tl: { + hd: 2, + tl: /* [] */0 + } + } + } + }, x => x > 4); + }); +}); + +Mocha.describe("List.flat", () => { + Mocha.test("List.flat", () => { + 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.describe("List.forEach", () => { + Mocha.test("List.forEach", () => { + List.forEach({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, x => { + console.log("Item: " + x); + }); + }); +}); + +Mocha.describe("List.forEach2", () => { + Mocha.test("List.forEach2", () => { + 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.describe("List.forEachWithIndex", () => { + Mocha.test("List.forEachWithIndex", () => { + List.forEachWithIndex({ + hd: "a", + tl: { + hd: "b", + tl: { + hd: "c", + tl: /* [] */0 + } + } + }, (x, index) => { + console.log("Item " + index.toString() + " is " + x); + }); + }); +}); + +Mocha.describe("List.fromArray", () => { + Mocha.test("List.fromArray", () => { + List.fromArray([ + 1, + 2, + 3 + ]); + }); +}); + +Mocha.describe("List.fromInitializer", () => { + Mocha.test("List.fromInitializer", () => { + List.fromInitializer(5, i => i); + List.fromInitializer(5, i => Math.imul(i, i)); + }); +}); + +Mocha.describe("List.get", () => { + Mocha.test("List.get", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + List.get(abc, 1); + List.get(abc, 4); + }); +}); + +Mocha.describe("List.getAssoc", () => { + Mocha.test("List.getAssoc", () => { + List.getAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 3, (a, b) => a === b); + List.getAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, (k, item) => k === item); + }); +}); + +Mocha.describe("List.getExn", () => { + Mocha.test("List.getExn", () => { + let abc = { + hd: "A", + tl: { + hd: "B", + tl: { + hd: "C", + tl: /* [] */0 + } + } + }; + Pervasives.assertEqual(List.getExn(abc, 1), "B"); + let exit = 0; + let val; + try { + val = 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", + 14485, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("List.has", () => { + Mocha.test("List.has", () => { + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2, (a, b) => a === b); + List.has({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4, (a, b) => a === b); + List.has({ + hd: -1, + tl: { + hd: -2, + tl: { + hd: -3, + tl: /* [] */0 + } + } + }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); + }); +}); + +Mocha.describe("List.hasAssoc", () => { + Mocha.test("List.hasAssoc", () => { + List.hasAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + List.hasAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 25, (k, item) => k === item); + }); +}); + +Mocha.describe("List.head", () => { + Mocha.test("List.head", () => { + List.head(/* [] */0); + List.head({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.headExn", () => { + Mocha.test("List.headExn", () => { + Pervasives.assertEqual(List.headExn({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }), 1); + let exit = 0; + let val; + try { + val = 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", + 14534, + 7 + ], + Error: new Error() + }; + } + + }); +}); + +Mocha.describe("List.length", () => { + Mocha.test("List.length", () => { + List.length({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.make", () => { + Mocha.test("List.make", () => { + List.make(3, 1); + }); +}); + +Mocha.describe("List.map", () => { + Mocha.test("List.map", () => { + List.map({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, x => x + 1 | 0); + }); +}); + +Mocha.describe("List.mapReverse", () => { + Mocha.test("List.mapReverse", () => { + let f = x => Math.imul(x, x); + let l = { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } + }; + let withMap = List.reverse(List.map(l, f)); + let withMapReverse = List.mapReverse(l, f); + console.log(Primitive_object.equal(withMap, withMapReverse)); + }); +}); + +Mocha.describe("List.mapReverse2", () => { + Mocha.test("List.mapReverse2", () => { + 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.describe("List.mapWithIndex", () => { + Mocha.test("List.mapWithIndex", () => { + List.mapWithIndex({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, (x, index) => index + x | 0); + }); +}); + +Mocha.describe("List.partition", () => { + Mocha.test("List.partition", () => { + List.partition({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, x => x > 2); + }); +}); + +Mocha.describe("List.reduce", () => { + Mocha.test("List.reduce", () => { + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduce({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (acc, item) => acc + item | 0); + }); +}); + +Mocha.describe("List.reduce2", () => { + Mocha.test("List.reduce2", () => { + List.reduce2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("List.reduceReverse", () => { + Mocha.test("List.reduceReverse", () => { + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 0, (a, b) => a + b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, 10, (a, b) => a - b | 0); + List.reduceReverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, /* [] */0, List.add); + }); +}); + +Mocha.describe("List.reduceReverse2", () => { + Mocha.test("List.reduceReverse2", () => { + List.reduceReverse2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); + }); +}); + +Mocha.describe("List.reduceWithIndex", () => { + Mocha.test("List.reduceWithIndex", () => { + 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.describe("List.removeAssoc", () => { + Mocha.test("List.removeAssoc", () => { + List.removeAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 1, (a, b) => a === b); + List.removeAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 15, + "afternoon" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 9, (k, item) => k === item); + }); +}); + +Mocha.describe("List.reverse", () => { + Mocha.test("List.reverse", () => { + List.reverse({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.reverseConcat", () => { + Mocha.test("List.reverseConcat", () => { + List.reverseConcat({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + }); + }); +}); + +Mocha.describe("List.setAssoc", () => { + Mocha.test("List.setAssoc", () => { + List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 2, + "b" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + } + }, 2, "x", (a, b) => a === b); + List.setAssoc({ + hd: [ + 1, + "a" + ], + tl: { + hd: [ + 3, + "c" + ], + tl: /* [] */0 + } + }, 2, "b", (a, b) => a === b); + List.setAssoc({ + hd: [ + 9, + "morning" + ], + tl: { + hd: [ + 3, + "morning?!" + ], + tl: { + hd: [ + 22, + "night" + ], + tl: /* [] */0 + } + } + }, 15, "afternoon", (a, b) => a % 12 === b % 12); + }); +}); + +Mocha.describe("List.size", () => { + Mocha.test("List.size", () => { + List.size({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + }); +}); + +Mocha.describe("List.some", () => { + Mocha.test("List.some", () => { + let isAbove100 = value => value > 100; + List.some({ + hd: 101, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + } + }, isAbove100); + List.some({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + }, isAbove100); + }); +}); + +Mocha.describe("List.some2", () => { + Mocha.test("List.some2", () => { + List.some2({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, { + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, (a, b) => a > b); + List.some2(/* [] */0, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + }, { + hd: 1, + tl: /* [] */0 + }, (a, b) => a > b); + List.some2({ + hd: 0, + tl: { + hd: 1, + tl: /* [] */0 + } + }, { + hd: 5, + tl: { + hd: 0, + tl: /* [] */0 + } + }, (a, b) => a > b); + }); +}); + +Mocha.describe("List.sort", () => { + Mocha.test("List.sort", () => { + List.sort({ + hd: 5, + tl: { + hd: 4, + tl: { + hd: 9, + tl: { + hd: 3, + tl: { + hd: 7, + tl: /* [] */0 + } + } + } + } + }, Primitive_int.compare); + }); +}); + +Mocha.describe("List.splitAt", () => { + Mocha.test("List.splitAt", () => { + List.splitAt({ + hd: "Hello", + tl: { + hd: "World", + tl: /* [] */0 + } + }, 1); + List.splitAt({ + hd: 0, + tl: { + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: { + hd: 4, + tl: /* [] */0 + } + } + } + } + }, 2); + }); +}); + +Mocha.describe("List.tail", () => { + Mocha.test("List.tail", () => { + List.tail({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); + List.tail(/* [] */0); + }); +}); + +Mocha.describe("List.tailExn", () => { + Mocha.test("List.tailExn", () => { + Pervasives.assertEqual(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 = 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", + 14786, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalSetInt.A.fill", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("List.take", () => { + Mocha.test("List.take", () => { + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 1); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 2); + List.take({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }, 4); }); }); -Mocha.describe("Belt_internalSetInt.A.blit", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("List.toArray", () => { + Mocha.test("List.toArray", () => { + List.toArray({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt_internalSetInt.A.some", () => { - Mocha.test("Belt_internalSetInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("List.toShuffled", () => { + Mocha.test("List.toShuffled", () => { + List.toShuffled({ + hd: 1, + tl: { + hd: 2, + tl: { + hd: 3, + tl: /* [] */0 + } + } + }); }); }); -Mocha.describe("Belt_Set.Dict.minUndefined", () => { - Mocha.test("Belt_Set.Dict.minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.unzip", () => { + Mocha.test("List.unzip", () => { + List.unzip({ + hd: [ + 1, + 2 + ], + tl: { + hd: [ + 3, + 4 + ], + tl: /* [] */0 + } + }); + 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 + } + } + } + } + } }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.minUndefined(undefined); - Belt_SetDict.minUndefined(s1); }); }); -Mocha.describe("Belt_Set.Dict.maxUndefined", () => { - Mocha.test("Belt_Set.Dict.maxUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("List.zip", () => { + Mocha.test("List.zip", () => { + List.zip({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }, { + hd: 3, + tl: { + hd: 4, + tl: { + hd: 5, + tl: /* [] */0 + } + } }); - let s1 = Belt_SetDict.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp.cmp); - Belt_SetDict.maxUndefined(undefined); - Belt_SetDict.maxUndefined(s1); }); }); -Mocha.describe("Belt_Result.mapWithDefault", () => { - Mocha.test("Belt_Result.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("List.zipBy", () => { + Mocha.test("List.zipBy", () => { + 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_Result.getWithDefault", () => { - Mocha.test("Belt_Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; +Mocha.describe("Map.clear", () => { + Mocha.test("Map.clear", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.clear(); }); }); -Mocha.describe("Belt_Option.mapWithDefault", () => { - Mocha.test("Belt_Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); +Mocha.describe("Map.delete", () => { + Mocha.test("Map.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.describe("Belt_Option.getWithDefault", () => { - Mocha.test("Belt_Option.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.describe("Map.entries", () => { + Mocha.test("Map.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.describe("Belt_MutableSet.removeMany", () => { - Mocha.test("Belt_MutableSet.removeMany", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Map.forEach", () => { + Mocha.test("Map.forEach", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach(value => { + console.log(value); }); - let set = Belt_MutableSet.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Belt_MutableSet.removeMany(set, [ - 5, - 4, - 3, - 2, - 1 - ]); - Belt_MutableSet.toArray(set); }); }); -Mocha.describe("Belt_MapString.findFirstBy", () => { - Mocha.test("Belt_MapString.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ +Mocha.describe("Map.forEachWithKey", () => { + Mocha.test("Map.forEachWithKey", () => { + let map = new Map(); + map.set("someKey", "someValue"); + map.set("someKey2", "someValue2"); + map.forEach((value, key) => { + console.log(value, key); + }); + }); +}); + +Mocha.describe("Map.fromArray", () => { + Mocha.test("Map.fromArray", () => { + let languageRank = [ [ - "1", - "one" + "ReScript", + 1 ], [ - "2", - "two" + "JavaScript", + 2 ], [ - "3", - "three" + "TypeScript", + 3 ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_List.forEachWithIndex", () => { - Mocha.test("Belt_List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); + ]; + 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.describe("Belt.Array.reduceWithIndex", () => { - Mocha.test("Belt.Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); +Mocha.describe("Map.fromIterator", () => { + Mocha.test("Map.fromIterator", () => { + let iterator = ((() => { + var map1 = new Map(); -Mocha.describe("Belt.List.forEachWithIndex", () => { - Mocha.test("Belt.List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); - }); -}); + map1.set('first', '1'); + map1.set('second', '2'); -Mocha.describe("Belt.MutableSet.removeMany", () => { - Mocha.test("Belt.MutableSet.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); + var iterator1 = map1[Symbol.iterator](); + return iterator1; + })()); + Pervasives.assertEqual(new Map(iterator).size, 2); }); }); -Mocha.describe("Belt.HashMap.valuesToArray", () => { - Mocha.test("Belt.HashMap.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("Map.get", () => { + Mocha.test("Map.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.describe("Belt.Option.mapWithDefault", () => { - Mocha.test("Belt.Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); +Mocha.describe("Map.has", () => { + Mocha.test("Map.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.describe("Belt.Option.getWithDefault", () => { - Mocha.test("Belt.Option.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.describe("Map.keys", () => { + Mocha.test("Map.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.describe("Belt.Result.mapWithDefault", () => { - Mocha.test("Belt.Result.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("Map.make", () => { + Mocha.test("Map.make", () => { + new Map(); + let map = new Map(); + map.set("lang", "ReScript"); }); }); -Mocha.describe("Belt.Result.getWithDefault", () => { - Mocha.test("Belt.Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; +Mocha.describe("Map.set", () => { + Mocha.test("Map.set", () => { + let map = new Map(); + map.set("someKey", "someValue"); }); }); -Mocha.describe("Belt.Set.Dict.minUndefined", () => { - Mocha.test("Belt.Set.Dict.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.describe("Map.size", () => { + Mocha.test("Map.size", () => { + let map = new Map(); + map.set("someKey", "someValue"); }); }); -Mocha.describe("Belt.Set.Dict.maxUndefined", () => { - Mocha.test("Belt.Set.Dict.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.describe("Map.values", () => { + Mocha.test("Map.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("Belt_Array.reduceWithIndex", () => { - Mocha.test("Belt_Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); +Mocha.describe("Math.Constants.e", () => { + Mocha.test("Math.Constants.e", () => {}); }); -Mocha.describe("Belt_HashMap.valuesToArray", () => { - Mocha.test("Belt_HashMap.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("Math.Constants.ln10", () => { + Mocha.test("Math.Constants.ln10", () => {}); }); -Mocha.describe("Array.reduceRightWithIndex", () => { - Mocha.test("Array.reduceRightWithIndex", () => { - Pervasives.assertEqual($$Array.reduceRightWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); +Mocha.describe("Math.Constants.ln2", () => { + Mocha.test("Math.Constants.ln2", () => {}); }); -Mocha.describe("Pervasives.setIntervalFloat", () => { - Mocha.test("Pervasives.setIntervalFloat", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms"); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500.0); - }); +Mocha.describe("Math.Constants.log10e", () => { + Mocha.test("Math.Constants.log10e", () => {}); }); -Mocha.describe("JSON.stringifyAnyWithIndent", () => { - Mocha.test("JSON.stringifyAnyWithIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.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", - 15451, - 7 - ], - Error: new Error() - }; - } - - }); +Mocha.describe("Math.Constants.log2e", () => { + Mocha.test("Math.Constants.log2e", () => {}); }); -Mocha.describe("JSON.stringifyAnyWithFilter", () => { - Mocha.test("JSON.stringifyAnyWithFilter", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 15475, - 7 - ], - Error: new Error() - }; - } - - }); +Mocha.describe("Math.Constants.pi", () => { + Mocha.test("Math.Constants.pi", () => {}); }); -Mocha.describe("Belt_internalSetString.A.eq", () => { - Mocha.test("Belt_internalSetString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); +Mocha.describe("Math.Constants.sqrt1_2", () => { + Mocha.test("Math.Constants.sqrt1_2", () => {}); }); -Mocha.describe("Belt_internalMapString.A.eq", () => { - Mocha.test("Belt_internalMapString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; +Mocha.describe("Math.Constants.sqrt2", () => { + Mocha.test("Math.Constants.sqrt2", () => {}); +}); + +Mocha.describe("Math.Int.abs", () => { + Mocha.test("Math.Int.abs", () => { + Math.abs(-2); + Math.abs(3); }); }); -Mocha.describe("Belt_internalMapInt.A.range", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.ceil", () => { + Mocha.test("Math.Int.ceil", () => { + $$Math.Int.ceil(3.7) === 4; + $$Math.Int.ceil(3.0) === 3; + $$Math.Int.ceil(-3.1) === -3; }); }); -Mocha.describe("Belt_internalMapInt.A.zipBy", () => { - Mocha.test("Belt_internalMapInt.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Math.Int.clz32", () => { + Mocha.test("Math.Int.clz32", () => { + Math.clz32(1); + Math.clz32(4); }); }); -Mocha.describe("Belt_internalMapInt.A.unzip", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.floor", () => { + Mocha.test("Math.Int.floor", () => { + $$Math.Int.floor(3.7) === 3; + $$Math.Int.floor(3.0) === 3; + $$Math.Int.floor(-3.1) === -4; }); }); -Mocha.describe("Belt_internalMapInt.A.slice", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.imul", () => { + Mocha.test("Math.Int.imul", () => { + Math.imul(3, 4); + Math.imul(-5, 12); }); }); -Mocha.describe("Belt_internalMapInt.A.getBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.max", () => { + Mocha.test("Math.Int.max", () => { + Math.max(1, 2); + Math.max(-1, -2); }); }); -Mocha.describe("Belt_internalMapInt.A.every", () => { - Mocha.test("Belt_internalMapInt.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Math.Int.maxMany", () => { + Mocha.test("Math.Int.maxMany", () => { + Math.max(1, 2); + Math.max(-1, -2); + isFinite(Math.max()); }); }); -Mocha.describe("Belt_internalMapInt.A.some2", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.Int.min", () => { + Mocha.test("Math.Int.min", () => { + Math.min(1, 2); + Math.min(-1, -2); }); }); -Mocha.describe("Belt_internalSetInt.A.range", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.Int.minMany", () => { + Mocha.test("Math.Int.minMany", () => { + Math.min(1, 2); + Math.min(-1, -2); + isFinite(Math.min()); }); }); -Mocha.describe("Belt_internalSetInt.A.zipBy", () => { - Mocha.test("Belt_internalSetInt.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Math.Int.pow", () => { + Mocha.test("Math.Int.pow", () => { + Math.pow(2, 4); + Math.pow(3, 4); }); }); -Mocha.describe("Belt_internalSetInt.A.unzip", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.Int.random", () => { + Mocha.test("Math.Int.random", () => { + $$Math.Int.random(2, 5) === 4; + $$Math.Int.random(505, 2000) === 1276; + $$Math.Int.random(-7, -2) === -4; + }); +}); + +Mocha.describe("Math.Int.sign", () => { + Mocha.test("Math.Int.sign", () => { + Math.sign(3); + Math.sign(-3); + Math.sign(0); }); }); -Mocha.describe("Belt_internalSetInt.A.slice", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.abs", () => { + Mocha.test("Math.abs", () => { + Math.abs(-2.0); + Math.abs(3.0); }); }); -Mocha.describe("Belt_internalSetInt.A.getBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.acos", () => { + Mocha.test("Math.acos", () => { + Math.acos(-1.0); + isNaN(Math.acos(-3.0)); }); }); -Mocha.describe("Belt_internalSetInt.A.every", () => { - Mocha.test("Belt_internalSetInt.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Math.acosh", () => { + Mocha.test("Math.acosh", () => { + Math.acosh(1.0); + isNaN(Math.acosh(0.5)); }); }); -Mocha.describe("Belt_internalSetInt.A.some2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.asin", () => { + Mocha.test("Math.asin", () => { + Math.asin(-1.0); + isNaN(Math.asin(-2.0)); }); }); -Mocha.describe("Belt_Map.String.findFirstBy", () => { - Mocha.test("Belt_Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); +Mocha.describe("Math.asinh", () => { + Mocha.test("Math.asinh", () => { + Math.asinh(-1.0); + Math.asinh(-0.0); }); }); -Mocha.describe("Belt.Array.forEachWithIndex", () => { - Mocha.test("Belt.Array.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.describe("Math.atan", () => { + Mocha.test("Math.atan", () => { + Math.atan(-0.0); + Math.atan(0.0); + Math.atan(1.0); }); }); -Mocha.describe("Belt.HashMap.keepMapInPlace", () => { - Mocha.test("Belt.HashMap.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.describe("Math.atan2", () => { + Mocha.test("Math.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.describe("Belt.Map.String.findFirstBy", () => { - Mocha.test("Belt.Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); +Mocha.describe("Math.atanh", () => { + Mocha.test("Math.atanh", () => { + isNaN(Math.atanh(-2.0)); + isFinite(Math.atanh(-1.0)); + Math.atanh(-0.0); + Math.atanh(0.0); + Math.atanh(0.5); + }); +}); + +Mocha.describe("Math.cbrt", () => { + Mocha.test("Math.cbrt", () => { + Math.cbrt(-1.0); + Math.cbrt(-0.0); + Math.cbrt(0.0); + }); +}); + +Mocha.describe("Math.ceil", () => { + Mocha.test("Math.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.describe("Math.cos", () => { + Mocha.test("Math.cos", () => { + Math.cos(-0.0); + Math.cos(0.0); + Math.cos(1.0); + }); +}); + +Mocha.describe("Math.cosh", () => { + Mocha.test("Math.cosh", () => { + Math.cosh(-1.0); + Math.cosh(-0.0); + Math.cosh(0.0); + }); +}); + +Mocha.describe("Math.exp", () => { + Mocha.test("Math.exp", () => { + Math.exp(-1.0); + Math.exp(0.0); + }); +}); + +Mocha.describe("Math.expm1", () => { + Mocha.test("Math.expm1", () => { + Math.expm1(-1.0); + Math.expm1(-0.0); }); }); -Mocha.describe("Belt_Array.forEachWithIndex", () => { - Mocha.test("Belt_Array.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.describe("Math.floor", () => { + Mocha.test("Math.floor", () => { + Math.floor(-45.95); + Math.floor(-45.05); + Math.floor(-0.0); }); }); -Mocha.describe("Belt_HashMap.keepMapInPlace", () => { - Mocha.test("Belt_HashMap.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.describe("Math.fround", () => { + Mocha.test("Math.fround", () => { + Math.fround(5.5) === 5.5; + Math.fround(5.05) === 5.050000190734863; }); }); -Mocha.describe("Int.toPrecisionWithPrecision", () => { - Mocha.test("Int.toPrecisionWithPrecision", () => { - (100).toPrecision(2); - (1).toPrecision(2); +Mocha.describe("Math.hypot", () => { + Mocha.test("Math.hypot", () => { + Math.hypot(3.0, 4.0); + Math.hypot(3.0, 5.0); }); }); -Mocha.describe("Belt_internalSetString.A.get", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Math.hypotMany", () => { + Mocha.test("Math.hypotMany", () => { + Math.hypot(3.0, 4.0, 5.0); + Math.hypot(); }); }); -Mocha.describe("Belt_internalSetString.A.zip", () => { - Mocha.test("Belt_internalSetString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); +Mocha.describe("Math.log", () => { + Mocha.test("Math.log", () => { + isNaN(Math.log(-1.0)); + isFinite(Math.log(-0.0)); + isFinite(Math.log(0.0)); + Math.log(1.0); }); }); -Mocha.describe("Belt_internalSetString.A.map", () => { - Mocha.test("Belt_internalSetString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("Math.log10", () => { + Mocha.test("Math.log10", () => { + isNaN(Math.log10(-2.0)); + isFinite(Math.log10(-0.0)); + isFinite(Math.log10(0.0)); + Math.log10(1.0); }); }); -Mocha.describe("Belt_internalSetString.A.cmp", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Math.log1p", () => { + Mocha.test("Math.log1p", () => { + isNaN(Math.log1p(-2.0)); + isFinite(Math.log1p(-1.0)); + Math.log1p(-0.0); }); }); -Mocha.describe("Belt_internalMapString.A.get", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Math.log2", () => { + Mocha.test("Math.log2", () => { + isNaN(Math.log2(-2.0)); + isFinite(Math.log2(-0.0)); + isFinite(Math.log2(0.0)); + Math.log2(1.0); }); }); -Mocha.describe("Belt_internalMapString.A.zip", () => { - Mocha.test("Belt_internalMapString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); +Mocha.describe("Math.max", () => { + Mocha.test("Math.max", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); }); }); -Mocha.describe("Belt_internalMapString.A.map", () => { - Mocha.test("Belt_internalMapString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); +Mocha.describe("Math.maxMany", () => { + Mocha.test("Math.maxMany", () => { + Math.max(1.0, 2.0); + Math.max(-1.0, -2.0); + isFinite(Math.max()); }); }); -Mocha.describe("Belt_internalMapString.A.cmp", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Math.min", () => { + Mocha.test("Math.min", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + }); +}); + +Mocha.describe("Math.minMany", () => { + Mocha.test("Math.minMany", () => { + Math.min(1.0, 2.0); + Math.min(-1.0, -2.0); + isFinite(Math.min()); }); }); -Mocha.describe("Belt_internalMapInt.A.length", () => { - Mocha.test("Belt_internalMapInt.A.length", () => {}); +Mocha.describe("Math.pow", () => { + Mocha.test("Math.pow", () => { + Math.pow(2.0, 4.0); + Math.pow(3.0, 4.0); + }); }); -Mocha.describe("Belt_internalMapInt.A.makeBy", () => { - Mocha.test("Belt_internalMapInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("Math.random", () => { + Mocha.test("Math.random", () => { + Math.random(); }); }); -Mocha.describe("Belt_internalMapInt.A.concat", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.round", () => { + Mocha.test("Math.round", () => { + Math.round(-20.5); + Math.round(-0.1); + Math.round(0.0); + Math.round(-0.0); }); }); -Mocha.describe("Belt_internalMapInt.A.reduce", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.sign", () => { + Mocha.test("Math.sign", () => { + Math.sign(3.0); + Math.sign(-3.0); + Math.sign(0.0); }); }); -Mocha.describe("Belt_internalMapInt.A.every2", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Math.sin", () => { + Mocha.test("Math.sin", () => { + Math.sin(-0.0); + Math.sin(0.0); + Math.sin(1.0); }); }); -Mocha.describe("Belt_internalSetInt.A.length", () => { - Mocha.test("Belt_internalSetInt.A.length", () => {}); +Mocha.describe("Math.sinh", () => { + Mocha.test("Math.sinh", () => { + Math.sinh(-0.0); + Math.sinh(0.0); + Math.sinh(1.0); + }); }); -Mocha.describe("Belt_internalSetInt.A.makeBy", () => { - Mocha.test("Belt_internalSetInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("Math.sqrt", () => { + Mocha.test("Math.sqrt", () => { + isNaN(Math.sqrt(-1.0)); + Math.sqrt(-0.0); + Math.sqrt(0.0); + Math.sqrt(1.0); + Math.sqrt(9.0); }); }); -Mocha.describe("Belt_internalSetInt.A.concat", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.tan", () => { + Mocha.test("Math.tan", () => { + Math.tan(-0.0); + Math.tan(0.0); + Math.tan(1.0); }); }); -Mocha.describe("Belt_internalSetInt.A.reduce", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.tanh", () => { + Mocha.test("Math.tanh", () => { + Math.tanh(-0.0); + Math.tanh(0.0); + Math.tanh(1.0); }); }); -Mocha.describe("Belt_internalSetInt.A.every2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Math.trunc", () => { + Mocha.test("Math.trunc", () => { + Math.trunc(0.123); + Math.trunc(1.999); + Math.trunc(13.37); + Math.trunc(42.84); }); }); -Mocha.describe("Belt_MutableSet.minUndefined", () => { - Mocha.test("Belt_MutableSet.minUndefined", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp +Mocha.describe("Null.asNullable", () => { + Mocha.test("Null.asNullable", () => {}); +}); + +Mocha.describe("Null.flatMap", () => { + Mocha.test("Null.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } else { + return null; + } + }; + Null.flatMap(2, addIfAboveOne); + Null.flatMap(-4, addIfAboveOne); + Null.flatMap(null, addIfAboveOne); + }); +}); + +Mocha.describe("Null.forEach", () => { + Mocha.test("Null.forEach", () => { + Null.forEach("thing", x => { + console.log(x); }); - let s0 = Belt_MutableSet.make(IntCmp); - let s1 = Belt_MutableSet.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Belt_MutableSet.minUndefined(s0); - Belt_MutableSet.minUndefined(s1); + Null.forEach(null, x => { + console.log(x); + }); + }); +}); + +Mocha.describe("Null.fromOption", () => { + Mocha.test("Null.fromOption", () => { + let asNull = Null.fromOption(undefined); + console.log(asNull === null); }); }); -Mocha.describe("Belt_MutableSet.maxUndefined", () => { - Mocha.test("Belt_MutableSet.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.describe("Null.getExn", () => { + Mocha.test("Null.getExn", () => { + Pervasives.assertEqual(Null.getExn(3), 3); + let exit = 0; + let value; + try { + value = 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", + 15731, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "ReScript"); + } + let exit$1 = 0; + let val; + try { + val = 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", + 15737, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt.Array.makeUninitialized", () => { - Mocha.test("Belt.Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Null.getOr", () => { + Mocha.test("Null.getOr", () => { + Null.getOr(null, "Banana"); + Null.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNull("Jane")); + greet(undefined); }); }); -Mocha.describe("Belt.MutableSet.minUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("Null.getUnsafe", () => { + Mocha.test("Null.getUnsafe", () => {}); }); -Mocha.describe("Belt.MutableSet.maxUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("Null.make", () => { + Mocha.test("Null.make", () => {}); +}); + +Mocha.describe("Null.map", () => { + Mocha.test("Null.map", () => { + Null.map(3, x => Math.imul(x, x)); + Null.map(null, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt_Array.makeUninitialized", () => { - Mocha.test("Belt_Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("Null.mapOr", () => { + Mocha.test("Null.mapOr", () => { + Null.mapOr(3, 0, x => x + 5 | 0); + Null.mapOr(null, 0, x => x + 5 | 0); }); }); -Mocha.describe("String.unsafeReplaceRegExpBy0", () => { - Mocha.test("String.unsafeReplaceRegExpBy0", () => { - let re = /[aeiou]/g; - let matchFn = (match, param, param$1) => match.toUpperCase(); - "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; +Mocha.describe("Null.null", () => { + Mocha.test("Null.null", () => { + console.log(null); }); }); -Mocha.describe("String.unsafeReplaceRegExpBy1", () => { - Mocha.test("String.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.describe("Null.toOption", () => { + Mocha.test("Null.toOption", () => { + let nullStr = "Hello"; + if (nullStr !== null) { + console.log("Got string:", nullStr); + } else { + console.log("Didn't have a value."); + } }); }); -Mocha.describe("String.unsafeReplaceRegExpBy2", () => { - Mocha.test("String.unsafeReplaceRegExpBy2", () => { - let re = /(\d+) times (\d+)/; - let matchFn = (param, group1, group2, param$1, param$2) => { - let match = Int.fromString(group1, undefined); - let match$1 = Int.fromString(group2, undefined); - if (match !== undefined && match$1 !== undefined) { - return Math.imul(match, match$1).toString(); +Mocha.describe("Nullable.flatMap", () => { + Mocha.test("Nullable.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; } else { - return "???"; + return null; } }; - "7 times 6".replace(re, matchFn) === "42"; + Nullable.flatMap(2, addIfAboveOne); + Nullable.flatMap(-4, addIfAboveOne); + Nullable.flatMap(null, addIfAboveOne); }); }); -Mocha.describe("Pervasives.encodeURIComponent", () => { - Mocha.test("Pervasives.encodeURIComponent", () => { - console.log(encodeURIComponent("array=[someValue]")); +Mocha.describe("Nullable.forEach", () => { + Mocha.test("Nullable.forEach", () => { + Nullable.forEach("thing", x => { + console.log(x); + }); + Nullable.forEach(null, x => { + console.log(x); + }); + Nullable.forEach(undefined, x => { + console.log(x); + }); }); }); -Mocha.describe("Pervasives.decodeURIComponent", () => { - Mocha.test("Pervasives.decodeURIComponent", () => { - console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); +Mocha.describe("Nullable.fromOption", () => { + Mocha.test("Nullable.fromOption", () => { + Nullable.fromOption("Hello"); }); }); -Mocha.describe("JSON.stringifyAnyWithReplacer", () => { - Mocha.test("JSON.stringifyAnyWithReplacer", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(() => "hello world"), undefined); +Mocha.describe("Nullable.getExn", () => { + Mocha.test("Nullable.getExn", () => { let exit = 0; + let value; + try { + value = 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", + 15869, + 35 + ], + Error: new Error() + }; + } + throw exn; + } + if (exit === 1) { + Pervasives.assertEqual(value, "Hello"); + } + let exit$1 = 0; let val; try { - val = JSON.stringify(BigInt(0)); - exit = 1; - } catch (exn) { + val = 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", + 15875, + 7 + ], + Error: new Error() + }; + } + let exit$2 = 0; + let val$1; + try { + val$1 = 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 === 1) { + if (exit$2 === 1) { throw { RE_EXN_ID: "Assert_failure", _1: [ "generated_mocha_test.res", - 16160, + 15880, 7 ], Error: new Error() @@ -20197,2642 +21047,1792 @@ Mocha.describe("JSON.stringifyAnyWithReplacer", () => { }); }); -Mocha.describe("Date.toLocaleStringWithLocale", () => { - Mocha.test("Date.toLocaleStringWithLocale", () => { - console.log(new Date().toLocaleString("en-US")); +Mocha.describe("Nullable.getOr", () => { + Mocha.test("Nullable.getOr", () => { + Nullable.getOr(null, "Banana"); + Nullable.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet(Primitive_option.fromNullable("Jane")); + greet(undefined); }); }); -Mocha.describe("Belt_internalSetString.A.fill", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Nullable.getUnsafe", () => { + Mocha.test("Nullable.getUnsafe", () => {}); +}); + +Mocha.describe("Nullable.isNullable", () => { + Mocha.test("Nullable.isNullable", () => { + if ("Hello" == null) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 15924, + 10 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalSetString.A.blit", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Nullable.make", () => { + Mocha.test("Nullable.make", () => { + let myStr = "Hello"; + if ((myStr == null) || myStr !== myStr) { + console.log("Values did not match."); + } else { + console.log("Yay, values matched!"); + } }); }); -Mocha.describe("Belt_internalSetString.A.some", () => { - Mocha.test("Belt_internalSetString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Nullable.map", () => { + Mocha.test("Nullable.map", () => { + Nullable.map(3, x => Math.imul(x, x)); + Nullable.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt_internalMapString.A.fill", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Nullable.mapOr", () => { + Mocha.test("Nullable.mapOr", () => { + Nullable.mapOr(3, 0, x => x + 5 | 0); + Nullable.mapOr(null, 0, x => x + 5 | 0); }); }); -Mocha.describe("Belt_internalMapString.A.blit", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Nullable.null", () => { + Mocha.test("Nullable.null", () => { + console.log(null); + }); +}); + +Mocha.describe("Nullable.toOption", () => { + Mocha.test("Nullable.toOption", () => { + let nullableString = "Hello"; + if (nullableString == null) { + console.log("Didn't have a value."); + } else { + console.log("Got string:", nullableString); + } + }); +}); + +Mocha.describe("Nullable.undefined", () => { + Mocha.test("Nullable.undefined", () => { + console.log(undefined); + }); +}); + +Mocha.describe("Object.assign", () => { + Mocha.test("Object.assign", () => { + Object.assign({ + a: 1 + }, { + a: 2 + }); + Object.assign({ + a: 1, + b: 2 + }, { + a: 0 + }); + Object.assign({ + a: 1 + }, { + a: null + }); + }); +}); + +Mocha.describe("Object.create", () => { + Mocha.test("Object.create", () => { + let x = { + fruit: "banana" + }; + Object.create(x); + }); +}); + +Mocha.describe("Object.freeze", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16039, + 7 + ], + Error: new Error() + }; + } + + } }); }); -Mocha.describe("Belt_internalMapString.A.some", () => { - Mocha.test("Belt_internalMapString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; +Mocha.describe("Object.get", () => { + Mocha.test("Object.get", () => { + Option.isSome(({ + a: 1 + })["toString"]); }); }); -Mocha.describe("Belt_internalMapInt.A.reverse", () => { - Mocha.test("Belt_internalMapInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Object.getSymbol", () => { + Mocha.test("Object.getSymbol", () => { + let fruit = Symbol("fruit"); + let x = {}; + x[fruit] = "banana"; }); }); -Mocha.describe("Belt_internalMapInt.A.rangeBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Object.hasOwnProperty", () => { + Mocha.test("Object.hasOwnProperty", () => { + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "a"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "b"); + Object.prototype.hasOwnProperty.call({ + a: 1 + }, "toString"); }); }); -Mocha.describe("Belt_internalMapInt.A.forEach", () => { - Mocha.test("Belt_internalMapInt.A.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); +Mocha.describe("Object.is", () => { + Mocha.test("Object.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 + } }); - let total = { - contents: 0 - }; - Belt_Array.forEach([ + Object.is([ 1, 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.flatMap", () => { - Mocha.test("Belt_internalMapInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ + 3 + ], [ 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 + 2, + 3 ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.keepMap", () => { - Mocha.test("Belt_internalMapInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ + Primitive_object.equal([ + 1, + 2, + 3 + ], [ 1, 2, 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reverse", () => { - Mocha.test("Belt_internalSetInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 ]); + let fruit = { + name: "Apple" + }; + Object.is(fruit, fruit); + Object.is(fruit, { + name: "Apple" + }); + Primitive_object.equal(fruit, { + name: "Apple" + }); }); }); -Mocha.describe("Belt_internalSetInt.A.rangeBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Object.isExtensible", () => { + Mocha.test("Object.isExtensible", () => { + let obj = { + a: 1 + }; + Object.isExtensible(obj); + Object.preventExtensions(obj); + Object.isExtensible(obj); }); }); -Mocha.describe("Belt_internalSetInt.A.forEach", () => { - Mocha.test("Belt_internalSetInt.A.forEach", () => { - Belt_Array.forEach([ - "a", - "b", - "c" - ], x => { - console.log("Item: " + x); +Mocha.describe("Object.isFrozen", () => { + Mocha.test("Object.isFrozen", () => { + let point = Object.freeze({ + x: 1, + y: 3 }); - let total = { - contents: 0 + Object.isFrozen(point); + let fruit = { + name: "Apple" }; - Belt_Array.forEach([ - 1, - 2, - 3, - 4 - ], x => { - total.contents = total.contents + x | 0; - }); + Object.isFrozen(fruit); }); }); -Mocha.describe("Belt_internalSetInt.A.flatMap", () => { - Mocha.test("Belt_internalSetInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("Object.isSealed", () => { + Mocha.test("Object.isSealed", () => { + let point = Object.seal({ + x: 1, + y: 3 + }); + Object.isSealed(point); + let fruit = { + name: "Apple" + }; + Object.isSealed(fruit); }); }); -Mocha.describe("Belt_internalSetInt.A.keepMap", () => { - Mocha.test("Belt_internalSetInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("Object.keysToArray", () => { + Mocha.test("Object.keysToArray", () => { + Object.keys({ + a: 1, + b: 2 + }); + Object.keys({ + a: undefined + }); + Object.keys({}); }); }); -Mocha.describe("Belt_SortArray.binarySearchBy", () => { - Mocha.test("Belt_SortArray.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.describe("Object.make", () => { + Mocha.test("Object.make", () => { + let x = {}; + Object.keys(x).length; + Option.isSome(x["toString"]); }); }); -Mocha.describe("Belt.SortArray.binarySearchBy", () => { - Mocha.test("Belt.SortArray.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.describe("Object.preventExtensions", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16175, + 7 + ], + Error: new Error() + }; + } + + } }); }); -Mocha.describe("Int.toExponentialWithPrecision", () => { - Mocha.test("Int.toExponentialWithPrecision", () => { - (77).toExponential(2); - (5678).toExponential(2); +Mocha.describe("Object.seal", () => { + Mocha.test("Object.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 !== Exn.$$Error) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16193, + 7 + ], + Error: new Error() + }; + } + + } + point["x"] = 13; }); }); -Mocha.describe("Float.toPrecisionWithPrecision", () => { - Mocha.test("Float.toPrecisionWithPrecision", () => { - (100.0).toPrecision(2); - (1.0).toPrecision(1); +Mocha.describe("Object.set", () => { + Mocha.test("Object.set", () => { + ({ + a: 1 + })["a"] = 2; + ({ + a: 1 + })["a"] = undefined; + ({ + a: 1 + })["b"] = 2; }); }); -Mocha.describe("Belt_internalSetString.A.range", () => { - Mocha.test("Belt_internalSetString.A.range", () => { - Primitive_object.equal(Belt_Array.range(0, 3), [ - 0, +Mocha.describe("Option.all", () => { + Mocha.test("Option.all", () => { + Option.all([ 1, 2, 3 ]); - Primitive_object.equal(Belt_Array.range(3, 0), []); - Primitive_object.equal(Belt_Array.range(3, 3), [3]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.zipBy", () => { - Mocha.test("Belt_internalSetString.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ + Option.all([ 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.unzip", () => { - Mocha.test("Belt_internalSetString.A.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 - ] + undefined ]); }); }); -Mocha.describe("Belt_internalSetString.A.slice", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Option.compare", () => { + Mocha.test("Option.compare", () => { + let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); + Option.compare(3, 15, clockCompare); + Option.compare(3, 14, clockCompare); + Option.compare(2, 15, clockCompare); + Option.compare(undefined, 15, clockCompare); + Option.compare(14, undefined, clockCompare); + Option.compare(undefined, undefined, clockCompare); }); }); -Mocha.describe("Belt_internalSetString.A.getBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Option.equal", () => { + Mocha.test("Option.equal", () => { + let clockEqual = (a, b) => a % 12 === b % 12; + Option.equal(3, 15, clockEqual); + Option.equal(3, undefined, clockEqual); + Option.equal(undefined, 3, clockEqual); + Option.equal(undefined, undefined, clockEqual); }); }); -Mocha.describe("Belt_internalSetString.A.every", () => { - Mocha.test("Belt_internalSetString.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Option.filter", () => { + Mocha.test("Option.filter", () => { + Option.filter(10, x => x > 5); + Option.filter(4, x => x > 5); + Option.filter(undefined, x => x > 5); }); }); -Mocha.describe("Belt_internalSetString.A.some2", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Option.flatMap", () => { + Mocha.test("Option.flatMap", () => { + let addIfAboveOne = value => { + if (value > 1) { + return value + 1 | 0; + } + + }; + Option.flatMap(2, addIfAboveOne); + Option.flatMap(-4, addIfAboveOne); + Option.flatMap(undefined, addIfAboveOne); }); }); -Mocha.describe("Belt_internalMapString.A.range", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Option.forEach", () => { + Mocha.test("Option.forEach", () => { + Option.forEach("thing", x => { + console.log(x); + }); + Option.forEach(undefined, x => { + console.log(x); + }); }); }); -Mocha.describe("Belt_internalMapString.A.zipBy", () => { - Mocha.test("Belt_internalMapString.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); +Mocha.describe("Option.getExn", () => { + Mocha.test("Option.getExn", () => { + Pervasives.assertEqual(Option.getExn(3, undefined), 3); + let exit = 0; + let val; + try { + val = Option.getExn(undefined, undefined); + exit = 1; + } catch (exn) { + + } + if (exit === 1) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16301, + 7 + ], + Error: new Error() + }; + } + let exit$1 = 0; + let val$1; + try { + val$1 = 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", + 16306, + 7 + ], + Error: new Error() + }; + } + }); }); -Mocha.describe("Belt_internalMapString.A.unzip", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Option.getOr", () => { + Mocha.test("Option.getOr", () => { + Option.getOr(undefined, "Banana"); + Option.getOr("Apple", "Banana"); + let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); + greet("Jane"); + greet(undefined); }); }); -Mocha.describe("Belt_internalMapString.A.slice", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Option.getUnsafe", () => { + Mocha.test("Option.getUnsafe", () => {}); +}); + +Mocha.describe("Option.isNone", () => { + Mocha.test("Option.isNone", () => { + Option.isNone(undefined); + Option.isNone(1); + }); +}); + +Mocha.describe("Option.isSome", () => { + Mocha.test("Option.isSome", () => { + Option.isSome(undefined); + Option.isSome(1); }); }); -Mocha.describe("Belt_internalMapString.A.getBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Option.map", () => { + Mocha.test("Option.map", () => { + Option.map(3, x => Math.imul(x, x)); + Option.map(undefined, x => Math.imul(x, x)); }); }); -Mocha.describe("Belt_internalMapString.A.every", () => { - Mocha.test("Belt_internalMapString.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; +Mocha.describe("Option.mapOr", () => { + Mocha.test("Option.mapOr", () => { + Option.mapOr(3, 0, x => x + 5 | 0); + Option.mapOr(undefined, 0, x => x + 5 | 0); }); }); -Mocha.describe("Belt_internalMapString.A.some2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Option.orElse", () => { + Mocha.test("Option.orElse", () => { + Primitive_object.equal(Option.orElse(1812, 1066), 1812); + Primitive_object.equal(Option.orElse(undefined, 1066), 1066); + Option.orElse(undefined, undefined) === undefined; }); }); -Mocha.describe("Belt_internalMapInt.A.joinWith", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Pervasives.assertEqual", () => { + Mocha.test("Pervasives.assertEqual", () => { + Pervasives.assertEqual(List.tailExn({ + hd: 1, + tl: { + hd: 2, + tl: /* [] */0 + } + }), { + hd: 2, + tl: /* [] */0 + }); }); }); -Mocha.describe("Belt_internalSetInt.A.joinWith", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Pervasives.clearInterval", () => { + Mocha.test("Pervasives.clearInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints in 100 ms"); + }, 100); + setTimeout(() => { + clearInterval(intervalId); + }, 500); }); }); -Mocha.describe("Belt_internalSetString.A.length", () => { - Mocha.test("Belt_internalSetString.A.length", () => {}); +Mocha.describe("Pervasives.clearTimeout", () => { + Mocha.test("Pervasives.clearTimeout", () => { + let timeoutId = setTimeout(() => { + console.log("This prints in 2 seconds."); + }, 2000); + clearTimeout(timeoutId); + }); }); -Mocha.describe("Belt_internalSetString.A.makeBy", () => { - Mocha.test("Belt_internalSetString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("Pervasives.decodeURI", () => { + Mocha.test("Pervasives.decodeURI", () => { + console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); }); }); -Mocha.describe("Belt_internalSetString.A.concat", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Pervasives.decodeURIComponent", () => { + Mocha.test("Pervasives.decodeURIComponent", () => { + console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); }); }); -Mocha.describe("Belt_internalSetString.A.reduce", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Pervasives.encodeURI", () => { + Mocha.test("Pervasives.encodeURI", () => { + console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); }); }); -Mocha.describe("Belt_internalSetString.A.every2", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Pervasives.encodeURIComponent", () => { + Mocha.test("Pervasives.encodeURIComponent", () => { + console.log(encodeURIComponent("array=[someValue]")); }); }); -Mocha.describe("Belt_internalMapString.A.length", () => { - Mocha.test("Belt_internalMapString.A.length", () => {}); +Mocha.describe("Pervasives.import", () => { + Mocha.test("Pervasives.import", () => {}); }); -Mocha.describe("Belt_internalMapString.A.makeBy", () => { - Mocha.test("Belt_internalMapString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); +Mocha.describe("Pervasives.setInterval", () => { + Mocha.test("Pervasives.setInterval", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms."); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500); }); }); -Mocha.describe("Belt_internalMapString.A.concat", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.setIntervalFloat", () => { + Mocha.test("Pervasives.setIntervalFloat", () => { + let intervalId = setInterval(() => { + console.log("This prints every 200 ms"); + }, 200); + setTimeout(() => { + clearInterval(intervalId); + }, 500.0); + }); +}); + +Mocha.describe("Pervasives.setTimeout", () => { + Mocha.test("Pervasives.setTimeout", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); }); }); -Mocha.describe("Belt_internalMapString.A.reduce", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Pervasives.setTimeoutFloat", () => { + Mocha.test("Pervasives.setTimeoutFloat", () => { + setTimeout(() => { + console.log("This prints in 200 ms."); + }, 200); }); }); -Mocha.describe("Belt_internalMapString.A.every2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Promise.all", () => { + Mocha.test("Promise.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.describe("Belt_internalMapInt.A.partition", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Promise.allSettled", () => { + Mocha.test("Promise.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.describe("Belt_internalSetInt.A.partition", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Promise.any", () => { + Mocha.test("Promise.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.describe("Belt.HashMap.getBucketHistogram", () => { - Mocha.test("Belt.HashMap.getBucketHistogram", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Promise.catch", () => { + Mocha.test("Promise.catch", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + $$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 === 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); }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.getBucketHistogram(hMap); }); }); -Mocha.describe("Belt_HashMap.getBucketHistogram", () => { - Mocha.test("Belt_HashMap.getBucketHistogram", () => { - let hash = a => a; - let eq = Primitive_object.equal; - let IntHash = Belt_Id.MakeHashable({ - hash: hash, - eq: eq +Mocha.describe("Promise.finally", () => { + Mocha.test("Promise.finally", () => { + let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); + let isDone = { + contents: false + }; + $$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.describe("Promise.make", () => { + Mocha.test("Promise.make", () => { + $$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.describe("Promise.race", () => { + Mocha.test("Promise.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(); }); - let hMap = Belt_HashMap.make(10, IntHash); - Belt_HashMap.set(hMap, 1, "1"); - Belt_HashMap.getBucketHistogram(hMap); }); }); -Mocha.describe("Float.toExponentialWithPrecision", () => { - Mocha.test("Float.toExponentialWithPrecision", () => { - (77.0).toExponential(2); - (5678.0).toExponential(2); +Mocha.describe("Promise.reject", () => { + Mocha.test("Promise.reject", () => { + let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); + $$Promise.$$catch(Promise.reject({ + RE_EXN_ID: TestError, + _1: "some rejected value" + }), v => { + if (v.RE_EXN_ID === TestError) { + Pervasives.assertEqual(v._1, "some rejected value"); + } else { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 16752, + 9 + ], + Error: new Error() + }; + } + return Promise.resolve(); + }); }); }); -Mocha.describe("Float.Constants.positiveInfinity", () => { - Mocha.test("Float.Constants.positiveInfinity", () => {}); +Mocha.describe("Promise.resolve", () => { + Mocha.test("Promise.resolve", () => { + Promise.resolve(5); + }); }); -Mocha.describe("Float.Constants.negativeInfinity", () => { - Mocha.test("Float.Constants.negativeInfinity", () => {}); +Mocha.describe("Promise.then", () => { + Mocha.test("Promise.then", () => { + Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { + console.log("Your lucky number is: ", num); + return Promise.resolve(); + }); + }); }); -Mocha.describe("Belt_internalSetString.A.reverse", () => { - Mocha.test("Belt_internalSetString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("Promise.thenResolve", () => { + Mocha.test("Promise.thenResolve", () => { + Promise.resolve("Anna").then(str => "Hello " + str).then(str => { + console.log(str); + }); }); }); -Mocha.describe("Belt_internalSetString.A.rangeBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("RegExp.Result.fullMatch", () => { + Mocha.test("RegExp.Result.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.describe("Belt_internalSetString.A.forEach", () => { - Mocha.test("Belt_internalSetString.A.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.describe("RegExp.Result.input", () => { + Mocha.test("RegExp.Result.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.describe("Belt_internalSetString.A.flatMap", () => { - Mocha.test("Belt_internalSetString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("RegExp.Result.matches", () => { + Mocha.test("RegExp.Result.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("Belt_internalSetString.A.keepMap", () => { - Mocha.test("Belt_internalSetString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("RegExp.exec", () => { + Mocha.test("RegExp.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.describe("Belt_internalMapString.A.reverse", () => { - Mocha.test("Belt_internalMapString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("RegExp.fromString", () => { + Mocha.test("RegExp.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.describe("Belt_internalMapString.A.rangeBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("RegExp.fromStringWithFlags", () => { + Mocha.test("RegExp.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.describe("Belt_internalMapString.A.forEach", () => { - Mocha.test("Belt_internalMapString.A.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.describe("RegExp.global", () => { + Mocha.test("RegExp.global", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.global); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.global); }); }); -Mocha.describe("Belt_internalMapString.A.flatMap", () => { - Mocha.test("Belt_internalMapString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); +Mocha.describe("RegExp.ignoreCase", () => { + Mocha.test("RegExp.ignoreCase", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.ignoreCase); + let regexp2 = new RegExp("\\w+", "i"); + console.log(regexp2.ignoreCase); }); }); -Mocha.describe("Belt_internalMapString.A.keepMap", () => { - Mocha.test("Belt_internalMapString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); +Mocha.describe("RegExp.lastIndex", () => { + Mocha.test("RegExp.lastIndex", () => { + let regexp = new RegExp("\\w+"); + console.log(regexp.lastIndex); + regexp.exec("Many words here."); + console.log(regexp.lastIndex); }); }); -Mocha.describe("Belt_internalMapInt.A.concatMany", () => { - Mocha.test("Belt_internalMapInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("RegExp.multiline", () => { + Mocha.test("RegExp.multiline", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.multiline); + let regexp2 = new RegExp("\\w+", "mi"); + console.log(regexp2.multiline); }); }); -Mocha.describe("Belt_internalMapInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("RegExp.setLastIndex", () => { + Mocha.test("RegExp.setLastIndex", () => { + let regexp = new RegExp("\\w+"); + regexp.lastIndex = 4; + regexp.exec("Many words here."); + console.log(regexp.lastIndex); }); }); -Mocha.describe("Belt_internalMapInt.A.getIndexBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("RegExp.source", () => { + Mocha.test("RegExp.source", () => { + let regexp = new RegExp("\\w+", "g"); + console.log(regexp.source); }); }); -Mocha.describe("Belt_internalSetInt.A.concatMany", () => { - Mocha.test("Belt_internalSetInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("RegExp.sticky", () => { + Mocha.test("RegExp.sticky", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "my"); + console.log(regexp2.unicode); }); }); -Mocha.describe("Belt_internalSetInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetInt.A.sliceToEnd", () => { - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], 2), [ - 12, - 13, - 14, - 15, - 16 +Mocha.describe("RegExp.test", () => { + Mocha.test("RegExp.test", () => { + let regexp = new RegExp("\\w+"); + if (regexp.test("ReScript is cool!")) { + console.log("Yay, there's a word in there."); + } + + }); +}); + +Mocha.describe("RegExp.unicode", () => { + Mocha.test("RegExp.unicode", () => { + let regexp1 = new RegExp("\\w+", "g"); + console.log(regexp1.unicode); + let regexp2 = new RegExp("\\w+", "mu"); + console.log(regexp2.unicode); + }); +}); + +Mocha.describe("Result.all", () => { + Mocha.test("Result.all", () => { + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Ok", + _0: 2 + }, + { + TAG: "Ok", + _0: 3 + } ]); - Primitive_object.equal(Belt_Array.sliceToEnd([ - 10, - 11, - 12, - 13, - 14, - 15, - 16 - ], -4), [ - 13, - 14, - 15, - 16 + Result.all([ + { + TAG: "Ok", + _0: 1 + }, + { + TAG: "Error", + _0: 1 + } ]); }); }); -Mocha.describe("Belt_internalSetInt.A.getIndexBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Result.compare", () => { + Mocha.test("Result.compare", () => { + let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === 1; + Result.compare({ + TAG: "Ok", + _0: 57 + }, { + TAG: "Ok", + _0: 39 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Ok", + _0: 39 + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Ok", + _0: 57 + }, mod10cmp) === -1; + Result.compare({ + TAG: "Error", + _0: "x" + }, { + TAG: "Error", + _0: "y" + }, mod10cmp) === 0; }); }); -Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyWithFilterAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ], 2); +Mocha.describe("Result.equal", () => { + Mocha.test("Result.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; + Result.equal(good1, good2, mod10equal) === true; + Result.equal(good1, bad1, mod10equal) === false; + Result.equal(bad2, good2, mod10equal) === false; + Result.equal(bad1, bad2, mod10equal) === true; }); }); -Mocha.describe("Date.toLocaleDateStringWithLocale", () => { - Mocha.test("Date.toLocaleDateStringWithLocale", () => { - console.log(new Date().toLocaleDateString("en-US")); +Mocha.describe("Result.flatMap", () => { + Mocha.test("Result.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(Result.flatMap({ + TAG: "Ok", + _0: 2.0 + }, recip), { + TAG: "Ok", + _0: 0.5 + }); + Primitive_object.equal(Result.flatMap({ + TAG: "Ok", + _0: 0.0 + }, recip), { + TAG: "Error", + _0: "Divide by zero" + }); + Primitive_object.equal(Result.flatMap({ + TAG: "Error", + _0: "Already bad" + }, recip), { + TAG: "Error", + _0: "Already bad" + }); }); }); -Mocha.describe("Date.toLocaleTimeStringWithLocale", () => { - Mocha.test("Date.toLocaleTimeStringWithLocale", () => { - console.log(new Date().toLocaleTimeString("en-US")); +Mocha.describe("Result.forEach", () => { + Mocha.test("Result.forEach", () => { + Result.forEach({ + TAG: "Ok", + _0: 3 + }, prim => { + console.log(prim); + }); + Result.forEach({ + TAG: "Error", + _0: "x" + }, prim => { + console.log(prim); + }); }); }); -Mocha.describe("Belt_internalSetString.A.joinWith", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Result.getOr", () => { + Mocha.test("Result.getOr", () => { + Result.getOr({ + TAG: "Ok", + _0: 42 + }, 0) === 42; + Result.getOr({ + TAG: "Error", + _0: "Invalid Data" + }, 0) === 0; }); }); -Mocha.describe("Belt_internalMapString.A.joinWith", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Result.map", () => { + Mocha.test("Result.map", () => { + let f = x => Math.sqrt(x); + Primitive_object.equal(Result.map({ + TAG: "Ok", + _0: 64 + }, f), { + TAG: "Ok", + _0: 8.0 + }); + Primitive_object.equal(Result.map({ + TAG: "Error", + _0: "Invalid data" + }, f), { + TAG: "Error", + _0: "Invalid data" + }); }); }); -Mocha.describe("Belt.Array.truncateToLengthUnsafe", () => { - Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("Result.mapError", () => { + Mocha.test("Result.mapError", () => { + let format = n => "Error code: " + n.toString(); + Result.mapError({ + TAG: "Error", + _0: 14 + }, format); + Result.mapError({ + TAG: "Ok", + _0: "abc" + }, format); }); }); -Mocha.describe("Belt_Array.truncateToLengthUnsafe", () => { - Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("Result.mapOr", () => { + Mocha.test("Result.mapOr", () => { + Result.mapOr({ + TAG: "Ok", + _0: 42 + }, 0, x => x / 2 | 0) === 21; + Result.mapOr({ + TAG: "Error", + _0: "Invalid data" + }, 0, x => x / 2 | 0) === 0; }); }); - -Mocha.describe("Belt_internalSetString.A.partition", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Set.add", () => { + Mocha.test("Set.add", () => { + let set = new Set(); + set.add("someValue"); }); }); -Mocha.describe("Belt_internalMapString.A.partition", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Set.clear", () => { + Mocha.test("Set.clear", () => { + let set = new Set(); + set.add("someKey"); + set.clear(); }); }); -Mocha.describe("Belt_internalMapInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Set.delete", () => { + Mocha.test("Set.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.describe("Belt_internalSetInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("Set.forEach", () => { + Mocha.test("Set.forEach", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue2"); + set.forEach(value => { + console.log(value); + }); }); }); -Mocha.describe("Belt.Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt.Array.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.describe("Set.fromArray", () => { + Mocha.test("Set.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.describe("Belt_Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt_Array.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.describe("Set.fromIterator", () => { + Mocha.test("Set.fromIterator", () => { + let iterator = ((() => { + var array1 = ['a', 'b', 'c']; + var iterator1 = array1[Symbol.iterator](); + return iterator1 + })()); + Pervasives.assertEqual(new Set(iterator).size, 3); }); }); -Mocha.describe("JSON.stringifyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer, 2); +Mocha.describe("Set.has", () => { + Mocha.test("Set.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.describe("Belt_internalSetString.A.concatMany", () => { - Mocha.test("Belt_internalSetString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("Set.make", () => { + Mocha.test("Set.make", () => { + new Set(); + let set = new Set(); + set.add("Fine name"); }); }); -Mocha.describe("Belt_internalSetString.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Set.size", () => { + Mocha.test("Set.size", () => { + let set = new Set(); + set.add("someValue"); + set.add("someValue"); + set.add("someValue2"); + }); +}); + +Mocha.describe("Set.toArray", () => { + Mocha.test("Set.toArray", () => { + let set = new Set([ + "apple", + "orange", + "apple", + "banana" ]); + Array.from(set); }); }); -Mocha.describe("Belt_internalSetString.A.getIndexBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Set.values", () => { + Mocha.test("Set.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("String.charAt", () => { + Mocha.test("String.charAt", () => { + "ReScript".charAt(0) === "R"; + "Hello".charAt(12) === ""; + "JS".charAt(5) === ""; }); }); -Mocha.describe("Belt_internalMapString.A.concatMany", () => { - Mocha.test("Belt_internalMapString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); +Mocha.describe("String.charCodeAt", () => { + Mocha.test("String.charCodeAt", () => { + "😺".charCodeAt(0) === 55357; + Primitive_object.equal("😺".codePointAt(0), 128570); }); }); -Mocha.describe("Belt_internalMapString.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapString.A.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.describe("String.codePointAt", () => { + Mocha.test("String.codePointAt", () => { + Primitive_object.equal("¿😺?".codePointAt(1), 128570); + "abc".codePointAt(5) === undefined; }); }); -Mocha.describe("Belt_internalMapString.A.getIndexBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("String.concat", () => { + Mocha.test("String.concat", () => { + "cow".concat("bell") === "cowbell"; + "Re".concat("Script") === "ReScript"; }); }); -Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("String.concatMany", () => { + Mocha.test("String.concatMany", () => { + "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; }); }); -Mocha.describe("Belt_internalMapInt.A.reduceReverse", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("String.endsWith", () => { + Mocha.test("String.endsWith", () => { + "BuckleScript".endsWith("Script") === true; + "BuckleShoes".endsWith("Script") === false; }); }); -Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); +Mocha.describe("String.endsWithFrom", () => { + Mocha.test("String.endsWithFrom", () => { + "abcd".endsWith("cd", 4) === true; + "abcde".endsWith("cd", 3) === false; + "abcde".endsWith("cde", 99) === true; + "example.dat".endsWith("ple", 7) === true; }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("String.fromCharCode", () => { + Mocha.test("String.fromCharCode", () => { + String.fromCharCode(65) === "A"; + String.fromCharCode(968) === "ψ"; + String.fromCharCode(54620) === "한"; + String.fromCharCode(-64568) === "ψ"; }); }); -Mocha.describe("Belt_SortArray.strictlySortedLength", () => { - Mocha.test("Belt_SortArray.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("String.fromCharCodeMany", () => { + Mocha.test("String.fromCharCodeMany", () => { + String.fromCharCode(189, 43, 190, 61) === "½+¾="; + String.fromCharCode(65, 66, 67) === "ABC"; }); }); -Mocha.describe("Belt.SortArray.strictlySortedLength", () => { - Mocha.test("Belt.SortArray.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("String.fromCodePoint", () => { + Mocha.test("String.fromCodePoint", () => { + String.fromCodePoint(65) === "A"; + String.fromCodePoint(968) === "ψ"; + String.fromCodePoint(54620) === "한"; + String.fromCodePoint(128570) === "😺"; }); }); -Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 17399, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("String.fromCodePointMany", () => { + Mocha.test("String.fromCodePointMany", () => { + String.fromCodePoint(54620, 44544, 128570) === "한글😺"; }); }); -Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("String.get", () => { + Mocha.test("String.get", () => { + Primitive_object.equal("ReScript"[0], "R"); + Primitive_object.equal("Hello"[4], "o"); }); }); -Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); +Mocha.describe("String.getUnsafe", () => { + Mocha.test("String.getUnsafe", () => {}); }); -Mocha.describe("Belt_internalMapInt.S.binarySearchBy", () => { - Mocha.test("Belt_internalMapInt.S.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.describe("String.includes", () => { + Mocha.test("String.includes", () => { + "programmer".includes("gram") === true; + "programmer".includes("er") === true; + "programmer".includes("pro") === true; + "programmer.dat".includes("xyz") === false; }); }); -Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("String.includesFrom", () => { + Mocha.test("String.includesFrom", () => { + "programmer".includes("gram", 1) === true; + "programmer".includes("gram", 4) === false; + "대한민국".includes("한", 1) === true; }); }); -Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("String.indexOf", () => { + Mocha.test("String.indexOf", () => { + "bookseller".indexOf("ok") === 2; + "bookseller".indexOf("sell") === 4; + "beekeeper".indexOf("ee") === 1; + "bookseller".indexOf("xyz") === -1; }); }); -Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("String.indexOfFrom", () => { + Mocha.test("String.indexOfFrom", () => { + "bookseller".indexOf("ok", 1) === 2; + "bookseller".indexOf("sell", 2) === 4; + "bookseller".indexOf("sell", 5) === -1; }); }); -Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); +Mocha.describe("String.indexOfOpt", () => { + Mocha.test("String.indexOfOpt", () => { + Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); + $$String.indexOfOpt("bookseller", "xyz") === undefined; }); }); -Mocha.describe("Belt_internalMapInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("String.lastIndexOf", () => { + Mocha.test("String.lastIndexOf", () => { + "bookseller".lastIndexOf("ok") === 2; + "beekeeper".lastIndexOf("ee") === 4; + "abcdefg".lastIndexOf("xyz") === -1; }); }); -Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("String.lastIndexOfFrom", () => { + Mocha.test("String.lastIndexOfFrom", () => { + "bookseller".lastIndexOf("ok", 6) === 2; + "beekeeper".lastIndexOf("ee", 8) === 4; + "beekeeper".lastIndexOf("ee", 3) === 1; + "abcdefg".lastIndexOf("xyz", 4) === -1; }); }); -Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 17524, - 7 - ], - Error: new Error() - }; - } - +Mocha.describe("String.lastIndexOfOpt", () => { + Mocha.test("String.lastIndexOfOpt", () => { + Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); + Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); + $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; }); }); -Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); +Mocha.describe("String.length", () => { + Mocha.test("String.length", () => {}); }); -Mocha.describe("Belt_internalSetString.A.reduceReverse", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("String.localeCompare", () => { + Mocha.test("String.localeCompare", () => { + "a".localeCompare("c") < 0.0 === true; + "a".localeCompare("a") === 0.0; }); }); -Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ +Mocha.describe("String.make", () => { + Mocha.test("String.make", () => { + String(3.5) === "3.5"; + String([ 1, 2, 3 - ], (_x, i) => i === 1), [2]); + ]) === "1,2,3"; }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; +Mocha.describe("String.match", () => { + Mocha.test("String.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.describe("Belt_internalMapInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("String.normalize", () => { + Mocha.test("String.normalize", () => { + let string1 = "\u00F1"; + let string2 = "\u006E\u0303"; + if (string1 === string2) { + throw { + RE_EXN_ID: "Assert_failure", + _1: [ + "generated_mocha_test.res", + 17605, + 0 + ], + Error: new Error() + }; + } + Pervasives.assertEqual(string1.normalize(), string2.normalize()); }); }); -Mocha.describe("Belt_internalSetInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("String.normalizeForm", () => { + Mocha.test("String.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.describe("Date.toLocaleStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("String.padEnd", () => { + Mocha.test("String.padEnd", () => { + "Hello".padEnd(10, ".") === "Hello....."; + "abc".padEnd(1, "") === "abc"; }); }); -Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("String.padStart", () => { + Mocha.test("String.padStart", () => { + "abc".padStart(5, " ") === " abc"; + "abc".padStart(6, "123465") === "123abc"; }); }); -Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("String.repeat", () => { + Mocha.test("String.repeat", () => { + "ha".repeat(3) === "hahaha"; + "empty".repeat(0) === ""; }); }); -Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); +Mocha.describe("String.replace", () => { + Mocha.test("String.replace", () => { + "old string".replace("old", "new") === "new string"; + "the cat and the dog".replace("the", "this") === "this cat and the dog"; }); }); -Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; +Mocha.describe("String.replaceAll", () => { + Mocha.test("String.replaceAll", () => { + "old old string".replaceAll("old", "new") === "new new string"; + "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; }); }); -Mocha.describe("Belt_internalMapString.S.binarySearchBy", () => { - Mocha.test("Belt_internalMapString.S.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.describe("String.replaceAllRegExp", () => { + Mocha.test("String.replaceAllRegExp", () => { + "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; }); }); -Mocha.describe("Belt_internalMapInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("String.replaceRegExp", () => { + Mocha.test("String.replaceRegExp", () => { + "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; + "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; }); }); -Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("String.search", () => { + Mocha.test("String.search", () => { + "testing 1 2 3".search(/\d+/) === 8; + "no numbers".search(/\d+/) === -1; }); }); -Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("String.searchOpt", () => { + Mocha.test("String.searchOpt", () => { + Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); + $$String.searchOpt("no numbers", /\d+/) === undefined; }); }); -Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; +Mocha.describe("String.slice", () => { + Mocha.test("String.slice", () => { + "abcdefg".slice(2, 5) === "cde"; + "abcdefg".slice(2, 9) === "cdefg"; + "abcdefg".slice(-4, -2) === "de"; + "abcdefg".slice(5, 1) === ""; }); }); -Mocha.describe("Belt_internalSetString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetString.A.forEachWithIndex", () => { - Belt_Array.forEachWithIndex([ +Mocha.describe("String.sliceToEnd", () => { + Mocha.test("String.sliceToEnd", () => { + "abcdefg".slice(4) === "efg"; + "abcdefg".slice(-2) === "fg"; + "abcdefg".slice(7) === ""; + }); +}); + +Mocha.describe("String.split", () => { + Mocha.test("String.split", () => { + Primitive_object.equal("2018-01-02".split("-"), [ + "2018", + "01", + "02" + ]); + Primitive_object.equal("a,b,,c".split(","), [ "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; - }); + ]); + 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.describe("String.splitAtMost", () => { + Mocha.test("String.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.describe("String.splitByRegExp", () => { + Mocha.test("String.splitByRegExp", () => { + Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ + "Jan", + "Feb", + "Mar" + ]); }); }); -Mocha.describe("Belt_internalMapString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapString.A.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.describe("String.splitByRegExpAtMost", () => { + Mocha.test("String.splitByRegExpAtMost", () => { + Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ + "Hello", + "World.", + "How" + ]); }); }); -Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("String.startsWith", () => { + Mocha.test("String.startsWith", () => { + "BuckleScript".startsWith("Buckle") === true; + "BuckleScript".startsWith("") === true; + "JavaScript".startsWith("Buckle") === false; }); }); -Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; +Mocha.describe("String.startsWithFrom", () => { + Mocha.test("String.startsWithFrom", () => { + "BuckleScript".startsWith("kle", 3) === true; + "BuckleScript".startsWith("", 3) === true; + "JavaScript".startsWith("Buckle", 2) === false; }); }); -Mocha.describe("Belt_internalMapInt.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapInt.S.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("String.substring", () => { + Mocha.test("String.substring", () => { + "playground".substring(3, 6) === "ygr"; + "playground".substring(6, 3) === "ygr"; + "playground".substring(4, 12) === "ground"; }); }); -Mocha.describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("String.substringToEnd", () => { + Mocha.test("String.substringToEnd", () => { + "playground".substring(4) === "ground"; + "playground".substring(-3) === "playground"; + "playground".substring(12) === ""; }); }); -Mocha.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleTimeString("en-US", { - timeStyle: "long" - })); - console.log(new Date().toLocaleTimeString("de", { - hour: "2-digit", - minute: "2-digit" - })); +Mocha.describe("String.toLowerCase", () => { + Mocha.test("String.toLowerCase", () => { + "ABC".toLowerCase() === "abc"; + "ΣΠ".toLowerCase() === "σπ"; + "ΠΣ".toLowerCase() === "πς"; }); }); -Mocha.describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("String.toUpperCase", () => { + Mocha.test("String.toUpperCase", () => { + "abc".toUpperCase() === "ABC"; + "Straße".toUpperCase() === "STRASSE"; + "πς".toUpperCase() === "ΠΣ"; }); }); -Mocha.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("String.trim", () => { + Mocha.test("String.trim", () => { + " abc def ".trim() === "abc def"; + "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; }); }); -Mocha.describe("Belt_internalMapString.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapString.S.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("String.trimEnd", () => { + Mocha.test("String.trimEnd", () => { + " Hello world! ".trimEnd() === " Hello world!"; + " Hello world! ".trimEnd() === " Hello world!"; }); }); -Mocha.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("String.trimStart", () => { + Mocha.test("String.trimStart", () => { + " Hello world! ".trimStart() === "Hello world! "; + " Hello world! ".trimStart() === "Hello world! "; }); }); -Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("String.unsafeReplaceRegExpBy0", () => { + Mocha.test("String.unsafeReplaceRegExpBy0", () => { + let re = /[aeiou]/g; + let matchFn = (match, param, param$1) => match.toUpperCase(); + "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; }); }); -Mocha.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("String.unsafeReplaceRegExpBy1", () => { + Mocha.test("String.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.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); +Mocha.describe("String.unsafeReplaceRegExpBy2", () => { + Mocha.test("String.unsafeReplaceRegExpBy2", () => { + let re = /(\d+) times (\d+)/; + let matchFn = (param, group1, group2, param$1, param$2) => { + let match = Int.fromString(group1, undefined); + let match$1 = Int.fromString(group2, undefined); + if (match !== undefined && match$1 !== undefined) { + return Math.imul(match, match$1).toString(); + } else { + return "???"; + } + }; + "7 times 6".replace(re, matchFn) === "42"; }); }); -Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Type.Classify.classify", () => { + Mocha.test("Type.Classify.classify", () => { + let match = 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("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Type.typeof", () => { + Mocha.test("Type.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..."); + } }); }); From 57138973f744e520efd438345bf4d548956948ee Mon Sep 17 00:00:00 2001 From: aspeddro Date: Fri, 27 Dec 2024 23:11:26 -0300 Subject: [PATCH 10/13] cleanup --- tests/docstrings_examples/Node.res | 30 -------------------------- tests/docstrings_examples/Node.res.mjs | 3 --- 2 files changed, 33 deletions(-) diff --git a/tests/docstrings_examples/Node.res b/tests/docstrings_examples/Node.res index 34b155ac4e..9440c31d56 100644 --- a/tests/docstrings_examples/Node.res +++ b/tests/docstrings_examples/Node.res @@ -1,20 +1,13 @@ module Path = { - @module("path") external join2: (string, string) => string = "join" @module("path") @variadic external join: array => string = "join" @module("path") external dirname: string => string = "dirname" } module Process = { - @scope("process") external exit: int => unit = "exit" - @scope(("process", "stderr")) - external stderrWrite: string => unit = "write" @scope("process") external cwd: unit => string = "cwd" - @val @scope("process") - external argv: array = "argv" } module Fs = { - @module("fs") external existsSync: string => bool = "existsSync" @module("fs") external readdirSync: string => array = "readdirSync" @module("node:fs/promises") external writeFile: (string, string) => promise = "writeFile" } @@ -25,10 +18,6 @@ module Buffer = { } module ChildProcess = { - type spawnSyncReturns = {stdout: Buffer.t} - @module("child_process") - external spawnSync: (string, array) => spawnSyncReturns = "spawnSync" - type readable type spawnReturns = {stderr: readable, stdout: readable} type options = {cwd?: string, env?: Dict.t, timeout?: int} @@ -36,35 +25,16 @@ module ChildProcess = { external spawn: (string, array, ~options: options=?) => spawnReturns = "spawn" @send external on: (readable, string, Buffer.t => unit) => unit = "on" - @send external onFromSpawn: (spawnReturns, string, Js.Null.t => unit) => unit = "on" @send external once: (spawnReturns, string, (Js.Null.t, Js.Null.t) => unit) => unit = "once" - @send - external onceError: (spawnReturns, string, Js.Exn.t => unit) => unit = "once" } module OS = { - @module("os") - external tmpdir: unit => string = "tmpdir" - @module("os") external cpus: unit => array<{.}> = "cpus" } -module Util = { - type arg = {@as("type") type_: string} - type config = { - args: array, - options: Dict.t, - } - type parsed = { - values: Dict.t, - positionals: array, - } - @module("node:util") external parseArgs: config => parsed = "parseArgs" -} - module URL = { @module("url") external fileURLToPath: string => string = "fileURLToPath" } diff --git a/tests/docstrings_examples/Node.res.mjs b/tests/docstrings_examples/Node.res.mjs index 106c4672a2..8ae5da3c11 100644 --- a/tests/docstrings_examples/Node.res.mjs +++ b/tests/docstrings_examples/Node.res.mjs @@ -13,8 +13,6 @@ let ChildProcess = {}; let OS = {}; -let Util = {}; - let URL = {}; export { @@ -24,7 +22,6 @@ export { Buffer, ChildProcess, OS, - Util, URL, } /* No side effect */ From af551427a8a6283db454bfc2878b217c513b492f Mon Sep 17 00:00:00 2001 From: aspeddro Date: Sun, 29 Dec 2024 16:28:53 -0300 Subject: [PATCH 11/13] adjusts --- scripts/test.js | 3 + tests/docstrings_examples/.gitignore | 2 + tests/docstrings_examples/DocTest.res | 121 +- tests/docstrings_examples/DocTest.res.mjs | 87 +- tests/docstrings_examples/Node.res | 1 + .../generated_mocha_test.res | 18311 ------------- .../generated_mocha_test.res.mjs | 22839 ---------------- 7 files changed, 151 insertions(+), 41213 deletions(-) create mode 100644 tests/docstrings_examples/.gitignore delete mode 100644 tests/docstrings_examples/generated_mocha_test.res delete mode 100644 tests/docstrings_examples/generated_mocha_test.res.mjs diff --git a/scripts/test.js b/scripts/test.js index 3dc2b5746d..cfe8a85939 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -137,16 +137,19 @@ async function runTests() { stdio: [0, 1, 2], }); + // Generate rescript file with all tests `generated_mocha_test.res` cp.execSync(`node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}`, { cwd: path.join(__dirname, ".."), 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/docstrings_examples"), stdio: [0, 1, 2], }); + // Format generated_mocha_test.res console.log("Formatting generated_mocha_test.res") cp.execSync(`./cli/rescript format ${path.join("tests", "docstrings_examples", "generated_mocha_test.res")}`, { cwd: path.join(__dirname, ".."), diff --git a/tests/docstrings_examples/.gitignore b/tests/docstrings_examples/.gitignore new file mode 100644 index 0000000000..448ac7b39c --- /dev/null +++ b/tests/docstrings_examples/.gitignore @@ -0,0 +1,2 @@ +generated_mocha_test.res +generated_mocha_test.res.mjs diff --git a/tests/docstrings_examples/DocTest.res b/tests/docstrings_examples/DocTest.res index e84dd80e50..2d3d7bdea6 100644 --- a/tests/docstrings_examples/DocTest.res +++ b/tests/docstrings_examples/DocTest.res @@ -9,18 +9,33 @@ type example = { docstrings: array, } -// Ignore some tests not supported by node v18 +// Only major version +let nodeVersion = + Process.version + ->String.replace("v", "") + ->String.split(".") + ->Array.get(0) + ->Option.getExn(~message="Failed to find major version of Node") + ->Int.fromString + ->Option.getExn(~message="Failed to convert node version to Int") + let ignoreRuntimeTests = [ - "Array.toReversed", - "Array.toSorted", - "Promise.withResolvers", - "Set.union", - "Set.isSupersetOf", - "Set.isSubsetOf", - "Set.isDisjointFrom", - "Set.intersection", - "Set.symmetricDifference", - "Set.difference", + ( + // Ignore some tests not supported by node v18 + 18, + [ + "Array.toReversed", + "Array.toSorted", + "Promise.withResolvers", + "Set.union", + "Set.isSupersetOf", + "Set.isSubsetOf", + "Set.isDisjointFrom", + "Set.intersection", + "Set.symmetricDifference", + "Set.difference", + ], + ), ] let getOutput = buffer => @@ -155,41 +170,81 @@ let extractExamples = async () => { let main = async () => { let examples = await extractExamples() - examples->Array.sort((a, b) => - Obj.magic(a.id) > Obj.magic(b.id) ? Ordering.fromInt(1) : Ordering.fromInt(-1) - ) - let testsContent = - examples - ->Array.filterMap(example => { - let codeExamples = getCodeBlocks(example) - let ignore = Array.includes(ignoreRuntimeTests, example.id) + examples->Array.sort((a, b) => String.compare(a.id, b.id)) - switch String.length(codeExamples) == 0 { - | true => None - | false => - ignore - ? None - : Some( - `describe("${example.id}", () => { - test("${example.id}", () => { - module Test = { - ${codeExamples} + let dict = dict{} + + examples->Array.forEach(cur => { + let modulePath = cur.id->String.split(".") + + let id = + modulePath + ->Array.slice(~start=0, ~end=Array.length(modulePath) - 1) + ->Array.join(".") + + let previous = switch dict->Dict.get(id) { + | Some(p) => p + | None => [] } - () + + dict->Dict.set(id, Array.concat([cur], previous)) }) + + let output = [] + + dict->Dict.forEachWithKey((examples, key) => { + let codeExamples = examples->Array.filterMap(example => { + let ignoreExample = Array.find( + ignoreRuntimeTests, + ((version, tests)) => { + nodeVersion === version && Array.includes(tests, example.id) + }, + )->Option.isSome + + switch ignoreExample { + | true => + Console.warn( + `Ignoring ${example.id} tests. Not supported by Node ${nodeVersion->Int.toString}`, + ) + None + | false => + let code = getCodeBlocks(example) + + switch String.length(code) === 0 { + | true => None + | false => + // Let's add the examples inside a Test module because some examples + // have type definitions that are not supported inside a block. + // Also add unit type `()` + Some( + `test("${example.id->String.split(".")->Array.at(-1)->Option.getExn}", () => { + module Test = { + ${code} + } + () })`, - ) + ) + } } }) - ->Array.join("\n\n") + + switch Array.length(codeExamples) > 0 { + | true => + let content = `describe("${key}", () => { +${codeExamples->Array.join("\n")} + })` + output->Array.push(content) + | false => () + } + }) let dirname = url->URL.fileURLToPath->Path.dirname let filepath = Path.join([dirname, "generated_mocha_test.res"]) let fileContent = `open Mocha @@warning("-32-34-60-37-109-3-44") -${testsContent}` +${output->Array.join("\n")}` await Fs.writeFile(filepath, fileContent) } diff --git a/tests/docstrings_examples/DocTest.res.mjs b/tests/docstrings_examples/DocTest.res.mjs index e933248953..955335592f 100644 --- a/tests/docstrings_examples/DocTest.res.mjs +++ b/tests/docstrings_examples/DocTest.res.mjs @@ -3,34 +3,41 @@ import * as Fs from "fs"; import * as Os from "os"; import * as Exn from "rescript/lib/es6/Exn.js"; +import * as Int from "rescript/lib/es6/Int.js"; import * as Url from "url"; +import * as Dict from "rescript/lib/es6/Dict.js"; import * as List from "rescript/lib/es6/List.js"; import * as Path from "path"; import * as $$Array from "rescript/lib/es6/Array.js"; import * as $$Error from "rescript/lib/es6/Error.js"; -import * as Ordering from "rescript/lib/es6/Ordering.js"; +import * as Option from "rescript/lib/es6/Option.js"; import * as Belt_List from "rescript/lib/es6/Belt_List.js"; import * as ArrayUtils from "./ArrayUtils.res.mjs"; import * as Belt_Array from "rescript/lib/es6/Belt_Array.js"; import * as Pervasives from "rescript/lib/es6/Pervasives.js"; import * as SpawnAsync from "./SpawnAsync.res.mjs"; -import * as Primitive_object from "rescript/lib/es6/Primitive_object.js"; +import * as Primitive_string from "rescript/lib/es6/Primitive_string.js"; import * as Promises from "node:fs/promises"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; import * as RescriptTools_Docgen from "rescript/lib/es6/RescriptTools_Docgen.js"; -let ignoreRuntimeTests = [ - "Array.toReversed", - "Array.toSorted", - "Promise.withResolvers", - "Set.union", - "Set.isSupersetOf", - "Set.isSubsetOf", - "Set.isDisjointFrom", - "Set.intersection", - "Set.symmetricDifference", - "Set.difference" -]; +let nodeVersion = Option.getExn(Int.fromString(Option.getExn(process.version.replace("v", "").split(".")[0], "Failed to find major version of Node"), undefined), "Failed to convert node version to Int"); + +let ignoreRuntimeTests = [[ + 18, + [ + "Array.toReversed", + "Array.toSorted", + "Promise.withResolvers", + "Set.union", + "Set.isSupersetOf", + "Set.isSubsetOf", + "Set.isDisjointFrom", + "Set.intersection", + "Set.symmetricDifference", + "Set.difference" + ] + ]]; function getOutput(buffer) { return buffer.map(e => e.toString()).join(""); @@ -53,7 +60,7 @@ async function extractDocFromFile(file) { RE_EXN_ID: "Assert_failure", _1: [ "DocTest.res", - 43, + 58, 9 ], Error: new Error() @@ -216,28 +223,48 @@ async function extractExamples() { async function main() { let examples = await extractExamples(); - examples.sort((a, b) => { - if (Primitive_object.greaterthan(a.id, b.id)) { - return Ordering.fromInt(1); - } else { - return Ordering.fromInt(-1); - } + examples.sort((a, b) => Primitive_string.compare(a.id, b.id)); + let dict = {}; + examples.forEach(cur => { + let modulePath = cur.id.split("."); + let id = modulePath.slice(0, modulePath.length - 1 | 0).join("."); + let p = dict[id]; + let previous = p !== undefined ? p : []; + dict[id] = [cur].concat(previous); }); - let testsContent = $$Array.filterMap(examples, example => { - let codeExamples = getCodeBlocks(example); - let ignore = ignoreRuntimeTests.includes(example.id); - if (codeExamples.length === 0 || ignore) { + let output = []; + Dict.forEachWithKey(dict, (examples, key) => { + let codeExamples = $$Array.filterMap(examples, example => { + let ignoreExample = Option.isSome(ignoreRuntimeTests.find(param => { + if (nodeVersion === param[0]) { + return param[1].includes(example.id); + } else { + return false; + } + })); + if (ignoreExample) { + console.warn("Ignoring " + example.id + " tests. Not supported by Node " + nodeVersion.toString()); + return; + } + let code = getCodeBlocks(example); + if (code.length === 0) { + return; + } else { + return "test(\"" + Option.getExn(example.id.split(".").at(-1), undefined) + "\", () => {\n module Test = {\n " + code + "\n }\n ()\n})"; + } + }); + if (codeExamples.length <= 0) { return; - } else { - return "describe(\"" + example.id + "\", () => {\n test(\"" + example.id + "\", () => {\n module Test = {\n " + codeExamples + "\n }\n ()\n })\n})"; } - }).join("\n\n"); + 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 fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + testsContent; + let fileContent = "open Mocha\n@@warning(\"-32-34-60-37-109-3-44\")\n\n" + output.join("\n"); return await Promises.writeFile(filepath, fileContent); } await main(); -/* batchSize Not a pure module */ +/* nodeVersion Not a pure module */ diff --git a/tests/docstrings_examples/Node.res b/tests/docstrings_examples/Node.res index 9440c31d56..2182b31703 100644 --- a/tests/docstrings_examples/Node.res +++ b/tests/docstrings_examples/Node.res @@ -5,6 +5,7 @@ module Path = { module Process = { @scope("process") external cwd: unit => string = "cwd" + @scope("process") @val external version: string = "version" } module Fs = { diff --git a/tests/docstrings_examples/generated_mocha_test.res b/tests/docstrings_examples/generated_mocha_test.res deleted file mode 100644 index 42da231211..0000000000 --- a/tests/docstrings_examples/generated_mocha_test.res +++ /dev/null @@ -1,18311 +0,0 @@ -open Mocha -@@warning("-32-34-60-37-109-3-44") - -describe("Array.at", () => { - test("Array.at", () => { - module Test = { - ["a", "b", "c"]->Array.at(0)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(2)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(3)->assertEqual(None) - ["a", "b", "c"]->Array.at(-1)->assertEqual(Some("c")) - ["a", "b", "c"]->Array.at(-3)->assertEqual(Some("a")) - ["a", "b", "c"]->Array.at(-4)->assertEqual(None) - } - () - }) -}) - -describe("Array.concat", () => { - test("Array.concat", () => { - module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay", "wehoo"] - - let someArray = array1->Array.concat(array2) - - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) - } - () - }) -}) - -describe("Array.concatMany", () => { - test("Array.concatMany", () => { - module Test = { - let array1 = ["hi", "hello"] - let array2 = ["yay"] - let array3 = ["wehoo"] - - let someArray = array1->Array.concatMany([array2, array3]) - - Console.log(someArray) // ["hi", "hello", "yay", "wehoo"] - } - () - }) -}) - -describe("Array.copy", () => { - test("Array.copy", () => { - module Test = { - let myArray = [1, 2, 3] - let copyOfMyArray = myArray->Array.copy - - copyOfMyArray->assertEqual([1, 2, 3]) - assertEqual(myArray === copyOfMyArray, false) - } - () - }) -}) - -describe("Array.every", () => { - test("Array.every", () => { - module Test = { - let array = [1, 2, 3, 4] - - array - ->Array.every(num => num <= 4) - ->assertEqual(true) - - array - ->Array.every(num => num === 1) - ->assertEqual(false) - } - () - }) -}) - -describe("Array.everyWithIndex", () => { - test("Array.everyWithIndex", () => { - module Test = { - let array = [1, 2, 3, 4] - - array - ->Array.everyWithIndex((num, index) => index < 5 && num <= 4) - ->assertEqual(true) - - array - ->Array.everyWithIndex((num, index) => index < 2 && num >= 2) - ->assertEqual(false) - } - () - }) -}) - -describe("Array.fill", () => { - test("Array.fill", () => { - module Test = { - let myArray = [1, 2, 3, 4] - - myArray->Array.fill(9, ~start=1, ~end=3) - - myArray->assertEqual([1, 9, 9, 4]) - } - () - }) -}) - -describe("Array.fillAll", () => { - test("Array.fillAll", () => { - module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillAll(9) - myArray->assertEqual([9, 9, 9, 9]) - } - () - }) -}) - -describe("Array.fillToEnd", () => { - test("Array.fillToEnd", () => { - module Test = { - let myArray = [1, 2, 3, 4] - myArray->Array.fillToEnd(9, ~start=1) - myArray->assertEqual([1, 9, 9, 9]) - } - () - }) -}) - -describe("Array.filter", () => { - test("Array.filter", () => { - module Test = { - [1, 2, 3, 4] - ->Array.filter(num => num > 2) - ->assertEqual([3, 4]) - } - () - }) -}) - -describe("Array.filterMap", () => { - test("Array.filterMap", () => { - module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.filterMap( - item => - switch item { - | "Hello" => Some(item->String.length) - | _ => None - }, - ) - ->assertEqual([5]) - - [1, 2, 3, 4, 5, 6] - ->Array.filterMap(n => mod(n, 2) == 0 ? Some(n * n) : None) - ->assertEqual([4, 16, 36]) - - Array.filterMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual([]) - - Array.filterMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual([]) - } - () - }) -}) - -describe("Array.filterWithIndex", () => { - test("Array.filterWithIndex", () => { - module Test = { - [1, 2, 3, 4] - ->Array.filterWithIndex((num, index) => index === 0 || num === 2) - ->assertEqual([1, 2]) - } - () - }) -}) - -describe("Array.find", () => { - test("Array.find", () => { - module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.find(item => item == ReScript) - ->assertEqual(Some(ReScript)) - } - () - }) -}) - -describe("Array.findIndex", () => { - test("Array.findIndex", () => { - module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] - - array - ->Array.findIndex(item => item == ReScript) - ->assertEqual(0) - - array - ->Array.findIndex(item => item == TypeScript) - ->assertEqual(-1) - } - () - }) -}) - -describe("Array.findIndexOpt", () => { - test("Array.findIndexOpt", () => { - module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.findIndexOpt(item => item == ReScript) - ->assertEqual(Some(0)) - } - () - }) -}) - -describe("Array.findIndexWithIndex", () => { - test("Array.findIndexWithIndex", () => { - module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [ReScript, JavaScript] - - let isReScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == ReScript) - let isTypeScriptFirst = - array->Array.findIndexWithIndex((item, index) => index === 0 && item == TypeScript) - - assertEqual(isReScriptFirst, 0) - assertEqual(isTypeScriptFirst, -1) - } - () - }) -}) - -describe("Array.findMap", () => { - test("Array.findMap", () => { - module Test = { - Array.findMap([1, 2, 3], n => mod(n, 2) == 0 ? Some(n - 2) : None)->assertEqual(Some(0)) - - Array.findMap([1, 2, 3, 4, 5, 6], n => mod(n, 2) == 0 ? Some(n - 8) : None)->assertEqual( - Some(-6), - ) - - Array.findMap([1, 2, 3, 4, 5, 6], _ => None)->assertEqual(None) - - Array.findMap([], n => mod(n, 2) == 0 ? Some(n * n) : None)->assertEqual(None) - } - () - }) -}) - -describe("Array.findWithIndex", () => { - test("Array.findWithIndex", () => { - module Test = { - type languages = ReScript | TypeScript | JavaScript - - let array = [TypeScript, JavaScript, ReScript] - - array - ->Array.findWithIndex((item, index) => index > 1 && item == ReScript) - ->assertEqual(Some(ReScript)) - } - () - }) -}) - -describe("Array.flat", () => { - test("Array.flat", () => { - module Test = { - [[1], [2], [3, 4]] - ->Array.flat - ->assertEqual([1, 2, 3, 4]) - } - () - }) -}) - -describe("Array.flatMap", () => { - test("Array.flatMap", () => { - module Test = { - type language = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.flatMap( - item => - switch item { - | ReScript => [1, 2, 3] - | TypeScript => [4, 5, 6] - | JavaScript => [7, 8, 9] - }, - ) - ->assertEqual([1, 2, 3, 4, 5, 6, 7, 8, 9]) - } - () - }) -}) - -describe("Array.flatMapWithIndex", () => { - test("Array.flatMapWithIndex", () => { - module Test = { - type language = ReScript | TypeScript | JavaScript - - let array = [ReScript, TypeScript, JavaScript] - - array - ->Array.flatMapWithIndex( - (item, index) => - switch item { - | ReScript => [index] - | TypeScript => [index, index + 1] - | JavaScript => [index, index + 1, index + 2] - }, - ) - ->assertEqual([0, 1, 2, 2, 3, 4]) - } - () - }) -}) - -describe("Array.forEach", () => { - test("Array.forEach", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array->Array.forEach( - item => { - Console.log(item) - }, - ) - } - () - }) -}) - -describe("Array.forEachWithIndex", () => { - test("Array.forEachWithIndex", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array->Array.forEachWithIndex( - (item, index) => { - Console.log("At item " ++ Int.toString(index) ++ ": " ++ item) - }, - ) - } - () - }) -}) - -describe("Array.fromInitializer", () => { - test("Array.fromInitializer", () => { - module Test = { - Array.fromInitializer(~length=3, i => i + 3)->assertEqual([3, 4, 5]) - - Array.fromInitializer(~length=7, i => i + 3)->assertEqual([3, 4, 5, 6, 7, 8, 9]) - } - () - }) -}) - -describe("Array.fromIterator", () => { - test("Array.fromIterator", () => { - module Test = { - Map.fromArray([("foo", 1), ("bar", 2)]) - ->Map.values - ->Array.fromIterator - ->assertEqual([1, 2]) - } - () - }) -}) - -describe("Array.get", () => { - test("Array.get", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.get(0) - ->assertEqual(Some("Hello")) - - array - ->Array.get(3) - ->assertEqual(None) - } - () - }) -}) - -describe("Array.getUnsafe", () => { - test("Array.getUnsafe", () => { - module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.getUnsafe(index) - Console.log(value) - } - } - () - }) -}) - -describe("Array.includes", () => { - test("Array.includes", () => { - module Test = { - [1, 2]->Array.includes(1)->assertEqual(true) - [1, 2]->Array.includes(3)->assertEqual(false) - - [{"language": "ReScript"}] - ->Array.includes({"language": "ReScript"}) - ->assertEqual(false) // false, because of strict equality - } - () - }) -}) - -describe("Array.indexOf", () => { - test("Array.indexOf", () => { - module Test = { - [1, 2]->Array.indexOf(2)->assertEqual(1) - [1, 2]->Array.indexOf(3)->assertEqual(-1) - - [{"language": "ReScript"}] - ->Array.indexOf({"language": "ReScript"}) - ->assertEqual(-1) // -1, because of strict equality - } - () - }) -}) - -describe("Array.indexOfOpt", () => { - test("Array.indexOfOpt", () => { - module Test = { - [1, 2]->Array.indexOfOpt(2)->assertEqual(Some(1)) - [1, 2]->Array.indexOfOpt(3)->assertEqual(None) - [{"language": "ReScript"}] - ->Array.indexOfOpt({"language": "ReScript"}) - ->assertEqual(None) // None, because of strict equality - } - () - }) -}) - -describe("Array.join", () => { - test("Array.join", () => { - module Test = { - ["One", "Two", "Three"] - ->Array.join(" -- ") - ->assertEqual("One -- Two -- Three") - } - () - }) -}) - -describe("Array.joinUnsafe", () => { - test("Array.joinUnsafe", () => { - module Test = { - [1, 2, 3] - ->Array.joinUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") - } - () - }) -}) - -describe("Array.joinWith", () => { - test("Array.joinWith", () => { - module Test = { - ["One", "Two", "Three"] - ->Array.joinWith(" -- ") - ->assertEqual("One -- Two -- Three") - } - () - }) -}) - -describe("Array.joinWithUnsafe", () => { - test("Array.joinWithUnsafe", () => { - module Test = { - [1, 2, 3] - ->Array.joinWithUnsafe(" -- ") - ->assertEqual("1 -- 2 -- 3") - } - () - }) -}) - -describe("Array.keepSome", () => { - test("Array.keepSome", () => { - module Test = { - Array.keepSome([Some(1), None, Some(3)])->assertEqual([1, 3]) - - Array.keepSome([Some(1), Some(2), Some(3)])->assertEqual([1, 2, 3]) - - Array.keepSome([None, None, None])->assertEqual([]) - - Array.keepSome([])->assertEqual([]) - } - () - }) -}) - -describe("Array.last", () => { - test("Array.last", () => { - module Test = { - ["Hello", "Hi", "Good bye"] - ->Array.last - ->assertEqual(Some("Good bye")) - - [] - ->Array.last - ->assertEqual(None) - } - () - }) -}) - -describe("Array.length", () => { - test("Array.length", () => { - module Test = { - let someArray = ["hi", "hello"] - - someArray - ->Array.length - ->assertEqual(2) - } - () - }) -}) - -describe("Array.make", () => { - test("Array.make", () => { - module Test = { - Array.make(~length=3, #apple)->assertEqual([#apple, #apple, #apple]) - Array.make(~length=6, 7)->assertEqual([7, 7, 7, 7, 7, 7]) - } - () - }) -}) - -describe("Array.map", () => { - test("Array.map", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = array->Array.map(greeting => greeting ++ " to you") - - assertEqual(mappedArray, ["Hello to you", "Hi to you", "Good bye to you"]) - } - () - }) -}) - -describe("Array.mapWithIndex", () => { - test("Array.mapWithIndex", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - let mappedArray = - array->Array.mapWithIndex( - (greeting, index) => greeting ++ " at position " ++ Int.toString(index), - ) - - assertEqual( - mappedArray, - ["Hello at position 0", "Hi at position 1", "Good bye at position 2"], - ) - } - () - }) -}) - -describe("Array.pop", () => { - test("Array.pop", () => { - module Test = { - let someArray = ["hi", "hello"] - - someArray - ->Array.pop - ->assertEqual(Some("hello")) - - someArray->assertEqual(["hi"]) // Notice last item is gone. - } - () - }) -}) - -describe("Array.push", () => { - test("Array.push", () => { - module Test = { - let someArray = ["hi", "hello"] - - someArray->Array.push("yay") - - someArray->assertEqual(["hi", "hello", "yay"]) - } - () - }) -}) - -describe("Array.pushMany", () => { - test("Array.pushMany", () => { - module Test = { - let someArray = ["hi", "hello"] - - someArray->Array.pushMany(["yay", "wehoo"]) - someArray->assertEqual(["hi", "hello", "yay", "wehoo"]) - } - () - }) -}) - -describe("Array.reduce", () => { - test("Array.reduce", () => { - module Test = { - Array.reduce([2, 3, 4], 1, (a, b) => a + b)->assertEqual(10) - - Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("abcd") - - [1, 2, 3] - ->Array.reduce(list{}, List.add) - ->assertEqual(list{3, 2, 1}) - - Array.reduce([], list{}, List.add)->assertEqual(list{}) - } - () - }) -}) - -describe("Array.reduceRight", () => { - test("Array.reduceRight", () => { - module Test = { - Array.reduceRight(["a", "b", "c", "d"], "", (a, b) => a ++ b)->assertEqual("dcba") - - Array.reduceRight([1, 2, 3], list{}, List.add)->assertEqual(list{1, 2, 3}) - - Array.reduceRight([], list{}, List.add)->assertEqual(list{}) - } - () - }) -}) - -describe("Array.reduceRightWithIndex", () => { - test("Array.reduceRightWithIndex", () => { - module Test = { - Array.reduceRightWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) - - Array.reduceRightWithIndex( - [], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{}) - } - () - }) -}) - -describe("Array.reduceWithIndex", () => { - test("Array.reduceWithIndex", () => { - module Test = { - Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i)->assertEqual(16) - - Array.reduceWithIndex( - [1, 2, 3], - list{}, - (acc, v, i) => list{v + i, ...acc}, - )->assertEqual(list{5, 3, 1}) - - Array.reduceWithIndex([], list{}, (acc, v, i) => list{v + i, ...acc})->assertEqual(list{}) - } - () - }) -}) - -describe("Array.reverse", () => { - test("Array.reverse", () => { - module Test = { - let someArray = ["hi", "hello"] - someArray->Array.reverse - - someArray->assertEqual(["hello", "hi"]) - } - () - }) -}) - -describe("Array.set", () => { - test("Array.set", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.set(1, "Hello") - - array[1]->assertEqual(Some("Hello")) - } - () - }) -}) - -describe("Array.setUnsafe", () => { - test("Array.setUnsafe", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.setUnsafe(1, "Hello") - - assertEqual(array[1], Some("Hello")) - } - () - }) -}) - -describe("Array.shift", () => { - test("Array.shift", () => { - module Test = { - let someArray = ["hi", "hello"] - - someArray - ->Array.shift - ->assertEqual(Some("hi")) - - someArray->assertEqual(["hello"]) // Notice first item is gone. - } - () - }) -}) - -describe("Array.shuffle", () => { - test("Array.shuffle", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - array->Array.shuffle - Console.log(array) - - let array2 = [1, 2, 3] - array2->Array.shuffle - - array2 - ->Array.length - ->assertEqual(3) - } - () - }) -}) - -describe("Array.slice", () => { - test("Array.slice", () => { - module Test = { - [1, 2, 3, 4] - ->Array.slice(~start=1, ~end=3) - ->assertEqual([2, 3]) - } - () - }) -}) - -describe("Array.sliceToEnd", () => { - test("Array.sliceToEnd", () => { - module Test = { - [1, 2, 3, 4] - ->Array.sliceToEnd(~start=1) - ->assertEqual([2, 3, 4]) - } - () - }) -}) - -describe("Array.some", () => { - test("Array.some", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.some(greeting => greeting === "Hello") - ->assertEqual(true) - } - () - }) -}) - -describe("Array.someWithIndex", () => { - test("Array.someWithIndex", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - - array - ->Array.someWithIndex((greeting, index) => greeting === "Hello" && index === 0) - ->assertEqual(true) - } - () - }) -}) - -describe("Array.sort", () => { - test("Array.sort", () => { - module Test = { - let array = [3, 2, 1] - array->Array.sort((a, b) => float(a - b)) - array->assertEqual([1, 2, 3]) - } - () - }) -}) - -describe("Array.toShuffled", () => { - test("Array.toShuffled", () => { - module Test = { - let array = ["Hello", "Hi", "Good bye"] - let shuffledArray = array->Array.toShuffled - Console.log(shuffledArray) - - Array.toShuffled([1, 2, 3]) - ->Array.length - ->assertEqual(3) - } - () - }) -}) - -describe("Array.toString", () => { - test("Array.toString", () => { - module Test = { - [1, 2, 3, 4] - ->Array.toString - ->assertEqual("1,2,3,4") - } - () - }) -}) - -describe("Array.unsafe_get", () => { - test("Array.unsafe_get", () => { - module Test = { - let array = [1, 2, 3] - for index in 0 to array->Array.length - 1 { - let value = array->Array.unsafe_get(index) - Console.log(value) - } - } - () - }) -}) - -describe("Array.unshift", () => { - test("Array.unshift", () => { - module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshift("yay") - someArray->assertEqual(["yay", "hi", "hello"]) - } - () - }) -}) - -describe("Array.unshiftMany", () => { - test("Array.unshiftMany", () => { - module Test = { - let someArray = ["hi", "hello"] - someArray->Array.unshiftMany(["yay", "wehoo"]) - someArray->assertEqual(["yay", "wehoo", "hi", "hello"]) - } - () - }) -}) - -describe("AsyncIterator.done", () => { - test("AsyncIterator.done", () => { - module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 - - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) - } - () - }) -}) - -describe("AsyncIterator.forEach", () => { - test("AsyncIterator.forEach", () => { - module Test = { - // Let's pretend we get an async iterator returning ints from somewhere. - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let main = async () => - await asyncIterator->AsyncIterator.forEach( - v => { - switch v { - | Some(("second", value)) => assertEqual(value, "2") - | _ => () - } - }, - ) - - main()->ignore - } - () - }) -}) - -describe("AsyncIterator.make", () => { - test("AsyncIterator.make", () => { - module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 - - { - AsyncIterator.value: Some(currentValue), - done: currentValue >= 3, - } - }, - ) - - // This will log 1, 2, 3 - let main = async () => - await asyncIterator->AsyncIterator.forEach( - value => - switch value { - | Some(value) => Console.log(value) - | None => () - }, - ) - - main()->ignore - } - () - }) -}) - -describe("AsyncIterator.next", () => { - test("AsyncIterator.next", () => { - module Test = { - let asyncIterator: AsyncIterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - let processMyAsyncIterator = async () => { - // ReScript doesn't have `for ... of` loops, but it's easy to mimic using a while loop. - let break = ref(false) - - while !break.contents { - // Await the next iterator value - let {value, done} = await asyncIterator->AsyncIterator.next - - // Exit the while loop if the iterator says it's done - break := done - - if done { - value - ->Option.isNone - ->assertEqual(true) - } - } - } - - processMyAsyncIterator()->ignore - } - () - }) -}) - -describe("AsyncIterator.value", () => { - test("AsyncIterator.value", () => { - module Test = { - let context = ref(0) - - let asyncIterator = AsyncIterator.make( - async () => { - let currentValue = context.contents - // Increment current value - context := currentValue + 1 - - if currentValue >= 3 { - AsyncIterator.done() - } else { - AsyncIterator.value(currentValue) - } - }, - ) - } - () - }) -}) - -describe("Belt.Array.blit", () => { - test("Belt.Array.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt.Array.cmp", () => { - test("Belt.Array.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt.Array.concat", () => { - test("Belt.Array.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt.Array.concatMany", () => { - test("Belt.Array.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt.Array.eq", () => { - test("Belt.Array.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt.Array.every", () => { - test("Belt.Array.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt.Array.every2", () => { - test("Belt.Array.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt.Array.fill", () => { - test("Belt.Array.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt.Array.flatMap", () => { - test("Belt.Array.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt.Array.forEach", () => { - test("Belt.Array.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt.Array.forEachWithIndex", () => { - test("Belt.Array.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt.Array.get", () => { - test("Belt.Array.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt.Array.getBy", () => { - test("Belt.Array.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt.Array.getIndexBy", () => { - test("Belt.Array.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt.Array.joinWith", () => { - test("Belt.Array.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt.Array.keepMap", () => { - test("Belt.Array.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt.Array.keepWithIndex", () => { - test("Belt.Array.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt.Array.length", () => { - test("Belt.Array.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt.Array.makeBy", () => { - test("Belt.Array.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt.Array.makeUninitialized", () => { - test("Belt.Array.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt.Array.makeUninitializedUnsafe", () => { - test("Belt.Array.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt.Array.map", () => { - test("Belt.Array.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt.Array.mapWithIndex", () => { - test("Belt.Array.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt.Array.partition", () => { - test("Belt.Array.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt.Array.range", () => { - test("Belt.Array.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt.Array.rangeBy", () => { - test("Belt.Array.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt.Array.reduce", () => { - test("Belt.Array.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt.Array.reduceReverse", () => { - test("Belt.Array.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt.Array.reduceReverse2", () => { - test("Belt.Array.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt.Array.reduceWithIndex", () => { - test("Belt.Array.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt.Array.reverse", () => { - test("Belt.Array.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt.Array.reverseInPlace", () => { - test("Belt.Array.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt.Array.slice", () => { - test("Belt.Array.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt.Array.sliceToEnd", () => { - test("Belt.Array.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt.Array.some", () => { - test("Belt.Array.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt.Array.some2", () => { - test("Belt.Array.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt.Array.truncateToLengthUnsafe", () => { - test("Belt.Array.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt.Array.unzip", () => { - test("Belt.Array.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt.Array.zip", () => { - test("Belt.Array.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt.Array.zipBy", () => { - test("Belt.Array.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("Belt.Float.*", () => { - test("Belt.Float.*", () => { - module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) - } - () - }) -}) - -describe("Belt.Float.+", () => { - test("Belt.Float.+", () => { - module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) - } - () - }) -}) - -describe("Belt.Float.-", () => { - test("Belt.Float.-", () => { - module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) - } - () - }) -}) - -describe("Belt.Float./", () => { - test("Belt.Float./", () => { - module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) - } - () - }) -}) - -describe("Belt.Float.fromInt", () => { - test("Belt.Float.fromInt", () => { - module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ - } - () - }) -}) - -describe("Belt.Float.fromString", () => { - test("Belt.Float.fromString", () => { - module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ - } - () - }) -}) - -describe("Belt.Float.toInt", () => { - test("Belt.Float.toInt", () => { - module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ - } - () - }) -}) - -describe("Belt.Float.toString", () => { - test("Belt.Float.toString", () => { - module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ - } - () - }) -}) - -describe("Belt.HashMap", () => { - test("Belt.HashMap", () => { - module Test = { - type t = int - module I0 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff_ff, ~eq=(a, b) => a == b)) - let s0: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I0), - ) - - module I1 = unpack(Belt.Id.hashable(~hash=(_: t) => 0xff, ~eq=(a, b) => a == b)) - let s1: Belt.HashMap.t = Belt.HashMap.make( - ~hintSize=40, - ~id=module(I1), - ) - - let () = { - Belt.HashMap.set(s0, 0, 3) - Belt.HashMap.set(s1, 1, "3") - } - } - () - }) -}) - -describe("Belt.HashMap.clear", () => { - test("Belt.HashMap.clear", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true - } - () - }) -}) - -describe("Belt.HashMap.copy", () => { - test("Belt.HashMap.copy", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) - } - () - }) -}) - -describe("Belt.HashMap.forEach", () => { - test("Belt.HashMap.forEach", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") - } - () - }) -}) - -describe("Belt.HashMap.fromArray", () => { - test("Belt.HashMap.fromArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] - } - () - }) -}) - -describe("Belt.HashMap.get", () => { - test("Belt.HashMap.get", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None - } - () - }) -}) - -describe("Belt.HashMap.getBucketHistogram", () => { - test("Belt.HashMap.getBucketHistogram", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.getBucketHistogram(hMap) - } - () - }) -}) - -describe("Belt.HashMap.has", () => { - test("Belt.HashMap.has", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false - } - () - }) -}) - -describe("Belt.HashMap.isEmpty", () => { - test("Belt.HashMap.isEmpty", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false - } - () - }) -}) - -describe("Belt.HashMap.keepMapInPlace", () => { - test("Belt.HashMap.keepMapInPlace", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) - } - () - }) -}) - -describe("Belt.HashMap.keysToArray", () => { - test("Belt.HashMap.keysToArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keysToArray(s0) == [1, 2] - } - () - }) -}) - -describe("Belt.HashMap.logStats", () => { - test("Belt.HashMap.logStats", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.logStats(hMap) - } - () - }) -}) - -describe("Belt.HashMap.make", () => { - test("Belt.HashMap.make", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(hMap, 0, "a") - } - () - }) -}) - -describe("Belt.HashMap.mergeMany", () => { - test("Belt.HashMap.mergeMany", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) - } - () - }) -}) - -describe("Belt.HashMap.reduce", () => { - test("Belt.HashMap.reduce", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") - - Console.log("lol") - } - () - }) -}) - -describe("Belt.HashMap.remove", () => { - test("Belt.HashMap.remove", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false - } - () - }) -}) - -describe("Belt.HashMap.set", () => { - test("Belt.HashMap.set", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] - } - () - }) -}) - -describe("Belt.HashMap.size", () => { - test("Belt.HashMap.size", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.size(s0) == 2 - } - () - }) -}) - -describe("Belt.HashMap.toArray", () => { - test("Belt.HashMap.toArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] - } - () - }) -}) - -describe("Belt.HashMap.valuesToArray", () => { - test("Belt.HashMap.valuesToArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] - } - () - }) -}) - -describe("Belt.HashSet", () => { - test("Belt.HashSet", () => { - module Test = { - module I0 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 65535), ~eq=(a, b) => a == b)) - - let s0 = Belt.HashSet.make(~id=module(I0), ~hintSize=40) - - module I1 = unpack(Belt.Id.hashable(~hash=(a: int) => land(a, 255), ~eq=(a, b) => a == b)) - - let s1 = Belt.HashSet.make(~id=module(I1), ~hintSize=40) - - Belt.HashSet.add(s1, 0) - Belt.HashSet.add(s1, 1) - } - () - }) -}) - -describe("Belt.Int.*", () => { - test("Belt.Int.*", () => { - module Test = { - open Belt.Int - assertEqual(2 * 2, 4) - } - () - }) -}) - -describe("Belt.Int.+", () => { - test("Belt.Int.+", () => { - module Test = { - open Belt.Int - assertEqual(2 + 2, 4) - } - () - }) -}) - -describe("Belt.Int.-", () => { - test("Belt.Int.-", () => { - module Test = { - open Belt.Int - assertEqual(2 - 1, 1) - } - () - }) -}) - -describe("Belt.Int./", () => { - test("Belt.Int./", () => { - module Test = { - open Belt.Int - assertEqual(4 / 2, 2) - } - () - }) -}) - -describe("Belt.Int.fromFloat", () => { - test("Belt.Int.fromFloat", () => { - module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) - } - () - }) -}) - -describe("Belt.Int.fromString", () => { - test("Belt.Int.fromString", () => { - module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt.Int.toFloat", () => { - test("Belt.Int.toFloat", () => { - module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) - } - () - }) -}) - -describe("Belt.Int.toString", () => { - test("Belt.Int.toString", () => { - module Test = { - Belt.Int.toString(1)->assertEqual("1") - } - () - }) -}) - -describe("Belt.List.add", () => { - test("Belt.List.add", () => { - module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} - } - () - }) -}) - -describe("Belt.List.cmp", () => { - test("Belt.List.cmp", () => { - module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ - } - () - }) -}) - -describe("Belt.List.cmpByLength", () => { - test("Belt.List.cmpByLength", () => { - module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ - } - () - }) -}) - -describe("Belt.List.concat", () => { - test("Belt.List.concat", () => { - module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} - } - () - }) -}) - -describe("Belt.List.concatMany", () => { - test("Belt.List.concatMany", () => { - module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("Belt.List.drop", () => { - test("Belt.List.drop", () => { - module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) - - list{1, 2, 3}->Belt.List.drop(4) // None - } - () - }) -}) - -describe("Belt.List.eq", () => { - test("Belt.List.eq", () => { - module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ - } - () - }) -}) - -describe("Belt.List.every", () => { - test("Belt.List.every", () => { - module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ - } - () - }) -}) - -describe("Belt.List.every2", () => { - test("Belt.List.every2", () => { - module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ - } - () - }) -}) - -describe("Belt.List.filter", () => { - test("Belt.List.filter", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ - } - () - }) -}) - -describe("Belt.List.filterWithIndex", () => { - test("Belt.List.filterWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) - -describe("Belt.List.flatten", () => { - test("Belt.List.flatten", () => { - module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("Belt.List.forEach", () => { - test("Belt.List.forEach", () => { - module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ - } - () - }) -}) - -describe("Belt.List.forEach2", () => { - test("Belt.List.forEach2", () => { - module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ - } - () - }) -}) - -describe("Belt.List.forEachWithIndex", () => { - test("Belt.List.forEachWithIndex", () => { - module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - } - () - }) -}) - -describe("Belt.List.fromArray", () => { - test("Belt.List.fromArray", () => { - module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} - } - () - }) -}) - -describe("Belt.List.get", () => { - test("Belt.List.get", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.get(1) // Some("B") - - abc->Belt.List.get(4) // None - } - () - }) -}) - -describe("Belt.List.getAssoc", () => { - test("Belt.List.getAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ - } - () - }) -}) - -describe("Belt.List.getBy", () => { - test("Belt.List.getBy", () => { - module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ - - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ - } - () - }) -}) - -describe("Belt.List.getExn", () => { - test("Belt.List.getExn", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.getExn(1)->assertEqual("B") - - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt.List.has", () => { - test("Belt.List.has", () => { - module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ - - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ - } - () - }) -}) - -describe("Belt.List.hasAssoc", () => { - test("Belt.List.hasAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ - } - () - }) -}) - -describe("Belt.List.head", () => { - test("Belt.List.head", () => { - module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) - } - () - }) -}) - -describe("Belt.List.headExn", () => { - test("Belt.List.headExn", () => { - module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt.List.keep", () => { - test("Belt.List.keep", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ - } - () - }) -}) - -describe("Belt.List.keepMap", () => { - test("Belt.List.keepMap", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ - - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ - } - () - }) -}) - -describe("Belt.List.keepWithIndex", () => { - test("Belt.List.keepWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) - -describe("Belt.List.length", () => { - test("Belt.List.length", () => { - module Test = { - Belt.List.length(list{1, 2, 3}) // 3 - } - () - }) -}) - -describe("Belt.List.make", () => { - test("Belt.List.make", () => { - module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} - } - () - }) -}) - -describe("Belt.List.makeBy", () => { - test("Belt.List.makeBy", () => { - module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} - - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} - } - () - }) -}) - -describe("Belt.List.map", () => { - test("Belt.List.map", () => { - module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} - } - () - }) -}) - -describe("Belt.List.mapReverse", () => { - test("Belt.List.mapReverse", () => { - module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) - } - () - }) -}) - -describe("Belt.List.mapReverse2", () => { - test("Belt.List.mapReverse2", () => { - module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} - } - () - }) -}) - -describe("Belt.List.mapWithIndex", () => { - test("Belt.List.mapWithIndex", () => { - module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} - } - () - }) -}) - -describe("Belt.List.partition", () => { - test("Belt.List.partition", () => { - module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) - } - () - }) -}) - -describe("Belt.List.reduce", () => { - test("Belt.List.reduce", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - - /* same as */ - - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ - } - () - }) -}) - -describe("Belt.List.reduce2", () => { - test("Belt.List.reduce2", () => { - module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ - } - () - }) -}) - -describe("Belt.List.reduceReverse", () => { - test("Belt.List.reduceReverse", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} - } - () - }) -}) - -describe("Belt.List.reduceReverse2", () => { - test("Belt.List.reduceReverse2", () => { - module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ - } - () - }) -}) - -describe("Belt.List.reduceWithIndex", () => { - test("Belt.List.reduceWithIndex", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ - } - () - }) -}) - -describe("Belt.List.removeAssoc", () => { - test("Belt.List.removeAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ - } - () - }) -}) - -describe("Belt.List.reverse", () => { - test("Belt.List.reverse", () => { - module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ - } - () - }) -}) - -describe("Belt.List.reverseConcat", () => { - test("Belt.List.reverseConcat", () => { - module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} - } - () - }) -}) - -describe("Belt.List.setAssoc", () => { - test("Belt.List.setAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ - - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ - - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ - } - () - }) -}) - -describe("Belt.List.shuffle", () => { - test("Belt.List.shuffle", () => { - module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} - } - () - }) -}) - -describe("Belt.List.some", () => { - test("Belt.List.some", () => { - module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ - } - () - }) -}) - -describe("Belt.List.some2", () => { - test("Belt.List.some2", () => { - module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ - } - () - }) -}) - -describe("Belt.List.sort", () => { - test("Belt.List.sort", () => { - module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} - } - () - }) -}) - -describe("Belt.List.splitAt", () => { - test("Belt.List.splitAt", () => { - module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) - } - () - }) -}) - -describe("Belt.List.tail", () => { - test("Belt.List.tail", () => { - module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - - Belt.List.tail(list{}) // None - } - () - }) -}) - -describe("Belt.List.tailExn", () => { - test("Belt.List.tailExn", () => { - module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt.List.take", () => { - test("Belt.List.take", () => { - module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->Belt.List.take(4) // None - } - () - }) -}) - -describe("Belt.List.toArray", () => { - test("Belt.List.toArray", () => { - module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] - } - () - }) -}) - -describe("Belt.List.unzip", () => { - test("Belt.List.unzip", () => { - module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ - - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ - } - () - }) -}) - -describe("Belt.List.zip", () => { - test("Belt.List.zip", () => { - module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} - } - () - }) -}) - -describe("Belt.List.zipBy", () => { - test("Belt.List.zipBy", () => { - module Test = { - Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} - } - () - }) -}) - -describe("Belt.Map.Dict.findFirstBy", () => { - test("Belt.Map.Dict.findFirstBy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) - } - () - }) -}) - -describe("Belt.Map.Int", () => { - test("Belt.Map.Int", () => { - module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> - } - () - }) -}) - -describe("Belt.Map.Int.findFirstBy", () => { - test("Belt.Map.Int.findFirstBy", () => { - module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) - } - () - }) -}) - -describe("Belt.Map.String.findFirstBy", () => { - test("Belt.Map.String.findFirstBy", () => { - module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) - } - () - }) -}) - -describe("Belt.Map.findFirstBy", () => { - test("Belt.Map.findFirstBy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) - } - () - }) -}) - -describe("Belt.Map.forEach", () => { - test("Belt.Map.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - let acc = ref(list{}) - - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) - - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} - } - () - }) -}) - -describe("Belt.Map.fromArray", () => { - test("Belt.Map.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] - } - () - }) -}) - -describe("Belt.Map.get", () => { - test("Belt.Map.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None - } - () - }) -}) - -describe("Belt.Map.has", () => { - test("Belt.Map.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true - } - () - }) -}) - -describe("Belt.Map.isEmpty", () => { - test("Belt.Map.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false - } - () - }) -}) - -describe("Belt.Map.keysToArray", () => { - test("Belt.Map.keysToArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] - } - () - }) -}) - -describe("Belt.Map.make", () => { - test("Belt.Map.make", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let m = Belt.Map.make(~id=module(IntCmp)) - - Belt.Map.set(m, 0, "a") - } - () - }) -}) - -describe("Belt.Map.reduce", () => { - test("Belt.Map.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) - - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ - } - () - }) -}) - -describe("Belt.Map.remove", () => { - test("Belt.Map.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) - - s1 === s2 - - Belt.Map.keysToArray(s1) == [2, 3] - } - () - }) -}) - -describe("Belt.Map.set", () => { - test("Belt.Map.set", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.set(s0, 2, "3") - - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] - } - () - }) -}) - -describe("Belt.Map.size", () => { - test("Belt.Map.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 - } - () - }) -}) - -describe("Belt.Map.toArray", () => { - test("Belt.Map.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] - } - () - }) -}) - -describe("Belt.Map.valuesToArray", () => { - test("Belt.Map.valuesToArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] - } - () - }) -}) - -describe("Belt.MutableSet", () => { - test("Belt.MutableSet", () => { - module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) - - let mySet = Belt.MutableSet.make(~id=module(PairComparator)) - mySet->Belt.MutableSet.add((1, 2)) - } - () - }) -}) - -describe("Belt.MutableSet.add", () => { - test("Belt.MutableSet.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ - } - () - }) -}) - -describe("Belt.MutableSet.copy", () => { - test("Belt.MutableSet.copy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt.MutableSet.diff", () => { - test("Belt.MutableSet.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ - } - () - }) -}) - -describe("Belt.MutableSet.eq", () => { - test("Belt.MutableSet.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.MutableSet.eq(s0, s1) /* true */ - } - () - }) -}) - -describe("Belt.MutableSet.every", () => { - test("Belt.MutableSet.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ - } - () - }) -}) - -describe("Belt.MutableSet.forEach", () => { - test("Belt.MutableSet.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt.MutableSet.fromArray", () => { - test("Belt.MutableSet.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt.MutableSet.get", () => { - test("Belt.MutableSet.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ - } - () - }) -}) - -describe("Belt.MutableSet.has", () => { - test("Belt.MutableSet.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ - } - () - }) -}) - -describe("Belt.MutableSet.intersect", () => { - test("Belt.MutableSet.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ - } - () - }) -}) - -describe("Belt.MutableSet.isEmpty", () => { - test("Belt.MutableSet.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ - } - () - }) -}) - -describe("Belt.MutableSet.keep", () => { - test("Belt.MutableSet.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ - } - () - }) -}) - -describe("Belt.MutableSet.maxUndefined", () => { - test("Belt.MutableSet.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ - } - () - }) -}) - -describe("Belt.MutableSet.maximum", () => { - test("Belt.MutableSet.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ - } - () - }) -}) - -describe("Belt.MutableSet.mergeMany", () => { - test("Belt.MutableSet.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.make(~id=module(IntCmp)) - - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ - } - () - }) -}) - -describe("Belt.MutableSet.minUndefined", () => { - test("Belt.MutableSet.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ - } - () - }) -}) - -describe("Belt.MutableSet.minimum", () => { - test("Belt.MutableSet.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ - } - () - }) -}) - -describe("Belt.MutableSet.partition", () => { - test("Belt.MutableSet.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt.MutableSet.reduce", () => { - test("Belt.MutableSet.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt.MutableSet.remove", () => { - test("Belt.MutableSet.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) - - s0->Belt.MutableSet.toArray /* [2,4,5] */ - } - () - }) -}) - -describe("Belt.MutableSet.removeMany", () => { - test("Belt.MutableSet.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ - } - () - }) -}) - -describe("Belt.MutableSet.size", () => { - test("Belt.MutableSet.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ - } - () - }) -}) - -describe("Belt.MutableSet.some", () => { - test("Belt.MutableSet.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ - } - () - }) -}) - -describe("Belt.MutableSet.split", () => { - test("Belt.MutableSet.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) - - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ - } - () - }) -}) - -describe("Belt.MutableSet.subset", () => { - test("Belt.MutableSet.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ - } - () - }) -}) - -describe("Belt.MutableSet.toArray", () => { - test("Belt.MutableSet.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt.MutableSet.toList", () => { - test("Belt.MutableSet.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toList /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt.MutableSet.union", () => { - test("Belt.MutableSet.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ - } - () - }) -}) - -describe("Belt.Option", () => { - test("Belt.Option", () => { - module Test = { - type option<'a> = None | Some('a) - - let someString: option = Some("hello") - } - () - }) -}) - -describe("Belt.Option.cmp", () => { - test("Belt.Option.cmp", () => { - module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ - - cmp(Some(14), None, clockCompare) /* 1 */ - - cmp(None, None, clockCompare) /* 0 */ - } - () - }) -}) - -describe("Belt.Option.eq", () => { - test("Belt.Option.eq", () => { - module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Belt.Option - - eq(Some(3), Some(15), clockEqual) /* true */ - - eq(Some(3), None, clockEqual) /* false */ - - eq(None, Some(3), clockEqual) /* false */ - - eq(None, None, clockEqual) /* true */ - } - () - }) -}) - -describe("Belt.Option.flatMap", () => { - test("Belt.Option.flatMap", () => { - module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ - } - () - }) -}) - -describe("Belt.Option.forEach", () => { - test("Belt.Option.forEach", () => { - module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ - } - () - }) -}) - -describe("Belt.Option.getExn", () => { - test("Belt.Option.getExn", () => { - module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) - - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt.Option.getWithDefault", () => { - test("Belt.Option.getWithDefault", () => { - module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ - } - () - }) -}) - -describe("Belt.Option.isNone", () => { - test("Belt.Option.isNone", () => { - module Test = { - Belt.Option.isNone(None) /* true */ - - Belt.Option.isNone(Some(1)) /* false */ - } - () - }) -}) - -describe("Belt.Option.isSome", () => { - test("Belt.Option.isSome", () => { - module Test = { - Belt.Option.isSome(None) /* false */ - - Belt.Option.isSome(Some(1)) /* true */ - } - () - }) -}) - -describe("Belt.Option.keep", () => { - test("Belt.Option.keep", () => { - module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ - } - () - }) -}) - -describe("Belt.Option.map", () => { - test("Belt.Option.map", () => { - module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ - - Belt.Option.map(None, x => x * x) /* None */ - } - () - }) -}) - -describe("Belt.Option.mapWithDefault", () => { - test("Belt.Option.mapWithDefault", () => { - module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ - } - () - }) -}) - -describe("Belt.Option.orElse", () => { - test("Belt.Option.orElse", () => { - module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None - } - () - }) -}) - -describe("Belt.Range.every", () => { - test("Belt.Range.every", () => { - module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ - - Belt.Range.every(0, 4, i => i < 4) /* false */ - } - () - }) -}) - -describe("Belt.Range.everyBy", () => { - test("Belt.Range.everyBy", () => { - module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ - - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt.Range.forEach", () => { - test("Belt.Range.forEach", () => { - module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) - - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 - } - () - }) -}) - -describe("Belt.Range.some", () => { - test("Belt.Range.some", () => { - module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ - - Belt.Range.some(0, 4, i => i > 2) /* true */ - } - () - }) -}) - -describe("Belt.Range.someBy", () => { - test("Belt.Range.someBy", () => { - module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt.Result.cmp", () => { - test("Belt.Result.cmp", () => { - module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 - - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 - } - () - }) -}) - -describe("Belt.Result.eq", () => { - test("Belt.Result.eq", () => { - module Test = { - let good1 = Belt.Result.Ok(42) - - let good2 = Belt.Result.Ok(32) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(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 - } - () - }) -}) - -describe("Belt.Result.flatMap", () => { - test("Belt.Result.flatMap", () => { - module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } - - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") - } - () - }) -}) - -describe("Belt.Result.getExn", () => { - test("Belt.Result.getExn", () => { - module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) - - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt.Result.getWithDefault", () => { - test("Belt.Result.getWithDefault", () => { - module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 - - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 - } - () - }) -}) - -describe("Belt.Result.map", () => { - test("Belt.Result.map", () => { - module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) - - Belt.Result.map(Ok(64), f) == Ok(8.0) - - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") - } - () - }) -}) - -describe("Belt.Result.mapWithDefault", () => { - test("Belt.Result.mapWithDefault", () => { - module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 - } - () - }) -}) - -describe("Belt.Set", () => { - test("Belt.Set", () => { - module Test = { - module PairComparator = Belt.Id.MakeComparable({ - type t = (int, int) - let cmp = ((a0, a1), (b0, b1)) => - switch Pervasives.compare(a0, b0) { - | 0 => Pervasives.compare(a1, b1) - | c => c - } - }) - - let mySet = Belt.Set.make(~id=module(PairComparator)) - let mySet2 = Belt.Set.add(mySet, (1, 2)) - - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - } - () - }) -}) - -describe("Belt.Set.Dict.add", () => { - test("Belt.Set.Dict.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.diff", () => { - test("Belt.Set.Dict.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ - } - () - }) -}) - -describe("Belt.Set.Dict.empty", () => { - test("Belt.Set.Dict.empty", () => { - module Test = { - let s0 = Belt.Set.Dict.empty - } - () - }) -}) - -describe("Belt.Set.Dict.eq", () => { - test("Belt.Set.Dict.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.every", () => { - test("Belt.Set.Dict.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.forEach", () => { - test("Belt.Set.Dict.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt.Set.Dict.fromArray", () => { - test("Belt.Set.Dict.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt.Set.Dict.get", () => { - test("Belt.Set.Dict.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ - } - () - }) -}) - -describe("Belt.Set.Dict.has", () => { - test("Belt.Set.Dict.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.intersect", () => { - test("Belt.Set.Dict.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ - } - () - }) -}) - -describe("Belt.Set.Dict.isEmpty", () => { - test("Belt.Set.Dict.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ - } - () - }) -}) - -describe("Belt.Set.Dict.keep", () => { - test("Belt.Set.Dict.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt.Set.Dict.maxUndefined", () => { - test("Belt.Set.Dict.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ - } - () - }) -}) - -describe("Belt.Set.Dict.maximum", () => { - test("Belt.Set.Dict.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ - } - () - }) -}) - -describe("Belt.Set.Dict.mergeMany", () => { - test("Belt.Set.Dict.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty - - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ - } - () - }) -}) - -describe("Belt.Set.Dict.minUndefined", () => { - test("Belt.Set.Dict.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ - } - () - }) -}) - -describe("Belt.Set.Dict.minimum", () => { - test("Belt.Set.Dict.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ - } - () - }) -}) - -describe("Belt.Set.Dict.partition", () => { - test("Belt.Set.Dict.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) - - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt.Set.Dict.reduce", () => { - test("Belt.Set.Dict.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt.Set.Dict.remove", () => { - test("Belt.Set.Dict.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.removeMany", () => { - test("Belt.Set.Dict.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ - } - () - }) -}) - -describe("Belt.Set.Dict.size", () => { - test("Belt.Set.Dict.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ - } - () - }) -}) - -describe("Belt.Set.Dict.some", () => { - test("Belt.Set.Dict.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ - } - () - }) -}) - -describe("Belt.Set.Dict.split", () => { - test("Belt.Set.Dict.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ - } - () - }) -}) - -describe("Belt.Set.Dict.subset", () => { - test("Belt.Set.Dict.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ - } - () - }) -}) - -describe("Belt.Set.Dict.toArray", () => { - test("Belt.Set.Dict.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt.Set.Dict.toList", () => { - test("Belt.Set.Dict.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt.Set.Dict.union", () => { - test("Belt.Set.Dict.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ - } - () - }) -}) - -describe("Belt.Set.add", () => { - test("Belt.Set.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) - - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) - } - () - }) -}) - -describe("Belt.Set.diff", () => { - test("Belt.Set.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - Belt.Set.diff(s0, s1) - ->Belt.Set.toArray - ->assertEqual([6]) - - Belt.Set.diff(s1, s0) - ->Belt.Set.toArray - ->assertEqual([1, 4]) - } - () - }) -}) - -describe("Belt.Set.eq", () => { - test("Belt.Set.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.Set.eq(s0, s1)->assertEqual(true) - } - () - }) -}) - -describe("Belt.Set.every", () => { - test("Belt.Set.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) - } - () - }) -}) - -describe("Belt.Set.forEach", () => { - test("Belt.Set.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - - let acc = ref(list{}) - - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) - }, - ) - - acc.contents->assertEqual(list{6, 5, 3, 2}) - } - () - }) -}) - -describe("Belt.Set.fromArray", () => { - test("Belt.Set.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) - } - () - }) -}) - -describe("Belt.Set.get", () => { - test("Belt.Set.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) - } - () - }) -}) - -describe("Belt.Set.has", () => { - test("Belt.Set.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) - } - () - }) -}) - -describe("Belt.Set.intersect", () => { - test("Belt.Set.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - let intersect = Belt.Set.intersect(s0, s1) - - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) - } - () - }) -}) - -describe("Belt.Set.isEmpty", () => { - test("Belt.Set.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) - - Belt.Set.isEmpty(empty)->assertEqual(true) - Belt.Set.isEmpty(notEmpty)->assertEqual(false) - } - () - }) -}) - -describe("Belt.Set.keep", () => { - test("Belt.Set.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.keep(isEven) - - s1->Belt.Set.toArray->assertEqual([2, 4]) - } - () - }) -}) - -describe("Belt.Set.make", () => { - test("Belt.Set.make", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) - - Belt.Set.isEmpty(set)->assertEqual(true) - } - () - }) -}) - -describe("Belt.Set.maxUndefined", () => { - test("Belt.Set.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) - - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) - } - () - }) -}) - -describe("Belt.Set.maximum", () => { - test("Belt.Set.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.maximum->assertEqual(None) - s1->Belt.Set.maximum->assertEqual(Some(5)) - } - () - }) -}) - -describe("Belt.Set.mergeMany", () => { - test("Belt.Set.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) - - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) - } - () - }) -}) - -describe("Belt.Set.minUndefined", () => { - test("Belt.Set.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt.Set.minimum", () => { - test("Belt.Set.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt.Set.partition", () => { - test("Belt.Set.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) - - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) - } - () - }) -}) - -describe("Belt.Set.reduce", () => { - test("Belt.Set.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) - } - () - }) -}) - -describe("Belt.Set.remove", () => { - test("Belt.Set.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) - - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) - } - () - }) -}) - -describe("Belt.Set.removeMany", () => { - test("Belt.Set.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([]) - } - () - }) -}) - -describe("Belt.Set.size", () => { - test("Belt.Set.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.Set.size->assertEqual(4) - } - () - }) -}) - -describe("Belt.Set.some", () => { - test("Belt.Set.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) - } - () - }) -}) - -describe("Belt.Set.split", () => { - test("Belt.Set.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.Set.split(3) - - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) - } - () - }) -}) - -describe("Belt.Set.subset", () => { - test("Belt.Set.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) - - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) - } - () - }) -}) - -describe("Belt.Set.toArray", () => { - test("Belt.Set.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) - } - () - }) -}) - -describe("Belt.Set.toList", () => { - test("Belt.Set.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) - } - () - }) -}) - -describe("Belt.Set.union", () => { - test("Belt.Set.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) - - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) - } - () - }) -}) - -describe("Belt.SortArray.binarySearchBy", () => { - test("Belt.SortArray.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 - } - () - }) -}) - -describe("Belt.SortArray.strictlySortedLength", () => { - test("Belt.SortArray.strictlySortedLength", () => { - module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 - } - () - }) -}) - -describe("Belt_Array.blit", () => { - test("Belt_Array.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt_Array.cmp", () => { - test("Belt_Array.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt_Array.concat", () => { - test("Belt_Array.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt_Array.concatMany", () => { - test("Belt_Array.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt_Array.eq", () => { - test("Belt_Array.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt_Array.every", () => { - test("Belt_Array.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_Array.every2", () => { - test("Belt_Array.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_Array.fill", () => { - test("Belt_Array.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt_Array.flatMap", () => { - test("Belt_Array.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt_Array.forEach", () => { - test("Belt_Array.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt_Array.forEachWithIndex", () => { - test("Belt_Array.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt_Array.get", () => { - test("Belt_Array.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt_Array.getBy", () => { - test("Belt_Array.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_Array.getIndexBy", () => { - test("Belt_Array.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_Array.joinWith", () => { - test("Belt_Array.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt_Array.keepMap", () => { - test("Belt_Array.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt_Array.keepWithIndex", () => { - test("Belt_Array.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt_Array.length", () => { - test("Belt_Array.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt_Array.makeBy", () => { - test("Belt_Array.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt_Array.makeUninitialized", () => { - test("Belt_Array.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt_Array.makeUninitializedUnsafe", () => { - test("Belt_Array.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt_Array.map", () => { - test("Belt_Array.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt_Array.mapWithIndex", () => { - test("Belt_Array.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt_Array.partition", () => { - test("Belt_Array.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt_Array.range", () => { - test("Belt_Array.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt_Array.rangeBy", () => { - test("Belt_Array.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt_Array.reduce", () => { - test("Belt_Array.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_Array.reduceReverse", () => { - test("Belt_Array.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt_Array.reduceReverse2", () => { - test("Belt_Array.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt_Array.reduceWithIndex", () => { - test("Belt_Array.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt_Array.reverse", () => { - test("Belt_Array.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_Array.reverseInPlace", () => { - test("Belt_Array.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_Array.slice", () => { - test("Belt_Array.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt_Array.sliceToEnd", () => { - test("Belt_Array.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt_Array.some", () => { - test("Belt_Array.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_Array.some2", () => { - test("Belt_Array.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_Array.truncateToLengthUnsafe", () => { - test("Belt_Array.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt_Array.unzip", () => { - test("Belt_Array.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt_Array.zip", () => { - test("Belt_Array.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt_Array.zipBy", () => { - test("Belt_Array.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("Belt_Float.*", () => { - test("Belt_Float.*", () => { - module Test = { - open Belt.Float - assertEqual(2.0 * 2.0, 4.0) - } - () - }) -}) - -describe("Belt_Float.+", () => { - test("Belt_Float.+", () => { - module Test = { - open Belt.Float - assertEqual(2.0 + 2.0, 4.0) - } - () - }) -}) - -describe("Belt_Float.-", () => { - test("Belt_Float.-", () => { - module Test = { - open Belt.Float - assertEqual(2.0 - 1.0, 1.0) - } - () - }) -}) - -describe("Belt_Float./", () => { - test("Belt_Float./", () => { - module Test = { - open Belt.Float - assertEqual(4.0 / 2.0, 2.0) - } - () - }) -}) - -describe("Belt_Float.fromInt", () => { - test("Belt_Float.fromInt", () => { - module Test = { - Js.log(Belt.Float.fromInt(1) === 1.0) /* true */ - } - () - }) -}) - -describe("Belt_Float.fromString", () => { - test("Belt_Float.fromString", () => { - module Test = { - Js.log(Belt.Float.fromString("1.0") === Some(1.0)) /* true */ - } - () - }) -}) - -describe("Belt_Float.toInt", () => { - test("Belt_Float.toInt", () => { - module Test = { - Js.log(Belt.Float.toInt(1.0) === 1) /* true */ - } - () - }) -}) - -describe("Belt_Float.toString", () => { - test("Belt_Float.toString", () => { - module Test = { - Js.log(Belt.Float.toString(1.0) === "1.0") /* true */ - } - () - }) -}) - -describe("Belt_HashMap.clear", () => { - test("Belt_HashMap.clear", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash)) - Belt.HashMap.clear(hMap) - Belt.HashMap.isEmpty(hMap) == true - } - () - }) -}) - -describe("Belt_HashMap.copy", () => { - test("Belt_HashMap.copy", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - let s1 = Belt.HashMap.copy(s0) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.get(s0, 2) != Belt.HashMap.get(s1, 2) - } - () - }) -}) - -describe("Belt_HashMap.forEach", () => { - test("Belt_HashMap.forEach", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.forEach(s0, (key, value) => Js.log2(key, value)) - // prints (1, "value1") - } - () - }) -}) - -describe("Belt_HashMap.fromArray", () => { - test("Belt_HashMap.fromArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(1, "value1"), (2, "value2")], ~id=module(IntHash)) - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] - } - () - }) -}) - -describe("Belt_HashMap.get", () => { - test("Belt_HashMap.get", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.get(s0, 1) == Some("value1") - Belt.HashMap.get(s0, 2) == None - } - () - }) -}) - -describe("Belt_HashMap.getBucketHistogram", () => { - test("Belt_HashMap.getBucketHistogram", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.getBucketHistogram(hMap) - } - () - }) -}) - -describe("Belt_HashMap.has", () => { - test("Belt_HashMap.has", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - - Belt.HashMap.has(s0, 1) == true - Belt.HashMap.has(s0, 2) == false - } - () - }) -}) - -describe("Belt_HashMap.isEmpty", () => { - test("Belt_HashMap.isEmpty", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - Belt.HashMap.isEmpty(Belt.HashMap.fromArray([(1, "1")], ~id=module(IntHash))) == false - } - () - }) -}) - -describe("Belt_HashMap.keepMapInPlace", () => { - test("Belt_HashMap.keepMapInPlace", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keepMapInPlace(s0, (key, value) => key == 1 ? None : Some(value)) - } - () - }) -}) - -describe("Belt_HashMap.keysToArray", () => { - test("Belt_HashMap.keysToArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.keysToArray(s0) == [1, 2] - } - () - }) -}) - -describe("Belt_HashMap.logStats", () => { - test("Belt_HashMap.logStats", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(hMap, 1, "1") - - Belt.HashMap.logStats(hMap) - } - () - }) -}) - -describe("Belt_HashMap.make", () => { - test("Belt_HashMap.make", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(hMap, 0, "a") - } - () - }) -}) - -describe("Belt_HashMap.mergeMany", () => { - test("Belt_HashMap.mergeMany", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let hMap = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.mergeMany(hMap, [(1, "1"), (2, "2")]) - } - () - }) -}) - -describe("Belt_HashMap.reduce", () => { - test("Belt_HashMap.reduce", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - s0 - ->Belt.HashMap.reduce("", (acc, _, value) => acc ++ (", " ++ value)) - ->assertEqual(", value1, value2") - - Console.log("lol") - } - () - }) -}) - -describe("Belt_HashMap.remove", () => { - test("Belt_HashMap.remove", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.remove(s0, 1) - Belt.HashMap.has(s0, 1) == false - } - () - }) -}) - -describe("Belt_HashMap.set", () => { - test("Belt_HashMap.set", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntHash)) - - Belt.HashMap.set(s0, 2, "3") - - Belt.HashMap.valuesToArray(s0) == ["1", "3", "3"] - } - () - }) -}) - -describe("Belt_HashMap.size", () => { - test("Belt_HashMap.size", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.size(s0) == 2 - } - () - }) -}) - -describe("Belt_HashMap.toArray", () => { - test("Belt_HashMap.toArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.toArray(s0) == [(1, "value1"), (2, "value2")] - } - () - }) -}) - -describe("Belt_HashMap.valuesToArray", () => { - test("Belt_HashMap.valuesToArray", () => { - module Test = { - module IntHash = Belt.Id.MakeHashable({ - type t = int - let hash = a => a - let eq = (a, b) => a == b - }) - - let s0 = Belt.HashMap.make(~hintSize=10, ~id=module(IntHash)) - Belt.HashMap.set(s0, 1, "value1") - Belt.HashMap.set(s0, 2, "value2") - - Belt.HashMap.valuesToArray(s0) == ["value1", "value2"] - } - () - }) -}) - -describe("Belt_Int.*", () => { - test("Belt_Int.*", () => { - module Test = { - open Belt.Int - assertEqual(2 * 2, 4) - } - () - }) -}) - -describe("Belt_Int.+", () => { - test("Belt_Int.+", () => { - module Test = { - open Belt.Int - assertEqual(2 + 2, 4) - } - () - }) -}) - -describe("Belt_Int.-", () => { - test("Belt_Int.-", () => { - module Test = { - open Belt.Int - assertEqual(2 - 1, 1) - } - () - }) -}) - -describe("Belt_Int./", () => { - test("Belt_Int./", () => { - module Test = { - open Belt.Int - assertEqual(4 / 2, 2) - } - () - }) -}) - -describe("Belt_Int.fromFloat", () => { - test("Belt_Int.fromFloat", () => { - module Test = { - Belt.Int.fromFloat(1.0)->assertEqual(1) - } - () - }) -}) - -describe("Belt_Int.fromString", () => { - test("Belt_Int.fromString", () => { - module Test = { - Belt.Int.fromString("1")->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt_Int.toFloat", () => { - test("Belt_Int.toFloat", () => { - module Test = { - Belt.Int.toFloat(1)->assertEqual(1.0) - } - () - }) -}) - -describe("Belt_Int.toString", () => { - test("Belt_Int.toString", () => { - module Test = { - Belt.Int.toString(1)->assertEqual("1") - } - () - }) -}) - -describe("Belt_List.add", () => { - test("Belt_List.add", () => { - module Test = { - Belt.List.add(list{2, 3}, 1) // list{1, 2, 3} - - Belt.List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} - } - () - }) -}) - -describe("Belt_List.cmp", () => { - test("Belt_List.cmp", () => { - module Test = { - Belt.List.cmp(list{3}, list{3, 7}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{5, 3}, list{5}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 4, 2}, (a, b) => compare(a, b)) /* (-1) */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 2, 3}, (a, b) => compare(a, b)) /* 1 */ - - Belt.List.cmp(list{1, 3, 5}, list{1, 3, 5}, (a, b) => compare(a, b)) /* 0 */ - } - () - }) -}) - -describe("Belt_List.cmpByLength", () => { - test("Belt_List.cmpByLength", () => { - module Test = { - Belt.List.cmpByLength(list{1, 2}, list{3, 4, 5, 6}) /* -1 */ - - Belt.List.cmpByLength(list{1, 2, 3}, list{4, 5, 6}) /* = 0 */ - - Belt.List.cmpByLength(list{1, 2, 3, 4}, list{5, 6}) /* = 1 */ - } - () - }) -}) - -describe("Belt_List.concat", () => { - test("Belt_List.concat", () => { - module Test = { - Belt.List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} - } - () - }) -}) - -describe("Belt_List.concatMany", () => { - test("Belt_List.concatMany", () => { - module Test = { - Belt.List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("Belt_List.drop", () => { - test("Belt_List.drop", () => { - module Test = { - list{1, 2, 3}->Belt.List.drop(2) // Some(list{3}) - - list{1, 2, 3}->Belt.List.drop(3) // Some(list{}) - - list{1, 2, 3}->Belt.List.drop(4) // None - } - () - }) -}) - -describe("Belt_List.eq", () => { - test("Belt_List.eq", () => { - module Test = { - Belt.List.eq(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) /* false */ - - Belt.List.eq(list{1, 2}, list{1, 2}, (a, b) => a == b) /* true */ - - Belt.List.eq(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) /* true */ - } - () - }) -}) - -describe("Belt_List.every", () => { - test("Belt_List.every", () => { - module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->Belt.List.every(isBelow10) /* true */ - - list{1, 99, 8, 2}->Belt.List.every(isBelow10) /* false */ - } - () - }) -}) - -describe("Belt_List.every2", () => { - test("Belt_List.every2", () => { - module Test = { - Belt.List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* false */ - } - () - }) -}) - -describe("Belt_List.filter", () => { - test("Belt_List.filter", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filter(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.filter( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ - } - () - }) -}) - -describe("Belt_List.filterWithIndex", () => { - test("Belt_List.filterWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) - -describe("Belt_List.flatten", () => { - test("Belt_List.flatten", () => { - module Test = { - Belt.List.flatten(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("Belt_List.forEach", () => { - test("Belt_List.forEach", () => { - module Test = { - Belt.List.forEach(list{"a", "b", "c"}, x => Js.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ - } - () - }) -}) - -describe("Belt_List.forEach2", () => { - test("Belt_List.forEach2", () => { - module Test = { - Belt.List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Js.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ - } - () - }) -}) - -describe("Belt_List.forEachWithIndex", () => { - test("Belt_List.forEachWithIndex", () => { - module Test = { - Belt.List.forEachWithIndex( - list{"a", "b", "c"}, - (index, x) => { - Js.log("Item " ++ Belt.Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - } - () - }) -}) - -describe("Belt_List.fromArray", () => { - test("Belt_List.fromArray", () => { - module Test = { - Belt.List.fromArray([1, 2, 3]) // list{1, 2, 3} - } - () - }) -}) - -describe("Belt_List.get", () => { - test("Belt_List.get", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.get(1) // Some("B") - - abc->Belt.List.get(4) // None - } - () - }) -}) - -describe("Belt_List.getAssoc", () => { - test("Belt_List.getAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.getAssoc(3, (a, b) => a == b) /* Some("c") */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - /* Some("afternoon") */ - } - () - }) -}) - -describe("Belt_List.getBy", () => { - test("Belt_List.getBy", () => { - module Test = { - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 3) /* Some(4) */ - - Belt.List.getBy(list{1, 4, 3, 2}, x => x > 4) /* None */ - } - () - }) -}) - -describe("Belt_List.getExn", () => { - test("Belt_List.getExn", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc->Belt.List.getExn(1)->assertEqual("B") - - switch abc->Belt.List.getExn(4) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt_List.has", () => { - test("Belt_List.has", () => { - module Test = { - list{1, 2, 3}->Belt.List.has(2, (a, b) => a == b) /* true */ - - list{1, 2, 3}->Belt.List.has(4, (a, b) => a == b) /* false */ - - list{-1, -2, -3}->Belt.List.has(2, (a, b) => abs(a) == abs(b)) /* true */ - } - () - }) -}) - -describe("Belt_List.hasAssoc", () => { - test("Belt_List.hasAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.hasAssoc(1, (a, b) => a == b) /* true */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) /* false */ - } - () - }) -}) - -describe("Belt_List.head", () => { - test("Belt_List.head", () => { - module Test = { - Belt.List.head(list{}) // None - Belt.List.head(list{1, 2, 3}) // Some(1) - } - () - }) -}) - -describe("Belt_List.headExn", () => { - test("Belt_List.headExn", () => { - module Test = { - Belt.List.headExn(list{1, 2, 3})->assertEqual(1) - - switch Belt.List.headExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt_List.keep", () => { - test("Belt_List.keep", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keep(list{1, 2, 3, 4}, isEven) /* list{2, 4} */ - - Belt.List.keep( - list{None, Some(2), Some(3), None}, - Belt.Option.isSome, - ) /* list{Some(2), Some(3)} */ - } - () - }) -}) - -describe("Belt_List.keepMap", () => { - test("Belt_List.keepMap", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->Belt.List.keepMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) /* list{2, 4} */ - - list{Some(1), Some(2), None}->Belt.List.keepMap(x => x) /* list{1, 2} */ - } - () - }) -}) - -describe("Belt_List.keepWithIndex", () => { - test("Belt_List.keepWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - Belt.List.keepWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) /* list{1, 3} */ - } - () - }) -}) - -describe("Belt_List.length", () => { - test("Belt_List.length", () => { - module Test = { - Belt.List.length(list{1, 2, 3}) // 3 - } - () - }) -}) - -describe("Belt_List.make", () => { - test("Belt_List.make", () => { - module Test = { - Belt.List.make(3, 1) // list{1, 1, 1} - } - () - }) -}) - -describe("Belt_List.makeBy", () => { - test("Belt_List.makeBy", () => { - module Test = { - Belt.List.makeBy(5, i => i) // list{0, 1, 2, 3, 4} - - Belt.List.makeBy(5, i => i * i) // list{0, 1, 4, 9, 16} - } - () - }) -}) - -describe("Belt_List.map", () => { - test("Belt_List.map", () => { - module Test = { - list{1, 2}->Belt.List.map(x => x + 1) // list{3, 4} - } - () - }) -}) - -describe("Belt_List.mapReverse", () => { - test("Belt_List.mapReverse", () => { - module Test = { - list{3, 4, 5} - ->Belt.List.mapReverse(x => x * x) - ->assertEqual(list{25, 16, 9}) - } - () - }) -}) - -describe("Belt_List.mapReverse2", () => { - test("Belt_List.mapReverse2", () => { - module Test = { - Belt.List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} - } - () - }) -}) - -describe("Belt_List.mapWithIndex", () => { - test("Belt_List.mapWithIndex", () => { - module Test = { - list{1, 2, 3}->Belt.List.mapWithIndex((index, x) => index + x) // list{1, 3, 5} - } - () - }) -}) - -describe("Belt_List.partition", () => { - test("Belt_List.partition", () => { - module Test = { - list{1, 2, 3, 4} - ->Belt.List.partition(x => x > 2) - ->assertEqual((list{3, 4}, list{1, 2})) - } - () - }) -}) - -describe("Belt_List.reduce", () => { - test("Belt_List.reduce", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduce(0, (a, b) => a + b) /* 10 */ - - /* same as */ - - list{1, 2, 3, 4}->Belt.List.reduce(0, (acc, item) => acc + item) /* 10 */ - } - () - }) -}) - -describe("Belt_List.reduce2", () => { - test("Belt_List.reduce2", () => { - module Test = { - Belt.List.reduce2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* 0 + (1 * 1 + 4) + (2 * 2 + 5) */ - } - () - }) -}) - -describe("Belt_List.reduceReverse", () => { - test("Belt_List.reduceReverse", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduceReverse(0, (a, b) => a + b) /* 10 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(10, (a, b) => a - b) /* 0 */ - - list{1, 2, 3, 4}->Belt.List.reduceReverse(list{}, Belt.List.add) // list{1, 2, 3, 4} - } - () - }) -}) - -describe("Belt_List.reduceReverse2", () => { - test("Belt_List.reduceReverse2", () => { - module Test = { - Belt.List.reduceReverse2( - list{1, 2, 3}, - list{4, 5}, - 0, - (acc, x, y) => acc + x * x + y, - ) /* + (1 * 1 + 4) + (2 * 2 + 5) */ - } - () - }) -}) - -describe("Belt_List.reduceWithIndex", () => { - test("Belt_List.reduceWithIndex", () => { - module Test = { - list{1, 2, 3, 4}->Belt.List.reduceWithIndex( - 0, - (acc, item, index) => acc + item + index, - ) /* 16 */ - } - () - }) -}) - -describe("Belt_List.removeAssoc", () => { - test("Belt_List.removeAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.removeAssoc( - 1, - (a, b) => a == b, - ) /* list{(2, "b"), (3, "c")} */ - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->Belt.List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - /* list{(15, "afternoon"), (22, "night")} */ - } - () - }) -}) - -describe("Belt_List.reverse", () => { - test("Belt_List.reverse", () => { - module Test = { - Belt.List.reverse(list{1, 2, 3}) /* list{3, 2, 1} */ - } - () - }) -}) - -describe("Belt_List.reverseConcat", () => { - test("Belt_List.reverseConcat", () => { - module Test = { - Belt.List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} - } - () - }) -}) - -describe("Belt_List.setAssoc", () => { - test("Belt_List.setAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->Belt.List.setAssoc( - 2, - "x", - (a, b) => a == b, - ) /* list{(1, "a"), (2, "x"), (3, "c")} */ - - list{(1, "a"), (3, "c")}->Belt.List.setAssoc( - 2, - "b", - (a, b) => a == b, - ) /* list{(2, "b"), (1, "a"), (3, "c")} */ - - list{(9, "morning"), (3, "morning?!"), (22, "night")}->Belt.List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - /* list{(9, "morning"), (15, "afternoon"), (22, "night")} */ - } - () - }) -}) - -describe("Belt_List.shuffle", () => { - test("Belt_List.shuffle", () => { - module Test = { - Belt.List.shuffle(list{1, 2, 3}) // list{2, 1, 3} - } - () - }) -}) - -describe("Belt_List.some", () => { - test("Belt_List.some", () => { - module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->Belt.List.some(isAbove100) /* true */ - - list{1, 2, 3, 4}->Belt.List.some(isAbove100) /* false */ - } - () - }) -}) - -describe("Belt_List.some2", () => { - test("Belt_List.some2", () => { - module Test = { - Belt.List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{}, list{1}, (a, b) => a > b) /* false */ - - Belt.List.some2(list{2, 3}, list{1}, (a, b) => a > b) /* true */ - - Belt.List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) /* true */ - } - () - }) -}) - -describe("Belt_List.sort", () => { - test("Belt_List.sort", () => { - module Test = { - Belt.List.sort(list{5, 4, 9, 3, 7}, (a, b) => a - b) // list{3, 4, 5, 7, 9} - } - () - }) -}) - -describe("Belt_List.splitAt", () => { - test("Belt_List.splitAt", () => { - module Test = { - list{"Hello", "World"}->Belt.List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - - list{0, 1, 2, 3, 4}->Belt.List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) - } - () - }) -}) - -describe("Belt_List.tail", () => { - test("Belt_List.tail", () => { - module Test = { - Belt.List.tail(list{1, 2, 3}) // Some(list{2, 3}) - - Belt.List.tail(list{}) // None - } - () - }) -}) - -describe("Belt_List.tailExn", () => { - test("Belt_List.tailExn", () => { - module Test = { - Belt.List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - - switch Belt.List.tailExn(list{}) { - // Raises an Error - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt_List.take", () => { - test("Belt_List.take", () => { - module Test = { - list{1, 2, 3}->Belt.List.take(1) // Some(list{1}) - - list{1, 2, 3}->Belt.List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->Belt.List.take(4) // None - } - () - }) -}) - -describe("Belt_List.toArray", () => { - test("Belt_List.toArray", () => { - module Test = { - Belt.List.toArray(list{1, 2, 3}) // [1, 2, 3] - } - () - }) -}) - -describe("Belt_List.unzip", () => { - test("Belt_List.unzip", () => { - module Test = { - Belt.List.unzip(list{(1, 2), (3, 4)}) /* (list{1, 3}, list{2, 4}) */ - - Belt.List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - /* (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) */ - } - () - }) -}) - -describe("Belt_List.zip", () => { - test("Belt_List.zip", () => { - module Test = { - Belt.List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} - } - () - }) -}) - -describe("Belt_List.zipBy", () => { - test("Belt_List.zipBy", () => { - module Test = { - Belt.List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} - } - () - }) -}) - -describe("Belt_Map.Dict.findFirstBy", () => { - test("Belt_Map.Dict.findFirstBy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) - } - () - }) -}) - -describe("Belt_Map.Int", () => { - test("Belt_Map.Int", () => { - module Test = { - type t<'key, 'value, 'identity> - type id<'key, 'id> = Belt_Id.comparable<'key, 'id> - } - () - }) -}) - -describe("Belt_Map.Int.findFirstBy", () => { - test("Belt_Map.Int.findFirstBy", () => { - module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) - } - () - }) -}) - -describe("Belt_Map.String.findFirstBy", () => { - test("Belt_Map.String.findFirstBy", () => { - module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) - } - () - }) -}) - -describe("Belt_Map.findFirstBy", () => { - test("Belt_Map.findFirstBy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - s0 - ->Belt.Map.findFirstBy((k, _) => k == 4) - ->assertEqual(Some(4, "4")) - } - () - }) -}) - -describe("Belt_Map.forEach", () => { - test("Belt_Map.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "")]) - - let acc = ref(list{}) - - Belt.Map.forEach(s0, (k, v) => acc := list{(k, v), ...acc.contents}) - - acc.contents == list{(4, "4"), (3, "3"), (2, "2"), (1, "1")} - } - () - }) -}) - -describe("Belt_Map.fromArray", () => { - test("Belt_Map.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] - } - () - }) -}) - -describe("Belt_Map.get", () => { - test("Belt_Map.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - Some("2") - - Belt.Map.get(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), 2) == - None - } - () - }) -}) - -describe("Belt_Map.has", () => { - test("Belt_Map.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.has(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp)), 1) == true - } - () - }) -}) - -describe("Belt_Map.isEmpty", () => { - test("Belt_Map.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.isEmpty(Belt.Map.fromArray([(1, "1")], ~id=module(IntCmp))) == false - } - () - }) -}) - -describe("Belt_Map.keysToArray", () => { - test("Belt_Map.keysToArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.keysToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == [1, 2, 3] - } - () - }) -}) - -describe("Belt_Map.make", () => { - test("Belt_Map.make", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let m = Belt.Map.make(~id=module(IntCmp)) - - Belt.Map.set(m, 0, "a") - } - () - }) -}) - -describe("Belt_Map.reduce", () => { - test("Belt_Map.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray(~id=module(IntCmp), [(4, "4"), (1, "1"), (2, "2"), (3, "3")]) - - Belt.Map.reduce( - s0, - list{}, - (acc, k, v) => list{(k, v), ...acc}, - ) /* [(4, "4"), (3, "3"), (2, "2"), (1, "1"), 0] */ - } - () - }) -}) - -describe("Belt_Map.remove", () => { - test("Belt_Map.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.remove(s0, 1) - - let s2 = Belt.Map.remove(s1, 1) - - s1 === s2 - - Belt.Map.keysToArray(s1) == [2, 3] - } - () - }) -}) - -describe("Belt_Map.set", () => { - test("Belt_Map.set", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - let s0 = Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)) - - let s1 = Belt.Map.set(s0, 2, "3") - - Belt.Map.valuesToArray(s1) == ["1", "3", "3"] - } - () - }) -}) - -describe("Belt_Map.size", () => { - test("Belt_Map.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.size(Belt.Map.fromArray([(2, "2"), (2, "1"), (3, "3")], ~id=module(IntCmp))) == 2 - } - () - }) -}) - -describe("Belt_Map.toArray", () => { - test("Belt_Map.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.toArray(Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp))) == [ - (1, "1"), - (2, "2"), - (3, "3"), - ] - } - () - }) -}) - -describe("Belt_Map.valuesToArray", () => { - test("Belt_Map.valuesToArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = (a, b) => Pervasives.compare(a, b) - }) - - Belt.Map.valuesToArray( - Belt.Map.fromArray([(2, "2"), (1, "1"), (3, "3")], ~id=module(IntCmp)), - ) == ["1", "2", "3"] - } - () - }) -}) - -describe("Belt_MapDict.findFirstBy", () => { - test("Belt_MapDict.findFirstBy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Map.Dict.fromArray([(4, "4"), (1, "1"), (2, "2"), (3, "3")], ~cmp=IntCmp.cmp) - - Belt.Map.Dict.findFirstBy(s0, (k, _) => k == 4) == Some((4, "4")) - } - () - }) -}) - -describe("Belt_MapInt.findFirstBy", () => { - test("Belt_MapInt.findFirstBy", () => { - module Test = { - let mapInt = Belt.Map.Int.fromArray([(1, "one"), (2, "two"), (3, "three")]) - - mapInt - ->Belt.Map.Int.findFirstBy((k, v) => k == 1 && v == "one") - ->assertEqual(Some(1, "one")) - } - () - }) -}) - -describe("Belt_MapString.findFirstBy", () => { - test("Belt_MapString.findFirstBy", () => { - module Test = { - let mapString = Belt.Map.String.fromArray([("1", "one"), ("2", "two"), ("3", "three")]) - - mapString - ->Belt.Map.String.findFirstBy((k, v) => k == "1" && v == "one") - ->assertEqual(Some("1", "one")) - } - () - }) -}) - -describe("Belt_MutableSet.add", () => { - test("Belt_MutableSet.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - s0->Belt.MutableSet.add(1) - s0->Belt.MutableSet.add(2) - s0->Belt.MutableSet.add(2) - - s0->Belt.MutableSet.toArray /* [1, 2] */ - } - () - }) -}) - -describe("Belt_MutableSet.copy", () => { - test("Belt_MutableSet.copy", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - let copied = s0->Belt.MutableSet.copy - copied->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt_MutableSet.diff", () => { - test("Belt_MutableSet.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - Belt.MutableSet.toArray(Belt.MutableSet.diff(s0, s1)) /* [6] */ - Belt.MutableSet.toArray(Belt.MutableSet.diff(s1, s0)) /* [1,4] */ - } - () - }) -}) - -describe("Belt_MutableSet.eq", () => { - test("Belt_MutableSet.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.MutableSet.eq(s0, s1) /* true */ - } - () - }) -}) - -describe("Belt_MutableSet.every", () => { - test("Belt_MutableSet.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.every(isEven) /* true */ - } - () - }) -}) - -describe("Belt_MutableSet.forEach", () => { - test("Belt_MutableSet.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let acc = ref(list{}) - s0->Belt.MutableSet.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_MutableSet.fromArray", () => { - test("Belt_MutableSet.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt_MutableSet.get", () => { - test("Belt_MutableSet.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.get(3) /* Some(3) */ - s0->Belt.MutableSet.get(20) /* None */ - } - () - }) -}) - -describe("Belt_MutableSet.has", () => { - test("Belt_MutableSet.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.MutableSet.has(3) /* false */ - set->Belt.MutableSet.has(1) /* true */ - } - () - }) -}) - -describe("Belt_MutableSet.intersect", () => { - test("Belt_MutableSet.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let intersect = Belt.MutableSet.intersect(s0, s1) - intersect->Belt.MutableSet.toArray /* [2,3,5] */ - } - () - }) -}) - -describe("Belt_MutableSet.isEmpty", () => { - test("Belt_MutableSet.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.MutableSet.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.MutableSet.fromArray([1], ~id=module(IntCmp)) - - Belt.MutableSet.isEmpty(empty) /* true */ - Belt.MutableSet.isEmpty(notEmpty) /* false */ - } - () - }) -}) - -describe("Belt_MutableSet.keep", () => { - test("Belt_MutableSet.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.MutableSet.keep(isEven) - - s1->Belt.MutableSet.toArray /* [2, 4] */ - } - () - }) -}) - -describe("Belt_MutableSet.maxUndefined", () => { - test("Belt_MutableSet.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maxUndefined /* undefined */ - s1->Belt.MutableSet.maxUndefined /* 5 */ - } - () - }) -}) - -describe("Belt_MutableSet.maximum", () => { - test("Belt_MutableSet.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.maximum /* None */ - s1->Belt.MutableSet.maximum /* Some(5) */ - } - () - }) -}) - -describe("Belt_MutableSet.mergeMany", () => { - test("Belt_MutableSet.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.make(~id=module(IntCmp)) - - set->Belt.MutableSet.mergeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [1, 2, 3, 4, 5] */ - } - () - }) -}) - -describe("Belt_MutableSet.minUndefined", () => { - test("Belt_MutableSet.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.minUndefined /* undefined */ - s1->Belt.MutableSet.minUndefined /* 1 */ - } - () - }) -}) - -describe("Belt_MutableSet.minimum", () => { - test("Belt_MutableSet.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.make(~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.minimum /* None */ - s1->Belt.MutableSet.minimum /* Some(1) */ - } - () - }) -}) - -describe("Belt_MutableSet.partition", () => { - test("Belt_MutableSet.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.MutableSet.partition(isOdd) - - s1->Belt.MutableSet.toArray /* [1,3,5] */ - s2->Belt.MutableSet.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt_MutableSet.reduce", () => { - test("Belt_MutableSet.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0->Belt.MutableSet.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_MutableSet.remove", () => { - test("Belt_MutableSet.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - s0->Belt.MutableSet.remove(1) - s0->Belt.MutableSet.remove(3) - s0->Belt.MutableSet.remove(3) - - s0->Belt.MutableSet.toArray /* [2,4,5] */ - } - () - }) -}) - -describe("Belt_MutableSet.removeMany", () => { - test("Belt_MutableSet.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - set->Belt.MutableSet.removeMany([5, 4, 3, 2, 1]) - set->Belt.MutableSet.toArray /* [] */ - } - () - }) -}) - -describe("Belt_MutableSet.size", () => { - test("Belt_MutableSet.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.MutableSet.size /* 4 */ - } - () - }) -}) - -describe("Belt_MutableSet.some", () => { - test("Belt_MutableSet.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.MutableSet.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.MutableSet.some(isOdd) /* true */ - } - () - }) -}) - -describe("Belt_MutableSet.split", () => { - test("Belt_MutableSet.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.MutableSet.split(3) - - present /* true */ - smaller->Belt.MutableSet.toArray /* [1,2] */ - larger->Belt.MutableSet.toArray /* [4,5] */ - } - () - }) -}) - -describe("Belt_MutableSet.subset", () => { - test("Belt_MutableSet.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.MutableSet.intersect(s0, s1) - Belt.MutableSet.subset(s2, s0) /* true */ - Belt.MutableSet.subset(s2, s1) /* true */ - Belt.MutableSet.subset(s1, s0) /* false */ - } - () - }) -}) - -describe("Belt_MutableSet.toArray", () => { - test("Belt_MutableSet.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toArray /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_MutableSet.toList", () => { - test("Belt_MutableSet.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.MutableSet.toList /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_MutableSet.union", () => { - test("Belt_MutableSet.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.MutableSet.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.MutableSet.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.MutableSet.union(s0, s1) - union->Belt.MutableSet.toArray /* [1,2,3,4,5,6] */ - } - () - }) -}) - -describe("Belt_Option.cmp", () => { - test("Belt_Option.cmp", () => { - module Test = { - let clockCompare = (a, b) => compare(mod(a, 12), mod(b, 12)) - - open Belt.Option - - cmp(Some(3), Some(15), clockCompare) /* 0 */ - - cmp(Some(3), Some(14), clockCompare) /* 1 */ - - cmp(Some(2), Some(15), clockCompare) /* (-1) */ - - cmp(None, Some(15), clockCompare) /* (-1) */ - - cmp(Some(14), None, clockCompare) /* 1 */ - - cmp(None, None, clockCompare) /* 0 */ - } - () - }) -}) - -describe("Belt_Option.eq", () => { - test("Belt_Option.eq", () => { - module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Belt.Option - - eq(Some(3), Some(15), clockEqual) /* true */ - - eq(Some(3), None, clockEqual) /* false */ - - eq(None, Some(3), clockEqual) /* false */ - - eq(None, None, clockEqual) /* true */ - } - () - }) -}) - -describe("Belt_Option.flatMap", () => { - test("Belt_Option.flatMap", () => { - module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Belt.Option.flatMap(Some(2), addIfAboveOne) /* Some(3) */ - - Belt.Option.flatMap(Some(-4), addIfAboveOne) /* None */ - - Belt.Option.flatMap(None, addIfAboveOne) /* None */ - } - () - }) -}) - -describe("Belt_Option.forEach", () => { - test("Belt_Option.forEach", () => { - module Test = { - Belt.Option.forEach(Some("thing"), x => Js.log(x)) /* logs "thing" */ - Belt.Option.forEach(None, x => Js.log(x)) /* returns () */ - } - () - }) -}) - -describe("Belt_Option.getExn", () => { - test("Belt_Option.getExn", () => { - module Test = { - Some(3) - ->Belt.Option.getExn - ->assertEqual(3) - - switch Belt.Option.getExn(None) { - // Raises an exception - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt_Option.getWithDefault", () => { - test("Belt_Option.getWithDefault", () => { - module Test = { - Belt.Option.getWithDefault(None, "Banana") /* Banana */ - - Belt.Option.getWithDefault(Some("Apple"), "Banana") /* Apple */ - - let greet = (firstName: option) => - "Greetings " ++ firstName->Belt.Option.getWithDefault("Anonymous") - - Some("Jane")->greet /* "Greetings Jane" */ - - None->greet /* "Greetings Anonymous" */ - } - () - }) -}) - -describe("Belt_Option.isNone", () => { - test("Belt_Option.isNone", () => { - module Test = { - Belt.Option.isNone(None) /* true */ - - Belt.Option.isNone(Some(1)) /* false */ - } - () - }) -}) - -describe("Belt_Option.isSome", () => { - test("Belt_Option.isSome", () => { - module Test = { - Belt.Option.isSome(None) /* false */ - - Belt.Option.isSome(Some(1)) /* true */ - } - () - }) -}) - -describe("Belt_Option.keep", () => { - test("Belt_Option.keep", () => { - module Test = { - Belt.Option.keep(Some(10), x => x > 5) /* returns `Some(10)` */ - Belt.Option.keep(Some(4), x => x > 5) /* returns `None` */ - Belt.Option.keep(None, x => x > 5) /* returns `None` */ - } - () - }) -}) - -describe("Belt_Option.map", () => { - test("Belt_Option.map", () => { - module Test = { - Belt.Option.map(Some(3), x => x * x) /* Some(9) */ - - Belt.Option.map(None, x => x * x) /* None */ - } - () - }) -}) - -describe("Belt_Option.mapWithDefault", () => { - test("Belt_Option.mapWithDefault", () => { - module Test = { - let someValue = Some(3) - someValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 8 */ - - let noneValue = None - noneValue->Belt.Option.mapWithDefault(0, x => x + 5) /* 0 */ - } - () - }) -}) - -describe("Belt_Option.orElse", () => { - test("Belt_Option.orElse", () => { - module Test = { - Belt.Option.orElse(Some(1812), Some(1066)) == Some(1812) - Belt.Option.orElse(None, Some(1066)) == Some(1066) - Belt.Option.orElse(None, None) == None - } - () - }) -}) - -describe("Belt_Range.every", () => { - test("Belt_Range.every", () => { - module Test = { - Belt.Range.every(0, 4, i => i < 5) /* true */ - - Belt.Range.every(0, 4, i => i < 4) /* false */ - } - () - }) -}) - -describe("Belt_Range.everyBy", () => { - test("Belt_Range.everyBy", () => { - module Test = { - Belt.Range.everyBy(0, 4, ~step=1, i => mod(i, 2) === 0) /* false */ - - Belt.Range.everyBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt_Range.forEach", () => { - test("Belt_Range.forEach", () => { - module Test = { - Belt.Range.forEach(0, 4, i => Js.log(i)) - - // Prints: - // 0 - // 1 - // 2 - // 3 - // 4 - } - () - }) -}) - -describe("Belt_Range.some", () => { - test("Belt_Range.some", () => { - module Test = { - Belt.Range.some(0, 4, i => i > 5) /* false */ - - Belt.Range.some(0, 4, i => i > 2) /* true */ - } - () - }) -}) - -describe("Belt_Range.someBy", () => { - test("Belt_Range.someBy", () => { - module Test = { - Belt.Range.someBy(1, 5, ~step=2, i => mod(i, 2) === 0) /* false */ - Belt.Range.someBy(0, 4, ~step=2, i => mod(i, 2) === 0) /* true */ - } - () - }) -}) - -describe("Belt_Result.cmp", () => { - test("Belt_Result.cmp", () => { - module Test = { - let good1 = Belt.Result.Ok(59) - - let good2 = Belt.Result.Ok(37) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10cmp = (a, b) => Pervasives.compare(mod(a, 10), mod(b, 10)) - - Belt.Result.cmp(Ok(39), Ok(57), mod10cmp) == 1 - - Belt.Result.cmp(Ok(57), Ok(39), mod10cmp) == -1 - - Belt.Result.cmp(Ok(39), Error("y"), mod10cmp) == 1 - - Belt.Result.cmp(Error("x"), Ok(57), mod10cmp) == -1 - - Belt.Result.cmp(Error("x"), Error("y"), mod10cmp) == 0 - } - () - }) -}) - -describe("Belt_Result.eq", () => { - test("Belt_Result.eq", () => { - module Test = { - let good1 = Belt.Result.Ok(42) - - let good2 = Belt.Result.Ok(32) - - let bad1 = Belt.Result.Error("invalid") - - let bad2 = Belt.Result.Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(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 - } - () - }) -}) - -describe("Belt_Result.flatMap", () => { - test("Belt_Result.flatMap", () => { - module Test = { - let recip = x => - if x !== 0.0 { - Belt.Result.Ok(1.0 /. x) - } else { - Belt.Result.Error("Divide by zero") - } - - Belt.Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Belt.Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Belt.Result.flatMap(Error("Already bad"), recip) == Error("Already bad") - } - () - }) -}) - -describe("Belt_Result.getExn", () => { - test("Belt_Result.getExn", () => { - module Test = { - Belt.Result.Ok(42) - ->Belt.Result.getExn - ->assertEqual(42) - - switch Belt.Result.getExn(Belt.Result.Error("Invalid data")) { - // raise a exception - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Belt_Result.getWithDefault", () => { - test("Belt_Result.getWithDefault", () => { - module Test = { - Belt.Result.getWithDefault(Ok(42), 0) == 42 - - Belt.Result.getWithDefault(Error("Invalid Data"), 0) == 0 - } - () - }) -}) - -describe("Belt_Result.map", () => { - test("Belt_Result.map", () => { - module Test = { - let f = x => sqrt(Belt.Int.toFloat(x)) - - Belt.Result.map(Ok(64), f) == Ok(8.0) - - Belt.Result.map(Error("Invalid data"), f) == Error("Invalid data") - } - () - }) -}) - -describe("Belt_Result.mapWithDefault", () => { - test("Belt_Result.mapWithDefault", () => { - module Test = { - let ok = Belt.Result.Ok(42) - Belt.Result.mapWithDefault(ok, 0, x => x / 2) == 21 - - let error = Belt.Result.Error("Invalid data") - Belt.Result.mapWithDefault(error, 0, x => x / 2) == 0 - } - () - }) -}) - -describe("Belt_Set.Dict.add", () => { - test("Belt_Set.Dict.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.diff", () => { - test("Belt_Set.Dict.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ - } - () - }) -}) - -describe("Belt_Set.Dict.empty", () => { - test("Belt_Set.Dict.empty", () => { - module Test = { - let s0 = Belt.Set.Dict.empty - } - () - }) -}) - -describe("Belt_Set.Dict.eq", () => { - test("Belt_Set.Dict.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.every", () => { - test("Belt_Set.Dict.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.forEach", () => { - test("Belt_Set.Dict.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_Set.Dict.fromArray", () => { - test("Belt_Set.Dict.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt_Set.Dict.get", () => { - test("Belt_Set.Dict.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ - } - () - }) -}) - -describe("Belt_Set.Dict.has", () => { - test("Belt_Set.Dict.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.intersect", () => { - test("Belt_Set.Dict.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ - } - () - }) -}) - -describe("Belt_Set.Dict.isEmpty", () => { - test("Belt_Set.Dict.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ - } - () - }) -}) - -describe("Belt_Set.Dict.keep", () => { - test("Belt_Set.Dict.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt_Set.Dict.maxUndefined", () => { - test("Belt_Set.Dict.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ - } - () - }) -}) - -describe("Belt_Set.Dict.maximum", () => { - test("Belt_Set.Dict.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ - } - () - }) -}) - -describe("Belt_Set.Dict.mergeMany", () => { - test("Belt_Set.Dict.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty - - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ - } - () - }) -}) - -describe("Belt_Set.Dict.minUndefined", () => { - test("Belt_Set.Dict.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ - } - () - }) -}) - -describe("Belt_Set.Dict.minimum", () => { - test("Belt_Set.Dict.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ - } - () - }) -}) - -describe("Belt_Set.Dict.partition", () => { - test("Belt_Set.Dict.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) - - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt_Set.Dict.reduce", () => { - test("Belt_Set.Dict.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_Set.Dict.remove", () => { - test("Belt_Set.Dict.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.removeMany", () => { - test("Belt_Set.Dict.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ - } - () - }) -}) - -describe("Belt_Set.Dict.size", () => { - test("Belt_Set.Dict.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ - } - () - }) -}) - -describe("Belt_Set.Dict.some", () => { - test("Belt_Set.Dict.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ - } - () - }) -}) - -describe("Belt_Set.Dict.split", () => { - test("Belt_Set.Dict.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ - } - () - }) -}) - -describe("Belt_Set.Dict.subset", () => { - test("Belt_Set.Dict.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ - } - () - }) -}) - -describe("Belt_Set.Dict.toArray", () => { - test("Belt_Set.Dict.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_Set.Dict.toList", () => { - test("Belt_Set.Dict.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_Set.Dict.union", () => { - test("Belt_Set.Dict.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ - } - () - }) -}) - -describe("Belt_Set.add", () => { - test("Belt_Set.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - - let s1 = s0->Belt.Set.add(1) - let s2 = s1->Belt.Set.add(2) - let s3 = s2->Belt.Set.add(2) - - s0->Belt.Set.toArray->assertEqual([]) - s1->Belt.Set.toArray->assertEqual([1]) - s2->Belt.Set.toArray->assertEqual([1, 2]) - s3->Belt.Set.toArray->assertEqual([1, 2]) - assertEqual(s2, s3) - } - () - }) -}) - -describe("Belt_Set.diff", () => { - test("Belt_Set.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - Belt.Set.diff(s0, s1) - ->Belt.Set.toArray - ->assertEqual([6]) - - Belt.Set.diff(s1, s0) - ->Belt.Set.toArray - ->assertEqual([1, 4]) - } - () - }) -}) - -describe("Belt_Set.eq", () => { - test("Belt_Set.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 5], ~id=module(IntCmp)) - - Belt.Set.eq(s0, s1)->assertEqual(true) - } - () - }) -}) - -describe("Belt_Set.every", () => { - test("Belt_Set.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.every(isEven)->assertEqual(true) - } - () - }) -}) - -describe("Belt_Set.forEach", () => { - test("Belt_Set.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - - let acc = ref(list{}) - - s0->Belt.Set.forEach( - x => { - acc := Belt.List.add(acc.contents, x) - }, - ) - - acc.contents->assertEqual(list{6, 5, 3, 2}) - } - () - }) -}) - -describe("Belt_Set.fromArray", () => { - test("Belt_Set.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 3, 2, 4], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 4]) - } - () - }) -}) - -describe("Belt_Set.get", () => { - test("Belt_Set.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - s0->Belt.Set.get(3)->assertEqual(Some(3)) - s0->Belt.Set.get(20)->assertEqual(None) - } - () - }) -}) - -describe("Belt_Set.has", () => { - test("Belt_Set.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 4, 2, 5], ~id=module(IntCmp)) - - set->Belt.Set.has(3)->assertEqual(false) - set->Belt.Set.has(1)->assertEqual(true) - } - () - }) -}) - -describe("Belt_Set.intersect", () => { - test("Belt_Set.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - - let intersect = Belt.Set.intersect(s0, s1) - - intersect - ->Belt.Set.toArray - ->assertEqual([2, 3, 5]) - } - () - }) -}) - -describe("Belt_Set.isEmpty", () => { - test("Belt_Set.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.fromArray([], ~id=module(IntCmp)) - let notEmpty = Belt.Set.fromArray([1], ~id=module(IntCmp)) - - Belt.Set.isEmpty(empty)->assertEqual(true) - Belt.Set.isEmpty(notEmpty)->assertEqual(false) - } - () - }) -}) - -describe("Belt_Set.keep", () => { - test("Belt_Set.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.keep(isEven) - - s1->Belt.Set.toArray->assertEqual([2, 4]) - } - () - }) -}) - -describe("Belt_Set.make", () => { - test("Belt_Set.make", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) - - Belt.Set.isEmpty(set)->assertEqual(true) - } - () - }) -}) - -describe("Belt_Set.maxUndefined", () => { - test("Belt_Set.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(None) - - s1 - ->Belt.Set.maxUndefined - ->Js.Undefined.toOption - ->assertEqual(Some(5)) - } - () - }) -}) - -describe("Belt_Set.maximum", () => { - test("Belt_Set.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.maximum->assertEqual(None) - s1->Belt.Set.maximum->assertEqual(Some(5)) - } - () - }) -}) - -describe("Belt_Set.mergeMany", () => { - test("Belt_Set.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.make(~id=module(IntCmp)) - - let newSet = set->Belt.Set.mergeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5]) - } - () - }) -}) - -describe("Belt_Set.minUndefined", () => { - test("Belt_Set.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(None) - s1->Belt.Set.minUndefined->Js.Undefined.toOption->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt_Set.minimum", () => { - test("Belt_Set.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.make(~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.minimum->assertEqual(None) - s1->Belt.Set.minimum->assertEqual(Some(1)) - } - () - }) -}) - -describe("Belt_Set.partition", () => { - test("Belt_Set.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - let (s1, s2) = s0->Belt.Set.partition(isOdd) - - s1->Belt.Set.toArray->assertEqual([1, 3, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4]) - } - () - }) -}) - -describe("Belt_Set.reduce", () => { - test("Belt_Set.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - s0 - ->Belt.Set.reduce(list{}, (acc, element) => acc->Belt.List.add(element)) - ->assertEqual(list{6, 5, 3, 2}) - } - () - }) -}) - -describe("Belt_Set.remove", () => { - test("Belt_Set.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([2, 3, 1, 4, 5], ~id=module(IntCmp)) - let s1 = s0->Belt.Set.remove(1) - let s2 = s1->Belt.Set.remove(3) - let s3 = s2->Belt.Set.remove(3) - - s1->Belt.Set.toArray->assertEqual([2, 3, 4, 5]) - s2->Belt.Set.toArray->assertEqual([2, 4, 5]) - assertEqual(s2, s3) - } - () - }) -}) - -describe("Belt_Set.removeMany", () => { - test("Belt_Set.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - let newSet = set->Belt.Set.removeMany([5, 4, 3, 2, 1]) - - newSet - ->Belt.Set.toArray - ->assertEqual([]) - } - () - }) -}) - -describe("Belt_Set.size", () => { - test("Belt_Set.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4], ~id=module(IntCmp)) - - s0->Belt.Set.size->assertEqual(4) - } - () - }) -}) - -describe("Belt_Set.some", () => { - test("Belt_Set.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.fromArray([1, 2, 4, 6, 8], ~id=module(IntCmp)) - s0->Belt.Set.some(isOdd)->assertEqual(true) - } - () - }) -}) - -describe("Belt_Set.split", () => { - test("Belt_Set.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([1, 2, 3, 4, 5], ~id=module(IntCmp)) - - let ((smaller, larger), present) = s0->Belt.Set.split(3) - - present->assertEqual(true) - smaller->Belt.Set.toArray->assertEqual([1, 2]) - larger->Belt.Set.toArray->assertEqual([4, 5]) - } - () - }) -}) - -describe("Belt_Set.subset", () => { - test("Belt_Set.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let s2 = Belt.Set.intersect(s0, s1) - - Belt.Set.subset(s2, s0)->assertEqual(true) - Belt.Set.subset(s2, s1)->assertEqual(true) - Belt.Set.subset(s1, s0)->assertEqual(false) - } - () - }) -}) - -describe("Belt_Set.toArray", () => { - test("Belt_Set.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toArray->assertEqual([1, 2, 3, 5]) - } - () - }) -}) - -describe("Belt_Set.toList", () => { - test("Belt_Set.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([3, 2, 1, 5], ~id=module(IntCmp)) - - s0->Belt.Set.toList->assertEqual(list{1, 2, 3, 5}) - } - () - }) -}) - -describe("Belt_Set.union", () => { - test("Belt_Set.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.fromArray([5, 2, 3, 5, 6], ~id=module(IntCmp)) - let s1 = Belt.Set.fromArray([5, 2, 3, 1, 5, 4], ~id=module(IntCmp)) - let union = Belt.Set.union(s0, s1) - - union - ->Belt.Set.toArray - ->assertEqual([1, 2, 3, 4, 5, 6]) - } - () - }) -}) - -describe("Belt_SetDict.add", () => { - test("Belt_SetDict.add", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = s0->Belt.Set.Dict.add(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.add(2, ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.toArray /* [] */ - s1->Belt.Set.Dict.toArray /* [1] */ - s2->Belt.Set.Dict.toArray /* [1, 2] */ - s3->Belt.Set.Dict.toArray /* [1,2 ] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt_SetDict.diff", () => { - test("Belt_SetDict.diff", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - - let diff1 = Belt.Set.Dict.diff(s0, s1, ~cmp=IntCmp.cmp) - let diff2 = Belt.Set.Dict.diff(s1, s0, ~cmp=IntCmp.cmp) - - diff1->Belt.Set.Dict.toArray /* [6] */ - diff2->Belt.Set.Dict.toArray /* [1,4] */ - } - () - }) -}) - -describe("Belt_SetDict.empty", () => { - test("Belt_SetDict.empty", () => { - module Test = { - let s0 = Belt.Set.Dict.empty - } - () - }) -}) - -describe("Belt_SetDict.eq", () => { - test("Belt_SetDict.eq", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([3, 2, 5], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.eq(s0, s1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt_SetDict.every", () => { - test("Belt_SetDict.every", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.every(isEven) /* true */ - } - () - }) -}) - -describe("Belt_SetDict.forEach", () => { - test("Belt_SetDict.forEach", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let acc = ref(list{}) - s0->Belt.Set.Dict.forEach(x => acc := Belt.List.add(acc.contents, x)) - acc /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_SetDict.fromArray", () => { - test("Belt_SetDict.fromArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 3, 2, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1, 2, 3, 4] */ - } - () - }) -}) - -describe("Belt_SetDict.get", () => { - test("Belt_SetDict.get", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.get(3, ~cmp=IntCmp.cmp) /* Some(3) */ - s0->Belt.Set.Dict.get(20, ~cmp=IntCmp.cmp) /* None */ - } - () - }) -}) - -describe("Belt_SetDict.has", () => { - test("Belt_SetDict.has", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 4, 2, 5], ~cmp=IntCmp.cmp) - - set->Belt.Set.Dict.has(3, ~cmp=IntCmp.cmp) /* false */ - set->Belt.Set.Dict.has(1, ~cmp=IntCmp.cmp) /* true */ - } - () - }) -}) - -describe("Belt_SetDict.intersect", () => { - test("Belt_SetDict.intersect", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let intersect = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - intersect->Belt.Set.Dict.toArray /* [2,3,5] */ - } - () - }) -}) - -describe("Belt_SetDict.isEmpty", () => { - test("Belt_SetDict.isEmpty", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let empty = Belt.Set.Dict.fromArray([], ~cmp=IntCmp.cmp) - let notEmpty = Belt.Set.Dict.fromArray([1], ~cmp=IntCmp.cmp) - - Belt.Set.Dict.isEmpty(empty) /* true */ - Belt.Set.Dict.isEmpty(notEmpty) /* false */ - } - () - }) -}) - -describe("Belt_SetDict.keep", () => { - test("Belt_SetDict.keep", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isEven = x => mod(x, 2) == 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.keep(isEven) - - s1->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt_SetDict.maxUndefined", () => { - test("Belt_SetDict.maxUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maxUndefined /* undefined */ - s1->Belt.Set.Dict.maxUndefined /* 5 */ - } - () - }) -}) - -describe("Belt_SetDict.maximum", () => { - test("Belt_SetDict.maximum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.maximum /* None */ - s1->Belt.Set.Dict.maximum /* Some(5) */ - } - () - }) -}) - -describe("Belt_SetDict.mergeMany", () => { - test("Belt_SetDict.mergeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.empty - - let newSet = set->Belt.Set.Dict.mergeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [1, 2, 3, 4, 5] */ - } - () - }) -}) - -describe("Belt_SetDict.minUndefined", () => { - test("Belt_SetDict.minUndefined", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minUndefined /* undefined */ - s1->Belt.Set.Dict.minUndefined /* 1 */ - } - () - }) -}) - -describe("Belt_SetDict.minimum", () => { - test("Belt_SetDict.minimum", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.empty - let s1 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.minimum /* None */ - s1->Belt.Set.Dict.minimum /* Some(1) */ - } - () - }) -}) - -describe("Belt_SetDict.partition", () => { - test("Belt_SetDict.partition", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - let (s1, s2) = s0->Belt.Set.Dict.partition(isOdd) - - s1->Belt.Set.Dict.toArray /* [1,3,5] */ - s2->Belt.Set.Dict.toArray /* [2,4] */ - } - () - }) -}) - -describe("Belt_SetDict.reduce", () => { - test("Belt_SetDict.reduce", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.reduce( - list{}, - (acc, element) => acc->Belt.List.add(element), - ) /* [6,5,3,2] */ - } - () - }) -}) - -describe("Belt_SetDict.remove", () => { - test("Belt_SetDict.remove", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([2, 3, 1, 4, 5], ~cmp=IntCmp.cmp) - let s1 = s0->Belt.Set.Dict.remove(1, ~cmp=IntCmp.cmp) - let s2 = s1->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - let s3 = s2->Belt.Set.Dict.remove(3, ~cmp=IntCmp.cmp) - - s1->Belt.Set.Dict.toArray /* [2,3,4,5] */ - s2->Belt.Set.Dict.toArray /* [2,4,5] */ - s2 == s3 /* true */ - } - () - }) -}) - -describe("Belt_SetDict.removeMany", () => { - test("Belt_SetDict.removeMany", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let set = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - let newSet = set->Belt.Set.Dict.removeMany([5, 4, 3, 2, 1], ~cmp=IntCmp.cmp) - newSet->Belt.Set.Dict.toArray /* [] */ - } - () - }) -}) - -describe("Belt_SetDict.size", () => { - test("Belt_SetDict.size", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.size /* 4 */ - } - () - }) -}) - -describe("Belt_SetDict.some", () => { - test("Belt_SetDict.some", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let isOdd = x => mod(x, 2) != 0 - - let s0 = Belt.Set.Dict.fromArray([1, 2, 4, 6, 8], ~cmp=IntCmp.cmp) - s0->Belt.Set.Dict.some(isOdd) /* true */ - } - () - }) -}) - -describe("Belt_SetDict.split", () => { - test("Belt_SetDict.split", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([1, 2, 3, 4, 5], ~cmp=IntCmp.cmp) - - let ((smaller, larger), present) = s0->Belt.Set.Dict.split(3, ~cmp=IntCmp.cmp) - - present /* true */ - smaller->Belt.Set.Dict.toArray /* [1,2] */ - larger->Belt.Set.Dict.toArray /* [4,5] */ - } - () - }) -}) - -describe("Belt_SetDict.subset", () => { - test("Belt_SetDict.subset", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let s2 = Belt.Set.Dict.intersect(s0, s1, ~cmp=IntCmp.cmp) - Belt.Set.Dict.subset(s2, s0, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s2, s1, ~cmp=IntCmp.cmp) /* true */ - Belt.Set.Dict.subset(s1, s0, ~cmp=IntCmp.cmp) /* false */ - } - () - }) -}) - -describe("Belt_SetDict.toArray", () => { - test("Belt_SetDict.toArray", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toArray /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_SetDict.toList", () => { - test("Belt_SetDict.toList", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([3, 2, 1, 5], ~cmp=IntCmp.cmp) - - s0->Belt.Set.Dict.toList /* [1,2,3,5] */ - } - () - }) -}) - -describe("Belt_SetDict.union", () => { - test("Belt_SetDict.union", () => { - module Test = { - module IntCmp = Belt.Id.MakeComparable({ - type t = int - let cmp = Pervasives.compare - }) - - let s0 = Belt.Set.Dict.fromArray([5, 2, 3, 5, 6], ~cmp=IntCmp.cmp) - let s1 = Belt.Set.Dict.fromArray([5, 2, 3, 1, 5, 4], ~cmp=IntCmp.cmp) - let union = Belt.Set.Dict.union(s0, s1, ~cmp=IntCmp.cmp) - union->Belt.Set.Dict.toArray /* [1,2,3,4,5,6] */ - } - () - }) -}) - -describe("Belt_SortArray.binarySearchBy", () => { - test("Belt_SortArray.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 - } - () - }) -}) - -describe("Belt_SortArray.strictlySortedLength", () => { - test("Belt_SortArray.strictlySortedLength", () => { - module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 - } - () - }) -}) - -describe("Belt_internalMapInt.A.blit", () => { - test("Belt_internalMapInt.A.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt_internalMapInt.A.cmp", () => { - test("Belt_internalMapInt.A.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt_internalMapInt.A.concat", () => { - test("Belt_internalMapInt.A.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt_internalMapInt.A.concatMany", () => { - test("Belt_internalMapInt.A.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt_internalMapInt.A.eq", () => { - test("Belt_internalMapInt.A.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt_internalMapInt.A.every", () => { - test("Belt_internalMapInt.A.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalMapInt.A.every2", () => { - test("Belt_internalMapInt.A.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalMapInt.A.fill", () => { - test("Belt_internalMapInt.A.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt_internalMapInt.A.flatMap", () => { - test("Belt_internalMapInt.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt_internalMapInt.A.forEach", () => { - test("Belt_internalMapInt.A.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt_internalMapInt.A.forEachWithIndex", () => { - test("Belt_internalMapInt.A.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt_internalMapInt.A.get", () => { - test("Belt_internalMapInt.A.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt_internalMapInt.A.getBy", () => { - test("Belt_internalMapInt.A.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalMapInt.A.getIndexBy", () => { - test("Belt_internalMapInt.A.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalMapInt.A.joinWith", () => { - test("Belt_internalMapInt.A.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt_internalMapInt.A.keepMap", () => { - test("Belt_internalMapInt.A.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt_internalMapInt.A.keepWithIndex", () => { - test("Belt_internalMapInt.A.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt_internalMapInt.A.length", () => { - test("Belt_internalMapInt.A.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt_internalMapInt.A.makeBy", () => { - test("Belt_internalMapInt.A.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt_internalMapInt.A.makeUninitialized", () => { - test("Belt_internalMapInt.A.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt_internalMapInt.A.map", () => { - test("Belt_internalMapInt.A.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt_internalMapInt.A.mapWithIndex", () => { - test("Belt_internalMapInt.A.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt_internalMapInt.A.partition", () => { - test("Belt_internalMapInt.A.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt_internalMapInt.A.range", () => { - test("Belt_internalMapInt.A.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt_internalMapInt.A.rangeBy", () => { - test("Belt_internalMapInt.A.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt_internalMapInt.A.reduce", () => { - test("Belt_internalMapInt.A.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_internalMapInt.A.reduceReverse", () => { - test("Belt_internalMapInt.A.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt_internalMapInt.A.reduceReverse2", () => { - test("Belt_internalMapInt.A.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt_internalMapInt.A.reduceWithIndex", () => { - test("Belt_internalMapInt.A.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt_internalMapInt.A.reverse", () => { - test("Belt_internalMapInt.A.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalMapInt.A.reverseInPlace", () => { - test("Belt_internalMapInt.A.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalMapInt.A.slice", () => { - test("Belt_internalMapInt.A.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt_internalMapInt.A.sliceToEnd", () => { - test("Belt_internalMapInt.A.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt_internalMapInt.A.some", () => { - test("Belt_internalMapInt.A.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalMapInt.A.some2", () => { - test("Belt_internalMapInt.A.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt_internalMapInt.A.unzip", () => { - test("Belt_internalMapInt.A.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt_internalMapInt.A.zip", () => { - test("Belt_internalMapInt.A.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt_internalMapInt.A.zipBy", () => { - test("Belt_internalMapInt.A.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("Belt_internalMapInt.S.binarySearchBy", () => { - test("Belt_internalMapInt.S.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 - } - () - }) -}) - -describe("Belt_internalMapInt.S.strictlySortedLength", () => { - test("Belt_internalMapInt.S.strictlySortedLength", () => { - module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 - } - () - }) -}) - -describe("Belt_internalMapString.A.blit", () => { - test("Belt_internalMapString.A.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt_internalMapString.A.cmp", () => { - test("Belt_internalMapString.A.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt_internalMapString.A.concat", () => { - test("Belt_internalMapString.A.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt_internalMapString.A.concatMany", () => { - test("Belt_internalMapString.A.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt_internalMapString.A.eq", () => { - test("Belt_internalMapString.A.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt_internalMapString.A.every", () => { - test("Belt_internalMapString.A.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalMapString.A.every2", () => { - test("Belt_internalMapString.A.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalMapString.A.fill", () => { - test("Belt_internalMapString.A.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt_internalMapString.A.flatMap", () => { - test("Belt_internalMapString.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt_internalMapString.A.forEach", () => { - test("Belt_internalMapString.A.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt_internalMapString.A.forEachWithIndex", () => { - test("Belt_internalMapString.A.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt_internalMapString.A.get", () => { - test("Belt_internalMapString.A.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt_internalMapString.A.getBy", () => { - test("Belt_internalMapString.A.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalMapString.A.getIndexBy", () => { - test("Belt_internalMapString.A.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalMapString.A.joinWith", () => { - test("Belt_internalMapString.A.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt_internalMapString.A.keepMap", () => { - test("Belt_internalMapString.A.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt_internalMapString.A.keepWithIndex", () => { - test("Belt_internalMapString.A.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt_internalMapString.A.length", () => { - test("Belt_internalMapString.A.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt_internalMapString.A.makeBy", () => { - test("Belt_internalMapString.A.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt_internalMapString.A.makeUninitialized", () => { - test("Belt_internalMapString.A.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - test("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt_internalMapString.A.map", () => { - test("Belt_internalMapString.A.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt_internalMapString.A.mapWithIndex", () => { - test("Belt_internalMapString.A.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt_internalMapString.A.partition", () => { - test("Belt_internalMapString.A.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt_internalMapString.A.range", () => { - test("Belt_internalMapString.A.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt_internalMapString.A.rangeBy", () => { - test("Belt_internalMapString.A.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt_internalMapString.A.reduce", () => { - test("Belt_internalMapString.A.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_internalMapString.A.reduceReverse", () => { - test("Belt_internalMapString.A.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt_internalMapString.A.reduceReverse2", () => { - test("Belt_internalMapString.A.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt_internalMapString.A.reduceWithIndex", () => { - test("Belt_internalMapString.A.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt_internalMapString.A.reverse", () => { - test("Belt_internalMapString.A.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalMapString.A.reverseInPlace", () => { - test("Belt_internalMapString.A.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalMapString.A.slice", () => { - test("Belt_internalMapString.A.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt_internalMapString.A.sliceToEnd", () => { - test("Belt_internalMapString.A.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt_internalMapString.A.some", () => { - test("Belt_internalMapString.A.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalMapString.A.some2", () => { - test("Belt_internalMapString.A.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt_internalMapString.A.unzip", () => { - test("Belt_internalMapString.A.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt_internalMapString.A.zip", () => { - test("Belt_internalMapString.A.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt_internalMapString.A.zipBy", () => { - test("Belt_internalMapString.A.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("Belt_internalMapString.S.binarySearchBy", () => { - test("Belt_internalMapString.S.binarySearchBy", () => { - module Test = { - Belt.SortArray.binarySearchBy([1, 2, 3, 4, 33, 35, 36], 33, Pervasives.compare) == 4 - - lnot(Belt.SortArray.binarySearchBy([1, 3, 5, 7], 4, Pervasives.compare)) == 2 - } - () - }) -}) - -describe("Belt_internalMapString.S.strictlySortedLength", () => { - test("Belt_internalMapString.S.strictlySortedLength", () => { - module Test = { - Belt.SortArray.strictlySortedLength([1, 2, 3, 4, 3], (x, y) => x < y) == 4 - - Belt.SortArray.strictlySortedLength([], (x, y) => x < y) == 0 - - Belt.SortArray.strictlySortedLength([1], (x, y) => x < y) == 1 - - Belt.SortArray.strictlySortedLength([4, 3, 2, 1], (x, y) => x < y) == -4 - } - () - }) -}) - -describe("Belt_internalSetInt.A.blit", () => { - test("Belt_internalSetInt.A.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt_internalSetInt.A.cmp", () => { - test("Belt_internalSetInt.A.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt_internalSetInt.A.concat", () => { - test("Belt_internalSetInt.A.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt_internalSetInt.A.concatMany", () => { - test("Belt_internalSetInt.A.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt_internalSetInt.A.eq", () => { - test("Belt_internalSetInt.A.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt_internalSetInt.A.every", () => { - test("Belt_internalSetInt.A.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalSetInt.A.every2", () => { - test("Belt_internalSetInt.A.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalSetInt.A.fill", () => { - test("Belt_internalSetInt.A.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt_internalSetInt.A.flatMap", () => { - test("Belt_internalSetInt.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt_internalSetInt.A.forEach", () => { - test("Belt_internalSetInt.A.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt_internalSetInt.A.forEachWithIndex", () => { - test("Belt_internalSetInt.A.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt_internalSetInt.A.get", () => { - test("Belt_internalSetInt.A.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt_internalSetInt.A.getBy", () => { - test("Belt_internalSetInt.A.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalSetInt.A.getIndexBy", () => { - test("Belt_internalSetInt.A.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalSetInt.A.joinWith", () => { - test("Belt_internalSetInt.A.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt_internalSetInt.A.keepMap", () => { - test("Belt_internalSetInt.A.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt_internalSetInt.A.keepWithIndex", () => { - test("Belt_internalSetInt.A.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt_internalSetInt.A.length", () => { - test("Belt_internalSetInt.A.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt_internalSetInt.A.makeBy", () => { - test("Belt_internalSetInt.A.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt_internalSetInt.A.makeUninitialized", () => { - test("Belt_internalSetInt.A.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt_internalSetInt.A.map", () => { - test("Belt_internalSetInt.A.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt_internalSetInt.A.mapWithIndex", () => { - test("Belt_internalSetInt.A.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt_internalSetInt.A.partition", () => { - test("Belt_internalSetInt.A.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt_internalSetInt.A.range", () => { - test("Belt_internalSetInt.A.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt_internalSetInt.A.rangeBy", () => { - test("Belt_internalSetInt.A.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt_internalSetInt.A.reduce", () => { - test("Belt_internalSetInt.A.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_internalSetInt.A.reduceReverse", () => { - test("Belt_internalSetInt.A.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt_internalSetInt.A.reduceReverse2", () => { - test("Belt_internalSetInt.A.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt_internalSetInt.A.reduceWithIndex", () => { - test("Belt_internalSetInt.A.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt_internalSetInt.A.reverse", () => { - test("Belt_internalSetInt.A.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalSetInt.A.reverseInPlace", () => { - test("Belt_internalSetInt.A.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalSetInt.A.slice", () => { - test("Belt_internalSetInt.A.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt_internalSetInt.A.sliceToEnd", () => { - test("Belt_internalSetInt.A.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt_internalSetInt.A.some", () => { - test("Belt_internalSetInt.A.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalSetInt.A.some2", () => { - test("Belt_internalSetInt.A.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt_internalSetInt.A.unzip", () => { - test("Belt_internalSetInt.A.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt_internalSetInt.A.zip", () => { - test("Belt_internalSetInt.A.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt_internalSetInt.A.zipBy", () => { - test("Belt_internalSetInt.A.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("Belt_internalSetString.A.blit", () => { - test("Belt_internalSetString.A.blit", () => { - module Test = { - let v1 = [10, 11, 12, 13, 14, 15, 16, 17] - let v2 = [20, 21, 22, 23, 24, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v2, ~dstOffset=2, ~len=3) - v2 == [20, 21, 14, 15, 16, 25, 26, 27] - - Belt.Array.blit(~src=v1, ~srcOffset=4, ~dst=v1, ~dstOffset=2, ~len=3) - v1 == [10, 11, 14, 15, 16, 15, 16, 17] - } - () - }) -}) - -describe("Belt_internalSetString.A.cmp", () => { - test("Belt_internalSetString.A.cmp", () => { - module Test = { - Belt.Array.cmp([1, 3, 5], [1, 4, 2], (a, b) => compare(a, b)) == -1 - - Belt.Array.cmp([1, 3, 5], [1, 2, 3], (a, b) => compare(a, b)) == 1 - - Belt.Array.cmp([1, 3, 5], [1, 3, 5], (a, b) => compare(a, b)) == 0 - } - () - }) -}) - -describe("Belt_internalSetString.A.concat", () => { - test("Belt_internalSetString.A.concat", () => { - module Test = { - Belt.Array.concat([1, 2, 3], [4, 5]) == [1, 2, 3, 4, 5] - - Belt.Array.concat([], ["a", "b", "c"]) == ["a", "b", "c"] - } - () - }) -}) - -describe("Belt_internalSetString.A.concatMany", () => { - test("Belt_internalSetString.A.concatMany", () => { - module Test = { - Belt.Array.concatMany([[1, 2, 3], [4, 5, 6], [7, 8]]) == [1, 2, 3, 4, 5, 6, 7, 8] - } - () - }) -}) - -describe("Belt_internalSetString.A.eq", () => { - test("Belt_internalSetString.A.eq", () => { - module Test = { - Belt.Array.eq([1, 2, 3], [-1, -2, -3], (a, b) => abs(a) == abs(b)) == true - } - () - }) -}) - -describe("Belt_internalSetString.A.every", () => { - test("Belt_internalSetString.A.every", () => { - module Test = { - Belt.Array.every([1, 3, 5], x => mod(x, 2) == 1) == true - - Belt.Array.every([1, -3, 5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalSetString.A.every2", () => { - test("Belt_internalSetString.A.every2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalSetString.A.fill", () => { - test("Belt_internalSetString.A.fill", () => { - module Test = { - let arr = Belt.Array.makeBy(5, i => i) - - Belt.Array.fill(arr, ~offset=2, ~len=2, 9) - - arr == [0, 1, 9, 9, 4] - - Belt.Array.fill(arr, ~offset=7, ~len=2, 8) - - arr == [0, 1, 9, 9, 4] - } - () - }) -}) - -describe("Belt_internalSetString.A.flatMap", () => { - test("Belt_internalSetString.A.flatMap", () => { - module Test = { - Belt.Array.flatMap([1, 2], x => [x + 10, x + 20]) == [11, 21, 12, 22] - } - () - }) -}) - -describe("Belt_internalSetString.A.forEach", () => { - test("Belt_internalSetString.A.forEach", () => { - module Test = { - Belt.Array.forEach(["a", "b", "c"], x => Js.log("Item: " ++ x)) - - /* - prints: - Item: a - Item: b - Item: c -*/ - let total = ref(0) - - Belt.Array.forEach([1, 2, 3, 4], x => total := total.contents + x) - - total.contents == 1 + 2 + 3 + 4 - } - () - }) -}) - -describe("Belt_internalSetString.A.forEachWithIndex", () => { - test("Belt_internalSetString.A.forEachWithIndex", () => { - module Test = { - Belt.Array.forEachWithIndex( - ["a", "b", "c"], - (i, x) => Js.log("Item " ++ Belt.Int.toString(i) ++ " is " ++ x), - ) - - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - let total = ref(0) - - Belt.Array.forEachWithIndex([10, 11, 12, 13], (i, x) => total := total.contents + x + i) - - total.contents == 0 + 10 + 1 + 11 + 2 + 12 + 3 + 13 - } - () - }) -}) - -describe("Belt_internalSetString.A.get", () => { - test("Belt_internalSetString.A.get", () => { - module Test = { - Belt.Array.get(["a", "b", "c"], 0) == Some("a") - Belt.Array.get(["a", "b", "c"], 3) == None - Belt.Array.get(["a", "b", "c"], -1) == None - } - () - }) -}) - -describe("Belt_internalSetString.A.getBy", () => { - test("Belt_internalSetString.A.getBy", () => { - module Test = { - Belt.Array.getBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(4) - Belt.Array.getBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalSetString.A.getIndexBy", () => { - test("Belt_internalSetString.A.getIndexBy", () => { - module Test = { - Belt.Array.getIndexBy([1, 4, 3, 2], x => mod(x, 2) == 0) == Some(1) - Belt.Array.getIndexBy([15, 13, 11], x => mod(x, 2) == 0) == None - } - () - }) -}) - -describe("Belt_internalSetString.A.joinWith", () => { - test("Belt_internalSetString.A.joinWith", () => { - module Test = { - Belt.Array.joinWith([0, 1], ", ", Js.Int.toString) == "0, 1" - Belt.Array.joinWith([], " ", Js.Int.toString) == "" - Belt.Array.joinWith([1], " ", Js.Int.toString) == "1" - } - () - }) -}) - -describe("Belt_internalSetString.A.keepMap", () => { - test("Belt_internalSetString.A.keepMap", () => { - module Test = { - Belt.Array.keepMap( - [1, 2, 3], - x => - if mod(x, 2) == 0 { - Some(x) - } else { - None - }, - ) == [2] - } - () - }) -}) - -describe("Belt_internalSetString.A.keepWithIndex", () => { - test("Belt_internalSetString.A.keepWithIndex", () => { - module Test = { - Belt.Array.keepWithIndex([1, 2, 3], (_x, i) => i == 1) == [2] - } - () - }) -}) - -describe("Belt_internalSetString.A.length", () => { - test("Belt_internalSetString.A.length", () => { - module Test = { - // Returns 1 - Belt.Array.length(["test"]) - } - () - }) -}) - -describe("Belt_internalSetString.A.makeBy", () => { - test("Belt_internalSetString.A.makeBy", () => { - module Test = { - Belt.Array.makeBy(5, i => i) == [0, 1, 2, 3, 4] - - Belt.Array.makeBy(5, i => i * i) == [0, 1, 4, 9, 16] - } - () - }) -}) - -describe("Belt_internalSetString.A.makeUninitialized", () => { - test("Belt_internalSetString.A.makeUninitialized", () => { - module Test = { - let arr: array> = Belt.Array.makeUninitialized(5) - - Belt.Array.getExn(arr, 0) == Js.undefined - } - () - }) -}) - -describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - test("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - module Test = { - let arr = Belt.Array.makeUninitializedUnsafe(5) - - Js.log(Belt.Array.getExn(arr, 0)) // undefined - - Belt.Array.setExn(arr, 0, "example") - - Js.log(Belt.Array.getExn(arr, 0) == "example") - } - () - }) -}) - -describe("Belt_internalSetString.A.map", () => { - test("Belt_internalSetString.A.map", () => { - module Test = { - Belt.Array.map([1, 2], x => x + 1) == [3, 4] - } - () - }) -}) - -describe("Belt_internalSetString.A.mapWithIndex", () => { - test("Belt_internalSetString.A.mapWithIndex", () => { - module Test = { - Belt.Array.mapWithIndex([1, 2, 3], (i, x) => i + x) == [0 + 1, 1 + 2, 2 + 3] - } - () - }) -}) - -describe("Belt_internalSetString.A.partition", () => { - test("Belt_internalSetString.A.partition", () => { - module Test = { - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) == 0) == ([2, 4], [1, 3, 5]) - - Belt.Array.partition([1, 2, 3, 4, 5], x => mod(x, 2) != 0) == ([1, 3, 5], [2, 4]) - } - () - }) -}) - -describe("Belt_internalSetString.A.range", () => { - test("Belt_internalSetString.A.range", () => { - module Test = { - Belt.Array.range(0, 3) == [0, 1, 2, 3] - - Belt.Array.range(3, 0) == [] - - Belt.Array.range(3, 3) == [3] - } - () - }) -}) - -describe("Belt_internalSetString.A.rangeBy", () => { - test("Belt_internalSetString.A.rangeBy", () => { - module Test = { - Belt.Array.rangeBy(0, 10, ~step=3) == [0, 3, 6, 9] - - Belt.Array.rangeBy(0, 12, ~step=3) == [0, 3, 6, 9, 12] - - Belt.Array.rangeBy(33, 0, ~step=1) == [] - - Belt.Array.rangeBy(33, 0, ~step=-1) == [] - - Belt.Array.rangeBy(3, 12, ~step=-1) == [] - - Belt.Array.rangeBy(3, 3, ~step=0) == [] - - Belt.Array.rangeBy(3, 3, ~step=1) == [3] - } - () - }) -}) - -describe("Belt_internalSetString.A.reduce", () => { - test("Belt_internalSetString.A.reduce", () => { - module Test = { - Belt.Array.reduce([2, 3, 4], 1, (a, b) => a + b) == 10 - - Belt.Array.reduce(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "abcd" - } - () - }) -}) - -describe("Belt_internalSetString.A.reduceReverse", () => { - test("Belt_internalSetString.A.reduceReverse", () => { - module Test = { - Belt.Array.reduceReverse(["a", "b", "c", "d"], "", (a, b) => a ++ b) == "dcba" - } - () - }) -}) - -describe("Belt_internalSetString.A.reduceReverse2", () => { - test("Belt_internalSetString.A.reduceReverse2", () => { - module Test = { - Belt.Array.reduceReverse2([1, 2, 3], [1, 2], 0, (acc, x, y) => acc + x + y) == 6 - } - () - }) -}) - -describe("Belt_internalSetString.A.reduceWithIndex", () => { - test("Belt_internalSetString.A.reduceWithIndex", () => { - module Test = { - Belt.Array.reduceWithIndex([1, 2, 3, 4], 0, (acc, x, i) => acc + x + i) == 16 - } - () - }) -}) - -describe("Belt_internalSetString.A.reverse", () => { - test("Belt_internalSetString.A.reverse", () => { - module Test = { - Belt.Array.reverse([10, 11, 12, 13, 14]) == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalSetString.A.reverseInPlace", () => { - test("Belt_internalSetString.A.reverseInPlace", () => { - module Test = { - let arr = [10, 11, 12, 13, 14] - - let () = Belt.Array.reverseInPlace(arr) - - arr == [14, 13, 12, 11, 10] - } - () - }) -}) - -describe("Belt_internalSetString.A.slice", () => { - test("Belt_internalSetString.A.slice", () => { - module Test = { - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=2, ~len=3) == [12, 13, 14] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=-4, ~len=3) == [13, 14, 15] - - Belt.Array.slice([10, 11, 12, 13, 14, 15, 16], ~offset=4, ~len=9) == [14, 15, 16] - } - () - }) -}) - -describe("Belt_internalSetString.A.sliceToEnd", () => { - test("Belt_internalSetString.A.sliceToEnd", () => { - module Test = { - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], 2) == [12, 13, 14, 15, 16] - - Belt.Array.sliceToEnd([10, 11, 12, 13, 14, 15, 16], -4) == [13, 14, 15, 16] - } - () - }) -}) - -describe("Belt_internalSetString.A.some", () => { - test("Belt_internalSetString.A.some", () => { - module Test = { - Belt.Array.some([2, 3, 4], x => mod(x, 2) == 1) == true - - Belt.Array.some([-1, -3, -5], x => x > 0) == false - } - () - }) -}) - -describe("Belt_internalSetString.A.some2", () => { - test("Belt_internalSetString.A.some2", () => { - module Test = { - 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 - } - () - }) -}) - -describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - module Test = { - let arr = ["ant", "bee", "cat", "dog", "elk"] - - Belt.Array.truncateToLengthUnsafe(arr, 3) - - arr == ["ant", "bee", "cat"] - } - () - }) -}) - -describe("Belt_internalSetString.A.unzip", () => { - test("Belt_internalSetString.A.unzip", () => { - module Test = { - Belt.Array.unzip([(1, 2), (3, 4)]) == ([1, 3], [2, 4]) - - Belt.Array.unzip([(1, 2), (3, 4), (5, 6), (7, 8)]) == ([1, 3, 5, 7], [2, 4, 6, 8]) - } - () - }) -}) - -describe("Belt_internalSetString.A.zip", () => { - test("Belt_internalSetString.A.zip", () => { - module Test = { - Belt.Array.zip([1, 2], [3, 4, 5]) == [(1, 3), (2, 4)] - } - () - }) -}) - -describe("Belt_internalSetString.A.zipBy", () => { - test("Belt_internalSetString.A.zipBy", () => { - module Test = { - Belt.Array.zipBy([1, 2, 3], [4, 5], (a, b) => 2 * a + b) == [6, 9] - } - () - }) -}) - -describe("BigInt.fromStringExn", () => { - test("BigInt.fromStringExn", () => { - module Test = { - /* returns 123n */ - BigInt.fromStringExn("123") - - /* returns 0n */ - BigInt.fromStringExn("") - - /* returns 17n */ - BigInt.fromStringExn("0x11") - - /* returns 3n */ - BigInt.fromStringExn("0b11") - - /* returns 9n */ - BigInt.fromStringExn("0o11") - - /* catch exception */ - try { - BigInt.fromStringExn("a") - } catch { - | Exn.Error(_error) => 0n - } - } - () - }) -}) - -describe("BigInt.toLocaleString", () => { - test("BigInt.toLocaleString", () => { - module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log - } - () - }) -}) - -describe("BigInt.toString", () => { - test("BigInt.toString", () => { - module Test = { - /* prints "123" */ - Js.BigInt.toString(123n)->Js.log - } - () - }) -}) - -describe("Console.assert2", () => { - test("Console.assert2", () => { - module Test = { - Console.assert2(false, "Hello", "World") - Console.assert2(42 == 42, [1, 2, 3], '4') - } - () - }) -}) - -describe("Console.assert3", () => { - test("Console.assert3", () => { - module Test = { - Console.assert3(false, "Hello", "World", "ReScript") - Console.assert3(42 == 42, "One", 2, #3) - } - () - }) -}) - -describe("Console.assert4", () => { - test("Console.assert4", () => { - module Test = { - let value = 42 - Console.assert4(false, "Hello", "World", "ReScript", "!!!") - Console.assert4(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar) - } - () - }) -}) - -describe("Console.assert5", () => { - test("Console.assert5", () => { - module Test = { - let value = 42 - Console.assert5(false, "Hello", "World", "JS", '!', '!') - Console.assert5(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.assert6", () => { - test("Console.assert6", () => { - module Test = { - let value = 42 - Console.assert6(false, "Hello", "World", "JS", '!', '!', '?') - Console.assert6(value == 42, [1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.assertMany", () => { - test("Console.assertMany", () => { - module Test = { - let value = 42 - Console.assertMany(false, ["Hello", "World"]) - Console.assertMany(value == 42, [1, 2, 3]) - } - () - }) -}) - -describe("Console.assert_", () => { - test("Console.assert_", () => { - module Test = { - Console.assert_(false, "Hello World!") - Console.assert_(42 == 42, "The answer") - } - () - }) -}) - -describe("Console.clear", () => { - test("Console.clear", () => { - module Test = { - Console.clear() - } - () - }) -}) - -describe("Console.count", () => { - test("Console.count", () => { - module Test = { - Console.count("rescript") - } - () - }) -}) - -describe("Console.countReset", () => { - test("Console.countReset", () => { - module Test = { - Console.countReset("rescript") - } - () - }) -}) - -describe("Console.debug", () => { - test("Console.debug", () => { - module Test = { - Console.debug("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.debug(obj) - } - () - }) -}) - -describe("Console.debug2", () => { - test("Console.debug2", () => { - module Test = { - Console.debug2("Hello", "World") - Console.debug2([1, 2, 3], '4') - } - () - }) -}) - -describe("Console.debug3", () => { - test("Console.debug3", () => { - module Test = { - Console.debug3("Hello", "World", "ReScript") - Console.debug3("One", 2, #3) - } - () - }) -}) - -describe("Console.debug4", () => { - test("Console.debug4", () => { - module Test = { - Console.debug4("Hello", "World", "ReScript", "!!!") - Console.debug4([1, 2], (3, 4), [#5, #6], #polyvar) - } - () - }) -}) - -describe("Console.debug5", () => { - test("Console.debug5", () => { - module Test = { - Console.debug5("Hello", "World", "JS", '!', '!') - Console.debug5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.debug6", () => { - test("Console.debug6", () => { - module Test = { - Console.debug6("Hello", "World", "JS", '!', '!', '?') - Console.debug6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.debugMany", () => { - test("Console.debugMany", () => { - module Test = { - Console.debugMany(["Hello", "World"]) - Console.debugMany([1, 2, 3]) - } - () - }) -}) - -describe("Console.dir", () => { - test("Console.dir", () => { - module Test = { - Console.dir({"language": "rescript", "version": "10.1.2"}) - } - () - }) -}) - -describe("Console.error", () => { - test("Console.error", () => { - module Test = { - Console.error("error message") - Console.error(("error", "invalid value")) - } - () - }) -}) - -describe("Console.error2", () => { - test("Console.error2", () => { - module Test = { - Console.error2("Error", "here") - Console.error2(("log", "error"), "message") - } - () - }) -}) - -describe("Console.error3", () => { - test("Console.error3", () => { - module Test = { - Console.error3("Hello", "World", "!!!") - Console.error3(#first, #second, #third) - } - () - }) -}) - -describe("Console.error4", () => { - test("Console.error4", () => { - module Test = { - Console.error4("Hello", "World", "ReScript", '!') - Console.error4(#first, #second, #third, "fourth") - } - () - }) -}) - -describe("Console.error5", () => { - test("Console.error5", () => { - module Test = { - Console.error5('e', 'r', 'r', 'o', 'r') - Console.error5(1, #second, #third, "fourth", 'c') - } - () - }) -}) - -describe("Console.error6", () => { - test("Console.error6", () => { - module Test = { - Console.error6("Hello", "World", "from", "JS", "!!!", '!') - Console.error6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.errorMany", () => { - test("Console.errorMany", () => { - module Test = { - Console.errorMany(["Hello", "World"]) - Console.errorMany([1, 2, 3]) - } - () - }) -}) - -describe("Console.group", () => { - test("Console.group", () => { - module Test = { - 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() - } - () - }) -}) - -describe("Console.info", () => { - test("Console.info", () => { - module Test = { - Console.info("Information") - Console.info(("Hello", "JS")) - } - () - }) -}) - -describe("Console.info2", () => { - test("Console.info2", () => { - module Test = { - Console.info2("Info", "failed to download") - Console.info2(#info, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.info3", () => { - test("Console.info3", () => { - module Test = { - Console.info3("Hello", "World", "ReScript") - Console.info3([1, 2, 3], #4, #5) - } - () - }) -}) - -describe("Console.info4", () => { - test("Console.info4", () => { - module Test = { - Console.info4("Hello", "World", "ReScript", '!') - Console.info4([1, 2, 3], #4, #5, #lastinfo) - } - () - }) -}) - -describe("Console.info5", () => { - test("Console.info5", () => { - module Test = { - Console.info5("Hello", "World", "from", "JS", "!!!") - Console.info5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.info6", () => { - test("Console.info6", () => { - module Test = { - Console.info6("Hello", "World", "from", "JS", "!!!", '!') - Console.info6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.infoMany", () => { - test("Console.infoMany", () => { - module Test = { - Console.infoMany(["Hello", "World"]) - Console.infoMany([1, 2, 3]) - } - () - }) -}) - -describe("Console.log", () => { - test("Console.log", () => { - module Test = { - Console.log("Hello") - let obj = {"name": "ReScript", "version": 10} - Console.log(obj) - } - () - }) -}) - -describe("Console.log2", () => { - test("Console.log2", () => { - module Test = { - Console.log2("Hello", "World") - Console.log2([1, 2, 3], '4') - } - () - }) -}) - -describe("Console.log3", () => { - test("Console.log3", () => { - module Test = { - Console.log3("Hello", "World", "ReScript") - Console.log3("One", 2, #3) - } - () - }) -}) - -describe("Console.log4", () => { - test("Console.log4", () => { - module Test = { - Console.log4("Hello", "World", "ReScript", "!!!") - Console.log4([1, 2], (3, 4), [#5, #6], #polyvar) - } - () - }) -}) - -describe("Console.log5", () => { - test("Console.log5", () => { - module Test = { - Console.log5("Hello", "World", "JS", '!', '!') - Console.log5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.log6", () => { - test("Console.log6", () => { - module Test = { - Console.log6("Hello", "World", "JS", '!', '!', '?') - Console.log6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.logMany", () => { - test("Console.logMany", () => { - module Test = { - Console.logMany(["Hello", "World"]) - Console.logMany([1, 2, 3]) - } - () - }) -}) - -describe("Console.table", () => { - test("Console.table", () => { - module Test = { - Console.table({"language": "rescript", "version": "10.1.2"}) - } - () - }) -}) - -describe("Console.time", () => { - test("Console.time", () => { - module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") - } - () - }) -}) - -describe("Console.timeEnd", () => { - test("Console.timeEnd", () => { - module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") - } - () - }) -}) - -describe("Console.timeLog", () => { - test("Console.timeLog", () => { - module Test = { - Console.time("for_time") - for x in 3 downto 1 { - Console.log(x) - Console.timeLog("for_time") - } - Console.timeEnd("for_time") - } - () - }) -}) - -describe("Console.trace", () => { - test("Console.trace", () => { - module Test = { - let main = () => { - Console.trace() - } - main() - // In the console, the following trace will be displayed: - // main - // - } - () - }) -}) - -describe("Console.warn", () => { - test("Console.warn", () => { - module Test = { - Console.warn("Warning") - Console.warn(("Warning", "invalid number")) - } - () - }) -}) - -describe("Console.warn2", () => { - test("Console.warn2", () => { - module Test = { - Console.warn2("Hello", "World") - Console.warn2([1, 2, 3], 4) - } - () - }) -}) - -describe("Console.warn3", () => { - test("Console.warn3", () => { - module Test = { - Console.warn3("Hello", "World", "ReScript") - Console.warn3([1, 2, 3], #4, #5) - } - () - }) -}) - -describe("Console.warn4", () => { - test("Console.warn4", () => { - module Test = { - Console.warn4("Hello", "World", "ReScript", "!!!") - Console.warn4(#first, #second, #third, "fourth") - } - () - }) -}) - -describe("Console.warn5", () => { - test("Console.warn5", () => { - module Test = { - Console.warn5("Hello", "World", "from", "JS", "!!!") - Console.warn5([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}) - } - () - }) -}) - -describe("Console.warn6", () => { - test("Console.warn6", () => { - module Test = { - Console.warn6("Hello", "World", "from", "JS", "!!!", '!') - Console.warn6([1, 2], (3, 4), [#5, #6], #polyvar, {"name": "ReScript"}, 42) - } - () - }) -}) - -describe("Console.warnMany", () => { - test("Console.warnMany", () => { - module Test = { - Console.warnMany(["Hello", "World"]) - Console.warnMany([1, 2, 3]) - } - () - }) -}) - -describe("Date.UTC.makeWithYM", () => { - test("Date.UTC.makeWithYM", () => { - module Test = { - Date.UTC.makeWithYM(~year=2023, ~month=0) - // 1672531200000 - - Date.UTC.makeWithYM(~year=2023, ~month=11) - // 1701388800000 - - Date.UTC.makeWithYM(~year=2023, ~month=12) - // 1704067200000 - - Date.UTC.makeWithYM(~year=2023, ~month=-1) - // 1669852800000 - } - () - }) -}) - -describe("Date.UTC.makeWithYMD", () => { - test("Date.UTC.makeWithYMD", () => { - module Test = { - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=20) - // 1676851200000 - - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=-1) - // 1675036800000 - - Date.UTC.makeWithYMD(~year=2023, ~month=1, ~date=29) - // 1677628800000 - } - () - }) -}) - -describe("Date.UTC.makeWithYMDH", () => { - test("Date.UTC.makeWithYMDH", () => { - module Test = { - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 1676908800000 - - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 1676937600000 - - Date.UTC.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 1676847600000 - } - () - }) -}) - -describe("Date.UTC.makeWithYMDHM", () => { - test("Date.UTC.makeWithYMDHM", () => { - module Test = { - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 1676911200000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 1676912400000 - - Date.UTC.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 1676908740000 - } - () - }) -}) - -describe("Date.UTC.makeWithYMDHMS", () => { - test("Date.UTC.makeWithYMDHMS", () => { - module Test = { - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 1676911200000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 1676911260000 - - Date.UTC.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 1676911199000 - } - () - }) -}) - -describe("Date.UTC.makeWithYMDHMSM", () => { - test("Date.UTC.makeWithYMDHMSM", () => { - module Test = { - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - )->Console.log - // 1676911200000 - - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - )->Console.log - // 1676911201000 - - Date.UTC.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=-1, - )->Console.log - // 1676911199999 - } - () - }) -}) - -describe("Date.fromString", () => { - test("Date.fromString", () => { - module Test = { - Date.fromString("2023") // 2023-01-01T00:00:00.000Z - - Date.fromString("2023-02-20") // 2023-02-20T00:00:00.000Z - - Date.fromString("2023-02-20T16:40:00.00Z") // 2023-02-20T16:40:00.000Z - - Date.fromString("") // Invalid Date - - Date.fromString("")->Date.getTime // NaN - } - () - }) -}) - -describe("Date.fromTime", () => { - test("Date.fromTime", () => { - module Test = { - Date.fromTime(0.0) - // 1970-01-01T00:00:00.000Z - - Date.fromTime(-86_400_000.0) - // 1969-12-31T00:00:00.000Z - - Date.fromTime(86_400_000.0) - // 1970-01-02T00:00:00.000Z - } - () - }) -}) - -describe("Date.getDate", () => { - test("Date.getDate", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDate - // 20 - } - () - }) -}) - -describe("Date.getDay", () => { - test("Date.getDay", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getDay - // 1 - } - () - }) -}) - -describe("Date.getFullYear", () => { - test("Date.getFullYear", () => { - module Test = { - Date.fromString("2023-02-20")->Date.getFullYear - // 2023 - } - () - }) -}) - -describe("Date.getHours", () => { - test("Date.getHours", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getHours - // 16 - } - () - }) -}) - -describe("Date.getMilliseconds", () => { - test("Date.getMilliseconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMilliseconds - // 0 - } - () - }) -}) - -describe("Date.getMinutes", () => { - test("Date.getMinutes", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getMinutes - // 40 - } - () - }) -}) - -describe("Date.getMonth", () => { - test("Date.getMonth", () => { - module Test = { - Date.fromString("2023-01-01")->Date.getMonth - // 0 - } - () - }) -}) - -describe("Date.getSeconds", () => { - test("Date.getSeconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.getSeconds - // 0 - } - () - }) -}) - -describe("Date.getTime", () => { - test("Date.getTime", () => { - module Test = { - Date.fromString("2023-02-20")->Date.getTime - // 1676851200000 - } - () - }) -}) - -describe("Date.getTimezoneOffset", () => { - test("Date.getTimezoneOffset", () => { - module Test = { - Date.fromString("2023-01-01")->Date.getTimezoneOffset - // -60 with local time zone = Europe/Berlin - - Date.fromString("2023-06-01")->Date.getTimezoneOffset - // -120 with local time zone = Europe/Berlin - } - () - }) -}) - -describe("Date.getUTCDate", () => { - test("Date.getUTCDate", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDate // 31 - } - () - }) -}) - -describe("Date.getUTCDay", () => { - test("Date.getUTCDay", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCDay // 6 - } - () - }) -}) - -describe("Date.getUTCFullYear", () => { - test("Date.getUTCFullYear", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCFullYear // 2022 - } - () - }) -}) - -describe("Date.getUTCHours", () => { - test("Date.getUTCHours", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCHours // 23 - } - () - }) -}) - -describe("Date.getUTCMilliseconds", () => { - test("Date.getUTCMilliseconds", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMilliseconds // 0 - } - () - }) -}) - -describe("Date.getUTCMinutes", () => { - test("Date.getUTCMinutes", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMinutes // 0 - } - () - }) -}) - -describe("Date.getUTCMonth", () => { - test("Date.getUTCMonth", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCMonth // 11 - } - () - }) -}) - -describe("Date.getUTCSeconds", () => { - test("Date.getUTCSeconds", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.getUTCSeconds // 0 - } - () - }) -}) - -describe("Date.make", () => { - test("Date.make", () => { - module Test = { - Date.make() - } - () - }) -}) - -describe("Date.makeWithYM", () => { - test("Date.makeWithYM", () => { - module Test = { - Date.makeWithYM(~year=2023, ~month=0) - // 2023-01-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=11) - // 2023-12-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=12) - // 2024-01-01T00:00:00.000Z - - Date.makeWithYM(~year=2023, ~month=-1) - // 2022-12-01T00:00:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - } - () - }) -}) - -describe("Date.makeWithYMD", () => { - test("Date.makeWithYMD", () => { - module Test = { - Date.makeWithYMD(~year=2023, ~month=1, ~date=20) - // 2023-02-20T00:00:00.000Z - - Date.makeWithYMD(~year=2023, ~month=1, ~date=-1) - // 2022-11-29T00:00:00.000Z - - Date.makeWithYMD(~year=2023, ~month=1, ~date=29) - // 2023-03-01T00:00:00.000Z - } - () - }) -}) - -describe("Date.makeWithYMDH", () => { - test("Date.makeWithYMDH", () => { - module Test = { - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=16) - // 2023-02-20T16:00:00.000Z - - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=24) - // 2023-02-21T00:00:00.000Z - - Date.makeWithYMDH(~year=2023, ~month=1, ~date=20, ~hours=-1) - // 2023-02-19T23:00:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - } - () - }) -}) - -describe("Date.makeWithYMDHM", () => { - test("Date.makeWithYMDHM", () => { - module Test = { - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=60) - // 2023-02-20T17:00:00.000Z - - Date.makeWithYMDHM(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=-1) - // 2023-02-20T15:59:00.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - } - () - }) -}) - -describe("Date.makeWithYMDHMS", () => { - test("Date.makeWithYMDHMS", () => { - module Test = { - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=0) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=60) - // 2023-02-20T16:41:00.000Z - - Date.makeWithYMDHMS(~year=2023, ~month=1, ~date=20, ~hours=16, ~minutes=40, ~seconds=-1) - // 2023-02-20T16:39:59.000Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - } - () - }) -}) - -describe("Date.makeWithYMDHMSM", () => { - test("Date.makeWithYMDHMSM", () => { - module Test = { - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=0, - ) - // 2023-02-20T16:40:00.000Z - - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=1000, - ) - // 2023-02-20T16:40:01.000Z - - Date.makeWithYMDHMSM( - ~year=2023, - ~month=1, - ~date=20, - ~hours=16, - ~minutes=40, - ~seconds=0, - ~milliseconds=-1, - ) - // 2023-02-20T16:39:59.999Z - - // Note: The output depends on your local time zone. - // In nodejs you can change it by using the TZ env (`export TZ='Europe/London' && node index.bs.js`) - } - () - }) -}) - -describe("Date.setDate", () => { - test("Date.setDate", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setDate(1) - } - () - }) -}) - -describe("Date.setFullYear", () => { - test("Date.setFullYear", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYear(2024) - } - () - }) -}) - -describe("Date.setFullYearM", () => { - test("Date.setFullYearM", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearM(~year=2024, ~month=0) - } - () - }) -}) - -describe("Date.setFullYearMD", () => { - test("Date.setFullYearMD", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setFullYearMD(~year=2024, ~month=0, ~date=1) - } - () - }) -}) - -describe("Date.setHours", () => { - test("Date.setHours", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHours(0) - } - () - }) -}) - -describe("Date.setHoursM", () => { - test("Date.setHoursM", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursM(~hours=0, ~minutes=0) - } - () - }) -}) - -describe("Date.setHoursMS", () => { - test("Date.setHoursMS", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMS(~hours=0, ~minutes=0, ~seconds=0) - } - () - }) -}) - -describe("Date.setHoursMSMs", () => { - test("Date.setHoursMSMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) - } - () - }) -}) - -describe("Date.setMilliseconds", () => { - test("Date.setMilliseconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMilliseconds(0) - } - () - }) -}) - -describe("Date.setMinutes", () => { - test("Date.setMinutes", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutes(0) - } - () - }) -}) - -describe("Date.setMinutesS", () => { - test("Date.setMinutesS", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesS(~minutes=0, ~seconds=0) - } - () - }) -}) - -describe("Date.setMinutesSMs", () => { - test("Date.setMinutesSMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) - } - () - }) -}) - -describe("Date.setMonth", () => { - test("Date.setMonth", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setMonth(0) - } - () - }) -}) - -describe("Date.setSeconds", () => { - test("Date.setSeconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSeconds(0) - } - () - }) -}) - -describe("Date.setSecondsMs", () => { - test("Date.setSecondsMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setSecondsMs(~seconds=0, ~milliseconds=0) - } - () - }) -}) - -describe("Date.setUTCDate", () => { - test("Date.setUTCDate", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCDate(1) - } - () - }) -}) - -describe("Date.setUTCFullYear", () => { - test("Date.setUTCFullYear", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYear(2024) - } - () - }) -}) - -describe("Date.setUTCFullYearM", () => { - test("Date.setUTCFullYearM", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearM(~year=2024, ~month=0) - } - () - }) -}) - -describe("Date.setUTCFullYearMD", () => { - test("Date.setUTCFullYearMD", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCFullYearMD( - ~year=2024, - ~month=0, - ~date=1, - ) - } - () - }) -}) - -describe("Date.setUTCHours", () => { - test("Date.setUTCHours", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHours(0) - } - () - }) -}) - -describe("Date.setUTCHoursM", () => { - test("Date.setUTCHoursM", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursM(~hours=0, ~minutes=0) - } - () - }) -}) - -describe("Date.setUTCHoursMS", () => { - test("Date.setUTCHoursMS", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMS( - ~hours=0, - ~minutes=0, - ~seconds=0, - ) - } - () - }) -}) - -describe("Date.setUTCHoursMSMs", () => { - test("Date.setUTCHoursMSMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCHoursMSMs( - ~hours=0, - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) - } - () - }) -}) - -describe("Date.setUTCMilliseconds", () => { - test("Date.setUTCMilliseconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMilliseconds(0) - } - () - }) -}) - -describe("Date.setUTCMinutes", () => { - test("Date.setUTCMinutes", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutes(0) - } - () - }) -}) - -describe("Date.setUTCMinutesS", () => { - test("Date.setUTCMinutesS", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesS(~minutes=0, ~seconds=0) - } - () - }) -}) - -describe("Date.setUTCMinutesSMs", () => { - test("Date.setUTCMinutesSMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMinutesSMs( - ~minutes=0, - ~seconds=0, - ~milliseconds=0, - ) - } - () - }) -}) - -describe("Date.setUTCMonth", () => { - test("Date.setUTCMonth", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCMonth(0) - } - () - }) -}) - -describe("Date.setUTCSeconds", () => { - test("Date.setUTCSeconds", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSeconds(0) - } - () - }) -}) - -describe("Date.setUTCSecondsMs", () => { - test("Date.setUTCSecondsMs", () => { - module Test = { - Date.fromString("2023-02-20T16:40:00.00")->Date.setUTCSecondsMs(~seconds=0, ~milliseconds=0) - } - () - }) -}) - -describe("Date.toDateString", () => { - test("Date.toDateString", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toDateString->Console.log - // Sun Jan 01 2023 - - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toDateString->Console.log - // Sat Dec 31 2022 - } - () - }) -}) - -describe("Date.toISOString", () => { - test("Date.toISOString", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toISOString->Console.log - // 2023-01-01T00:00:00.000Z - - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toISOString->Console.log - // 2022-12-31T16:00:00.000Z - } - () - }) -}) - -describe("Date.toJSON", () => { - test("Date.toJSON", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toJSON - // Some("2023-01-01T00:00:00.000Z") - - Date.fromString("")->Date.toJSON - // None - } - () - }) -}) - -describe("Date.toLocaleDateString", () => { - test("Date.toLocaleDateString", () => { - module Test = { - Date.make()->Date.toLocaleDateString->Console.log - // 2/19/2023 - } - () - }) -}) - -describe("Date.toLocaleDateStringWithLocale", () => { - test("Date.toLocaleDateStringWithLocale", () => { - module Test = { - Date.make()->Date.toLocaleDateStringWithLocale("en-US")->Console.log - // 2/19/2023 - } - () - }) -}) - -describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { - test("Date.toLocaleDateStringWithLocaleAndOptions", () => { - module Test = { - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("en-US", {dateStyle: #long}) - ->Console.log - // February 19, 2023 - - Date.make() - ->Date.toLocaleDateStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 19.2.2023, 15:40 - - Date.make()->Date.toLocaleDateStringWithLocaleAndOptions("de", {year: #numeric})->Console.log - // 2023 - } - () - }) -}) - -describe("Date.toLocaleString", () => { - test("Date.toLocaleString", () => { - module Test = { - Date.make()->Date.toLocaleString->Console.log - // 2/19/2023, 3:40:00 PM - } - () - }) -}) - -describe("Date.toLocaleStringWithLocale", () => { - test("Date.toLocaleStringWithLocale", () => { - module Test = { - Date.make()->Date.toLocaleStringWithLocale("en-US")->Console.log - // 2/19/2023, 3:40:00 PM - } - () - }) -}) - -describe("Date.toLocaleStringWithLocaleAndOptions", () => { - test("Date.toLocaleStringWithLocaleAndOptions", () => { - module Test = { - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions("en", {dateStyle: #short, timeStyle: #short}) - ->Console.log - // 2/19/23, 3:40 PM - - Date.make() - ->Date.toLocaleStringWithLocaleAndOptions( - "en", - { - era: #long, - year: #numeric, - month: #"2-digit", - day: #"2-digit", - hour: #numeric, - timeZoneName: #short, - }, - ) - ->Console.log - // 02/19/2023 Anno Domini, 3 PM GMT+1 - } - () - }) -}) - -describe("Date.toLocaleTimeString", () => { - test("Date.toLocaleTimeString", () => { - module Test = { - Date.make()->Date.toLocaleTimeString->Console.log - // 3:40:00 PM - } - () - }) -}) - -describe("Date.toLocaleTimeStringWithLocale", () => { - test("Date.toLocaleTimeStringWithLocale", () => { - module Test = { - Date.make()->Date.toLocaleTimeStringWithLocale("en-US")->Console.log - // 3:40:00 PM - } - () - }) -}) - -describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - module Test = { - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("en-US", {timeStyle: #long}) - ->Console.log - // 3:40:00 PM GMT+1 - - Date.make() - ->Date.toLocaleTimeStringWithLocaleAndOptions("de", {hour: #"2-digit", minute: #"2-digit"}) - ->Console.log - // 15:40 - } - () - }) -}) - -describe("Date.toString", () => { - test("Date.toString", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toString->Console.log - // Sun Jan 01 2023 00:00:00 GMT+0100 (Central European Standard Time) - - Date.fromString("2023-06-01T00:00:00.00+01:00")->Date.toString->Console.log - // Thu Jun 01 2023 01:00:00 GMT+0200 (Central European Summer Time) - } - () - }) -}) - -describe("Date.toTimeString", () => { - test("Date.toTimeString", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+01:00")->Date.toTimeString->Console.log - // 00:00:00 GMT+0100 (Central European Standard Time) - - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toTimeString->Console.log - // 17:00:00 GMT+0100 (Central European Standard Time) - } - () - }) -}) - -describe("Date.toUTCString", () => { - test("Date.toUTCString", () => { - module Test = { - Date.fromString("2023-01-01T00:00:00.00+00:00")->Date.toUTCString->Console.log - // Sun, 01 Jan 2023 00:00:00 GMT - - Date.fromString("2023-01-01T00:00:00.00+08:00")->Date.toUTCString->Console.log - // Sat, 31 Dec 2022 16:00:00 GMT - } - () - }) -}) - -describe("Dict.assign", () => { - test("Dict.assign", () => { - module Test = { - let dict1 = Dict.make() - dict1->Dict.set("firstKey", 1) - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey"]` - - let dict2 = Dict.make() - dict2->Dict.set("someKey", 2) - dict2->Dict.set("someKey2", 3) - - let dict1 = dict1->Dict.assign(dict2) - - Console.log(dict1->Dict.keysToArray) // Logs `["firstKey", "someKey", "someKey2"]` - } - () - }) -}) - -describe("Dict.copy", () => { - test("Dict.copy", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let dict2 = dict->Dict.copy - - // Both log `["key1", "key2"]` here. - Console.log2(dict->Dict.keysToArray, dict2->Dict.keysToArray) - } - () - }) -}) - -describe("Dict.delete", () => { - test("Dict.delete", () => { - module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - dict->Dict.delete("someKey") - } - () - }) -}) - -describe("Dict.forEach", () => { - test("Dict.forEach", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - - dict->Dict.forEach( - value => { - Console.log(value) - }, - ) - } - () - }) -}) - -describe("Dict.forEachWithKey", () => { - test("Dict.forEachWithKey", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - - dict->Dict.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) - } - () - }) -}) - -describe("Dict.fromArray", () => { - test("Dict.fromArray", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - } - () - }) -}) - -describe("Dict.fromIterator", () => { - test("Dict.fromIterator", () => { - module Test = { - let iterator: Iterator.t<(string, int)> = %raw(` - (() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - iterator - ->Dict.fromIterator - ->Dict.valuesToArray - ->assertEqual([1, 2]) - } - () - }) -}) - -describe("Dict.get", () => { - test("Dict.get", () => { - module Test = { - let dict = Dict.fromArray([("someKey", "someValue")]) - - switch dict->Dict.get("someKey") { - | None => Console.log("Nope, didn't have the key.") - | Some(value) => Console.log(value) - } - } - () - }) -}) - -describe("Dict.getUnsafe", () => { - test("Dict.getUnsafe", () => { - module Test = { - let dict = Dict.fromArray([("key1", "value1"), ("key2", "value2")]) - let value = dict->Dict.getUnsafe("key1") - Console.log(value) // value1 - } - () - }) -}) - -describe("Dict.keysToArray", () => { - test("Dict.keysToArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let keys = dict->Dict.keysToArray - Console.log(keys) // Logs `["someKey", "someKey2"]` to the console - } - () - }) -}) - -describe("Dict.make", () => { - test("Dict.make", () => { - module Test = { - let dict1: dict = Dict.make() // You can annotate the type of the values of your dict yourself if you want - - let dict2 = Dict.make() // Or you can let ReScript infer it via usage. - dict2->Dict.set("someKey", 12) - } - () - }) -}) - -describe("Dict.mapValues", () => { - test("Dict.mapValues", () => { - module Test = { - let dict = Dict.fromArray([("key1", 1), ("key2", 2)]) - - dict->Dict.mapValues(v => v + 10)->Dict.toArray // [("key1", 11), ("key2", 12)] - dict->Dict.mapValues(v => Int.toString(v))->Dict.toArray // [("key1", "1"), ("key2", "2")] - } - () - }) -}) - -describe("Dict.set", () => { - test("Dict.set", () => { - module Test = { - let dict = Dict.make() - - dict->Dict.set("someKey", "someValue") - } - () - }) -}) - -describe("Dict.toArray", () => { - test("Dict.toArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let asArray = dict->Dict.toArray - Console.log(asArray) // Logs `[["someKey", 1], ["someKey2", 2]]` to the console - } - () - }) -}) - -describe("Dict.valuesToArray", () => { - test("Dict.valuesToArray", () => { - module Test = { - let dict = Dict.make() - dict->Dict.set("someKey", 1) - dict->Dict.set("someKey2", 2) - let values = dict->Dict.valuesToArray - Console.log(values) // Logs `[1, 2]` to the console - } - () - }) -}) - -describe("Error.make", () => { - test("Error.make", () => { - module Test = { - let error = Error.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console - Console.log(error->Error.name) // Logs "Error" to the console, because this is a regular error - } - () - }) -}) - -describe("Error.message", () => { - test("Error.message", () => { - module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.message) // Logs "Some message here" to the console - } - () - }) -}) - -describe("Error.name", () => { - test("Error.name", () => { - module Test = { - let error = Error.SyntaxError.make("Some message here") - Console.log(error->Error.name) // Logs "SyntaxError" to the console - } - () - }) -}) - -describe("Error.panic", () => { - test("Error.panic", () => { - module Test = { - try { - Error.panic("Uh oh. This was unexpected!") - } catch { - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(m) => assert(m == "Panic! Uh oh. This was unexpected!") - | None => assert(false) - } - | _ => assert(false) - } - } - () - }) -}) - -describe("Error.raise", () => { - test("Error.raise", () => { - module Test = { - let error = Error.make("Everything is upside down.") - - if 5 > 10 { - error->Error.raise - } else { - Console.log("Phew, sanity still rules.") - } - } - () - }) -}) - -describe("Error.stack", () => { - test("Error.stack", () => { - module Test = { - let error = Error.make("error") - Console.log(error->Error.stack) // Logs `stack` if it exists on `someError` - } - () - }) -}) - -describe("Error.toException", () => { - test("Error.toException", () => { - module Test = { - let error = Error.make("Something went wrong.") - - let asExn = error->Error.toException // `asExn` is now type `exn` - } - () - }) -}) - -describe("Float.Constants.epsilon", () => { - test("Float.Constants.epsilon", () => { - module Test = { - Float.Constants.epsilon - } - () - }) -}) - -describe("Float.Constants.maxValue", () => { - test("Float.Constants.maxValue", () => { - module Test = { - Float.Constants.minValue - } - () - }) -}) - -describe("Float.Constants.minValue", () => { - test("Float.Constants.minValue", () => { - module Test = { - Float.Constants.minValue - } - () - }) -}) - -describe("Float.Constants.nan", () => { - test("Float.Constants.nan", () => { - module Test = { - Float.Constants.nan - } - () - }) -}) - -describe("Float.Constants.negativeInfinity", () => { - test("Float.Constants.negativeInfinity", () => { - module Test = { - Float.Constants.negativeInfinity - } - () - }) -}) - -describe("Float.Constants.positiveInfinity", () => { - test("Float.Constants.positiveInfinity", () => { - module Test = { - Float.Constants.positiveInfinity - } - () - }) -}) - -describe("Float.clamp", () => { - test("Float.clamp", () => { - module Test = { - Float.clamp(4.2) == 4.2 - Float.clamp(4.2, ~min=4.3) == 4.3 - Float.clamp(4.2, ~max=4.1) == 4.1 - Float.clamp(4.2, ~min=4.3, ~max=4.1) == 4.3 - } - () - }) -}) - -describe("Float.fromInt", () => { - test("Float.fromInt", () => { - module Test = { - Float.fromInt(2) == 2.0 - Float.fromInt(1) == 1.0 - } - () - }) -}) - -describe("Float.fromString", () => { - test("Float.fromString", () => { - module Test = { - Float.fromString("0") == Some(0.0) - Float.fromString("NaN") == None - Float.fromString("6") == Some(6.0) - } - () - }) -}) - -describe("Float.isFinite", () => { - test("Float.isFinite", () => { - module Test = { - Float.isFinite(1.0) // true - Float.isFinite(Float.Constants.nan) // false - Float.isFinite(Float.Constants.positiveInfinity) // false - } - () - }) -}) - -describe("Float.isNaN", () => { - test("Float.isNaN", () => { - module Test = { - Float.isNaN(3.0) // false - Float.isNaN(Float.Constants.nan) // true - } - () - }) -}) - -describe("Float.mod", () => { - test("Float.mod", () => { - module Test = { - Float.mod(7.0, 4.0) == 3.0 - } - () - }) -}) - -describe("Float.parseFloat", () => { - test("Float.parseFloat", () => { - module Test = { - Float.parseFloat("1.0") // 1.0 - Float.parseFloat(" 3.14 ") // 3.14 - Float.parseFloat("3.0") // 3.0 - Float.parseFloat("3.14some non-digit characters") // 3.14 - Float.parseFloat("error")->Float.isNaN // true - } - () - }) -}) - -describe("Float.parseInt", () => { - test("Float.parseInt", () => { - module Test = { - Float.parseInt("1.0") // 1.0 - Float.parseInt(" 3.14 ") // 3.0 - Float.parseInt(3) // 3.0 - Float.parseInt("3.14some non-digit characters") // 3.0 - Float.parseInt("error")->Float.isNaN // true - Float.parseInt("10.0", ~radix=2) // 2.0 - Float.parseInt("15 * 3", ~radix=10) // 15.0 - Float.parseInt("12", ~radix=13) // 15.0 - Float.parseInt("17", ~radix=40)->Float.isNaN // true - } - () - }) -}) - -describe("Float.parseIntWithRadix", () => { - test("Float.parseIntWithRadix", () => { - module Test = { - Float.parseIntWithRadix("10.0", ~radix=2) // 2.0 - Float.parseIntWithRadix("15 * 3", ~radix=10) // 15.0 - Float.parseIntWithRadix("12", ~radix=13) // 15.0 - Float.parseIntWithRadix("17", ~radix=40)->Float.isNaN // true - } - () - }) -}) - -describe("Float.toExponential", () => { - test("Float.toExponential", () => { - module Test = { - Float.toExponential(1000.0) // "1e+3" - Float.toExponential(-1000.0) // "-1e+3" - Float.toExponential(77.0, ~digits=2) // "7.70e+1" - Float.toExponential(5678.0, ~digits=2) // "5.68e+3" - } - () - }) -}) - -describe("Float.toExponentialWithPrecision", () => { - test("Float.toExponentialWithPrecision", () => { - module Test = { - Float.toExponentialWithPrecision(77.0, ~digits=2) // "7.70e+1" - Float.toExponentialWithPrecision(5678.0, ~digits=2) // "5.68e+3" - } - () - }) -}) - -describe("Float.toFixed", () => { - test("Float.toFixed", () => { - module Test = { - Float.toFixed(123456.0) // "123456.00" - Float.toFixed(10.0) // "10.00" - Float.toFixed(300.0, ~digits=4) // "300.0000" - Float.toFixed(300.0, ~digits=1) // "300.0" - } - () - }) -}) - -describe("Float.toFixedWithPrecision", () => { - test("Float.toFixedWithPrecision", () => { - module Test = { - Float.toFixedWithPrecision(300.0, ~digits=4) // "300.0000" - Float.toFixedWithPrecision(300.0, ~digits=1) // "300.0" - } - () - }) -}) - -describe("Float.toInt", () => { - test("Float.toInt", () => { - module Test = { - Float.toInt(2.0) == 2 - Float.toInt(1.0) == 1 - Float.toInt(1.1) == 1 - Float.toInt(1.6) == 1 - } - () - }) -}) - -describe("Float.toLocaleString", () => { - test("Float.toLocaleString", () => { - module Test = { - // If the application uses English as the default language - Float.toLocaleString(1000.0) // "1,000" - - // If the application uses Portuguese Brazil as the default language - Float.toLocaleString(1000.0) // "1.000" - } - () - }) -}) - -describe("Float.toPrecision", () => { - test("Float.toPrecision", () => { - module Test = { - Float.toPrecision(100.0) // "100" - Float.toPrecision(1.0) // "1" - Float.toPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecision(1.0, ~digits=1) // "1" - } - () - }) -}) - -describe("Float.toPrecisionWithPrecision", () => { - test("Float.toPrecisionWithPrecision", () => { - module Test = { - Float.toPrecisionWithPrecision(100.0, ~digits=2) // "1.0e+2" - Float.toPrecisionWithPrecision(1.0, ~digits=1) // "1" - } - () - }) -}) - -describe("Float.toString", () => { - test("Float.toString", () => { - module Test = { - Float.toString(1000.0) // "1000" - Float.toString(-1000.0) // "-1000" - } - () - }) -}) - -describe("Float.toStringWithRadix", () => { - test("Float.toStringWithRadix", () => { - module Test = { - Float.toStringWithRadix(6.0, ~radix=2) // "110" - Float.toStringWithRadix(3735928559.0, ~radix=16) // "deadbeef" - Float.toStringWithRadix(123456.0, ~radix=36) // "2n9c" - } - () - }) -}) - -describe("Int.Bitwise.asr", () => { - test("Int.Bitwise.asr", () => { - module Test = { - Int.Bitwise.asr(4, 1) == 2 - } - () - }) -}) - -describe("Int.Bitwise.land", () => { - test("Int.Bitwise.land", () => { - module Test = { - Int.Bitwise.land(7, 4) == 4 - } - () - }) -}) - -describe("Int.Bitwise.lnot", () => { - test("Int.Bitwise.lnot", () => { - module Test = { - Int.Bitwise.lnot(2) == -3 - } - () - }) -}) - -describe("Int.Bitwise.lor", () => { - test("Int.Bitwise.lor", () => { - module Test = { - Int.Bitwise.lor(7, 4) == 7 - } - () - }) -}) - -describe("Int.Bitwise.lsl", () => { - test("Int.Bitwise.lsl", () => { - module Test = { - Int.Bitwise.lsl(4, 1) == 8 - } - () - }) -}) - -describe("Int.Bitwise.lsr", () => { - test("Int.Bitwise.lsr", () => { - module Test = { - Int.Bitwise.lsr(8, 1) == 4 - } - () - }) -}) - -describe("Int.Bitwise.lxor", () => { - test("Int.Bitwise.lxor", () => { - module Test = { - Int.Bitwise.lxor(7, 4) == 3 - } - () - }) -}) - -describe("Int.Constants.maxValue", () => { - test("Int.Constants.maxValue", () => { - module Test = { - Console.log(Int.Constants.maxValue) - } - () - }) -}) - -describe("Int.Constants.minValue", () => { - test("Int.Constants.minValue", () => { - module Test = { - Console.log(Int.Constants.minValue) - } - () - }) -}) - -describe("Int.clamp", () => { - test("Int.clamp", () => { - module Test = { - Int.clamp(42) == 42 - Int.clamp(42, ~min=50) == 50 - Int.clamp(42, ~max=40) == 40 - Int.clamp(42, ~min=50, ~max=40) == 50 - } - () - }) -}) - -describe("Int.fromFloat", () => { - test("Int.fromFloat", () => { - module Test = { - Int.fromFloat(2.0) == 2 - Int.fromFloat(1.999) == 1 - Int.fromFloat(1.5) == 1 - Int.fromFloat(0.9999) == 0 - } - () - }) -}) - -describe("Int.fromString", () => { - test("Int.fromString", () => { - module Test = { - Int.fromString("0") == Some(0) - Int.fromString("NaN") == None - Int.fromString("6", ~radix=2) == None - } - () - }) -}) - -describe("Int.mod", () => { - test("Int.mod", () => { - module Test = { - Int.mod(7, 4) == 3 - } - () - }) -}) - -describe("Int.range", () => { - test("Int.range", () => { - module Test = { - Int.range(3, 6) == [3, 4, 5] - Int.range(-3, -1) == [-3, -2] - Int.range(3, 1) == [3, 2] - Int.range(3, 7, ~options={step: 2}) == [3, 5] - Int.range(3, 7, ~options={step: 2, inclusive: true}) == [3, 5, 7] - Int.range(3, 6, ~options={step: -2}) // RangeError - } - () - }) -}) - -describe("Int.rangeWithOptions", () => { - test("Int.rangeWithOptions", () => { - module Test = { - Int.rangeWithOptions(3, 7, {step: 2}) == [3, 5] - Int.rangeWithOptions(3, 7, {step: 2, inclusive: true}) == [3, 5, 7] - Int.rangeWithOptions(3, 6, {step: -2}) // RangeError - } - () - }) -}) - -describe("Int.toExponential", () => { - test("Int.toExponential", () => { - module Test = { - Int.toExponential(1000) // "1e+3" - Int.toExponential(-1000) // "-1e+3" - Int.toExponential(77, ~digits=2) // "7.70e+1" - Int.toExponential(5678, ~digits=2) // "5.68e+3" - } - () - }) -}) - -describe("Int.toExponentialWithPrecision", () => { - test("Int.toExponentialWithPrecision", () => { - module Test = { - Int.toExponentialWithPrecision(77, ~digits=2) // "7.70e+1" - Int.toExponentialWithPrecision(5678, ~digits=2) // "5.68e+3" - } - () - }) -}) - -describe("Int.toFixed", () => { - test("Int.toFixed", () => { - module Test = { - Int.toFixed(123456) // "123456.00" - Int.toFixed(10) // "10.00" - Int.toFixed(300, ~digits=4) // "300.0000" - Int.toFixed(300, ~digits=1) // "300.0" - } - () - }) -}) - -describe("Int.toFixedWithPrecision", () => { - test("Int.toFixedWithPrecision", () => { - module Test = { - Int.toFixedWithPrecision(300, ~digits=4) // "300.0000" - Int.toFixedWithPrecision(300, ~digits=1) // "300.0" - } - () - }) -}) - -describe("Int.toFloat", () => { - test("Int.toFloat", () => { - module Test = { - Int.toFloat(100) == 100.0 - Int.toFloat(2) == 2.0 - } - () - }) -}) - -describe("Int.toLocaleString", () => { - test("Int.toLocaleString", () => { - module Test = { - // If the application uses English as the default language - Int.toLocaleString(1000) // "1,000" - - // If the application uses Portuguese Brazil as the default language - Int.toLocaleString(1000) // "1.000" - } - () - }) -}) - -describe("Int.toPrecision", () => { - test("Int.toPrecision", () => { - module Test = { - Int.toPrecision(100) // "100" - Int.toPrecision(1) // "1" - Int.toPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecision(1, ~digits=2) // "1.0" - } - () - }) -}) - -describe("Int.toPrecisionWithPrecision", () => { - test("Int.toPrecisionWithPrecision", () => { - module Test = { - Int.toPrecisionWithPrecision(100, ~digits=2) // "1.0e+2" - Int.toPrecisionWithPrecision(1, ~digits=2) // "1.0" - } - () - }) -}) - -describe("Int.toString", () => { - test("Int.toString", () => { - module Test = { - Int.toString(1000) // "1000" - Int.toString(-1000) // "-1000" - Int.toString(6, ~radix=2) // "110" - Int.toString(373592855, ~radix=16) // "16449317" - Int.toString(123456, ~radix=36) // "2n9c" - } - () - }) -}) - -describe("Int.toStringWithRadix", () => { - test("Int.toStringWithRadix", () => { - module Test = { - Int.toStringWithRadix(6, ~radix=2) // "110" - Int.toStringWithRadix(373592855, ~radix=16) // "16449317" - Int.toStringWithRadix(123456, ~radix=36) // "2n9c" - } - () - }) -}) - -describe("Iterator.forEach", () => { - test("Iterator.forEach", () => { - module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - iterator->Iterator.forEach( - v => { - switch v { - | Some("a" | "b" | "c") => assert(true) - | other => - other - ->Option.isNone - ->assertEqual(true) - } - }, - ) - } - () - }) -}) - -describe("Iterator.next", () => { - test("Iterator.next", () => { - module Test = { - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - (iterator->Iterator.next).done->assertEqual(false) - (iterator->Iterator.next).done->assertEqual(true) - } - () - }) -}) - -describe("Iterator.toArray", () => { - test("Iterator.toArray", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = map->Map.keys->Iterator.toArray - - Console.log(mapKeysAsArray) // Logs ["someKey", "someKey2"] to the console. - } - () - }) -}) - -describe("Iterator.toArrayWithMapper", () => { - test("Iterator.toArrayWithMapper", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - // `Map.keys` returns all keys of the map as an iterator. - let mapKeysAsArray = - map - ->Map.keys - ->Iterator.toArrayWithMapper(key => key->String.length) - - Console.log(mapKeysAsArray) // Logs [7, 8] to the console. - } - () - }) -}) - -describe("JSON.Classify.classify", () => { - test("JSON.Classify.classify", () => { - module Test = { - JSON.Classify.classify("hello world") - // String("hello world") - - JSON.Classify.classify(42) - // Number(42) - } - () - }) -}) - -describe("JSON.Decode.array", () => { - test("JSON.Decode.array", () => { - module Test = { - JSON.parseExn(`["foo", "bar"]`)->JSON.Decode.array - // Some([ 'foo', 'bar' ]) - - JSON.parseExn(`"hello world"`)->JSON.Decode.array - // None - } - () - }) -}) - -describe("JSON.Decode.bool", () => { - test("JSON.Decode.bool", () => { - module Test = { - JSON.parseExn(`true`)->JSON.Decode.bool - // Some(true) - - JSON.parseExn(`"hello world"`)->JSON.Decode.bool - // None - } - () - }) -}) - -describe("JSON.Decode.float", () => { - test("JSON.Decode.float", () => { - module Test = { - JSON.parseExn(`42.0`)->JSON.Decode.float - // Some(42.0) - - JSON.parseExn(`"hello world"`)->JSON.Decode.float - // None - } - () - }) -}) - -describe("JSON.Decode.null", () => { - test("JSON.Decode.null", () => { - module Test = { - JSON.parseExn(`null`)->JSON.Decode.null - // Some(null) - - JSON.parseExn(`"hello world"`)->JSON.Decode.null - // None - } - () - }) -}) - -describe("JSON.Decode.object", () => { - test("JSON.Decode.object", () => { - module Test = { - JSON.parseExn(`{"foo":"bar"}`)->JSON.Decode.object - // Some({ foo: 'bar' }) - - JSON.parseExn(`"hello world"`)->JSON.Decode.object - // None - } - () - }) -}) - -describe("JSON.Decode.string", () => { - test("JSON.Decode.string", () => { - module Test = { - JSON.parseExn(`"hello world"`)->JSON.Decode.string - // Some("hello world") - - JSON.parseExn(`42`)->JSON.Decode.string - // None - } - () - }) -}) - -describe("JSON.Encode.array", () => { - test("JSON.Encode.array", () => { - module Test = { - let array = [JSON.Encode.string("hello world"), JSON.Encode.int(42)] - - JSON.Encode.array(array) - } - () - }) -}) - -describe("JSON.Encode.bool", () => { - test("JSON.Encode.bool", () => { - module Test = { - JSON.Encode.bool(true) - } - () - }) -}) - -describe("JSON.Encode.float", () => { - test("JSON.Encode.float", () => { - module Test = { - JSON.Encode.float(42.0) - } - () - }) -}) - -describe("JSON.Encode.int", () => { - test("JSON.Encode.int", () => { - module Test = { - JSON.Encode.int(42) - } - () - }) -}) - -describe("JSON.Encode.null", () => { - test("JSON.Encode.null", () => { - module Test = { - JSON.Encode.null - } - () - }) -}) - -describe("JSON.Encode.object", () => { - test("JSON.Encode.object", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ]) - - JSON.Encode.object(dict) - } - () - }) -}) - -describe("JSON.Encode.string", () => { - test("JSON.Encode.string", () => { - module Test = { - JSON.Encode.string("hello world") - } - () - }) -}) - -describe("JSON.parseExn", () => { - test("JSON.parseExn", () => { - module Test = { - try { - let _ = JSON.parseExn(`{"foo":"bar","hello":"world"}`) - // { foo: 'bar', hello: 'world' } - - let _ = JSON.parseExn("") - // error - } catch { - | Exn.Error(_) => Console.log("error") - } - - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` - - try { - JSON.parseExn(jsonString, ~reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } - - JSON.parseExn("", ~reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } - } - () - }) -}) - -describe("JSON.parseExnWithReviver", () => { - test("JSON.parseExnWithReviver", () => { - module Test = { - let reviver = (_, value: JSON.t) => - switch value { - | String(string) => string->String.toUpperCase->JSON.Encode.string - | Number(number) => (number *. 2.0)->JSON.Encode.float - | _ => value - } - - let jsonString = `{"hello":"world","someNumber":21}` - - try { - JSON.parseExnWithReviver(jsonString, reviver)->Console.log - // { hello: 'WORLD', someNumber: 42 } - - JSON.parseExnWithReviver("", reviver)->Console.log - // error - } catch { - | Exn.Error(_) => Console.log("error") - } - } - () - }) -}) - -describe("JSON.stringify", () => { - test("JSON.stringify", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringify(json) - // {"foo":"bar","hello":"world","someNumber":42} - - JSON.stringify(json, ~space=2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } - - JSON.stringify(json, ~replacer=Keys(["foo", "someNumber"])) - // {"foo":"bar","someNumber":42} - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) - - JSON.stringify(json, ~replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} - } - () - }) -}) - -describe("JSON.stringifyAny", () => { - test("JSON.stringifyAny", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - let replacer = JSON.Replacer( - (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - }, - ) - - dict - ->JSON.stringifyAny(~replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - // Raise a exception - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyAnyWithFilter", () => { - test("JSON.stringifyAnyWithFilter", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithFilter(["foo", "someNumber"]) - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyAnyWithFilterAndIndent", () => { - test("JSON.stringifyAnyWithFilterAndIndent", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAny - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","hello":"world","someNumber":42}`) - - dict - ->JSON.stringifyAny(~space=2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - dict - ->JSON.stringifyAny(~replacer=Keys(["foo", "someNumber"])) - ->Option.getUnsafe - ->assertEqual(`{"foo":"bar","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyAnyWithIndent", () => { - test("JSON.stringifyAnyWithIndent", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - dict - ->JSON.stringifyAnyWithIndent(2) - ->Option.getUnsafe - ->assertEqual(`{ - "foo": "bar", - "hello": "world", - "someNumber": 42 -}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyAnyWithReplacer", () => { - test("JSON.stringifyAnyWithReplacer", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - test("JSON.stringifyAnyWithReplacerAndIndent", () => { - module Test = { - let dict = Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ]) - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - dict - ->JSON.stringifyAnyWithReplacer(replacer) - ->Option.getUnsafe - ->assertEqual(`{"foo":"BAR","hello":"WORLD","someNumber":42}`) - - JSON.stringifyAny(() => "hello world")->assertEqual(None) - - switch BigInt.fromInt(0)->JSON.stringifyAny { - | exception _ => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("JSON.stringifyWithFilter", () => { - test("JSON.stringifyWithFilter", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringifyWithFilter(json, ["foo", "someNumber"]) - // {"foo":"bar","someNumber":42} - } - () - }) -}) - -describe("JSON.stringifyWithFilterAndIndent", () => { - test("JSON.stringifyWithFilterAndIndent", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringifyWithFilterAndIndent(json, ["foo", "someNumber"], 2) - // { - // "foo": "bar", - // "someNumber": 42 - // } - } - () - }) -}) - -describe("JSON.stringifyWithIndent", () => { - test("JSON.stringifyWithIndent", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - JSON.stringifyWithIndent(json, 2) - // { - // "foo": "bar", - // "hello": "world", - // "someNumber": 42 - // } - } - () - }) -}) - -describe("JSON.stringifyWithReplacer", () => { - test("JSON.stringifyWithReplacer", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - JSON.stringifyWithReplacer(json, replacer) - // {"foo":"BAR","hello":"WORLD","someNumber":42} - } - () - }) -}) - -describe("JSON.stringifyWithReplacerAndIndent", () => { - test("JSON.stringifyWithReplacerAndIndent", () => { - module Test = { - let json = - Dict.fromArray([ - ("foo", JSON.Encode.string("bar")), - ("hello", JSON.Encode.string("world")), - ("someNumber", JSON.Encode.int(42)), - ])->JSON.Encode.object - - let replacer = (_, value) => { - let decodedValue = value->JSON.Decode.string - - switch decodedValue { - | Some(string) => string->String.toUpperCase->JSON.Encode.string - | None => value - } - } - - JSON.stringifyWithReplacerAndIndent(json, replacer, 2) - // { - // "foo": "BAR", - // "hello": "WORLD", - // "someNumber": 42 - // } - } - () - }) -}) - -describe("List.add", () => { - test("List.add", () => { - module Test = { - List.add(list{2, 3}, 1) // list{1, 2, 3} - - List.add(list{"World", "!"}, "Hello") // list{"Hello", "World", "!"} - } - () - }) -}) - -describe("List.compare", () => { - test("List.compare", () => { - module Test = { - List.compare(list{3}, list{3, 7}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{5, 3}, list{5}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 4, 2}, (a, b) => Int.compare(a, b)) // -1. - List.compare(list{1, 3, 5}, list{1, 2, 3}, (a, b) => Int.compare(a, b)) // 1. - List.compare(list{1, 3, 5}, list{1, 3, 5}, (a, b) => Int.compare(a, b)) // 0. - } - () - }) -}) - -describe("List.compareLength", () => { - test("List.compareLength", () => { - module Test = { - List.compareLength(list{1, 2}, list{3, 4, 5, 6}) // -1. - - List.compareLength(list{1, 2, 3}, list{4, 5, 6}) // 0. - - List.compareLength(list{1, 2, 3, 4}, list{5, 6}) // 1. - } - () - }) -}) - -describe("List.concat", () => { - test("List.concat", () => { - module Test = { - List.concat(list{1, 2, 3}, list{4, 5}) // list{1, 2, 3, 4, 5} - } - () - }) -}) - -describe("List.concatMany", () => { - test("List.concatMany", () => { - module Test = { - List.concatMany([list{1, 2, 3}, list{}, list{3}]) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("List.drop", () => { - test("List.drop", () => { - module Test = { - list{1, 2, 3}->List.drop(2) // Some(list{3}) - - list{1, 2, 3}->List.drop(3) // Some(list{}) - - list{1, 2, 3}->List.drop(4) // None - } - () - }) -}) - -describe("List.equal", () => { - test("List.equal", () => { - module Test = { - List.equal(list{1, 2, 3}, list{1, 2}, (a, b) => a == b) // false - - List.equal(list{1, 2}, list{1, 2}, (a, b) => a == b) // true - - List.equal(list{1, 2, 3}, list{-1, -2, -3}, (a, b) => abs(a) == abs(b)) // true - } - () - }) -}) - -describe("List.every", () => { - test("List.every", () => { - module Test = { - let isBelow10 = value => value < 10 - - list{1, 9, 8, 2}->List.every(isBelow10) // true - - list{1, 99, 8, 2}->List.every(isBelow10) // false - } - () - }) -}) - -describe("List.every2", () => { - test("List.every2", () => { - module Test = { - List.every2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - - List.every2(list{}, list{1}, (a, b) => a > b) // true - - List.every2(list{2, 3}, list{1}, (a, b) => a > b) // true - - List.every2(list{0, 1}, list{5, 0}, (a, b) => a > b) // false - } - () - }) -}) - -describe("List.filter", () => { - test("List.filter", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filter(list{1, 2, 3, 4}, isEven) // list{2, 4} - - List.filter(list{None, Some(2), Some(3), None}, Option.isSome) // list{Some(2), Some(3)} - } - () - }) -}) - -describe("List.filterMap", () => { - test("List.filterMap", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - list{1, 2, 3, 4}->List.filterMap( - x => - if isEven(x) { - Some(x) - } else { - None - }, - ) // list{2, 4} - - list{Some(1), Some(2), None}->List.filterMap(x => x) // list{1, 2} - } - () - }) -}) - -describe("List.filterWithIndex", () => { - test("List.filterWithIndex", () => { - module Test = { - let isEven = x => mod(x, 2) == 0 - - List.filterWithIndex(list{1, 2, 3, 4}, (_x, index) => isEven(index)) // list{1, 3} - } - () - }) -}) - -describe("List.find", () => { - test("List.find", () => { - module Test = { - List.find(list{1, 4, 3, 2}, x => x > 3) // Some(4) - - List.find(list{1, 4, 3, 2}, x => x > 4) // None - } - () - }) -}) - -describe("List.flat", () => { - test("List.flat", () => { - module Test = { - List.flat(list{list{1, 2, 3}, list{}, list{3}}) // list{1, 2, 3, 3} - } - () - }) -}) - -describe("List.forEach", () => { - test("List.forEach", () => { - module Test = { - List.forEach(list{"a", "b", "c"}, x => Console.log("Item: " ++ x)) - /* - prints: - Item: a - Item: b - Item: c -*/ - } - () - }) -}) - -describe("List.forEach2", () => { - test("List.forEach2", () => { - module Test = { - List.forEach2(list{"Z", "Y"}, list{"A", "B", "C"}, (x, y) => Console.log2(x, y)) - - /* - prints: - "Z" "A" - "Y" "B" -*/ - } - () - }) -}) - -describe("List.forEachWithIndex", () => { - test("List.forEachWithIndex", () => { - module Test = { - List.forEachWithIndex( - list{"a", "b", "c"}, - (x, index) => { - Console.log("Item " ++ Int.toString(index) ++ " is " ++ x) - }, - ) - /* - prints: - Item 0 is a - Item 1 is b - Item 2 is cc -*/ - } - () - }) -}) - -describe("List.fromArray", () => { - test("List.fromArray", () => { - module Test = { - List.fromArray([1, 2, 3]) // list{1, 2, 3} - } - () - }) -}) - -describe("List.fromInitializer", () => { - test("List.fromInitializer", () => { - module Test = { - List.fromInitializer(~length=5, i => i) // list{0, 1, 2, 3, 4} - - List.fromInitializer(~length=5, i => i * i) // list{0, 1, 4, 9, 16} - } - () - }) -}) - -describe("List.get", () => { - test("List.get", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc->List.get(1) // Some("B") - - abc->List.get(4) // None - } - () - }) -}) - -describe("List.getAssoc", () => { - test("List.getAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.getAssoc(3, (a, b) => a == b) // Some("c") - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.getAssoc( - 15, - (k, item) => k /* 15 */ == item /* 9, 5, 22 */, - ) - // Some("afternoon") - } - () - }) -}) - -describe("List.getExn", () => { - test("List.getExn", () => { - module Test = { - let abc = list{"A", "B", "C"} - - abc - ->List.getExn(1) - ->assertEqual("B") - - switch abc->List.getExn(4) { - | exception Not_found => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("List.has", () => { - test("List.has", () => { - module Test = { - list{1, 2, 3}->List.has(2, (a, b) => a == b) // true - - list{1, 2, 3}->List.has(4, (a, b) => a == b) // false - - list{-1, -2, -3}->List.has(2, (a, b) => abs(a) == abs(b)) // true - } - () - }) -}) - -describe("List.hasAssoc", () => { - test("List.hasAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.hasAssoc(1, (a, b) => a == b) // true - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.hasAssoc( - 25, - (k, item) => k /* 25 */ == item /* 9, 5, 22 */, - ) // false - } - () - }) -}) - -describe("List.head", () => { - test("List.head", () => { - module Test = { - List.head(list{}) // None - List.head(list{1, 2, 3}) // Some(1) - } - () - }) -}) - -describe("List.headExn", () => { - test("List.headExn", () => { - module Test = { - List.headExn(list{1, 2, 3})->assertEqual(1) - - switch List.headExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("List.length", () => { - test("List.length", () => { - module Test = { - List.length(list{1, 2, 3}) // 3 - } - () - }) -}) - -describe("List.make", () => { - test("List.make", () => { - module Test = { - List.make(~length=3, 1) // list{1, 1, 1} - } - () - }) -}) - -describe("List.map", () => { - test("List.map", () => { - module Test = { - list{1, 2}->List.map(x => x + 1) // list{3, 4} - } - () - }) -}) - -describe("List.mapReverse", () => { - test("List.mapReverse", () => { - module Test = { - let f = x => x * x - let l = list{3, 4, 5} - - let withMap = List.map(l, f)->List.reverse - let withMapReverse = l->List.mapReverse(f) - - Console.log(withMap == withMapReverse) // true - } - () - }) -}) - -describe("List.mapReverse2", () => { - test("List.mapReverse2", () => { - module Test = { - List.mapReverse2(list{1, 2, 3}, list{1, 2}, (a, b) => a + b) // list{4, 2} - } - () - }) -}) - -describe("List.mapWithIndex", () => { - test("List.mapWithIndex", () => { - module Test = { - list{1, 2, 3}->List.mapWithIndex((x, index) => index + x) // list{1, 3, 5} - } - () - }) -}) - -describe("List.partition", () => { - test("List.partition", () => { - module Test = { - // (elementsThatSatisfies, elementsThatDoesNotSatisfy) - - List.partition(list{1, 2, 3, 4}, x => x > 2) // (list{3, 4}, list{1, 2}) - } - () - }) -}) - -describe("List.reduce", () => { - test("List.reduce", () => { - module Test = { - list{1, 2, 3, 4}->List.reduce(0, (a, b) => a + b) // 10 - - // same as - - list{1, 2, 3, 4}->List.reduce(0, (acc, item) => acc + item) // 10 - } - () - }) -}) - -describe("List.reduce2", () => { - test("List.reduce2", () => { - module Test = { - List.reduce2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // 0 + (1 * 1 + 4) + (2 * 2 + 5) - } - () - }) -}) - -describe("List.reduceReverse", () => { - test("List.reduceReverse", () => { - module Test = { - list{1, 2, 3, 4}->List.reduceReverse(0, (a, b) => a + b) // 10 - - list{1, 2, 3, 4}->List.reduceReverse(10, (a, b) => a - b) // 0 - - list{1, 2, 3, 4}->List.reduceReverse(list{}, List.add) // list{1, 2, 3, 4} - } - () - }) -}) - -describe("List.reduceReverse2", () => { - test("List.reduceReverse2", () => { - module Test = { - List.reduceReverse2(list{1, 2, 3}, list{4, 5}, 0, (acc, x, y) => acc + x * x + y) // + (1 * 1 + 4) + (2 * 2 + 5) - } - () - }) -}) - -describe("List.reduceWithIndex", () => { - test("List.reduceWithIndex", () => { - module Test = { - list{1, 2, 3, 4}->List.reduceWithIndex(0, (acc, item, index) => acc + item + index) // 16 - } - () - }) -}) - -describe("List.removeAssoc", () => { - test("List.removeAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.removeAssoc(1, (a, b) => a == b) // list{(2, "b"), (3, "c")} - - list{(9, "morning"), (15, "afternoon"), (22, "night")}->List.removeAssoc( - 9, - (k, item) => k /* 9 */ == item /* 9, 5, 22 */, - ) - // list{(15, "afternoon"), (22, "night")} - } - () - }) -}) - -describe("List.reverse", () => { - test("List.reverse", () => { - module Test = { - List.reverse(list{1, 2, 3}) // list{3, 2, 1} - } - () - }) -}) - -describe("List.reverseConcat", () => { - test("List.reverseConcat", () => { - module Test = { - List.reverseConcat(list{1, 2}, list{3, 4}) // list{2, 1, 3, 4} - } - () - }) -}) - -describe("List.setAssoc", () => { - test("List.setAssoc", () => { - module Test = { - list{(1, "a"), (2, "b"), (3, "c")}->List.setAssoc(2, "x", (a, b) => a == b) // list{(1, "a"), (2, "x"), (3, "c")} - - list{(1, "a"), (3, "c")}->List.setAssoc(2, "b", (a, b) => a == b) // list{(2, "b"), (1, "a"), (3, "c")} - - list{(9, "morning"), (3, "morning?!"), (22, "night")}->List.setAssoc( - 15, - "afternoon", - (a, b) => mod(a, 12) == mod(b, 12), - ) - // list{(9, "morning"), (15, "afternoon"), (22, "night")} - } - () - }) -}) - -describe("List.size", () => { - test("List.size", () => { - module Test = { - List.size(list{1, 2, 3}) // 3 - } - () - }) -}) - -describe("List.some", () => { - test("List.some", () => { - module Test = { - let isAbove100 = value => value > 100 - - list{101, 1, 2, 3}->List.some(isAbove100) // true - - list{1, 2, 3, 4}->List.some(isAbove100) // false - } - () - }) -}) - -describe("List.some2", () => { - test("List.some2", () => { - module Test = { - List.some2(list{1, 2, 3}, list{0, 1}, (a, b) => a > b) // true - - List.some2(list{}, list{1}, (a, b) => a > b) // false - - List.some2(list{2, 3}, list{1}, (a, b) => a > b) // true - - List.some2(list{0, 1}, list{5, 0}, (a, b) => a > b) // true - } - () - }) -}) - -describe("List.sort", () => { - test("List.sort", () => { - module Test = { - List.sort(list{5, 4, 9, 3, 7}, Int.compare) // list{3, 4, 5, 7, 9} - } - () - }) -}) - -describe("List.splitAt", () => { - test("List.splitAt", () => { - module Test = { - list{"Hello", "World"}->List.splitAt(1) // Some((list{"Hello"}, list{"World"})) - - list{0, 1, 2, 3, 4}->List.splitAt(2) // Some((list{0, 1}, list{2, 3, 4})) - } - () - }) -}) - -describe("List.tail", () => { - test("List.tail", () => { - module Test = { - List.tail(list{1, 2, 3}) // Some(list{2, 3}) - - List.tail(list{}) // None - } - () - }) -}) - -describe("List.tailExn", () => { - test("List.tailExn", () => { - module Test = { - List.tailExn(list{1, 2, 3})->assertEqual(list{2, 3}) - - switch List.tailExn(list{}) { - | exception Not_found => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("List.take", () => { - test("List.take", () => { - module Test = { - list{1, 2, 3}->List.take(1) // Some(list{1}) - - list{1, 2, 3}->List.take(2) // Some(list{1, 2}) - - list{1, 2, 3}->List.take(4) // None - } - () - }) -}) - -describe("List.toArray", () => { - test("List.toArray", () => { - module Test = { - List.toArray(list{1, 2, 3}) // [1, 2, 3] - } - () - }) -}) - -describe("List.toShuffled", () => { - test("List.toShuffled", () => { - module Test = { - List.toShuffled(list{1, 2, 3}) // list{2, 1, 3} - } - () - }) -}) - -describe("List.unzip", () => { - test("List.unzip", () => { - module Test = { - List.unzip(list{(1, 2), (3, 4)}) // (list{1, 3}, list{2, 4}) - - List.unzip(list{("H", "W"), ("e", "o"), ("l", "r"), ("l", "l"), ("o", "d"), (" ", "!")}) - // (list{"H", "e", "l", "l", "o", " "}, list{"W", "o", "r", "l", "d", "!"}) - } - () - }) -}) - -describe("List.zip", () => { - test("List.zip", () => { - module Test = { - List.zip(list{1, 2}, list{3, 4, 5}) // list{(1, 3), (2, 4)} - } - () - }) -}) - -describe("List.zipBy", () => { - test("List.zipBy", () => { - module Test = { - List.zipBy(list{1, 2, 3}, list{4, 5}, (a, b) => 2 * a + b) // list{6, 9} - } - () - }) -}) - -describe("Map.clear", () => { - test("Map.clear", () => { - module Test = { - let map = Map.make() - - map->Map.set("someKey", "someValue") - map->Map.size // 1 - - map->Map.clear - map->Map.size // 0 - } - () - }) -}) - -describe("Map.delete", () => { - test("Map.delete", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - let didDeleteKey = map->Map.delete("someKey") - Console.log(didDeleteKey) // Logs `true` to the console, becuase the map had the key, so it was successfully deleted - - let didDeleteKey = map->Map.delete("someNonExistantKey") - Console.log(didDeleteKey) // Logs `false` to the console, becuase the key did not exist - } - () - }) -}) - -describe("Map.entries", () => { - test("Map.entries", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let entries = map->Map.entries - - // Logs the first value - Console.log(Iterator.next(entries).value) - - // You can also turn the iterator into an array. - // Remember that an iterator consumes entries. We'll need a fresh entries iterator to get an array of all entries, since we consumed a value via `next` above already. - Console.log(map->Map.entries->Iterator.toArray) - } - () - }) -}) - -describe("Map.forEach", () => { - test("Map.forEach", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - map->Map.forEach( - value => { - Console.log(value) - }, - ) - } - () - }) -}) - -describe("Map.forEachWithKey", () => { - test("Map.forEachWithKey", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("someKey2", "someValue2") - - map->Map.forEachWithKey( - (value, key) => { - Console.log2(value, key) - }, - ) - } - () - }) -}) - -describe("Map.fromArray", () => { - test("Map.fromArray", () => { - module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [(ReScript, 1), (JavaScript, 2), (TypeScript, 3)] - - let map = Map.fromArray(languageRank) // Map.t - - switch map->Map.get(ReScript) { - | Some(1) => Console.log("Yay, ReScript is #1!") - | _ => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } - } - () - }) -}) - -describe("Map.fromIterator", () => { - test("Map.fromIterator", () => { - module Test = { - // Let's pretend we have an interator in the correct shape - let iterator: Iterator.t<(string, string)> = %raw(` - (() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })() -`) - - iterator - ->Map.fromIterator - ->Map.size - ->assertEqual(2) - } - () - }) -}) - -describe("Map.get", () => { - test("Map.get", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - - switch map->Map.get("someKey") { - | None => Console.log("Nope, didn't have it.") - | Some(value) => Console.log2("Yay, had the value, and it's:", value) - } - } - () - }) -}) - -describe("Map.has", () => { - test("Map.has", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - - switch map->Map.has("someKey") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } - } - () - }) -}) - -describe("Map.keys", () => { - test("Map.keys", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let keys = map->Map.keys - - // Logs the first key - Console.log(Iterator.next(keys).value) - - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh keys iterator to get an array of all keys, since we consumed a value via `next` above already. - Console.log(map->Map.keys->Iterator.toArray) - } - () - }) -}) - -describe("Map.make", () => { - test("Map.make", () => { - module Test = { - `make()` - // You can annotate the type of your map if you want to - let myMap: Map.t = Map.make() - - // Or you can let ReScript infer what's in your map - let map = Map.make() - map->Map.set("lang", "ReScript") // Inferred as Map.t - } - () - }) -}) - -describe("Map.set", () => { - test("Map.set", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - } - () - }) -}) - -describe("Map.size", () => { - test("Map.size", () => { - module Test = { - let map = Map.make() - - map->Map.set("someKey", "someValue") - - let size = map->Map.size // 1 - } - () - }) -}) - -describe("Map.values", () => { - test("Map.values", () => { - module Test = { - let map = Map.make() - map->Map.set("someKey", "someValue") - map->Map.set("anotherKey", "anotherValue") - - let values = map->Map.values - - // Logs the first value - Console.log(Iterator.next(values).value) - - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(map->Map.values->Iterator.toArray) - } - () - }) -}) - -describe("Math.Constants.e", () => { - test("Math.Constants.e", () => { - module Test = { - Math.Constants.e - } - () - }) -}) - -describe("Math.Constants.ln10", () => { - test("Math.Constants.ln10", () => { - module Test = { - Math.Constants.ln10 - } - () - }) -}) - -describe("Math.Constants.ln2", () => { - test("Math.Constants.ln2", () => { - module Test = { - Math.Constants.ln2 - } - () - }) -}) - -describe("Math.Constants.log10e", () => { - test("Math.Constants.log10e", () => { - module Test = { - Math.Constants.log10e - } - () - }) -}) - -describe("Math.Constants.log2e", () => { - test("Math.Constants.log2e", () => { - module Test = { - Math.Constants.log2e - } - () - }) -}) - -describe("Math.Constants.pi", () => { - test("Math.Constants.pi", () => { - module Test = { - Math.Constants.pi - } - () - }) -}) - -describe("Math.Constants.sqrt1_2", () => { - test("Math.Constants.sqrt1_2", () => { - module Test = { - Math.Constants.sqrt1_2 - } - () - }) -}) - -describe("Math.Constants.sqrt2", () => { - test("Math.Constants.sqrt2", () => { - module Test = { - Math.Constants.sqrt2 - } - () - }) -}) - -describe("Math.Int.abs", () => { - test("Math.Int.abs", () => { - module Test = { - Math.Int.abs(-2) // 2 - Math.Int.abs(3) // 3 - } - () - }) -}) - -describe("Math.Int.ceil", () => { - test("Math.Int.ceil", () => { - module Test = { - Math.Int.ceil(3.7) == 4 - Math.Int.ceil(3.0) == 3 - Math.Int.ceil(-3.1) == -3 - } - () - }) -}) - -describe("Math.Int.clz32", () => { - test("Math.Int.clz32", () => { - module Test = { - // 00000000000000000000000000000001 - Math.Int.clz32(1) // 31 - // 00000000000000000000000000000100 - Math.Int.clz32(4) // 29 - } - () - }) -}) - -describe("Math.Int.floor", () => { - test("Math.Int.floor", () => { - module Test = { - Math.Int.floor(3.7) == 3 - Math.Int.floor(3.0) == 3 - Math.Int.floor(-3.1) == -4 - } - () - }) -}) - -describe("Math.Int.imul", () => { - test("Math.Int.imul", () => { - module Test = { - Math.Int.imul(3, 4) // 12 - Math.Int.imul(-5, 12) // 60 - } - () - }) -}) - -describe("Math.Int.max", () => { - test("Math.Int.max", () => { - module Test = { - Math.Int.max(1, 2) // 2 - Math.Int.max(-1, -2) // -1 - } - () - }) -}) - -describe("Math.Int.maxMany", () => { - test("Math.Int.maxMany", () => { - module Test = { - Math.Int.maxMany([1, 2]) // 2 - Math.Int.maxMany([-1, -2]) // -1 - Math.Int.maxMany([])->Int.toFloat->Float.isFinite // false - } - () - }) -}) - -describe("Math.Int.min", () => { - test("Math.Int.min", () => { - module Test = { - Math.Int.min(1, 2) // 1 - Math.Int.min(-1, -2) // -2 - } - () - }) -}) - -describe("Math.Int.minMany", () => { - test("Math.Int.minMany", () => { - module Test = { - Math.Int.minMany([1, 2]) // 1 - Math.Int.minMany([-1, -2]) // -2 - Math.Int.minMany([])->Int.toFloat->Float.isFinite // false - } - () - }) -}) - -describe("Math.Int.pow", () => { - test("Math.Int.pow", () => { - module Test = { - Math.Int.pow(2, ~exp=4) // 16 - Math.Int.pow(3, ~exp=4) // 81 - } - () - }) -}) - -describe("Math.Int.random", () => { - test("Math.Int.random", () => { - module Test = { - Math.Int.random(2, 5) == 4 - Math.Int.random(505, 2000) == 1276 - Math.Int.random(-7, -2) == -4 - } - () - }) -}) - -describe("Math.Int.sign", () => { - test("Math.Int.sign", () => { - module Test = { - Math.Int.sign(3) // 1 - Math.Int.sign(-3) // -1 - Math.Int.sign(0) // 0 - } - () - }) -}) - -describe("Math.abs", () => { - test("Math.abs", () => { - module Test = { - Math.abs(-2.0) // 2.0 - Math.abs(3.0) // 3.0 - } - () - }) -}) - -describe("Math.acos", () => { - test("Math.acos", () => { - module Test = { - Math.acos(-1.0) // 3.141592653589793 - Math.acos(-3.0)->Float.isNaN // true - } - () - }) -}) - -describe("Math.acosh", () => { - test("Math.acosh", () => { - module Test = { - Math.acosh(1.0) // 0.0 - Math.acosh(0.5)->Float.isNaN // true - } - () - }) -}) - -describe("Math.asin", () => { - test("Math.asin", () => { - module Test = { - Math.asin(-1.0) // -1.5707963267948966 - Math.asin(-2.0)->Float.isNaN // true - } - () - }) -}) - -describe("Math.asinh", () => { - test("Math.asinh", () => { - module Test = { - Math.asinh(-1.0) // -0.881373587019543 - Math.asinh(-0.0) // -0.0 - } - () - }) -}) - -describe("Math.atan", () => { - test("Math.atan", () => { - module Test = { - Math.atan(-0.0) // -0.0 - Math.atan(0.0) // 0.0 - Math.atan(1.0) // 0.7853981633974483 - } - () - }) -}) - -describe("Math.atan2", () => { - test("Math.atan2", () => { - module Test = { - Math.atan2(~y=0.0, ~x=10.0) == 0.0 - Math.atan2(~x=5.0, ~y=5.0) == Math.Constants.pi /. 4.0 - Math.atan2(~x=90.0, ~y=15.0) // 1.4056476493802699 - Math.atan2(~x=15.0, ~y=90.0) // 0.16514867741462683 - } - () - }) -}) - -describe("Math.atanh", () => { - test("Math.atanh", () => { - module Test = { - Math.atanh(-2.0)->Float.isNaN // true - Math.atanh(-1.0)->Float.isFinite // false - Math.atanh(-0.0) // -0.0 - Math.atanh(0.0) // 0.0 - Math.atanh(0.5) // 0.5493061443340548 - } - () - }) -}) - -describe("Math.cbrt", () => { - test("Math.cbrt", () => { - module Test = { - Math.cbrt(-1.0) // -1.0 - Math.cbrt(-0.0) // -0.0 - Math.cbrt(0.0) // 0.0 - } - () - }) -}) - -describe("Math.ceil", () => { - test("Math.ceil", () => { - module Test = { - Math.ceil(3.1) == 4.0 - Math.ceil(3.0) == 3.0 - Math.ceil(-3.1) == -3.0 - Math.ceil(2_150_000_000.3) == 2_150_000_001.0 - } - () - }) -}) - -describe("Math.cos", () => { - test("Math.cos", () => { - module Test = { - Math.cos(-0.0) // 1.0 - Math.cos(0.0) // 1.0 - Math.cos(1.0) // 0.5403023058681398 - } - () - }) -}) - -describe("Math.cosh", () => { - test("Math.cosh", () => { - module Test = { - Math.cosh(-1.0) // 1.5430806348152437 - Math.cosh(-0.0) // 1.0 - Math.cosh(0.0) // 1.0 - } - () - }) -}) - -describe("Math.exp", () => { - test("Math.exp", () => { - module Test = { - Math.exp(-1.0) // 0.36787944117144233 - Math.exp(0.0) // 1.0 - } - () - }) -}) - -describe("Math.expm1", () => { - test("Math.expm1", () => { - module Test = { - Math.expm1(-1.0) // -0.6321205588285577 - Math.expm1(-0.0) // -0 - } - () - }) -}) - -describe("Math.floor", () => { - test("Math.floor", () => { - module Test = { - Math.floor(-45.95) // -46.0 - Math.floor(-45.05) // -46.0 - Math.floor(-0.0) // -0.0 - } - () - }) -}) - -describe("Math.fround", () => { - test("Math.fround", () => { - module Test = { - Math.fround(5.5) == 5.5 - Math.fround(5.05) == 5.050000190734863 - } - () - }) -}) - -describe("Math.hypot", () => { - test("Math.hypot", () => { - module Test = { - Math.hypot(3.0, 4.0) // 5.0 - Math.hypot(3.0, 5.0) // 5.8309518948453 - } - () - }) -}) - -describe("Math.hypotMany", () => { - test("Math.hypotMany", () => { - module Test = { - Math.hypotMany([3.0, 4.0, 5.0]) // 7.0710678118654755 - Math.hypotMany([]) // 0.0 - } - () - }) -}) - -describe("Math.log", () => { - test("Math.log", () => { - module Test = { - Math.log(-1.0)->Float.isNaN // true - Math.log(-0.0)->Float.isFinite // false - Math.log(0.0)->Float.isFinite // false - Math.log(1.0) // 0 - } - () - }) -}) - -describe("Math.log10", () => { - test("Math.log10", () => { - module Test = { - Math.log10(-2.0)->Float.isNaN // true - Math.log10(-0.0)->Float.isFinite // false - Math.log10(0.0)->Float.isFinite // false - Math.log10(1.0) // 0 - } - () - }) -}) - -describe("Math.log1p", () => { - test("Math.log1p", () => { - module Test = { - Math.log1p(-2.0)->Float.isNaN // true - Math.log1p(-1.0)->Float.isFinite // false - Math.log1p(-0.0) // -0 - } - () - }) -}) - -describe("Math.log2", () => { - test("Math.log2", () => { - module Test = { - Math.log2(-2.0)->Float.isNaN // true - Math.log2(-0.0)->Float.isFinite // false - Math.log2(0.0)->Float.isFinite // false - Math.log2(1.0) // 0.0 - } - () - }) -}) - -describe("Math.max", () => { - test("Math.max", () => { - module Test = { - Math.max(1.0, 2.0) // 2.0 - Math.max(-1.0, -2.0) // -1.0 - } - () - }) -}) - -describe("Math.maxMany", () => { - test("Math.maxMany", () => { - module Test = { - Math.maxMany([1.0, 2.0]) // 2.0 - Math.maxMany([-1.0, -2.0]) // -1.0 - Math.maxMany([])->Float.isFinite // false - } - () - }) -}) - -describe("Math.min", () => { - test("Math.min", () => { - module Test = { - Math.min(1.0, 2.0) // 1.0 - Math.min(-1.0, -2.0) // -2.0 - } - () - }) -}) - -describe("Math.minMany", () => { - test("Math.minMany", () => { - module Test = { - Math.minMany([1.0, 2.0]) // 1.0 - Math.minMany([-1.0, -2.0]) // -2.0 - Math.minMany([])->Float.isFinite // false - } - () - }) -}) - -describe("Math.pow", () => { - test("Math.pow", () => { - module Test = { - Math.pow(2.0, ~exp=4.0) // 16.0 - Math.pow(3.0, ~exp=4.0) // 81.0 - } - () - }) -}) - -describe("Math.random", () => { - test("Math.random", () => { - module Test = { - Math.random() - } - () - }) -}) - -describe("Math.round", () => { - test("Math.round", () => { - module Test = { - Math.round(-20.5) // -20.0 - Math.round(-0.1) // -0.0 - Math.round(0.0) // 0.0 - Math.round(-0.0) // -0.0 - } - () - }) -}) - -describe("Math.sign", () => { - test("Math.sign", () => { - module Test = { - Math.sign(3.0) // 1.0 - Math.sign(-3.0) // 1.0 - Math.sign(0.0) // 0.0 - } - () - }) -}) - -describe("Math.sin", () => { - test("Math.sin", () => { - module Test = { - Math.sin(-0.0) // -0.0 - Math.sin(0.0) // 0.0 - Math.sin(1.0) // 0.8414709848078965 - } - () - }) -}) - -describe("Math.sinh", () => { - test("Math.sinh", () => { - module Test = { - Math.sinh(-0.0) // -0.0 - Math.sinh(0.0) // 0.0 - Math.sinh(1.0) // 1.1752011936438014 - } - () - }) -}) - -describe("Math.sqrt", () => { - test("Math.sqrt", () => { - module Test = { - Math.sqrt(-1.0)->Float.isNaN // true - Math.sqrt(-0.0) // -0.0 - Math.sqrt(0.0) // 0.0 - Math.sqrt(1.0) // 1.0 - Math.sqrt(9.0) // 3.0 - } - () - }) -}) - -describe("Math.tan", () => { - test("Math.tan", () => { - module Test = { - Math.tan(-0.0) // -0.0 - Math.tan(0.0) // 0.0 - Math.tan(1.0) // 1.5574077246549023 - } - () - }) -}) - -describe("Math.tanh", () => { - test("Math.tanh", () => { - module Test = { - Math.tanh(-0.0) // -0.0 - Math.tanh(0.0) // 0.0 - Math.tanh(1.0) // 0.7615941559557649 - } - () - }) -}) - -describe("Math.trunc", () => { - test("Math.trunc", () => { - module Test = { - Math.trunc(0.123) // 0.0 - Math.trunc(1.999) // 1.0 - Math.trunc(13.37) // 13.0 - Math.trunc(42.84) // 42.0 - } - () - }) -}) - -describe("Null.asNullable", () => { - test("Null.asNullable", () => { - module Test = { - let nullValue = Null.make("Hello") - let asNullable = nullValue->Null.asNullable // Nullable.t - } - () - }) -}) - -describe("Null.flatMap", () => { - test("Null.flatMap", () => { - module Test = { - let addIfAboveOne = value => - if value > 1 { - Null.make(value + 1) - } else { - Null.null - } - - Null.flatMap(Null.make(2), addIfAboveOne) // Null.make(3) - Null.flatMap(Null.make(-4), addIfAboveOne) // null - Null.flatMap(Null.null, addIfAboveOne) // null - } - () - }) -}) - -describe("Null.forEach", () => { - test("Null.forEach", () => { - module Test = { - Null.forEach(Null.make("thing"), x => Console.log(x)) // logs "thing" - Null.forEach(Null.null, x => Console.log(x)) // logs nothing - } - () - }) -}) - -describe("Null.fromOption", () => { - test("Null.fromOption", () => { - module Test = { - let optString: option = None - let asNull = optString->Null.fromOption // Null.t - Console.log(asNull == Null.null) // Logs `true` to the console. - } - () - }) -}) - -describe("Null.getExn", () => { - test("Null.getExn", () => { - module Test = { - Null.getExn(Null.make(3))->assertEqual(3) - - switch Null.getExn(%raw("'ReScript'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "ReScript") - } - - switch Null.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Null.getOr", () => { - test("Null.getOr", () => { - module Test = { - Null.getOr(Null.null, "Banana") // Banana - Null.getOr(Null.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Null.make("Jane")->Null.toOption->greet // "Greetings Jane" - Null.null->Null.toOption->greet // "Greetings Anonymous" - } - () - }) -}) - -describe("Null.getUnsafe", () => { - test("Null.getUnsafe", () => { - module Test = { - Null.getUnsafe(Null.make(3)) == 3 - Null.getUnsafe(Null.null) // Raises an error - } - () - }) -}) - -describe("Null.make", () => { - test("Null.make", () => { - module Test = { - let myStr = "Hello" - let asNullValue = myStr->Null.make // The compiler now thinks this can be `string` or `null`. - } - () - }) -}) - -describe("Null.map", () => { - test("Null.map", () => { - module Test = { - Null.map(Null.make(3), x => x * x) // Null.make(9) - Null.map(Null.null, x => x * x) // null - } - () - }) -}) - -describe("Null.mapOr", () => { - test("Null.mapOr", () => { - module Test = { - let someValue = Null.make(3) - someValue->Null.mapOr(0, x => x + 5) // 8 - - let noneValue = Null.null - noneValue->Null.mapOr(0, x => x + 5) // 0 - } - () - }) -}) - -describe("Null.null", () => { - test("Null.null", () => { - module Test = { - Console.log(null) // Logs `null` to the console. - } - () - }) -}) - -describe("Null.toOption", () => { - test("Null.toOption", () => { - module Test = { - let nullStr = Null.make("Hello") - - switch nullStr->Null.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } - } - () - }) -}) - -describe("Nullable.flatMap", () => { - test("Nullable.flatMap", () => { - module Test = { - let addIfAboveOne = value => - if value > 1 { - Nullable.make(value + 1) - } else { - Nullable.null - } - - Nullable.flatMap(Nullable.make(2), addIfAboveOne) // Nullable.make(3) - Nullable.flatMap(Nullable.make(-4), addIfAboveOne) // undefined - Nullable.flatMap(Nullable.null, addIfAboveOne) // undefined - } - () - }) -}) - -describe("Nullable.forEach", () => { - test("Nullable.forEach", () => { - module Test = { - Nullable.forEach(Nullable.make("thing"), x => Console.log(x)) // logs "thing" - Nullable.forEach(Nullable.null, x => Console.log(x)) // returns () - Nullable.forEach(undefined, x => Console.log(x)) // returns () - } - () - }) -}) - -describe("Nullable.fromOption", () => { - test("Nullable.fromOption", () => { - module Test = { - let optString = Some("Hello") - let asNullable = optString->Nullable.fromOption // Nullable.t - } - () - }) -}) - -describe("Nullable.getExn", () => { - test("Nullable.getExn", () => { - module Test = { - switch Nullable.getExn(%raw("'Hello'")) { - | exception Invalid_argument(_) => assert(false) - | value => assertEqual(value, "Hello") - } - - switch Nullable.getExn(%raw("null")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } - - switch Nullable.getExn(%raw("undefined")) { - | exception Invalid_argument(_) => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Nullable.getOr", () => { - test("Nullable.getOr", () => { - module Test = { - Nullable.getOr(Nullable.null, "Banana") // Banana - Nullable.getOr(Nullable.make("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Nullable.make("Jane")->Nullable.toOption->greet // "Greetings Jane" - Nullable.null->Nullable.toOption->greet // "Greetings Anonymous" - } - () - }) -}) - -describe("Nullable.getUnsafe", () => { - test("Nullable.getUnsafe", () => { - module Test = { - Nullable.getUnsafe(Nullable.make(3)) == 3 - Nullable.getUnsafe(Nullable.null) // Raises an error - } - () - }) -}) - -describe("Nullable.isNullable", () => { - test("Nullable.isNullable", () => { - module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Check if asNullable is not null or undefined - switch asNullable->Nullable.isNullable { - | true => assert(false) - | false => assert(true) - } - } - () - }) -}) - -describe("Nullable.make", () => { - test("Nullable.make", () => { - module Test = { - let myStr = "Hello" - let asNullable = myStr->Nullable.make - - // Can't do the below because we're now forced to check for nullability - // myStr == asNullable - - // Need to do this - switch asNullable->Nullable.toOption { - | Some(value) if value == myStr => Console.log("Yay, values matched!") - | _ => Console.log("Values did not match.") - } - } - () - }) -}) - -describe("Nullable.map", () => { - test("Nullable.map", () => { - module Test = { - Nullable.map(Nullable.make(3), x => x * x) // Nullable.make(9) - Nullable.map(undefined, x => x * x) // undefined - } - () - }) -}) - -describe("Nullable.mapOr", () => { - test("Nullable.mapOr", () => { - module Test = { - let someValue = Nullable.make(3) - someValue->Nullable.mapOr(0, x => x + 5) // 8 - - let noneValue = Nullable.null - noneValue->Nullable.mapOr(0, x => x + 5) // 0 - } - () - }) -}) - -describe("Nullable.null", () => { - test("Nullable.null", () => { - module Test = { - Console.log(Nullable.null) // Logs `null` to the console. - } - () - }) -}) - -describe("Nullable.toOption", () => { - test("Nullable.toOption", () => { - module Test = { - let nullableString = Nullable.make("Hello") - - switch nullableString->Nullable.toOption { - | Some(str) => Console.log2("Got string:", str) - | None => Console.log("Didn't have a value.") - } - } - () - }) -}) - -describe("Nullable.undefined", () => { - test("Nullable.undefined", () => { - module Test = { - Console.log(undefined) // Logs `undefined` to the console. - } - () - }) -}) - -describe("Object.assign", () => { - test("Object.assign", () => { - module Test = { - Object.assign({"a": 1}, {"a": 2}) // {"a": 2} - Object.assign({"a": 1, "b": 2}, {"a": 0}) // {"a": 0, "b": 2} - Object.assign({"a": 1}, {"a": null}) // {"a": null} - } - () - }) -}) - -describe("Object.create", () => { - test("Object.create", () => { - module Test = { - let x = {"fruit": "banana"} - let y = Object.create(x) - y->Object.get("fruit") // Some("banana") - } - () - }) -}) - -describe("Object.freeze", () => { - test("Object.freeze", () => { - module Test = { - let obj = {"a": 1} - obj->Object.set("a", 2) // succeeds - obj->Object.freeze->ignore - - try { - obj->Object.set("a", 3) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Object.get", () => { - test("Object.get", () => { - module Test = { - {"a": 1}->Object.get("a") // Some(1) - {"a": 1}->Object.get("b") // None - {"a": undefined}->Object.get("a") // None - {"a": null}->Object.get("a") // Some(null) - {"a": 1}->Object.get("toString")->Option.isSome // true - } - () - }) -}) - -describe("Object.getSymbol", () => { - test("Object.getSymbol", () => { - module Test = { - let fruit = Symbol.make("fruit") - let x = Object.make() - x->Object.setSymbol(fruit, "banana") - x->Object.getSymbol(fruit) // Some("banana") - } - () - }) -}) - -describe("Object.hasOwnProperty", () => { - test("Object.hasOwnProperty", () => { - module Test = { - let point = {"x": 1, "y": 2} - {"a": 1}->Object.hasOwnProperty("a") // true - {"a": 1}->Object.hasOwnProperty("b") // false - {"a": 1}->Object.hasOwnProperty("toString") // false - } - () - }) -}) - -describe("Object.is", () => { - test("Object.is", () => { - module Test = { - Object.is(25, 13) // false - Object.is("abc", "abc") // true - Object.is(undefined, undefined) // true - Object.is(undefined, null) // false - Object.is(-0.0, 0.0) // false - Object.is(list{1, 2}, list{1, 2}) // false - - Object.is([1, 2, 3], [1, 2, 3]) // false - [1, 2, 3] == [1, 2, 3] // true - [1, 2, 3] === [1, 2, 3] // false - - let fruit = {"name": "Apple"} - Object.is(fruit, fruit) // true - Object.is(fruit, {"name": "Apple"}) // false - fruit == {"name": "Apple"} // true - fruit === {"name": "Apple"} // false - } - () - }) -}) - -describe("Object.isExtensible", () => { - test("Object.isExtensible", () => { - module Test = { - let obj = {"a": 1} - obj->Object.isExtensible // true - obj->Object.preventExtensions->ignore - obj->Object.isExtensible // false - } - () - }) -}) - -describe("Object.isFrozen", () => { - test("Object.isFrozen", () => { - module Test = { - let point = {"x": 1, "y": 3}->Object.freeze - let pointIsFrozen = point->Object.isFrozen // true - let fruit = {"name": "Apple"} - let fruitIsFrozen = fruit->Object.isFrozen // false - } - () - }) -}) - -describe("Object.isSealed", () => { - test("Object.isSealed", () => { - module Test = { - let point = {"x": 1, "y": 3}->Object.seal - let pointIsSealed = point->Object.isSealed // true - let fruit = {"name": "Apple"} - let fruitIsSealed = fruit->Object.isSealed // false - } - () - }) -}) - -describe("Object.keysToArray", () => { - test("Object.keysToArray", () => { - module Test = { - {"a": 1, "b": 2}->Object.keysToArray // ["a", "b"] - {"a": None}->Object.keysToArray // ["a"] - Object.make()->Object.keysToArray // [] - } - () - }) -}) - -describe("Object.make", () => { - test("Object.make", () => { - module Test = { - let x = Object.make() - x->Object.keysToArray->Array.length // 0 - x->Object.get("toString")->Option.isSome // true - } - () - }) -}) - -describe("Object.preventExtensions", () => { - test("Object.preventExtensions", () => { - module Test = { - let obj = {"a": 1} - obj->Object.set("b", 2) // succeeds - obj->Object.preventExtensions->ignore - try { - obj->Object.set("c", 3) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } - } - () - }) -}) - -describe("Object.seal", () => { - test("Object.seal", () => { - module Test = { - let point = {"x": 1, "y": 2} - point->Object.set("x", -7) // succeeds - point->Object.seal->ignore - - try { - point->Object.set("z", 9) // fails - } catch { - | Exn.Error(_) => assert(true) - | _ => assert(false) - } - - point->Object.set("x", 13) // succeeds - } - () - }) -}) - -describe("Object.set", () => { - test("Object.set", () => { - module Test = { - {"a": 1}->Object.set("a", 2) // {"a": 2} - {"a": 1}->Object.set("a", None) // {"a": None} - {"a": 1}->Object.set("b", 2) // {"a": 1, "b": 2} - } - () - }) -}) - -describe("Option.all", () => { - test("Option.all", () => { - module Test = { - Option.all([Some(1), Some(2), Some(3)]) // Some([1, 2, 3]) - Option.all([Some(1), None]) // None - } - () - }) -}) - -describe("Option.compare", () => { - test("Option.compare", () => { - module Test = { - let clockCompare = (a, b) => Int.compare(mod(a, 12), mod(b, 12)) - - Option.compare(Some(3), Some(15), clockCompare) // 0. - Option.compare(Some(3), Some(14), clockCompare) // 1. - Option.compare(Some(2), Some(15), clockCompare) // (-1.) - Option.compare(None, Some(15), clockCompare) // (-1.) - Option.compare(Some(14), None, clockCompare) // 1. - Option.compare(None, None, clockCompare) // 0. - } - () - }) -}) - -describe("Option.equal", () => { - test("Option.equal", () => { - module Test = { - let clockEqual = (a, b) => mod(a, 12) == mod(b, 12) - - open Option - - equal(Some(3), Some(15), clockEqual) // true - equal(Some(3), None, clockEqual) // false - equal(None, Some(3), clockEqual) // false - equal(None, None, clockEqual) // true - } - () - }) -}) - -describe("Option.filter", () => { - test("Option.filter", () => { - module Test = { - Option.filter(Some(10), x => x > 5) // Some(10) - Option.filter(Some(4), x => x > 5) // None - Option.filter(None, x => x > 5) // None - } - () - }) -}) - -describe("Option.flatMap", () => { - test("Option.flatMap", () => { - module Test = { - let addIfAboveOne = value => - if value > 1 { - Some(value + 1) - } else { - None - } - - Option.flatMap(Some(2), addIfAboveOne) // Some(3) - Option.flatMap(Some(-4), addIfAboveOne) // None - Option.flatMap(None, addIfAboveOne) // None - } - () - }) -}) - -describe("Option.forEach", () => { - test("Option.forEach", () => { - module Test = { - Option.forEach(Some("thing"), x => Console.log(x)) // logs "thing" - Option.forEach(None, x => Console.log(x)) // returns () - } - () - }) -}) - -describe("Option.getExn", () => { - test("Option.getExn", () => { - module Test = { - Option.getExn(Some(3))->assertEqual(3) - - switch Option.getExn(None) { - | exception _ => assert(true) - | _ => assert(false) - } - - switch Option.getExn(None, ~message="was None!") { - | exception _ => assert(true) // Raises an Error with the message "was None!" - | _ => assert(false) - } - } - () - }) -}) - -describe("Option.getOr", () => { - test("Option.getOr", () => { - module Test = { - Option.getOr(None, "Banana") // Banana - Option.getOr(Some("Apple"), "Banana") // Apple - - let greet = (firstName: option) => - "Greetings " ++ firstName->Option.getOr("Anonymous") - - Some("Jane")->greet // "Greetings Jane" - None->greet // "Greetings Anonymous" - } - () - }) -}) - -describe("Option.getUnsafe", () => { - test("Option.getUnsafe", () => { - module Test = { - Option.getUnsafe(Some(3)) == 3 - Option.getUnsafe((None: option)) // Returns `undefined`, which is not a valid `int` - } - () - }) -}) - -describe("Option.isNone", () => { - test("Option.isNone", () => { - module Test = { - Option.isNone(None) // true - Option.isNone(Some(1)) // false - } - () - }) -}) - -describe("Option.isSome", () => { - test("Option.isSome", () => { - module Test = { - Option.isSome(None) // false - Option.isSome(Some(1)) // true - } - () - }) -}) - -describe("Option.map", () => { - test("Option.map", () => { - module Test = { - Option.map(Some(3), x => x * x) // Some(9) - Option.map(None, x => x * x) // None - } - () - }) -}) - -describe("Option.mapOr", () => { - test("Option.mapOr", () => { - module Test = { - let someValue = Some(3) - someValue->Option.mapOr(0, x => x + 5) // 8 - - let noneValue = None - noneValue->Option.mapOr(0, x => x + 5) // 0 - } - () - }) -}) - -describe("Option.orElse", () => { - test("Option.orElse", () => { - module Test = { - Option.orElse(Some(1812), Some(1066)) == Some(1812) - Option.orElse(None, Some(1066)) == Some(1066) - Option.orElse(None, None) == None - } - () - }) -}) - -describe("Pervasives.assertEqual", () => { - test("Pervasives.assertEqual", () => { - module Test = { - list{1, 2} - ->List.tailExn - ->assertEqual(list{2}) - } - () - }) -}) - -describe("Pervasives.clearInterval", () => { - test("Pervasives.clearInterval", () => { - module Test = { - let intervalId = setInterval( - () => { - Console.log("This prints in 100 ms") - }, - 100, - ) - - // Stop the interval after 500 ms - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) - } - () - }) -}) - -describe("Pervasives.clearTimeout", () => { - test("Pervasives.clearTimeout", () => { - module Test = { - let timeoutId = setTimeout( - () => { - Console.log("This prints in 2 seconds.") - }, - 2000, - ) - - // Clearing the timeout right away, before 2 seconds has passed, means that the above callback logging to the console will never run. - clearTimeout(timeoutId) - } - () - }) -}) - -describe("Pervasives.decodeURI", () => { - test("Pervasives.decodeURI", () => { - module Test = { - Console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")) - // Logs "https://rescript-lang.org?array=[someValue]" to the console. - } - () - }) -}) - -describe("Pervasives.decodeURIComponent", () => { - test("Pervasives.decodeURIComponent", () => { - module Test = { - Console.log(decodeURIComponent("array%3D%5BsomeValue%5D")) - // Logs "array=[someValue]" to the console. - } - () - }) -}) - -describe("Pervasives.encodeURI", () => { - test("Pervasives.encodeURI", () => { - module Test = { - Console.log(encodeURI("https://rescript-lang.org?array=[someValue]")) - // Logs "https://rescript-lang.org?array=%5BsomeValue%5D" to the console. - } - () - }) -}) - -describe("Pervasives.encodeURIComponent", () => { - test("Pervasives.encodeURIComponent", () => { - module Test = { - Console.log(encodeURIComponent("array=[someValue]")) - // Logs "array%3D%5BsomeValue%5D" to the console. - } - () - }) -}) - -describe("Pervasives.import", () => { - test("Pervasives.import", () => { - module Test = { - @send external indexOf: (array<'a>, 'a) => int = "indexOf" - - let indexOfOpt = (arr, item) => - switch arr->indexOf(item) { - | -1 => None - | index => Some(index) - } - - let main = async () => { - let indexOfOpt = await import(Array.indexOfOpt) - let index = indexOfOpt([1, 2], 2) - Console.log(index) - } - } - () - }) -}) - -describe("Pervasives.setInterval", () => { - test("Pervasives.setInterval", () => { - module Test = { - // Log to the console ever 200 ms (200 milliseconds). - let intervalId = setInterval( - () => { - Console.log("This prints every 200 ms.") - }, - 200, - ) - - let timeoutId = setTimeout( - () => { - clearInterval(intervalId) - }, - 500, - ) - } - () - }) -}) - -describe("Pervasives.setIntervalFloat", () => { - test("Pervasives.setIntervalFloat", () => { - module Test = { - // Log to the console ever 2 seconds (200 milliseconds). - let intervalId = setIntervalFloat( - () => { - Console.log("This prints every 200 ms") - }, - 200., - ) - - // Stop the interval after 500 ms - let timeoutId = setTimeoutFloat( - () => { - clearInterval(intervalId) - }, - 500.0, - ) - } - () - }) -}) - -describe("Pervasives.setTimeout", () => { - test("Pervasives.setTimeout", () => { - module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeout( - () => { - Console.log("This prints in 200 ms.") - }, - 200, - ) - } - () - }) -}) - -describe("Pervasives.setTimeoutFloat", () => { - test("Pervasives.setTimeoutFloat", () => { - module Test = { - // Log to the console after 200 milliseconds. - let timeoutId = setTimeoutFloat( - () => { - Console.log("This prints in 200 ms.") - }, - 200., - ) - } - () - }) -}) - -describe("Promise.all", () => { - test("Promise.all", () => { - module Test = { - open Promise - let promises = [resolve(1), resolve(2), resolve(3)] - - all(promises) - ->then( - results => { - results->Array.forEach( - num => { - Console.log2("Number: ", num) - }, - ) - - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.allSettled", () => { - test("Promise.allSettled", () => { - module Test = { - open Promise - - exception TestError(string) - - let promises = [resolve(1), resolve(2), reject(TestError("some rejected promise"))] - - allSettled(promises) - ->then( - results => { - results->Array.forEach( - result => { - switch result { - | Fulfilled({value: num}) => Console.log2("Number: ", num) - | Rejected({reason}) => Console.log(reason) - } - }, - ) - - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.any", () => { - test("Promise.any", () => { - module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - any(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) - } - () - }) -}) - -describe("Promise.catch", () => { - test("Promise.catch", () => { - module Test = { - open Promise - - exception SomeError(string) - - reject(SomeError("this is an error")) - ->then( - _ => { - Ok("This result will never be returned")->resolve - }, - ) - ->catch( - e => { - let msg = switch e { - | SomeError(msg) => "ReScript error occurred: " ++ msg - | Exn.Error(obj) => - switch Exn.message(obj) { - | Some(msg) => "JS exception occurred: " ++ msg - | None => "Some other JS value has been thrown" - } - | _ => "Unexpected error occurred" - } - - Error(msg)->resolve - }, - ) - ->then( - result => { - switch result { - | Ok(r) => Console.log2("Operation successful: ", r) - | Error(msg) => Console.log2("Operation failed: ", msg) - }->resolve - }, - ) - ->ignore // Ignore needed for side-effects - } - () - }) -}) - -describe("Promise.finally", () => { - test("Promise.finally", () => { - module Test = { - open Promise - exception SomeError(string) - let isDone = ref(false) - - resolve(5) - ->then( - _ => { - reject(SomeError("test")) - }, - ) - ->then( - v => { - Console.log2("final result", v) - resolve() - }, - ) - ->catch( - _ => { - Console.log("Error handled") - resolve() - }, - ) - ->finally( - () => { - Console.log("finally") - isDone := true - }, - ) - ->then( - () => { - Console.log2("isDone:", isDone.contents) - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.make", () => { - test("Promise.make", () => { - module Test = { - open Promise - - let n = 4 - Promise.make( - (resolve, reject) => { - if n < 5 { - resolve("success") - } else { - reject("failed") - } - }, - ) - ->then( - str => { - Console.log(str)->resolve - }, - ) - ->catch( - _ => { - Console.log("Error occurred") - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.race", () => { - test("Promise.race", () => { - module Test = { - open Promise - let racer = (ms, name) => { - Promise.make( - (resolve, _) => { - setTimeout( - () => { - resolve(name) - }, - ms, - )->ignore - }, - ) - } - - let promises = [racer(1000, "Turtle"), racer(500, "Hare"), racer(100, "Eagle")] - - race(promises)->then( - winner => { - Console.log("The winner is " ++ winner) - resolve() - }, - ) - } - () - }) -}) - -describe("Promise.reject", () => { - test("Promise.reject", () => { - module Test = { - exception TestError(string) - - TestError("some rejected value") - ->Promise.reject - ->Promise.catch( - v => { - switch v { - | TestError(msg) => assertEqual(msg, "some rejected value") - | _ => assert(false) - } - Promise.resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.resolve", () => { - test("Promise.resolve", () => { - module Test = { - let p = Promise.resolve(5) // promise - } - () - }) -}) - -describe("Promise.then", () => { - test("Promise.then", () => { - module Test = { - open Promise - resolve(5) - ->then( - num => { - resolve(num + 5) - }, - ) - ->then( - num => { - Console.log2("Your lucky number is: ", num) - resolve() - }, - ) - ->ignore - } - () - }) -}) - -describe("Promise.thenResolve", () => { - test("Promise.thenResolve", () => { - module Test = { - open Promise - resolve("Anna") - ->thenResolve( - str => { - "Hello " ++ str - }, - ) - ->thenResolve( - str => { - Console.log(str) - }, - ) - ->ignore // Ignore needed for side-effects - } - () - }) -}) - -describe("RegExp.Result.fullMatch", () => { - test("RegExp.Result.fullMatch", () => { - module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") - - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints the full string that matched, "ReScript is" - } - } - () - }) -}) - -describe("RegExp.Result.input", () => { - test("RegExp.Result.input", () => { - module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") - - // This below will log the full input string "ReScript is pretty cool, right?" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.input) - } - } - () - }) -}) - -describe("RegExp.Result.matches", () => { - test("RegExp.Result.matches", () => { - module Test = { - // Match the first two words separated by a space - let regexp = RegExp.fromString("(\\w+) (\\w+)") - - // This below will log "ReScript" and "is" to the console. - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => - switch result->RegExp.Result.matches { - | [firstWord, secondWord] => Console.log2(firstWord, secondWord) - | _ => Console.log("Didn't find exactly two words...") - } - } - } - () - }) -}) - -describe("RegExp.exec", () => { - test("RegExp.exec", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } - } - () - }) -}) - -describe("RegExp.fromString", () => { - test("RegExp.fromString", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } - } - () - }) -}) - -describe("RegExp.fromStringWithFlags", () => { - test("RegExp.fromStringWithFlags", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") - - switch regexp->RegExp.exec("ReScript is pretty cool, right?") { - | None => Console.log("Nope, no match...") - | Some(result) => Console.log(result->RegExp.Result.fullMatch) // Prints "ReScript" - } - } - () - }) -}) - -describe("RegExp.global", () => { - test("RegExp.global", () => { - module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.global) // Logs `true`, since `g` is set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.global) // Logs `false`, since `g` is not set - } - () - }) -}) - -describe("RegExp.ignoreCase", () => { - test("RegExp.ignoreCase", () => { - module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.ignoreCase) // Logs `false`, since `i` is not set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="i") - Console.log(regexp2->RegExp.ignoreCase) // Logs `true`, since `i` is set - } - () - }) -}) - -describe("RegExp.lastIndex", () => { - test("RegExp.lastIndex", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." - - Console.log(regexp->RegExp.lastIndex) // Logs `0` to the console - - regexp->RegExp.exec(someStr)->ignore - - Console.log(regexp->RegExp.lastIndex) // Logs `4` to the console - } - () - }) -}) - -describe("RegExp.multiline", () => { - test("RegExp.multiline", () => { - module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.multiline) // Logs `false`, since `m` is not set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mi") - Console.log(regexp2->RegExp.multiline) // Logs `true`, since `m` is set - } - () - }) -}) - -describe("RegExp.setLastIndex", () => { - test("RegExp.setLastIndex", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - let someStr = "Many words here." - - regexp->RegExp.setLastIndex(4) - regexp->RegExp.exec(someStr)->ignore - - Console.log(regexp->RegExp.lastIndex) // Logs `10` to the console - } - () - }) -}) - -describe("RegExp.source", () => { - test("RegExp.source", () => { - module Test = { - let regexp = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp->RegExp.source) // Logs `\w+`, the source text of the `RegExp` - } - () - }) -}) - -describe("RegExp.sticky", () => { - test("RegExp.sticky", () => { - module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `y` is not set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="my") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `y` is set - } - () - }) -}) - -describe("RegExp.test", () => { - test("RegExp.test", () => { - module Test = { - // Match the first word in a sentence - let regexp = RegExp.fromString("\\w+") - - if regexp->RegExp.test("ReScript is cool!") { - Console.log("Yay, there's a word in there.") - } - } - () - }) -}) - -describe("RegExp.unicode", () => { - test("RegExp.unicode", () => { - module Test = { - let regexp1 = RegExp.fromStringWithFlags("\\w+", ~flags="g") - Console.log(regexp1->RegExp.unicode) // Logs `false`, since `u` is not set - - let regexp2 = RegExp.fromStringWithFlags("\\w+", ~flags="mu") - Console.log(regexp2->RegExp.unicode) // Logs `true`, since `u` is set - } - () - }) -}) - -describe("Result.all", () => { - test("Result.all", () => { - module Test = { - Result.all([Ok(1), Ok(2), Ok(3)]) // Ok([1, 2, 3]) - Result.all([Ok(1), Error(1)]) // Error(1) - } - () - }) -}) - -describe("Result.compare", () => { - test("Result.compare", () => { - module Test = { - let good1 = Ok(59) - - let good2 = Ok(37) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") - - let mod10cmp = (a, b) => Int.compare(mod(a, 10), mod(b, 10)) - - Result.compare(Ok(39), Ok(57), mod10cmp) == 1. - - Result.compare(Ok(57), Ok(39), mod10cmp) == -1. - - Result.compare(Ok(39), Error("y"), mod10cmp) == 1. - - Result.compare(Error("x"), Ok(57), mod10cmp) == -1. - - Result.compare(Error("x"), Error("y"), mod10cmp) == 0. - } - () - }) -}) - -describe("Result.equal", () => { - test("Result.equal", () => { - module Test = { - let good1 = Ok(42) - - let good2 = Ok(32) - - let bad1 = Error("invalid") - - let bad2 = Error("really invalid") - - let mod10equal = (a, b) => mod(a, 10) === mod(b, 10) - - Result.equal(good1, good2, mod10equal) == true - - Result.equal(good1, bad1, mod10equal) == false - - Result.equal(bad2, good2, mod10equal) == false - - Result.equal(bad1, bad2, mod10equal) == true - } - () - }) -}) - -describe("Result.flatMap", () => { - test("Result.flatMap", () => { - module Test = { - let recip = x => - if x !== 0.0 { - Ok(1.0 /. x) - } else { - Error("Divide by zero") - } - - Result.flatMap(Ok(2.0), recip) == Ok(0.5) - - Result.flatMap(Ok(0.0), recip) == Error("Divide by zero") - - Result.flatMap(Error("Already bad"), recip) == Error("Already bad") - } - () - }) -}) - -describe("Result.forEach", () => { - test("Result.forEach", () => { - module Test = { - Result.forEach(Ok(3), Console.log) // Logs "3", returns () - Result.forEach(Error("x"), Console.log) // Does nothing, returns () - } - () - }) -}) - -describe("Result.getOr", () => { - test("Result.getOr", () => { - module Test = { - Result.getOr(Ok(42), 0) == 42 - - Result.getOr(Error("Invalid Data"), 0) == 0 - } - () - }) -}) - -describe("Result.map", () => { - test("Result.map", () => { - module Test = { - let f = x => sqrt(Int.toFloat(x)) - - Result.map(Ok(64), f) == Ok(8.0) - - Result.map(Error("Invalid data"), f) == Error("Invalid data") - } - () - }) -}) - -describe("Result.mapError", () => { - test("Result.mapError", () => { - module Test = { - let format = n => `Error code: ${n->Int.toString}` - Result.mapError(Error(14), format) // Error("Error code: 14") - Result.mapError(Ok("abc"), format) // Ok("abc") - } - () - }) -}) - -describe("Result.mapOr", () => { - test("Result.mapOr", () => { - module Test = { - let ok = Ok(42) - Result.mapOr(ok, 0, x => x / 2) == 21 - - let error = Error("Invalid data") - Result.mapOr(error, 0, x => x / 2) == 0 - } - () - }) -}) - -describe("Set.add", () => { - test("Set.add", () => { - module Test = { - let set = Set.make() - set->Set.add("someValue") - } - () - }) -}) - -describe("Set.clear", () => { - test("Set.clear", () => { - module Test = { - let set = Set.make() - - set->Set.add("someKey") - set->Set.size // 1 - - set->Set.clear - set->Set.size // 0 - } - () - }) -}) - -describe("Set.delete", () => { - test("Set.delete", () => { - module Test = { - let set = Set.make() - set->Set.add("someValue") - let didDeleteValue = set->Set.delete("someValue") - Console.log(didDeleteValue) // Logs `true` to the console, becuase the set had the value, so it was successfully deleted - - let didDeleteValue = set->Set.delete("someNonExistantKey") - Console.log(didDeleteValue) // Logs `false` to the console, becuase the value did not exist in the set - } - () - }) -}) - -describe("Set.forEach", () => { - test("Set.forEach", () => { - module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("someValue2") - - set->Set.forEach( - value => { - Console.log(value) - }, - ) - } - () - }) -}) - -describe("Set.fromArray", () => { - test("Set.fromArray", () => { - module Test = { - type languages = ReScript | JavaScript | TypeScript - let languageRank = [ReScript, JavaScript, TypeScript] - - let set = Set.fromArray(languageRank) // Set.t - - switch set->Set.has(ReScript) { - | true => Console.log("Yay, ReScript is in there!") - | false => Console.log("Uh-oh, something is _terribly_ wrong with this program... abort.") - } - } - () - }) -}) - -describe("Set.fromIterator", () => { - test("Set.fromIterator", () => { - module Test = { - // Let's pretend we have an interator - let iterator: Iterator.t = %raw(` - (() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })() -`) - - iterator - ->Set.fromIterator - ->Set.size - ->assertEqual(3) - } - () - }) -}) - -describe("Set.has", () => { - test("Set.has", () => { - module Test = { - let set = Set.make() - set->Set.add("someValue") - - switch set->Set.has("someValue") { - | false => Console.log("Nope, didn't have it.") - | true => Console.log("Yay, we have the value!") - } - } - () - }) -}) - -describe("Set.make", () => { - test("Set.make", () => { - module Test = { - // You can annotate the type of your set if you want to - let mySet: Set.t = Set.make() - - // Or you can let ReScript infer what's in your Set - let set = Set.make() - set->Set.add("Fine name") // Inferred as Set.t - } - () - }) -}) - -describe("Set.size", () => { - test("Set.size", () => { - module Test = { - let set = Set.make() - - set->Set.add("someValue") - set->Set.add("someValue") - set->Set.add("someValue2") - - let size = set->Set.size // 2 - } - () - }) -}) - -describe("Set.toArray", () => { - test("Set.toArray", () => { - module Test = { - let set = Set.fromArray(["apple", "orange", "apple", "banana"]) - set->Set.toArray // ["apple", "orange", "banana"] - } - () - }) -}) - -describe("Set.values", () => { - test("Set.values", () => { - module Test = { - let set = Set.make() - set->Set.add("someValue") - set->Set.add("anotherValue") - - let values = set->Set.values - - // Logs the first value - Console.log(Iterator.next(values).value) - - // You can also turn the iterator into an array. - // Remember that an iterator consumes values. We'll need a fresh values iterator to get an array of all values, since we consumed a value via `next` above already. - Console.log(set->Set.values->Iterator.toArray) - } - () - }) -}) - -describe("String.charAt", () => { - test("String.charAt", () => { - module Test = { - String.charAt("ReScript", 0) == "R" - String.charAt("Hello", 12) == "" - String.charAt(`JS`, 5) == "" - } - () - }) -}) - -describe("String.charCodeAt", () => { - test("String.charCodeAt", () => { - module Test = { - String.charCodeAt(`😺`, 0) == 0xd83d->Int.toFloat - String.codePointAt(`😺`, 0) == Some(0x1f63a) - } - () - }) -}) - -describe("String.codePointAt", () => { - test("String.codePointAt", () => { - module Test = { - String.codePointAt(`¿😺?`, 1) == Some(0x1f63a) - String.codePointAt("abc", 5) == None - } - () - }) -}) - -describe("String.concat", () => { - test("String.concat", () => { - module Test = { - String.concat("cow", "bell") == "cowbell" - String.concat("Re", "Script") == "ReScript" - } - () - }) -}) - -describe("String.concatMany", () => { - test("String.concatMany", () => { - module Test = { - String.concatMany("1st", ["2nd", "3rd", "4th"]) == "1st2nd3rd4th" - } - () - }) -}) - -describe("String.endsWith", () => { - test("String.endsWith", () => { - module Test = { - String.endsWith("BuckleScript", "Script") == true - String.endsWith("BuckleShoes", "Script") == false - } - () - }) -}) - -describe("String.endsWithFrom", () => { - test("String.endsWithFrom", () => { - module Test = { - String.endsWithFrom("abcd", "cd", 4) == true - String.endsWithFrom("abcde", "cd", 3) == false - String.endsWithFrom("abcde", "cde", 99) == true - String.endsWithFrom("example.dat", "ple", 7) == true - } - () - }) -}) - -describe("String.fromCharCode", () => { - test("String.fromCharCode", () => { - module Test = { - String.fromCharCode(65) == "A" - String.fromCharCode(0x3c8) == `ψ` - String.fromCharCode(0xd55c) == `한` - String.fromCharCode(-64568) == `ψ` - } - () - }) -}) - -describe("String.fromCharCodeMany", () => { - test("String.fromCharCodeMany", () => { - module Test = { - String.fromCharCodeMany([189, 43, 190, 61]) == "½+¾=" - String.fromCharCodeMany([65, 66, 67]) == "ABC" - } - () - }) -}) - -describe("String.fromCodePoint", () => { - test("String.fromCodePoint", () => { - module Test = { - String.fromCodePoint(65) == "A" - String.fromCodePoint(0x3c8) == `ψ` - String.fromCodePoint(0xd55c) == `한` - String.fromCodePoint(0x1f63a) == `😺` - } - () - }) -}) - -describe("String.fromCodePointMany", () => { - test("String.fromCodePointMany", () => { - module Test = { - String.fromCodePointMany([0xd55c, 0xae00, 0x1f63a]) == `한글😺` - } - () - }) -}) - -describe("String.get", () => { - test("String.get", () => { - module Test = { - String.get("ReScript", 0) == Some("R") - String.get("Hello", 4) == Some("o") - String.get(`JS`, 4) == None - } - () - }) -}) - -describe("String.getUnsafe", () => { - test("String.getUnsafe", () => { - module Test = { - String.getUnsafe("ReScript", 0) == "R" - String.getUnsafe("Hello", 4) == "o" - } - () - }) -}) - -describe("String.includes", () => { - test("String.includes", () => { - module Test = { - String.includes("programmer", "gram") == true - String.includes("programmer", "er") == true - String.includes("programmer", "pro") == true - String.includes("programmer.dat", "xyz") == false - } - () - }) -}) - -describe("String.includesFrom", () => { - test("String.includesFrom", () => { - module Test = { - String.includesFrom("programmer", "gram", 1) == true - String.includesFrom("programmer", "gram", 4) == false - String.includesFrom(`대한민국`, `한`, 1) == true - } - () - }) -}) - -describe("String.indexOf", () => { - test("String.indexOf", () => { - module Test = { - String.indexOf("bookseller", "ok") == 2 - String.indexOf("bookseller", "sell") == 4 - String.indexOf("beekeeper", "ee") == 1 - String.indexOf("bookseller", "xyz") == -1 - } - () - }) -}) - -describe("String.indexOfFrom", () => { - test("String.indexOfFrom", () => { - module Test = { - String.indexOfFrom("bookseller", "ok", 1) == 2 - String.indexOfFrom("bookseller", "sell", 2) == 4 - String.indexOfFrom("bookseller", "sell", 5) == -1 - } - () - }) -}) - -describe("String.indexOfOpt", () => { - test("String.indexOfOpt", () => { - module Test = { - String.indexOfOpt("bookseller", "ok") == Some(2) - String.indexOfOpt("bookseller", "xyz") == None - } - () - }) -}) - -describe("String.lastIndexOf", () => { - test("String.lastIndexOf", () => { - module Test = { - String.lastIndexOf("bookseller", "ok") == 2 - String.lastIndexOf("beekeeper", "ee") == 4 - String.lastIndexOf("abcdefg", "xyz") == -1 - } - () - }) -}) - -describe("String.lastIndexOfFrom", () => { - test("String.lastIndexOfFrom", () => { - module Test = { - String.lastIndexOfFrom("bookseller", "ok", 6) == 2 - String.lastIndexOfFrom("beekeeper", "ee", 8) == 4 - String.lastIndexOfFrom("beekeeper", "ee", 3) == 1 - String.lastIndexOfFrom("abcdefg", "xyz", 4) == -1 - } - () - }) -}) - -describe("String.lastIndexOfOpt", () => { - test("String.lastIndexOfOpt", () => { - module Test = { - String.lastIndexOfOpt("bookseller", "ok") == Some(2) - String.lastIndexOfOpt("beekeeper", "ee") == Some(4) - String.lastIndexOfOpt("abcdefg", "xyz") == None - } - () - }) -}) - -describe("String.length", () => { - test("String.length", () => { - module Test = { - String.length("abcd") == 4 - } - () - }) -}) - -describe("String.localeCompare", () => { - test("String.localeCompare", () => { - module Test = { - String.localeCompare("a", "c") < 0.0 == true - String.localeCompare("a", "a") == 0.0 - } - () - }) -}) - -describe("String.make", () => { - test("String.make", () => { - module Test = { - String.make(3.5) == "3.5" - String.make([1, 2, 3]) == "1,2,3" - } - () - }) -}) - -describe("String.match", () => { - test("String.match", () => { - module Test = { - String.match("The better bats", /b[aeiou]t/) == Some([Some("bet")]) - String.match("The better bats", /b[aeiou]t/g) == Some([Some("bet"), Some("bat")]) - String.match("Today is 2018-04-05.", /(\d+)-(\d+)-(\d+)/) == - Some([Some("2018-04-05"), Some("2018"), Some("04"), Some("05")]) - String.match("The optional example", /(foo)?(example)/) == - Some([Some("example"), None, Some("example")]) - String.match("The large container.", /b[aeiou]g/) == None - } - () - }) -}) - -describe("String.normalize", () => { - test("String.normalize", () => { - module Test = { - let string1 = "\u00F1" - let string2 = "\u006E\u0303" - - assert(string1 != string2) // true - assertEqual(String.normalize(string1), String.normalize(string2)) - } - () - }) -}) - -describe("String.normalizeForm", () => { - test("String.normalizeForm", () => { - module Test = { - let string1 = "\uFB00" - let string2 = "\u0066\u0066" - Console.log(string1 == string2) // false - - let normalizeString1 = String.normalizeByForm(string1, #NFKD) - let normalizeString2 = String.normalizeByForm(string2, #NFKD) - Console.log(normalizeString1 == normalizeString2) // true - } - () - }) -}) - -describe("String.padEnd", () => { - test("String.padEnd", () => { - module Test = { - String.padEnd("Hello", 10, ".") == "Hello....." - String.padEnd("abc", 1, "") == "abc" - } - () - }) -}) - -describe("String.padStart", () => { - test("String.padStart", () => { - module Test = { - String.padStart("abc", 5, " ") == " abc" - String.padStart("abc", 6, "123465") == "123abc" - } - () - }) -}) - -describe("String.repeat", () => { - test("String.repeat", () => { - module Test = { - String.repeat("ha", 3) == "hahaha" - String.repeat("empty", 0) == "" - } - () - }) -}) - -describe("String.replace", () => { - test("String.replace", () => { - module Test = { - String.replace("old string", "old", "new") == "new string" - String.replace("the cat and the dog", "the", "this") == "this cat and the dog" - } - () - }) -}) - -describe("String.replaceAll", () => { - test("String.replaceAll", () => { - module Test = { - String.replaceAll("old old string", "old", "new") == "new new string" - String.replaceAll("the cat and the dog", "the", "this") == "this cat and this dog" - } - () - }) -}) - -describe("String.replaceAllRegExp", () => { - test("String.replaceAllRegExp", () => { - module Test = { - String.replaceAllRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceAllRegExp("aabbcc", /b/g, ".") == "aa..cc" - } - () - }) -}) - -describe("String.replaceRegExp", () => { - test("String.replaceRegExp", () => { - module Test = { - String.replaceRegExp("vowels be gone", /[aeiou]/g, "x") == "vxwxls bx gxnx" - String.replaceRegExp("Juan Fulano", /(\w+) (\w+)/, "$2, $1") == "Fulano, Juan" - } - () - }) -}) - -describe("String.search", () => { - test("String.search", () => { - module Test = { - String.search("testing 1 2 3", /\d+/) == 8 - String.search("no numbers", /\d+/) == -1 - } - () - }) -}) - -describe("String.searchOpt", () => { - test("String.searchOpt", () => { - module Test = { - String.searchOpt("testing 1 2 3", /\d+/) == Some(8) - String.searchOpt("no numbers", /\d+/) == None - } - () - }) -}) - -describe("String.slice", () => { - test("String.slice", () => { - module Test = { - String.slice("abcdefg", ~start=2, ~end=5) == "cde" - String.slice("abcdefg", ~start=2, ~end=9) == "cdefg" - String.slice("abcdefg", ~start=-4, ~end=-2) == "de" - String.slice("abcdefg", ~start=5, ~end=1) == "" - } - () - }) -}) - -describe("String.sliceToEnd", () => { - test("String.sliceToEnd", () => { - module Test = { - String.sliceToEnd("abcdefg", ~start=4) == "efg" - String.sliceToEnd("abcdefg", ~start=-2) == "fg" - String.sliceToEnd("abcdefg", ~start=7) == "" - } - () - }) -}) - -describe("String.split", () => { - test("String.split", () => { - module Test = { - String.split("2018-01-02", "-") == ["2018", "01", "02"] - String.split("a,b,,c", ",") == ["a", "b", "", "c"] - String.split("good::bad as great::awful", "::") == ["good", "bad as great", "awful"] - String.split("has-no-delimiter", ";") == ["has-no-delimiter"] - } - () - }) -}) - -describe("String.splitAtMost", () => { - test("String.splitAtMost", () => { - module Test = { - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=3) == ["ant", "bee", "cat"] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=0) == [] - String.splitAtMost("ant/bee/cat/dog/elk", "/", ~limit=9) == [ - "ant", - "bee", - "cat", - "dog", - "elk", - ] - } - () - }) -}) - -describe("String.splitByRegExp", () => { - test("String.splitByRegExp", () => { - module Test = { - String.splitByRegExp("Jan,Feb,Mar", /,/) == [Some("Jan"), Some("Feb"), Some("Mar")] - } - () - }) -}) - -describe("String.splitByRegExpAtMost", () => { - test("String.splitByRegExpAtMost", () => { - module Test = { - String.splitByRegExpAtMost("Hello World. How are you doing?", / /, ~limit=3) == [ - Some("Hello"), - Some("World."), - Some("How"), - ] - } - () - }) -}) - -describe("String.startsWith", () => { - test("String.startsWith", () => { - module Test = { - String.startsWith("BuckleScript", "Buckle") == true - String.startsWith("BuckleScript", "") == true - String.startsWith("JavaScript", "Buckle") == false - } - () - }) -}) - -describe("String.startsWithFrom", () => { - test("String.startsWithFrom", () => { - module Test = { - String.startsWithFrom("BuckleScript", "kle", 3) == true - String.startsWithFrom("BuckleScript", "", 3) == true - String.startsWithFrom("JavaScript", "Buckle", 2) == false - } - () - }) -}) - -describe("String.substring", () => { - test("String.substring", () => { - module Test = { - String.substring("playground", ~start=3, ~end=6) == "ygr" - String.substring("playground", ~start=6, ~end=3) == "ygr" - String.substring("playground", ~start=4, ~end=12) == "ground" - } - () - }) -}) - -describe("String.substringToEnd", () => { - test("String.substringToEnd", () => { - module Test = { - String.substringToEnd("playground", ~start=4) == "ground" - String.substringToEnd("playground", ~start=-3) == "playground" - String.substringToEnd("playground", ~start=12) == "" - } - () - }) -}) - -describe("String.toLowerCase", () => { - test("String.toLowerCase", () => { - module Test = { - String.toLowerCase("ABC") == "abc" - String.toLowerCase(`ΣΠ`) == `σπ` - String.toLowerCase(`ΠΣ`) == `πς` - } - () - }) -}) - -describe("String.toUpperCase", () => { - test("String.toUpperCase", () => { - module Test = { - String.toUpperCase("abc") == "ABC" - String.toUpperCase(`Straße`) == `STRASSE` - String.toUpperCase(`πς`) == `ΠΣ` - } - () - }) -}) - -describe("String.trim", () => { - test("String.trim", () => { - module Test = { - String.trim(" abc def ") == "abc def" - String.trim("\n\r\t abc def \n\n\t\r ") == "abc def" - } - () - }) -}) - -describe("String.trimEnd", () => { - test("String.trimEnd", () => { - module Test = { - String.trimEnd(" Hello world! ") == " Hello world!" - String.trimEnd(" Hello world! ") == " Hello world!" - } - () - }) -}) - -describe("String.trimStart", () => { - test("String.trimStart", () => { - module Test = { - String.trimStart(" Hello world! ") == "Hello world! " - String.trimStart(" Hello world! ") == "Hello world! " - } - () - }) -}) - -describe("String.unsafeReplaceRegExpBy0", () => { - test("String.unsafeReplaceRegExpBy0", () => { - module Test = { - let str = "beautiful vowels" - let re = /[aeiou]/g - let matchFn = (~match, ~offset as _, ~input as _) => String.toUpperCase(match) - String.unsafeReplaceRegExpBy0(str, re, matchFn) == "bEAUtIfUl vOwEls" - } - () - }) -}) - -describe("String.unsafeReplaceRegExpBy1", () => { - test("String.unsafeReplaceRegExpBy1", () => { - module Test = { - let str = "Jony is 40" - let re = /(Jony is )\d+/g - let matchFn = (~match as _, ~group1, ~offset as _, ~input as _) => { - group1 ++ "41" - } - String.unsafeReplaceRegExpBy1(str, re, matchFn) == "Jony is 41" - } - () - }) -}) - -describe("String.unsafeReplaceRegExpBy2", () => { - test("String.unsafeReplaceRegExpBy2", () => { - module Test = { - let str = "7 times 6" - let re = /(\d+) times (\d+)/ - let matchFn = (~match as _, ~group1, ~group2, ~offset as _, ~input as _) => { - switch (Int.fromString(group1), Int.fromString(group2)) { - | (Some(x), Some(y)) => Int.toString(x * y) - | _ => "???" - } - } - String.unsafeReplaceRegExpBy2(str, re, matchFn) == "42" - } - () - }) -}) - -describe("Type.Classify.classify", () => { - test("Type.Classify.classify", () => { - module Test = { - switch %raw(`null`)->Type.Classify.classify { - | Null => Console.log("Yup, that's null.") - | _ => Console.log("This doesn't actually appear to be null...") - } - } - () - }) -}) - -describe("Type.typeof", () => { - test("Type.typeof", () => { - module Test = { - Console.log(Type.typeof("Hello")) // Logs "string" to the console. - - let someVariable = true - - switch someVariable->Type.typeof { - | #boolean => Console.log("This is a bool, yay!") - | _ => Console.log("Oh, not a bool sadly...") - } - } - () - }) -}) diff --git a/tests/docstrings_examples/generated_mocha_test.res.mjs b/tests/docstrings_examples/generated_mocha_test.res.mjs deleted file mode 100644 index bdf8d22d0b..0000000000 --- a/tests/docstrings_examples/generated_mocha_test.res.mjs +++ /dev/null @@ -1,22839 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - -import * as Exn from "rescript/lib/es6/Exn.js"; -import * as Int from "rescript/lib/es6/Int.js"; -import * as Dict from "rescript/lib/es6/Dict.js"; -import * as $$JSON from "rescript/lib/es6/JSON.js"; -import * as List from "rescript/lib/es6/List.js"; -import * as $$Math from "rescript/lib/es6/Math.js"; -import * as Null from "rescript/lib/es6/Null.js"; -import * as Type from "rescript/lib/es6/Type.js"; -import * as $$Array from "rescript/lib/es6/Array.js"; -import * as $$Error from "rescript/lib/es6/Error.js"; -import * as Float from "rescript/lib/es6/Float.js"; -import * as Mocha from "mocha"; -import * as Option from "rescript/lib/es6/Option.js"; -import * as Result from "rescript/lib/es6/Result.js"; -import * as $$String from "rescript/lib/es6/String.js"; -import * as Belt_Id from "rescript/lib/es6/Belt_Id.js"; -import * as $$Promise from "rescript/lib/es6/Promise.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 $$Iterator from "rescript/lib/es6/Iterator.js"; -import * as Nullable from "rescript/lib/es6/Nullable.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 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 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 $$AsyncIterator from "rescript/lib/es6/AsyncIterator.js"; -import * as Primitive_int from "rescript/lib/es6/Primitive_int.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 Belt_MutableSet from "rescript/lib/es6/Belt_MutableSet.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"; - -Mocha.describe("Array.at", () => { - Mocha.test("Array.at", () => { - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(0), "a"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(2), "c"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(3), undefined); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-1), "c"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-3), "a"); - Pervasives.assertEqual([ - "a", - "b", - "c" - ].at(-4), undefined); - }); -}); - -Mocha.describe("Array.concat", () => { - Mocha.test("Array.concat", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = [ - "yay", - "wehoo" - ]; - let someArray = array1.concat(array2); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" - ]); - }); -}); - -Mocha.describe("Array.concatMany", () => { - Mocha.test("Array.concatMany", () => { - let array1 = [ - "hi", - "hello" - ]; - let array2 = ["yay"]; - let array3 = ["wehoo"]; - let someArray = array1.concat(array2, array3); - console.log(someArray); - }); -}); - -Mocha.describe("Array.copy", () => { - Mocha.test("Array.copy", () => { - let myArray = [ - 1, - 2, - 3 - ]; - let copyOfMyArray = myArray.slice(); - Pervasives.assertEqual(copyOfMyArray, [ - 1, - 2, - 3 - ]); - Pervasives.assertEqual(myArray === copyOfMyArray, false); - }); -}); - -Mocha.describe("Array.every", () => { - Mocha.test("Array.every", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Pervasives.assertEqual(array.every(num => num <= 4), true); - Pervasives.assertEqual(array.every(num => num === 1), false); - }); -}); - -Mocha.describe("Array.everyWithIndex", () => { - Mocha.test("Array.everyWithIndex", () => { - let array = [ - 1, - 2, - 3, - 4 - ]; - Pervasives.assertEqual(array.every((num, index) => { - if (index < 5) { - return num <= 4; - } else { - return false; - } - }), true); - Pervasives.assertEqual(array.every((num, index) => { - if (index < 2) { - return num >= 2; - } else { - return false; - } - }), false); - }); -}); - -Mocha.describe("Array.fill", () => { - Mocha.test("Array.fill", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1, 3); - Pervasives.assertEqual(myArray, [ - 1, - 9, - 9, - 4 - ]); - }); -}); - -Mocha.describe("Array.fillAll", () => { - Mocha.test("Array.fillAll", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9); - Pervasives.assertEqual(myArray, [ - 9, - 9, - 9, - 9 - ]); - }); -}); - -Mocha.describe("Array.fillToEnd", () => { - Mocha.test("Array.fillToEnd", () => { - let myArray = [ - 1, - 2, - 3, - 4 - ]; - myArray.fill(9, 1); - Pervasives.assertEqual(myArray, [ - 1, - 9, - 9, - 9 - ]); - }); -}); - -Mocha.describe("Array.filter", () => { - Mocha.test("Array.filter", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].filter(num => num > 2), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Array.filterMap", () => { - Mocha.test("Array.filterMap", () => { - Pervasives.assertEqual($$Array.filterMap([ - "Hello", - "Hi", - "Good bye" - ], item => { - if (item === "Hello") { - return item.length; - } - - }), [5]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - }), [ - 4, - 16, - 36 - ]); - Pervasives.assertEqual($$Array.filterMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), []); - Pervasives.assertEqual($$Array.filterMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - }), []); - }); -}); - -Mocha.describe("Array.filterWithIndex", () => { - Mocha.test("Array.filterWithIndex", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].filter((num, index) => { - if (index === 0) { - return true; - } else { - return num === 2; - } - }), [ - 1, - 2 - ]); - }); -}); - -Mocha.describe("Array.find", () => { - Mocha.test("Array.find", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.find(item => item === "ReScript"), "ReScript"); - }); -}); - -Mocha.describe("Array.findIndex", () => { - Mocha.test("Array.findIndex", () => { - let array = [ - "ReScript", - "JavaScript" - ]; - Pervasives.assertEqual(array.findIndex(item => item === "ReScript"), 0); - Pervasives.assertEqual(array.findIndex(item => item === "TypeScript"), -1); - }); -}); - -Mocha.describe("Array.findIndexOpt", () => { - Mocha.test("Array.findIndexOpt", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.assertEqual($$Array.findIndexOpt(array, item => item === "ReScript"), 0); - }); -}); - -Mocha.describe("Array.findIndexWithIndex", () => { - Mocha.test("Array.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; - } - }); - Pervasives.assertEqual(isReScriptFirst, 0); - Pervasives.assertEqual(isTypeScriptFirst, -1); - }); -}); - -Mocha.describe("Array.findMap", () => { - Mocha.test("Array.findMap", () => { - Pervasives.assertEqual($$Array.findMap([ - 1, - 2, - 3 - ], n => { - if (n % 2 === 0) { - return n - 2 | 0; - } - - }), 0); - Pervasives.assertEqual($$Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], n => { - if (n % 2 === 0) { - return n - 8 | 0; - } - - }), -6); - Pervasives.assertEqual($$Array.findMap([ - 1, - 2, - 3, - 4, - 5, - 6 - ], param => {}), undefined); - Pervasives.assertEqual($$Array.findMap([], n => { - if (n % 2 === 0) { - return Math.imul(n, n); - } - - }), undefined); - }); -}); - -Mocha.describe("Array.findWithIndex", () => { - Mocha.test("Array.findWithIndex", () => { - let array = [ - "TypeScript", - "JavaScript", - "ReScript" - ]; - Pervasives.assertEqual(array.find((item, index) => { - if (index > 1) { - return item === "ReScript"; - } else { - return false; - } - }), "ReScript"); - }); -}); - -Mocha.describe("Array.flat", () => { - Mocha.test("Array.flat", () => { - Pervasives.assertEqual([ - [1], - [2], - [ - 3, - 4 - ] - ].flat(), [ - 1, - 2, - 3, - 4 - ]); - }); -}); - -Mocha.describe("Array.flatMap", () => { - Mocha.test("Array.flatMap", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.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.describe("Array.flatMapWithIndex", () => { - Mocha.test("Array.flatMapWithIndex", () => { - let array = [ - "ReScript", - "TypeScript", - "JavaScript" - ]; - Pervasives.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.describe("Array.forEach", () => { - Mocha.test("Array.forEach", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach(item => { - console.log(item); - }); - }); -}); - -Mocha.describe("Array.forEachWithIndex", () => { - Mocha.test("Array.forEachWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array.forEach((item, index) => { - console.log("At item " + index.toString() + ": " + item); - }); - }); -}); - -Mocha.describe("Array.fromInitializer", () => { - Mocha.test("Array.fromInitializer", () => { - Pervasives.assertEqual($$Array.fromInitializer(3, i => i + 3 | 0), [ - 3, - 4, - 5 - ]); - Pervasives.assertEqual($$Array.fromInitializer(7, i => i + 3 | 0), [ - 3, - 4, - 5, - 6, - 7, - 8, - 9 - ]); - }); -}); - -Mocha.describe("Array.fromIterator", () => { - Mocha.test("Array.fromIterator", () => { - Pervasives.assertEqual(Array.from(new Map([ - [ - "foo", - 1 - ], - [ - "bar", - 2 - ] - ]).values()), [ - 1, - 2 - ]); - }); -}); - -Mocha.describe("Array.get", () => { - Mocha.test("Array.get", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array[0], "Hello"); - Pervasives.assertEqual(array[3], undefined); - }); -}); - -Mocha.describe("Array.getUnsafe", () => { - Mocha.test("Array.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.describe("Array.includes", () => { - Mocha.test("Array.includes", () => { - Pervasives.assertEqual([ - 1, - 2 - ].includes(1), true); - Pervasives.assertEqual([ - 1, - 2 - ].includes(3), false); - Pervasives.assertEqual([{ - language: "ReScript" - }].includes({ - language: "ReScript" - }), false); - }); -}); - -Mocha.describe("Array.indexOf", () => { - Mocha.test("Array.indexOf", () => { - Pervasives.assertEqual([ - 1, - 2 - ].indexOf(2), 1); - Pervasives.assertEqual([ - 1, - 2 - ].indexOf(3), -1); - Pervasives.assertEqual([{ - language: "ReScript" - }].indexOf({ - language: "ReScript" - }), -1); - }); -}); - -Mocha.describe("Array.indexOfOpt", () => { - Mocha.test("Array.indexOfOpt", () => { - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 2), 1); - Pervasives.assertEqual($$Array.indexOfOpt([ - 1, - 2 - ], 3), undefined); - Pervasives.assertEqual($$Array.indexOfOpt([{ - language: "ReScript" - }], { - language: "ReScript" - }), undefined); - }); -}); - -Mocha.describe("Array.join", () => { - Mocha.test("Array.join", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); - }); -}); - -Mocha.describe("Array.joinUnsafe", () => { - Mocha.test("Array.joinUnsafe", () => { - Pervasives.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); -}); - -Mocha.describe("Array.joinWith", () => { - Mocha.test("Array.joinWith", () => { - Pervasives.assertEqual([ - "One", - "Two", - "Three" - ].join(" -- "), "One -- Two -- Three"); - }); -}); - -Mocha.describe("Array.joinWithUnsafe", () => { - Mocha.test("Array.joinWithUnsafe", () => { - Pervasives.assertEqual([ - 1, - 2, - 3 - ].join(" -- "), "1 -- 2 -- 3"); - }); -}); - -Mocha.describe("Array.keepSome", () => { - Mocha.test("Array.keepSome", () => { - Pervasives.assertEqual($$Array.keepSome([ - 1, - undefined, - 3 - ]), [ - 1, - 3 - ]); - Pervasives.assertEqual($$Array.keepSome([ - 1, - 2, - 3 - ]), [ - 1, - 2, - 3 - ]); - Pervasives.assertEqual($$Array.keepSome([ - undefined, - undefined, - undefined - ]), []); - Pervasives.assertEqual($$Array.keepSome([]), []); - }); -}); - -Mocha.describe("Array.last", () => { - Mocha.test("Array.last", () => { - Pervasives.assertEqual($$Array.last([ - "Hello", - "Hi", - "Good bye" - ]), "Good bye"); - Pervasives.assertEqual($$Array.last([]), undefined); - }); -}); - -Mocha.describe("Array.length", () => { - Mocha.test("Array.length", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.length, 2); - }); -}); - -Mocha.describe("Array.make", () => { - Mocha.test("Array.make", () => { - Pervasives.assertEqual($$Array.make(3, "apple"), [ - "apple", - "apple", - "apple" - ]); - Pervasives.assertEqual($$Array.make(6, 7), [ - 7, - 7, - 7, - 7, - 7, - 7 - ]); - }); -}); - -Mocha.describe("Array.map", () => { - Mocha.test("Array.map", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map(greeting => greeting + " to you"); - Pervasives.assertEqual(mappedArray, [ - "Hello to you", - "Hi to you", - "Good bye to you" - ]); - }); -}); - -Mocha.describe("Array.mapWithIndex", () => { - Mocha.test("Array.mapWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let mappedArray = array.map((greeting, index) => greeting + " at position " + index.toString()); - Pervasives.assertEqual(mappedArray, [ - "Hello at position 0", - "Hi at position 1", - "Good bye at position 2" - ]); - }); -}); - -Mocha.describe("Array.pop", () => { - Mocha.test("Array.pop", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.pop(), "hello"); - Pervasives.assertEqual(someArray, ["hi"]); - }); -}); - -Mocha.describe("Array.push", () => { - Mocha.test("Array.push", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay" - ]); - }); -}); - -Mocha.describe("Array.pushMany", () => { - Mocha.test("Array.pushMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.push("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "hi", - "hello", - "yay", - "wehoo" - ]); - }); -}); - -Mocha.describe("Array.reduce", () => { - Mocha.test("Array.reduce", () => { - Pervasives.assertEqual($$Array.reduce([ - 2, - 3, - 4 - ], 1, (a, b) => a + b | 0), 10); - Pervasives.assertEqual($$Array.reduce([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "abcd"); - Pervasives.assertEqual($$Array.reduce([ - 1, - 2, - 3 - ], /* [] */0, List.add), { - hd: 3, - tl: { - hd: 2, - tl: { - hd: 1, - tl: /* [] */0 - } - } - }); - Pervasives.assertEqual($$Array.reduce([], /* [] */0, List.add), /* [] */0); - }); -}); - -Mocha.describe("Array.reduceRight", () => { - Mocha.test("Array.reduceRight", () => { - Pervasives.assertEqual($$Array.reduceRight([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b), "dcba"); - Pervasives.assertEqual($$Array.reduceRight([ - 1, - 2, - 3 - ], /* [] */0, List.add), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Pervasives.assertEqual($$Array.reduceRight([], /* [] */0, List.add), /* [] */0); - }); -}); - -Mocha.describe("Array.reduceRightWithIndex", () => { - Mocha.test("Array.reduceRightWithIndex", () => { - Pervasives.assertEqual($$Array.reduceRightWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$Array.reduceRightWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); -}); - -Mocha.describe("Array.reduceWithIndex", () => { - Mocha.test("Array.reduceWithIndex", () => { - Pervasives.assertEqual($$Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0), 16); - Pervasives.assertEqual($$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 - } - } - }); - Pervasives.assertEqual($$Array.reduceWithIndex([], /* [] */0, (acc, v, i) => ({ - hd: v + i | 0, - tl: acc - })), /* [] */0); - }); -}); - -Mocha.describe("Array.reverse", () => { - Mocha.test("Array.reverse", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.reverse(); - Pervasives.assertEqual(someArray, [ - "hello", - "hi" - ]); - }); -}); - -Mocha.describe("Array.set", () => { - Mocha.test("Array.set", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); - }); -}); - -Mocha.describe("Array.setUnsafe", () => { - Mocha.test("Array.setUnsafe", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - array[1] = "Hello"; - Pervasives.assertEqual(array[1], "Hello"); - }); -}); - -Mocha.describe("Array.shift", () => { - Mocha.test("Array.shift", () => { - let someArray = [ - "hi", - "hello" - ]; - Pervasives.assertEqual(someArray.shift(), "hi"); - Pervasives.assertEqual(someArray, ["hello"]); - }); -}); - -Mocha.describe("Array.shuffle", () => { - Mocha.test("Array.shuffle", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - $$Array.shuffle(array); - console.log(array); - let array2 = [ - 1, - 2, - 3 - ]; - $$Array.shuffle(array2); - Pervasives.assertEqual(array2.length, 3); - }); -}); - -Mocha.describe("Array.slice", () => { - Mocha.test("Array.slice", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1, 3), [ - 2, - 3 - ]); - }); -}); - -Mocha.describe("Array.sliceToEnd", () => { - Mocha.test("Array.sliceToEnd", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].slice(1), [ - 2, - 3, - 4 - ]); - }); -}); - -Mocha.describe("Array.some", () => { - Mocha.test("Array.some", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some(greeting => greeting === "Hello"), true); - }); -}); - -Mocha.describe("Array.someWithIndex", () => { - Mocha.test("Array.someWithIndex", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - Pervasives.assertEqual(array.some((greeting, index) => { - if (greeting === "Hello") { - return index === 0; - } else { - return false; - } - }), true); - }); -}); - -Mocha.describe("Array.sort", () => { - Mocha.test("Array.sort", () => { - let array = [ - 3, - 2, - 1 - ]; - array.sort((a, b) => a - b | 0); - Pervasives.assertEqual(array, [ - 1, - 2, - 3 - ]); - }); -}); - -Mocha.describe("Array.toShuffled", () => { - Mocha.test("Array.toShuffled", () => { - let array = [ - "Hello", - "Hi", - "Good bye" - ]; - let shuffledArray = $$Array.toShuffled(array); - console.log(shuffledArray); - Pervasives.assertEqual($$Array.toShuffled([ - 1, - 2, - 3 - ]).length, 3); - }); -}); - -Mocha.describe("Array.toString", () => { - Mocha.test("Array.toString", () => { - Pervasives.assertEqual([ - 1, - 2, - 3, - 4 - ].toString(), "1,2,3,4"); - }); -}); - -Mocha.describe("Array.unsafe_get", () => { - Mocha.test("Array.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.describe("Array.unshift", () => { - Mocha.test("Array.unshift", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay"); - Pervasives.assertEqual(someArray, [ - "yay", - "hi", - "hello" - ]); - }); -}); - -Mocha.describe("Array.unshiftMany", () => { - Mocha.test("Array.unshiftMany", () => { - let someArray = [ - "hi", - "hello" - ]; - someArray.unshift("yay", "wehoo"); - Pervasives.assertEqual(someArray, [ - "yay", - "wehoo", - "hi", - "hello" - ]); - }); -}); - -Mocha.describe("AsyncIterator.done", () => { - Mocha.test("AsyncIterator.done", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); - } - }); - }); -}); - -Mocha.describe("AsyncIterator.forEach", () => { - Mocha.test("AsyncIterator.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 $$AsyncIterator.forEach(asyncIterator, v => { - if (v !== undefined && v[0] === "second") { - return Pervasives.assertEqual(v[1], "2"); - } - - }); - main(); - }); -}); - -Mocha.describe("AsyncIterator.make", () => { - Mocha.test("AsyncIterator.make", () => { - let context = { - contents: 0 - }; - let asyncIterator = $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - return { - done: currentValue >= 3, - value: currentValue - }; - }); - let main = async () => await $$AsyncIterator.forEach(asyncIterator, value => { - if (value !== undefined) { - console.log(value); - return; - } - - }); - main(); - }); -}); - -Mocha.describe("AsyncIterator.next", () => { - Mocha.test("AsyncIterator.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) { - Pervasives.assertEqual(Option.isNone(match.value), true); - } - - }; - }; - processMyAsyncIterator(); - }); -}); - -Mocha.describe("AsyncIterator.value", () => { - Mocha.test("AsyncIterator.value", () => { - let context = { - contents: 0 - }; - $$AsyncIterator.make(async () => { - let currentValue = context.contents; - context.contents = currentValue + 1 | 0; - if (currentValue >= 3) { - return $$AsyncIterator.done(undefined); - } else { - return $$AsyncIterator.value(currentValue); - } - }); - }); -}); - -Mocha.describe("Belt.Array.blit", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.cmp", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.concat", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.concatMany", () => { - Mocha.test("Belt.Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt.Array.eq", () => { - Mocha.test("Belt.Array.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt.Array.every", () => { - Mocha.test("Belt.Array.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt.Array.every2", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.fill", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.flatMap", () => { - Mocha.test("Belt.Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt.Array.forEach", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.forEachWithIndex", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.get", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.getBy", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.getIndexBy", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.joinWith", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.keepMap", () => { - Mocha.test("Belt.Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt.Array.keepWithIndex", () => { - Mocha.test("Belt.Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt.Array.length", () => { - Mocha.test("Belt.Array.length", () => {}); -}); - -Mocha.describe("Belt.Array.makeBy", () => { - Mocha.test("Belt.Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt.Array.makeUninitialized", () => { - Mocha.test("Belt.Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt.Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.map", () => { - Mocha.test("Belt.Array.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt.Array.mapWithIndex", () => { - Mocha.test("Belt.Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Array.partition", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.range", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.rangeBy", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.reduce", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.reduceReverse", () => { - Mocha.test("Belt.Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt.Array.reduceReverse2", () => { - Mocha.test("Belt.Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt.Array.reduceWithIndex", () => { - Mocha.test("Belt.Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt.Array.reverse", () => { - Mocha.test("Belt.Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt.Array.reverseInPlace", () => { - Mocha.test("Belt.Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt.Array.slice", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.sliceToEnd", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.some", () => { - Mocha.test("Belt.Array.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt.Array.some2", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.truncateToLengthUnsafe", () => { - Mocha.test("Belt.Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt.Array.unzip", () => { - Mocha.test("Belt.Array.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.describe("Belt.Array.zip", () => { - Mocha.test("Belt.Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt.Array.zipBy", () => { - Mocha.test("Belt.Array.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("Belt.Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); - }); -}); - -Mocha.describe("Belt.Float.+", () => { - Mocha.test("Belt.Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); - }); -}); - -Mocha.describe("Belt.Float.-", () => { - Mocha.test("Belt.Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); - }); -}); - -Mocha.describe("Belt.Float./", () => { - Mocha.test("Belt.Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); - }); -}); - -Mocha.describe("Belt.Float.fromInt", () => { - Mocha.test("Belt.Float.fromInt", () => { - console.log(1 === 1.0); - }); -}); - -Mocha.describe("Belt.Float.fromString", () => { - Mocha.test("Belt.Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); - }); -}); - -Mocha.describe("Belt.Float.toInt", () => { - Mocha.test("Belt.Float.toInt", () => { - console.log(true); - }); -}); - -Mocha.describe("Belt.Float.toString", () => { - Mocha.test("Belt.Float.toString", () => { - console.log(String(1.0) === "1.0"); - }); -}); - -Mocha.describe("Belt.HashMap", () => { - Mocha.test("Belt.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.describe("Belt.HashMap.clear", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.copy", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.forEach", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.fromArray", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.get", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.getBucketHistogram", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.has", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.isEmpty", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.keepMapInPlace", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.keysToArray", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.logStats", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.make", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.mergeMany", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.reduce", () => { - Mocha.test("Belt.HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); - }); -}); - -Mocha.describe("Belt.HashMap.remove", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.set", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.size", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.toArray", () => { - Mocha.test("Belt.HashMap.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.describe("Belt.HashMap.valuesToArray", () => { - Mocha.test("Belt.HashMap.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.HashSet", () => { - Mocha.test("Belt.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.describe("Belt.Int.*", () => { - Mocha.test("Belt.Int.*", () => { - Pervasives.assertEqual(4, 4); - }); -}); - -Mocha.describe("Belt.Int.+", () => { - Mocha.test("Belt.Int.+", () => { - Pervasives.assertEqual(4, 4); - }); -}); - -Mocha.describe("Belt.Int.-", () => { - Mocha.test("Belt.Int.-", () => { - Pervasives.assertEqual(1, 1); - }); -}); - -Mocha.describe("Belt.Int./", () => { - Mocha.test("Belt.Int./", () => { - Pervasives.assertEqual(2, 2); - }); -}); - -Mocha.describe("Belt.Int.fromFloat", () => { - Mocha.test("Belt.Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); - }); -}); - -Mocha.describe("Belt.Int.fromString", () => { - Mocha.test("Belt.Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); - }); -}); - -Mocha.describe("Belt.Int.toFloat", () => { - Mocha.test("Belt.Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); - }); -}); - -Mocha.describe("Belt.Int.toString", () => { - Mocha.test("Belt.Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); - }); -}); - -Mocha.describe("Belt.List.add", () => { - Mocha.test("Belt.List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); -}); - -Mocha.describe("Belt.List.cmp", () => { - Mocha.test("Belt.List.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.describe("Belt.List.cmpByLength", () => { - Mocha.test("Belt.List.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.describe("Belt.List.concat", () => { - Mocha.test("Belt.List.concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("Belt.List.concatMany", () => { - Mocha.test("Belt.List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); -}); - -Mocha.describe("Belt.List.drop", () => { - Mocha.test("Belt.List.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.describe("Belt.List.eq", () => { - Mocha.test("Belt.List.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.describe("Belt.List.every", () => { - Mocha.test("Belt.List.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.describe("Belt.List.every2", () => { - Mocha.test("Belt.List.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.describe("Belt.List.filter", () => { - Mocha.test("Belt.List.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.describe("Belt.List.filterWithIndex", () => { - Mocha.test("Belt.List.filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("Belt.List.flatten", () => { - Mocha.test("Belt.List.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.describe("Belt.List.forEach", () => { - Mocha.test("Belt.List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); -}); - -Mocha.describe("Belt.List.forEach2", () => { - Mocha.test("Belt.List.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.describe("Belt.List.forEachWithIndex", () => { - Mocha.test("Belt.List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); - }); -}); - -Mocha.describe("Belt.List.fromArray", () => { - Mocha.test("Belt.List.fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 - ]); - }); -}); - -Mocha.describe("Belt.List.get", () => { - Mocha.test("Belt.List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); - }); -}); - -Mocha.describe("Belt.List.getAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt.List.getBy", () => { - Mocha.test("Belt.List.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.describe("Belt.List.getExn", () => { - Mocha.test("Belt.List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.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", - 2266, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.List.has", () => { - Mocha.test("Belt.List.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.describe("Belt.List.hasAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt.List.head", () => { - Mocha.test("Belt.List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.headExn", () => { - Mocha.test("Belt.List.headExn", () => { - Pervasives.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", - 2315, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.List.keep", () => { - Mocha.test("Belt.List.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.describe("Belt.List.keepMap", () => { - Mocha.test("Belt.List.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.describe("Belt.List.keepWithIndex", () => { - Mocha.test("Belt.List.keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("Belt.List.length", () => { - Mocha.test("Belt.List.length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.make", () => { - Mocha.test("Belt.List.make", () => { - Belt_List.make(3, 1); - }); -}); - -Mocha.describe("Belt.List.makeBy", () => { - Mocha.test("Belt.List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); - }); -}); - -Mocha.describe("Belt.List.map", () => { - Mocha.test("Belt.List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); -}); - -Mocha.describe("Belt.List.mapReverse", () => { - Mocha.test("Belt.List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.mapReverse2", () => { - Mocha.test("Belt.List.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.describe("Belt.List.mapWithIndex", () => { - Mocha.test("Belt.List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); - }); -}); - -Mocha.describe("Belt.List.partition", () => { - Mocha.test("Belt.List.partition", () => { - Pervasives.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.describe("Belt.List.reduce", () => { - Mocha.test("Belt.List.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.describe("Belt.List.reduce2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("Belt.List.reduceReverse", () => { - Mocha.test("Belt.List.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.describe("Belt.List.reduceReverse2", () => { - Mocha.test("Belt.List.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 + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("Belt.List.reduceWithIndex", () => { - Mocha.test("Belt.List.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.describe("Belt.List.removeAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt.List.reverse", () => { - Mocha.test("Belt.List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.reverseConcat", () => { - Mocha.test("Belt.List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("Belt.List.setAssoc", () => { - Mocha.test("Belt.List.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.describe("Belt.List.shuffle", () => { - Mocha.test("Belt.List.shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.some", () => { - Mocha.test("Belt.List.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.describe("Belt.List.some2", () => { - Mocha.test("Belt.List.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.describe("Belt.List.sort", () => { - Mocha.test("Belt.List.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.describe("Belt.List.splitAt", () => { - Mocha.test("Belt.List.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.describe("Belt.List.tail", () => { - Mocha.test("Belt.List.tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); - }); -}); - -Mocha.describe("Belt.List.tailExn", () => { - Mocha.test("Belt.List.tailExn", () => { - Pervasives.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", - 2619, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.List.take", () => { - Mocha.test("Belt.List.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.describe("Belt.List.toArray", () => { - Mocha.test("Belt.List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.unzip", () => { - Mocha.test("Belt.List.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.describe("Belt.List.zip", () => { - Mocha.test("Belt.List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt.List.zipBy", () => { - Mocha.test("Belt.List.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.Dict.findFirstBy", () => { - Mocha.test("Belt.Map.Dict.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("Belt.Map.Int", () => {}); -}); - -Mocha.describe("Belt.Map.Int.findFirstBy", () => { - Mocha.test("Belt.Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt.Map.String.findFirstBy", () => { - Mocha.test("Belt.Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt.Map.findFirstBy", () => { - Mocha.test("Belt.Map.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); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt.Map.forEach", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.fromArray", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.get", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.has", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.isEmpty", () => { - Mocha.test("Belt.Map.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; - }); -}); - -Mocha.describe("Belt.Map.keysToArray", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.make", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.reduce", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.remove", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.set", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.size", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.toArray", () => { - Mocha.test("Belt.Map.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.describe("Belt.Map.valuesToArray", () => { - Mocha.test("Belt.Map.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.MutableSet", () => { - Mocha.test("Belt.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.describe("Belt.MutableSet.add", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.copy", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.diff", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.eq", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.every", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.forEach", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.fromArray", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.get", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.has", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.intersect", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.isEmpty", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.keep", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.maxUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.maximum", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.mergeMany", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.minUndefined", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.minimum", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.partition", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.reduce", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.remove", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.removeMany", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.size", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.some", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.split", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.subset", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.toArray", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.toList", () => { - Mocha.test("Belt.MutableSet.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.describe("Belt.MutableSet.union", () => { - Mocha.test("Belt.MutableSet.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("Belt.Option", () => {}); -}); - -Mocha.describe("Belt.Option.cmp", () => { - Mocha.test("Belt.Option.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.describe("Belt.Option.eq", () => { - Mocha.test("Belt.Option.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.describe("Belt.Option.flatMap", () => { - Mocha.test("Belt.Option.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.describe("Belt.Option.forEach", () => { - Mocha.test("Belt.Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Belt.Option.getExn", () => { - Mocha.test("Belt.Option.getExn", () => { - Pervasives.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", - 3572, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.Option.getWithDefault", () => { - Mocha.test("Belt.Option.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.describe("Belt.Option.isNone", () => { - Mocha.test("Belt.Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); - }); -}); - -Mocha.describe("Belt.Option.isSome", () => { - Mocha.test("Belt.Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); - }); -}); - -Mocha.describe("Belt.Option.keep", () => { - Mocha.test("Belt.Option.keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); - }); -}); - -Mocha.describe("Belt.Option.map", () => { - Mocha.test("Belt.Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Belt.Option.mapWithDefault", () => { - Mocha.test("Belt.Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Belt.Option.orElse", () => { - Mocha.test("Belt.Option.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.every", () => { - Mocha.test("Belt.Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); -}); - -Mocha.describe("Belt.Range.everyBy", () => { - Mocha.test("Belt.Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt.Range.forEach", () => { - Mocha.test("Belt.Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); -}); - -Mocha.describe("Belt.Range.some", () => { - Mocha.test("Belt.Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); -}); - -Mocha.describe("Belt.Range.someBy", () => { - Mocha.test("Belt.Range.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.cmp", () => { - Mocha.test("Belt.Result.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.describe("Belt.Result.eq", () => { - Mocha.test("Belt.Result.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.describe("Belt.Result.flatMap", () => { - Mocha.test("Belt.Result.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.describe("Belt.Result.getExn", () => { - Mocha.test("Belt.Result.getExn", () => { - Pervasives.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", - 3806, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt.Result.getWithDefault", () => { - Mocha.test("Belt.Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); -}); - -Mocha.describe("Belt.Result.map", () => { - Mocha.test("Belt.Result.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.describe("Belt.Result.mapWithDefault", () => { - Mocha.test("Belt.Result.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("Belt.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.Set.Dict.add", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.diff", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.empty", () => { - Mocha.test("Belt.Set.Dict.empty", () => {}); -}); - -Mocha.describe("Belt.Set.Dict.eq", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.every", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.forEach", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.fromArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.get", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.has", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.intersect", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.isEmpty", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.keep", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.maxUndefined", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.maximum", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.mergeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.minUndefined", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.minimum", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.partition", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.reduce", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.remove", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.removeMany", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.size", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.some", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.split", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.subset", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.toArray", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.toList", () => { - Mocha.test("Belt.Set.Dict.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.describe("Belt.Set.Dict.union", () => { - Mocha.test("Belt.Set.Dict.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.Set.add", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); - }); -}); - -Mocha.describe("Belt.Set.diff", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); - }); -}); - -Mocha.describe("Belt.Set.eq", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); - }); -}); - -Mocha.describe("Belt.Set.every", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); - }); -}); - -Mocha.describe("Belt.Set.forEach", () => { - Mocha.test("Belt.Set.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); - }); - Pervasives.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt.Set.fromArray", () => { - Mocha.test("Belt.Set.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt.Set.get", () => { - Mocha.test("Belt.Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); - }); -}); - -Mocha.describe("Belt.Set.has", () => { - Mocha.test("Belt.Set.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); - }); -}); - -Mocha.describe("Belt.Set.intersect", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Set.isEmpty", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); - }); -}); - -Mocha.describe("Belt.Set.keep", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 4 - ]); - }); -}); - -Mocha.describe("Belt.Set.make", () => { - Mocha.test("Belt.Set.make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); - }); -}); - -Mocha.describe("Belt.Set.maxUndefined", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); - }); -}); - -Mocha.describe("Belt.Set.maximum", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); - }); -}); - -Mocha.describe("Belt.Set.mergeMany", () => { - Mocha.test("Belt.Set.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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ - 1, - 2, - 3, - 4, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Set.minUndefined", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); - }); -}); - -Mocha.describe("Belt.Set.minimum", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); - }); -}); - -Mocha.describe("Belt.Set.partition", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); - }); -}); - -Mocha.describe("Belt.Set.reduce", () => { - Mocha.test("Belt.Set.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt.Set.remove", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Pervasives.assertEqual(s2, s3); - }); -}); - -Mocha.describe("Belt.Set.removeMany", () => { - Mocha.test("Belt.Set.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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); - }); -}); - -Mocha.describe("Belt.Set.size", () => { - Mocha.test("Belt.Set.size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); - }); -}); - -Mocha.describe("Belt.Set.some", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); - }); -}); - -Mocha.describe("Belt.Set.split", () => { - Mocha.test("Belt.Set.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]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Set.subset", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); - }); -}); - -Mocha.describe("Belt.Set.toArray", () => { - Mocha.test("Belt.Set.toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt.Set.toList", () => { - Mocha.test("Belt.Set.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt.Set.union", () => { - Mocha.test("Belt.Set.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); - Pervasives.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, - 3, - 4, - 5, - 6 - ]); - }); -}); - -Mocha.describe("Belt.SortArray.binarySearchBy", () => { - Mocha.test("Belt.SortArray.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.describe("Belt.SortArray.strictlySortedLength", () => { - Mocha.test("Belt.SortArray.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.blit", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.cmp", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.concat", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.concatMany", () => { - Mocha.test("Belt_Array.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt_Array.eq", () => { - Mocha.test("Belt_Array.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt_Array.every", () => { - Mocha.test("Belt_Array.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_Array.every2", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.fill", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.flatMap", () => { - Mocha.test("Belt_Array.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_Array.forEach", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.forEachWithIndex", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.get", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.getBy", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.getIndexBy", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.joinWith", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.keepMap", () => { - Mocha.test("Belt_Array.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_Array.keepWithIndex", () => { - Mocha.test("Belt_Array.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt_Array.length", () => { - Mocha.test("Belt_Array.length", () => {}); -}); - -Mocha.describe("Belt_Array.makeBy", () => { - Mocha.test("Belt_Array.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt_Array.makeUninitialized", () => { - Mocha.test("Belt_Array.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt_Array.makeUninitializedUnsafe", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.map", () => { - Mocha.test("Belt_Array.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_Array.mapWithIndex", () => { - Mocha.test("Belt_Array.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_Array.partition", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.range", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.rangeBy", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.reduce", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.reduceReverse", () => { - Mocha.test("Belt_Array.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_Array.reduceReverse2", () => { - Mocha.test("Belt_Array.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_Array.reduceWithIndex", () => { - Mocha.test("Belt_Array.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_Array.reverse", () => { - Mocha.test("Belt_Array.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_Array.reverseInPlace", () => { - Mocha.test("Belt_Array.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_Array.slice", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.sliceToEnd", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.some", () => { - Mocha.test("Belt_Array.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_Array.some2", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.truncateToLengthUnsafe", () => { - Mocha.test("Belt_Array.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt_Array.unzip", () => { - Mocha.test("Belt_Array.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.describe("Belt_Array.zip", () => { - Mocha.test("Belt_Array.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_Array.zipBy", () => { - Mocha.test("Belt_Array.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("Belt_Float.*", () => { - Pervasives.assertEqual(2.0 * 2.0, 4.0); - }); -}); - -Mocha.describe("Belt_Float.+", () => { - Mocha.test("Belt_Float.+", () => { - Pervasives.assertEqual(2.0 + 2.0, 4.0); - }); -}); - -Mocha.describe("Belt_Float.-", () => { - Mocha.test("Belt_Float.-", () => { - Pervasives.assertEqual(2.0 - 1.0, 1.0); - }); -}); - -Mocha.describe("Belt_Float./", () => { - Mocha.test("Belt_Float./", () => { - Pervasives.assertEqual(4.0 / 2.0, 2.0); - }); -}); - -Mocha.describe("Belt_Float.fromInt", () => { - Mocha.test("Belt_Float.fromInt", () => { - console.log(1 === 1.0); - }); -}); - -Mocha.describe("Belt_Float.fromString", () => { - Mocha.test("Belt_Float.fromString", () => { - console.log(Belt_Float.fromString("1.0") === 1.0); - }); -}); - -Mocha.describe("Belt_Float.toInt", () => { - Mocha.test("Belt_Float.toInt", () => { - console.log(true); - }); -}); - -Mocha.describe("Belt_Float.toString", () => { - Mocha.test("Belt_Float.toString", () => { - console.log(String(1.0) === "1.0"); - }); -}); - -Mocha.describe("Belt_HashMap.clear", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.copy", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.forEach", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.fromArray", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.get", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.getBucketHistogram", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.has", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.isEmpty", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.keepMapInPlace", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.keysToArray", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.logStats", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.make", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.mergeMany", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.reduce", () => { - Mocha.test("Belt_HashMap.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"); - Pervasives.assertEqual(Belt_HashMap.reduce(s0, "", (acc, param, value) => acc + (", " + value)), ", value1, value2"); - console.log("lol"); - }); -}); - -Mocha.describe("Belt_HashMap.remove", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.set", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.size", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.toArray", () => { - Mocha.test("Belt_HashMap.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.describe("Belt_HashMap.valuesToArray", () => { - Mocha.test("Belt_HashMap.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("Belt_Int.*", () => { - Pervasives.assertEqual(4, 4); - }); -}); - -Mocha.describe("Belt_Int.+", () => { - Mocha.test("Belt_Int.+", () => { - Pervasives.assertEqual(4, 4); - }); -}); - -Mocha.describe("Belt_Int.-", () => { - Mocha.test("Belt_Int.-", () => { - Pervasives.assertEqual(1, 1); - }); -}); - -Mocha.describe("Belt_Int./", () => { - Mocha.test("Belt_Int./", () => { - Pervasives.assertEqual(2, 2); - }); -}); - -Mocha.describe("Belt_Int.fromFloat", () => { - Mocha.test("Belt_Int.fromFloat", () => { - Pervasives.assertEqual(1, 1); - }); -}); - -Mocha.describe("Belt_Int.fromString", () => { - Mocha.test("Belt_Int.fromString", () => { - Pervasives.assertEqual(Belt_Int.fromString("1"), 1); - }); -}); - -Mocha.describe("Belt_Int.toFloat", () => { - Mocha.test("Belt_Int.toFloat", () => { - Pervasives.assertEqual(1, 1.0); - }); -}); - -Mocha.describe("Belt_Int.toString", () => { - Mocha.test("Belt_Int.toString", () => { - Pervasives.assertEqual(String(1), "1"); - }); -}); - -Mocha.describe("Belt_List.add", () => { - Mocha.test("Belt_List.add", () => { - Belt_List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - Belt_List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); -}); - -Mocha.describe("Belt_List.cmp", () => { - Mocha.test("Belt_List.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.describe("Belt_List.cmpByLength", () => { - Mocha.test("Belt_List.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.describe("Belt_List.concat", () => { - Mocha.test("Belt_List.concat", () => { - Belt_List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("Belt_List.concatMany", () => { - Mocha.test("Belt_List.concatMany", () => { - Belt_List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); -}); - -Mocha.describe("Belt_List.drop", () => { - Mocha.test("Belt_List.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.describe("Belt_List.eq", () => { - Mocha.test("Belt_List.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.describe("Belt_List.every", () => { - Mocha.test("Belt_List.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.describe("Belt_List.every2", () => { - Mocha.test("Belt_List.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.describe("Belt_List.filter", () => { - Mocha.test("Belt_List.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.describe("Belt_List.filterWithIndex", () => { - Mocha.test("Belt_List.filterWithIndex", () => { - Belt_List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("Belt_List.flatten", () => { - Mocha.test("Belt_List.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.describe("Belt_List.forEach", () => { - Mocha.test("Belt_List.forEach", () => { - Belt_List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); -}); - -Mocha.describe("Belt_List.forEach2", () => { - Mocha.test("Belt_List.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.describe("Belt_List.forEachWithIndex", () => { - Mocha.test("Belt_List.forEachWithIndex", () => { - Belt_List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (index, x) => { - console.log("Item " + String(index) + " is " + x); - }); - }); -}); - -Mocha.describe("Belt_List.fromArray", () => { - Mocha.test("Belt_List.fromArray", () => { - Belt_List.fromArray([ - 1, - 2, - 3 - ]); - }); -}); - -Mocha.describe("Belt_List.get", () => { - Mocha.test("Belt_List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Belt_List.get(abc, 1); - Belt_List.get(abc, 4); - }); -}); - -Mocha.describe("Belt_List.getAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.getBy", () => { - Mocha.test("Belt_List.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.describe("Belt_List.getExn", () => { - Mocha.test("Belt_List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.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", - 6148, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_List.has", () => { - Mocha.test("Belt_List.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.describe("Belt_List.hasAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.head", () => { - Mocha.test("Belt_List.head", () => { - Belt_List.head(/* [] */0); - Belt_List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.headExn", () => { - Mocha.test("Belt_List.headExn", () => { - Pervasives.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", - 6197, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_List.keep", () => { - Mocha.test("Belt_List.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.describe("Belt_List.keepMap", () => { - Mocha.test("Belt_List.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.describe("Belt_List.keepWithIndex", () => { - Mocha.test("Belt_List.keepWithIndex", () => { - Belt_List.keepWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("Belt_List.length", () => { - Mocha.test("Belt_List.length", () => { - Belt_List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.make", () => { - Mocha.test("Belt_List.make", () => { - Belt_List.make(3, 1); - }); -}); - -Mocha.describe("Belt_List.makeBy", () => { - Mocha.test("Belt_List.makeBy", () => { - Belt_List.makeBy(5, i => i); - Belt_List.makeBy(5, i => Math.imul(i, i)); - }); -}); - -Mocha.describe("Belt_List.map", () => { - Mocha.test("Belt_List.map", () => { - Belt_List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); -}); - -Mocha.describe("Belt_List.mapReverse", () => { - Mocha.test("Belt_List.mapReverse", () => { - Pervasives.assertEqual(Belt_List.mapReverse({ - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }, x => Math.imul(x, x)), { - hd: 25, - tl: { - hd: 16, - tl: { - hd: 9, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.mapReverse2", () => { - Mocha.test("Belt_List.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.describe("Belt_List.mapWithIndex", () => { - Mocha.test("Belt_List.mapWithIndex", () => { - Belt_List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (index, x) => index + x | 0); - }); -}); - -Mocha.describe("Belt_List.partition", () => { - Mocha.test("Belt_List.partition", () => { - Pervasives.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.describe("Belt_List.reduce", () => { - Mocha.test("Belt_List.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.describe("Belt_List.reduce2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("Belt_List.reduceReverse", () => { - Mocha.test("Belt_List.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.describe("Belt_List.reduceReverse2", () => { - Mocha.test("Belt_List.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 + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("Belt_List.reduceWithIndex", () => { - Mocha.test("Belt_List.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.describe("Belt_List.removeAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.reverse", () => { - Mocha.test("Belt_List.reverse", () => { - Belt_List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.reverseConcat", () => { - Mocha.test("Belt_List.reverseConcat", () => { - Belt_List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("Belt_List.setAssoc", () => { - Mocha.test("Belt_List.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.describe("Belt_List.shuffle", () => { - Mocha.test("Belt_List.shuffle", () => { - Belt_List.shuffle({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.some", () => { - Mocha.test("Belt_List.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.describe("Belt_List.some2", () => { - Mocha.test("Belt_List.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.describe("Belt_List.sort", () => { - Mocha.test("Belt_List.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.describe("Belt_List.splitAt", () => { - Mocha.test("Belt_List.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.describe("Belt_List.tail", () => { - Mocha.test("Belt_List.tail", () => { - Belt_List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - Belt_List.tail(/* [] */0); - }); -}); - -Mocha.describe("Belt_List.tailExn", () => { - Mocha.test("Belt_List.tailExn", () => { - Pervasives.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", - 6501, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_List.take", () => { - Mocha.test("Belt_List.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.describe("Belt_List.toArray", () => { - Mocha.test("Belt_List.toArray", () => { - Belt_List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.unzip", () => { - Mocha.test("Belt_List.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.describe("Belt_List.zip", () => { - Mocha.test("Belt_List.zip", () => { - Belt_List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("Belt_List.zipBy", () => { - Mocha.test("Belt_List.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.Dict.findFirstBy", () => { - Mocha.test("Belt_Map.Dict.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("Belt_Map.Int", () => {}); -}); - -Mocha.describe("Belt_Map.Int.findFirstBy", () => { - Mocha.test("Belt_Map.Int.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt_Map.String.findFirstBy", () => { - Mocha.test("Belt_Map.String.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_Map.findFirstBy", () => { - Mocha.test("Belt_Map.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); - Pervasives.assertEqual(Belt_Map.findFirstBy(s0, (k, param) => k === 4), [ - 4, - "4" - ]); - }); -}); - -Mocha.describe("Belt_Map.forEach", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.fromArray", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.get", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.has", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.isEmpty", () => { - Mocha.test("Belt_Map.isEmpty", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - Belt_Map.isEmpty(Belt_Map.fromArray([[ - 1, - "1" - ]], IntCmp)) === false; - }); -}); - -Mocha.describe("Belt_Map.keysToArray", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.make", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.reduce", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.remove", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.set", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.size", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.toArray", () => { - Mocha.test("Belt_Map.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.describe("Belt_Map.valuesToArray", () => { - Mocha.test("Belt_Map.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_MapDict.findFirstBy", () => { - Mocha.test("Belt_MapDict.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.findFirstBy", () => { - Mocha.test("Belt_MapInt.findFirstBy", () => { - let mapInt = Belt_MapInt.fromArray([ - [ - 1, - "one" - ], - [ - 2, - "two" - ], - [ - 3, - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapInt.findFirstBy(mapInt, (k, v) => { - if (k === 1) { - return v === "one"; - } else { - return false; - } - }), [ - 1, - "one" - ]); - }); -}); - -Mocha.describe("Belt_MapString.findFirstBy", () => { - Mocha.test("Belt_MapString.findFirstBy", () => { - let mapString = Belt_MapString.fromArray([ - [ - "1", - "one" - ], - [ - "2", - "two" - ], - [ - "3", - "three" - ] - ]); - Pervasives.assertEqual(Belt_MapString.findFirstBy(mapString, (k, v) => { - if (k === "1") { - return v === "one"; - } else { - return false; - } - }), [ - "1", - "one" - ]); - }); -}); - -Mocha.describe("Belt_MutableSet.add", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.copy", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.diff", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.eq", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.every", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.forEach", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.fromArray", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.get", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.has", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.intersect", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.isEmpty", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.keep", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.maxUndefined", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.maximum", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.mergeMany", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.minUndefined", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.minimum", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.partition", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.reduce", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.remove", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.removeMany", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.size", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.some", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.split", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.subset", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.toArray", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.toList", () => { - Mocha.test("Belt_MutableSet.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.describe("Belt_MutableSet.union", () => { - Mocha.test("Belt_MutableSet.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.cmp", () => { - Mocha.test("Belt_Option.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.describe("Belt_Option.eq", () => { - Mocha.test("Belt_Option.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.describe("Belt_Option.flatMap", () => { - Mocha.test("Belt_Option.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.describe("Belt_Option.forEach", () => { - Mocha.test("Belt_Option.forEach", () => { - Belt_Option.forEach("thing", x => { - console.log(x); - }); - Belt_Option.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Belt_Option.getExn", () => { - Mocha.test("Belt_Option.getExn", () => { - Pervasives.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", - 7466, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_Option.getWithDefault", () => { - Mocha.test("Belt_Option.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.describe("Belt_Option.isNone", () => { - Mocha.test("Belt_Option.isNone", () => { - Belt_Option.isNone(undefined); - Belt_Option.isNone(1); - }); -}); - -Mocha.describe("Belt_Option.isSome", () => { - Mocha.test("Belt_Option.isSome", () => { - Belt_Option.isSome(undefined); - Belt_Option.isSome(1); - }); -}); - -Mocha.describe("Belt_Option.keep", () => { - Mocha.test("Belt_Option.keep", () => { - Belt_Option.keep(10, x => x > 5); - Belt_Option.keep(4, x => x > 5); - Belt_Option.keep(undefined, x => x > 5); - }); -}); - -Mocha.describe("Belt_Option.map", () => { - Mocha.test("Belt_Option.map", () => { - Belt_Option.map(3, x => Math.imul(x, x)); - Belt_Option.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Belt_Option.mapWithDefault", () => { - Mocha.test("Belt_Option.mapWithDefault", () => { - Belt_Option.mapWithDefault(3, 0, x => x + 5 | 0); - Belt_Option.mapWithDefault(undefined, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Belt_Option.orElse", () => { - Mocha.test("Belt_Option.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.every", () => { - Mocha.test("Belt_Range.every", () => { - Belt_Range.every(0, 4, i => i < 5); - Belt_Range.every(0, 4, i => i < 4); - }); -}); - -Mocha.describe("Belt_Range.everyBy", () => { - Mocha.test("Belt_Range.everyBy", () => { - Belt_Range.everyBy(0, 4, 1, i => i % 2 === 0); - Belt_Range.everyBy(0, 4, 2, i => i % 2 === 0); - }); -}); - -Mocha.describe("Belt_Range.forEach", () => { - Mocha.test("Belt_Range.forEach", () => { - Belt_Range.forEach(0, 4, i => { - console.log(i); - }); - }); -}); - -Mocha.describe("Belt_Range.some", () => { - Mocha.test("Belt_Range.some", () => { - Belt_Range.some(0, 4, i => i > 5); - Belt_Range.some(0, 4, i => i > 2); - }); -}); - -Mocha.describe("Belt_Range.someBy", () => { - Mocha.test("Belt_Range.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.cmp", () => { - Mocha.test("Belt_Result.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.describe("Belt_Result.eq", () => { - Mocha.test("Belt_Result.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.describe("Belt_Result.flatMap", () => { - Mocha.test("Belt_Result.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.describe("Belt_Result.getExn", () => { - Mocha.test("Belt_Result.getExn", () => { - Pervasives.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", - 7700, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Belt_Result.getWithDefault", () => { - Mocha.test("Belt_Result.getWithDefault", () => { - Belt_Result.getWithDefault({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Belt_Result.getWithDefault({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); -}); - -Mocha.describe("Belt_Result.map", () => { - Mocha.test("Belt_Result.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.describe("Belt_Result.mapWithDefault", () => { - Mocha.test("Belt_Result.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.Dict.add", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.diff", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.empty", () => { - Mocha.test("Belt_Set.Dict.empty", () => {}); -}); - -Mocha.describe("Belt_Set.Dict.eq", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.every", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.forEach", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.fromArray", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.get", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.has", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.intersect", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.isEmpty", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.keep", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.maxUndefined", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.maximum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.mergeMany", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.minUndefined", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.minimum", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.partition", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.reduce", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.remove", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.removeMany", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.size", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.some", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.split", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.subset", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.toArray", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.toList", () => { - Mocha.test("Belt_Set.Dict.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.describe("Belt_Set.Dict.union", () => { - Mocha.test("Belt_Set.Dict.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_Set.add", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s0), []); - Pervasives.assertEqual(Belt_Set.toArray(s1), [1]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s3), [ - 1, - 2 - ]); - Pervasives.assertEqual(s2, s3); - }); -}); - -Mocha.describe("Belt_Set.diff", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s0, s1)), [6]); - Pervasives.assertEqual(Belt_Set.toArray(Belt_Set.diff(s1, s0)), [ - 1, - 4 - ]); - }); -}); - -Mocha.describe("Belt_Set.eq", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.eq(s0, s1), true); - }); -}); - -Mocha.describe("Belt_Set.every", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.every(s0, isEven), true); - }); -}); - -Mocha.describe("Belt_Set.forEach", () => { - Mocha.test("Belt_Set.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); - }); - Pervasives.assertEqual(acc.contents, { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt_Set.fromArray", () => { - Mocha.test("Belt_Set.fromArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 3, - 2, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_Set.get", () => { - Mocha.test("Belt_Set.get", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.get(s0, 3), 3); - Pervasives.assertEqual(Belt_Set.get(s0, 20), undefined); - }); -}); - -Mocha.describe("Belt_Set.has", () => { - Mocha.test("Belt_Set.has", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.fromArray([ - 1, - 4, - 2, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.has(set, 3), false); - Pervasives.assertEqual(Belt_Set.has(set, 1), true); - }); -}); - -Mocha.describe("Belt_Set.intersect", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(intersect), [ - 2, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_Set.isEmpty", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.isEmpty(empty), true); - Pervasives.assertEqual(Belt_Set.isEmpty(notEmpty), false); - }); -}); - -Mocha.describe("Belt_Set.keep", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 4 - ]); - }); -}); - -Mocha.describe("Belt_Set.make", () => { - Mocha.test("Belt_Set.make", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let set = Belt_Set.make(IntCmp); - Pervasives.assertEqual(Belt_Set.isEmpty(set), true); - }); -}); - -Mocha.describe("Belt_Set.maxUndefined", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.maxUndefined(s1)), 5); - }); -}); - -Mocha.describe("Belt_Set.maximum", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.maximum(s0), undefined); - Pervasives.assertEqual(Belt_Set.maximum(s1), 5); - }); -}); - -Mocha.describe("Belt_Set.mergeMany", () => { - Mocha.test("Belt_Set.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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), [ - 1, - 2, - 3, - 4, - 5 - ]); - }); -}); - -Mocha.describe("Belt_Set.minUndefined", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s0)), undefined); - Pervasives.assertEqual(Primitive_option.fromUndefined(Belt_Set.minUndefined(s1)), 1); - }); -}); - -Mocha.describe("Belt_Set.minimum", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.minimum(s0), undefined); - Pervasives.assertEqual(Belt_Set.minimum(s1), 1); - }); -}); - -Mocha.describe("Belt_Set.partition", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(match[0]), [ - 1, - 3, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match[1]), [ - 2, - 4 - ]); - }); -}); - -Mocha.describe("Belt_Set.reduce", () => { - Mocha.test("Belt_Set.reduce", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 5, - 2, - 3, - 5, - 6 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.reduce(s0, /* [] */0, Belt_List.add), { - hd: 6, - tl: { - hd: 5, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt_Set.remove", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(s1), [ - 2, - 3, - 4, - 5 - ]); - Pervasives.assertEqual(Belt_Set.toArray(s2), [ - 2, - 4, - 5 - ]); - Pervasives.assertEqual(s2, s3); - }); -}); - -Mocha.describe("Belt_Set.removeMany", () => { - Mocha.test("Belt_Set.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 - ]); - Pervasives.assertEqual(Belt_Set.toArray(newSet), []); - }); -}); - -Mocha.describe("Belt_Set.size", () => { - Mocha.test("Belt_Set.size", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 1, - 2, - 3, - 4 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.size(s0), 4); - }); -}); - -Mocha.describe("Belt_Set.some", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.some(s0, isOdd), true); - }); -}); - -Mocha.describe("Belt_Set.split", () => { - Mocha.test("Belt_Set.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]; - Pervasives.assertEqual(match[1], true); - Pervasives.assertEqual(Belt_Set.toArray(match$1[0]), [ - 1, - 2 - ]); - Pervasives.assertEqual(Belt_Set.toArray(match$1[1]), [ - 4, - 5 - ]); - }); -}); - -Mocha.describe("Belt_Set.subset", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.subset(s2, s0), true); - Pervasives.assertEqual(Belt_Set.subset(s2, s1), true); - Pervasives.assertEqual(Belt_Set.subset(s1, s0), false); - }); -}); - -Mocha.describe("Belt_Set.toArray", () => { - Mocha.test("Belt_Set.toArray", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toArray(s0), [ - 1, - 2, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_Set.toList", () => { - Mocha.test("Belt_Set.toList", () => { - let cmp = Primitive_object.compare; - let IntCmp = Belt_Id.MakeComparable({ - cmp: cmp - }); - let s0 = Belt_Set.fromArray([ - 3, - 2, - 1, - 5 - ], IntCmp); - Pervasives.assertEqual(Belt_Set.toList(s0), { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 5, - tl: /* [] */0 - } - } - } - }); - }); -}); - -Mocha.describe("Belt_Set.union", () => { - Mocha.test("Belt_Set.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); - Pervasives.assertEqual(Belt_Set.toArray(union), [ - 1, - 2, - 3, - 4, - 5, - 6 - ]); - }); -}); - -Mocha.describe("Belt_SetDict.add", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.diff", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.empty", () => { - Mocha.test("Belt_SetDict.empty", () => {}); -}); - -Mocha.describe("Belt_SetDict.eq", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.every", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.forEach", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.fromArray", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.get", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.has", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.intersect", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.isEmpty", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.keep", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.maxUndefined", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.maximum", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.mergeMany", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.minUndefined", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.minimum", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.partition", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.reduce", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.remove", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.removeMany", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.size", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.some", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.split", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.subset", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.toArray", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.toList", () => { - Mocha.test("Belt_SetDict.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.describe("Belt_SetDict.union", () => { - Mocha.test("Belt_SetDict.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.binarySearchBy", () => { - Mocha.test("Belt_SortArray.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.describe("Belt_SortArray.strictlySortedLength", () => { - Mocha.test("Belt_SortArray.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.blit", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.cmp", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.concat", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.concatMany", () => { - Mocha.test("Belt_internalMapInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.eq", () => { - Mocha.test("Belt_internalMapInt.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.every", () => { - Mocha.test("Belt_internalMapInt.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.every2", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.fill", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.flatMap", () => { - Mocha.test("Belt_internalMapInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.forEach", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.get", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.getBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.getIndexBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.joinWith", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.keepMap", () => { - Mocha.test("Belt_internalMapInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.length", () => { - Mocha.test("Belt_internalMapInt.A.length", () => {}); -}); - -Mocha.describe("Belt_internalMapInt.A.makeBy", () => { - Mocha.test("Belt_internalMapInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.map", () => { - Mocha.test("Belt_internalMapInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.partition", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.range", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.rangeBy", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.reduce", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.reduceReverse", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reverse", () => { - Mocha.test("Belt_internalMapInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.slice", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.some", () => { - Mocha.test("Belt_internalMapInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapInt.A.some2", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.unzip", () => { - Mocha.test("Belt_internalMapInt.A.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.describe("Belt_internalMapInt.A.zip", () => { - Mocha.test("Belt_internalMapInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_internalMapInt.A.zipBy", () => { - Mocha.test("Belt_internalMapInt.A.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.binarySearchBy", () => { - Mocha.test("Belt_internalMapInt.S.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.describe("Belt_internalMapInt.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapInt.S.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.blit", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.cmp", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.concat", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.concatMany", () => { - Mocha.test("Belt_internalMapString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.eq", () => { - Mocha.test("Belt_internalMapString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt_internalMapString.A.every", () => { - Mocha.test("Belt_internalMapString.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapString.A.every2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.fill", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.flatMap", () => { - Mocha.test("Belt_internalMapString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.forEach", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.get", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.getBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.getIndexBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.joinWith", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.keepMap", () => { - Mocha.test("Belt_internalMapString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.keepWithIndex", () => { - Mocha.test("Belt_internalMapString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.length", () => { - Mocha.test("Belt_internalMapString.A.length", () => {}); -}); - -Mocha.describe("Belt_internalMapString.A.makeBy", () => { - Mocha.test("Belt_internalMapString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.makeUninitialized", () => { - Mocha.test("Belt_internalMapString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt_internalMapString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.map", () => { - Mocha.test("Belt_internalMapString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.mapWithIndex", () => { - Mocha.test("Belt_internalMapString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.partition", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.range", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.rangeBy", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.reduce", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.reduceReverse", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalMapString.A.reduceReverse2", () => { - Mocha.test("Belt_internalMapString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_internalMapString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalMapString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_internalMapString.A.reverse", () => { - Mocha.test("Belt_internalMapString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.reverseInPlace", () => { - Mocha.test("Belt_internalMapString.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.slice", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.sliceToEnd", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.some", () => { - Mocha.test("Belt_internalMapString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalMapString.A.some2", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalMapString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.unzip", () => { - Mocha.test("Belt_internalMapString.A.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.describe("Belt_internalMapString.A.zip", () => { - Mocha.test("Belt_internalMapString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_internalMapString.A.zipBy", () => { - Mocha.test("Belt_internalMapString.A.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.binarySearchBy", () => { - Mocha.test("Belt_internalMapString.S.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.describe("Belt_internalMapString.S.strictlySortedLength", () => { - Mocha.test("Belt_internalMapString.S.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.blit", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.cmp", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.concat", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.concatMany", () => { - Mocha.test("Belt_internalSetInt.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.eq", () => { - Mocha.test("Belt_internalSetInt.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.every", () => { - Mocha.test("Belt_internalSetInt.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.every2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.fill", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.flatMap", () => { - Mocha.test("Belt_internalSetInt.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.forEach", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.get", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.getBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.getIndexBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.joinWith", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.keepMap", () => { - Mocha.test("Belt_internalSetInt.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.length", () => { - Mocha.test("Belt_internalSetInt.A.length", () => {}); -}); - -Mocha.describe("Belt_internalSetInt.A.makeBy", () => { - Mocha.test("Belt_internalSetInt.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetInt.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.map", () => { - Mocha.test("Belt_internalSetInt.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.partition", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.range", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.rangeBy", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.reduce", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.reduceReverse", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetInt.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetInt.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reverse", () => { - Mocha.test("Belt_internalSetInt.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetInt.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.slice", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.some", () => { - Mocha.test("Belt_internalSetInt.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalSetInt.A.some2", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetInt.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.unzip", () => { - Mocha.test("Belt_internalSetInt.A.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.describe("Belt_internalSetInt.A.zip", () => { - Mocha.test("Belt_internalSetInt.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_internalSetInt.A.zipBy", () => { - Mocha.test("Belt_internalSetInt.A.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.blit", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.cmp", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.concat", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.concatMany", () => { - Mocha.test("Belt_internalSetString.A.concatMany", () => { - Primitive_object.equal(Belt_Array.concatMany([ - [ - 1, - 2, - 3 - ], - [ - 4, - 5, - 6 - ], - [ - 7, - 8 - ] - ]), [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.eq", () => { - Mocha.test("Belt_internalSetString.A.eq", () => { - Belt_Array.eq([ - 1, - 2, - 3 - ], [ - -1, - -2, - -3 - ], (a, b) => Pervasives.abs(a) === Pervasives.abs(b)) === true; - }); -}); - -Mocha.describe("Belt_internalSetString.A.every", () => { - Mocha.test("Belt_internalSetString.A.every", () => { - Belt_Array.every([ - 1, - 3, - 5 - ], x => x % 2 === 1) === true; - Belt_Array.every([ - 1, - -3, - 5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalSetString.A.every2", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.fill", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.flatMap", () => { - Mocha.test("Belt_internalSetString.A.flatMap", () => { - Primitive_object.equal(Belt_Array.flatMap([ - 1, - 2 - ], x => [ - x + 10 | 0, - x + 20 | 0 - ]), [ - 11, - 21, - 12, - 22 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.forEach", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.forEachWithIndex", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.get", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.getBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.getIndexBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.joinWith", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.keepMap", () => { - Mocha.test("Belt_internalSetString.A.keepMap", () => { - Primitive_object.equal(Belt_Array.keepMap([ - 1, - 2, - 3 - ], x => { - if (x % 2 === 0) { - return x; - } - - }), [2]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.keepWithIndex", () => { - Mocha.test("Belt_internalSetString.A.keepWithIndex", () => { - Primitive_object.equal(Belt_Array.keepWithIndex([ - 1, - 2, - 3 - ], (_x, i) => i === 1), [2]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.length", () => { - Mocha.test("Belt_internalSetString.A.length", () => {}); -}); - -Mocha.describe("Belt_internalSetString.A.makeBy", () => { - Mocha.test("Belt_internalSetString.A.makeBy", () => { - Primitive_object.equal(Belt_Array.makeBy(5, i => i), [ - 0, - 1, - 2, - 3, - 4 - ]); - Primitive_object.equal(Belt_Array.makeBy(5, i => Math.imul(i, i)), [ - 0, - 1, - 4, - 9, - 16 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.makeUninitialized", () => { - Mocha.test("Belt_internalSetString.A.makeUninitialized", () => { - let arr = new Array(5); - Belt_Array.getExn(arr, 0) === undefined; - }); -}); - -Mocha.describe("Belt_internalSetString.A.makeUninitializedUnsafe", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.map", () => { - Mocha.test("Belt_internalSetString.A.map", () => { - Primitive_object.equal(Belt_Array.map([ - 1, - 2 - ], x => x + 1 | 0), [ - 3, - 4 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.mapWithIndex", () => { - Mocha.test("Belt_internalSetString.A.mapWithIndex", () => { - Primitive_object.equal(Belt_Array.mapWithIndex([ - 1, - 2, - 3 - ], (i, x) => i + x | 0), [ - 1, - 3, - 5 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.partition", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.range", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.rangeBy", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.reduce", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.reduceReverse", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse", () => { - Belt_Array.reduceReverse([ - "a", - "b", - "c", - "d" - ], "", (a, b) => a + b) === "dcba"; - }); -}); - -Mocha.describe("Belt_internalSetString.A.reduceReverse2", () => { - Mocha.test("Belt_internalSetString.A.reduceReverse2", () => { - Belt_Array.reduceReverse2([ - 1, - 2, - 3 - ], [ - 1, - 2 - ], 0, (acc, x, y) => (acc + x | 0) + y | 0) === 6; - }); -}); - -Mocha.describe("Belt_internalSetString.A.reduceWithIndex", () => { - Mocha.test("Belt_internalSetString.A.reduceWithIndex", () => { - Belt_Array.reduceWithIndex([ - 1, - 2, - 3, - 4 - ], 0, (acc, x, i) => (acc + x | 0) + i | 0) === 16; - }); -}); - -Mocha.describe("Belt_internalSetString.A.reverse", () => { - Mocha.test("Belt_internalSetString.A.reverse", () => { - Primitive_object.equal(Belt_Array.reverse([ - 10, - 11, - 12, - 13, - 14 - ]), [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.reverseInPlace", () => { - Mocha.test("Belt_internalSetString.A.reverseInPlace", () => { - let arr = [ - 10, - 11, - 12, - 13, - 14 - ]; - Belt_Array.reverseInPlace(arr); - Primitive_object.equal(arr, [ - 14, - 13, - 12, - 11, - 10 - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.slice", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.sliceToEnd", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.some", () => { - Mocha.test("Belt_internalSetString.A.some", () => { - Belt_Array.some([ - 2, - 3, - 4 - ], x => x % 2 === 1) === true; - Belt_Array.some([ - -1, - -3, - -5 - ], x => x > 0) === false; - }); -}); - -Mocha.describe("Belt_internalSetString.A.some2", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - Mocha.test("Belt_internalSetString.A.truncateToLengthUnsafe", () => { - let arr = [ - "ant", - "bee", - "cat", - "dog", - "elk" - ]; - arr.length = 3; - Primitive_object.equal(arr, [ - "ant", - "bee", - "cat" - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.unzip", () => { - Mocha.test("Belt_internalSetString.A.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.describe("Belt_internalSetString.A.zip", () => { - Mocha.test("Belt_internalSetString.A.zip", () => { - Primitive_object.equal(Belt_Array.zip([ - 1, - 2 - ], [ - 3, - 4, - 5 - ]), [ - [ - 1, - 3 - ], - [ - 2, - 4 - ] - ]); - }); -}); - -Mocha.describe("Belt_internalSetString.A.zipBy", () => { - Mocha.test("Belt_internalSetString.A.zipBy", () => { - Primitive_object.equal(Belt_Array.zipBy([ - 1, - 2, - 3 - ], [ - 4, - 5 - ], (a, b) => (a << 1) + b | 0), [ - 6, - 9 - ]); - }); -}); - -Mocha.describe("BigInt.fromStringExn", () => { - Mocha.test("BigInt.fromStringExn", () => { - BigInt("123"); - BigInt(""); - BigInt("0x11"); - BigInt("0b11"); - BigInt("0o11"); - try { - BigInt("a"); - } catch (raw__error) { - let _error = Primitive_exceptions.internalToException(raw__error); - if (_error.RE_EXN_ID !== Exn.$$Error) { - throw _error; - } - - } - }); -}); - -Mocha.describe("BigInt.toLocaleString", () => { - Mocha.test("BigInt.toLocaleString", () => { - console.log((123n).toString()); - }); -}); - -Mocha.describe("BigInt.toString", () => { - Mocha.test("BigInt.toString", () => { - console.log((123n).toString()); - }); -}); - -Mocha.describe("Console.assert2", () => { - Mocha.test("Console.assert2", () => { - console.assert(false, "Hello", "World"); - console.assert(true, [ - 1, - 2, - 3 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.assert3", () => { - Mocha.test("Console.assert3", () => { - console.assert(false, "Hello", "World", "ReScript"); - console.assert(true, "One", 2, 3); - }); -}); - -Mocha.describe("Console.assert4", () => { - Mocha.test("Console.assert4", () => { - console.assert(false, "Hello", "World", "ReScript", "!!!"); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); -}); - -Mocha.describe("Console.assert5", () => { - Mocha.test("Console.assert5", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.assert6", () => { - Mocha.test("Console.assert6", () => { - console.assert(false, "Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.assert(true, [ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.assertMany", () => { - Mocha.test("Console.assertMany", () => { - console.assert(false, "Hello", "World"); - console.assert(true, 1, 2, 3); - }); -}); - -Mocha.describe("Console.assert_", () => { - Mocha.test("Console.assert_", () => { - console.assert(false, "Hello World!"); - console.assert(true, "The answer"); - }); -}); - -Mocha.describe("Console.clear", () => { - Mocha.test("Console.clear", () => { - console.clear(); - }); -}); - -Mocha.describe("Console.count", () => { - Mocha.test("Console.count", () => { - console.count("rescript"); - }); -}); - -Mocha.describe("Console.countReset", () => { - Mocha.test("Console.countReset", () => { - console.countReset("rescript"); - }); -}); - -Mocha.describe("Console.debug", () => { - Mocha.test("Console.debug", () => { - console.debug("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.debug(obj); - }); -}); - -Mocha.describe("Console.debug2", () => { - Mocha.test("Console.debug2", () => { - console.debug("Hello", "World"); - console.debug([ - 1, - 2, - 3 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.debug3", () => { - Mocha.test("Console.debug3", () => { - console.debug("Hello", "World", "ReScript"); - console.debug("One", 2, 3); - }); -}); - -Mocha.describe("Console.debug4", () => { - Mocha.test("Console.debug4", () => { - console.debug("Hello", "World", "ReScript", "!!!"); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); -}); - -Mocha.describe("Console.debug5", () => { - Mocha.test("Console.debug5", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.debug6", () => { - Mocha.test("Console.debug6", () => { - console.debug("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.debug([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.debugMany", () => { - Mocha.test("Console.debugMany", () => { - console.debug("Hello", "World"); - console.debug(1, 2, 3); - }); -}); - -Mocha.describe("Console.dir", () => { - Mocha.test("Console.dir", () => { - console.dir({ - language: "rescript", - version: "10.1.2" - }); - }); -}); - -Mocha.describe("Console.error", () => { - Mocha.test("Console.error", () => { - console.error("error message"); - console.error([ - "error", - "invalid value" - ]); - }); -}); - -Mocha.describe("Console.error2", () => { - Mocha.test("Console.error2", () => { - console.error("Error", "here"); - console.error([ - "log", - "error" - ], "message"); - }); -}); - -Mocha.describe("Console.error3", () => { - Mocha.test("Console.error3", () => { - console.error("Hello", "World", "!!!"); - console.error("first", "second", "third"); - }); -}); - -Mocha.describe("Console.error4", () => { - Mocha.test("Console.error4", () => { - console.error("Hello", "World", "ReScript", /* '!' */33); - console.error("first", "second", "third", "fourth"); - }); -}); - -Mocha.describe("Console.error5", () => { - Mocha.test("Console.error5", () => { - console.error(/* 'e' */101, /* 'r' */114, /* 'r' */114, /* 'o' */111, /* 'r' */114); - console.error(1, "second", "third", "fourth", /* 'c' */99); - }); -}); - -Mocha.describe("Console.error6", () => { - Mocha.test("Console.error6", () => { - console.error("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.error([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.errorMany", () => { - Mocha.test("Console.errorMany", () => { - console.error("Hello", "World"); - console.error(1, 2, 3); - }); -}); - -Mocha.describe("Console.group", () => { - Mocha.test("Console.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.describe("Console.info", () => { - Mocha.test("Console.info", () => { - console.info("Information"); - console.info([ - "Hello", - "JS" - ]); - }); -}); - -Mocha.describe("Console.info2", () => { - Mocha.test("Console.info2", () => { - console.info("Info", "failed to download"); - console.info("info", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.info3", () => { - Mocha.test("Console.info3", () => { - console.info("Hello", "World", "ReScript"); - console.info([ - 1, - 2, - 3 - ], 4, 5); - }); -}); - -Mocha.describe("Console.info4", () => { - Mocha.test("Console.info4", () => { - console.info("Hello", "World", "ReScript", /* '!' */33); - console.info([ - 1, - 2, - 3 - ], 4, 5, "lastinfo"); - }); -}); - -Mocha.describe("Console.info5", () => { - Mocha.test("Console.info5", () => { - console.info("Hello", "World", "from", "JS", "!!!"); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.info6", () => { - Mocha.test("Console.info6", () => { - console.info("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.info([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.infoMany", () => { - Mocha.test("Console.infoMany", () => { - console.info("Hello", "World"); - console.info(1, 2, 3); - }); -}); - -Mocha.describe("Console.log", () => { - Mocha.test("Console.log", () => { - console.log("Hello"); - let obj = { - name: "ReScript", - version: 10 - }; - console.log(obj); - }); -}); - -Mocha.describe("Console.log2", () => { - Mocha.test("Console.log2", () => { - console.log("Hello", "World"); - console.log([ - 1, - 2, - 3 - ], /* '4' */52); - }); -}); - -Mocha.describe("Console.log3", () => { - Mocha.test("Console.log3", () => { - console.log("Hello", "World", "ReScript"); - console.log("One", 2, 3); - }); -}); - -Mocha.describe("Console.log4", () => { - Mocha.test("Console.log4", () => { - console.log("Hello", "World", "ReScript", "!!!"); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar"); - }); -}); - -Mocha.describe("Console.log5", () => { - Mocha.test("Console.log5", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.log6", () => { - Mocha.test("Console.log6", () => { - console.log("Hello", "World", "JS", /* '!' */33, /* '!' */33, /* '?' */63); - console.log([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.logMany", () => { - Mocha.test("Console.logMany", () => { - console.log("Hello", "World"); - console.log(1, 2, 3); - }); -}); - -Mocha.describe("Console.table", () => { - Mocha.test("Console.table", () => { - console.table({ - language: "rescript", - version: "10.1.2" - }); - }); -}); - -Mocha.describe("Console.time", () => { - Mocha.test("Console.time", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); -}); - -Mocha.describe("Console.timeEnd", () => { - Mocha.test("Console.timeEnd", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); -}); - -Mocha.describe("Console.timeLog", () => { - Mocha.test("Console.timeLog", () => { - console.time("for_time"); - for (let x = 3; x >= 1; --x) { - console.log(x); - console.timeLog("for_time"); - } - console.timeEnd("for_time"); - }); -}); - -Mocha.describe("Console.trace", () => { - Mocha.test("Console.trace", () => { - console.trace(); - }); -}); - -Mocha.describe("Console.warn", () => { - Mocha.test("Console.warn", () => { - console.warn("Warning"); - console.warn([ - "Warning", - "invalid number" - ]); - }); -}); - -Mocha.describe("Console.warn2", () => { - Mocha.test("Console.warn2", () => { - console.warn("Hello", "World"); - console.warn([ - 1, - 2, - 3 - ], 4); - }); -}); - -Mocha.describe("Console.warn3", () => { - Mocha.test("Console.warn3", () => { - console.warn("Hello", "World", "ReScript"); - console.warn([ - 1, - 2, - 3 - ], 4, 5); - }); -}); - -Mocha.describe("Console.warn4", () => { - Mocha.test("Console.warn4", () => { - console.warn("Hello", "World", "ReScript", "!!!"); - console.warn("first", "second", "third", "fourth"); - }); -}); - -Mocha.describe("Console.warn5", () => { - Mocha.test("Console.warn5", () => { - console.warn("Hello", "World", "from", "JS", "!!!"); - console.warn([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }); - }); -}); - -Mocha.describe("Console.warn6", () => { - Mocha.test("Console.warn6", () => { - console.warn("Hello", "World", "from", "JS", "!!!", /* '!' */33); - console.warn([ - 1, - 2 - ], [ - 3, - 4 - ], [ - 5, - 6 - ], "polyvar", { - name: "ReScript" - }, 42); - }); -}); - -Mocha.describe("Console.warnMany", () => { - Mocha.test("Console.warnMany", () => { - console.warn("Hello", "World"); - console.warn(1, 2, 3); - }); -}); - -Mocha.describe("Date.UTC.makeWithYM", () => { - Mocha.test("Date.UTC.makeWithYM", () => { - Date.UTC(2023, 0); - Date.UTC(2023, 11); - Date.UTC(2023, 12); - Date.UTC(2023, -1); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMD", () => { - Mocha.test("Date.UTC.makeWithYMD", () => { - Date.UTC(2023, 1, 20); - Date.UTC(2023, 1, -1); - Date.UTC(2023, 1, 29); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMDH", () => { - Mocha.test("Date.UTC.makeWithYMDH", () => { - Date.UTC(2023, 1, 20, 16); - Date.UTC(2023, 1, 20, 24); - Date.UTC(2023, 1, 20, -1); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMDHM", () => { - Mocha.test("Date.UTC.makeWithYMDHM", () => { - Date.UTC(2023, 1, 20, 16, 40); - Date.UTC(2023, 1, 20, 16, 60); - Date.UTC(2023, 1, 20, 16, -1); - }); -}); - -Mocha.describe("Date.UTC.makeWithYMDHMS", () => { - Mocha.test("Date.UTC.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.describe("Date.UTC.makeWithYMDHMSM", () => { - Mocha.test("Date.UTC.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("Date.fromString", () => { - Mocha.test("Date.fromString", () => { - new Date("2023"); - new Date("2023-02-20"); - new Date("2023-02-20T16:40:00.00Z"); - new Date(""); - new Date("").getTime(); - }); -}); - -Mocha.describe("Date.fromTime", () => { - Mocha.test("Date.fromTime", () => { - new Date(0.0); - new Date(-86400000.0); - new Date(86400000.0); - }); -}); - -Mocha.describe("Date.getDate", () => { - Mocha.test("Date.getDate", () => { - new Date("2023-02-20T16:40:00.00").getDate(); - }); -}); - -Mocha.describe("Date.getDay", () => { - Mocha.test("Date.getDay", () => { - new Date("2023-02-20T16:40:00.00").getDay(); - }); -}); - -Mocha.describe("Date.getFullYear", () => { - Mocha.test("Date.getFullYear", () => { - new Date("2023-02-20").getFullYear(); - }); -}); - -Mocha.describe("Date.getHours", () => { - Mocha.test("Date.getHours", () => { - new Date("2023-02-20T16:40:00.00").getHours(); - }); -}); - -Mocha.describe("Date.getMilliseconds", () => { - Mocha.test("Date.getMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").getMilliseconds(); - }); -}); - -Mocha.describe("Date.getMinutes", () => { - Mocha.test("Date.getMinutes", () => { - new Date("2023-02-20T16:40:00.00").getMinutes(); - }); -}); - -Mocha.describe("Date.getMonth", () => { - Mocha.test("Date.getMonth", () => { - new Date("2023-01-01").getMonth(); - }); -}); - -Mocha.describe("Date.getSeconds", () => { - Mocha.test("Date.getSeconds", () => { - new Date("2023-02-20T16:40:00.00").getSeconds(); - }); -}); - -Mocha.describe("Date.getTime", () => { - Mocha.test("Date.getTime", () => { - new Date("2023-02-20").getTime(); - }); -}); - -Mocha.describe("Date.getTimezoneOffset", () => { - Mocha.test("Date.getTimezoneOffset", () => { - new Date("2023-01-01").getTimezoneOffset(); - new Date("2023-06-01").getTimezoneOffset(); - }); -}); - -Mocha.describe("Date.getUTCDate", () => { - Mocha.test("Date.getUTCDate", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDate(); - }); -}); - -Mocha.describe("Date.getUTCDay", () => { - Mocha.test("Date.getUTCDay", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCDay(); - }); -}); - -Mocha.describe("Date.getUTCFullYear", () => { - Mocha.test("Date.getUTCFullYear", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCFullYear(); - }); -}); - -Mocha.describe("Date.getUTCHours", () => { - Mocha.test("Date.getUTCHours", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCHours(); - }); -}); - -Mocha.describe("Date.getUTCMilliseconds", () => { - Mocha.test("Date.getUTCMilliseconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMilliseconds(); - }); -}); - -Mocha.describe("Date.getUTCMinutes", () => { - Mocha.test("Date.getUTCMinutes", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMinutes(); - }); -}); - -Mocha.describe("Date.getUTCMonth", () => { - Mocha.test("Date.getUTCMonth", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCMonth(); - }); -}); - -Mocha.describe("Date.getUTCSeconds", () => { - Mocha.test("Date.getUTCSeconds", () => { - new Date("2023-01-01T00:00:00.00+01:00").getUTCSeconds(); - }); -}); - -Mocha.describe("Date.make", () => { - Mocha.test("Date.make", () => { - new Date(); - }); -}); - -Mocha.describe("Date.makeWithYM", () => { - Mocha.test("Date.makeWithYM", () => { - new Date(2023, 0); - new Date(2023, 11); - new Date(2023, 12); - new Date(2023, -1); - }); -}); - -Mocha.describe("Date.makeWithYMD", () => { - Mocha.test("Date.makeWithYMD", () => { - new Date(2023, 1, 20); - new Date(2023, 1, -1); - new Date(2023, 1, 29); - }); -}); - -Mocha.describe("Date.makeWithYMDH", () => { - Mocha.test("Date.makeWithYMDH", () => { - new Date(2023, 1, 20, 16); - new Date(2023, 1, 20, 24); - new Date(2023, 1, 20, -1); - }); -}); - -Mocha.describe("Date.makeWithYMDHM", () => { - Mocha.test("Date.makeWithYMDHM", () => { - new Date(2023, 1, 20, 16, 40); - new Date(2023, 1, 20, 16, 60); - new Date(2023, 1, 20, 16, -1); - }); -}); - -Mocha.describe("Date.makeWithYMDHMS", () => { - Mocha.test("Date.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.describe("Date.makeWithYMDHMSM", () => { - Mocha.test("Date.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.describe("Date.setDate", () => { - Mocha.test("Date.setDate", () => { - new Date("2023-02-20T16:40:00.00").setDate(1); - }); -}); - -Mocha.describe("Date.setFullYear", () => { - Mocha.test("Date.setFullYear", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024); - }); -}); - -Mocha.describe("Date.setFullYearM", () => { - Mocha.test("Date.setFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0); - }); -}); - -Mocha.describe("Date.setFullYearMD", () => { - Mocha.test("Date.setFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setFullYear(2024, 0, 1); - }); -}); - -Mocha.describe("Date.setHours", () => { - Mocha.test("Date.setHours", () => { - new Date("2023-02-20T16:40:00.00").setHours(0); - }); -}); - -Mocha.describe("Date.setHoursM", () => { - Mocha.test("Date.setHoursM", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0); - }); -}); - -Mocha.describe("Date.setHoursMS", () => { - Mocha.test("Date.setHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0); - }); -}); - -Mocha.describe("Date.setHoursMSMs", () => { - Mocha.test("Date.setHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setHours(0, 0, 0, 0); - }); -}); - -Mocha.describe("Date.setMilliseconds", () => { - Mocha.test("Date.setMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setMilliseconds(0); - }); -}); - -Mocha.describe("Date.setMinutes", () => { - Mocha.test("Date.setMinutes", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0); - }); -}); - -Mocha.describe("Date.setMinutesS", () => { - Mocha.test("Date.setMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0); - }); -}); - -Mocha.describe("Date.setMinutesSMs", () => { - Mocha.test("Date.setMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setMinutes(0, 0, 0); - }); -}); - -Mocha.describe("Date.setMonth", () => { - Mocha.test("Date.setMonth", () => { - new Date("2023-02-20T16:40:00.00").setMonth(0); - }); -}); - -Mocha.describe("Date.setSeconds", () => { - Mocha.test("Date.setSeconds", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0); - }); -}); - -Mocha.describe("Date.setSecondsMs", () => { - Mocha.test("Date.setSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setSeconds(0, 0); - }); -}); - -Mocha.describe("Date.setUTCDate", () => { - Mocha.test("Date.setUTCDate", () => { - new Date("2023-02-20T16:40:00.00").setUTCDate(1); - }); -}); - -Mocha.describe("Date.setUTCFullYear", () => { - Mocha.test("Date.setUTCFullYear", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024); - }); -}); - -Mocha.describe("Date.setUTCFullYearM", () => { - Mocha.test("Date.setUTCFullYearM", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0); - }); -}); - -Mocha.describe("Date.setUTCFullYearMD", () => { - Mocha.test("Date.setUTCFullYearMD", () => { - new Date("2023-02-20T16:40:00.00").setUTCFullYear(2024, 0, 1); - }); -}); - -Mocha.describe("Date.setUTCHours", () => { - Mocha.test("Date.setUTCHours", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0); - }); -}); - -Mocha.describe("Date.setUTCHoursM", () => { - Mocha.test("Date.setUTCHoursM", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0); - }); -}); - -Mocha.describe("Date.setUTCHoursMS", () => { - Mocha.test("Date.setUTCHoursMS", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0); - }); -}); - -Mocha.describe("Date.setUTCHoursMSMs", () => { - Mocha.test("Date.setUTCHoursMSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCHours(0, 0, 0, 0); - }); -}); - -Mocha.describe("Date.setUTCMilliseconds", () => { - Mocha.test("Date.setUTCMilliseconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCMilliseconds(0); - }); -}); - -Mocha.describe("Date.setUTCMinutes", () => { - Mocha.test("Date.setUTCMinutes", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0); - }); -}); - -Mocha.describe("Date.setUTCMinutesS", () => { - Mocha.test("Date.setUTCMinutesS", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0); - }); -}); - -Mocha.describe("Date.setUTCMinutesSMs", () => { - Mocha.test("Date.setUTCMinutesSMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCMinutes(0, 0, 0); - }); -}); - -Mocha.describe("Date.setUTCMonth", () => { - Mocha.test("Date.setUTCMonth", () => { - new Date("2023-02-20T16:40:00.00").setUTCMonth(0); - }); -}); - -Mocha.describe("Date.setUTCSeconds", () => { - Mocha.test("Date.setUTCSeconds", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0); - }); -}); - -Mocha.describe("Date.setUTCSecondsMs", () => { - Mocha.test("Date.setUTCSecondsMs", () => { - new Date("2023-02-20T16:40:00.00").setUTCSeconds(0, 0); - }); -}); - -Mocha.describe("Date.toDateString", () => { - Mocha.test("Date.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.describe("Date.toISOString", () => { - Mocha.test("Date.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.describe("Date.toJSON", () => { - Mocha.test("Date.toJSON", () => { - new Date("2023-01-01T00:00:00.00+00:00").toJSON(); - new Date("").toJSON(); - }); -}); - -Mocha.describe("Date.toLocaleDateString", () => { - Mocha.test("Date.toLocaleDateString", () => { - console.log(new Date().toLocaleDateString()); - }); -}); - -Mocha.describe("Date.toLocaleDateStringWithLocale", () => { - Mocha.test("Date.toLocaleDateStringWithLocale", () => { - console.log(new Date().toLocaleDateString("en-US")); - }); -}); - -Mocha.describe("Date.toLocaleDateStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("Date.toLocaleString", () => { - Mocha.test("Date.toLocaleString", () => { - console.log(new Date().toLocaleString()); - }); -}); - -Mocha.describe("Date.toLocaleStringWithLocale", () => { - Mocha.test("Date.toLocaleStringWithLocale", () => { - console.log(new Date().toLocaleString("en-US")); - }); -}); - -Mocha.describe("Date.toLocaleStringWithLocaleAndOptions", () => { - Mocha.test("Date.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.describe("Date.toLocaleTimeString", () => { - Mocha.test("Date.toLocaleTimeString", () => { - console.log(new Date().toLocaleTimeString()); - }); -}); - -Mocha.describe("Date.toLocaleTimeStringWithLocale", () => { - Mocha.test("Date.toLocaleTimeStringWithLocale", () => { - console.log(new Date().toLocaleTimeString("en-US")); - }); -}); - -Mocha.describe("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - Mocha.test("Date.toLocaleTimeStringWithLocaleAndOptions", () => { - console.log(new Date().toLocaleTimeString("en-US", { - timeStyle: "long" - })); - console.log(new Date().toLocaleTimeString("de", { - hour: "2-digit", - minute: "2-digit" - })); - }); -}); - -Mocha.describe("Date.toString", () => { - Mocha.test("Date.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.describe("Date.toTimeString", () => { - Mocha.test("Date.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.describe("Date.toUTCString", () => { - Mocha.test("Date.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("Dict.assign", () => { - Mocha.test("Dict.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.describe("Dict.copy", () => { - Mocha.test("Dict.copy", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let dict2 = Object.assign({}, dict); - console.log(Object.keys(dict), Object.keys(dict2)); - }); -}); - -Mocha.describe("Dict.delete", () => { - Mocha.test("Dict.delete", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - Dict.$$delete(dict, "someKey"); - }); -}); - -Mocha.describe("Dict.forEach", () => { - Mocha.test("Dict.forEach", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEach(dict, value => { - console.log(value); - }); - }); -}); - -Mocha.describe("Dict.forEachWithKey", () => { - Mocha.test("Dict.forEachWithKey", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - Dict.forEachWithKey(dict, (value, key) => { - console.log(value, key); - }); - }); -}); - -Mocha.describe("Dict.fromArray", () => { - Mocha.test("Dict.fromArray", () => { - Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - }); -}); - -Mocha.describe("Dict.fromIterator", () => { - Mocha.test("Dict.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - map1.set('first', 1); - map1.set('second', 2); - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(Object.values(Object.fromEntries(iterator)), [ - 1, - 2 - ]); - }); -}); - -Mocha.describe("Dict.get", () => { - Mocha.test("Dict.get", () => { - let dict = Object.fromEntries([[ - "someKey", - "someValue" - ]]); - let value = dict["someKey"]; - if (value !== undefined) { - console.log(value); - } else { - console.log("Nope, didn't have the key."); - } - }); -}); - -Mocha.describe("Dict.getUnsafe", () => { - Mocha.test("Dict.getUnsafe", () => { - let dict = Object.fromEntries([ - [ - "key1", - "value1" - ], - [ - "key2", - "value2" - ] - ]); - let value = dict["key1"]; - console.log(value); - }); -}); - -Mocha.describe("Dict.keysToArray", () => { - Mocha.test("Dict.keysToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let keys = Object.keys(dict); - console.log(keys); - }); -}); - -Mocha.describe("Dict.make", () => { - Mocha.test("Dict.make", () => { - let dict2 = {}; - dict2["someKey"] = 12; - }); -}); - -Mocha.describe("Dict.mapValues", () => { - Mocha.test("Dict.mapValues", () => { - let dict = Object.fromEntries([ - [ - "key1", - 1 - ], - [ - "key2", - 2 - ] - ]); - Object.entries(Dict.mapValues(dict, v => v + 10 | 0)); - Object.entries(Dict.mapValues(dict, v => v.toString())); - }); -}); - -Mocha.describe("Dict.set", () => { - Mocha.test("Dict.set", () => { - let dict = {}; - dict["someKey"] = "someValue"; - }); -}); - -Mocha.describe("Dict.toArray", () => { - Mocha.test("Dict.toArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let asArray = Object.entries(dict); - console.log(asArray); - }); -}); - -Mocha.describe("Dict.valuesToArray", () => { - Mocha.test("Dict.valuesToArray", () => { - let dict = {}; - dict["someKey"] = 1; - dict["someKey2"] = 2; - let values = Object.values(dict); - console.log(values); - }); -}); - -Mocha.describe("Error.make", () => { - Mocha.test("Error.make", () => { - let error = new Error("Some message here"); - console.log(error.message); - console.log(error.name); - }); -}); - -Mocha.describe("Error.message", () => { - Mocha.test("Error.message", () => { - let error = new SyntaxError("Some message here"); - console.log(error.message); - }); -}); - -Mocha.describe("Error.name", () => { - Mocha.test("Error.name", () => { - let error = new SyntaxError("Some message here"); - console.log(error.name); - }); -}); - -Mocha.describe("Error.panic", () => { - Mocha.test("Error.panic", () => { - try { - $$Error.panic("Uh oh. This was unexpected!"); - } catch (raw_obj) { - let obj = Primitive_exceptions.internalToException(raw_obj); - if (obj.RE_EXN_ID === 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", - 12962, - 15 - ], - Error: new Error() - }; - } - - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12963, - 12 - ], - Error: new Error() - }; - } - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 12965, - 7 - ], - Error: new Error() - }; - } - } - }); -}); - -Mocha.describe("Error.raise", () => { - Mocha.test("Error.raise", () => { - new Error("Everything is upside down."); - console.log("Phew, sanity still rules."); - }); -}); - -Mocha.describe("Error.stack", () => { - Mocha.test("Error.stack", () => { - let error = new Error("error"); - console.log(error.stack); - }); -}); - -Mocha.describe("Error.toException", () => { - Mocha.test("Error.toException", () => { - new Error("Something went wrong."); - }); -}); - -Mocha.describe("Float.Constants.epsilon", () => { - Mocha.test("Float.Constants.epsilon", () => {}); -}); - -Mocha.describe("Float.Constants.maxValue", () => { - Mocha.test("Float.Constants.maxValue", () => {}); -}); - -Mocha.describe("Float.Constants.minValue", () => { - Mocha.test("Float.Constants.minValue", () => {}); -}); - -Mocha.describe("Float.Constants.nan", () => { - Mocha.test("Float.Constants.nan", () => {}); -}); - -Mocha.describe("Float.Constants.negativeInfinity", () => { - Mocha.test("Float.Constants.negativeInfinity", () => {}); -}); - -Mocha.describe("Float.Constants.positiveInfinity", () => { - Mocha.test("Float.Constants.positiveInfinity", () => {}); -}); - -Mocha.describe("Float.clamp", () => { - Mocha.test("Float.clamp", () => { - Float.clamp(undefined, undefined, 4.2) === 4.2; - Float.clamp(4.3, undefined, 4.2) === 4.3; - Float.clamp(undefined, 4.1, 4.2) === 4.1; - Float.clamp(4.3, 4.1, 4.2) === 4.3; - }); -}); - -Mocha.describe("Float.fromInt", () => { - Mocha.test("Float.fromInt", () => {}); -}); - -Mocha.describe("Float.fromString", () => { - Mocha.test("Float.fromString", () => { - Primitive_object.equal(Float.fromString("0"), 0.0); - Float.fromString("NaN") === undefined; - Primitive_object.equal(Float.fromString("6"), 6.0); - }); -}); - -Mocha.describe("Float.isFinite", () => { - Mocha.test("Float.isFinite", () => { - isFinite(1.0); - isFinite(NaN); - isFinite(Number.POSITIVE_INFINITY); - }); -}); - -Mocha.describe("Float.isNaN", () => { - Mocha.test("Float.isNaN", () => { - isNaN(3.0); - isNaN(NaN); - }); -}); - -Mocha.describe("Float.mod", () => { - Mocha.test("Float.mod", () => {}); -}); - -Mocha.describe("Float.parseFloat", () => { - Mocha.test("Float.parseFloat", () => { - parseFloat("1.0"); - parseFloat(" 3.14 "); - parseFloat("3.0"); - parseFloat("3.14some non-digit characters"); - isNaN(parseFloat("error")); - }); -}); - -Mocha.describe("Float.parseInt", () => { - Mocha.test("Float.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.describe("Float.parseIntWithRadix", () => { - Mocha.test("Float.parseIntWithRadix", () => { - parseInt("10.0", 2); - parseInt("15 * 3", 10); - parseInt("12", 13); - isNaN(parseInt("17", 40)); - }); -}); - -Mocha.describe("Float.toExponential", () => { - Mocha.test("Float.toExponential", () => { - (1000.0).toExponential(); - (-1000.0).toExponential(); - (77.0).toExponential(2); - (5678.0).toExponential(2); - }); -}); - -Mocha.describe("Float.toExponentialWithPrecision", () => { - Mocha.test("Float.toExponentialWithPrecision", () => { - (77.0).toExponential(2); - (5678.0).toExponential(2); - }); -}); - -Mocha.describe("Float.toFixed", () => { - Mocha.test("Float.toFixed", () => { - (123456.0).toFixed(); - (10.0).toFixed(); - (300.0).toFixed(4); - (300.0).toFixed(1); - }); -}); - -Mocha.describe("Float.toFixedWithPrecision", () => { - Mocha.test("Float.toFixedWithPrecision", () => { - (300.0).toFixed(4); - (300.0).toFixed(1); - }); -}); - -Mocha.describe("Float.toInt", () => { - Mocha.test("Float.toInt", () => {}); -}); - -Mocha.describe("Float.toLocaleString", () => { - Mocha.test("Float.toLocaleString", () => { - (1000.0).toLocaleString(); - (1000.0).toLocaleString(); - }); -}); - -Mocha.describe("Float.toPrecision", () => { - Mocha.test("Float.toPrecision", () => { - (100.0).toPrecision(); - (1.0).toPrecision(); - (100.0).toPrecision(2); - (1.0).toPrecision(1); - }); -}); - -Mocha.describe("Float.toPrecisionWithPrecision", () => { - Mocha.test("Float.toPrecisionWithPrecision", () => { - (100.0).toPrecision(2); - (1.0).toPrecision(1); - }); -}); - -Mocha.describe("Float.toString", () => { - Mocha.test("Float.toString", () => { - (1000.0).toString(); - (-1000.0).toString(); - }); -}); - -Mocha.describe("Float.toStringWithRadix", () => { - Mocha.test("Float.toStringWithRadix", () => { - (6.0).toString(2); - (3735928559.0).toString(16); - (123456.0).toString(36); - }); -}); - -Mocha.describe("Int.Bitwise.asr", () => { - Mocha.test("Int.Bitwise.asr", () => {}); -}); - -Mocha.describe("Int.Bitwise.land", () => { - Mocha.test("Int.Bitwise.land", () => {}); -}); - -Mocha.describe("Int.Bitwise.lnot", () => { - Mocha.test("Int.Bitwise.lnot", () => { - Int.Bitwise.lnot(2) === -3; - }); -}); - -Mocha.describe("Int.Bitwise.lor", () => { - Mocha.test("Int.Bitwise.lor", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsl", () => { - Mocha.test("Int.Bitwise.lsl", () => {}); -}); - -Mocha.describe("Int.Bitwise.lsr", () => { - Mocha.test("Int.Bitwise.lsr", () => {}); -}); - -Mocha.describe("Int.Bitwise.lxor", () => { - Mocha.test("Int.Bitwise.lxor", () => {}); -}); - -Mocha.describe("Int.Constants.maxValue", () => { - Mocha.test("Int.Constants.maxValue", () => { - console.log(Int.Constants.maxValue); - }); -}); - -Mocha.describe("Int.Constants.minValue", () => { - Mocha.test("Int.Constants.minValue", () => { - console.log(Int.Constants.minValue); - }); -}); - -Mocha.describe("Int.clamp", () => { - Mocha.test("Int.clamp", () => { - Int.clamp(undefined, undefined, 42) === 42; - Int.clamp(50, undefined, 42) === 50; - Int.clamp(undefined, 40, 42) === 40; - Int.clamp(50, 40, 42) === 50; - }); -}); - -Mocha.describe("Int.fromFloat", () => { - Mocha.test("Int.fromFloat", () => {}); -}); - -Mocha.describe("Int.fromString", () => { - Mocha.test("Int.fromString", () => { - Primitive_object.equal(Int.fromString("0", undefined), 0); - Int.fromString("NaN", undefined) === undefined; - Int.fromString("6", 2) === undefined; - }); -}); - -Mocha.describe("Int.mod", () => { - Mocha.test("Int.mod", () => {}); -}); - -Mocha.describe("Int.range", () => { - Mocha.test("Int.range", () => { - Primitive_object.equal(Int.range(3, 6, undefined), [ - 3, - 4, - 5 - ]); - Primitive_object.equal(Int.range(-3, -1, undefined), [ - -3, - -2 - ]); - Primitive_object.equal(Int.range(3, 1, undefined), [ - 3, - 2 - ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2 - }), [ - 3, - 5 - ]); - Primitive_object.equal(Int.range(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Int.range(3, 6, { - step: -2 - }); - }); -}); - -Mocha.describe("Int.rangeWithOptions", () => { - Mocha.test("Int.rangeWithOptions", () => { - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2 - }), [ - 3, - 5 - ]); - Primitive_object.equal(Int.rangeWithOptions(3, 7, { - step: 2, - inclusive: true - }), [ - 3, - 5, - 7 - ]); - Int.rangeWithOptions(3, 6, { - step: -2 - }); - }); -}); - -Mocha.describe("Int.toExponential", () => { - Mocha.test("Int.toExponential", () => { - (1000).toExponential(); - (-1000).toExponential(); - (77).toExponential(2); - (5678).toExponential(2); - }); -}); - -Mocha.describe("Int.toExponentialWithPrecision", () => { - Mocha.test("Int.toExponentialWithPrecision", () => { - (77).toExponential(2); - (5678).toExponential(2); - }); -}); - -Mocha.describe("Int.toFixed", () => { - Mocha.test("Int.toFixed", () => { - (123456).toFixed(); - (10).toFixed(); - (300).toFixed(4); - (300).toFixed(1); - }); -}); - -Mocha.describe("Int.toFixedWithPrecision", () => { - Mocha.test("Int.toFixedWithPrecision", () => { - (300).toFixed(4); - (300).toFixed(1); - }); -}); - -Mocha.describe("Int.toFloat", () => { - Mocha.test("Int.toFloat", () => {}); -}); - -Mocha.describe("Int.toLocaleString", () => { - Mocha.test("Int.toLocaleString", () => { - (1000).toLocaleString(); - (1000).toLocaleString(); - }); -}); - -Mocha.describe("Int.toPrecision", () => { - Mocha.test("Int.toPrecision", () => { - (100).toPrecision(); - (1).toPrecision(); - (100).toPrecision(2); - (1).toPrecision(2); - }); -}); - -Mocha.describe("Int.toPrecisionWithPrecision", () => { - Mocha.test("Int.toPrecisionWithPrecision", () => { - (100).toPrecision(2); - (1).toPrecision(2); - }); -}); - -Mocha.describe("Int.toString", () => { - Mocha.test("Int.toString", () => { - (1000).toString(); - (-1000).toString(); - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); - }); -}); - -Mocha.describe("Int.toStringWithRadix", () => { - Mocha.test("Int.toStringWithRadix", () => { - (6).toString(2); - (373592855).toString(16); - (123456).toString(36); - }); -}); - -Mocha.describe("Iterator.forEach", () => { - Mocha.test("Iterator.forEach", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - $$Iterator.forEach(iterator, v => { - if (v === undefined) { - return Pervasives.assertEqual(Option.isNone(v), true); - } - switch (v) { - case "a" : - case "b" : - case "c" : - return; - default: - return Pervasives.assertEqual(Option.isNone(v), true); - } - }); - }); -}); - -Mocha.describe("Iterator.next", () => { - Mocha.test("Iterator.next", () => { - let iterator = ((() => { - var array1 = ['a']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(iterator.next().done, false); - Pervasives.assertEqual(iterator.next().done, true); - }); -}); - -Mocha.describe("Iterator.toArray", () => { - Mocha.test("Iterator.toArray", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - let mapKeysAsArray = Array.from(map.keys()); - console.log(mapKeysAsArray); - }); -}); - -Mocha.describe("Iterator.toArrayWithMapper", () => { - Mocha.test("Iterator.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("JSON.Classify.classify", () => { - Mocha.test("JSON.Classify.classify", () => { - $$JSON.Classify.classify("hello world"); - $$JSON.Classify.classify(42); - }); -}); - -Mocha.describe("JSON.Decode.array", () => { - Mocha.test("JSON.Decode.array", () => { - $$JSON.Decode.array(JSON.parse("[\"foo\", \"bar\"]")); - $$JSON.Decode.array(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.bool", () => { - Mocha.test("JSON.Decode.bool", () => { - $$JSON.Decode.bool(JSON.parse("true")); - $$JSON.Decode.bool(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.float", () => { - Mocha.test("JSON.Decode.float", () => { - $$JSON.Decode.float(JSON.parse("42.0")); - $$JSON.Decode.float(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.null", () => { - Mocha.test("JSON.Decode.null", () => { - $$JSON.Decode.$$null(JSON.parse("null")); - $$JSON.Decode.$$null(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.object", () => { - Mocha.test("JSON.Decode.object", () => { - $$JSON.Decode.object(JSON.parse("{\"foo\":\"bar\"}")); - $$JSON.Decode.object(JSON.parse("\"hello world\"")); - }); -}); - -Mocha.describe("JSON.Decode.string", () => { - Mocha.test("JSON.Decode.string", () => { - $$JSON.Decode.string(JSON.parse("\"hello world\"")); - $$JSON.Decode.string(JSON.parse("42")); - }); -}); - -Mocha.describe("JSON.Encode.array", () => { - Mocha.test("JSON.Encode.array", () => {}); -}); - -Mocha.describe("JSON.Encode.bool", () => { - Mocha.test("JSON.Encode.bool", () => {}); -}); - -Mocha.describe("JSON.Encode.float", () => { - Mocha.test("JSON.Encode.float", () => {}); -}); - -Mocha.describe("JSON.Encode.int", () => { - Mocha.test("JSON.Encode.int", () => {}); -}); - -Mocha.describe("JSON.Encode.null", () => { - Mocha.test("JSON.Encode.null", () => {}); -}); - -Mocha.describe("JSON.Encode.object", () => { - Mocha.test("JSON.Encode.object", () => { - Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ] - ]); - }); -}); - -Mocha.describe("JSON.Encode.string", () => { - Mocha.test("JSON.Encode.string", () => {}); -}); - -Mocha.describe("JSON.parseExn", () => { - Mocha.test("JSON.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 === 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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn$1; - } - } - }); -}); - -Mocha.describe("JSON.parseExnWithReviver", () => { - Mocha.test("JSON.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 === Exn.$$Error) { - console.log("error"); - } else { - throw exn; - } - } - }); -}); - -Mocha.describe("JSON.stringify", () => { - Mocha.test("JSON.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 = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); -}); - -Mocha.describe("JSON.stringifyAny", () => { - Mocha.test("JSON.stringifyAny", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 13927, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithFilter", () => { - Mocha.test("JSON.stringifyAnyWithFilter", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 13951, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithFilterAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict), "{\"foo\":\"bar\",\"hello\":\"world\",\"someNumber\":42}"); - Pervasives.assertEqual(JSON.stringify(dict, undefined, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.assertEqual(JSON.stringify(dict, [ - "foo", - "someNumber" - ]), "{\"foo\":\"bar\",\"someNumber\":42}"); - Pervasives.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", - 13990, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithIndent", () => { - Mocha.test("JSON.stringifyAnyWithIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - Pervasives.assertEqual(JSON.stringify(dict, null, 2), "{\n \"foo\": \"bar\",\n \"hello\": \"world\",\n \"someNumber\": 42\n}"); - Pervasives.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", - 14019, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithReplacer", () => { - Mocha.test("JSON.stringifyAnyWithReplacer", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 14053, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyAnyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyAnyWithReplacerAndIndent", () => { - let dict = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - Pervasives.assertEqual(JSON.stringify(dict, replacer), "{\"foo\":\"BAR\",\"hello\":\"WORLD\",\"someNumber\":42}"); - Pervasives.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", - 14087, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("JSON.stringifyWithFilter", () => { - Mocha.test("JSON.stringifyWithFilter", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ]); - }); -}); - -Mocha.describe("JSON.stringifyWithFilterAndIndent", () => { - Mocha.test("JSON.stringifyWithFilterAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, [ - "foo", - "someNumber" - ], 2); - }); -}); - -Mocha.describe("JSON.stringifyWithIndent", () => { - Mocha.test("JSON.stringifyWithIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - JSON.stringify(json, null, 2); - }); -}); - -Mocha.describe("JSON.stringifyWithReplacer", () => { - Mocha.test("JSON.stringifyWithReplacer", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer); - }); -}); - -Mocha.describe("JSON.stringifyWithReplacerAndIndent", () => { - Mocha.test("JSON.stringifyWithReplacerAndIndent", () => { - let json = Object.fromEntries([ - [ - "foo", - "bar" - ], - [ - "hello", - "world" - ], - [ - "someNumber", - 42 - ] - ]); - let replacer = (param, value) => { - let decodedValue = $$JSON.Decode.string(value); - if (decodedValue !== undefined) { - return decodedValue.toUpperCase(); - } else { - return value; - } - }; - JSON.stringify(json, replacer, 2); - }); -}); - -Mocha.describe("List.add", () => { - Mocha.test("List.add", () => { - List.add({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, 1); - List.add({ - hd: "World", - tl: { - hd: "!", - tl: /* [] */0 - } - }, "Hello"); - }); -}); - -Mocha.describe("List.compare", () => { - Mocha.test("List.compare", () => { - List.compare({ - hd: 3, - tl: /* [] */0 - }, { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - }, Primitive_int.compare); - List.compare({ - hd: 5, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 5, - tl: /* [] */0 - }, Primitive_int.compare); - 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); - 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); - 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.describe("List.compareLength", () => { - Mocha.test("List.compareLength", () => { - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - } - }); - List.compareLength({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, { - hd: 5, - tl: { - hd: 6, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("List.concat", () => { - Mocha.test("List.concat", () => { - List.concat({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("List.concatMany", () => { - Mocha.test("List.concatMany", () => { - List.concatMany([ - { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, - /* [] */0, - { - hd: 3, - tl: /* [] */0 - } - ]); - }); -}); - -Mocha.describe("List.drop", () => { - Mocha.test("List.drop", () => { - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 3); - List.drop({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); -}); - -Mocha.describe("List.equal", () => { - Mocha.test("List.equal", () => { - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - List.equal({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, (a, b) => a === b); - 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.describe("List.every", () => { - Mocha.test("List.every", () => { - let isBelow10 = value => value < 10; - List.every({ - hd: 1, - tl: { - hd: 9, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - List.every({ - hd: 1, - tl: { - hd: 99, - tl: { - hd: 8, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, isBelow10); - }); -}); - -Mocha.describe("List.every2", () => { - Mocha.test("List.every2", () => { - List.every2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.every2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.every2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); -}); - -Mocha.describe("List.filter", () => { - Mocha.test("List.filter", () => { - let isEven = x => x % 2 === 0; - List.filter({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isEven); - List.filter({ - hd: undefined, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - } - }, Option.isSome); - }); -}); - -Mocha.describe("List.filterMap", () => { - Mocha.test("List.filterMap", () => { - let isEven = x => x % 2 === 0; - List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => { - if (isEven(x)) { - return x; - } - - }); - List.filterMap({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: undefined, - tl: /* [] */0 - } - } - }, x => x); - }); -}); - -Mocha.describe("List.filterWithIndex", () => { - Mocha.test("List.filterWithIndex", () => { - List.filterWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, (_x, index) => index % 2 === 0); - }); -}); - -Mocha.describe("List.find", () => { - Mocha.test("List.find", () => { - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 3); - List.find({ - hd: 1, - tl: { - hd: 4, - tl: { - hd: 3, - tl: { - hd: 2, - tl: /* [] */0 - } - } - } - }, x => x > 4); - }); -}); - -Mocha.describe("List.flat", () => { - Mocha.test("List.flat", () => { - 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.describe("List.forEach", () => { - Mocha.test("List.forEach", () => { - List.forEach({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, x => { - console.log("Item: " + x); - }); - }); -}); - -Mocha.describe("List.forEach2", () => { - Mocha.test("List.forEach2", () => { - 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.describe("List.forEachWithIndex", () => { - Mocha.test("List.forEachWithIndex", () => { - List.forEachWithIndex({ - hd: "a", - tl: { - hd: "b", - tl: { - hd: "c", - tl: /* [] */0 - } - } - }, (x, index) => { - console.log("Item " + index.toString() + " is " + x); - }); - }); -}); - -Mocha.describe("List.fromArray", () => { - Mocha.test("List.fromArray", () => { - List.fromArray([ - 1, - 2, - 3 - ]); - }); -}); - -Mocha.describe("List.fromInitializer", () => { - Mocha.test("List.fromInitializer", () => { - List.fromInitializer(5, i => i); - List.fromInitializer(5, i => Math.imul(i, i)); - }); -}); - -Mocha.describe("List.get", () => { - Mocha.test("List.get", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - List.get(abc, 1); - List.get(abc, 4); - }); -}); - -Mocha.describe("List.getAssoc", () => { - Mocha.test("List.getAssoc", () => { - List.getAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 3, (a, b) => a === b); - List.getAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, (k, item) => k === item); - }); -}); - -Mocha.describe("List.getExn", () => { - Mocha.test("List.getExn", () => { - let abc = { - hd: "A", - tl: { - hd: "B", - tl: { - hd: "C", - tl: /* [] */0 - } - } - }; - Pervasives.assertEqual(List.getExn(abc, 1), "B"); - let exit = 0; - let val; - try { - val = 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", - 14485, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("List.has", () => { - Mocha.test("List.has", () => { - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2, (a, b) => a === b); - List.has({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4, (a, b) => a === b); - List.has({ - hd: -1, - tl: { - hd: -2, - tl: { - hd: -3, - tl: /* [] */0 - } - } - }, 2, (a, b) => Pervasives.abs(a) === Pervasives.abs(b)); - }); -}); - -Mocha.describe("List.hasAssoc", () => { - Mocha.test("List.hasAssoc", () => { - List.hasAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - List.hasAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 25, (k, item) => k === item); - }); -}); - -Mocha.describe("List.head", () => { - Mocha.test("List.head", () => { - List.head(/* [] */0); - List.head({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.headExn", () => { - Mocha.test("List.headExn", () => { - Pervasives.assertEqual(List.headExn({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }), 1); - let exit = 0; - let val; - try { - val = 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", - 14534, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("List.length", () => { - Mocha.test("List.length", () => { - List.length({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.make", () => { - Mocha.test("List.make", () => { - List.make(3, 1); - }); -}); - -Mocha.describe("List.map", () => { - Mocha.test("List.map", () => { - List.map({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, x => x + 1 | 0); - }); -}); - -Mocha.describe("List.mapReverse", () => { - Mocha.test("List.mapReverse", () => { - let f = x => Math.imul(x, x); - let l = { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }; - let withMap = List.reverse(List.map(l, f)); - let withMapReverse = List.mapReverse(l, f); - console.log(Primitive_object.equal(withMap, withMapReverse)); - }); -}); - -Mocha.describe("List.mapReverse2", () => { - Mocha.test("List.mapReverse2", () => { - 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.describe("List.mapWithIndex", () => { - Mocha.test("List.mapWithIndex", () => { - List.mapWithIndex({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, (x, index) => index + x | 0); - }); -}); - -Mocha.describe("List.partition", () => { - Mocha.test("List.partition", () => { - List.partition({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, x => x > 2); - }); -}); - -Mocha.describe("List.reduce", () => { - Mocha.test("List.reduce", () => { - List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduce({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (acc, item) => acc + item | 0); - }); -}); - -Mocha.describe("List.reduce2", () => { - Mocha.test("List.reduce2", () => { - List.reduce2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("List.reduceReverse", () => { - Mocha.test("List.reduceReverse", () => { - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 0, (a, b) => a + b | 0); - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, 10, (a, b) => a - b | 0); - List.reduceReverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, /* [] */0, List.add); - }); -}); - -Mocha.describe("List.reduceReverse2", () => { - Mocha.test("List.reduceReverse2", () => { - List.reduceReverse2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - }, 0, (acc, x, y) => (acc + Math.imul(x, x) | 0) + y | 0); - }); -}); - -Mocha.describe("List.reduceWithIndex", () => { - Mocha.test("List.reduceWithIndex", () => { - 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.describe("List.removeAssoc", () => { - Mocha.test("List.removeAssoc", () => { - List.removeAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 1, (a, b) => a === b); - List.removeAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 15, - "afternoon" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 9, (k, item) => k === item); - }); -}); - -Mocha.describe("List.reverse", () => { - Mocha.test("List.reverse", () => { - List.reverse({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.reverseConcat", () => { - Mocha.test("List.reverseConcat", () => { - List.reverseConcat({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - }); - }); -}); - -Mocha.describe("List.setAssoc", () => { - Mocha.test("List.setAssoc", () => { - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 2, - "b" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - } - }, 2, "x", (a, b) => a === b); - List.setAssoc({ - hd: [ - 1, - "a" - ], - tl: { - hd: [ - 3, - "c" - ], - tl: /* [] */0 - } - }, 2, "b", (a, b) => a === b); - List.setAssoc({ - hd: [ - 9, - "morning" - ], - tl: { - hd: [ - 3, - "morning?!" - ], - tl: { - hd: [ - 22, - "night" - ], - tl: /* [] */0 - } - } - }, 15, "afternoon", (a, b) => a % 12 === b % 12); - }); -}); - -Mocha.describe("List.size", () => { - Mocha.test("List.size", () => { - List.size({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.some", () => { - Mocha.test("List.some", () => { - let isAbove100 = value => value > 100; - List.some({ - hd: 101, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - } - }, isAbove100); - List.some({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - }, isAbove100); - }); -}); - -Mocha.describe("List.some2", () => { - Mocha.test("List.some2", () => { - List.some2({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, { - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, (a, b) => a > b); - List.some2(/* [] */0, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - }, { - hd: 1, - tl: /* [] */0 - }, (a, b) => a > b); - List.some2({ - hd: 0, - tl: { - hd: 1, - tl: /* [] */0 - } - }, { - hd: 5, - tl: { - hd: 0, - tl: /* [] */0 - } - }, (a, b) => a > b); - }); -}); - -Mocha.describe("List.sort", () => { - Mocha.test("List.sort", () => { - List.sort({ - hd: 5, - tl: { - hd: 4, - tl: { - hd: 9, - tl: { - hd: 3, - tl: { - hd: 7, - tl: /* [] */0 - } - } - } - } - }, Primitive_int.compare); - }); -}); - -Mocha.describe("List.splitAt", () => { - Mocha.test("List.splitAt", () => { - List.splitAt({ - hd: "Hello", - tl: { - hd: "World", - tl: /* [] */0 - } - }, 1); - List.splitAt({ - hd: 0, - tl: { - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: { - hd: 4, - tl: /* [] */0 - } - } - } - } - }, 2); - }); -}); - -Mocha.describe("List.tail", () => { - Mocha.test("List.tail", () => { - List.tail({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - List.tail(/* [] */0); - }); -}); - -Mocha.describe("List.tailExn", () => { - Mocha.test("List.tailExn", () => { - Pervasives.assertEqual(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 = 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", - 14786, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("List.take", () => { - Mocha.test("List.take", () => { - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 1); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 2); - List.take({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }, 4); - }); -}); - -Mocha.describe("List.toArray", () => { - Mocha.test("List.toArray", () => { - List.toArray({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.toShuffled", () => { - Mocha.test("List.toShuffled", () => { - List.toShuffled({ - hd: 1, - tl: { - hd: 2, - tl: { - hd: 3, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.unzip", () => { - Mocha.test("List.unzip", () => { - List.unzip({ - hd: [ - 1, - 2 - ], - tl: { - hd: [ - 3, - 4 - ], - tl: /* [] */0 - } - }); - 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.describe("List.zip", () => { - Mocha.test("List.zip", () => { - List.zip({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }, { - hd: 3, - tl: { - hd: 4, - tl: { - hd: 5, - tl: /* [] */0 - } - } - }); - }); -}); - -Mocha.describe("List.zipBy", () => { - Mocha.test("List.zipBy", () => { - 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("Map.clear", () => { - Mocha.test("Map.clear", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.clear(); - }); -}); - -Mocha.describe("Map.delete", () => { - Mocha.test("Map.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.describe("Map.entries", () => { - Mocha.test("Map.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.describe("Map.forEach", () => { - Mocha.test("Map.forEach", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach(value => { - console.log(value); - }); - }); -}); - -Mocha.describe("Map.forEachWithKey", () => { - Mocha.test("Map.forEachWithKey", () => { - let map = new Map(); - map.set("someKey", "someValue"); - map.set("someKey2", "someValue2"); - map.forEach((value, key) => { - console.log(value, key); - }); - }); -}); - -Mocha.describe("Map.fromArray", () => { - Mocha.test("Map.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.describe("Map.fromIterator", () => { - Mocha.test("Map.fromIterator", () => { - let iterator = ((() => { - var map1 = new Map(); - - map1.set('first', '1'); - map1.set('second', '2'); - - var iterator1 = map1[Symbol.iterator](); - return iterator1; - })()); - Pervasives.assertEqual(new Map(iterator).size, 2); - }); -}); - -Mocha.describe("Map.get", () => { - Mocha.test("Map.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.describe("Map.has", () => { - Mocha.test("Map.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.describe("Map.keys", () => { - Mocha.test("Map.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.describe("Map.make", () => { - Mocha.test("Map.make", () => { - new Map(); - let map = new Map(); - map.set("lang", "ReScript"); - }); -}); - -Mocha.describe("Map.set", () => { - Mocha.test("Map.set", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); -}); - -Mocha.describe("Map.size", () => { - Mocha.test("Map.size", () => { - let map = new Map(); - map.set("someKey", "someValue"); - }); -}); - -Mocha.describe("Map.values", () => { - Mocha.test("Map.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("Math.Constants.e", () => { - Mocha.test("Math.Constants.e", () => {}); -}); - -Mocha.describe("Math.Constants.ln10", () => { - Mocha.test("Math.Constants.ln10", () => {}); -}); - -Mocha.describe("Math.Constants.ln2", () => { - Mocha.test("Math.Constants.ln2", () => {}); -}); - -Mocha.describe("Math.Constants.log10e", () => { - Mocha.test("Math.Constants.log10e", () => {}); -}); - -Mocha.describe("Math.Constants.log2e", () => { - Mocha.test("Math.Constants.log2e", () => {}); -}); - -Mocha.describe("Math.Constants.pi", () => { - Mocha.test("Math.Constants.pi", () => {}); -}); - -Mocha.describe("Math.Constants.sqrt1_2", () => { - Mocha.test("Math.Constants.sqrt1_2", () => {}); -}); - -Mocha.describe("Math.Constants.sqrt2", () => { - Mocha.test("Math.Constants.sqrt2", () => {}); -}); - -Mocha.describe("Math.Int.abs", () => { - Mocha.test("Math.Int.abs", () => { - Math.abs(-2); - Math.abs(3); - }); -}); - -Mocha.describe("Math.Int.ceil", () => { - Mocha.test("Math.Int.ceil", () => { - $$Math.Int.ceil(3.7) === 4; - $$Math.Int.ceil(3.0) === 3; - $$Math.Int.ceil(-3.1) === -3; - }); -}); - -Mocha.describe("Math.Int.clz32", () => { - Mocha.test("Math.Int.clz32", () => { - Math.clz32(1); - Math.clz32(4); - }); -}); - -Mocha.describe("Math.Int.floor", () => { - Mocha.test("Math.Int.floor", () => { - $$Math.Int.floor(3.7) === 3; - $$Math.Int.floor(3.0) === 3; - $$Math.Int.floor(-3.1) === -4; - }); -}); - -Mocha.describe("Math.Int.imul", () => { - Mocha.test("Math.Int.imul", () => { - Math.imul(3, 4); - Math.imul(-5, 12); - }); -}); - -Mocha.describe("Math.Int.max", () => { - Mocha.test("Math.Int.max", () => { - Math.max(1, 2); - Math.max(-1, -2); - }); -}); - -Mocha.describe("Math.Int.maxMany", () => { - Mocha.test("Math.Int.maxMany", () => { - Math.max(1, 2); - Math.max(-1, -2); - isFinite(Math.max()); - }); -}); - -Mocha.describe("Math.Int.min", () => { - Mocha.test("Math.Int.min", () => { - Math.min(1, 2); - Math.min(-1, -2); - }); -}); - -Mocha.describe("Math.Int.minMany", () => { - Mocha.test("Math.Int.minMany", () => { - Math.min(1, 2); - Math.min(-1, -2); - isFinite(Math.min()); - }); -}); - -Mocha.describe("Math.Int.pow", () => { - Mocha.test("Math.Int.pow", () => { - Math.pow(2, 4); - Math.pow(3, 4); - }); -}); - -Mocha.describe("Math.Int.random", () => { - Mocha.test("Math.Int.random", () => { - $$Math.Int.random(2, 5) === 4; - $$Math.Int.random(505, 2000) === 1276; - $$Math.Int.random(-7, -2) === -4; - }); -}); - -Mocha.describe("Math.Int.sign", () => { - Mocha.test("Math.Int.sign", () => { - Math.sign(3); - Math.sign(-3); - Math.sign(0); - }); -}); - -Mocha.describe("Math.abs", () => { - Mocha.test("Math.abs", () => { - Math.abs(-2.0); - Math.abs(3.0); - }); -}); - -Mocha.describe("Math.acos", () => { - Mocha.test("Math.acos", () => { - Math.acos(-1.0); - isNaN(Math.acos(-3.0)); - }); -}); - -Mocha.describe("Math.acosh", () => { - Mocha.test("Math.acosh", () => { - Math.acosh(1.0); - isNaN(Math.acosh(0.5)); - }); -}); - -Mocha.describe("Math.asin", () => { - Mocha.test("Math.asin", () => { - Math.asin(-1.0); - isNaN(Math.asin(-2.0)); - }); -}); - -Mocha.describe("Math.asinh", () => { - Mocha.test("Math.asinh", () => { - Math.asinh(-1.0); - Math.asinh(-0.0); - }); -}); - -Mocha.describe("Math.atan", () => { - Mocha.test("Math.atan", () => { - Math.atan(-0.0); - Math.atan(0.0); - Math.atan(1.0); - }); -}); - -Mocha.describe("Math.atan2", () => { - Mocha.test("Math.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.describe("Math.atanh", () => { - Mocha.test("Math.atanh", () => { - isNaN(Math.atanh(-2.0)); - isFinite(Math.atanh(-1.0)); - Math.atanh(-0.0); - Math.atanh(0.0); - Math.atanh(0.5); - }); -}); - -Mocha.describe("Math.cbrt", () => { - Mocha.test("Math.cbrt", () => { - Math.cbrt(-1.0); - Math.cbrt(-0.0); - Math.cbrt(0.0); - }); -}); - -Mocha.describe("Math.ceil", () => { - Mocha.test("Math.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.describe("Math.cos", () => { - Mocha.test("Math.cos", () => { - Math.cos(-0.0); - Math.cos(0.0); - Math.cos(1.0); - }); -}); - -Mocha.describe("Math.cosh", () => { - Mocha.test("Math.cosh", () => { - Math.cosh(-1.0); - Math.cosh(-0.0); - Math.cosh(0.0); - }); -}); - -Mocha.describe("Math.exp", () => { - Mocha.test("Math.exp", () => { - Math.exp(-1.0); - Math.exp(0.0); - }); -}); - -Mocha.describe("Math.expm1", () => { - Mocha.test("Math.expm1", () => { - Math.expm1(-1.0); - Math.expm1(-0.0); - }); -}); - -Mocha.describe("Math.floor", () => { - Mocha.test("Math.floor", () => { - Math.floor(-45.95); - Math.floor(-45.05); - Math.floor(-0.0); - }); -}); - -Mocha.describe("Math.fround", () => { - Mocha.test("Math.fround", () => { - Math.fround(5.5) === 5.5; - Math.fround(5.05) === 5.050000190734863; - }); -}); - -Mocha.describe("Math.hypot", () => { - Mocha.test("Math.hypot", () => { - Math.hypot(3.0, 4.0); - Math.hypot(3.0, 5.0); - }); -}); - -Mocha.describe("Math.hypotMany", () => { - Mocha.test("Math.hypotMany", () => { - Math.hypot(3.0, 4.0, 5.0); - Math.hypot(); - }); -}); - -Mocha.describe("Math.log", () => { - Mocha.test("Math.log", () => { - isNaN(Math.log(-1.0)); - isFinite(Math.log(-0.0)); - isFinite(Math.log(0.0)); - Math.log(1.0); - }); -}); - -Mocha.describe("Math.log10", () => { - Mocha.test("Math.log10", () => { - isNaN(Math.log10(-2.0)); - isFinite(Math.log10(-0.0)); - isFinite(Math.log10(0.0)); - Math.log10(1.0); - }); -}); - -Mocha.describe("Math.log1p", () => { - Mocha.test("Math.log1p", () => { - isNaN(Math.log1p(-2.0)); - isFinite(Math.log1p(-1.0)); - Math.log1p(-0.0); - }); -}); - -Mocha.describe("Math.log2", () => { - Mocha.test("Math.log2", () => { - isNaN(Math.log2(-2.0)); - isFinite(Math.log2(-0.0)); - isFinite(Math.log2(0.0)); - Math.log2(1.0); - }); -}); - -Mocha.describe("Math.max", () => { - Mocha.test("Math.max", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - }); -}); - -Mocha.describe("Math.maxMany", () => { - Mocha.test("Math.maxMany", () => { - Math.max(1.0, 2.0); - Math.max(-1.0, -2.0); - isFinite(Math.max()); - }); -}); - -Mocha.describe("Math.min", () => { - Mocha.test("Math.min", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - }); -}); - -Mocha.describe("Math.minMany", () => { - Mocha.test("Math.minMany", () => { - Math.min(1.0, 2.0); - Math.min(-1.0, -2.0); - isFinite(Math.min()); - }); -}); - -Mocha.describe("Math.pow", () => { - Mocha.test("Math.pow", () => { - Math.pow(2.0, 4.0); - Math.pow(3.0, 4.0); - }); -}); - -Mocha.describe("Math.random", () => { - Mocha.test("Math.random", () => { - Math.random(); - }); -}); - -Mocha.describe("Math.round", () => { - Mocha.test("Math.round", () => { - Math.round(-20.5); - Math.round(-0.1); - Math.round(0.0); - Math.round(-0.0); - }); -}); - -Mocha.describe("Math.sign", () => { - Mocha.test("Math.sign", () => { - Math.sign(3.0); - Math.sign(-3.0); - Math.sign(0.0); - }); -}); - -Mocha.describe("Math.sin", () => { - Mocha.test("Math.sin", () => { - Math.sin(-0.0); - Math.sin(0.0); - Math.sin(1.0); - }); -}); - -Mocha.describe("Math.sinh", () => { - Mocha.test("Math.sinh", () => { - Math.sinh(-0.0); - Math.sinh(0.0); - Math.sinh(1.0); - }); -}); - -Mocha.describe("Math.sqrt", () => { - Mocha.test("Math.sqrt", () => { - isNaN(Math.sqrt(-1.0)); - Math.sqrt(-0.0); - Math.sqrt(0.0); - Math.sqrt(1.0); - Math.sqrt(9.0); - }); -}); - -Mocha.describe("Math.tan", () => { - Mocha.test("Math.tan", () => { - Math.tan(-0.0); - Math.tan(0.0); - Math.tan(1.0); - }); -}); - -Mocha.describe("Math.tanh", () => { - Mocha.test("Math.tanh", () => { - Math.tanh(-0.0); - Math.tanh(0.0); - Math.tanh(1.0); - }); -}); - -Mocha.describe("Math.trunc", () => { - Mocha.test("Math.trunc", () => { - Math.trunc(0.123); - Math.trunc(1.999); - Math.trunc(13.37); - Math.trunc(42.84); - }); -}); - -Mocha.describe("Null.asNullable", () => { - Mocha.test("Null.asNullable", () => {}); -}); - -Mocha.describe("Null.flatMap", () => { - Mocha.test("Null.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; - } - }; - Null.flatMap(2, addIfAboveOne); - Null.flatMap(-4, addIfAboveOne); - Null.flatMap(null, addIfAboveOne); - }); -}); - -Mocha.describe("Null.forEach", () => { - Mocha.test("Null.forEach", () => { - Null.forEach("thing", x => { - console.log(x); - }); - Null.forEach(null, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Null.fromOption", () => { - Mocha.test("Null.fromOption", () => { - let asNull = Null.fromOption(undefined); - console.log(asNull === null); - }); -}); - -Mocha.describe("Null.getExn", () => { - Mocha.test("Null.getExn", () => { - Pervasives.assertEqual(Null.getExn(3), 3); - let exit = 0; - let value; - try { - value = 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", - 15731, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "ReScript"); - } - let exit$1 = 0; - let val; - try { - val = 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", - 15737, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Null.getOr", () => { - Mocha.test("Null.getOr", () => { - Null.getOr(null, "Banana"); - Null.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNull("Jane")); - greet(undefined); - }); -}); - -Mocha.describe("Null.getUnsafe", () => { - Mocha.test("Null.getUnsafe", () => {}); -}); - -Mocha.describe("Null.make", () => { - Mocha.test("Null.make", () => {}); -}); - -Mocha.describe("Null.map", () => { - Mocha.test("Null.map", () => { - Null.map(3, x => Math.imul(x, x)); - Null.map(null, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Null.mapOr", () => { - Mocha.test("Null.mapOr", () => { - Null.mapOr(3, 0, x => x + 5 | 0); - Null.mapOr(null, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Null.null", () => { - Mocha.test("Null.null", () => { - console.log(null); - }); -}); - -Mocha.describe("Null.toOption", () => { - Mocha.test("Null.toOption", () => { - let nullStr = "Hello"; - if (nullStr !== null) { - console.log("Got string:", nullStr); - } else { - console.log("Didn't have a value."); - } - }); -}); - -Mocha.describe("Nullable.flatMap", () => { - Mocha.test("Nullable.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } else { - return null; - } - }; - Nullable.flatMap(2, addIfAboveOne); - Nullable.flatMap(-4, addIfAboveOne); - Nullable.flatMap(null, addIfAboveOne); - }); -}); - -Mocha.describe("Nullable.forEach", () => { - Mocha.test("Nullable.forEach", () => { - Nullable.forEach("thing", x => { - console.log(x); - }); - Nullable.forEach(null, x => { - console.log(x); - }); - Nullable.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Nullable.fromOption", () => { - Mocha.test("Nullable.fromOption", () => { - Nullable.fromOption("Hello"); - }); -}); - -Mocha.describe("Nullable.getExn", () => { - Mocha.test("Nullable.getExn", () => { - let exit = 0; - let value; - try { - value = 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", - 15869, - 35 - ], - Error: new Error() - }; - } - throw exn; - } - if (exit === 1) { - Pervasives.assertEqual(value, "Hello"); - } - let exit$1 = 0; - let val; - try { - val = 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", - 15875, - 7 - ], - Error: new Error() - }; - } - let exit$2 = 0; - let val$1; - try { - val$1 = 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", - 15880, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Nullable.getOr", () => { - Mocha.test("Nullable.getOr", () => { - Nullable.getOr(null, "Banana"); - Nullable.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet(Primitive_option.fromNullable("Jane")); - greet(undefined); - }); -}); - -Mocha.describe("Nullable.getUnsafe", () => { - Mocha.test("Nullable.getUnsafe", () => {}); -}); - -Mocha.describe("Nullable.isNullable", () => { - Mocha.test("Nullable.isNullable", () => { - if ("Hello" == null) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 15924, - 10 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Nullable.make", () => { - Mocha.test("Nullable.make", () => { - let myStr = "Hello"; - if ((myStr == null) || myStr !== myStr) { - console.log("Values did not match."); - } else { - console.log("Yay, values matched!"); - } - }); -}); - -Mocha.describe("Nullable.map", () => { - Mocha.test("Nullable.map", () => { - Nullable.map(3, x => Math.imul(x, x)); - Nullable.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Nullable.mapOr", () => { - Mocha.test("Nullable.mapOr", () => { - Nullable.mapOr(3, 0, x => x + 5 | 0); - Nullable.mapOr(null, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Nullable.null", () => { - Mocha.test("Nullable.null", () => { - console.log(null); - }); -}); - -Mocha.describe("Nullable.toOption", () => { - Mocha.test("Nullable.toOption", () => { - let nullableString = "Hello"; - if (nullableString == null) { - console.log("Didn't have a value."); - } else { - console.log("Got string:", nullableString); - } - }); -}); - -Mocha.describe("Nullable.undefined", () => { - Mocha.test("Nullable.undefined", () => { - console.log(undefined); - }); -}); - -Mocha.describe("Object.assign", () => { - Mocha.test("Object.assign", () => { - Object.assign({ - a: 1 - }, { - a: 2 - }); - Object.assign({ - a: 1, - b: 2 - }, { - a: 0 - }); - Object.assign({ - a: 1 - }, { - a: null - }); - }); -}); - -Mocha.describe("Object.create", () => { - Mocha.test("Object.create", () => { - let x = { - fruit: "banana" - }; - Object.create(x); - }); -}); - -Mocha.describe("Object.freeze", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16039, - 7 - ], - Error: new Error() - }; - } - - } - }); -}); - -Mocha.describe("Object.get", () => { - Mocha.test("Object.get", () => { - Option.isSome(({ - a: 1 - })["toString"]); - }); -}); - -Mocha.describe("Object.getSymbol", () => { - Mocha.test("Object.getSymbol", () => { - let fruit = Symbol("fruit"); - let x = {}; - x[fruit] = "banana"; - }); -}); - -Mocha.describe("Object.hasOwnProperty", () => { - Mocha.test("Object.hasOwnProperty", () => { - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "a"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "b"); - Object.prototype.hasOwnProperty.call({ - a: 1 - }, "toString"); - }); -}); - -Mocha.describe("Object.is", () => { - Mocha.test("Object.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.describe("Object.isExtensible", () => { - Mocha.test("Object.isExtensible", () => { - let obj = { - a: 1 - }; - Object.isExtensible(obj); - Object.preventExtensions(obj); - Object.isExtensible(obj); - }); -}); - -Mocha.describe("Object.isFrozen", () => { - Mocha.test("Object.isFrozen", () => { - let point = Object.freeze({ - x: 1, - y: 3 - }); - Object.isFrozen(point); - let fruit = { - name: "Apple" - }; - Object.isFrozen(fruit); - }); -}); - -Mocha.describe("Object.isSealed", () => { - Mocha.test("Object.isSealed", () => { - let point = Object.seal({ - x: 1, - y: 3 - }); - Object.isSealed(point); - let fruit = { - name: "Apple" - }; - Object.isSealed(fruit); - }); -}); - -Mocha.describe("Object.keysToArray", () => { - Mocha.test("Object.keysToArray", () => { - Object.keys({ - a: 1, - b: 2 - }); - Object.keys({ - a: undefined - }); - Object.keys({}); - }); -}); - -Mocha.describe("Object.make", () => { - Mocha.test("Object.make", () => { - let x = {}; - Object.keys(x).length; - Option.isSome(x["toString"]); - }); -}); - -Mocha.describe("Object.preventExtensions", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16175, - 7 - ], - Error: new Error() - }; - } - - } - }); -}); - -Mocha.describe("Object.seal", () => { - Mocha.test("Object.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 !== Exn.$$Error) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16193, - 7 - ], - Error: new Error() - }; - } - - } - point["x"] = 13; - }); -}); - -Mocha.describe("Object.set", () => { - Mocha.test("Object.set", () => { - ({ - a: 1 - })["a"] = 2; - ({ - a: 1 - })["a"] = undefined; - ({ - a: 1 - })["b"] = 2; - }); -}); - -Mocha.describe("Option.all", () => { - Mocha.test("Option.all", () => { - Option.all([ - 1, - 2, - 3 - ]); - Option.all([ - 1, - undefined - ]); - }); -}); - -Mocha.describe("Option.compare", () => { - Mocha.test("Option.compare", () => { - let clockCompare = (a, b) => Primitive_int.compare(a % 12, b % 12); - Option.compare(3, 15, clockCompare); - Option.compare(3, 14, clockCompare); - Option.compare(2, 15, clockCompare); - Option.compare(undefined, 15, clockCompare); - Option.compare(14, undefined, clockCompare); - Option.compare(undefined, undefined, clockCompare); - }); -}); - -Mocha.describe("Option.equal", () => { - Mocha.test("Option.equal", () => { - let clockEqual = (a, b) => a % 12 === b % 12; - Option.equal(3, 15, clockEqual); - Option.equal(3, undefined, clockEqual); - Option.equal(undefined, 3, clockEqual); - Option.equal(undefined, undefined, clockEqual); - }); -}); - -Mocha.describe("Option.filter", () => { - Mocha.test("Option.filter", () => { - Option.filter(10, x => x > 5); - Option.filter(4, x => x > 5); - Option.filter(undefined, x => x > 5); - }); -}); - -Mocha.describe("Option.flatMap", () => { - Mocha.test("Option.flatMap", () => { - let addIfAboveOne = value => { - if (value > 1) { - return value + 1 | 0; - } - - }; - Option.flatMap(2, addIfAboveOne); - Option.flatMap(-4, addIfAboveOne); - Option.flatMap(undefined, addIfAboveOne); - }); -}); - -Mocha.describe("Option.forEach", () => { - Mocha.test("Option.forEach", () => { - Option.forEach("thing", x => { - console.log(x); - }); - Option.forEach(undefined, x => { - console.log(x); - }); - }); -}); - -Mocha.describe("Option.getExn", () => { - Mocha.test("Option.getExn", () => { - Pervasives.assertEqual(Option.getExn(3, undefined), 3); - let exit = 0; - let val; - try { - val = Option.getExn(undefined, undefined); - exit = 1; - } catch (exn) { - - } - if (exit === 1) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16301, - 7 - ], - Error: new Error() - }; - } - let exit$1 = 0; - let val$1; - try { - val$1 = 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", - 16306, - 7 - ], - Error: new Error() - }; - } - - }); -}); - -Mocha.describe("Option.getOr", () => { - Mocha.test("Option.getOr", () => { - Option.getOr(undefined, "Banana"); - Option.getOr("Apple", "Banana"); - let greet = firstName => "Greetings " + Option.getOr(firstName, "Anonymous"); - greet("Jane"); - greet(undefined); - }); -}); - -Mocha.describe("Option.getUnsafe", () => { - Mocha.test("Option.getUnsafe", () => {}); -}); - -Mocha.describe("Option.isNone", () => { - Mocha.test("Option.isNone", () => { - Option.isNone(undefined); - Option.isNone(1); - }); -}); - -Mocha.describe("Option.isSome", () => { - Mocha.test("Option.isSome", () => { - Option.isSome(undefined); - Option.isSome(1); - }); -}); - -Mocha.describe("Option.map", () => { - Mocha.test("Option.map", () => { - Option.map(3, x => Math.imul(x, x)); - Option.map(undefined, x => Math.imul(x, x)); - }); -}); - -Mocha.describe("Option.mapOr", () => { - Mocha.test("Option.mapOr", () => { - Option.mapOr(3, 0, x => x + 5 | 0); - Option.mapOr(undefined, 0, x => x + 5 | 0); - }); -}); - -Mocha.describe("Option.orElse", () => { - Mocha.test("Option.orElse", () => { - Primitive_object.equal(Option.orElse(1812, 1066), 1812); - Primitive_object.equal(Option.orElse(undefined, 1066), 1066); - Option.orElse(undefined, undefined) === undefined; - }); -}); - -Mocha.describe("Pervasives.assertEqual", () => { - Mocha.test("Pervasives.assertEqual", () => { - Pervasives.assertEqual(List.tailExn({ - hd: 1, - tl: { - hd: 2, - tl: /* [] */0 - } - }), { - hd: 2, - tl: /* [] */0 - }); - }); -}); - -Mocha.describe("Pervasives.clearInterval", () => { - Mocha.test("Pervasives.clearInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints in 100 ms"); - }, 100); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); -}); - -Mocha.describe("Pervasives.clearTimeout", () => { - Mocha.test("Pervasives.clearTimeout", () => { - let timeoutId = setTimeout(() => { - console.log("This prints in 2 seconds."); - }, 2000); - clearTimeout(timeoutId); - }); -}); - -Mocha.describe("Pervasives.decodeURI", () => { - Mocha.test("Pervasives.decodeURI", () => { - console.log(decodeURI("https://rescript-lang.org?array=%5BsomeValue%5D")); - }); -}); - -Mocha.describe("Pervasives.decodeURIComponent", () => { - Mocha.test("Pervasives.decodeURIComponent", () => { - console.log(decodeURIComponent("array%3D%5BsomeValue%5D")); - }); -}); - -Mocha.describe("Pervasives.encodeURI", () => { - Mocha.test("Pervasives.encodeURI", () => { - console.log(encodeURI("https://rescript-lang.org?array=[someValue]")); - }); -}); - -Mocha.describe("Pervasives.encodeURIComponent", () => { - Mocha.test("Pervasives.encodeURIComponent", () => { - console.log(encodeURIComponent("array=[someValue]")); - }); -}); - -Mocha.describe("Pervasives.import", () => { - Mocha.test("Pervasives.import", () => {}); -}); - -Mocha.describe("Pervasives.setInterval", () => { - Mocha.test("Pervasives.setInterval", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms."); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500); - }); -}); - -Mocha.describe("Pervasives.setIntervalFloat", () => { - Mocha.test("Pervasives.setIntervalFloat", () => { - let intervalId = setInterval(() => { - console.log("This prints every 200 ms"); - }, 200); - setTimeout(() => { - clearInterval(intervalId); - }, 500.0); - }); -}); - -Mocha.describe("Pervasives.setTimeout", () => { - Mocha.test("Pervasives.setTimeout", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); -}); - -Mocha.describe("Pervasives.setTimeoutFloat", () => { - Mocha.test("Pervasives.setTimeoutFloat", () => { - setTimeout(() => { - console.log("This prints in 200 ms."); - }, 200); - }); -}); - -Mocha.describe("Promise.all", () => { - Mocha.test("Promise.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.describe("Promise.allSettled", () => { - Mocha.test("Promise.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.describe("Promise.any", () => { - Mocha.test("Promise.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.describe("Promise.catch", () => { - Mocha.test("Promise.catch", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - $$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 === 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.describe("Promise.finally", () => { - Mocha.test("Promise.finally", () => { - let SomeError = /* @__PURE__ */Primitive_exceptions.create("SomeError"); - let isDone = { - contents: false - }; - $$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.describe("Promise.make", () => { - Mocha.test("Promise.make", () => { - $$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.describe("Promise.race", () => { - Mocha.test("Promise.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.describe("Promise.reject", () => { - Mocha.test("Promise.reject", () => { - let TestError = /* @__PURE__ */Primitive_exceptions.create("TestError"); - $$Promise.$$catch(Promise.reject({ - RE_EXN_ID: TestError, - _1: "some rejected value" - }), v => { - if (v.RE_EXN_ID === TestError) { - Pervasives.assertEqual(v._1, "some rejected value"); - } else { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 16752, - 9 - ], - Error: new Error() - }; - } - return Promise.resolve(); - }); - }); -}); - -Mocha.describe("Promise.resolve", () => { - Mocha.test("Promise.resolve", () => { - Promise.resolve(5); - }); -}); - -Mocha.describe("Promise.then", () => { - Mocha.test("Promise.then", () => { - Promise.resolve(5).then(num => Promise.resolve(num + 5 | 0)).then(num => { - console.log("Your lucky number is: ", num); - return Promise.resolve(); - }); - }); -}); - -Mocha.describe("Promise.thenResolve", () => { - Mocha.test("Promise.thenResolve", () => { - Promise.resolve("Anna").then(str => "Hello " + str).then(str => { - console.log(str); - }); - }); -}); - -Mocha.describe("RegExp.Result.fullMatch", () => { - Mocha.test("RegExp.Result.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.describe("RegExp.Result.input", () => { - Mocha.test("RegExp.Result.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.describe("RegExp.Result.matches", () => { - Mocha.test("RegExp.Result.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("RegExp.exec", () => { - Mocha.test("RegExp.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.describe("RegExp.fromString", () => { - Mocha.test("RegExp.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.describe("RegExp.fromStringWithFlags", () => { - Mocha.test("RegExp.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.describe("RegExp.global", () => { - Mocha.test("RegExp.global", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.global); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.global); - }); -}); - -Mocha.describe("RegExp.ignoreCase", () => { - Mocha.test("RegExp.ignoreCase", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.ignoreCase); - let regexp2 = new RegExp("\\w+", "i"); - console.log(regexp2.ignoreCase); - }); -}); - -Mocha.describe("RegExp.lastIndex", () => { - Mocha.test("RegExp.lastIndex", () => { - let regexp = new RegExp("\\w+"); - console.log(regexp.lastIndex); - regexp.exec("Many words here."); - console.log(regexp.lastIndex); - }); -}); - -Mocha.describe("RegExp.multiline", () => { - Mocha.test("RegExp.multiline", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.multiline); - let regexp2 = new RegExp("\\w+", "mi"); - console.log(regexp2.multiline); - }); -}); - -Mocha.describe("RegExp.setLastIndex", () => { - Mocha.test("RegExp.setLastIndex", () => { - let regexp = new RegExp("\\w+"); - regexp.lastIndex = 4; - regexp.exec("Many words here."); - console.log(regexp.lastIndex); - }); -}); - -Mocha.describe("RegExp.source", () => { - Mocha.test("RegExp.source", () => { - let regexp = new RegExp("\\w+", "g"); - console.log(regexp.source); - }); -}); - -Mocha.describe("RegExp.sticky", () => { - Mocha.test("RegExp.sticky", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "my"); - console.log(regexp2.unicode); - }); -}); - -Mocha.describe("RegExp.test", () => { - Mocha.test("RegExp.test", () => { - let regexp = new RegExp("\\w+"); - if (regexp.test("ReScript is cool!")) { - console.log("Yay, there's a word in there."); - } - - }); -}); - -Mocha.describe("RegExp.unicode", () => { - Mocha.test("RegExp.unicode", () => { - let regexp1 = new RegExp("\\w+", "g"); - console.log(regexp1.unicode); - let regexp2 = new RegExp("\\w+", "mu"); - console.log(regexp2.unicode); - }); -}); - -Mocha.describe("Result.all", () => { - Mocha.test("Result.all", () => { - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Ok", - _0: 2 - }, - { - TAG: "Ok", - _0: 3 - } - ]); - Result.all([ - { - TAG: "Ok", - _0: 1 - }, - { - TAG: "Error", - _0: 1 - } - ]); - }); -}); - -Mocha.describe("Result.compare", () => { - Mocha.test("Result.compare", () => { - let mod10cmp = (a, b) => Primitive_int.compare(a % 10, b % 10); - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === 1; - Result.compare({ - TAG: "Ok", - _0: 57 - }, { - TAG: "Ok", - _0: 39 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Ok", - _0: 39 - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Ok", - _0: 57 - }, mod10cmp) === -1; - Result.compare({ - TAG: "Error", - _0: "x" - }, { - TAG: "Error", - _0: "y" - }, mod10cmp) === 0; - }); -}); - -Mocha.describe("Result.equal", () => { - Mocha.test("Result.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; - Result.equal(good1, good2, mod10equal) === true; - Result.equal(good1, bad1, mod10equal) === false; - Result.equal(bad2, good2, mod10equal) === false; - Result.equal(bad1, bad2, mod10equal) === true; - }); -}); - -Mocha.describe("Result.flatMap", () => { - Mocha.test("Result.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(Result.flatMap({ - TAG: "Ok", - _0: 2.0 - }, recip), { - TAG: "Ok", - _0: 0.5 - }); - Primitive_object.equal(Result.flatMap({ - TAG: "Ok", - _0: 0.0 - }, recip), { - TAG: "Error", - _0: "Divide by zero" - }); - Primitive_object.equal(Result.flatMap({ - TAG: "Error", - _0: "Already bad" - }, recip), { - TAG: "Error", - _0: "Already bad" - }); - }); -}); - -Mocha.describe("Result.forEach", () => { - Mocha.test("Result.forEach", () => { - Result.forEach({ - TAG: "Ok", - _0: 3 - }, prim => { - console.log(prim); - }); - Result.forEach({ - TAG: "Error", - _0: "x" - }, prim => { - console.log(prim); - }); - }); -}); - -Mocha.describe("Result.getOr", () => { - Mocha.test("Result.getOr", () => { - Result.getOr({ - TAG: "Ok", - _0: 42 - }, 0) === 42; - Result.getOr({ - TAG: "Error", - _0: "Invalid Data" - }, 0) === 0; - }); -}); - -Mocha.describe("Result.map", () => { - Mocha.test("Result.map", () => { - let f = x => Math.sqrt(x); - Primitive_object.equal(Result.map({ - TAG: "Ok", - _0: 64 - }, f), { - TAG: "Ok", - _0: 8.0 - }); - Primitive_object.equal(Result.map({ - TAG: "Error", - _0: "Invalid data" - }, f), { - TAG: "Error", - _0: "Invalid data" - }); - }); -}); - -Mocha.describe("Result.mapError", () => { - Mocha.test("Result.mapError", () => { - let format = n => "Error code: " + n.toString(); - Result.mapError({ - TAG: "Error", - _0: 14 - }, format); - Result.mapError({ - TAG: "Ok", - _0: "abc" - }, format); - }); -}); - -Mocha.describe("Result.mapOr", () => { - Mocha.test("Result.mapOr", () => { - Result.mapOr({ - TAG: "Ok", - _0: 42 - }, 0, x => x / 2 | 0) === 21; - Result.mapOr({ - TAG: "Error", - _0: "Invalid data" - }, 0, x => x / 2 | 0) === 0; - }); -}); - -Mocha.describe("Set.add", () => { - Mocha.test("Set.add", () => { - let set = new Set(); - set.add("someValue"); - }); -}); - -Mocha.describe("Set.clear", () => { - Mocha.test("Set.clear", () => { - let set = new Set(); - set.add("someKey"); - set.clear(); - }); -}); - -Mocha.describe("Set.delete", () => { - Mocha.test("Set.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.describe("Set.forEach", () => { - Mocha.test("Set.forEach", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue2"); - set.forEach(value => { - console.log(value); - }); - }); -}); - -Mocha.describe("Set.fromArray", () => { - Mocha.test("Set.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.describe("Set.fromIterator", () => { - Mocha.test("Set.fromIterator", () => { - let iterator = ((() => { - var array1 = ['a', 'b', 'c']; - var iterator1 = array1[Symbol.iterator](); - return iterator1 - })()); - Pervasives.assertEqual(new Set(iterator).size, 3); - }); -}); - -Mocha.describe("Set.has", () => { - Mocha.test("Set.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.describe("Set.make", () => { - Mocha.test("Set.make", () => { - new Set(); - let set = new Set(); - set.add("Fine name"); - }); -}); - -Mocha.describe("Set.size", () => { - Mocha.test("Set.size", () => { - let set = new Set(); - set.add("someValue"); - set.add("someValue"); - set.add("someValue2"); - }); -}); - -Mocha.describe("Set.toArray", () => { - Mocha.test("Set.toArray", () => { - let set = new Set([ - "apple", - "orange", - "apple", - "banana" - ]); - Array.from(set); - }); -}); - -Mocha.describe("Set.values", () => { - Mocha.test("Set.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("String.charAt", () => { - Mocha.test("String.charAt", () => { - "ReScript".charAt(0) === "R"; - "Hello".charAt(12) === ""; - "JS".charAt(5) === ""; - }); -}); - -Mocha.describe("String.charCodeAt", () => { - Mocha.test("String.charCodeAt", () => { - "😺".charCodeAt(0) === 55357; - Primitive_object.equal("😺".codePointAt(0), 128570); - }); -}); - -Mocha.describe("String.codePointAt", () => { - Mocha.test("String.codePointAt", () => { - Primitive_object.equal("¿😺?".codePointAt(1), 128570); - "abc".codePointAt(5) === undefined; - }); -}); - -Mocha.describe("String.concat", () => { - Mocha.test("String.concat", () => { - "cow".concat("bell") === "cowbell"; - "Re".concat("Script") === "ReScript"; - }); -}); - -Mocha.describe("String.concatMany", () => { - Mocha.test("String.concatMany", () => { - "1st".concat("2nd", "3rd", "4th") === "1st2nd3rd4th"; - }); -}); - -Mocha.describe("String.endsWith", () => { - Mocha.test("String.endsWith", () => { - "BuckleScript".endsWith("Script") === true; - "BuckleShoes".endsWith("Script") === false; - }); -}); - -Mocha.describe("String.endsWithFrom", () => { - Mocha.test("String.endsWithFrom", () => { - "abcd".endsWith("cd", 4) === true; - "abcde".endsWith("cd", 3) === false; - "abcde".endsWith("cde", 99) === true; - "example.dat".endsWith("ple", 7) === true; - }); -}); - -Mocha.describe("String.fromCharCode", () => { - Mocha.test("String.fromCharCode", () => { - String.fromCharCode(65) === "A"; - String.fromCharCode(968) === "ψ"; - String.fromCharCode(54620) === "한"; - String.fromCharCode(-64568) === "ψ"; - }); -}); - -Mocha.describe("String.fromCharCodeMany", () => { - Mocha.test("String.fromCharCodeMany", () => { - String.fromCharCode(189, 43, 190, 61) === "½+¾="; - String.fromCharCode(65, 66, 67) === "ABC"; - }); -}); - -Mocha.describe("String.fromCodePoint", () => { - Mocha.test("String.fromCodePoint", () => { - String.fromCodePoint(65) === "A"; - String.fromCodePoint(968) === "ψ"; - String.fromCodePoint(54620) === "한"; - String.fromCodePoint(128570) === "😺"; - }); -}); - -Mocha.describe("String.fromCodePointMany", () => { - Mocha.test("String.fromCodePointMany", () => { - String.fromCodePoint(54620, 44544, 128570) === "한글😺"; - }); -}); - -Mocha.describe("String.get", () => { - Mocha.test("String.get", () => { - Primitive_object.equal("ReScript"[0], "R"); - Primitive_object.equal("Hello"[4], "o"); - }); -}); - -Mocha.describe("String.getUnsafe", () => { - Mocha.test("String.getUnsafe", () => {}); -}); - -Mocha.describe("String.includes", () => { - Mocha.test("String.includes", () => { - "programmer".includes("gram") === true; - "programmer".includes("er") === true; - "programmer".includes("pro") === true; - "programmer.dat".includes("xyz") === false; - }); -}); - -Mocha.describe("String.includesFrom", () => { - Mocha.test("String.includesFrom", () => { - "programmer".includes("gram", 1) === true; - "programmer".includes("gram", 4) === false; - "대한민국".includes("한", 1) === true; - }); -}); - -Mocha.describe("String.indexOf", () => { - Mocha.test("String.indexOf", () => { - "bookseller".indexOf("ok") === 2; - "bookseller".indexOf("sell") === 4; - "beekeeper".indexOf("ee") === 1; - "bookseller".indexOf("xyz") === -1; - }); -}); - -Mocha.describe("String.indexOfFrom", () => { - Mocha.test("String.indexOfFrom", () => { - "bookseller".indexOf("ok", 1) === 2; - "bookseller".indexOf("sell", 2) === 4; - "bookseller".indexOf("sell", 5) === -1; - }); -}); - -Mocha.describe("String.indexOfOpt", () => { - Mocha.test("String.indexOfOpt", () => { - Primitive_object.equal($$String.indexOfOpt("bookseller", "ok"), 2); - $$String.indexOfOpt("bookseller", "xyz") === undefined; - }); -}); - -Mocha.describe("String.lastIndexOf", () => { - Mocha.test("String.lastIndexOf", () => { - "bookseller".lastIndexOf("ok") === 2; - "beekeeper".lastIndexOf("ee") === 4; - "abcdefg".lastIndexOf("xyz") === -1; - }); -}); - -Mocha.describe("String.lastIndexOfFrom", () => { - Mocha.test("String.lastIndexOfFrom", () => { - "bookseller".lastIndexOf("ok", 6) === 2; - "beekeeper".lastIndexOf("ee", 8) === 4; - "beekeeper".lastIndexOf("ee", 3) === 1; - "abcdefg".lastIndexOf("xyz", 4) === -1; - }); -}); - -Mocha.describe("String.lastIndexOfOpt", () => { - Mocha.test("String.lastIndexOfOpt", () => { - Primitive_object.equal($$String.lastIndexOfOpt("bookseller", "ok"), 2); - Primitive_object.equal($$String.lastIndexOfOpt("beekeeper", "ee"), 4); - $$String.lastIndexOfOpt("abcdefg", "xyz") === undefined; - }); -}); - -Mocha.describe("String.length", () => { - Mocha.test("String.length", () => {}); -}); - -Mocha.describe("String.localeCompare", () => { - Mocha.test("String.localeCompare", () => { - "a".localeCompare("c") < 0.0 === true; - "a".localeCompare("a") === 0.0; - }); -}); - -Mocha.describe("String.make", () => { - Mocha.test("String.make", () => { - String(3.5) === "3.5"; - String([ - 1, - 2, - 3 - ]) === "1,2,3"; - }); -}); - -Mocha.describe("String.match", () => { - Mocha.test("String.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.describe("String.normalize", () => { - Mocha.test("String.normalize", () => { - let string1 = "\u00F1"; - let string2 = "\u006E\u0303"; - if (string1 === string2) { - throw { - RE_EXN_ID: "Assert_failure", - _1: [ - "generated_mocha_test.res", - 17605, - 0 - ], - Error: new Error() - }; - } - Pervasives.assertEqual(string1.normalize(), string2.normalize()); - }); -}); - -Mocha.describe("String.normalizeForm", () => { - Mocha.test("String.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.describe("String.padEnd", () => { - Mocha.test("String.padEnd", () => { - "Hello".padEnd(10, ".") === "Hello....."; - "abc".padEnd(1, "") === "abc"; - }); -}); - -Mocha.describe("String.padStart", () => { - Mocha.test("String.padStart", () => { - "abc".padStart(5, " ") === " abc"; - "abc".padStart(6, "123465") === "123abc"; - }); -}); - -Mocha.describe("String.repeat", () => { - Mocha.test("String.repeat", () => { - "ha".repeat(3) === "hahaha"; - "empty".repeat(0) === ""; - }); -}); - -Mocha.describe("String.replace", () => { - Mocha.test("String.replace", () => { - "old string".replace("old", "new") === "new string"; - "the cat and the dog".replace("the", "this") === "this cat and the dog"; - }); -}); - -Mocha.describe("String.replaceAll", () => { - Mocha.test("String.replaceAll", () => { - "old old string".replaceAll("old", "new") === "new new string"; - "the cat and the dog".replaceAll("the", "this") === "this cat and this dog"; - }); -}); - -Mocha.describe("String.replaceAllRegExp", () => { - Mocha.test("String.replaceAllRegExp", () => { - "vowels be gone".replaceAll(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "aabbcc".replaceAll(/b/g, ".") === "aa..cc"; - }); -}); - -Mocha.describe("String.replaceRegExp", () => { - Mocha.test("String.replaceRegExp", () => { - "vowels be gone".replace(/[aeiou]/g, "x") === "vxwxls bx gxnx"; - "Juan Fulano".replace(/(\w+) (\w+)/, "$2, $1") === "Fulano, Juan"; - }); -}); - -Mocha.describe("String.search", () => { - Mocha.test("String.search", () => { - "testing 1 2 3".search(/\d+/) === 8; - "no numbers".search(/\d+/) === -1; - }); -}); - -Mocha.describe("String.searchOpt", () => { - Mocha.test("String.searchOpt", () => { - Primitive_object.equal($$String.searchOpt("testing 1 2 3", /\d+/), 8); - $$String.searchOpt("no numbers", /\d+/) === undefined; - }); -}); - -Mocha.describe("String.slice", () => { - Mocha.test("String.slice", () => { - "abcdefg".slice(2, 5) === "cde"; - "abcdefg".slice(2, 9) === "cdefg"; - "abcdefg".slice(-4, -2) === "de"; - "abcdefg".slice(5, 1) === ""; - }); -}); - -Mocha.describe("String.sliceToEnd", () => { - Mocha.test("String.sliceToEnd", () => { - "abcdefg".slice(4) === "efg"; - "abcdefg".slice(-2) === "fg"; - "abcdefg".slice(7) === ""; - }); -}); - -Mocha.describe("String.split", () => { - Mocha.test("String.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.describe("String.splitAtMost", () => { - Mocha.test("String.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.describe("String.splitByRegExp", () => { - Mocha.test("String.splitByRegExp", () => { - Primitive_object.equal("Jan,Feb,Mar".split(/,/), [ - "Jan", - "Feb", - "Mar" - ]); - }); -}); - -Mocha.describe("String.splitByRegExpAtMost", () => { - Mocha.test("String.splitByRegExpAtMost", () => { - Primitive_object.equal("Hello World. How are you doing?".split(/ /, 3), [ - "Hello", - "World.", - "How" - ]); - }); -}); - -Mocha.describe("String.startsWith", () => { - Mocha.test("String.startsWith", () => { - "BuckleScript".startsWith("Buckle") === true; - "BuckleScript".startsWith("") === true; - "JavaScript".startsWith("Buckle") === false; - }); -}); - -Mocha.describe("String.startsWithFrom", () => { - Mocha.test("String.startsWithFrom", () => { - "BuckleScript".startsWith("kle", 3) === true; - "BuckleScript".startsWith("", 3) === true; - "JavaScript".startsWith("Buckle", 2) === false; - }); -}); - -Mocha.describe("String.substring", () => { - Mocha.test("String.substring", () => { - "playground".substring(3, 6) === "ygr"; - "playground".substring(6, 3) === "ygr"; - "playground".substring(4, 12) === "ground"; - }); -}); - -Mocha.describe("String.substringToEnd", () => { - Mocha.test("String.substringToEnd", () => { - "playground".substring(4) === "ground"; - "playground".substring(-3) === "playground"; - "playground".substring(12) === ""; - }); -}); - -Mocha.describe("String.toLowerCase", () => { - Mocha.test("String.toLowerCase", () => { - "ABC".toLowerCase() === "abc"; - "ΣΠ".toLowerCase() === "σπ"; - "ΠΣ".toLowerCase() === "πς"; - }); -}); - -Mocha.describe("String.toUpperCase", () => { - Mocha.test("String.toUpperCase", () => { - "abc".toUpperCase() === "ABC"; - "Straße".toUpperCase() === "STRASSE"; - "πς".toUpperCase() === "ΠΣ"; - }); -}); - -Mocha.describe("String.trim", () => { - Mocha.test("String.trim", () => { - " abc def ".trim() === "abc def"; - "\n\r\t abc def \n\n\t\r ".trim() === "abc def"; - }); -}); - -Mocha.describe("String.trimEnd", () => { - Mocha.test("String.trimEnd", () => { - " Hello world! ".trimEnd() === " Hello world!"; - " Hello world! ".trimEnd() === " Hello world!"; - }); -}); - -Mocha.describe("String.trimStart", () => { - Mocha.test("String.trimStart", () => { - " Hello world! ".trimStart() === "Hello world! "; - " Hello world! ".trimStart() === "Hello world! "; - }); -}); - -Mocha.describe("String.unsafeReplaceRegExpBy0", () => { - Mocha.test("String.unsafeReplaceRegExpBy0", () => { - let re = /[aeiou]/g; - let matchFn = (match, param, param$1) => match.toUpperCase(); - "beautiful vowels".replace(re, matchFn) === "bEAUtIfUl vOwEls"; - }); -}); - -Mocha.describe("String.unsafeReplaceRegExpBy1", () => { - Mocha.test("String.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.describe("String.unsafeReplaceRegExpBy2", () => { - Mocha.test("String.unsafeReplaceRegExpBy2", () => { - let re = /(\d+) times (\d+)/; - let matchFn = (param, group1, group2, param$1, param$2) => { - let match = Int.fromString(group1, undefined); - let match$1 = Int.fromString(group2, undefined); - if (match !== undefined && match$1 !== undefined) { - return Math.imul(match, match$1).toString(); - } else { - return "???"; - } - }; - "7 times 6".replace(re, matchFn) === "42"; - }); -}); - -Mocha.describe("Type.Classify.classify", () => { - Mocha.test("Type.Classify.classify", () => { - let match = 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("Type.typeof", () => { - Mocha.test("Type.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 adfa1a90a5d15e5a026f280f5fed78df2f292b1d Mon Sep 17 00:00:00 2001 From: aspeddro Date: Sun, 29 Dec 2024 16:42:43 -0300 Subject: [PATCH 12/13] Remove `generated_mocha_test.res` if file exists --- scripts/test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/test.js b/scripts/test.js index cfe8a85939..0ebc642bd6 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -132,11 +132,21 @@ async function runTests() { console.log(`Skipping docstrings tests on ${process.platform}`); } else { console.log("Running runtime docstrings tests"); + + const generated_mocha_test_res = path.join("tests", "docstrings_examples", "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: path.join(__dirname, "..", "tests/docstrings_examples"), stdio: [0, 1, 2], }); + // Generate rescript file with all tests `generated_mocha_test.res` cp.execSync(`node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}`, { cwd: path.join(__dirname, ".."), @@ -151,7 +161,7 @@ async function runTests() { // Format generated_mocha_test.res console.log("Formatting generated_mocha_test.res") - cp.execSync(`./cli/rescript format ${path.join("tests", "docstrings_examples", "generated_mocha_test.res")}`, { + cp.execSync(`./cli/rescript format ${generated_mocha_test_res}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], }) From 59f1ab14df6704a1b4a2ab78c9dc1ba2f520bd46 Mon Sep 17 00:00:00 2001 From: aspeddro Date: Sun, 29 Dec 2024 19:32:21 -0300 Subject: [PATCH 13/13] format --- scripts/test.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/scripts/test.js b/scripts/test.js index 0ebc642bd6..e33d3add47 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -133,12 +133,16 @@ async function runTests() { } else { console.log("Running runtime docstrings tests"); - const generated_mocha_test_res = path.join("tests", "docstrings_examples", "generated_mocha_test.res") + const generated_mocha_test_res = path.join( + "tests", + "docstrings_examples", + "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) + console.log(`Removing ${generated_mocha_test_res}`); + fs.unlinkSync(generated_mocha_test_res); } cp.execSync(`${rescript_exe} build`, { @@ -146,12 +150,14 @@ async function runTests() { stdio: [0, 1, 2], }); - // Generate rescript file with all tests `generated_mocha_test.res` - cp.execSync(`node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}`, { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], - }) + cp.execSync( + `node ${path.join("tests", "docstrings_examples", "DocTest.res.mjs")}`, + { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }, + ); // Build again to check if generated_mocha_test.res has syntax or type erros cp.execSync(`${rescript_exe} build`, { @@ -160,17 +166,20 @@ async function runTests() { }); // Format generated_mocha_test.res - console.log("Formatting generated_mocha_test.res") + console.log("Formatting generated_mocha_test.res"); cp.execSync(`./cli/rescript format ${generated_mocha_test_res}`, { cwd: path.join(__dirname, ".."), stdio: [0, 1, 2], - }) - - console.log("Run mocha test") - cp.execSync(`npx mocha ${path.join("tests", "docstrings_examples", "generated_mocha_test.res.mjs")}`, { - cwd: path.join(__dirname, ".."), - stdio: [0, 1, 2], }); + + console.log("Run mocha test"); + cp.execSync( + `npx mocha ${path.join("tests", "docstrings_examples", "generated_mocha_test.res.mjs")}`, + { + cwd: path.join(__dirname, ".."), + stdio: [0, 1, 2], + }, + ); } } }