Skip to content

Commit

Permalink
🧪 test(dist): Make tests run.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Oct 29, 2022
1 parent 37678e4 commit a7a415a
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions test/src/_fixtures.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,58 @@
import {
eq0,
eq1,
eq_1,
le0,
lt0,
ge0,
gt0,
le1,
lt1,
ge1,
gt1,
ge,
lt,
le,
gt,
eq,
ne,
} from '#module';

const _names = new Map([
[eq0, 'eq0'],
[eq1, 'eq1'],
[eq_1, 'eq_1'],
[le0, 'le0'],
[lt0, 'lt0'],
[ge0, 'ge0'],
[gt0, 'gt0'],
[le1, 'le1'],
[lt1, 'lt1'],
[ge1, 'ge1'],
[gt1, 'gt1'],
[ge, 'ge'],
[lt, 'lt'],
[le, 'le'],
[gt, 'gt'],
[eq, 'eq'],
[ne, 'ne'],
]);

const name = (f) => _names.get(f) ?? f.name;

export const macro = (t, expected, f, ...args) => {
t.is(f(...args), expected);
};

macro.title = (title, expected, f, ...args) =>
title ?? `${f.name}(${args.join(', ')}) is ${JSON.stringify(expected)}`;
title ?? `${name(f)}(${args.join(', ')}) is ${JSON.stringify(expected)}`;

const throws = (t, expected, f, ...args) => {
t.throws(() => f(...args), expected);
};

throws.title = (title, expected, f, ...args) => {
return (
title ?? `${f.name}(${args.join(', ')}) throws ${JSON.stringify(expected)}`
title ?? `${name(f)}(${args.join(', ')}) throws ${JSON.stringify(expected)}`
);
};

0 comments on commit a7a415a

Please sign in to comment.