From 84b8abd6998410eeb6cbe66e5e0d041cce019f0d Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Tue, 12 Mar 2024 18:09:31 -0700 Subject: [PATCH] fixup! merge repair --- .../test/encodePassable-for-testing.js | 13 ++++- packages/marshal/test/test-encodePassable.js | 53 +++++++++++++++++-- .../marshal/test/test-string-rank-order.js | 2 +- .../patterns/test/test-string-key-order.js | 3 +- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/packages/marshal/test/encodePassable-for-testing.js b/packages/marshal/test/encodePassable-for-testing.js index bb480c1d9b..032383bf95 100644 --- a/packages/marshal/test/encodePassable-for-testing.js +++ b/packages/marshal/test/encodePassable-for-testing.js @@ -54,12 +54,23 @@ const encodePassableInternal = makeEncodePassable({ encodeError: er => encodeThing('!', er), }); +export const encodePassableInternal2 = makeEncodePassable({ + encodeRemotable: r => encodeThing('r', r), + encodePromise: p => encodeThing('?', p), + encodeError: er => encodeThing('!', er), + format: 'compactOrdered', +}); + export const encodePassable = passable => { resetBuffers(); return encodePassableInternal(passable); }; -const decodePassableInternal = makeDecodePassable({ +export const encodePassable2 = passable => { + resetBuffers(); + return encodePassableInternal2(passable); +}; +export const decodePassableInternal = makeDecodePassable({ decodeRemotable: e => decodeThing('r', e), decodePromise: e => decodeThing('?', e), decodeError: e => decodeThing('!', e), diff --git a/packages/marshal/test/test-encodePassable.js b/packages/marshal/test/test-encodePassable.js index 2cdc637431..d539b7df08 100644 --- a/packages/marshal/test/test-encodePassable.js +++ b/packages/marshal/test/test-encodePassable.js @@ -1,3 +1,4 @@ +// @ts-nocheck /* eslint-disable no-bitwise, @endo/restrict-comparison-operands */ import test from '@endo/ses-ava/prepare-endo.js'; @@ -6,17 +7,61 @@ import { Remotable } from '@endo/pass-style'; import { arbPassable } from '@endo/pass-style/tools.js'; import { Fail } from '@endo/errors'; -// eslint-disable-next-line import/no-extraneous-dependencies - +import { makePassableKit, makeEncodePassable } from '../src/encodePassable.js'; import { compareRank } from '../src/rankOrder.js'; -import { sample } from './test-rankOrder.js'; +import { unsortedSample } from './marshal-test-data.js'; import { encodePassable, + encodePassable2, + encodePassableInternal2, decodePassable, + decodePassableInternal, compareFull, } from './encodePassable-for-testing.js'; +test('makePassableKit output shape', t => { + const kit = makePassableKit(); + t.deepEqual(Reflect.ownKeys(kit).sort(), [ + 'decodePassable', + 'encodePassable', + ]); + t.deepEqual( + Object.fromEntries( + Object.entries(kit).map(([key, value]) => [key, typeof value]), + ), + { encodePassable: 'function', decodePassable: 'function' }, + ); +}); + +const verifyEncodeOptions = test.macro({ + title: label => `${label} encode options validation`, + // eslint-disable-next-line no-shadow + exec: (t, makeEncodePassable) => { + t.notThrows(() => makeEncodePassable(), 'must accept zero arguments'); + t.notThrows(() => makeEncodePassable({}), 'must accept empty options'); + t.notThrows( + () => makeEncodePassable({ format: 'legacyOrdered' }), + 'must accept format: "legacyOrdered"', + ); + t.notThrows( + () => makeEncodePassable({ format: 'compactOrdered' }), + 'must accept format: "compactOrdered"', + ); + t.throws( + () => makeEncodePassable({ format: 'newHotness' }), + { message: /^Unrecognized format\b/ }, + 'must reject unknown format', + ); + }, +}); +test('makeEncodePassable', verifyEncodeOptions, makeEncodePassable); +test( + 'makePassableKit', + verifyEncodeOptions, + (...args) => makePassableKit(...args).encodePassable, +); + const asNumber = new Float64Array(1); const asBits = new BigUint64Array(asNumber.buffer); const getNaN = (hexEncoding = '0008000000000000') => { @@ -31,7 +76,7 @@ const getNaN = (hexEncoding = '0008000000000000') => { const NegativeNaN = getNaN('ffffffffffffffff'); -/** @type {[number | bigint, string][]} */ +/** @type {[Key, string][]} */ const goldenPairs = harden([ [1, 'fbff0000000000000'], [-1, 'f400fffffffffffff'], diff --git a/packages/marshal/test/test-string-rank-order.js b/packages/marshal/test/test-string-rank-order.js index b80ab0be9f..b8c5333d44 100644 --- a/packages/marshal/test/test-string-rank-order.js +++ b/packages/marshal/test/test-string-rank-order.js @@ -1,4 +1,4 @@ -import { test } from './prepare-test-env-ava.js'; +import test from '@endo/ses-ava/prepare-endo.js'; import { compareRank } from '../src/rankOrder.js'; import { encodePassable } from './encodePassable-for-testing.js'; diff --git a/packages/patterns/test/test-string-key-order.js b/packages/patterns/test/test-string-key-order.js index c1a1f3d293..28c04c0c6c 100644 --- a/packages/patterns/test/test-string-key-order.js +++ b/packages/patterns/test/test-string-key-order.js @@ -1,6 +1,5 @@ // modeled on test-string-rank-order.js - -import { test } from './prepare-test-env-ava.js'; +import test from '@endo/ses-ava/prepare-endo.js'; import { compareKeys } from '../src/keys/compareKeys.js';