38 lines
1 KiB
JavaScript
38 lines
1 KiB
JavaScript
import assert from "node:assert";
|
|
|
|
import { makeTypeConstructor } from "../lib/meta/type_constructor.js";
|
|
import { Bool, Char, Int } from "../lib/primitives/primitive_types.js";
|
|
import { makeModuleStruct } from "../lib/structures/struct.types.js";
|
|
import { lsType } from "../lib/structures/type_constructors.types.js";
|
|
|
|
|
|
const symbolPerson = "Person__22a59ca589b4a7efdbe20b52f380e50f";
|
|
|
|
const Person = makeTypeConstructor(symbolPerson)(0);
|
|
|
|
const fields = [
|
|
{l: "name", r: lsType(_ => Char)},
|
|
{l: "age", r: Int},
|
|
{l: "isMale", r: Bool},
|
|
];
|
|
|
|
const [
|
|
[, {i: newPerson}],
|
|
[, {i: getName}],
|
|
[, {i: getAge}],
|
|
[, {i: getIsMale}],
|
|
] = makeModuleStruct(Person)(fields);
|
|
|
|
const expectedName = "billy";
|
|
const expectedAge = 99;
|
|
const expectedIsMale = true;
|
|
|
|
const billy = newPerson(expectedName)(expectedAge)(expectedIsMale);
|
|
|
|
const actualName = getName(billy);
|
|
const actualAge = getAge(billy);
|
|
const actualIsMale = getIsMale(billy);
|
|
|
|
assert.equal(actualName, expectedName);
|
|
assert.equal(actualAge, expectedAge);
|
|
assert.equal(actualIsMale, expectedIsMale);
|