Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dubzzz/fast-check
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.4.1
Choose a base ref
...
head repository: dubzzz/fast-check
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.5.0
Choose a head ref
Loading
Showing with 8,059 additions and 1,374 deletions.
  1. +20 −0 CHANGELOG.md
  2. +33 −0 codemods/unify-signatures/snippet-5.js
  3. +70 −1 codemods/unify-signatures/transform.cjs
  4. +107 −61 documentation/Arbitraries.md
  5. +8 −8 example/package.json
  6. +432 −379 example/yarn.lock
  7. +1 −1 package.json
  8. +88 −0 src/check/arbitrary/CloneArbitrary.ts
  9. +5 −82 src/check/arbitrary/DedupArbitrary.ts
  10. +42 −1 src/check/arbitrary/LoremArbitrary.ts
  11. +96 −13 src/check/arbitrary/ObjectArbitrary.ts
  12. +7 −1 src/fast-check-default.ts
  13. +2 −0 test/e2e/GenerateAllValues.spec.ts
  14. +2 −2 test/e2e/ModelBased.spec.ts
  15. +2 −2 test/e2e/NoRegression.spec.ts
  16. +4 −4 test/e2e/StateFullArbitraries.spec.ts
  17. +99 −99 test/e2e/__snapshots__/NoRegression.spec.ts.snap
  18. +3 −1 test/e2e/documentation/Docs.md.spec.ts
  19. +1 −1 test/esm/rollup-with-import/package.json
  20. +4 −4 test/esm/rollup-with-import/yarn.lock
  21. +1 −1 test/esm/rollup-with-require/package.json
  22. +4 −4 test/esm/rollup-with-require/yarn.lock
  23. +1 −1 test/esm/webpack-with-import/package.json
  24. +3,284 −157 test/esm/webpack-with-import/yarn.lock
  25. +1 −1 test/esm/webpack-with-require/package.json
  26. +3,284 −157 test/esm/webpack-with-require/yarn.lock
  27. +7 −7 test/type/index.test-d.ts
  28. +8 −8 test/unit/check/arbitrary/{DedupArbitrary.spec.ts → CloneArbitrary.spec.ts}
  29. +2 −2 test/unit/check/arbitrary/DateArbitrary.utest.spec.ts
  30. +26 −3 test/unit/check/arbitrary/LoremArbitrary.spec.ts
  31. +1 −0 test/unit/check/arbitrary/ObjectArbitrary.spec.ts
  32. +1 −1 test/unit/check/arbitrary/generic/GenericArbitraryHelper.ts
  33. +1 −0 test/unit/utils/stringify.spec.ts
  34. +412 −372 yarn.lock
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 2.5.0

_Towards a uniform way to constrain arbitraries - step 2: remaining arbitraries except number related ones_
[[Code](https://github.com/dubzzz/fast-check/tree/v2.5.0)][[Diff](https://github.com/dubzzz/fast-check/compare/v2.4.0...v2.5.0)]

## Features

- ([PR#1023](https://github.com/dubzzz/fast-check/pull/1023)) Unify signatures on arbitraries: fc.\*\[jJ\]son\* (see [#992](https://github.com/dubzzz/fast-check/issues/992))
- ([PR#1026](https://github.com/dubzzz/fast-check/pull/1026)) Unify signatures on arbitraries: fc.lorem (see [#992](https://github.com/dubzzz/fast-check/issues/992))
- ([PR#1063](https://github.com/dubzzz/fast-check/pull/1063)) Rename fc.dedup into fc.clone (older name has been deprecated for the moment)
- ([PR#1065](https://github.com/dubzzz/fast-check/pull/1065)) Add withDate option on fc.object

## Fixes

- ([PR#1022](https://github.com/dubzzz/fast-check/pull/1022)) Tool: Script udate:examples should not fail on updates
- ([PR#1024](https://github.com/dubzzz/fast-check/pull/1024)) Doc: Support fc.option in codemod for [#992](https://github.com/dubzzz/fast-check/issues/992)
- ([PR#1025](https://github.com/dubzzz/fast-check/pull/1025)) Doc: Support fc.commands in codemod for [#992](https://github.com/dubzzz/fast-check/issues/992)

---

# 2.4.0

_Towards a uniform way to constrain arbitraries - step 1: array-like arbitraries_
33 changes: 33 additions & 0 deletions codemods/unify-signatures/snippet-5.js
Original file line number Diff line number Diff line change
@@ -37,3 +37,36 @@ fc.shuffledSubarray([1, 2, 3]);
fc.shuffledSubarray([1, 2, 3], 1, 2);
fc.shuffledSubarray(myArray, 1, 2);
fc.shuffledSubarray(computeArray(), 1, 2);

// json

fc.json();
fc.json(2);
fc.json(10);
fc.json({ maxDepth: 10 });

// option

fc.option(fc.nat());
fc.option(fc.nat(), 10);
fc.option(fc.nat(), { freq: 10, nil: null });

// option

fc.commands([]);
fc.commands([], 10);
fc.commands([], 50);
fc.commands([], { maxCommands: 50 });

// lorem

fc.lorem();
fc.lorem(5);
fc.lorem(10);
fc.lorem(num);
fc.lorem(5, true);
fc.lorem(10, true);
fc.lorem(10, false);
fc.lorem(10, something);
fc.lorem(num, something);
fc.lorem({ maxCount: 10 });
71 changes: 70 additions & 1 deletion codemods/unify-signatures/transform.cjs
Original file line number Diff line number Diff line change
@@ -4,6 +4,10 @@
// Or against the codebase of fast-check itself:
// npx jscodeshift --parser=ts --extensions=ts -t transform.cjs ../../example/ ../../src/ ../../test/ --local=true --debug=true --simplifyMin=true --simplifyMax=true

// Useful ressources:
// - https://astexplorer.net/
// - https://npmdoc.github.io/node-npmdoc-jscodeshift/build/apidoc.html

/**
* Find any imports related to fast-check
* either module as a whole or named imports
@@ -138,7 +142,11 @@ module.exports = function (file, api, options) {
}
function isNumeric(argument) {
// 0 -- Default parser: Literal / TS parser: NumericLiteral
return argument.type === 'Literal' || argument.type === 'NumericLiteral';
return (argument.type === 'Literal' || argument.type === 'NumericLiteral') && typeof argument.value === 'number';
}
function isBoolean(argument) {
// true -- Default parser: Literal / TS parser: BooleanLiteral
return (argument.type === 'Literal' || argument.type === 'BooleanLiteral') && typeof argument.value === 'boolean';
}
function isArray(argument) {
// [1, 2, 3] -- Default & TS parser: ArrayExpression
@@ -280,6 +288,67 @@ module.exports = function (file, api, options) {
}
break;
}
case 'json':
case 'unicodeJson':
case 'jsonObject':
case 'unicodeJsonObject': {
if (p.value.arguments.length === 1 && p.value.arguments[0].type !== 'ObjectExpression') {
// fc.json(10) -> fc.json({maxDepth})
const simplifyMax = options.simplifyMax && isNumericValue(p.value.arguments[0], 2);
p.value.arguments = computeNewArguments(
[],
[!simplifyMax && j.property('init', j.identifier('maxDepth'), p.value.arguments[0])]
);
}
break;
}
case 'option': {
if (p.value.arguments.length === 2 && p.value.arguments[1].type !== 'ObjectExpression') {
// fc.option(arb, 10) -> fc.option(arb, {freq})
p.value.arguments = computeNewArguments(
[p.value.arguments[0]],
[j.property('init', j.identifier('freq'), p.value.arguments[1])]
);
}
break;
}
case 'commands': {
if (p.value.arguments.length === 2 && p.value.arguments[1].type !== 'ObjectExpression') {
// fc.commands(commandArbs, maxCommands) -> fc.commands(commandArbs, {maxCommands})
const simplifyMax = options.simplifyMax && isNumericValue(p.value.arguments[1], 10);
p.value.arguments = computeNewArguments(
[p.value.arguments[0]],
[!simplifyMax && j.property('init', j.identifier('maxCommands'), p.value.arguments[1])]
);
}
break;
}
case 'lorem': {
if (p.value.arguments.length === 1 && p.value.arguments[0].type !== 'ObjectExpression') {
// fc.lorem(maxWordsCount) -> fc.lorem({maxCount})
const simplifyMax = options.simplifyMax && isNumericValue(p.value.arguments[0], 5);
p.value.arguments = computeNewArguments(
[],
[!simplifyMax && j.property('init', j.identifier('maxCount'), p.value.arguments[0])]
);
} else if (p.value.arguments.length === 2) {
// fc.lorem(maxWordsCount, sentencesMode) -> fc.lorem({maxCount, mode})
const simplifyMax = options.simplifyMax && isNumericValue(p.value.arguments[0], 5);
const mode = isBoolean(p.value.arguments[1])
? p.value.arguments[1].value === true
? j.literal('sentences')
: j.literal('words')
: j.conditionalExpression(p.value.arguments[1], j.literal('sentences'), j.literal('words'));
p.value.arguments = computeNewArguments(
[],
[
!simplifyMax && j.property('init', j.identifier('maxCount'), p.value.arguments[0]),
j.property('init', j.identifier('mode'), mode),
]
);
}
break;
}
}
return p;
})
Loading