Skip to content

Commit

Permalink
refactor testIncludes for conciseness
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Gibson <[email protected]>
  • Loading branch information
dckc and gibson042 authored Nov 7, 2023
1 parent 03f4d44 commit ca7799a
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions proposals/53:kread-start/core-eval-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ export const getContractInfo = async (path, io = {}) => {
return m.fromCapData({ body, slots });
};

// not really core-eval related
/**
* Asserts that `haystack` includes `needle` (or when `sense` is false, that it
* does not), providing pretty output in the case of failure.
*
* @param {import('ava').ExecutionContext} t
* @param {unknown} needle
* @param {unknown[]} haystack
* @param {string} label
* @param {boolean} [sense] true to assert inclusion; false for exclusion
* @returns {void}
*/
export const testIncludes = (t, needle, haystack, label, sense = true) => {
t.log(needle, sense ? 'in' : 'not in', haystack.length, label, '?');
const check = sense ? t.deepEqual : t.notDeepEqual;
if (sense) {
t.deepEqual(
haystack.filter(c => c === needle),
[needle],
);
} else {
t.deepEqual(
haystack.filter(c => c === needle),
[],
);
}
const matches = haystack.filter(c => Object.is(c, needle));
t.deepEqual(matches, sense ? [needle] : [], label);
};

/**
Expand Down

0 comments on commit ca7799a

Please sign in to comment.