Skip to content

Conversation

@dubzzz
Copy link
Owner

@dubzzz dubzzz commented Aug 23, 2024

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:

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

  • The name of my PR follows gitmoji specification
  • My PR references one of several related issues (if any)
    • New features or breaking changes must come with an associated Issue or Discussion
    • My PR does not add any new dependency without an associated Issue or Discussion
  • My PR includes bumps details, please run yarn bump and flag the impacts properly
  • My PR adds relevant tests and they would have failed without my PR (when applicable)

Advanced

  • Category: 🗑️ Deprecating
  • Impacts: API reduction

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 23, 2024

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 048f09f:

Sandbox Source
@fast-check/examples Configuration

@github-actions
Copy link
Contributor

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

@codecov
Copy link

codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

Additional details and impacted files
@@           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 Coverage Δ
unit-tests 95.32% <ø> (ø)
unit-tests-18.x-Linux 95.32% <ø> (ø)
unit-tests-20.x-Linux 95.32% <ø> (ø)
unit-tests-22.x-Linux 95.32% <ø> (ø)
unit-tests-latest-Linux 95.32% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dubzzz
Copy link
Owner Author

dubzzz commented Aug 23, 2024

Waiting for yarnpkg/berry#6461

@changeset-bot
Copy link

changeset-bot bot commented Aug 24, 2024

⚠️ No Changeset found

Latest commit: 048f09f

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
Copy link
Contributor

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

@dubzzz dubzzz merged commit 3f4f120 into main Aug 24, 2024
@dubzzz dubzzz deleted the deprecate-string-char-arbs branch August 24, 2024 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants