Skip to content

Commit

Permalink
test(exo): test explicit M.rawValue()
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Oct 18, 2023
1 parent 8109f8d commit 25f027a
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions packages/exo/test/test-heap-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,49 @@ test('sloppy option', t => {

const RawGreeterI = M.interface('greeter', {}, { defaultGuards: 'raw' });

test('raw defaultGuards', t => {
const testGreeter = (t, greeter, msg) => {
const mutable = {};
t.is(greeter.sayHello(mutable), 'hello', `${msg} can sayHello`);
t.deepEqual(mutable, { x: 3 }, `${msg} mutable is mutated`);
mutable.y = 4;
t.deepEqual(mutable, { x: 3, y: 4 }, `${msg} mutable is mutated again}`);
};

test('rawValues', t => {
const greeter = makeExo('greeter', RawGreeterI, {
sayHello(mutable) {
mutable.x = 3;
return 'hello';
},
});
const mutable = {};
t.is(greeter.sayHello(mutable), 'hello');
t.deepEqual(mutable, { x: 3 });
mutable.y = 4;
t.deepEqual(mutable, { x: 3, y: 4 });
t.deepEqual(greeter[GET_INTERFACE_GUARD](), RawGreeterI);
testGreeter(t, greeter, 'raw defaultGuards');

const Greeter2I = M.interface('greeter2', {
sayHello: M.call(M.rawValue()).returns(M.string()),
tortuous: M.call(M.any(), M.rawValue(), M.any())
.optional(M.any(), M.rawValue())
.returns(M.any()),
});
const greeter2 = makeExo('greeter2', Greeter2I, {
sayHello(mutable) {
mutable.x = 3;
return 'hello';
},
tortuous(hardA, softB, hardC, optHardD, optSoftE = {}) {
t.is(Object.isFrozen(hardA), true);
t.is(Object.isFrozen(softB), false);
softB.b = 2;
t.is(Object.isFrozen(hardC), true);
t.is(Object.isFrozen(optHardD), true);
t.is(Object.isFrozen(optSoftE), false);
return {};
},
});
t.deepEqual(greeter2[GET_INTERFACE_GUARD](), Greeter2I);
testGreeter(t, greeter, 'explicit rawValue');
t.is(Object.isFrozen(greeter2.tortuous({}, {}, {}, {}, {})), true);
t.is(Object.isFrozen(greeter2.tortuous({}, {}, {})), true);
});

const GreeterI = M.interface('greeter', {
Expand Down

0 comments on commit 25f027a

Please sign in to comment.