Skip to content

Commit

Permalink
💥 Drop deprecated hexa* (#5283)
Browse files Browse the repository at this point in the history
**Description**

<!-- Please provide a short description and potentially linked issues
justifying the need for this PR -->

The arbitraries `hexa` and `hexaString` 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:

```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() });
}
```

<details><summary>
Or even more accurate</summary>

```ts
function hexa(): fc.Arbitrary<string> {
  return fc.integer({ min: 0, max: 15 }).map(
    (n) => items[n],
    (c) => {
      if (typeof c !== 'string') {
        throw new Error('Not a string');
      }
      const index = items.indexOf(c);
      if (index === -1) {
        throw new Error('Unknown "char"');
      }
      return index;
    },
  );
}

// Or shorter

function hexa(): fc.Arbitrary<string> {
  return fc.integer({ min: 0, max: 15 }).map(
    (n) => items[n],
    (c) => items.indexOf(c),
  );
}
```
</details>

<!-- * 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?
-->
  • Loading branch information
dubzzz authored Sep 23, 2024
1 parent bcdbbd1 commit 2d1c4cd
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 339 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PauseCommand } from './PauseCommand';
import { NextCommand } from './NextCommand';
import { AddTrackCommand } from './AddTrackCommand';

export const TrackNameArb = fc.hexaString({ minLength: 1 });
export const TrackNameArb = fc.string({ minLength: 1 });

export const MusicPlayerCommands = fc.commands([
fc.constant(new PlayCommand()),
Expand Down
7 changes: 3 additions & 4 deletions examples/005-race/todolist/main.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ describe('TodoList', () => {
.asyncProperty(
fc.scheduler(),
TodoListCommands,
fc.uniqueArray(
fc.record({ id: fc.hexaString({ minLength: 8, maxLength: 8 }), label: fc.string(), checked: fc.boolean() }),
{ selector: (entry) => entry.id },
),
fc.uniqueArray(fc.record({ id: fc.uuid(), label: fc.string(), checked: fc.boolean() }), {
selector: (entry) => entry.id,
}),
fc.infiniteStream(fc.boolean()),
async (s, commands, initialTodos, allFailures) => {
const { mockedApi, expectedTodos } = mockApi(s, initialTodos, allFailures);
Expand Down
28 changes: 0 additions & 28 deletions packages/fast-check/src/arbitrary/hexa.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/fast-check/src/arbitrary/hexaString.ts

This file was deleted.

23 changes: 21 additions & 2 deletions packages/fast-check/src/arbitrary/ipV6.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { array } from './array';
import type { Arbitrary } from '../check/arbitrary/definition/Arbitrary';
import { oneof } from './oneof';
import { hexaString } from './hexaString';
import { string } from './string';
import { tuple } from './tuple';
import { ipV4 } from './ipV4';
import {
Expand All @@ -18,6 +18,7 @@ import {
noTrailingMapper,
noTrailingUnmapper,
} from './_internals/mappers/EntitiesToIPv6';
import { integer } from './integer';

/** @internal */
function h16sTol32Mapper([a, b]: [string, string]): string {
Expand All @@ -31,6 +32,24 @@ function h16sTol32Unmapper(value: unknown): [string, string] {
return value.split(':', 2) as [string, string];
}

const items = '0123456789abcdef';
/** @internal */
function hexa(): Arbitrary<string> {
return integer({ min: 0, max: 15 }).map(
(n) => items[n],
(c) => {
if (typeof c !== 'string') {
throw new Error('Not a string');
}
const index = items.indexOf(c);
if (index === -1) {
throw new Error('Unknown "char"');
}
return index;
},
);
}

/**
* For valid IP v6
*
Expand All @@ -55,7 +74,7 @@ export function ipV6(): Arbitrary<string> {
// Any size-based arbitrary called within the implementation of ipV6 has
// to be called with size:'max' in order to prevent any behaviour change
// related to global settings on size. ipV6 is fully independent of size
const h16Arb = hexaString({ minLength: 1, maxLength: 4, size: 'max' });
const h16Arb = string({ unit: hexa(), minLength: 1, maxLength: 4, size: 'max' });
const ls32Arb = oneof(tuple(h16Arb, h16Arb).map(h16sTol32Mapper, h16sTol32Unmapper), ipV4());
return oneof(
tuple(array(h16Arb, { minLength: 6, maxLength: 6, size: 'max' }), ls32Arb).map(
Expand Down
4 changes: 0 additions & 4 deletions packages/fast-check/src/fast-check-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { base64 } from './arbitrary/base64';
import { char } from './arbitrary/char';
import { char16bits } from './arbitrary/char16bits';
import { fullUnicode } from './arbitrary/fullUnicode';
import { hexa } from './arbitrary/hexa';
import { unicode } from './arbitrary/unicode';
import { constant } from './arbitrary/constant';
import { constantFrom } from './arbitrary/constantFrom';
Expand Down Expand Up @@ -108,7 +107,6 @@ import { uniqueArray } from './arbitrary/uniqueArray';
import { infiniteStream } from './arbitrary/infiniteStream';
import { base64String } from './arbitrary/base64String';
import { fullUnicodeString } from './arbitrary/fullUnicodeString';
import { hexaString } from './arbitrary/hexaString';
import type { StringSharedConstraints, StringConstraints } from './arbitrary/string';
import { string } from './arbitrary/string';
import { string16bits } from './arbitrary/string16bits';
Expand Down Expand Up @@ -362,15 +360,13 @@ export {
char16bits,
unicode,
fullUnicode,
hexa,
base64,
mixedCase,
string,
string16bits,
stringOf,
unicodeString,
fullUnicodeString,
hexaString,
base64String,
stringMatching,
limitShrink,
Expand Down
3 changes: 0 additions & 3 deletions packages/fast-check/test/e2e/GenerateAllValues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ describe(`Generate all values (seed: ${seed})`, () => {
it('Should be able to produce any character from unicode (UCS-2 subset only)', () =>
lookForMissing(fc.unicode(), numCharacters));
});
describe('fc.hexa()', () => {
it('Should be able to produce any character from hexa', () => lookForMissing(fc.hexa(), 16));
});
describe('fc.base64()', () => {
it('Should be able to produce any character from base64', () => lookForMissing(fc.base64(), 64));
});
Expand Down
10 changes: 0 additions & 10 deletions packages/fast-check/test/e2e/NoRegression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,6 @@ describe(`NoRegression`, () => {
),
).toThrowErrorMatchingSnapshot();
});
it('hexaString', () => {
expect(
runWithSanitizedStack(() =>
fc.assert(
fc.property(fc.hexaString(), (v) => testFunc(v)),
settings,
),
),
).toThrowErrorMatchingSnapshot();
});
it('base64String', () => {
expect(
runWithSanitizedStack(() =>
Expand Down
2 changes: 0 additions & 2 deletions packages/fast-check/test/e2e/Poisoning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@ describe(`Poisoning (seed: ${seed})`, () => {
{ name: 'bigUint', arbitraryBuilder: () => fc.bigUint() },
// String
// : Single character
{ name: 'hexa', arbitraryBuilder: () => fc.hexa() },
{ name: 'base64', arbitraryBuilder: () => fc.base64() },
{ name: 'char', arbitraryBuilder: () => fc.char() },
{ name: 'unicode', arbitraryBuilder: () => fc.unicode() },
{ name: 'char16bits', arbitraryBuilder: () => fc.char16bits() },
{ name: 'fullUnicode', arbitraryBuilder: () => fc.fullUnicode() },
// : Multiple characters
{ name: 'hexaString', arbitraryBuilder: () => fc.hexaString() },
{ name: 'base64String', arbitraryBuilder: () => fc.base64String() },
{ name: 'string', arbitraryBuilder: () => fc.string() },
{ name: 'unicodeString', arbitraryBuilder: () => fc.unicodeString() },
Expand Down
2 changes: 1 addition & 1 deletion packages/fast-check/test/e2e/ReplayFailures.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fc from '../../src/fast-check';
import { seed } from './seed';

describe(`ReplayFailures (seed: ${seed})`, () => {
const propArbitrary = fc.uniqueArray(fc.hexaString());
const propArbitrary = fc.uniqueArray(fc.string());
const propCheck = (data: string[]) => {
// element at <idx> should not contain the first character of the element just before
// 01, 12, 20 - is correct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3886,52 +3886,6 @@ Execution summary:
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . √ [[0,0]]]
`;

exports[`NoRegression > hexaString 1`] = `
[Error: Property failed after 6 tests
{ seed: 42, path: "5:1:1:10:1:5:0", endOnFailure: true }
Counterexample: ["66"]
Shrunk 6 time(s)

Execution summary:
√ [""]
√ ["a7984c84"]
√ ["a6db51"]
√ ["19"]
√ [""]
× ["213bcfddc6"]
. √ [""]
. × ["fddc6"]
. . √ ["dc6"]
. . × ["ddc6"]
. . . √ ["dc6"]
. . . √ ["0dc6"]
. . . √ ["7dc6"]
. . . √ ["adc6"]
. . . √ ["cdc6"]
. . . √ ["d"]
. . . √ ["dc6"]
. . . √ ["d0c6"]
. . . √ ["d7c6"]
. . . √ ["dac6"]
. . . × ["dcc6"]
. . . . √ ["c6"]
. . . . × ["cc6"]
. . . . . √ ["c6"]
. . . . . √ ["bc6"]
. . . . . √ ["c"]
. . . . . √ ["c6"]
. . . . . √ ["c06"]
. . . . . × ["c66"]
. . . . . . × ["66"]
. . . . . . . √ ["6"]
. . . . . . . √ ["36"]
. . . . . . . √ ["56"]
. . . . . . . √ ["6"]
. . . . . . . √ ["60"]
. . . . . . . √ ["63"]
. . . . . . . √ ["65"]]
`;

exports[`NoRegression > infiniteStream 1`] = `
[Error: Property failed after 1 tests
{ seed: 42, path: "0", endOnFailure: true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ describe('SchedulerImplem', () => {
fc.array(
fc.letrec((tie) => ({
self: fc.record({
name: fc.noBias(fc.hexaString({ minLength: 4, maxLength: 4 })),
name: fc.noBias(fc.string({ minLength: 4, maxLength: 4 })),
children: fc.oneof(
fc.constant<ExecutionPlan[]>([]),
fc.array(tie('self') as fc.Arbitrary<ExecutionPlan>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import {
paddedEightsToUuidUnmapper,
} from '../../../../../src/arbitrary/_internals/mappers/PaddedEightsToUuid';

const items = '0123456789abcdef';
function hexa(): fc.Arbitrary<string> {
return fc.integer({ min: 0, max: 15 }).map((n) => items[n]);
}

describe('paddedEightsToUuidUnmapper', () => {
it('should be able to unmap any mapped value', () =>
fc.assert(
fc.property(
fc.hexaString({ minLength: 8, maxLength: 8 }),
fc.hexaString({ minLength: 8, maxLength: 8 }),
fc.hexaString({ minLength: 8, maxLength: 8 }),
fc.hexaString({ minLength: 8, maxLength: 8 }),
fc.string({ unit: hexa(), minLength: 8, maxLength: 8 }),
fc.string({ unit: hexa(), minLength: 8, maxLength: 8 }),
fc.string({ unit: hexa(), minLength: 8, maxLength: 8 }),
fc.string({ unit: hexa(), minLength: 8, maxLength: 8 }),
(a, b, c, d) => {
// Arrange
const ins: [string, string, string, string] = [a, b, c, d];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe('versionsApplierMapper', () => {
});

describe('versionsApplierUnmapper', () => {
const items = '0123456789abcdef';
function hexa(): fc.Arbitrary<string> {
return fc.integer({ min: 0, max: 15 }).map((n) => items[n]);
}

it('should correctly unmap from a known version', () => {
// Arrange
const source = '901'; // 9 is at index 3, so it should unmap to 3
Expand Down Expand Up @@ -73,7 +78,7 @@ describe('versionsApplierUnmapper', () => {
fc.property(
fc.uniqueArray(fc.nat({ max: 15 }), { minLength: 1 }),
fc.nat(),
fc.hexaString(),
fc.string({ unit: hexa() }),
(versions, diceIndex, tail) => {
// Arrange
const index = diceIndex % versions.length;
Expand Down
Loading

0 comments on commit 2d1c4cd

Please sign in to comment.