Skip to content

Commit

Permalink
Test that number() rejects infinities
Browse files Browse the repository at this point in the history
  • Loading branch information
ryota-ka committed Jan 24, 2023
1 parent c01a056 commit 7d59a0a
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/VariableDecoder/number.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fc from 'fast-check';
import * as E from 'fp-ts/Either';

import { DecodeFailed } from '../EnvironmentError';
import { Variable } from '../Variable';

import { number } from './number';
Expand All @@ -10,10 +11,19 @@ describe(number, () => {
const decoder = number();

fc.assert(
fc.property(fc.float(), (n) => {
const variable = new Variable('KEY', String(n));
expect(decoder(variable)).toStrictEqual(E.right(n));
}),
fc.property(
fc.float().filter((x) => Number.isFinite(x)),
(n) => {
const variable = new Variable('KEY', String(n));
expect(decoder(variable)).toStrictEqual(E.right(n));
},
),
);
});

test.each([Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY])('rejects "%s"', (str) => {
const decoder = number();
const variable = new Variable('KEY', String(str));
expect(decoder(variable)).toStrictEqual(E.left(new DecodeFailed(variable, 'must be finite')));
});
});

0 comments on commit 7d59a0a

Please sign in to comment.