-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhex.test.ts
27 lines (23 loc) · 900 Bytes
/
hex.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';
import { hex } from './hex';
describe(hex, () => {
it('accepts an arbitrary non-empty hexadecimal string', () => {
fc.assert(
fc.property(
fc.hexaString().filter((str) => str !== ''),
(str) => {
const variable = new Variable('KEY', str);
const buf = Buffer.from(str, 'hex');
expect(hex()(variable)).toStrictEqual(E.right(buf));
},
),
);
});
test.each(['', 'foo'])('rejects "%s"', (str) => {
const variable = new Variable('KEY', str);
expect(hex()(variable)).toStrictEqual(E.left(new DecodeFailed(variable, 'must be a valid hexadecimal string')));
});
});