diff --git a/packages/exo/test/test-heap-classes.js b/packages/exo/test/test-heap-classes.js index c81f650357..61716b4a52 100644 --- a/packages/exo/test/test-heap-classes.js +++ b/packages/exo/test/test-heap-classes.js @@ -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', {