simplify 'struct'
This commit is contained in:
parent
43342e90d4
commit
366b1ec4e0
3 changed files with 57 additions and 52 deletions
38
tests/struct.js
Normal file
38
tests/struct.js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue