rescript-test
Version:
> A lightweight test framework for ReScript
135 lines (114 loc) • 3.97 kB
JavaScript
// Generated by ReScript, PLEASE EDIT WITH CARE
import * as Test from "../src/Test.mjs";
import * as Caml_obj from "rescript/lib/es6/caml_obj.js";
import * as Belt_MapString from "rescript/lib/es6/belt_MapString.js";
function equal(message, a, b) {
Test.assertion(message, "equal", (function (a, b) {
return a === b;
}), a, b);
}
function deepEqual(message, a, b) {
Test.assertion(message, "deepEqual", Caml_obj.equal, a, b);
}
Test.testAsync("Async", undefined, (function (cb) {
setTimeout((function () {
Test.pass(undefined, undefined);
cb(undefined, undefined);
}), 100);
}));
Test.test("Equals", (function () {
equal(undefined, 1, 1);
}));
function isCharCode(a, b) {
return a.charCodeAt(0) === b;
}
Test.test("Custom comparator", (function () {
Test.assertion("Char code should match", "isCharCode", isCharCode, "a", 97.0);
}));
Test.test("DeepEquals", (function () {
equal(undefined, "user", "user");
deepEqual(undefined, {
username: "user",
id: "a"
}, {
username: "user",
id: "a"
});
}));
var testWithSetup = Test.createTestWith((function () {
return {
contents: 0
};
}), undefined);
testWithSetup("Setup", (function (someRef) {
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 1);
}));
testWithSetup("Setup", (function (someRef) {
equal(undefined, someRef.contents, 0);
someRef.contents = someRef.contents + 1 | 0;
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 2);
}));
var testWithSetupAndTeardown = Test.createTestWith((function () {
return {
contents: 0
};
}), (function (someRef) {
someRef.contents = 0;
}));
testWithSetupAndTeardown("Setup & teardown", (function (someRef) {
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 1);
}));
testWithSetupAndTeardown("Setup & teardown 2", (function (someRef) {
equal(undefined, someRef.contents, 0);
someRef.contents = someRef.contents + 1 | 0;
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 2);
}));
var testAsyncWithSetupAndTeardown = Test.createTestAsyncWith((function () {
return {
contents: 0
};
}), (function (someRef) {
someRef.contents = 0;
}));
testAsyncWithSetupAndTeardown("Async setup & teardown", undefined, (function (someRef, callback) {
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 1);
callback(undefined, undefined);
}));
testAsyncWithSetupAndTeardown("Async setup & teardown 2", undefined, (function (someRef, callback) {
equal(undefined, someRef.contents, 0);
someRef.contents = someRef.contents + 1 | 0;
someRef.contents = someRef.contents + 1 | 0;
equal(undefined, someRef.contents, 2);
callback(undefined, undefined);
}));
function stringMapEqual(message, a, b) {
Test.assertion(message, "stringMapEqual", (function (a, b) {
return Belt_MapString.eq(a, b, (function (a, b) {
return a === b;
}));
}), a, b);
}
Test.test("Cutom operator Equals", (function () {
stringMapEqual(undefined, Belt_MapString.fromArray([[
"a",
1
]]), Belt_MapString.fromArray([[
"a",
1
]]));
}));
export {
equal ,
deepEqual ,
isCharCode ,
testWithSetup ,
testWithSetupAndTeardown ,
testAsyncWithSetupAndTeardown ,
stringMapEqual ,
}
/* Not a pure module */