|
1 | | -import { describe, expect, test } from '@jest/globals' |
| 1 | +import { test } from '@fast-check/jest' |
| 2 | +import { describe, expect } from '@jest/globals' |
2 | 3 | import * as O from 'fp-ts/Option' |
3 | 4 | import * as _ from '../src' |
4 | 5 | import * as fc from './fc' |
5 | 6 |
|
6 | 7 | describe('doi-ts', () => { |
7 | 8 | describe('destructors', () => { |
8 | | - test('toUrl', () => { |
9 | | - fc.assert( |
10 | | - fc.property(fc.doi(), doi => { |
11 | | - expect(_.toUrl(doi)).toStrictEqual(new URL(`https://doi.org/${doi}`)) |
12 | | - }), |
13 | | - ) |
| 9 | + test.prop([fc.doi()])('toUrl', doi => { |
| 10 | + expect(_.toUrl(doi)).toStrictEqual(new URL(`https://doi.org/${doi}`)) |
14 | 11 | }) |
15 | 12 | }) |
16 | 13 |
|
17 | 14 | describe('instances', () => { |
18 | 15 | describe('Eq', () => { |
19 | | - test('with the same DOI', () => { |
20 | | - fc.assert( |
21 | | - fc.property(fc.doi(), doi => { |
22 | | - expect(_.Eq.equals(doi, doi)).toBe(true) |
23 | | - }), |
24 | | - ) |
| 16 | + test.prop([fc.doi()])('with the same DOI', doi => { |
| 17 | + expect(_.Eq.equals(doi, doi)).toBe(true) |
25 | 18 | }) |
26 | 19 |
|
27 | | - test('with the same DOI in different cases', () => { |
28 | | - fc.assert( |
29 | | - fc.property(fc.doi(), doi => { |
30 | | - expect(_.Eq.equals(doi, doi.toLowerCase() as _.Doi)).toBe(true) |
31 | | - }), |
32 | | - ) |
| 20 | + test.prop([fc.doi()])('with the same DOI in different cases', doi => { |
| 21 | + expect(_.Eq.equals(doi, doi.toLowerCase() as _.Doi)).toBe(true) |
33 | 22 | }) |
34 | 23 |
|
35 | | - test('with different DOIs', () => { |
36 | | - fc.assert( |
37 | | - fc.property(fc.doi(), fc.doi(), (doi1, doi2) => { |
38 | | - expect(_.Eq.equals(doi1, doi2)).toBe(false) |
39 | | - }), |
40 | | - ) |
| 24 | + test.prop([fc.doi(), fc.doi()])('with different DOIs', (doi1, doi2) => { |
| 25 | + expect(_.Eq.equals(doi1, doi2)).toBe(false) |
41 | 26 | }) |
42 | 27 | }) |
43 | 28 | }) |
44 | 29 |
|
45 | 30 | describe('refinements', () => { |
46 | 31 | describe('isDoi', () => { |
47 | | - test('with a DOI', () => { |
48 | | - fc.assert( |
49 | | - fc.property(fc.doi(), doi => { |
50 | | - expect(_.isDoi(doi)).toBe(true) |
51 | | - }), |
52 | | - ) |
| 32 | + test.prop([fc.doi()])('with a DOI', doi => { |
| 33 | + expect(_.isDoi(doi)).toBe(true) |
53 | 34 | }) |
54 | 35 |
|
55 | | - test('with a non-DOI', () => { |
56 | | - fc.assert( |
57 | | - fc.property(fc.anything(), value => { |
58 | | - expect(_.isDoi(value)).toBe(false) |
59 | | - }), |
60 | | - ) |
| 36 | + test.prop([fc.anything()])('with a non-DOI', value => { |
| 37 | + expect(_.isDoi(value)).toBe(false) |
61 | 38 | }) |
62 | 39 | }) |
63 | 40 |
|
64 | 41 | describe('hasRegistrant', () => { |
65 | | - test('when the registrant matches', () => { |
66 | | - fc.assert( |
67 | | - fc.property( |
68 | | - fc |
69 | | - .array(fc.registrant(), { minLength: 1 }) |
70 | | - .chain(registrants => fc.tuple(fc.constant(registrants), fc.doi(fc.constantFrom(...registrants)))), |
71 | | - ([registrants, doi]) => { |
72 | | - expect(_.hasRegistrant(...registrants)(doi)).toBe(true) |
73 | | - }, |
74 | | - ), |
75 | | - ) |
| 42 | + test.prop([ |
| 43 | + fc |
| 44 | + .array(fc.registrant(), { minLength: 1 }) |
| 45 | + .chain(registrants => fc.tuple(fc.constant(registrants), fc.doi(fc.constantFrom(...registrants)))), |
| 46 | + ])('when the registrant matches', ([registrants, doi]) => { |
| 47 | + expect(_.hasRegistrant(...registrants)(doi)).toBe(true) |
76 | 48 | }) |
77 | 49 |
|
78 | | - test('when the registrant does not match', () => { |
79 | | - fc.assert( |
80 | | - fc.property(fc.array(fc.registrant()), fc.doi(), (registrants, doi) => { |
81 | | - expect(_.hasRegistrant(...registrants)(doi)).toBe(false) |
82 | | - }), |
83 | | - ) |
| 50 | + test.prop([fc.array(fc.registrant()), fc.doi()])('when the registrant does not match', (registrants, doi) => { |
| 51 | + expect(_.hasRegistrant(...registrants)(doi)).toBe(false) |
84 | 52 | }) |
85 | 53 | }) |
86 | 54 | }) |
87 | 55 |
|
88 | 56 | describe('utils', () => { |
89 | 57 | describe('parse', () => { |
90 | | - test('when it contains a DOI', () => { |
91 | | - fc.assert( |
92 | | - fc.property( |
93 | | - fc |
94 | | - .tuple( |
95 | | - fc.doi(), |
96 | | - fc.stringOf(fc.constant(' ')), |
97 | | - fc.constantFrom( |
98 | | - 'doi:', |
99 | | - 'https://doi.org/', |
100 | | - 'http://doi.org/', |
101 | | - 'https://dx.doi.org/', |
102 | | - 'http://dx.doi.org/', |
103 | | - ), |
104 | | - fc.stringOf(fc.constant(' ')), |
105 | | - ) |
106 | | - .map(([doi, whitespaceBefore, prefix, whitespaceAfter]) => [ |
107 | | - doi, |
108 | | - `${whitespaceBefore}${prefix}${doi}${whitespaceAfter}`, |
109 | | - ]), |
110 | | - ([doi, input]) => { |
111 | | - expect(_.parse(input)).toStrictEqual(O.some(doi)) |
112 | | - }, |
113 | | - ), |
114 | | - ) |
| 58 | + test.prop([ |
| 59 | + fc |
| 60 | + .tuple( |
| 61 | + fc.doi(), |
| 62 | + fc.stringOf(fc.constant(' ')), |
| 63 | + fc.constantFrom('doi:', 'https://doi.org/', 'http://doi.org/', 'https://dx.doi.org/', 'http://dx.doi.org/'), |
| 64 | + fc.stringOf(fc.constant(' ')), |
| 65 | + ) |
| 66 | + .map(([doi, whitespaceBefore, prefix, whitespaceAfter]) => [ |
| 67 | + doi, |
| 68 | + `${whitespaceBefore}${prefix}${doi}${whitespaceAfter}`, |
| 69 | + ]), |
| 70 | + ])('when it contains a DOI', ([doi, input]) => { |
| 71 | + expect(_.parse(input)).toStrictEqual(O.some(doi)) |
115 | 72 | }) |
116 | 73 |
|
117 | | - test('when it does not contain a DOI', () => { |
118 | | - fc.assert( |
119 | | - fc.property(fc.unicodeString(), input => { |
120 | | - expect(_.parse(input)).toStrictEqual(O.none) |
121 | | - }), |
122 | | - ) |
| 74 | + test.prop([fc.unicodeString()])('when it does not contain a DOI', input => { |
| 75 | + expect(_.parse(input)).toStrictEqual(O.none) |
123 | 76 | }) |
124 | 77 | }) |
125 | 78 |
|
126 | | - test('getRegistrant', () => { |
127 | | - fc.assert( |
128 | | - fc.property( |
129 | | - fc.registrant().chain(registrant => fc.tuple(fc.constant(registrant), fc.doi(fc.constant(registrant)))), |
130 | | - ([registrant, doi]) => { |
131 | | - expect(_.getRegistrant(doi)).toBe(registrant) |
132 | | - }, |
133 | | - ), |
134 | | - ) |
| 79 | + test.prop([ |
| 80 | + fc.registrant().chain(registrant => fc.tuple(fc.constant(registrant), fc.doi(fc.constant(registrant)))), |
| 81 | + ])('getRegistrant', ([registrant, doi]) => { |
| 82 | + expect(_.getRegistrant(doi)).toBe(registrant) |
135 | 83 | }) |
136 | 84 | }) |
137 | 85 | }) |
0 commit comments