Skip to content

Commit 134ccd1

Browse files
authored
💥 Drop deprecated char16bits and string16bits (#5289)
**Description** <!-- Please provide a short description and potentially linked issues justifying the need for this PR --> The arbitraries `char16bits` and `string16bits` have been marked for deprecation since version 3.22.0. They are now being fully dropped. If you still want to rely on something behaving this way we recommend you to use the following constructs: ```js const char16bits = fc.nat({ max: 0xffff }).map((n) => String.fromCharCode(n)); const string16bits = fc.string({ unit: char16bits }); ``` <!-- * 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: 💥 Breaking change - [x] Impacts: Dropped arbitraries <!-- [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 2a4b09e commit 134ccd1

File tree

15 files changed

+20
-281
lines changed

15 files changed

+20
-281
lines changed

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

-19
This file was deleted.

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

-29
This file was deleted.

packages/fast-check/src/fast-check-default.ts

-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import { boolean } from './arbitrary/boolean';
3434
import type { FalsyContraints, FalsyValue } from './arbitrary/falsy';
3535
import { falsy } from './arbitrary/falsy';
3636
import { char } from './arbitrary/char';
37-
import { char16bits } from './arbitrary/char16bits';
3837
import { fullUnicode } from './arbitrary/fullUnicode';
3938
import { unicode } from './arbitrary/unicode';
4039
import { constant } from './arbitrary/constant';
@@ -108,7 +107,6 @@ import { base64String } from './arbitrary/base64String';
108107
import { fullUnicodeString } from './arbitrary/fullUnicodeString';
109108
import type { StringSharedConstraints, StringConstraints } from './arbitrary/string';
110109
import { string } from './arbitrary/string';
111-
import { string16bits } from './arbitrary/string16bits';
112110
import { unicodeString } from './arbitrary/unicodeString';
113111
import type { SubarrayConstraints } from './arbitrary/subarray';
114112
import { subarray } from './arbitrary/subarray';
@@ -355,12 +353,10 @@ export {
355353
bigInt,
356354
bigUint,
357355
char,
358-
char16bits,
359356
unicode,
360357
fullUnicode,
361358
mixedCase,
362359
string,
363-
string16bits,
364360
unicodeString,
365361
fullUnicodeString,
366362
base64String,

packages/fast-check/test/e2e/GenerateAllValues.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ describe(`Generate all values (seed: ${seed})`, () => {
3131
describe('fc.char()', () => {
3232
it('Should be able to produce any printable character', () => lookForMissing(fc.char(), 95));
3333
});
34-
describe('fc.char16bits()', () => {
35-
it('Should be able to produce any 16 bits character', () => lookForMissing(fc.char16bits(), 65536));
36-
});
3734
describe('fc.unicode()', () => {
3835
const numCharacters = 65536 - (0xdfff - 0xd800 + 1);
3936
it('Should be able to produce any character from unicode (UCS-2 subset only)', () =>

packages/fast-check/test/e2e/NoRegression.spec.ts

-4
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ describe(`NoRegression`, () => {
156156
),
157157
).toThrowErrorMatchingSnapshot();
158158
});
159-
// // Jest Snapshot seems not to support incomplete surrogate pair correctly
160-
// it('string16bits', () => {
161-
// expect(runWithSanitizedStack(() => fc.assert(fc.property(fc.string16bits(), v => testFunc(v + v)), settings))).toThrowErrorMatchingSnapshot();
162-
// });
163159
it('stringMatching', () => {
164160
expect(
165161
runWithSanitizedStack(() =>

packages/fast-check/test/e2e/Poisoning.spec.ts

-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ describe(`Poisoning (seed: ${seed})`, () => {
4343
// : Single character
4444
{ name: 'char', arbitraryBuilder: () => fc.char() },
4545
{ name: 'unicode', arbitraryBuilder: () => fc.unicode() },
46-
{ name: 'char16bits', arbitraryBuilder: () => fc.char16bits() },
4746
{ name: 'fullUnicode', arbitraryBuilder: () => fc.fullUnicode() },
4847
// : Multiple characters
4948
{ name: 'base64String', arbitraryBuilder: () => fc.base64String() },
5049
{ name: 'string', arbitraryBuilder: () => fc.string() },
5150
{ name: 'unicodeString', arbitraryBuilder: () => fc.unicodeString() },
52-
{ name: 'string16bits', arbitraryBuilder: () => fc.string16bits() },
5351
{ name: 'fullUnicodeString', arbitraryBuilder: () => fc.fullUnicodeString() },
5452
{ name: 'stringMatching', arbitraryBuilder: () => preBuiltStringMatching },
5553
// : More specific strings

packages/fast-check/test/e2e/arbitraries/StringArbitrary.spec.ts

-10
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,4 @@ describe(`StringArbitrary (seed: ${seed})`, () => {
4545
);
4646
});
4747
});
48-
describe('string16bits', () => {
49-
it('Should be able to produce invalid UTF-16 strings', () => {
50-
const out = fc.check(
51-
fc.property(fc.string16bits(), (s: string) => encodeURIComponent(s) !== null),
52-
{ seed: seed },
53-
);
54-
expect(out.failed).toBe(true);
55-
expect(out.counterexample).toEqual(['\ud800']);
56-
});
57-
});
5848
});

packages/fast-check/test/unit/arbitrary/_internals/mappers/CharsToString.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('charsToStringUnmapper', () => {
1919

2020
it('should be able to split any string mapped from chars into chars', () =>
2121
fc.assert(
22-
fc.property(fc.array(fc.char16bits()), (data) => {
22+
fc.property(fc.array(fc.nat({ max: 0xffff }).map((n) => String.fromCharCode(n))), (data) => {
2323
// Arrange
2424
const source = charsToStringMapper(data);
2525

packages/fast-check/test/unit/arbitrary/_internals/mappers/IndexToCharString.spec.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ describe('indexToCharStringUnmapper', () => {
3333

3434
it('should accept any 1 char string (including half-surrogates)', () =>
3535
fc.assert(
36-
fc.property(fc.char16bits(), (c) => {
37-
// Arrange / Act / Assert
38-
expect(indexToCharStringUnmapper(c)).toBe(c.charCodeAt(0));
39-
}),
36+
fc.property(
37+
fc.nat({ max: 0xffff }).map((n) => String.fromCharCode(n)),
38+
(c) => {
39+
// Arrange / Act / Assert
40+
expect(indexToCharStringUnmapper(c)).toBe(c.charCodeAt(0));
41+
},
42+
),
4043
));
4144
});

packages/fast-check/test/unit/arbitrary/char16bits.spec.ts

-95
This file was deleted.

packages/fast-check/test/unit/arbitrary/string16bits.spec.ts

-47
This file was deleted.

packages/fast-check/test/unit/utils/hash.spec.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ describe('hash', () => {
1212
}),
1313
));
1414
it('Should be able to compute hash even for invalid strings', () =>
15-
fc.assert(fc.property(fc.char16bits(), (a) => typeof hash(a) === 'number')));
15+
fc.assert(fc.property(string16bits, (a) => typeof hash(a) === 'number')));
1616
it('Should compute the same value as reference for strings of characters <0x80', () =>
1717
fc.assert(fc.property(string0x80, (s) => hash(s) === hashReference(s))));
1818
it('Should compute the same value as reference for strings of characters <0x800', () =>
1919
fc.assert(fc.property(string0x800, (s) => hash(s) === hashReference(s))));
2020
it('Should compute the same value as reference for any string', () =>
2121
fc.assert(fc.property(fc.fullUnicodeString(), (s) => hash(s) === hashReference(s))));
2222
it('Should compute the same value as reference for potentially invalid strings', () =>
23-
fc.assert(fc.property(fc.char16bits(), (s) => hash(s) === hashReference(s))));
23+
fc.assert(fc.property(string16bits, (s) => hash(s) === hashReference(s))));
2424
it('Should consider any invalid surrogate pair as <ef bf bd> or 0xfffd', () => {
2525
// This is the behaviour of the reference implementation based on Buffer.from (see below)
2626
// Buffer.from([0xef,0xbf,0xbd]).toString('utf8') === '\ufffd'
@@ -35,6 +35,9 @@ describe('hash', () => {
3535

3636
// Helpers
3737

38+
const char16bits = fc.nat({ max: 0xffff }).map((n) => String.fromCharCode(n));
39+
const string16bits = fc.string({ unit: char16bits });
40+
3841
const char0x80 = fc.nat(0x79).map((n) => String.fromCharCode(n));
3942
const string0x80 = fc.string({ unit: char0x80 });
4043

packages/fast-check/test/unit/utils/stringify.spec.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ const anythingEnableAll: fc.ObjectConstraints = {
5353
describe('stringify', () => {
5454
it('Should be able to stringify fc.anything()', () =>
5555
fc.assert(fc.property(fc.anything(anythingEnableAll), (a) => typeof stringify(a) === 'string')));
56-
it('Should be able to stringify fc.char16bits() (ie. possibly invalid strings)', () =>
57-
fc.assert(fc.property(fc.char16bits(), (a) => typeof stringify(a) === 'string')));
56+
it('Should be able to stringify possibly invalid strings', () =>
57+
fc.assert(
58+
fc.property(
59+
fc.string({ unit: fc.nat({ max: 0xffff }).map((n) => String.fromCharCode(n)) }),
60+
(a) => typeof stringify(a) === 'string',
61+
),
62+
));
5863
it('Should be able to stringify bigint in object correctly', () =>
5964
fc.assert(fc.property(fc.bigInt(), (b) => stringify({ b }) === '{"b":' + b + 'n}')));
6065
it('Should be equivalent to JSON.stringify for JSON compliant objects', () =>

website/docs/core-blocks/arbitraries/primitives/char.md

-20
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,6 @@ fc.unicode();
4444
Resources: [API reference](https://fast-check.dev/api-reference/functions/unicode.html).
4545
Available since 0.0.11.
4646

47-
## char16bits
48-
49-
One unicode character from BMP-plan (including part of surrogate pair) — _ie.: one character between `0x0000` (included) and `0xffff` (included)_.
50-
51-
Generate any 16 bits character. Be aware the values within `0xd800` and `0xdfff` which constitutes the surrogate pair characters are also generated meaning that some generated characters might appear invalid regarding UCS-2 and UTF-16 encoding.
52-
53-
**Signatures:**
54-
55-
- `fc.char16bits()`_deprecated since v3.22.0 (more details at [#5233](https://github.com/dubzzz/fast-check/pull/5233))_
56-
57-
**Usages:**
58-
59-
```js
60-
fc.char16bits();
61-
// Examples of generated values: "", "毒", "丬", "縻", "贑"…
62-
```
63-
64-
Resources: [API reference](https://fast-check.dev/api-reference/functions/char16bits.html).
65-
Available since 0.0.11.
66-
6747
## fullUnicode
6848

6949
One unicode character — _ie.: one character between `0x0000` (included) and `0x10ffff` (included) but excluding surrogate pairs (between `0xd800` and `0xdfff`)_.

0 commit comments

Comments
 (0)