dubzzz / fast-check

Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
https://fast-check.dev/
MIT License
4.29k stars 178 forks source link

🗑️ Mark as deprecated most of char and string arbitraries #5233

Closed dubzzz closed 3 weeks ago

dubzzz commented 3 weeks ago

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:

(1) Converting unicodeString to string:

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:

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:

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

ChecklistDon't delete this checklist and make sure you do the following before opening the PR

Advanced

codesandbox-ci[bot] commented 3 weeks ago

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 048f09fc40602476190f9aaa4b9b4893c4d05ebb:

Sandbox Source
@fast-check/examples Configuration
github-actions[bot] commented 3 weeks ago

👋 A preview of the new documentation is available at: http://66c8d397f02c1bf06d16b818--dubzzz-fast-check.netlify.app

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.32%. Comparing base (a14bc3a) to head (048f09f). Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #5233 +/- ## ======================================= Coverage 95.32% 95.32% ======================================= Files 234 234 Lines 10414 10414 Branches 2774 2774 ======================================= Hits 9927 9927 Misses 487 487 ``` | [Flag](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | Coverage Δ | | |---|---|---| | [unit-tests](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | `95.32% <ø> (ø)` | | | [unit-tests-18.x-Linux](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | `95.32% <ø> (ø)` | | | [unit-tests-20.x-Linux](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | `95.32% <ø> (ø)` | | | [unit-tests-22.x-Linux](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | `95.32% <ø> (ø)` | | | [unit-tests-latest-Linux](https://app.codecov.io/gh/dubzzz/fast-check/pull/5233/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN) | `95.32% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Nicolas+DUBIEN#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

dubzzz commented 3 weeks ago

Waiting for https://github.com/yarnpkg/berry/pull/6461

changeset-bot[bot] commented 3 weeks ago

⚠️ No Changeset found

Latest commit: 048f09fc40602476190f9aaa4b9b4893c4d05ebb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

github-actions[bot] commented 3 weeks ago

👋 A preview of the new documentation is available at: http://66c98ff69d7767a033ca991f--dubzzz-fast-check.netlify.app