-
Notifications
You must be signed in to change notification settings - Fork 1
/
string.test.ts
36 lines (29 loc) · 1.11 KB
/
string.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
28
29
30
31
32
33
34
35
36
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';
import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';
import { string } from './string';
describe(string, () => {
it('accepts an arbitrary non-empty string', () => {
const decoder = string();
fc.assert(
fc.property(
fc.string().filter((x) => x !== ''),
(str) => {
const variable = new Variable('KEY', str);
expect(decoder(variable)).toStrictEqual(E.right(str));
},
),
);
});
it('rejects an empty string by default', () => {
const decoder = string();
const variable = new Variable('KEY', '');
expect(decoder(variable)).toStrictEqual(E.left(new DecodeFailed(variable, 'must be a non-empty string')));
});
it('accepts an empty string when explicitly allowed', () => {
const decoder = string({ allowEmpty: true });
const variable = new Variable('KEY', '');
expect(decoder(variable)).toStrictEqual(E.right(''));
});
});