Skip to content

Commit

Permalink
Prefer examples for DOIs that need special handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Jan 26, 2024
1 parent 4f5a665 commit ba3f156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions test/Doi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,27 @@ describe('DoiSchema', () => {
})
})

test.prop([fc.doi().map(doi => [doi, new URL(`https://doi.org/${doi}`).href] satisfies [_.Doi, string])], {
examples: [
[[_.Doi('10.0001/journal/pone.0011111'), 'https://doi.org/10.0001/journal/pone.0011111']],
[
test.prop(
[
fc
.doi({ suffix: fc.string({ minLength: 1 }).filter(s => !/[\\/]/.test(s)) })
.map(doi => [doi, new URL(`https://doi.org/${doi}`).href] satisfies [_.Doi, string]),
],
{
examples: [
[[_.Doi('10.0001/journal/pone.0011111'), 'https://doi.org/10.0001/journal/pone.0011111']],
[
_.Doi('10.1002/(SICI)1096-8644(199808)106:4<483::AID-AJPA4>3.0.CO;2-K'),
'https://doi.org/10.1002/(SICI)1096-8644(199808)106:4%3C483::AID-AJPA4%3E3.0.CO;2-K',
[
_.Doi('10.1002/(SICI)1096-8644(199808)106:4<483::AID-AJPA4>3.0.CO;2-K'),
'https://doi.org/10.1002/(SICI)1096-8644(199808)106:4%3C483::AID-AJPA4%3E3.0.CO;2-K',
],
],
[[_.Doi('10.1000/./'), 'https://doi.org/10.1000/.%2F']],
[[_.Doi('10.1000/../'), 'https://doi.org/10.1000/..%2F']],
[[_.Doi('10.1000/\\'), 'https://doi.org/10.1000/%5C']],
[[_.Doi('10.1000/\u0000'), 'https://doi.org/10.1000/%00']],
],
[[_.Doi('10.1000/./'), 'https://doi.org/10.1000/.%2F']],
[[_.Doi('10.1000/../'), 'https://doi.org/10.1000/..%2F']],
[[_.Doi('10.1000/\\'), 'https://doi.org/10.1000/%5C']],
],
})('toUrl', ([doi, url]) => {
},
)('toUrl', ([doi, url]) => {
expect(_.toUrl(doi).href).toStrictEqual(url)
})
4 changes: 2 additions & 2 deletions test/fc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export const plainDate = (): fc.Arbitrary<Temporal.PlainDate> =>
})
.map(args => Temporal.PlainDate.from(args))

export const doi = (): fc.Arbitrary<Doi.Doi> =>
export const doi = ({ suffix }: { suffix?: fc.Arbitrary<string> } = {}): fc.Arbitrary<Doi.Doi> =>
fc
.tuple(doiRegistrant(), fc.unicodeString({ minLength: 1 }))
.tuple(doiRegistrant(), suffix ?? fc.unicodeString({ minLength: 1 }))
.map(([prefix, suffix]) => `10.${prefix}/${suffix}` as Doi.Doi)
.filter(s => doiRegex({ exact: true }).test(s) && !s.endsWith('/.') && !s.endsWith('/..'))

Expand Down

0 comments on commit ba3f156

Please sign in to comment.