Skip to content

Commit 3f4f120

Browse files
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

17 files changed

+40
-19
lines changed

.yarn/versions/2d16b9e2.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
releases:
2+
fast-check: minor
3+
4+
declined:
5+
- "@fast-check/ava"
6+
- "@fast-check/jest"
7+
- "@fast-check/vitest"
8+
- "@fast-check/worker"

packages/fast-check/src/arbitrary/ascii.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { indexToPrintableIndexMapper, indexToPrintableIndexUnmapper } from './_i
44

55
/**
66
* For single ascii characters - char code between 0x00 (included) and 0x7f (included)
7+
* @deprecated Please use ${@link string} with `fc.string({ unit: 'binary-ascii', minLength: 1, maxLength: 1 })` instead
78
* @remarks Since 0.0.1
89
* @public
910
*/

packages/fast-check/src/arbitrary/asciiString.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const safeObjectAssign = Object.assign;
1414
*
1515
* @param constraints - Constraints to apply when building instances (since 2.4.0)
1616
*
17+
* @deprecated Please use ${@link string} with `fc.string({ unit: 'binary-ascii', ...constraints })` instead
1718
* @remarks Since 0.0.1
1819
* @public
1920
*/

packages/fast-check/src/arbitrary/base64.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function base64Unmapper(v: number) {
1919

2020
/**
2121
* For single base64 characters - A-Z, a-z, 0-9, + or /
22+
* @deprecated Prefer using `fc.constantFrom(...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/')`
2223
* @remarks Since 0.0.1
2324
* @public
2425
*/

packages/fast-check/src/arbitrary/char.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function identity(v: number) {
1111
*
1212
* {@link https://www.ascii-code.com/}
1313
*
14+
* @deprecated Please use ${@link string} with `fc.string({ minLength: 1, maxLength: 1 })` instead
1415
* @remarks Since 0.0.1
1516
* @public
1617
*/

packages/fast-check/src/arbitrary/char16bits.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { indexToPrintableIndexMapper, indexToPrintableIndexUnmapper } from './_i
1010
* Some generated characters might appear invalid regarding UCS-2 and UTF-16 encoding.
1111
* Indeed values within 0xd800 and 0xdfff constitute surrogate pair characters and are illegal without their paired character.
1212
*
13+
* @deprecated Please use ${@link string} with `fc.string({ unit, minLength: 1, maxLength: 1 })`, utilizing one of its unit variants instead
1314
* @remarks Since 0.0.11
1415
* @public
1516
*/

packages/fast-check/src/arbitrary/fullUnicode.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function unicodeUnmapper(v: number) {
3030
*
3131
* {@link https://tc39.github.io/ecma262/#sec-utf16encoding}
3232
*
33+
* @deprecated Please use ${@link string} with `fc.string({ unit: 'grapheme', minLength: 1, maxLength: 1 })` or `fc.string({ unit: 'binary', minLength: 1, maxLength: 1 })` instead
3334
* @remarks Since 0.0.11
3435
* @public
3536
*/

packages/fast-check/src/arbitrary/fullUnicodeString.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const safeObjectAssign = Object.assign;
1414
*
1515
* @param constraints - Constraints to apply when building instances (since 2.4.0)
1616
*
17+
* @deprecated Please use ${@link string} with `fc.string({ unit: 'grapheme', ...constraints })` or `fc.string({ unit: 'binary', ...constraints })` instead
1718
* @remarks Since 0.0.11
1819
* @public
1920
*/

packages/fast-check/src/arbitrary/hexa.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function hexaUnmapper(v: number): number {
1919

2020
/**
2121
* For single hexadecimal characters - 0-9 or a-f
22+
* @deprecated Prefer using `fc.constantFrom(...'0123456789abcdef')`
2223
* @remarks Since 0.0.1
2324
* @public
2425
*/

packages/fast-check/src/arbitrary/hexaString.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const safeObjectAssign = Object.assign;
1414
*
1515
* @param constraints - Constraints to apply when building instances (since 2.4.0)
1616
*
17+
* @deprecated Please use ${@link string} with `fc.string({ unit: fc.constantFrom(...'0123456789abcdef'), ...constraints })` instead
1718
* @remarks Since 0.0.1
1819
* @public
1920
*/

0 commit comments

Comments
 (0)