Commit 3f4f120
authored
🗑️ Mark as deprecated most of char and string arbitraries (#5233)
**Description**
This PR deprecates all our past arbitraries of single characters. We
recommend to replace them by arbitraries on strings with `minLength` and
`maxLength` both set to `1`.
This PR also deprecates all string arbitraries except `string`,
`base64String`, `stringMatching` and `mixedCase`. All the deprecated
arbitraries could now be expressed using `fc.string` with a specific
`unit`. Here are our recommended migration paths:
- `asciiString` can be replaced by `fc.string({ unit: 'binary-ascii' })`
(identical behavior).
- `unicodeString` does not have direct equivalent in the recommended
world, we either recommend you to build a custom unit arbitrary (see 1
below) or to rely on existing units provided by `fc.string`. Depending
on what you wanted to achieve when selecting `fc.unicode` you may go for
either `'grapheme'` and related or `'binary'` and related. On our side,
we rather recommend to rely on `'grapheme'` and related builders as they
better fit with the definition of what is a grapheme from an Unicode
point of view.
- `string16bits` does not have direct equivalent in the recommended
world (you may read the text written above for `unicodeString` for more
recommendations). See 2 below for an exact conversion.
- `fullUnicodeString` can be replaced by `fc.string({ unit: 'binary' })`
(identical behavior), that said we rather recommend you to go for
`fc.string({ unit: 'grapheme' })` or `fc.string({ unit:
'grapheme-composite' })`.
- `hexaString` does not have direct equivalent in the recommended world.
See 3 below for an exact conversion.
**(1) Converting `unicodeString` to `string`:**
```ts
const gapSize = 0xdfff + 1 - 0xd800;
function unicodeMapper(v: number) {
if (v < 0xd800) return v;
return v + gapSize;
}
function unicode(): fc.Arbitrary<string> {
return fc.integer({ min: 0x00, max: 0xff }).map(n => String.fromCodePoint(unicodeMapper(n)));
}
function unicodeString(constraints: fc.StringConstraints = {}): fc.Arbitrary<string> {
return fc.string({ ...constraints, unit: unicode() });
}
```
**(2) Converting `string16bits` to `string`:**
```ts
function char16bits(): fc.Arbitrary<string> {
return fc.integer({ min: 0x0000, max: 0xffff }).map(n => String.fromCodePoint(n));
}
function string16bits(constraints: fc.StringConstraints = {}): fc.Arbitrary<string> {
return fc.string({ ...constraints, unit: char16bits() });
}
```
**(3) Converting `hexaString` to `string`:**
```ts
const items = '0123456789abcdef';
function hexa(): fc.Arbitrary<string> {
return fc.integer({ min: 0, max: 15 }).map(n => items[n]);
}
function hexaString(constraints: fc.StringConstraints = {}): fc.Arbitrary<string> {
return fc.string({ ...constraints, unit: hexa() });
}
```
<!-- Please provide a short description and potentially linked issues
justifying the need for this PR -->
<!-- * Your PR is fixing a bug or regression? Check for existing issues
related to this bug and link them -->
<!-- * Your PR is adding a new feature? Make sure there is a related
issue or discussion attached to it -->
<!-- You can provide any additional context to help into understanding
what's this PR is attempting to solve: reproduction of a bug, code
snippets... -->
**Checklist** — _Don't delete this checklist and make sure you do the
following before opening the PR_
- [x] The name of my PR follows [gitmoji](https://gitmoji.dev/)
specification
- [x] My PR references one of several related issues (if any)
- [x] New features or breaking changes must come with an associated
Issue or Discussion
- [x] My PR does not add any new dependency without an associated Issue
or Discussion
- [x] My PR includes bumps details, please run `yarn bump` and flag the
impacts properly
- [x] My PR adds relevant tests and they would have failed without my PR
(when applicable)
<!-- More about contributing at
https://github.com/dubzzz/fast-check/blob/main/CONTRIBUTING.md -->
**Advanced**
<!-- How to fill the advanced section is detailed below! -->
- [x] Category: 🗑️ Deprecating
- [x] Impacts: API reduction
<!-- [Category] Please use one of the categories below, it will help us
into better understanding the urgency of the PR -->
<!-- * ✨ Introduce new features -->
<!-- * 📝 Add or update documentation -->
<!-- * ✅ Add or update tests -->
<!-- * 🐛 Fix a bug -->
<!-- * 🏷️ Add or update types -->
<!-- * ⚡️ Improve performance -->
<!-- * _Other(s):_ ... -->
<!-- [Impacts] Please provide a comma separated list of the potential
impacts that might be introduced by this change -->
<!-- * Generated values: Can your change impact any of the existing
generators in terms of generated values, if so which ones? when? -->
<!-- * Shrink values: Can your change impact any of the existing
generators in terms of shrink values, if so which ones? when? -->
<!-- * Performance: Can it require some typings changes on user side?
Please give more details -->
<!-- * Typings: Is there a potential performance impact? In which cases?
-->1 parent a14bc3a commit 3f4f120
File tree
17 files changed
+40
-19
lines changed- .yarn/versions
- packages/fast-check/src/arbitrary
- website/docs/core-blocks/arbitraries
- combiners
- primitives
17 files changed
+40
-19
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
0 commit comments