Добавлена ДБ

This commit is contained in:
Georgiy Syralev
2025-09-15 18:10:26 +03:00
parent 253ad8c19b
commit c954b5268e
5824 changed files with 1107594 additions and 19141 deletions

1039
node_modules/fast-check/CHANGELOG.md generated vendored Normal file

File diff suppressed because it is too large Load Diff

21
node_modules/fast-check/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Nicolas DUBIEN
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

249
node_modules/fast-check/README.md generated vendored Normal file
View File

@@ -0,0 +1,249 @@
<h1 align="center">
<img align="center" src="https://media.githubusercontent.com/media/dubzzz/fast-check/main/website/static/img/logo.png" alt="fast-check logo" />
</h1>
<p align="center">
Property based testing framework for JavaScript/TypeScript
</p>
<p align="center">
<a href="https://github.com/dubzzz/fast-check/actions?query=branch%3Amain+workflow%3A%22Build+Status%22"><img src="https://github.com/dubzzz/fast-check/workflows/Build%20Status/badge.svg?branch=main" alt="Build Status" /></a>
<a href="https://badge.fury.io/js/fast-check"><img src="https://badge.fury.io/js/fast-check.svg" alt="npm version" /></a>
<a href="https://www.npmjs.com/package/fast-check"><img src="https://img.shields.io/npm/dm/fast-check" alt="monthly downloads" /></a>
<a href="https://fast-check.dev/"><img src="https://img.shields.io/badge/-Documentation-%23282ea9.svg" title="Documentation" /></a>
</p>
<p align="center">
<a href="https://app.codecov.io/gh/dubzzz/fast-check/branch/main"><img src="https://codecov.io/gh/dubzzz/fast-check/branch/main/graph/badge.svg" alt="Coverage Status (unit tests)" /></a>
<a href="https://packagequality.com/#?package=fast-check"><img src="https://packagequality.com/shield/fast-check.svg" alt="Package quality" /></a>
<a href="https://snyk.io/advisor/npm-package/fast-check"><img src="https://snyk.io/advisor/npm-package/fast-check/badge.svg" alt="Snyk Package quality" /></a>
<a href="https://securityscorecards.dev/viewer/?platform=github.com&org=dubzzz&repo=fast-check"><img src="https://api.securityscorecards.dev/projects/github.com/dubzzz/fast-check/badge" alt="OpenSSF Scorecard" /></a>
<a href="https://bestpractices.coreinfrastructure.org/projects/7450"><img src="https://bestpractices.coreinfrastructure.org/projects/7450/badge" alt="OpenSSF Best Practices" /></a>
</p>
<p align="center">
<a href="https://github.com/dubzzz/fast-check/labels/good%20first%20issue"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome" /></a>
<a href="https://github.com/dubzzz/fast-check/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/fast-check.svg" alt="License" /></a>
</p>
## Getting started
Hands-on tutorial and definition of Property Based Testing: [🏁 see tutorial](https://fast-check.dev/docs/tutorials/quick-start/). Or directly try it online on our pre-configured [CodeSandbox](https://codesandbox.io/s/github/dubzzz/fast-check/tree/main/examples?previewwindow=tests).
Property based testing frameworks check the truthfulness of properties. A property is a statement like: _for all (x, y, ...) such that precondition(x, y, ...) holds predicate(x, y, ...) is true_.
Install the module with: `yarn add fast-check --dev` or `npm install fast-check --save-dev`
Example of integration in [mocha](http://mochajs.org/):
```js
import fc from 'fast-check';
// Code under test
const contains = (text, pattern) => text.indexOf(pattern) >= 0;
// Properties
describe('properties', () => {
// string text always contains itself
it('should always contain itself', () => {
fc.assert(fc.property(fc.string(), (text) => contains(text, text)));
});
// string a + b + c always contains b, whatever the values of a, b and c
it('should always contain its substrings', () => {
fc.assert(
fc.property(fc.string(), fc.string(), fc.string(), (a, b, c) => {
// Alternatively: no return statement and direct usage of expect or assert
return contains(a + b + c, b);
}),
);
});
});
```
In case of failure, the test raises a red flag. Its output should help you to diagnose what went wrong in your implementation. Example with a failing implementation of contain:
```
1) should always contain its substrings
Error: Property failed after 1 tests (seed: 1527422598337, path: 0:0): ["","",""]
Shrunk 1 time(s)
Got error: Property failed by returning false
Hint: Enable verbose mode in order to have the list of all failing values encountered during the run
```
Integration with other test frameworks: [ava](https://github.com/dubzzz/fast-check-examples/blob/main/test-ava/example.spec.js), [jasmine](https://github.com/dubzzz/fast-check-examples/blob/main/test-jasmine/example.spec.js), [jest](https://github.com/dubzzz/fast-check-examples/blob/main/test-jest/example.spec.js), [mocha](https://github.com/dubzzz/fast-check-examples/blob/main/test/longest%20common%20substr/test.js) and [tape](https://github.com/dubzzz/fast-check-examples/blob/main/test-tape/example.spec.js).
More examples: [simple examples](https://github.com/dubzzz/fast-check/tree/main/examples), [fuzzing](https://github.com/dubzzz/fuzz-rest-api) and [against various algorithms](https://github.com/dubzzz/fast-check-examples).
Useful documentations:
- [🏁 Introduction to Property Based & Hands On](https://fast-check.dev/docs/tutorials/quick-start/)
- [🐣 Built-in arbitraries](https://fast-check.dev/docs/core-blocks/arbitraries/)
- [🔧 Custom arbitraries](https://fast-check.dev/docs/core-blocks/arbitraries/combiners/)
- [🏃‍♂️ Property based runners](https://fast-check.dev/docs/core-blocks/runners/)
- [💥 Tips](https://fast-check.dev/docs/configuration/)
- [🔌 API Reference](https://fast-check.dev/api-reference/index.html)
- [⭐ Awesome fast-check](https://fast-check.dev/docs/ecosystem/)
## Why should I migrate to fast-check?
fast-check has initially been designed in an attempt to cope with limitations I encountered while using other property based testing frameworks designed for JavaScript:
- **Types:** strong and up-to-date types - _thanks to TypeScript_
- **Extendable:** easy `map` method to derive existing arbitraries while keeping shrink \[[more](https://fast-check.dev/docs/core-blocks/arbitraries/combiners/any/#map)\] - _some frameworks ask the user to provide both a->b and b->a mappings in order to keep a shrinker_
- **Extendable:** kind of flatMap-operation called `chain` \[[more](https://fast-check.dev/docs/core-blocks/arbitraries/combiners/any/#chain)\] - _able to bind the output of an arbitrary as input of another one while keeping the shrink working_
- **Extendable:** precondition checks with `fc.pre(...)` \[[more](https://fast-check.dev/docs/core-blocks/properties/#example)\] - _filtering invalid entries can be done directly inside the check function if needed_
- **Extendable:** easily switch from fake data in tests to property based with `fc.gen()` \[[more](https://fast-check.dev/docs/core-blocks/arbitraries/others/#gen)\] - _generate random values within your predicates_
- **Smart:** ability to shrink on `fc.oneof` \[[more](https://fast-check.dev/docs/core-blocks/arbitraries/combiners/any/#oneof)\] - _surprisingly some frameworks don't_
- **Smart:** biased by default - _by default it generates both small and large values, making it easier to dig into counterexamples without having to tweak a size parameter manually_
- **Debug:** verbose mode \[[more](https://fast-check.dev/docs/configuration/custom-reports/#verbosity)\]\[[tutorial](https://fast-check.dev/docs/tutorials/quick-start/read-test-reports/#how-to-increase-verbosity)\] - _easier troubleshooting with verbose mode enabled_
- **Debug:** replay directly on the minimal counterexample \[[tutorial](https://fast-check.dev/docs/tutorials/quick-start/read-test-reports/#how-to-re-run)\] - _no need to replay the whole sequence, you get directly the counterexample_
- **Debug:** custom examples in addition of generated ones \[[more](https://fast-check.dev/docs/configuration/user-definable-values/#run-against-custom-values)\] - _no need to duplicate the code to play the property on custom examples_
- **Debug:** logger per predicate run \[[more](https://fast-check.dev/docs/core-blocks/arbitraries/others/#context)\] - _simplify your troubleshoot with fc.context and its logging feature_
- **Unique:** model based approach \[[more](https://fast-check.dev/docs/advanced/model-based-testing/)\]\[[article](https://medium.com/criteo-labs/detecting-the-unexpected-in-web-ui-fuzzing-1f3822c8a3a5)\] - _use the power of property based testing to test UI, APIs or state machines_
- **Unique:** detect race conditions in your code \[[more](https://fast-check.dev/docs/advanced/race-conditions/)\]\[[tutorial](https://fast-check.dev/docs/tutorials/detect-race-conditions/)\] - _shuffle the way your promises and async calls resolve using the power of property based testing to detect races_
- **Unique:** simplify user definable corner cases \[[more](https://fast-check.dev/docs/configuration/user-definable-values/#shrink-custom-values)\] - _simplify bug resolution by asking fast-check if it can find an even simpler corner case_
For more details, refer to the documentation in the links above.
### Trusted
fast-check has been trusted for years by big projects like: [jest](https://github.com/jestjs/jest), [jasmine](https://github.com/jasmine/jasmine), [fp-ts](https://github.com/gcanti/fp-ts), [io-ts](https://github.com/gcanti/io-ts), [ramda](https://github.com/ramda/ramda), [js-yaml](https://github.com/nodeca/js-yaml), [query-string](https://github.com/sindresorhus/query-string)...
### Powerful
It also proved useful in finding bugs among major open source projects such as [jest](https://github.com/jestjs/jest), [query-string](https://github.com/sindresorhus/query-string)... and [many others](https://fast-check.dev/docs/introduction/track-record/).
## Compatibility
Here are the minimal requirements to use fast-check properly without any polyfills:
| fast-check | node | ECMAScript version | _TypeScript (optional)_ |
| ---------- | ------------------- | ------------------ | ----------------------- |
| **3.x** | ≥8<sup>(1)</sup> | ES2017 | ≥4.1<sup>(2)</sup> |
| **2.x** | ≥8<sup>(1)</sup> | ES2017 | ≥3.2<sup>(3)</sup> |
| **1.x** | ≥0.12<sup>(1)</sup> | ES3 | ≥3.0<sup>(3)</sup> |
<details>
<summary>More details...</summary>
1. Except for features that cannot be polyfilled - such as `bigint`-related ones - all the capabilities of fast-check should be usable given you use at least the minimal recommended version of node associated to your major of fast-check.
2. Require either lib or target ≥ ES2020 or `@types/node` to be installed.
3. Require either lib or target ≥ ES2015 or `@types/node` to be installed.
</details>
### ReScript bindings
Bindings to use fast-check in [ReScript](https://rescript-lang.org) are available in package [rescript-fast-check](https://www.npmjs.com/rescript-fast-check). They are maintained by [@TheSpyder](https://github.com/TheSpyder) as an external project.
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dubzzz"><img src="https://avatars.githubusercontent.com/u/5300235?v=4?s=100" width="100px;" alt="Nicolas DUBIEN"/><br /><sub><b>Nicolas DUBIEN</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=dubzzz" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=dubzzz" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=dubzzz" title="Tests">⚠️</a> <a href="#infra-dubzzz" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#design-dubzzz" title="Design">🎨</a> <a href="#maintenance-dubzzz" title="Maintenance">🚧</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/hath995"><img src="https://avatars.githubusercontent.com/u/381037?v=4?s=100" width="100px;" alt="Aaron Elligsen"/><br /><sub><b>Aaron Elligsen</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=hath995" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=hath995" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=hath995" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/willheslam"><img src="https://avatars.githubusercontent.com/u/5377213?v=4?s=100" width="100px;" alt="Will Heslam"/><br /><sub><b>Will Heslam</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=willheslam" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kazchimo"><img src="https://avatars.githubusercontent.com/u/31263328?v=4?s=100" width="100px;" alt="kazchimo"/><br /><sub><b>kazchimo</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=kazchimo" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=kazchimo" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/brandon-leapyear"><img src="https://avatars.githubusercontent.com/u/27799541?v=4?s=100" width="100px;" alt="Brandon Chinn"/><br /><sub><b>Brandon Chinn</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=brandon-leapyear" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=brandon-leapyear" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://safareli.github.io/resume/"><img src="https://avatars.githubusercontent.com/u/1932383?v=4?s=100" width="100px;" alt="Irakli Safareli"/><br /><sub><b>Irakli Safareli</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=safareli" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/TheSpyder"><img src="https://avatars.githubusercontent.com/u/298292?v=4?s=100" width="100px;" alt="Andrew Herron"/><br /><sub><b>Andrew Herron</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=TheSpyder" title="Documentation">📖</a> <a href="#plugin-TheSpyder" title="Plugin/utility libraries">🔌</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/EricCrosson"><img src="https://avatars.githubusercontent.com/u/1596818?v=4?s=100" width="100px;" alt="Eric Crosson"/><br /><sub><b>Eric Crosson</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=EricCrosson" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=EricCrosson" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/burrscurr"><img src="https://avatars.githubusercontent.com/u/23213508?v=4?s=100" width="100px;" alt="burrscurr"/><br /><sub><b>burrscurr</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=burrscurr" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.dijonkitchen.org/"><img src="https://avatars.githubusercontent.com/u/11434205?v=4?s=100" width="100px;" alt="JC (Jonathan Chen)"/><br /><sub><b>JC (Jonathan Chen)</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=dijonkitchen" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://fixate.it/"><img src="https://avatars.githubusercontent.com/u/1510520?v=4?s=100" width="100px;" alt="Larry Botha"/><br /><sub><b>Larry Botha</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=larrybotha" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=larrybotha" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=larrybotha" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://epa.ms/RomanGusev"><img src="https://avatars.githubusercontent.com/u/5839225?v=4?s=100" width="100px;" alt="Roman Gusev"/><br /><sub><b>Roman Gusev</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=102" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://timwis.com/"><img src="https://avatars.githubusercontent.com/u/761444?v=4?s=100" width="100px;" alt="Tim Wisniewski"/><br /><sub><b>Tim Wisniewski</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=timwis" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://world.hey.com/brais"><img src="https://avatars.githubusercontent.com/u/17855450?v=4?s=100" width="100px;" alt="Brais Piñeiro"/><br /><sub><b>Brais Piñeiro</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=brapifra" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=brapifra" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/brds"><img src="https://avatars.githubusercontent.com/u/118620?v=4?s=100" width="100px;" alt="Renaud-Pierre Bordes"/><br /><sub><b>Renaud-Pierre Bordes</b></sub></a><br /><a href="#design-brds" title="Design">🎨</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/fwip"><img src="https://avatars.githubusercontent.com/u/190414?v=4?s=100" width="100px;" alt="Jemma Nelson"/><br /><sub><b>Jemma Nelson</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=fwip" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://fullof.bs/"><img src="https://avatars.githubusercontent.com/u/77482?v=4?s=100" width="100px;" alt="John Haugeland"/><br /><sub><b>John Haugeland</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=StoneCypher" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/treydavis"><img src="https://avatars.githubusercontent.com/u/1691239?v=4?s=100" width="100px;" alt="Trey Davis"/><br /><sub><b>Trey Davis</b></sub></a><br /><a href="#design-treydavis" title="Design">🎨</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://leonzalion.com/"><img src="https://avatars.githubusercontent.com/u/36966635?v=4?s=100" width="100px;" alt="Leon Si"/><br /><sub><b>Leon Si</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=leonzalion" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://spion.github.io/"><img src="https://avatars.githubusercontent.com/u/502412?v=4?s=100" width="100px;" alt="Gorgi Kosev"/><br /><sub><b>Gorgi Kosev</b></sub></a><br /><a href="#infra-spion" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mayconsacht"><img src="https://avatars.githubusercontent.com/u/5214042?v=4?s=100" width="100px;" alt="mayconsacht"/><br /><sub><b>mayconsacht</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=mayconsacht" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/paldepind"><img src="https://avatars.githubusercontent.com/u/521604?v=4?s=100" width="100px;" alt="Simon Friis Vindum"/><br /><sub><b>Simon Friis Vindum</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=paldepind" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=paldepind" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://twitter.com/gibson042"><img src="https://avatars.githubusercontent.com/u/1199584?v=4?s=100" width="100px;" alt="Richard Gibson"/><br /><sub><b>Richard Gibson</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=gibson042" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://alanharper.com.au/"><img src="https://avatars.githubusercontent.com/u/475?v=4?s=100" width="100px;" alt="Alan Harper"/><br /><sub><b>Alan Harper</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=aussiegeek" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Osman-Sodefa"><img src="https://avatars.githubusercontent.com/u/90332566?v=4?s=100" width="100px;" alt="Makien Osman"/><br /><sub><b>Makien Osman</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=Osman-Sodefa" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/sommd"><img src="https://avatars.githubusercontent.com/u/7817485?v=4?s=100" width="100px;" alt="David Sommerich"/><br /><sub><b>David Sommerich</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=sommd" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=sommd" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/diegopedro94"><img src="https://avatars.githubusercontent.com/u/7157796?v=4?s=100" width="100px;" alt="Diego Pedro"/><br /><sub><b>Diego Pedro</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=diegopedro94" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=diegopedro94" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/BoruiGu"><img src="https://avatars.githubusercontent.com/u/8686167?v=4?s=100" width="100px;" alt="Borui Gu"/><br /><sub><b>Borui Gu</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=BoruiGu" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/eventualbuddha"><img src="https://avatars.githubusercontent.com/u/1938?v=4?s=100" width="100px;" alt="Brian Donovan"/><br /><sub><b>Brian Donovan</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=eventualbuddha" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/volrk"><img src="https://avatars.githubusercontent.com/u/32265974?v=4?s=100" width="100px;" alt="volrk"/><br /><sub><b>volrk</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=volrk" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=volrk" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=volrk" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tinydylan"><img src="https://avatars.githubusercontent.com/u/41112113?v=4?s=100" width="100px;" alt="tinydylan"/><br /><sub><b>tinydylan</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=tinydylan" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=tinydylan" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jasikpark"><img src="https://avatars.githubusercontent.com/u/10626596?v=4?s=100" width="100px;" alt="Caleb Jasik"/><br /><sub><b>Caleb Jasik</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=jasikpark" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/rulai-hu"><img src="https://avatars.githubusercontent.com/u/2570932?v=4?s=100" width="100px;" alt="Rulai Hu"/><br /><sub><b>Rulai Hu</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=rulai-hu" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/afonsojramos"><img src="https://avatars.githubusercontent.com/u/19473034?v=4?s=100" width="100px;" alt="Afonso Jorge Ramos"/><br /><sub><b>Afonso Jorge Ramos</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=afonsojramos" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://tjenkinson.me/"><img src="https://avatars.githubusercontent.com/u/3259993?v=4?s=100" width="100px;" alt="Tom Jenkinson"/><br /><sub><b>Tom Jenkinson</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=tjenkinson" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/phormio"><img src="https://avatars.githubusercontent.com/u/28146332?v=4?s=100" width="100px;" alt="phormio"/><br /><sub><b>phormio</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=phormio" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://buildo.io/"><img src="https://avatars.githubusercontent.com/u/2643520?v=4?s=100" width="100px;" alt="Giovanni Gonzaga"/><br /><sub><b>Giovanni Gonzaga</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=giogonzo" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=giogonzo" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://caurea.org/"><img src="https://avatars.githubusercontent.com/u/34538?v=4?s=100" width="100px;" alt="Tomas Carnecky"/><br /><sub><b>Tomas Carnecky</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=wereHamster" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Djaler"><img src="https://avatars.githubusercontent.com/u/7964583?v=4?s=100" width="100px;" alt="Kirill Romanov"/><br /><sub><b>Kirill Romanov</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=Djaler" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=Djaler" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=Djaler" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://giovannyg.github.io/"><img src="https://avatars.githubusercontent.com/u/5326411?v=4?s=100" width="100px;" alt="Giovanny González"/><br /><sub><b>Giovanny González</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=giovannyg" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/markkulube"><img src="https://avatars.githubusercontent.com/u/34955942?v=4?s=100" width="100px;" alt="Mark Kulube"/><br /><sub><b>Mark Kulube</b></sub></a><br /><a href="#infra-markkulube" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.undiscoveredfeatures.com/"><img src="https://avatars.githubusercontent.com/u/354848?v=4?s=100" width="100px;" alt="Peter Hamilton"/><br /><sub><b>Peter Hamilton</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=hamiltop" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ChineduOzodi"><img src="https://avatars.githubusercontent.com/u/11678369?v=4?s=100" width="100px;" alt="Chinedu Ozodi"/><br /><sub><b>Chinedu Ozodi</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=ChineduOzodi" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gunar"><img src="https://avatars.githubusercontent.com/u/7684574?v=4?s=100" width="100px;" alt="Gunar Gessner"/><br /><sub><b>Gunar Gessner</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=gunar" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/CSBatchelor"><img src="https://avatars.githubusercontent.com/u/18668440?v=4?s=100" width="100px;" alt="Christian Batchelor"/><br /><sub><b>Christian Batchelor</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=CSBatchelor" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://tomeraberba.ch/"><img src="https://avatars.githubusercontent.com/u/23299544?v=4?s=100" width="100px;" alt="Tomer Aberbach"/><br /><sub><b>Tomer Aberbach</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=TomerAberbach" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=TomerAberbach" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=TomerAberbach" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/0xflotus"><img src="https://avatars.githubusercontent.com/u/26602940?v=4?s=100" width="100px;" alt="0xflotus"/><br /><sub><b>0xflotus</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=0xflotus" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/CodeLenny"><img src="https://avatars.githubusercontent.com/u/9272847?v=4?s=100" width="100px;" alt="Ryan Leonard"/><br /><sub><b>Ryan Leonard</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=CodeLenny" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=CodeLenny" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=CodeLenny" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://blog.bitjson.com/"><img src="https://avatars.githubusercontent.com/u/904007?v=4?s=100" width="100px;" alt="Jason Dreyzehner"/><br /><sub><b>Jason Dreyzehner</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=bitjson" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=bitjson" title="Tests">⚠️</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://matinzd.dev/"><img src="https://avatars.githubusercontent.com/u/24797481?v=4?s=100" width="100px;" alt="Matin Zadeh Dolatabad"/><br /><sub><b>Matin Zadeh Dolatabad</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=matinzd" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://goo.gl/IlWG8U"><img src="https://avatars.githubusercontent.com/u/500?v=4?s=100" width="100px;" alt="Juan Julián Merelo Guervós"/><br /><sub><b>Juan Julián Merelo Guervós</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=JJ" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/SimenB"><img src="https://avatars.githubusercontent.com/u/1404810?v=4?s=100" width="100px;" alt="Simen Bekkhus"/><br /><sub><b>Simen Bekkhus</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=SimenB" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/tskj"><img src="https://avatars.githubusercontent.com/u/25415972?v=4?s=100" width="100px;" alt="Tarjei Skjærset"/><br /><sub><b>Tarjei Skjærset</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=tskj" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://denisgorbachev.com/"><img src="https://avatars.githubusercontent.com/u/829578?v=4?s=100" width="100px;" alt="Denis Gorbachev"/><br /><sub><b>Denis Gorbachev</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=DenisGorbachev" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://senocular.github.io/"><img src="https://avatars.githubusercontent.com/u/3536716?v=4?s=100" width="100px;" alt="Trevor McCauley"/><br /><sub><b>Trevor McCauley</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=senocular" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://grantkiely.com/"><img src="https://avatars.githubusercontent.com/u/1948935?v=4?s=100" width="100px;" alt="Grant Kiely"/><br /><sub><b>Grant Kiely</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=gkiely" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/vecerek"><img src="https://avatars.githubusercontent.com/u/5737996?v=4?s=100" width="100px;" alt="Attila Večerek"/><br /><sub><b>Attila Večerek</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=vecerek" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=vecerek" title="Documentation">📖</a> <a href="https://github.com/dubzzz/fast-check/commits?author=vecerek" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="http://www.zachbjornson.com/"><img src="https://avatars.githubusercontent.com/u/469365?v=4?s=100" width="100px;" alt="Zach Bjornson"/><br /><sub><b>Zach Bjornson</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=zbjornson" title="Code">💻</a> <a href="https://github.com/dubzzz/fast-check/commits?author=zbjornson" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/bennettp123"><img src="https://avatars.githubusercontent.com/u/1610227?v=4?s=100" width="100px;" alt="Bennett Perkins"/><br /><sub><b>Bennett Perkins</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=bennettp123" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nielk"><img src="https://avatars.githubusercontent.com/u/4980521?v=4?s=100" width="100px;" alt="Alexandre Oger"/><br /><sub><b>Alexandre Oger</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=nielk" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ej-shafran"><img src="https://avatars.githubusercontent.com/u/116496520?v=4?s=100" width="100px;" alt="ej shafran"/><br /><sub><b>ej shafran</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=ej-shafran" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gruhn"><img src="https://avatars.githubusercontent.com/u/26570572?v=4?s=100" width="100px;" alt="Niklas Gruhn"/><br /><sub><b>Niklas Gruhn</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=gruhn" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://patrickroza.com/"><img src="https://avatars.githubusercontent.com/u/42661?v=4?s=100" width="100px;" alt="Patrick Roza"/><br /><sub><b>Patrick Roza</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=patroza" title="Code">💻</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/cindywu"><img src="https://avatars.githubusercontent.com/u/1177031?v=4?s=100" width="100px;" alt="Cindy Wu"/><br /><sub><b>Cindy Wu</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=cindywu" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/nmay231"><img src="https://avatars.githubusercontent.com/u/35386821?v=4?s=100" width="100px;" alt="Noah"/><br /><sub><b>Noah</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=nmay231" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jamesbvaughan"><img src="https://avatars.githubusercontent.com/u/2906913?v=4?s=100" width="100px;" alt="James Vaughan"/><br /><sub><b>James Vaughan</b></sub></a><br /><a href="https://github.com/dubzzz/fast-check/commits?author=jamesbvaughan" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! [Become one of them](CONTRIBUTING.md)
## Sponsors 💸
Many individuals and companies offer their financial support to the project, a huge thanks to all of them too 💓
<a href="https://github.com/sponsors/dubzzz"><img align="center" src="https://raw.githubusercontent.com/dubzzz/sponsors-svg/main/sponsorkit/sponsors.svg" alt="all sponsors" /></a>
You can also become one of them by contributing via [GitHub Sponsors](https://github.com/sponsors/dubzzz) or [OpenCollective](https://opencollective.com/fast-check/contribute).

View File

@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.adapter = adapter;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const Stream_1 = require("../../stream/Stream");
const AdaptedValue = Symbol('adapted-value');
function toAdapterValue(rawValue, adapter) {
const adapted = adapter(rawValue.value_);
if (!adapted.adapted) {
return rawValue;
}
return new Value_1.Value(adapted.value, AdaptedValue);
}
class AdapterArbitrary extends Arbitrary_1.Arbitrary {
constructor(sourceArb, adapter) {
super();
this.sourceArb = sourceArb;
this.adapter = adapter;
this.adaptValue = (rawValue) => toAdapterValue(rawValue, adapter);
}
generate(mrng, biasFactor) {
const rawValue = this.sourceArb.generate(mrng, biasFactor);
return this.adaptValue(rawValue);
}
canShrinkWithoutContext(value) {
return this.sourceArb.canShrinkWithoutContext(value) && !this.adapter(value).adapted;
}
shrink(value, context) {
if (context === AdaptedValue) {
if (!this.sourceArb.canShrinkWithoutContext(value)) {
return Stream_1.Stream.nil();
}
return this.sourceArb.shrink(value, undefined).map(this.adaptValue);
}
return this.sourceArb.shrink(value, context).map(this.adaptValue);
}
}
function adapter(sourceArb, adapter) {
return new AdapterArbitrary(sourceArb, adapter);
}

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlwaysShrinkableArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Stream_1 = require("../../stream/Stream");
const NoUndefinedAsContext_1 = require("./helpers/NoUndefinedAsContext");
class AlwaysShrinkableArbitrary extends Arbitrary_1.Arbitrary {
constructor(arb) {
super();
this.arb = arb;
}
generate(mrng, biasFactor) {
const value = this.arb.generate(mrng, biasFactor);
return (0, NoUndefinedAsContext_1.noUndefinedAsContext)(value);
}
canShrinkWithoutContext(value) {
return true;
}
shrink(value, context) {
if (context === undefined && !this.arb.canShrinkWithoutContext(value)) {
return Stream_1.Stream.nil();
}
const safeContext = context !== NoUndefinedAsContext_1.UndefinedContextPlaceholder ? context : undefined;
return this.arb.shrink(value, safeContext).map(NoUndefinedAsContext_1.noUndefinedAsContext);
}
}
exports.AlwaysShrinkableArbitrary = AlwaysShrinkableArbitrary;

View File

@@ -0,0 +1,223 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayArbitrary = void 0;
const Stream_1 = require("../../stream/Stream");
const symbols_1 = require("../../check/symbols");
const integer_1 = require("../integer");
const LazyIterableIterator_1 = require("../../stream/LazyIterableIterator");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const DepthContext_1 = require("./helpers/DepthContext");
const BuildSlicedGenerator_1 = require("./helpers/BuildSlicedGenerator");
const globals_1 = require("../../utils/globals");
const safeMathFloor = Math.floor;
const safeMathLog = Math.log;
const safeMathMax = Math.max;
const safeArrayIsArray = Array.isArray;
function biasedMaxLength(minLength, maxLength) {
if (minLength === maxLength) {
return minLength;
}
return minLength + safeMathFloor(safeMathLog(maxLength - minLength) / safeMathLog(2));
}
class ArrayArbitrary extends Arbitrary_1.Arbitrary {
constructor(arb, minLength, maxGeneratedLength, maxLength, depthIdentifier, setBuilder, customSlices) {
super();
this.arb = arb;
this.minLength = minLength;
this.maxGeneratedLength = maxGeneratedLength;
this.maxLength = maxLength;
this.setBuilder = setBuilder;
this.customSlices = customSlices;
this.lengthArb = (0, integer_1.integer)({ min: minLength, max: maxGeneratedLength });
this.depthContext = (0, DepthContext_1.getDepthContextFor)(depthIdentifier);
}
preFilter(tab) {
if (this.setBuilder === undefined) {
return tab;
}
const s = this.setBuilder();
for (let index = 0; index !== tab.length; ++index) {
s.tryAdd(tab[index]);
}
return s.getData();
}
static makeItCloneable(vs, shrinkables) {
vs[symbols_1.cloneMethod] = () => {
const cloned = [];
for (let idx = 0; idx !== shrinkables.length; ++idx) {
(0, globals_1.safePush)(cloned, shrinkables[idx].value);
}
this.makeItCloneable(cloned, shrinkables);
return cloned;
};
return vs;
}
generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) {
let numSkippedInRow = 0;
const s = setBuilder();
const slicedGenerator = (0, BuildSlicedGenerator_1.buildSlicedGenerator)(this.arb, mrng, this.customSlices, biasFactorItems);
while (s.size() < N && numSkippedInRow < this.maxGeneratedLength) {
const current = slicedGenerator.next();
if (s.tryAdd(current)) {
numSkippedInRow = 0;
}
else {
numSkippedInRow += 1;
}
}
return s.getData();
}
safeGenerateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems) {
const depthImpact = safeMathMax(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength));
this.depthContext.depth += depthImpact;
try {
return this.generateNItemsNoDuplicates(setBuilder, N, mrng, biasFactorItems);
}
finally {
this.depthContext.depth -= depthImpact;
}
}
generateNItems(N, mrng, biasFactorItems) {
const items = [];
const slicedGenerator = (0, BuildSlicedGenerator_1.buildSlicedGenerator)(this.arb, mrng, this.customSlices, biasFactorItems);
slicedGenerator.attemptExact(N);
for (let index = 0; index !== N; ++index) {
const current = slicedGenerator.next();
(0, globals_1.safePush)(items, current);
}
return items;
}
safeGenerateNItems(N, mrng, biasFactorItems) {
const depthImpact = safeMathMax(0, N - biasedMaxLength(this.minLength, this.maxGeneratedLength));
this.depthContext.depth += depthImpact;
try {
return this.generateNItems(N, mrng, biasFactorItems);
}
finally {
this.depthContext.depth -= depthImpact;
}
}
wrapper(itemsRaw, shrunkOnce, itemsRawLengthContext, startIndex) {
const items = shrunkOnce ? this.preFilter(itemsRaw) : itemsRaw;
let cloneable = false;
const vs = [];
const itemsContexts = [];
for (let idx = 0; idx !== items.length; ++idx) {
const s = items[idx];
cloneable = cloneable || s.hasToBeCloned;
(0, globals_1.safePush)(vs, s.value);
(0, globals_1.safePush)(itemsContexts, s.context);
}
if (cloneable) {
ArrayArbitrary.makeItCloneable(vs, items);
}
const context = {
shrunkOnce,
lengthContext: itemsRaw.length === items.length && itemsRawLengthContext !== undefined
? itemsRawLengthContext
: undefined,
itemsContexts,
startIndex,
};
return new Value_1.Value(vs, context);
}
generate(mrng, biasFactor) {
const biasMeta = this.applyBias(mrng, biasFactor);
const targetSize = biasMeta.size;
const items = this.setBuilder !== undefined
? this.safeGenerateNItemsNoDuplicates(this.setBuilder, targetSize, mrng, biasMeta.biasFactorItems)
: this.safeGenerateNItems(targetSize, mrng, biasMeta.biasFactorItems);
return this.wrapper(items, false, undefined, 0);
}
applyBias(mrng, biasFactor) {
if (biasFactor === undefined) {
return { size: this.lengthArb.generate(mrng, undefined).value };
}
if (this.minLength === this.maxGeneratedLength) {
return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor };
}
if (mrng.nextInt(1, biasFactor) !== 1) {
return { size: this.lengthArb.generate(mrng, undefined).value };
}
if (mrng.nextInt(1, biasFactor) !== 1 || this.minLength === this.maxGeneratedLength) {
return { size: this.lengthArb.generate(mrng, undefined).value, biasFactorItems: biasFactor };
}
const maxBiasedLength = biasedMaxLength(this.minLength, this.maxGeneratedLength);
const targetSizeValue = (0, integer_1.integer)({ min: this.minLength, max: maxBiasedLength }).generate(mrng, undefined);
return { size: targetSizeValue.value, biasFactorItems: biasFactor };
}
canShrinkWithoutContext(value) {
if (!safeArrayIsArray(value) || this.minLength > value.length || value.length > this.maxLength) {
return false;
}
for (let index = 0; index !== value.length; ++index) {
if (!(index in value)) {
return false;
}
if (!this.arb.canShrinkWithoutContext(value[index])) {
return false;
}
}
const filtered = this.preFilter((0, globals_1.safeMap)(value, (item) => new Value_1.Value(item, undefined)));
return filtered.length === value.length;
}
shrinkItemByItem(value, safeContext, endIndex) {
const shrinks = [];
for (let index = safeContext.startIndex; index < endIndex; ++index) {
(0, globals_1.safePush)(shrinks, (0, LazyIterableIterator_1.makeLazy)(() => this.arb.shrink(value[index], safeContext.itemsContexts[index]).map((v) => {
const beforeCurrent = (0, globals_1.safeMap)((0, globals_1.safeSlice)(value, 0, index), (v, i) => new Value_1.Value((0, symbols_1.cloneIfNeeded)(v), safeContext.itemsContexts[i]));
const afterCurrent = (0, globals_1.safeMap)((0, globals_1.safeSlice)(value, index + 1), (v, i) => new Value_1.Value((0, symbols_1.cloneIfNeeded)(v), safeContext.itemsContexts[i + index + 1]));
return [
[...beforeCurrent, v, ...afterCurrent],
undefined,
index,
];
})));
}
return Stream_1.Stream.nil().join(...shrinks);
}
shrinkImpl(value, context) {
if (value.length === 0) {
return Stream_1.Stream.nil();
}
const safeContext = context !== undefined
? context
: { shrunkOnce: false, lengthContext: undefined, itemsContexts: [], startIndex: 0 };
return (this.lengthArb
.shrink(value.length, safeContext.lengthContext)
.drop(safeContext.shrunkOnce && safeContext.lengthContext === undefined && value.length > this.minLength + 1
? 1
: 0)
.map((lengthValue) => {
const sliceStart = value.length - lengthValue.value;
return [
(0, globals_1.safeMap)((0, globals_1.safeSlice)(value, sliceStart), (v, index) => new Value_1.Value((0, symbols_1.cloneIfNeeded)(v), safeContext.itemsContexts[index + sliceStart])),
lengthValue.context,
0,
];
})
.join((0, LazyIterableIterator_1.makeLazy)(() => value.length > this.minLength
? this.shrinkItemByItem(value, safeContext, 1)
: this.shrinkItemByItem(value, safeContext, value.length)))
.join(value.length > this.minLength
? (0, LazyIterableIterator_1.makeLazy)(() => {
const subContext = {
shrunkOnce: false,
lengthContext: undefined,
itemsContexts: (0, globals_1.safeSlice)(safeContext.itemsContexts, 1),
startIndex: 0,
};
return this.shrinkImpl((0, globals_1.safeSlice)(value, 1), subContext)
.filter((v) => this.minLength <= v[0].length + 1)
.map((v) => {
return [[new Value_1.Value((0, symbols_1.cloneIfNeeded)(value[0]), safeContext.itemsContexts[0]), ...v[0]], undefined, 0];
});
})
: Stream_1.Stream.nil()));
}
shrink(value, context) {
return this.shrinkImpl(value, context).map((contextualValue) => this.wrapper(contextualValue[0], true, contextualValue[1], contextualValue[2]));
}
}
exports.ArrayArbitrary = ArrayArbitrary;

View File

@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayInt64 = arrayInt64;
const Stream_1 = require("../../stream/Stream");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const ArrayInt64_1 = require("./helpers/ArrayInt64");
class ArrayInt64Arbitrary extends Arbitrary_1.Arbitrary {
constructor(min, max) {
super();
this.min = min;
this.max = max;
this.biasedRanges = null;
}
generate(mrng, biasFactor) {
const range = this.computeGenerateRange(mrng, biasFactor);
const uncheckedValue = mrng.nextArrayInt(range.min, range.max);
if (uncheckedValue.data.length === 1) {
uncheckedValue.data.unshift(0);
}
return new Value_1.Value(uncheckedValue, undefined);
}
computeGenerateRange(mrng, biasFactor) {
if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {
return { min: this.min, max: this.max };
}
const ranges = this.retrieveBiasedRanges();
if (ranges.length === 1) {
return ranges[0];
}
const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2);
return id < 0 ? ranges[0] : ranges[id + 1];
}
canShrinkWithoutContext(value) {
const unsafeValue = value;
return (typeof value === 'object' &&
value !== null &&
(unsafeValue.sign === -1 || unsafeValue.sign === 1) &&
Array.isArray(unsafeValue.data) &&
unsafeValue.data.length === 2 &&
(((0, ArrayInt64_1.isStrictlySmaller64)(this.min, unsafeValue) && (0, ArrayInt64_1.isStrictlySmaller64)(unsafeValue, this.max)) ||
(0, ArrayInt64_1.isEqual64)(this.min, unsafeValue) ||
(0, ArrayInt64_1.isEqual64)(this.max, unsafeValue)));
}
shrinkArrayInt64(value, target, tryTargetAsap) {
const realGap = (0, ArrayInt64_1.substract64)(value, target);
function* shrinkGen() {
let previous = tryTargetAsap ? undefined : target;
const gap = tryTargetAsap ? realGap : (0, ArrayInt64_1.halve64)(realGap);
for (let toremove = gap; !(0, ArrayInt64_1.isZero64)(toremove); toremove = (0, ArrayInt64_1.halve64)(toremove)) {
const next = (0, ArrayInt64_1.substract64)(value, toremove);
yield new Value_1.Value(next, previous);
previous = next;
}
}
return (0, Stream_1.stream)(shrinkGen());
}
shrink(current, context) {
if (!ArrayInt64Arbitrary.isValidContext(current, context)) {
const target = this.defaultTarget();
return this.shrinkArrayInt64(current, target, true);
}
if (this.isLastChanceTry(current, context)) {
return Stream_1.Stream.of(new Value_1.Value(context, undefined));
}
return this.shrinkArrayInt64(current, context, false);
}
defaultTarget() {
if (!(0, ArrayInt64_1.isStrictlyPositive64)(this.min) && !(0, ArrayInt64_1.isStrictlyNegative64)(this.max)) {
return ArrayInt64_1.Zero64;
}
return (0, ArrayInt64_1.isStrictlyNegative64)(this.min) ? this.max : this.min;
}
isLastChanceTry(current, context) {
if ((0, ArrayInt64_1.isZero64)(current)) {
return false;
}
if (current.sign === 1) {
return (0, ArrayInt64_1.isEqual64)(current, (0, ArrayInt64_1.add64)(context, ArrayInt64_1.Unit64)) && (0, ArrayInt64_1.isStrictlyPositive64)((0, ArrayInt64_1.substract64)(current, this.min));
}
else {
return (0, ArrayInt64_1.isEqual64)(current, (0, ArrayInt64_1.substract64)(context, ArrayInt64_1.Unit64)) && (0, ArrayInt64_1.isStrictlyNegative64)((0, ArrayInt64_1.substract64)(current, this.max));
}
}
static isValidContext(_current, context) {
if (context === undefined) {
return false;
}
if (typeof context !== 'object' || context === null || !('sign' in context) || !('data' in context)) {
throw new Error(`Invalid context type passed to ArrayInt64Arbitrary (#1)`);
}
return true;
}
retrieveBiasedRanges() {
if (this.biasedRanges != null) {
return this.biasedRanges;
}
if ((0, ArrayInt64_1.isEqual64)(this.min, this.max)) {
this.biasedRanges = [{ min: this.min, max: this.max }];
return this.biasedRanges;
}
const minStrictlySmallerZero = (0, ArrayInt64_1.isStrictlyNegative64)(this.min);
const maxStrictlyGreaterZero = (0, ArrayInt64_1.isStrictlyPositive64)(this.max);
if (minStrictlySmallerZero && maxStrictlyGreaterZero) {
const logMin = (0, ArrayInt64_1.logLike64)(this.min);
const logMax = (0, ArrayInt64_1.logLike64)(this.max);
this.biasedRanges = [
{ min: logMin, max: logMax },
{ min: (0, ArrayInt64_1.substract64)(this.max, logMax), max: this.max },
{ min: this.min, max: (0, ArrayInt64_1.substract64)(this.min, logMin) },
];
}
else {
const logGap = (0, ArrayInt64_1.logLike64)((0, ArrayInt64_1.substract64)(this.max, this.min));
const arbCloseToMin = { min: this.min, max: (0, ArrayInt64_1.add64)(this.min, logGap) };
const arbCloseToMax = { min: (0, ArrayInt64_1.substract64)(this.max, logGap), max: this.max };
this.biasedRanges = minStrictlySmallerZero
? [arbCloseToMax, arbCloseToMin]
: [arbCloseToMin, arbCloseToMax];
}
return this.biasedRanges;
}
}
function arrayInt64(min, max) {
const arb = new ArrayInt64Arbitrary(min, max);
return arb;
}

View File

@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BigIntArbitrary = void 0;
const Stream_1 = require("../../stream/Stream");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const BiasNumericRange_1 = require("./helpers/BiasNumericRange");
const ShrinkBigInt_1 = require("./helpers/ShrinkBigInt");
const globals_1 = require("../../utils/globals");
class BigIntArbitrary extends Arbitrary_1.Arbitrary {
constructor(min, max) {
super();
this.min = min;
this.max = max;
}
generate(mrng, biasFactor) {
const range = this.computeGenerateRange(mrng, biasFactor);
return new Value_1.Value(mrng.nextBigInt(range.min, range.max), undefined);
}
computeGenerateRange(mrng, biasFactor) {
if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {
return { min: this.min, max: this.max };
}
const ranges = (0, BiasNumericRange_1.biasNumericRange)(this.min, this.max, BiasNumericRange_1.bigIntLogLike);
if (ranges.length === 1) {
return ranges[0];
}
const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2);
return id < 0 ? ranges[0] : ranges[id + 1];
}
canShrinkWithoutContext(value) {
return typeof value === 'bigint' && this.min <= value && value <= this.max;
}
shrink(current, context) {
if (!BigIntArbitrary.isValidContext(current, context)) {
const target = this.defaultTarget();
return (0, ShrinkBigInt_1.shrinkBigInt)(current, target, true);
}
if (this.isLastChanceTry(current, context)) {
return Stream_1.Stream.of(new Value_1.Value(context, undefined));
}
return (0, ShrinkBigInt_1.shrinkBigInt)(current, context, false);
}
defaultTarget() {
if (this.min <= 0 && this.max >= 0) {
return (0, globals_1.BigInt)(0);
}
return this.min < 0 ? this.max : this.min;
}
isLastChanceTry(current, context) {
if (current > 0)
return current === context + (0, globals_1.BigInt)(1) && current > this.min;
if (current < 0)
return current === context - (0, globals_1.BigInt)(1) && current < this.max;
return false;
}
static isValidContext(current, context) {
if (context === undefined) {
return false;
}
if (typeof context !== 'bigint') {
throw new Error(`Invalid context type passed to BigIntArbitrary (#1)`);
}
const differentSigns = (current > 0 && context < 0) || (current < 0 && context > 0);
if (context !== (0, globals_1.BigInt)(0) && differentSigns) {
throw new Error(`Invalid context value passed to BigIntArbitrary (#2)`);
}
return true;
}
}
exports.BigIntArbitrary = BigIntArbitrary;

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloneArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const symbols_1 = require("../../check/symbols");
const Stream_1 = require("../../stream/Stream");
const globals_1 = require("../../utils/globals");
const safeSymbolIterator = Symbol.iterator;
const safeIsArray = Array.isArray;
const safeObjectIs = Object.is;
class CloneArbitrary extends Arbitrary_1.Arbitrary {
constructor(arb, numValues) {
super();
this.arb = arb;
this.numValues = numValues;
}
generate(mrng, biasFactor) {
const items = [];
if (this.numValues <= 0) {
return this.wrapper(items);
}
for (let idx = 0; idx !== this.numValues - 1; ++idx) {
(0, globals_1.safePush)(items, this.arb.generate(mrng.clone(), biasFactor));
}
(0, globals_1.safePush)(items, this.arb.generate(mrng, biasFactor));
return this.wrapper(items);
}
canShrinkWithoutContext(value) {
if (!safeIsArray(value) || value.length !== this.numValues) {
return false;
}
if (value.length === 0) {
return true;
}
for (let index = 1; index < value.length; ++index) {
if (!safeObjectIs(value[0], value[index])) {
return false;
}
}
return this.arb.canShrinkWithoutContext(value[0]);
}
shrink(value, context) {
if (value.length === 0) {
return Stream_1.Stream.nil();
}
return new Stream_1.Stream(this.shrinkImpl(value, context !== undefined ? context : [])).map((v) => this.wrapper(v));
}
*shrinkImpl(value, contexts) {
const its = (0, globals_1.safeMap)(value, (v, idx) => this.arb.shrink(v, contexts[idx])[safeSymbolIterator]());
let cur = (0, globals_1.safeMap)(its, (it) => it.next());
while (!cur[0].done) {
yield (0, globals_1.safeMap)(cur, (c) => c.value);
cur = (0, globals_1.safeMap)(its, (it) => it.next());
}
}
static makeItCloneable(vs, shrinkables) {
vs[symbols_1.cloneMethod] = () => {
const cloned = [];
for (let idx = 0; idx !== shrinkables.length; ++idx) {
(0, globals_1.safePush)(cloned, shrinkables[idx].value);
}
this.makeItCloneable(cloned, shrinkables);
return cloned;
};
return vs;
}
wrapper(items) {
let cloneable = false;
const vs = [];
const contexts = [];
for (let idx = 0; idx !== items.length; ++idx) {
const s = items[idx];
cloneable = cloneable || s.hasToBeCloned;
(0, globals_1.safePush)(vs, s.value);
(0, globals_1.safePush)(contexts, s.context);
}
if (cloneable) {
CloneArbitrary.makeItCloneable(vs, items);
}
return new Value_1.Value(vs, contexts);
}
}
exports.CloneArbitrary = CloneArbitrary;

View File

@@ -0,0 +1,110 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandsArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const CommandsIterable_1 = require("../../check/model/commands/CommandsIterable");
const CommandWrapper_1 = require("../../check/model/commands/CommandWrapper");
const ReplayPath_1 = require("../../check/model/ReplayPath");
const LazyIterableIterator_1 = require("../../stream/LazyIterableIterator");
const Stream_1 = require("../../stream/Stream");
const oneof_1 = require("../oneof");
const RestrictedIntegerArbitraryBuilder_1 = require("./builders/RestrictedIntegerArbitraryBuilder");
class CommandsArbitrary extends Arbitrary_1.Arbitrary {
constructor(commandArbs, maxGeneratedCommands, maxCommands, sourceReplayPath, disableReplayLog) {
super();
this.sourceReplayPath = sourceReplayPath;
this.disableReplayLog = disableReplayLog;
this.oneCommandArb = (0, oneof_1.oneof)(...commandArbs).map((c) => new CommandWrapper_1.CommandWrapper(c));
this.lengthArb = (0, RestrictedIntegerArbitraryBuilder_1.restrictedIntegerArbitraryBuilder)(0, maxGeneratedCommands, maxCommands);
this.replayPath = [];
this.replayPathPosition = 0;
}
metadataForReplay() {
return this.disableReplayLog ? '' : `replayPath=${JSON.stringify(ReplayPath_1.ReplayPath.stringify(this.replayPath))}`;
}
buildValueFor(items, shrunkOnce) {
const commands = items.map((item) => item.value_);
const context = { shrunkOnce, items };
return new Value_1.Value(new CommandsIterable_1.CommandsIterable(commands, () => this.metadataForReplay()), context);
}
generate(mrng) {
const size = this.lengthArb.generate(mrng, undefined);
const sizeValue = size.value;
const items = Array(sizeValue);
for (let idx = 0; idx !== sizeValue; ++idx) {
const item = this.oneCommandArb.generate(mrng, undefined);
items[idx] = item;
}
this.replayPathPosition = 0;
return this.buildValueFor(items, false);
}
canShrinkWithoutContext(value) {
return false;
}
filterOnExecution(itemsRaw) {
const items = [];
for (const c of itemsRaw) {
if (c.value_.hasRan) {
this.replayPath.push(true);
items.push(c);
}
else
this.replayPath.push(false);
}
return items;
}
filterOnReplay(itemsRaw) {
return itemsRaw.filter((c, idx) => {
const state = this.replayPath[this.replayPathPosition + idx];
if (state === undefined)
throw new Error(`Too short replayPath`);
if (!state && c.value_.hasRan)
throw new Error(`Mismatch between replayPath and real execution`);
return state;
});
}
filterForShrinkImpl(itemsRaw) {
if (this.replayPathPosition === 0) {
this.replayPath = this.sourceReplayPath !== null ? ReplayPath_1.ReplayPath.parse(this.sourceReplayPath) : [];
}
const items = this.replayPathPosition < this.replayPath.length
? this.filterOnReplay(itemsRaw)
: this.filterOnExecution(itemsRaw);
this.replayPathPosition += itemsRaw.length;
return items;
}
shrink(_value, context) {
if (context === undefined) {
return Stream_1.Stream.nil();
}
const safeContext = context;
const shrunkOnce = safeContext.shrunkOnce;
const itemsRaw = safeContext.items;
const items = this.filterForShrinkImpl(itemsRaw);
if (items.length === 0) {
return Stream_1.Stream.nil();
}
const rootShrink = shrunkOnce
? Stream_1.Stream.nil()
: new Stream_1.Stream([[]][Symbol.iterator]());
const nextShrinks = [];
for (let numToKeep = 0; numToKeep !== items.length; ++numToKeep) {
nextShrinks.push((0, LazyIterableIterator_1.makeLazy)(() => {
const fixedStart = items.slice(0, numToKeep);
return this.lengthArb
.shrink(items.length - 1 - numToKeep, undefined)
.map((l) => fixedStart.concat(items.slice(items.length - (l.value + 1))));
}));
}
for (let itemAt = 0; itemAt !== items.length; ++itemAt) {
nextShrinks.push((0, LazyIterableIterator_1.makeLazy)(() => this.oneCommandArb
.shrink(items[itemAt].value_, items[itemAt].context)
.map((v) => items.slice(0, itemAt).concat([v], items.slice(itemAt + 1)))));
}
return rootShrink.join(...nextShrinks).map((shrinkables) => {
return this.buildValueFor(shrinkables.map((c) => new Value_1.Value(c.value_.clone(), c.context)), true);
});
}
}
exports.CommandsArbitrary = CommandsArbitrary;

View File

@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConstantArbitrary = void 0;
const Stream_1 = require("../../stream/Stream");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const symbols_1 = require("../../check/symbols");
const globals_1 = require("../../utils/globals");
const safeObjectIs = Object.is;
class ConstantArbitrary extends Arbitrary_1.Arbitrary {
constructor(values) {
super();
this.values = values;
}
generate(mrng, _biasFactor) {
const idx = this.values.length === 1 ? 0 : mrng.nextInt(0, this.values.length - 1);
const value = this.values[idx];
if (!(0, symbols_1.hasCloneMethod)(value)) {
return new Value_1.Value(value, idx);
}
return new Value_1.Value(value, idx, () => value[symbols_1.cloneMethod]());
}
canShrinkWithoutContext(value) {
if (this.values.length === 1) {
return safeObjectIs(this.values[0], value);
}
if (this.fastValues === undefined) {
this.fastValues = new FastConstantValuesLookup(this.values);
}
return this.fastValues.has(value);
}
shrink(value, context) {
if (context === 0 || safeObjectIs(value, this.values[0])) {
return Stream_1.Stream.nil();
}
return Stream_1.Stream.of(new Value_1.Value(this.values[0], 0));
}
}
exports.ConstantArbitrary = ConstantArbitrary;
class FastConstantValuesLookup {
constructor(values) {
this.values = values;
this.fastValues = new globals_1.Set(this.values);
let hasMinusZero = false;
let hasPlusZero = false;
if ((0, globals_1.safeHas)(this.fastValues, 0)) {
for (let idx = 0; idx !== this.values.length; ++idx) {
const value = this.values[idx];
hasMinusZero = hasMinusZero || safeObjectIs(value, -0);
hasPlusZero = hasPlusZero || safeObjectIs(value, 0);
}
}
this.hasMinusZero = hasMinusZero;
this.hasPlusZero = hasPlusZero;
}
has(value) {
if (value === 0) {
if (safeObjectIs(value, 0)) {
return this.hasPlusZero;
}
return this.hasMinusZero;
}
return (0, globals_1.safeHas)(this.fastValues, value);
}
}

View File

@@ -0,0 +1,166 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FrequencyArbitrary = void 0;
const Stream_1 = require("../../stream/Stream");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const DepthContext_1 = require("./helpers/DepthContext");
const MaxLengthFromMinLength_1 = require("./helpers/MaxLengthFromMinLength");
const globals_1 = require("../../utils/globals");
const safePositiveInfinity = Number.POSITIVE_INFINITY;
const safeMaxSafeInteger = Number.MAX_SAFE_INTEGER;
const safeNumberIsInteger = Number.isInteger;
const safeMathFloor = Math.floor;
const safeMathPow = Math.pow;
const safeMathMin = Math.min;
class FrequencyArbitrary extends Arbitrary_1.Arbitrary {
static from(warbs, constraints, label) {
if (warbs.length === 0) {
throw new Error(`${label} expects at least one weighted arbitrary`);
}
let totalWeight = 0;
for (let idx = 0; idx !== warbs.length; ++idx) {
const currentArbitrary = warbs[idx].arbitrary;
if (currentArbitrary === undefined) {
throw new Error(`${label} expects arbitraries to be specified`);
}
const currentWeight = warbs[idx].weight;
totalWeight += currentWeight;
if (!safeNumberIsInteger(currentWeight)) {
throw new Error(`${label} expects weights to be integer values`);
}
if (currentWeight < 0) {
throw new Error(`${label} expects weights to be superior or equal to 0`);
}
}
if (totalWeight <= 0) {
throw new Error(`${label} expects the sum of weights to be strictly superior to 0`);
}
const sanitizedConstraints = {
depthBias: (0, MaxLengthFromMinLength_1.depthBiasFromSizeForArbitrary)(constraints.depthSize, constraints.maxDepth !== undefined),
maxDepth: constraints.maxDepth != undefined ? constraints.maxDepth : safePositiveInfinity,
withCrossShrink: !!constraints.withCrossShrink,
};
return new FrequencyArbitrary(warbs, sanitizedConstraints, (0, DepthContext_1.getDepthContextFor)(constraints.depthIdentifier));
}
constructor(warbs, constraints, context) {
super();
this.warbs = warbs;
this.constraints = constraints;
this.context = context;
let currentWeight = 0;
this.cumulatedWeights = [];
for (let idx = 0; idx !== warbs.length; ++idx) {
currentWeight += warbs[idx].weight;
(0, globals_1.safePush)(this.cumulatedWeights, currentWeight);
}
this.totalWeight = currentWeight;
}
generate(mrng, biasFactor) {
if (this.mustGenerateFirst()) {
return this.safeGenerateForIndex(mrng, 0, biasFactor);
}
const selected = mrng.nextInt(this.computeNegDepthBenefit(), this.totalWeight - 1);
for (let idx = 0; idx !== this.cumulatedWeights.length; ++idx) {
if (selected < this.cumulatedWeights[idx]) {
return this.safeGenerateForIndex(mrng, idx, biasFactor);
}
}
throw new Error(`Unable to generate from fc.frequency`);
}
canShrinkWithoutContext(value) {
return this.canShrinkWithoutContextIndex(value) !== -1;
}
shrink(value, context) {
if (context !== undefined) {
const safeContext = context;
const selectedIndex = safeContext.selectedIndex;
const originalBias = safeContext.originalBias;
const originalArbitrary = this.warbs[selectedIndex].arbitrary;
const originalShrinks = originalArbitrary
.shrink(value, safeContext.originalContext)
.map((v) => this.mapIntoValue(selectedIndex, v, null, originalBias));
if (safeContext.clonedMrngForFallbackFirst !== null) {
if (safeContext.cachedGeneratedForFirst === undefined) {
safeContext.cachedGeneratedForFirst = this.safeGenerateForIndex(safeContext.clonedMrngForFallbackFirst, 0, originalBias);
}
const valueFromFirst = safeContext.cachedGeneratedForFirst;
return Stream_1.Stream.of(valueFromFirst).join(originalShrinks);
}
return originalShrinks;
}
const potentialSelectedIndex = this.canShrinkWithoutContextIndex(value);
if (potentialSelectedIndex === -1) {
return Stream_1.Stream.nil();
}
return this.defaultShrinkForFirst(potentialSelectedIndex).join(this.warbs[potentialSelectedIndex].arbitrary
.shrink(value, undefined)
.map((v) => this.mapIntoValue(potentialSelectedIndex, v, null, undefined)));
}
defaultShrinkForFirst(selectedIndex) {
++this.context.depth;
try {
if (!this.mustFallbackToFirstInShrink(selectedIndex) || this.warbs[0].fallbackValue === undefined) {
return Stream_1.Stream.nil();
}
}
finally {
--this.context.depth;
}
const rawShrinkValue = new Value_1.Value(this.warbs[0].fallbackValue.default, undefined);
return Stream_1.Stream.of(this.mapIntoValue(0, rawShrinkValue, null, undefined));
}
canShrinkWithoutContextIndex(value) {
if (this.mustGenerateFirst()) {
return this.warbs[0].arbitrary.canShrinkWithoutContext(value) ? 0 : -1;
}
try {
++this.context.depth;
for (let idx = 0; idx !== this.warbs.length; ++idx) {
const warb = this.warbs[idx];
if (warb.weight !== 0 && warb.arbitrary.canShrinkWithoutContext(value)) {
return idx;
}
}
return -1;
}
finally {
--this.context.depth;
}
}
mapIntoValue(idx, value, clonedMrngForFallbackFirst, biasFactor) {
const context = {
selectedIndex: idx,
originalBias: biasFactor,
originalContext: value.context,
clonedMrngForFallbackFirst,
};
return new Value_1.Value(value.value, context);
}
safeGenerateForIndex(mrng, idx, biasFactor) {
++this.context.depth;
try {
const value = this.warbs[idx].arbitrary.generate(mrng, biasFactor);
const clonedMrngForFallbackFirst = this.mustFallbackToFirstInShrink(idx) ? mrng.clone() : null;
return this.mapIntoValue(idx, value, clonedMrngForFallbackFirst, biasFactor);
}
finally {
--this.context.depth;
}
}
mustGenerateFirst() {
return this.constraints.maxDepth <= this.context.depth;
}
mustFallbackToFirstInShrink(idx) {
return idx !== 0 && this.constraints.withCrossShrink && this.warbs[0].weight !== 0;
}
computeNegDepthBenefit() {
const depthBias = this.constraints.depthBias;
if (depthBias <= 0 || this.warbs[0].weight === 0) {
return 0;
}
const depthBenefit = safeMathFloor(safeMathPow(1 + depthBias, this.context.depth)) - 1;
return -safeMathMin(this.totalWeight * depthBenefit, safeMaxSafeInteger) || 0;
}
}
exports.FrequencyArbitrary = FrequencyArbitrary;

View File

@@ -0,0 +1,44 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GeneratorArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Stream_1 = require("../../stream/Stream");
const globals_1 = require("../../utils/globals");
const GeneratorValueBuilder_1 = require("./builders/GeneratorValueBuilder");
const StableArbitraryGeneratorCache_1 = require("./builders/StableArbitraryGeneratorCache");
const TupleArbitrary_1 = require("./TupleArbitrary");
class GeneratorArbitrary extends Arbitrary_1.Arbitrary {
constructor() {
super(...arguments);
this.arbitraryCache = (0, StableArbitraryGeneratorCache_1.buildStableArbitraryGeneratorCache)(StableArbitraryGeneratorCache_1.naiveIsEqual);
}
generate(mrng, biasFactor) {
return (0, GeneratorValueBuilder_1.buildGeneratorValue)(mrng, biasFactor, () => [], this.arbitraryCache);
}
canShrinkWithoutContext(value) {
return false;
}
shrink(_value, context) {
if (context === undefined) {
return Stream_1.Stream.nil();
}
const safeContext = context;
const mrng = safeContext.mrng;
const biasFactor = safeContext.biasFactor;
const history = safeContext.history;
return (0, TupleArbitrary_1.tupleShrink)(history.map((c) => c.arb), history.map((c) => c.value), history.map((c) => c.context)).map((shrink) => {
function computePreBuiltValues() {
const subValues = shrink.value;
const subContexts = shrink.context;
return (0, globals_1.safeMap)(history, (entry, index) => ({
arb: entry.arb,
value: subValues[index],
context: subContexts[index],
mrng: entry.mrng,
}));
}
return (0, GeneratorValueBuilder_1.buildGeneratorValue)(mrng, biasFactor, computePreBuiltValues, this.arbitraryCache);
});
}
}
exports.GeneratorArbitrary = GeneratorArbitrary;

View File

@@ -0,0 +1,76 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntegerArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const Stream_1 = require("../../stream/Stream");
const BiasNumericRange_1 = require("./helpers/BiasNumericRange");
const ShrinkInteger_1 = require("./helpers/ShrinkInteger");
const safeMathSign = Math.sign;
const safeNumberIsInteger = Number.isInteger;
const safeObjectIs = Object.is;
class IntegerArbitrary extends Arbitrary_1.Arbitrary {
constructor(min, max) {
super();
this.min = min;
this.max = max;
}
generate(mrng, biasFactor) {
const range = this.computeGenerateRange(mrng, biasFactor);
return new Value_1.Value(mrng.nextInt(range.min, range.max), undefined);
}
canShrinkWithoutContext(value) {
return (typeof value === 'number' &&
safeNumberIsInteger(value) &&
!safeObjectIs(value, -0) &&
this.min <= value &&
value <= this.max);
}
shrink(current, context) {
if (!IntegerArbitrary.isValidContext(current, context)) {
const target = this.defaultTarget();
return (0, ShrinkInteger_1.shrinkInteger)(current, target, true);
}
if (this.isLastChanceTry(current, context)) {
return Stream_1.Stream.of(new Value_1.Value(context, undefined));
}
return (0, ShrinkInteger_1.shrinkInteger)(current, context, false);
}
defaultTarget() {
if (this.min <= 0 && this.max >= 0) {
return 0;
}
return this.min < 0 ? this.max : this.min;
}
computeGenerateRange(mrng, biasFactor) {
if (biasFactor === undefined || mrng.nextInt(1, biasFactor) !== 1) {
return { min: this.min, max: this.max };
}
const ranges = (0, BiasNumericRange_1.biasNumericRange)(this.min, this.max, BiasNumericRange_1.integerLogLike);
if (ranges.length === 1) {
return ranges[0];
}
const id = mrng.nextInt(-2 * (ranges.length - 1), ranges.length - 2);
return id < 0 ? ranges[0] : ranges[id + 1];
}
isLastChanceTry(current, context) {
if (current > 0)
return current === context + 1 && current > this.min;
if (current < 0)
return current === context - 1 && current < this.max;
return false;
}
static isValidContext(current, context) {
if (context === undefined) {
return false;
}
if (typeof context !== 'number') {
throw new Error(`Invalid context type passed to IntegerArbitrary (#1)`);
}
if (context !== 0 && safeMathSign(current) !== safeMathSign(context)) {
throw new Error(`Invalid context value passed to IntegerArbitrary (#2)`);
}
return true;
}
}
exports.IntegerArbitrary = IntegerArbitrary;

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LazyArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
class LazyArbitrary extends Arbitrary_1.Arbitrary {
constructor(name) {
super();
this.name = name;
this.underlying = null;
}
generate(mrng, biasFactor) {
if (!this.underlying) {
throw new Error(`Lazy arbitrary ${JSON.stringify(this.name)} not correctly initialized`);
}
return this.underlying.generate(mrng, biasFactor);
}
canShrinkWithoutContext(value) {
if (!this.underlying) {
throw new Error(`Lazy arbitrary ${JSON.stringify(this.name)} not correctly initialized`);
}
return this.underlying.canShrinkWithoutContext(value);
}
shrink(value, context) {
if (!this.underlying) {
throw new Error(`Lazy arbitrary ${JSON.stringify(this.name)} not correctly initialized`);
}
return this.underlying.shrink(value, context);
}
}
exports.LazyArbitrary = LazyArbitrary;

View File

@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LimitedShrinkArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const Stream_1 = require("../../stream/Stream");
const ZipIterableIterators_1 = require("./helpers/ZipIterableIterators");
function* iotaFrom(startValue) {
let value = startValue;
while (true) {
yield value;
++value;
}
}
class LimitedShrinkArbitrary extends Arbitrary_1.Arbitrary {
constructor(arb, maxShrinks) {
super();
this.arb = arb;
this.maxShrinks = maxShrinks;
}
generate(mrng, biasFactor) {
const value = this.arb.generate(mrng, biasFactor);
return this.valueMapper(value, 0);
}
canShrinkWithoutContext(value) {
return this.arb.canShrinkWithoutContext(value);
}
shrink(value, context) {
if (this.isSafeContext(context)) {
return this.safeShrink(value, context.originalContext, context.length);
}
return this.safeShrink(value, undefined, 0);
}
safeShrink(value, originalContext, currentLength) {
const remaining = this.maxShrinks - currentLength;
if (remaining <= 0) {
return Stream_1.Stream.nil();
}
return new Stream_1.Stream((0, ZipIterableIterators_1.zipIterableIterators)(this.arb.shrink(value, originalContext), iotaFrom(currentLength + 1)))
.take(remaining)
.map((valueAndLength) => this.valueMapper(valueAndLength[0], valueAndLength[1]));
}
valueMapper(v, newLength) {
const context = { originalContext: v.context, length: newLength };
return new Value_1.Value(v.value, context);
}
isSafeContext(context) {
return (context != null &&
typeof context === 'object' &&
'originalContext' in context &&
'length' in context);
}
}
exports.LimitedShrinkArbitrary = LimitedShrinkArbitrary;

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MixedCaseArbitrary = void 0;
const bigUintN_1 = require("../bigUintN");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const LazyIterableIterator_1 = require("../../stream/LazyIterableIterator");
const ToggleFlags_1 = require("./helpers/ToggleFlags");
const globals_1 = require("../../utils/globals");
const globals_2 = require("../../utils/globals");
class MixedCaseArbitrary extends Arbitrary_1.Arbitrary {
constructor(stringArb, toggleCase, untoggleAll) {
super();
this.stringArb = stringArb;
this.toggleCase = toggleCase;
this.untoggleAll = untoggleAll;
}
buildContextFor(rawStringValue, flagsValue) {
return {
rawString: rawStringValue.value,
rawStringContext: rawStringValue.context,
flags: flagsValue.value,
flagsContext: flagsValue.context,
};
}
generate(mrng, biasFactor) {
const rawStringValue = this.stringArb.generate(mrng, biasFactor);
const chars = [...rawStringValue.value];
const togglePositions = (0, ToggleFlags_1.computeTogglePositions)(chars, this.toggleCase);
const flagsArb = (0, bigUintN_1.bigUintN)(togglePositions.length);
const flagsValue = flagsArb.generate(mrng, undefined);
(0, ToggleFlags_1.applyFlagsOnChars)(chars, flagsValue.value, togglePositions, this.toggleCase);
return new Value_1.Value((0, globals_1.safeJoin)(chars, ''), this.buildContextFor(rawStringValue, flagsValue));
}
canShrinkWithoutContext(value) {
if (typeof value !== 'string') {
return false;
}
return this.untoggleAll !== undefined
? this.stringArb.canShrinkWithoutContext(this.untoggleAll(value))
:
this.stringArb.canShrinkWithoutContext(value);
}
shrink(value, context) {
let contextSafe;
if (context !== undefined) {
contextSafe = context;
}
else {
if (this.untoggleAll !== undefined) {
const untoggledValue = this.untoggleAll(value);
const valueChars = [...value];
const untoggledValueChars = [...untoggledValue];
const togglePositions = (0, ToggleFlags_1.computeTogglePositions)(untoggledValueChars, this.toggleCase);
contextSafe = {
rawString: untoggledValue,
rawStringContext: undefined,
flags: (0, ToggleFlags_1.computeFlagsFromChars)(untoggledValueChars, valueChars, togglePositions),
flagsContext: undefined,
};
}
else {
contextSafe = {
rawString: value,
rawStringContext: undefined,
flags: (0, globals_2.BigInt)(0),
flagsContext: undefined,
};
}
}
const rawString = contextSafe.rawString;
const flags = contextSafe.flags;
return this.stringArb
.shrink(rawString, contextSafe.rawStringContext)
.map((nRawStringValue) => {
const nChars = [...nRawStringValue.value];
const nTogglePositions = (0, ToggleFlags_1.computeTogglePositions)(nChars, this.toggleCase);
const nFlags = (0, ToggleFlags_1.computeNextFlags)(flags, nTogglePositions.length);
(0, ToggleFlags_1.applyFlagsOnChars)(nChars, nFlags, nTogglePositions, this.toggleCase);
return new Value_1.Value((0, globals_1.safeJoin)(nChars, ''), this.buildContextFor(nRawStringValue, new Value_1.Value(nFlags, undefined)));
})
.join((0, LazyIterableIterator_1.makeLazy)(() => {
const chars = [...rawString];
const togglePositions = (0, ToggleFlags_1.computeTogglePositions)(chars, this.toggleCase);
return (0, bigUintN_1.bigUintN)(togglePositions.length)
.shrink(flags, contextSafe.flagsContext)
.map((nFlagsValue) => {
const nChars = (0, globals_1.safeSlice)(chars);
(0, ToggleFlags_1.applyFlagsOnChars)(nChars, nFlagsValue.value, togglePositions, this.toggleCase);
return new Value_1.Value((0, globals_1.safeJoin)(nChars, ''), this.buildContextFor(new Value_1.Value(rawString, contextSafe.rawStringContext), nFlagsValue));
});
}));
}
}
exports.MixedCaseArbitrary = MixedCaseArbitrary;

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchedulerArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const Stream_1 = require("../../stream/Stream");
const SchedulerImplem_1 = require("./implementations/SchedulerImplem");
function buildNextTaskIndex(mrng) {
const clonedMrng = mrng.clone();
return {
clone: () => buildNextTaskIndex(clonedMrng),
nextTaskIndex: (scheduledTasks) => {
return mrng.nextInt(0, scheduledTasks.length - 1);
},
};
}
class SchedulerArbitrary extends Arbitrary_1.Arbitrary {
constructor(act) {
super();
this.act = act;
}
generate(mrng, _biasFactor) {
return new Value_1.Value(new SchedulerImplem_1.SchedulerImplem(this.act, buildNextTaskIndex(mrng.clone())), undefined);
}
canShrinkWithoutContext(value) {
return false;
}
shrink(_value, _context) {
return Stream_1.Stream.nil();
}
}
exports.SchedulerArbitrary = SchedulerArbitrary;

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StreamArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const symbols_1 = require("../../check/symbols");
const Stream_1 = require("../../stream/Stream");
const globals_1 = require("../../utils/globals");
const stringify_1 = require("../../utils/stringify");
const safeObjectDefineProperties = Object.defineProperties;
function prettyPrint(seenValuesStrings) {
return `Stream(${(0, globals_1.safeJoin)(seenValuesStrings, ',')}…)`;
}
class StreamArbitrary extends Arbitrary_1.Arbitrary {
constructor(arb) {
super();
this.arb = arb;
}
generate(mrng, biasFactor) {
const appliedBiasFactor = biasFactor !== undefined && mrng.nextInt(1, biasFactor) === 1 ? biasFactor : undefined;
const enrichedProducer = () => {
const seenValues = [];
const g = function* (arb, clonedMrng) {
while (true) {
const value = arb.generate(clonedMrng, appliedBiasFactor).value;
(0, globals_1.safePush)(seenValues, value);
yield value;
}
};
const s = new Stream_1.Stream(g(this.arb, mrng.clone()));
return safeObjectDefineProperties(s, {
toString: { value: () => prettyPrint(seenValues.map(stringify_1.stringify)) },
[stringify_1.toStringMethod]: { value: () => prettyPrint(seenValues.map(stringify_1.stringify)) },
[stringify_1.asyncToStringMethod]: { value: async () => prettyPrint(await Promise.all(seenValues.map(stringify_1.asyncStringify))) },
[symbols_1.cloneMethod]: { value: enrichedProducer, enumerable: true },
});
};
return new Value_1.Value(enrichedProducer(), undefined);
}
canShrinkWithoutContext(value) {
return false;
}
shrink(_value, _context) {
return Stream_1.Stream.nil();
}
}
exports.StreamArbitrary = StreamArbitrary;

View File

@@ -0,0 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringUnit = stringUnit;
const globals_1 = require("../../utils/globals");
const mapToConstant_1 = require("../mapToConstant");
const GraphemeRanges_1 = require("./data/GraphemeRanges");
const GraphemeRangesHelpers_1 = require("./helpers/GraphemeRangesHelpers");
const registeredStringUnitInstancesMap = Object.create(null);
function getAlphabetRanges(alphabet) {
switch (alphabet) {
case 'full':
return GraphemeRanges_1.fullAlphabetRanges;
case 'ascii':
return GraphemeRanges_1.asciiAlphabetRanges;
}
}
function getOrCreateStringUnitInstance(type, alphabet) {
const key = `${type}:${alphabet}`;
const registered = registeredStringUnitInstancesMap[key];
if (registered !== undefined) {
return registered;
}
const alphabetRanges = getAlphabetRanges(alphabet);
const ranges = type === 'binary' ? alphabetRanges : (0, GraphemeRangesHelpers_1.intersectGraphemeRanges)(alphabetRanges, GraphemeRanges_1.autonomousGraphemeRanges);
const entries = [];
for (const range of ranges) {
(0, globals_1.safePush)(entries, (0, GraphemeRangesHelpers_1.convertGraphemeRangeToMapToConstantEntry)(range));
}
if (type === 'grapheme') {
const decomposedRanges = (0, GraphemeRangesHelpers_1.intersectGraphemeRanges)(alphabetRanges, GraphemeRanges_1.autonomousDecomposableGraphemeRanges);
for (const range of decomposedRanges) {
const rawEntry = (0, GraphemeRangesHelpers_1.convertGraphemeRangeToMapToConstantEntry)(range);
(0, globals_1.safePush)(entries, {
num: rawEntry.num,
build: (idInGroup) => (0, globals_1.safeNormalize)(rawEntry.build(idInGroup), 'NFD'),
});
}
}
const stringUnitInstance = (0, mapToConstant_1.mapToConstant)(...entries);
registeredStringUnitInstancesMap[key] = stringUnitInstance;
return stringUnitInstance;
}
function stringUnit(type, alphabet) {
return getOrCreateStringUnitInstance(type, alphabet);
}

View File

@@ -0,0 +1,74 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubarrayArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const LazyIterableIterator_1 = require("../../stream/LazyIterableIterator");
const Stream_1 = require("../../stream/Stream");
const globals_1 = require("../../utils/globals");
const IsSubarrayOf_1 = require("./helpers/IsSubarrayOf");
const IntegerArbitrary_1 = require("./IntegerArbitrary");
const safeMathFloor = Math.floor;
const safeMathLog = Math.log;
const safeArrayIsArray = Array.isArray;
class SubarrayArbitrary extends Arbitrary_1.Arbitrary {
constructor(originalArray, isOrdered, minLength, maxLength) {
super();
this.originalArray = originalArray;
this.isOrdered = isOrdered;
this.minLength = minLength;
this.maxLength = maxLength;
if (minLength < 0 || minLength > originalArray.length)
throw new Error('fc.*{s|S}ubarrayOf expects the minimal length to be between 0 and the size of the original array');
if (maxLength < 0 || maxLength > originalArray.length)
throw new Error('fc.*{s|S}ubarrayOf expects the maximal length to be between 0 and the size of the original array');
if (minLength > maxLength)
throw new Error('fc.*{s|S}ubarrayOf expects the minimal length to be inferior or equal to the maximal length');
this.lengthArb = new IntegerArbitrary_1.IntegerArbitrary(minLength, maxLength);
this.biasedLengthArb =
minLength !== maxLength
? new IntegerArbitrary_1.IntegerArbitrary(minLength, minLength + safeMathFloor(safeMathLog(maxLength - minLength) / safeMathLog(2)))
: this.lengthArb;
}
generate(mrng, biasFactor) {
const lengthArb = biasFactor !== undefined && mrng.nextInt(1, biasFactor) === 1 ? this.biasedLengthArb : this.lengthArb;
const size = lengthArb.generate(mrng, undefined);
const sizeValue = size.value;
const remainingElements = (0, globals_1.safeMap)(this.originalArray, (_v, idx) => idx);
const ids = [];
for (let index = 0; index !== sizeValue; ++index) {
const selectedIdIndex = mrng.nextInt(0, remainingElements.length - 1);
(0, globals_1.safePush)(ids, remainingElements[selectedIdIndex]);
(0, globals_1.safeSplice)(remainingElements, selectedIdIndex, 1);
}
if (this.isOrdered) {
(0, globals_1.safeSort)(ids, (a, b) => a - b);
}
return new Value_1.Value((0, globals_1.safeMap)(ids, (i) => this.originalArray[i]), size.context);
}
canShrinkWithoutContext(value) {
if (!safeArrayIsArray(value)) {
return false;
}
if (!this.lengthArb.canShrinkWithoutContext(value.length)) {
return false;
}
return (0, IsSubarrayOf_1.isSubarrayOf)(this.originalArray, value);
}
shrink(value, context) {
if (value.length === 0) {
return Stream_1.Stream.nil();
}
return this.lengthArb
.shrink(value.length, context)
.map((newSize) => {
return new Value_1.Value((0, globals_1.safeSlice)(value, value.length - newSize.value), newSize.context);
})
.join(value.length > this.minLength
? (0, LazyIterableIterator_1.makeLazy)(() => this.shrink((0, globals_1.safeSlice)(value, 1), undefined)
.filter((newValue) => this.minLength <= newValue.value.length + 1)
.map((newValue) => new Value_1.Value([value[0], ...newValue.value], undefined)))
: Stream_1.Stream.nil());
}
}
exports.SubarrayArbitrary = SubarrayArbitrary;

View File

@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TupleArbitrary = void 0;
exports.tupleShrink = tupleShrink;
const Stream_1 = require("../../stream/Stream");
const symbols_1 = require("../../check/symbols");
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
const globals_1 = require("../../utils/globals");
const LazyIterableIterator_1 = require("../../stream/LazyIterableIterator");
const safeArrayIsArray = Array.isArray;
const safeObjectDefineProperty = Object.defineProperty;
function tupleMakeItCloneable(vs, values) {
return safeObjectDefineProperty(vs, symbols_1.cloneMethod, {
value: () => {
const cloned = [];
for (let idx = 0; idx !== values.length; ++idx) {
(0, globals_1.safePush)(cloned, values[idx].value);
}
tupleMakeItCloneable(cloned, values);
return cloned;
},
});
}
function tupleWrapper(values) {
let cloneable = false;
const vs = [];
const ctxs = [];
for (let idx = 0; idx !== values.length; ++idx) {
const v = values[idx];
cloneable = cloneable || v.hasToBeCloned;
(0, globals_1.safePush)(vs, v.value);
(0, globals_1.safePush)(ctxs, v.context);
}
if (cloneable) {
tupleMakeItCloneable(vs, values);
}
return new Value_1.Value(vs, ctxs);
}
function tupleShrink(arbs, value, context) {
const shrinks = [];
const safeContext = safeArrayIsArray(context) ? context : [];
for (let idx = 0; idx !== arbs.length; ++idx) {
(0, globals_1.safePush)(shrinks, (0, LazyIterableIterator_1.makeLazy)(() => arbs[idx]
.shrink(value[idx], safeContext[idx])
.map((v) => {
const nextValues = (0, globals_1.safeMap)(value, (v, idx) => new Value_1.Value((0, symbols_1.cloneIfNeeded)(v), safeContext[idx]));
return [...(0, globals_1.safeSlice)(nextValues, 0, idx), v, ...(0, globals_1.safeSlice)(nextValues, idx + 1)];
})
.map(tupleWrapper)));
}
return Stream_1.Stream.nil().join(...shrinks);
}
class TupleArbitrary extends Arbitrary_1.Arbitrary {
constructor(arbs) {
super();
this.arbs = arbs;
for (let idx = 0; idx !== arbs.length; ++idx) {
const arb = arbs[idx];
if (arb == null || arb.generate == null)
throw new Error(`Invalid parameter encountered at index ${idx}: expecting an Arbitrary`);
}
}
generate(mrng, biasFactor) {
const mapped = [];
for (let idx = 0; idx !== this.arbs.length; ++idx) {
(0, globals_1.safePush)(mapped, this.arbs[idx].generate(mrng, biasFactor));
}
return tupleWrapper(mapped);
}
canShrinkWithoutContext(value) {
if (!safeArrayIsArray(value) || value.length !== this.arbs.length) {
return false;
}
for (let index = 0; index !== this.arbs.length; ++index) {
if (!this.arbs[index].canShrinkWithoutContext(value[index])) {
return false;
}
}
return true;
}
shrink(value, context) {
return tupleShrink(this.arbs, value, context);
}
}
exports.TupleArbitrary = TupleArbitrary;

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithShrinkFromOtherArbitrary = void 0;
const Arbitrary_1 = require("../../check/arbitrary/definition/Arbitrary");
const Value_1 = require("../../check/arbitrary/definition/Value");
function isSafeContext(context) {
return context !== undefined;
}
function toGeneratorValue(value) {
if (value.hasToBeCloned) {
return new Value_1.Value(value.value_, { generatorContext: value.context }, () => value.value);
}
return new Value_1.Value(value.value_, { generatorContext: value.context });
}
function toShrinkerValue(value) {
if (value.hasToBeCloned) {
return new Value_1.Value(value.value_, { shrinkerContext: value.context }, () => value.value);
}
return new Value_1.Value(value.value_, { shrinkerContext: value.context });
}
class WithShrinkFromOtherArbitrary extends Arbitrary_1.Arbitrary {
constructor(generatorArbitrary, shrinkerArbitrary) {
super();
this.generatorArbitrary = generatorArbitrary;
this.shrinkerArbitrary = shrinkerArbitrary;
}
generate(mrng, biasFactor) {
return toGeneratorValue(this.generatorArbitrary.generate(mrng, biasFactor));
}
canShrinkWithoutContext(value) {
return this.shrinkerArbitrary.canShrinkWithoutContext(value);
}
shrink(value, context) {
if (!isSafeContext(context)) {
return this.shrinkerArbitrary.shrink(value, undefined).map(toShrinkerValue);
}
if ('generatorContext' in context) {
return this.generatorArbitrary.shrink(value, context.generatorContext).map(toGeneratorValue);
}
return this.shrinkerArbitrary.shrink(value, context.shrinkerContext).map(toShrinkerValue);
}
}
exports.WithShrinkFromOtherArbitrary = WithShrinkFromOtherArbitrary;

View File

@@ -0,0 +1,69 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.anyArbitraryBuilder = anyArbitraryBuilder;
const stringify_1 = require("../../../utils/stringify");
const array_1 = require("../../array");
const oneof_1 = require("../../oneof");
const tuple_1 = require("../../tuple");
const bigInt_1 = require("../../bigInt");
const date_1 = require("../../date");
const float32Array_1 = require("../../float32Array");
const float64Array_1 = require("../../float64Array");
const int16Array_1 = require("../../int16Array");
const int32Array_1 = require("../../int32Array");
const int8Array_1 = require("../../int8Array");
const uint16Array_1 = require("../../uint16Array");
const uint32Array_1 = require("../../uint32Array");
const uint8Array_1 = require("../../uint8Array");
const uint8ClampedArray_1 = require("../../uint8ClampedArray");
const sparseArray_1 = require("../../sparseArray");
const ArrayToMap_1 = require("../mappers/ArrayToMap");
const ArrayToSet_1 = require("../mappers/ArrayToSet");
const letrec_1 = require("../../letrec");
const uniqueArray_1 = require("../../uniqueArray");
const DepthContext_1 = require("../helpers/DepthContext");
const dictionary_1 = require("../../dictionary");
function mapOf(ka, va, maxKeys, size, depthIdentifier) {
return (0, uniqueArray_1.uniqueArray)((0, tuple_1.tuple)(ka, va), {
maxLength: maxKeys,
size,
comparator: 'SameValueZero',
selector: (t) => t[0],
depthIdentifier,
}).map(ArrayToMap_1.arrayToMapMapper, ArrayToMap_1.arrayToMapUnmapper);
}
function dictOf(ka, va, maxKeys, size, depthIdentifier, withNullPrototype) {
return (0, dictionary_1.dictionary)(ka, va, {
maxKeys,
noNullPrototype: !withNullPrototype,
size,
depthIdentifier,
});
}
function setOf(va, maxKeys, size, depthIdentifier) {
return (0, uniqueArray_1.uniqueArray)(va, { maxLength: maxKeys, size, comparator: 'SameValueZero', depthIdentifier }).map(ArrayToSet_1.arrayToSetMapper, ArrayToSet_1.arrayToSetUnmapper);
}
function typedArray(constraints) {
return (0, oneof_1.oneof)((0, int8Array_1.int8Array)(constraints), (0, uint8Array_1.uint8Array)(constraints), (0, uint8ClampedArray_1.uint8ClampedArray)(constraints), (0, int16Array_1.int16Array)(constraints), (0, uint16Array_1.uint16Array)(constraints), (0, int32Array_1.int32Array)(constraints), (0, uint32Array_1.uint32Array)(constraints), (0, float32Array_1.float32Array)(constraints), (0, float64Array_1.float64Array)(constraints));
}
function anyArbitraryBuilder(constraints) {
const arbitrariesForBase = constraints.values;
const depthSize = constraints.depthSize;
const depthIdentifier = (0, DepthContext_1.createDepthIdentifier)();
const maxDepth = constraints.maxDepth;
const maxKeys = constraints.maxKeys;
const size = constraints.size;
const baseArb = (0, oneof_1.oneof)(...arbitrariesForBase, ...(constraints.withBigInt ? [(0, bigInt_1.bigInt)()] : []), ...(constraints.withDate ? [(0, date_1.date)()] : []));
return (0, letrec_1.letrec)((tie) => ({
anything: (0, oneof_1.oneof)({ maxDepth, depthSize, depthIdentifier }, baseArb, tie('array'), tie('object'), ...(constraints.withMap ? [tie('map')] : []), ...(constraints.withSet ? [tie('set')] : []), ...(constraints.withObjectString ? [tie('anything').map((o) => (0, stringify_1.stringify)(o))] : []), ...(constraints.withTypedArray ? [typedArray({ maxLength: maxKeys, size })] : []), ...(constraints.withSparseArray
? [(0, sparseArray_1.sparseArray)(tie('anything'), { maxNumElements: maxKeys, size, depthIdentifier })]
: [])),
keys: constraints.withObjectString
? (0, oneof_1.oneof)({ arbitrary: constraints.key, weight: 10 }, { arbitrary: tie('anything').map((o) => (0, stringify_1.stringify)(o)), weight: 1 })
: constraints.key,
array: (0, array_1.array)(tie('anything'), { maxLength: maxKeys, size, depthIdentifier }),
set: setOf(tie('anything'), maxKeys, size, depthIdentifier),
map: (0, oneof_1.oneof)(mapOf(tie('keys'), tie('anything'), maxKeys, size, depthIdentifier), mapOf(tie('anything'), tie('anything'), maxKeys, size, depthIdentifier)),
object: dictOf(tie('keys'), tie('anything'), maxKeys, size, depthIdentifier, constraints.withNullPrototype),
})).anything;
}

View File

@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.boxedArbitraryBuilder = boxedArbitraryBuilder;
const UnboxedToBoxed_1 = require("../mappers/UnboxedToBoxed");
function boxedArbitraryBuilder(arb) {
return arb.map(UnboxedToBoxed_1.unboxedToBoxedMapper, UnboxedToBoxed_1.unboxedToBoxedUnmapper);
}

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildCharacterArbitrary = buildCharacterArbitrary;
const integer_1 = require("../../integer");
const IndexToCharString_1 = require("../mappers/IndexToCharString");
function buildCharacterArbitrary(min, max, mapToCode, unmapFromCode) {
return (0, integer_1.integer)({ min, max }).map((n) => (0, IndexToCharString_1.indexToCharStringMapper)(mapToCode(n)), (c) => unmapFromCode((0, IndexToCharString_1.indexToCharStringUnmapper)(c)));
}

View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOrCreateLowerAlphaArbitrary = getOrCreateLowerAlphaArbitrary;
exports.getOrCreateLowerAlphaNumericArbitrary = getOrCreateLowerAlphaNumericArbitrary;
exports.getOrCreateAlphaNumericPercentArbitrary = getOrCreateAlphaNumericPercentArbitrary;
const fullUnicode_1 = require("../../fullUnicode");
const oneof_1 = require("../../oneof");
const mapToConstant_1 = require("../../mapToConstant");
const globals_1 = require("../../../utils/globals");
const SMap = Map;
const safeStringFromCharCode = String.fromCharCode;
const lowerCaseMapper = { num: 26, build: (v) => safeStringFromCharCode(v + 0x61) };
const upperCaseMapper = { num: 26, build: (v) => safeStringFromCharCode(v + 0x41) };
const numericMapper = { num: 10, build: (v) => safeStringFromCharCode(v + 0x30) };
function percentCharArbMapper(c) {
const encoded = (0, globals_1.encodeURIComponent)(c);
return c !== encoded ? encoded : `%${(0, globals_1.safeNumberToString)((0, globals_1.safeCharCodeAt)(c, 0), 16)}`;
}
function percentCharArbUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported');
}
const decoded = decodeURIComponent(value);
return decoded;
}
const percentCharArb = (0, fullUnicode_1.fullUnicode)().map(percentCharArbMapper, percentCharArbUnmapper);
let lowerAlphaArbitrary = undefined;
function getOrCreateLowerAlphaArbitrary() {
if (lowerAlphaArbitrary === undefined) {
lowerAlphaArbitrary = (0, mapToConstant_1.mapToConstant)(lowerCaseMapper);
}
return lowerAlphaArbitrary;
}
let lowerAlphaNumericArbitraries = undefined;
function getOrCreateLowerAlphaNumericArbitrary(others) {
if (lowerAlphaNumericArbitraries === undefined) {
lowerAlphaNumericArbitraries = new SMap();
}
let match = (0, globals_1.safeMapGet)(lowerAlphaNumericArbitraries, others);
if (match === undefined) {
match = (0, mapToConstant_1.mapToConstant)(lowerCaseMapper, numericMapper, {
num: others.length,
build: (v) => others[v],
});
(0, globals_1.safeMapSet)(lowerAlphaNumericArbitraries, others, match);
}
return match;
}
function buildAlphaNumericArbitrary(others) {
return (0, mapToConstant_1.mapToConstant)(lowerCaseMapper, upperCaseMapper, numericMapper, {
num: others.length,
build: (v) => others[v],
});
}
let alphaNumericPercentArbitraries = undefined;
function getOrCreateAlphaNumericPercentArbitrary(others) {
if (alphaNumericPercentArbitraries === undefined) {
alphaNumericPercentArbitraries = new SMap();
}
let match = (0, globals_1.safeMapGet)(alphaNumericPercentArbitraries, others);
if (match === undefined) {
match = (0, oneof_1.oneof)({ weight: 10, arbitrary: buildAlphaNumericArbitrary(others) }, { weight: 1, arbitrary: percentCharArb });
(0, globals_1.safeMapSet)(alphaNumericPercentArbitraries, others, match);
}
return match;
}

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildCompareFunctionArbitrary = buildCompareFunctionArbitrary;
const TextEscaper_1 = require("../helpers/TextEscaper");
const symbols_1 = require("../../../check/symbols");
const hash_1 = require("../../../utils/hash");
const stringify_1 = require("../../../utils/stringify");
const integer_1 = require("../../integer");
const noShrink_1 = require("../../noShrink");
const tuple_1 = require("../../tuple");
const globals_1 = require("../../../utils/globals");
const safeObjectAssign = Object.assign;
const safeObjectKeys = Object.keys;
function buildCompareFunctionArbitrary(cmp) {
return (0, tuple_1.tuple)((0, noShrink_1.noShrink)((0, integer_1.integer)()), (0, noShrink_1.noShrink)((0, integer_1.integer)({ min: 1, max: 0xffffffff }))).map(([seed, hashEnvSize]) => {
const producer = () => {
const recorded = {};
const f = (a, b) => {
const reprA = (0, stringify_1.stringify)(a);
const reprB = (0, stringify_1.stringify)(b);
const hA = (0, hash_1.hash)(`${seed}${reprA}`) % hashEnvSize;
const hB = (0, hash_1.hash)(`${seed}${reprB}`) % hashEnvSize;
const val = cmp(hA, hB);
recorded[`[${reprA},${reprB}]`] = val;
return val;
};
return safeObjectAssign(f, {
toString: () => {
const seenValues = safeObjectKeys(recorded)
.sort()
.map((k) => `${k} => ${(0, stringify_1.stringify)(recorded[k])}`)
.map((line) => `/* ${(0, TextEscaper_1.escapeForMultilineComments)(line)} */`);
return `function(a, b) {
// With hash and stringify coming from fast-check${seenValues.length !== 0 ? `\n ${(0, globals_1.safeJoin)(seenValues, '\n ')}` : ''}
const cmp = ${cmp};
const hA = hash('${seed}' + stringify(a)) % ${hashEnvSize};
const hB = hash('${seed}' + stringify(b)) % ${hashEnvSize};
return cmp(hA, hB);
}`;
},
[symbols_1.cloneMethod]: producer,
});
};
return producer();
});
}

View File

@@ -0,0 +1,41 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildGeneratorValue = buildGeneratorValue;
const Value_1 = require("../../../check/arbitrary/definition/Value");
const symbols_1 = require("../../../check/symbols");
const globals_1 = require("../../../utils/globals");
const stringify_1 = require("../../../utils/stringify");
const safeObjectAssign = Object.assign;
function buildGeneratorValue(mrng, biasFactor, computePreBuiltValues, arbitraryCache) {
const preBuiltValues = computePreBuiltValues();
let localMrng = mrng.clone();
const context = { mrng: mrng.clone(), biasFactor, history: [] };
const valueFunction = (arb) => {
const preBuiltValue = preBuiltValues[context.history.length];
if (preBuiltValue !== undefined && preBuiltValue.arb === arb) {
const value = preBuiltValue.value;
(0, globals_1.safePush)(context.history, { arb, value, context: preBuiltValue.context, mrng: preBuiltValue.mrng });
localMrng = preBuiltValue.mrng.clone();
return value;
}
const g = arb.generate(localMrng, biasFactor);
(0, globals_1.safePush)(context.history, { arb, value: g.value_, context: g.context, mrng: localMrng.clone() });
return g.value;
};
const memoedValueFunction = (arb, ...args) => {
return valueFunction(arbitraryCache(arb, args));
};
const valueMethods = {
values() {
return (0, globals_1.safeMap)(context.history, (c) => c.value);
},
[symbols_1.cloneMethod]() {
return buildGeneratorValue(mrng, biasFactor, computePreBuiltValues, arbitraryCache).value;
},
[stringify_1.toStringMethod]() {
return (0, stringify_1.stringify)((0, globals_1.safeMap)(context.history, (c) => c.value));
},
};
const value = safeObjectAssign(memoedValueFunction, valueMethods);
return new Value_1.Value(value, context);
}

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPaddedNumberArbitrary = buildPaddedNumberArbitrary;
const integer_1 = require("../../integer");
const NumberToPaddedEight_1 = require("../mappers/NumberToPaddedEight");
function buildPaddedNumberArbitrary(min, max) {
return (0, integer_1.integer)({ min, max }).map(NumberToPaddedEight_1.numberToPaddedEightMapper, NumberToPaddedEight_1.numberToPaddedEightUnmapper);
}

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildPartialRecordArbitrary = buildPartialRecordArbitrary;
const globals_1 = require("../../../utils/globals");
const boolean_1 = require("../../boolean");
const constant_1 = require("../../constant");
const option_1 = require("../../option");
const tuple_1 = require("../../tuple");
const EnumerableKeysExtractor_1 = require("../helpers/EnumerableKeysExtractor");
const ValuesAndSeparateKeysToObject_1 = require("../mappers/ValuesAndSeparateKeysToObject");
const noKeyValue = Symbol('no-key');
function buildPartialRecordArbitrary(recordModel, requiredKeys, noNullPrototype) {
const keys = (0, EnumerableKeysExtractor_1.extractEnumerableKeys)(recordModel);
const arbs = [];
for (let index = 0; index !== keys.length; ++index) {
const k = keys[index];
const requiredArbitrary = recordModel[k];
if (requiredKeys === undefined || (0, globals_1.safeIndexOf)(requiredKeys, k) !== -1) {
(0, globals_1.safePush)(arbs, requiredArbitrary);
}
else {
(0, globals_1.safePush)(arbs, (0, option_1.option)(requiredArbitrary, { nil: noKeyValue }));
}
}
return (0, tuple_1.tuple)((0, tuple_1.tuple)(...arbs), noNullPrototype ? (0, constant_1.constant)(false) : (0, boolean_1.boolean)()).map((0, ValuesAndSeparateKeysToObject_1.buildValuesAndSeparateKeysToObjectMapper)(keys, noKeyValue), (0, ValuesAndSeparateKeysToObject_1.buildValuesAndSeparateKeysToObjectUnmapper)(keys, noKeyValue));
}

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.restrictedIntegerArbitraryBuilder = restrictedIntegerArbitraryBuilder;
const integer_1 = require("../../integer");
const WithShrinkFromOtherArbitrary_1 = require("../WithShrinkFromOtherArbitrary");
function restrictedIntegerArbitraryBuilder(min, maxGenerated, max) {
const generatorArbitrary = (0, integer_1.integer)({ min, max: maxGenerated });
if (maxGenerated === max) {
return generatorArbitrary;
}
const shrinkerArbitrary = (0, integer_1.integer)({ min, max });
return new WithShrinkFromOtherArbitrary_1.WithShrinkFromOtherArbitrary(generatorArbitrary, shrinkerArbitrary);
}

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildStableArbitraryGeneratorCache = buildStableArbitraryGeneratorCache;
exports.naiveIsEqual = naiveIsEqual;
const globals_1 = require("../../../utils/globals");
const safeArrayIsArray = Array.isArray;
const safeObjectKeys = Object.keys;
const safeObjectIs = Object.is;
function buildStableArbitraryGeneratorCache(isEqual) {
const previousCallsPerBuilder = new globals_1.Map();
return function stableArbitraryGeneratorCache(builder, args) {
const entriesForBuilder = (0, globals_1.safeMapGet)(previousCallsPerBuilder, builder);
if (entriesForBuilder === undefined) {
const newValue = builder(...args);
(0, globals_1.safeMapSet)(previousCallsPerBuilder, builder, [{ args, value: newValue }]);
return newValue;
}
const safeEntriesForBuilder = entriesForBuilder;
for (const entry of safeEntriesForBuilder) {
if (isEqual(args, entry.args)) {
return entry.value;
}
}
const newValue = builder(...args);
(0, globals_1.safePush)(safeEntriesForBuilder, { args, value: newValue });
return newValue;
};
}
function naiveIsEqual(v1, v2) {
if (v1 !== null && typeof v1 === 'object' && v2 !== null && typeof v2 === 'object') {
if (safeArrayIsArray(v1)) {
if (!safeArrayIsArray(v2))
return false;
if (v1.length !== v2.length)
return false;
}
else if (safeArrayIsArray(v2)) {
return false;
}
if (safeObjectKeys(v1).length !== safeObjectKeys(v2).length) {
return false;
}
for (const index in v1) {
if (!(index in v2)) {
return false;
}
if (!naiveIsEqual(v1[index], v2[index])) {
return false;
}
}
return true;
}
else {
return safeObjectIs(v1, v2);
}
}

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildStringifiedNatArbitrary = buildStringifiedNatArbitrary;
const constantFrom_1 = require("../../constantFrom");
const nat_1 = require("../../nat");
const tuple_1 = require("../../tuple");
const NatToStringifiedNat_1 = require("../mappers/NatToStringifiedNat");
function buildStringifiedNatArbitrary(maxValue) {
return (0, tuple_1.tuple)((0, constantFrom_1.constantFrom)('dec', 'oct', 'hex'), (0, nat_1.nat)(maxValue)).map(NatToStringifiedNat_1.natToStringifiedNatMapper, NatToStringifiedNat_1.natToStringifiedNatUnmapper);
}

View File

@@ -0,0 +1,33 @@
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.typedIntArrayArbitraryArbitraryBuilder = typedIntArrayArbitraryArbitraryBuilder;
const array_1 = require("../../array");
function typedIntArrayArbitraryArbitraryBuilder(constraints, defaultMin, defaultMax, TypedArrayClass, arbitraryBuilder) {
const generatorName = TypedArrayClass.name;
const { min = defaultMin, max = defaultMax } = constraints, arrayConstraints = __rest(constraints, ["min", "max"]);
if (min > max) {
throw new Error(`Invalid range passed to ${generatorName}: min must be lower than or equal to max`);
}
if (min < defaultMin) {
throw new Error(`Invalid min value passed to ${generatorName}: min must be greater than or equal to ${defaultMin}`);
}
if (max > defaultMax) {
throw new Error(`Invalid max value passed to ${generatorName}: max must be lower than or equal to ${defaultMax}`);
}
return (0, array_1.array)(arbitraryBuilder({ min, max }), arrayConstraints).map((data) => TypedArrayClass.from(data), (value) => {
if (!(value instanceof TypedArrayClass))
throw new Error('Invalid type');
return [...value];
});
}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUriPathArbitrary = buildUriPathArbitrary;
const webSegment_1 = require("../../webSegment");
const array_1 = require("../../array");
const SegmentsToPath_1 = require("../mappers/SegmentsToPath");
const oneof_1 = require("../../oneof");
function sqrtSize(size) {
switch (size) {
case 'xsmall':
return ['xsmall', 'xsmall'];
case 'small':
return ['small', 'xsmall'];
case 'medium':
return ['small', 'small'];
case 'large':
return ['medium', 'small'];
case 'xlarge':
return ['medium', 'medium'];
}
}
function buildUriPathArbitraryInternal(segmentSize, numSegmentSize) {
return (0, array_1.array)((0, webSegment_1.webSegment)({ size: segmentSize }), { size: numSegmentSize }).map(SegmentsToPath_1.segmentsToPathMapper, SegmentsToPath_1.segmentsToPathUnmapper);
}
function buildUriPathArbitrary(resolvedSize) {
const [segmentSize, numSegmentSize] = sqrtSize(resolvedSize);
if (segmentSize === numSegmentSize) {
return buildUriPathArbitraryInternal(segmentSize, numSegmentSize);
}
return (0, oneof_1.oneof)(buildUriPathArbitraryInternal(segmentSize, numSegmentSize), buildUriPathArbitraryInternal(numSegmentSize, segmentSize));
}

View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildUriQueryOrFragmentArbitrary = buildUriQueryOrFragmentArbitrary;
const CharacterRangeArbitraryBuilder_1 = require("./CharacterRangeArbitraryBuilder");
const string_1 = require("../../string");
function buildUriQueryOrFragmentArbitrary(size) {
return (0, string_1.string)({ unit: (0, CharacterRangeArbitraryBuilder_1.getOrCreateAlphaNumericPercentArbitrary)("-._~!$&'()*+,;=:@/?"), size });
}

View File

@@ -0,0 +1,988 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.autonomousDecomposableGraphemeRanges = exports.autonomousGraphemeRanges = exports.fullAlphabetRanges = exports.asciiAlphabetRanges = void 0;
exports.asciiAlphabetRanges = [[0x00, 0x7f]];
exports.fullAlphabetRanges = [
[0x0000, 0xd7ff],
[0xe000, 0x10ffff],
];
exports.autonomousGraphemeRanges = [
[0x20, 0x7e],
[0xa0, 0xac],
[0xae, 0x2ff],
[0x370, 0x377],
[0x37a, 0x37f],
[0x384, 0x38a],
[0x38c],
[0x38e, 0x3a1],
[0x3a3, 0x482],
[0x48a, 0x52f],
[0x531, 0x556],
[0x559, 0x58a],
[0x58d, 0x58f],
[0x5be],
[0x5c0],
[0x5c3],
[0x5c6],
[0x5d0, 0x5ea],
[0x5ef, 0x5f4],
[0x606, 0x60f],
[0x61b],
[0x61d, 0x64a],
[0x660, 0x66f],
[0x671, 0x6d5],
[0x6de],
[0x6e5, 0x6e6],
[0x6e9],
[0x6ee, 0x70d],
[0x710],
[0x712, 0x72f],
[0x74d, 0x7a5],
[0x7b1],
[0x7c0, 0x7ea],
[0x7f4, 0x7fa],
[0x7fe, 0x815],
[0x81a],
[0x824],
[0x828],
[0x830, 0x83e],
[0x840, 0x858],
[0x85e],
[0x860, 0x86a],
[0x870, 0x88e],
[0x8a0, 0x8c9],
[0x904, 0x939],
[0x93d],
[0x950],
[0x958, 0x961],
[0x964, 0x980],
[0x985, 0x98c],
[0x98f, 0x990],
[0x993, 0x9a8],
[0x9aa, 0x9b0],
[0x9b2],
[0x9b6, 0x9b9],
[0x9bd],
[0x9ce],
[0x9dc, 0x9dd],
[0x9df, 0x9e1],
[0x9e6, 0x9fd],
[0xa05, 0xa0a],
[0xa0f, 0xa10],
[0xa13, 0xa28],
[0xa2a, 0xa30],
[0xa32, 0xa33],
[0xa35, 0xa36],
[0xa38, 0xa39],
[0xa59, 0xa5c],
[0xa5e],
[0xa66, 0xa6f],
[0xa72, 0xa74],
[0xa76],
[0xa85, 0xa8d],
[0xa8f, 0xa91],
[0xa93, 0xaa8],
[0xaaa, 0xab0],
[0xab2, 0xab3],
[0xab5, 0xab9],
[0xabd],
[0xad0],
[0xae0, 0xae1],
[0xae6, 0xaf1],
[0xaf9],
[0xb05, 0xb0c],
[0xb0f, 0xb10],
[0xb13, 0xb28],
[0xb2a, 0xb30],
[0xb32, 0xb33],
[0xb35, 0xb39],
[0xb3d],
[0xb5c, 0xb5d],
[0xb5f, 0xb61],
[0xb66, 0xb77],
[0xb83],
[0xb85, 0xb8a],
[0xb8e, 0xb90],
[0xb92, 0xb95],
[0xb99, 0xb9a],
[0xb9c],
[0xb9e, 0xb9f],
[0xba3, 0xba4],
[0xba8, 0xbaa],
[0xbae, 0xbb9],
[0xbd0],
[0xbe6, 0xbfa],
[0xc05, 0xc0c],
[0xc0e, 0xc10],
[0xc12, 0xc28],
[0xc2a, 0xc39],
[0xc3d],
[0xc58, 0xc5a],
[0xc5d],
[0xc60, 0xc61],
[0xc66, 0xc6f],
[0xc77, 0xc80],
[0xc84, 0xc8c],
[0xc8e, 0xc90],
[0xc92, 0xca8],
[0xcaa, 0xcb3],
[0xcb5, 0xcb9],
[0xcbd],
[0xcdd, 0xcde],
[0xce0, 0xce1],
[0xce6, 0xcef],
[0xcf1, 0xcf2],
[0xd04, 0xd0c],
[0xd0e, 0xd10],
[0xd12, 0xd3a],
[0xd3d],
[0xd4f],
[0xd54, 0xd56],
[0xd58, 0xd61],
[0xd66, 0xd7f],
[0xd85, 0xd96],
[0xd9a, 0xdb1],
[0xdb3, 0xdbb],
[0xdbd],
[0xdc0, 0xdc6],
[0xde6, 0xdef],
[0xdf4],
[0xe01, 0xe30],
[0xe32],
[0xe3f, 0xe46],
[0xe4f, 0xe5b],
[0xe81, 0xe82],
[0xe84],
[0xe86, 0xe8a],
[0xe8c, 0xea3],
[0xea5],
[0xea7, 0xeb0],
[0xeb2],
[0xebd],
[0xec0, 0xec4],
[0xec6],
[0xed0, 0xed9],
[0xedc, 0xedf],
[0xf00, 0xf17],
[0xf1a, 0xf34],
[0xf36],
[0xf38],
[0xf3a, 0xf3d],
[0xf40, 0xf47],
[0xf49, 0xf6c],
[0xf85],
[0xf88, 0xf8c],
[0xfbe, 0xfc5],
[0xfc7, 0xfcc],
[0xfce, 0xfda],
[0x1000, 0x102a],
[0x103f, 0x1055],
[0x105a, 0x105d],
[0x1061],
[0x1065, 0x1066],
[0x106e, 0x1070],
[0x1075, 0x1081],
[0x108e],
[0x1090, 0x1099],
[0x109e, 0x10c5],
[0x10c7],
[0x10cd],
[0x10d0, 0x10ff],
[0x1200, 0x1248],
[0x124a, 0x124d],
[0x1250, 0x1256],
[0x1258],
[0x125a, 0x125d],
[0x1260, 0x1288],
[0x128a, 0x128d],
[0x1290, 0x12b0],
[0x12b2, 0x12b5],
[0x12b8, 0x12be],
[0x12c0],
[0x12c2, 0x12c5],
[0x12c8, 0x12d6],
[0x12d8, 0x1310],
[0x1312, 0x1315],
[0x1318, 0x135a],
[0x1360, 0x137c],
[0x1380, 0x1399],
[0x13a0, 0x13f5],
[0x13f8, 0x13fd],
[0x1400, 0x169c],
[0x16a0, 0x16f8],
[0x1700, 0x1711],
[0x171f, 0x1731],
[0x1735, 0x1736],
[0x1740, 0x1751],
[0x1760, 0x176c],
[0x176e, 0x1770],
[0x1780, 0x17b3],
[0x17d4, 0x17dc],
[0x17e0, 0x17e9],
[0x17f0, 0x17f9],
[0x1800, 0x180a],
[0x1810, 0x1819],
[0x1820, 0x1878],
[0x1880, 0x1884],
[0x1887, 0x18a8],
[0x18aa],
[0x18b0, 0x18f5],
[0x1900, 0x191e],
[0x1940],
[0x1944, 0x196d],
[0x1970, 0x1974],
[0x1980, 0x19ab],
[0x19b0, 0x19c9],
[0x19d0, 0x19da],
[0x19de, 0x1a16],
[0x1a1e, 0x1a54],
[0x1a80, 0x1a89],
[0x1a90, 0x1a99],
[0x1aa0, 0x1aad],
[0x1b05, 0x1b33],
[0x1b45, 0x1b4c],
[0x1b50, 0x1b6a],
[0x1b74, 0x1b7e],
[0x1b83, 0x1ba0],
[0x1bae, 0x1be5],
[0x1bfc, 0x1c23],
[0x1c3b, 0x1c49],
[0x1c4d, 0x1c88],
[0x1c90, 0x1cba],
[0x1cbd, 0x1cc7],
[0x1cd3],
[0x1ce9, 0x1cec],
[0x1cee, 0x1cf3],
[0x1cf5, 0x1cf6],
[0x1cfa],
[0x1d00, 0x1dbf],
[0x1e00, 0x1f15],
[0x1f18, 0x1f1d],
[0x1f20, 0x1f45],
[0x1f48, 0x1f4d],
[0x1f50, 0x1f57],
[0x1f59],
[0x1f5b],
[0x1f5d],
[0x1f5f, 0x1f7d],
[0x1f80, 0x1fb4],
[0x1fb6, 0x1fc4],
[0x1fc6, 0x1fd3],
[0x1fd6, 0x1fdb],
[0x1fdd, 0x1fef],
[0x1ff2, 0x1ff4],
[0x1ff6, 0x1ffe],
[0x2000, 0x200a],
[0x2010, 0x2029],
[0x202f, 0x205f],
[0x2070, 0x2071],
[0x2074, 0x208e],
[0x2090, 0x209c],
[0x20a0, 0x20c0],
[0x2100, 0x218b],
[0x2190, 0x2426],
[0x2440, 0x244a],
[0x2460, 0x2b73],
[0x2b76, 0x2b95],
[0x2b97, 0x2cee],
[0x2cf2, 0x2cf3],
[0x2cf9, 0x2d25],
[0x2d27],
[0x2d2d],
[0x2d30, 0x2d67],
[0x2d6f, 0x2d70],
[0x2d80, 0x2d96],
[0x2da0, 0x2da6],
[0x2da8, 0x2dae],
[0x2db0, 0x2db6],
[0x2db8, 0x2dbe],
[0x2dc0, 0x2dc6],
[0x2dc8, 0x2dce],
[0x2dd0, 0x2dd6],
[0x2dd8, 0x2dde],
[0x2e00, 0x2e5d],
[0x2e80, 0x2e99],
[0x2e9b, 0x2ef3],
[0x2f00, 0x2fd5],
[0x2ff0, 0x3029],
[0x3030, 0x303f],
[0x3041, 0x3096],
[0x309b, 0x30ff],
[0x3105, 0x312f],
[0x3131, 0x318e],
[0x3190, 0x31e3],
[0x31ef, 0x321e],
[0x3220, 0x3400],
[0x4dbf, 0x4e00],
[0x9fff, 0xa48c],
[0xa490, 0xa4c6],
[0xa4d0, 0xa62b],
[0xa640, 0xa66e],
[0xa673],
[0xa67e, 0xa69d],
[0xa6a0, 0xa6ef],
[0xa6f2, 0xa6f7],
[0xa700, 0xa7ca],
[0xa7d0, 0xa7d1],
[0xa7d3],
[0xa7d5, 0xa7d9],
[0xa7f2, 0xa801],
[0xa803, 0xa805],
[0xa807, 0xa80a],
[0xa80c, 0xa822],
[0xa828, 0xa82b],
[0xa830, 0xa839],
[0xa840, 0xa877],
[0xa882, 0xa8b3],
[0xa8ce, 0xa8d9],
[0xa8f2, 0xa8fe],
[0xa900, 0xa925],
[0xa92e, 0xa946],
[0xa95f],
[0xa984, 0xa9b2],
[0xa9c1, 0xa9cd],
[0xa9cf, 0xa9d9],
[0xa9de, 0xa9e4],
[0xa9e6, 0xa9fe],
[0xaa00, 0xaa28],
[0xaa40, 0xaa42],
[0xaa44, 0xaa4b],
[0xaa50, 0xaa59],
[0xaa5c, 0xaa7a],
[0xaa7e, 0xaaaf],
[0xaab1],
[0xaab5, 0xaab6],
[0xaab9, 0xaabd],
[0xaac0],
[0xaac2],
[0xaadb, 0xaaea],
[0xaaf0, 0xaaf4],
[0xab01, 0xab06],
[0xab09, 0xab0e],
[0xab11, 0xab16],
[0xab20, 0xab26],
[0xab28, 0xab2e],
[0xab30, 0xab6b],
[0xab70, 0xabe2],
[0xabeb],
[0xabf0, 0xabf9],
[0xac00],
[0xd7a3],
[0xf900, 0xfa6d],
[0xfa70, 0xfad9],
[0xfb00, 0xfb06],
[0xfb13, 0xfb17],
[0xfb1d],
[0xfb1f, 0xfb36],
[0xfb38, 0xfb3c],
[0xfb3e],
[0xfb40, 0xfb41],
[0xfb43, 0xfb44],
[0xfb46, 0xfbc2],
[0xfbd3, 0xfd8f],
[0xfd92, 0xfdc7],
[0xfdcf],
[0xfdf0, 0xfdff],
[0xfe10, 0xfe19],
[0xfe30, 0xfe52],
[0xfe54, 0xfe66],
[0xfe68, 0xfe6b],
[0xfe70, 0xfe74],
[0xfe76, 0xfefc],
[0xff01, 0xff9d],
[0xffa0, 0xffbe],
[0xffc2, 0xffc7],
[0xffca, 0xffcf],
[0xffd2, 0xffd7],
[0xffda, 0xffdc],
[0xffe0, 0xffe6],
[0xffe8, 0xffee],
[0xfffc, 0xfffd],
[0x10000, 0x1000b],
[0x1000d, 0x10026],
[0x10028, 0x1003a],
[0x1003c, 0x1003d],
[0x1003f, 0x1004d],
[0x10050, 0x1005d],
[0x10080, 0x100fa],
[0x10100, 0x10102],
[0x10107, 0x10133],
[0x10137, 0x1018e],
[0x10190, 0x1019c],
[0x101a0],
[0x101d0, 0x101fc],
[0x10280, 0x1029c],
[0x102a0, 0x102d0],
[0x102e1, 0x102fb],
[0x10300, 0x10323],
[0x1032d, 0x1034a],
[0x10350, 0x10375],
[0x10380, 0x1039d],
[0x1039f, 0x103c3],
[0x103c8, 0x103d5],
[0x10400, 0x1049d],
[0x104a0, 0x104a9],
[0x104b0, 0x104d3],
[0x104d8, 0x104fb],
[0x10500, 0x10527],
[0x10530, 0x10563],
[0x1056f, 0x1057a],
[0x1057c, 0x1058a],
[0x1058c, 0x10592],
[0x10594, 0x10595],
[0x10597, 0x105a1],
[0x105a3, 0x105b1],
[0x105b3, 0x105b9],
[0x105bb, 0x105bc],
[0x10600, 0x10736],
[0x10740, 0x10755],
[0x10760, 0x10767],
[0x10780, 0x10785],
[0x10787, 0x107b0],
[0x107b2, 0x107ba],
[0x10800, 0x10805],
[0x10808],
[0x1080a, 0x10835],
[0x10837, 0x10838],
[0x1083c],
[0x1083f, 0x10855],
[0x10857, 0x1089e],
[0x108a7, 0x108af],
[0x108e0, 0x108f2],
[0x108f4, 0x108f5],
[0x108fb, 0x1091b],
[0x1091f, 0x10939],
[0x1093f],
[0x10980, 0x109b7],
[0x109bc, 0x109cf],
[0x109d2, 0x10a00],
[0x10a10, 0x10a13],
[0x10a15, 0x10a17],
[0x10a19, 0x10a35],
[0x10a40, 0x10a48],
[0x10a50, 0x10a58],
[0x10a60, 0x10a9f],
[0x10ac0, 0x10ae4],
[0x10aeb, 0x10af6],
[0x10b00, 0x10b35],
[0x10b39, 0x10b55],
[0x10b58, 0x10b72],
[0x10b78, 0x10b91],
[0x10b99, 0x10b9c],
[0x10ba9, 0x10baf],
[0x10c00, 0x10c48],
[0x10c80, 0x10cb2],
[0x10cc0, 0x10cf2],
[0x10cfa, 0x10d23],
[0x10d30, 0x10d39],
[0x10e60, 0x10e7e],
[0x10e80, 0x10ea9],
[0x10ead],
[0x10eb0, 0x10eb1],
[0x10f00, 0x10f27],
[0x10f30, 0x10f45],
[0x10f51, 0x10f59],
[0x10f70, 0x10f81],
[0x10f86, 0x10f89],
[0x10fb0, 0x10fcb],
[0x10fe0, 0x10ff6],
[0x11003, 0x11037],
[0x11047, 0x1104d],
[0x11052, 0x1106f],
[0x11071, 0x11072],
[0x11075],
[0x11083, 0x110af],
[0x110bb, 0x110bc],
[0x110be, 0x110c1],
[0x110d0, 0x110e8],
[0x110f0, 0x110f9],
[0x11103, 0x11126],
[0x11136, 0x11144],
[0x11147],
[0x11150, 0x11172],
[0x11174, 0x11176],
[0x11183, 0x111b2],
[0x111c1],
[0x111c4, 0x111c8],
[0x111cd],
[0x111d0, 0x111df],
[0x111e1, 0x111f4],
[0x11200, 0x11211],
[0x11213, 0x1122b],
[0x11238, 0x1123d],
[0x1123f, 0x11240],
[0x11280, 0x11286],
[0x11288],
[0x1128a, 0x1128d],
[0x1128f, 0x1129d],
[0x1129f, 0x112a9],
[0x112b0, 0x112de],
[0x112f0, 0x112f9],
[0x11305, 0x1130c],
[0x1130f, 0x11310],
[0x11313, 0x11328],
[0x1132a, 0x11330],
[0x11332, 0x11333],
[0x11335, 0x11339],
[0x1133d],
[0x11350],
[0x1135d, 0x11361],
[0x11400, 0x11434],
[0x11447, 0x1145b],
[0x1145d],
[0x1145f, 0x11461],
[0x11480, 0x114af],
[0x114c4, 0x114c7],
[0x114d0, 0x114d9],
[0x11580, 0x115ae],
[0x115c1, 0x115db],
[0x11600, 0x1162f],
[0x11641, 0x11644],
[0x11650, 0x11659],
[0x11660, 0x1166c],
[0x11680, 0x116aa],
[0x116b8, 0x116b9],
[0x116c0, 0x116c9],
[0x11700, 0x1171a],
[0x11730, 0x11746],
[0x11800, 0x1182b],
[0x1183b],
[0x118a0, 0x118f2],
[0x118ff, 0x11906],
[0x11909],
[0x1190c, 0x11913],
[0x11915, 0x11916],
[0x11918, 0x1192f],
[0x11944, 0x11946],
[0x11950, 0x11959],
[0x119a0, 0x119a7],
[0x119aa, 0x119d0],
[0x119e1, 0x119e3],
[0x11a00],
[0x11a0b, 0x11a32],
[0x11a3f, 0x11a46],
[0x11a50],
[0x11a5c, 0x11a83],
[0x11a9a, 0x11aa2],
[0x11ab0, 0x11af8],
[0x11b00, 0x11b09],
[0x11c00, 0x11c08],
[0x11c0a, 0x11c2e],
[0x11c40, 0x11c45],
[0x11c50, 0x11c6c],
[0x11c70, 0x11c8f],
[0x11d00, 0x11d06],
[0x11d08, 0x11d09],
[0x11d0b, 0x11d30],
[0x11d50, 0x11d59],
[0x11d60, 0x11d65],
[0x11d67, 0x11d68],
[0x11d6a, 0x11d89],
[0x11d98],
[0x11da0, 0x11da9],
[0x11ee0, 0x11ef2],
[0x11ef7, 0x11ef8],
[0x11f04, 0x11f10],
[0x11f12, 0x11f33],
[0x11f43, 0x11f59],
[0x11fb0],
[0x11fc0, 0x11ff1],
[0x11fff, 0x12399],
[0x12400, 0x1246e],
[0x12470, 0x12474],
[0x12480, 0x12543],
[0x12f90, 0x12ff2],
[0x13000, 0x1342f],
[0x13441, 0x13446],
[0x14400, 0x14646],
[0x16800, 0x16a38],
[0x16a40, 0x16a5e],
[0x16a60, 0x16a69],
[0x16a6e, 0x16abe],
[0x16ac0, 0x16ac9],
[0x16ad0, 0x16aed],
[0x16af5],
[0x16b00, 0x16b2f],
[0x16b37, 0x16b45],
[0x16b50, 0x16b59],
[0x16b5b, 0x16b61],
[0x16b63, 0x16b77],
[0x16b7d, 0x16b8f],
[0x16e40, 0x16e9a],
[0x16f00, 0x16f4a],
[0x16f50],
[0x16f93, 0x16f9f],
[0x16fe0, 0x16fe3],
[0x17000],
[0x187f7],
[0x18800, 0x18cd5],
[0x18d00],
[0x18d08],
[0x1aff0, 0x1aff3],
[0x1aff5, 0x1affb],
[0x1affd, 0x1affe],
[0x1b000, 0x1b122],
[0x1b132],
[0x1b150, 0x1b152],
[0x1b155],
[0x1b164, 0x1b167],
[0x1b170, 0x1b2fb],
[0x1bc00, 0x1bc6a],
[0x1bc70, 0x1bc7c],
[0x1bc80, 0x1bc88],
[0x1bc90, 0x1bc99],
[0x1bc9c],
[0x1bc9f],
[0x1cf50, 0x1cfc3],
[0x1d000, 0x1d0f5],
[0x1d100, 0x1d126],
[0x1d129, 0x1d164],
[0x1d16a, 0x1d16c],
[0x1d183, 0x1d184],
[0x1d18c, 0x1d1a9],
[0x1d1ae, 0x1d1ea],
[0x1d200, 0x1d241],
[0x1d245],
[0x1d2c0, 0x1d2d3],
[0x1d2e0, 0x1d2f3],
[0x1d300, 0x1d356],
[0x1d360, 0x1d378],
[0x1d400, 0x1d454],
[0x1d456, 0x1d49c],
[0x1d49e, 0x1d49f],
[0x1d4a2],
[0x1d4a5, 0x1d4a6],
[0x1d4a9, 0x1d4ac],
[0x1d4ae, 0x1d4b9],
[0x1d4bb],
[0x1d4bd, 0x1d4c3],
[0x1d4c5, 0x1d505],
[0x1d507, 0x1d50a],
[0x1d50d, 0x1d514],
[0x1d516, 0x1d51c],
[0x1d51e, 0x1d539],
[0x1d53b, 0x1d53e],
[0x1d540, 0x1d544],
[0x1d546],
[0x1d54a, 0x1d550],
[0x1d552, 0x1d6a5],
[0x1d6a8, 0x1d7cb],
[0x1d7ce, 0x1d9ff],
[0x1da37, 0x1da3a],
[0x1da6d, 0x1da74],
[0x1da76, 0x1da83],
[0x1da85, 0x1da8b],
[0x1df00, 0x1df1e],
[0x1df25, 0x1df2a],
[0x1e030, 0x1e06d],
[0x1e100, 0x1e12c],
[0x1e137, 0x1e13d],
[0x1e140, 0x1e149],
[0x1e14e, 0x1e14f],
[0x1e290, 0x1e2ad],
[0x1e2c0, 0x1e2eb],
[0x1e2f0, 0x1e2f9],
[0x1e2ff],
[0x1e4d0, 0x1e4eb],
[0x1e4f0, 0x1e4f9],
[0x1e7e0, 0x1e7e6],
[0x1e7e8, 0x1e7eb],
[0x1e7ed, 0x1e7ee],
[0x1e7f0, 0x1e7fe],
[0x1e800, 0x1e8c4],
[0x1e8c7, 0x1e8cf],
[0x1e900, 0x1e943],
[0x1e94b],
[0x1e950, 0x1e959],
[0x1e95e, 0x1e95f],
[0x1ec71, 0x1ecb4],
[0x1ed01, 0x1ed3d],
[0x1ee00, 0x1ee03],
[0x1ee05, 0x1ee1f],
[0x1ee21, 0x1ee22],
[0x1ee24],
[0x1ee27],
[0x1ee29, 0x1ee32],
[0x1ee34, 0x1ee37],
[0x1ee39],
[0x1ee3b],
[0x1ee42],
[0x1ee47],
[0x1ee49],
[0x1ee4b],
[0x1ee4d, 0x1ee4f],
[0x1ee51, 0x1ee52],
[0x1ee54],
[0x1ee57],
[0x1ee59],
[0x1ee5b],
[0x1ee5d],
[0x1ee5f],
[0x1ee61, 0x1ee62],
[0x1ee64],
[0x1ee67, 0x1ee6a],
[0x1ee6c, 0x1ee72],
[0x1ee74, 0x1ee77],
[0x1ee79, 0x1ee7c],
[0x1ee7e],
[0x1ee80, 0x1ee89],
[0x1ee8b, 0x1ee9b],
[0x1eea1, 0x1eea3],
[0x1eea5, 0x1eea9],
[0x1eeab, 0x1eebb],
[0x1eef0, 0x1eef1],
[0x1f000, 0x1f02b],
[0x1f030, 0x1f093],
[0x1f0a0, 0x1f0ae],
[0x1f0b1, 0x1f0bf],
[0x1f0c1, 0x1f0cf],
[0x1f0d1, 0x1f0f5],
[0x1f100, 0x1f1ad],
[0x1f200, 0x1f202],
[0x1f210, 0x1f23b],
[0x1f240, 0x1f248],
[0x1f250, 0x1f251],
[0x1f260, 0x1f265],
[0x1f300, 0x1f3fa],
[0x1f400, 0x1f6d7],
[0x1f6dc, 0x1f6ec],
[0x1f6f0, 0x1f6fc],
[0x1f700, 0x1f776],
[0x1f77b, 0x1f7d9],
[0x1f7e0, 0x1f7eb],
[0x1f7f0],
[0x1f800, 0x1f80b],
[0x1f810, 0x1f847],
[0x1f850, 0x1f859],
[0x1f860, 0x1f887],
[0x1f890, 0x1f8ad],
[0x1f8b0, 0x1f8b1],
[0x1f900, 0x1fa53],
[0x1fa60, 0x1fa6d],
[0x1fa70, 0x1fa7c],
[0x1fa80, 0x1fa88],
[0x1fa90, 0x1fabd],
[0x1fabf, 0x1fac5],
[0x1face, 0x1fadb],
[0x1fae0, 0x1fae8],
[0x1faf0, 0x1faf8],
[0x1fb00, 0x1fb92],
[0x1fb94, 0x1fbca],
[0x1fbf0, 0x1fbf9],
[0x20000],
[0x2a6df],
[0x2a700],
[0x2b739],
[0x2b740],
[0x2b81d],
[0x2b820],
[0x2cea1],
[0x2ceb0],
[0x2ebe0],
[0x2ebf0],
[0x2ee5d],
[0x2f800, 0x2fa1d],
[0x30000],
[0x3134a],
[0x31350],
[0x323af],
];
exports.autonomousDecomposableGraphemeRanges = [
[0xc0, 0xc5],
[0xc7, 0xcf],
[0xd1, 0xd6],
[0xd9, 0xdd],
[0xe0, 0xe5],
[0xe7, 0xef],
[0xf1, 0xf6],
[0xf9, 0xfd],
[0xff, 0x10f],
[0x112, 0x125],
[0x128, 0x130],
[0x134, 0x137],
[0x139, 0x13e],
[0x143, 0x148],
[0x14c, 0x151],
[0x154, 0x165],
[0x168, 0x17e],
[0x1a0, 0x1a1],
[0x1af, 0x1b0],
[0x1cd, 0x1dc],
[0x1de, 0x1e3],
[0x1e6, 0x1f0],
[0x1f4, 0x1f5],
[0x1f8, 0x21b],
[0x21e, 0x21f],
[0x226, 0x233],
[0x385, 0x386],
[0x388, 0x38a],
[0x38c],
[0x38e, 0x390],
[0x3aa, 0x3b0],
[0x3ca, 0x3ce],
[0x3d3, 0x3d4],
[0x400, 0x401],
[0x403],
[0x407],
[0x40c, 0x40e],
[0x419],
[0x439],
[0x450, 0x451],
[0x453],
[0x457],
[0x45c, 0x45e],
[0x476, 0x477],
[0x4c1, 0x4c2],
[0x4d0, 0x4d3],
[0x4d6, 0x4d7],
[0x4da, 0x4df],
[0x4e2, 0x4e7],
[0x4ea, 0x4f5],
[0x4f8, 0x4f9],
[0x622, 0x626],
[0x6c0],
[0x6c2],
[0x6d3],
[0x929],
[0x931],
[0x934],
[0x958, 0x95f],
[0x9dc, 0x9dd],
[0x9df],
[0xa33],
[0xa36],
[0xa59, 0xa5b],
[0xa5e],
[0xb5c, 0xb5d],
[0xb94],
[0xf43],
[0xf4d],
[0xf52],
[0xf57],
[0xf5c],
[0xf69],
[0x1026],
[0x1b06],
[0x1b08],
[0x1b0a],
[0x1b0c],
[0x1b0e],
[0x1b12],
[0x1e00, 0x1e99],
[0x1e9b],
[0x1ea0, 0x1ef9],
[0x1f00, 0x1f15],
[0x1f18, 0x1f1d],
[0x1f20, 0x1f45],
[0x1f48, 0x1f4d],
[0x1f50, 0x1f57],
[0x1f59],
[0x1f5b],
[0x1f5d],
[0x1f5f, 0x1f70],
[0x1f72],
[0x1f74],
[0x1f76],
[0x1f78],
[0x1f7a],
[0x1f7c],
[0x1f80, 0x1fb4],
[0x1fb6, 0x1fba],
[0x1fbc],
[0x1fc1, 0x1fc4],
[0x1fc6, 0x1fc8],
[0x1fca],
[0x1fcc, 0x1fd2],
[0x1fd6, 0x1fda],
[0x1fdd, 0x1fe2],
[0x1fe4, 0x1fea],
[0x1fec, 0x1fed],
[0x1ff2, 0x1ff4],
[0x1ff6, 0x1ff8],
[0x1ffa],
[0x1ffc],
[0x219a, 0x219b],
[0x21ae],
[0x21cd, 0x21cf],
[0x2204],
[0x2209],
[0x220c],
[0x2224],
[0x2226],
[0x2241],
[0x2244],
[0x2247],
[0x2249],
[0x2260],
[0x2262],
[0x226d, 0x2271],
[0x2274, 0x2275],
[0x2278, 0x2279],
[0x2280, 0x2281],
[0x2284, 0x2285],
[0x2288, 0x2289],
[0x22ac, 0x22af],
[0x22e0, 0x22e3],
[0x22ea, 0x22ed],
[0x2adc],
[0x304c],
[0x304e],
[0x3050],
[0x3052],
[0x3054],
[0x3056],
[0x3058],
[0x305a],
[0x305c],
[0x305e],
[0x3060],
[0x3062],
[0x3065],
[0x3067],
[0x3069],
[0x3070, 0x3071],
[0x3073, 0x3074],
[0x3076, 0x3077],
[0x3079, 0x307a],
[0x307c, 0x307d],
[0x3094],
[0x309e],
[0x30ac],
[0x30ae],
[0x30b0],
[0x30b2],
[0x30b4],
[0x30b6],
[0x30b8],
[0x30ba],
[0x30bc],
[0x30be],
[0x30c0],
[0x30c2],
[0x30c5],
[0x30c7],
[0x30c9],
[0x30d0, 0x30d1],
[0x30d3, 0x30d4],
[0x30d6, 0x30d7],
[0x30d9, 0x30da],
[0x30dc, 0x30dd],
[0x30f4],
[0x30f7, 0x30fa],
[0x30fe],
[0xac00],
[0xd7a3],
[0xfb1d],
[0xfb1f],
[0xfb2a, 0xfb36],
[0xfb38, 0xfb3c],
[0xfb3e],
[0xfb40, 0xfb41],
[0xfb43, 0xfb44],
[0xfb46, 0xfb4e],
[0x1109a],
[0x1109c],
[0x110ab],
[0x1d15e, 0x1d164],
[0x1d1bb, 0x1d1c0],
];

View File

@@ -0,0 +1,100 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Unit64 = exports.Zero64 = void 0;
exports.isZero64 = isZero64;
exports.isStrictlyNegative64 = isStrictlyNegative64;
exports.isStrictlyPositive64 = isStrictlyPositive64;
exports.isEqual64 = isEqual64;
exports.isStrictlySmaller64 = isStrictlySmaller64;
exports.clone64 = clone64;
exports.substract64 = substract64;
exports.negative64 = negative64;
exports.add64 = add64;
exports.halve64 = halve64;
exports.logLike64 = logLike64;
exports.Zero64 = { sign: 1, data: [0, 0] };
exports.Unit64 = { sign: 1, data: [0, 1] };
function isZero64(a) {
return a.data[0] === 0 && a.data[1] === 0;
}
function isStrictlyNegative64(a) {
return a.sign === -1 && !isZero64(a);
}
function isStrictlyPositive64(a) {
return a.sign === 1 && !isZero64(a);
}
function isEqual64(a, b) {
if (a.data[0] === b.data[0] && a.data[1] === b.data[1]) {
return a.sign === b.sign || (a.data[0] === 0 && a.data[1] === 0);
}
return false;
}
function isStrictlySmaller64Internal(a, b) {
return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1]);
}
function isStrictlySmaller64(a, b) {
if (a.sign === b.sign) {
return a.sign === 1
? isStrictlySmaller64Internal(a.data, b.data)
: isStrictlySmaller64Internal(b.data, a.data);
}
return a.sign === -1 && (!isZero64(a) || !isZero64(b));
}
function clone64(a) {
return { sign: a.sign, data: [a.data[0], a.data[1]] };
}
function substract64DataInternal(a, b) {
let reminderLow = 0;
let low = a[1] - b[1];
if (low < 0) {
reminderLow = 1;
low = low >>> 0;
}
return [a[0] - b[0] - reminderLow, low];
}
function substract64Internal(a, b) {
if (a.sign === 1 && b.sign === -1) {
const low = a.data[1] + b.data[1];
const high = a.data[0] + b.data[0] + (low > 0xffffffff ? 1 : 0);
return { sign: 1, data: [high >>> 0, low >>> 0] };
}
return {
sign: 1,
data: a.sign === 1 ? substract64DataInternal(a.data, b.data) : substract64DataInternal(b.data, a.data),
};
}
function substract64(arrayIntA, arrayIntB) {
if (isStrictlySmaller64(arrayIntA, arrayIntB)) {
const out = substract64Internal(arrayIntB, arrayIntA);
out.sign = -1;
return out;
}
return substract64Internal(arrayIntA, arrayIntB);
}
function negative64(arrayIntA) {
return {
sign: -arrayIntA.sign,
data: [arrayIntA.data[0], arrayIntA.data[1]],
};
}
function add64(arrayIntA, arrayIntB) {
if (isZero64(arrayIntB)) {
if (isZero64(arrayIntA)) {
return clone64(exports.Zero64);
}
return clone64(arrayIntA);
}
return substract64(arrayIntA, negative64(arrayIntB));
}
function halve64(a) {
return {
sign: a.sign,
data: [Math.floor(a.data[0] / 2), (a.data[0] % 2 === 1 ? 0x80000000 : 0) + Math.floor(a.data[1] / 2)],
};
}
function logLike64(a) {
return {
sign: a.sign,
data: [0, Math.floor(Math.log(a.data[0] * 0x100000000 + a.data[1]) / Math.log(2))],
};
}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.integerLogLike = integerLogLike;
exports.bigIntLogLike = bigIntLogLike;
exports.biasNumericRange = biasNumericRange;
const globals_1 = require("../../../utils/globals");
const safeMathFloor = Math.floor;
const safeMathLog = Math.log;
function integerLogLike(v) {
return safeMathFloor(safeMathLog(v) / safeMathLog(2));
}
function bigIntLogLike(v) {
if (v === (0, globals_1.BigInt)(0))
return (0, globals_1.BigInt)(0);
return (0, globals_1.BigInt)((0, globals_1.String)(v).length);
}
function biasNumericRange(min, max, logLike) {
if (min === max) {
return [{ min: min, max: max }];
}
if (min < 0 && max > 0) {
const logMin = logLike(-min);
const logMax = logLike(max);
return [
{ min: -logMin, max: logMax },
{ min: (max - logMax), max: max },
{ min: min, max: min + logMin },
];
}
const logGap = logLike((max - min));
const arbCloseToMin = { min: min, max: min + logGap };
const arbCloseToMax = { min: (max - logGap), max: max };
return min < 0
? [arbCloseToMax, arbCloseToMin]
: [arbCloseToMin, arbCloseToMax];
}

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSchedulerFor = buildSchedulerFor;
const SchedulerImplem_1 = require("../implementations/SchedulerImplem");
function buildNextTaskIndex(ordering) {
let numTasks = 0;
return {
clone: () => buildNextTaskIndex(ordering),
nextTaskIndex: (scheduledTasks) => {
if (ordering.length <= numTasks) {
throw new Error(`Invalid schedulerFor defined: too many tasks have been scheduled`);
}
const taskIndex = scheduledTasks.findIndex((t) => t.taskId === ordering[numTasks]);
if (taskIndex === -1) {
throw new Error(`Invalid schedulerFor defined: unable to find next task`);
}
++numTasks;
return taskIndex;
},
};
}
function buildSchedulerFor(act, ordering) {
return new SchedulerImplem_1.SchedulerImplem(act, buildNextTaskIndex(ordering));
}

View File

@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildSlicedGenerator = buildSlicedGenerator;
const NoopSlicedGenerator_1 = require("../implementations/NoopSlicedGenerator");
const SlicedBasedGenerator_1 = require("../implementations/SlicedBasedGenerator");
function buildSlicedGenerator(arb, mrng, slices, biasFactor) {
if (biasFactor === undefined || slices.length === 0 || mrng.nextInt(1, biasFactor) !== 1) {
return new NoopSlicedGenerator_1.NoopSlicedGenerator(arb, mrng, biasFactor);
}
return new SlicedBasedGenerator_1.SlicedBasedGenerator(arb, mrng, slices, biasFactor);
}

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CustomEqualSet = void 0;
const globals_1 = require("../../../utils/globals");
class CustomEqualSet {
constructor(isEqual) {
this.isEqual = isEqual;
this.data = [];
}
tryAdd(value) {
for (let idx = 0; idx !== this.data.length; ++idx) {
if (this.isEqual(this.data[idx], value)) {
return false;
}
}
(0, globals_1.safePush)(this.data, value);
return true;
}
size() {
return this.data.length;
}
getData() {
return this.data;
}
}
exports.CustomEqualSet = CustomEqualSet;

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDepthContextFor = getDepthContextFor;
exports.createDepthIdentifier = createDepthIdentifier;
const globals_1 = require("../../../utils/globals");
const depthContextCache = new Map();
function getDepthContextFor(contextMeta) {
if (contextMeta === undefined) {
return { depth: 0 };
}
if (typeof contextMeta !== 'string') {
return contextMeta;
}
const cachedContext = (0, globals_1.safeMapGet)(depthContextCache, contextMeta);
if (cachedContext !== undefined) {
return cachedContext;
}
const context = { depth: 0 };
(0, globals_1.safeMapSet)(depthContextCache, contextMeta, context);
return context;
}
function createDepthIdentifier() {
const identifier = { depth: 0 };
return identifier;
}

View File

@@ -0,0 +1,90 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decomposeDouble = decomposeDouble;
exports.doubleToIndex = doubleToIndex;
exports.indexToDouble = indexToDouble;
const ArrayInt64_1 = require("./ArrayInt64");
const safeNegativeInfinity = Number.NEGATIVE_INFINITY;
const safePositiveInfinity = Number.POSITIVE_INFINITY;
const safeEpsilon = Number.EPSILON;
const INDEX_POSITIVE_INFINITY = { sign: 1, data: [2146435072, 0] };
const INDEX_NEGATIVE_INFINITY = { sign: -1, data: [2146435072, 1] };
const f64 = new Float64Array(1);
const u32 = new Uint32Array(f64.buffer, f64.byteOffset);
function bitCastDoubleToUInt64(f) {
f64[0] = f;
return [u32[1], u32[0]];
}
function decomposeDouble(d) {
const { 0: hi, 1: lo } = bitCastDoubleToUInt64(d);
const signBit = hi >>> 31;
const exponentBits = (hi >>> 20) & 0x7ff;
const significandBits = (hi & 0xfffff) * 0x100000000 + lo;
const exponent = exponentBits === 0 ? -1022 : exponentBits - 1023;
let significand = exponentBits === 0 ? 0 : 1;
significand += significandBits / 2 ** 52;
significand *= signBit === 0 ? 1 : -1;
return { exponent, significand };
}
function positiveNumberToInt64(n) {
return [~~(n / 0x100000000), n >>> 0];
}
function indexInDoubleFromDecomp(exponent, significand) {
if (exponent === -1022) {
const rescaledSignificand = significand * 2 ** 52;
return positiveNumberToInt64(rescaledSignificand);
}
const rescaledSignificand = (significand - 1) * 2 ** 52;
const exponentOnlyHigh = (exponent + 1023) * 2 ** 20;
const index = positiveNumberToInt64(rescaledSignificand);
index[0] += exponentOnlyHigh;
return index;
}
function doubleToIndex(d) {
if (d === safePositiveInfinity) {
return (0, ArrayInt64_1.clone64)(INDEX_POSITIVE_INFINITY);
}
if (d === safeNegativeInfinity) {
return (0, ArrayInt64_1.clone64)(INDEX_NEGATIVE_INFINITY);
}
const decomp = decomposeDouble(d);
const exponent = decomp.exponent;
const significand = decomp.significand;
if (d > 0 || (d === 0 && 1 / d === safePositiveInfinity)) {
return { sign: 1, data: indexInDoubleFromDecomp(exponent, significand) };
}
else {
const indexOpposite = indexInDoubleFromDecomp(exponent, -significand);
if (indexOpposite[1] === 0xffffffff) {
indexOpposite[0] += 1;
indexOpposite[1] = 0;
}
else {
indexOpposite[1] += 1;
}
return { sign: -1, data: indexOpposite };
}
}
function indexToDouble(index) {
if (index.sign === -1) {
const indexOpposite = { sign: 1, data: [index.data[0], index.data[1]] };
if (indexOpposite.data[1] === 0) {
indexOpposite.data[0] -= 1;
indexOpposite.data[1] = 0xffffffff;
}
else {
indexOpposite.data[1] -= 1;
}
return -indexToDouble(indexOpposite);
}
if ((0, ArrayInt64_1.isEqual64)(index, INDEX_POSITIVE_INFINITY)) {
return safePositiveInfinity;
}
if (index.data[0] < 0x200000) {
return (index.data[0] * 0x100000000 + index.data[1]) * 2 ** -1074;
}
const postIndexHigh = index.data[0] - 0x200000;
const exponent = -1021 + (postIndexHigh >> 20);
const significand = 1 + ((postIndexHigh & 0xfffff) * 2 ** 32 + index.data[1]) * safeEpsilon;
return significand * 2 ** exponent;
}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onlyIntegersAfterThisValue = exports.maxNonIntegerValue = void 0;
exports.refineConstraintsForDoubleOnly = refineConstraintsForDoubleOnly;
exports.doubleOnlyMapper = doubleOnlyMapper;
exports.doubleOnlyUnmapper = doubleOnlyUnmapper;
const FloatingOnlyHelpers_1 = require("./FloatingOnlyHelpers");
const safeNegativeInfinity = Number.NEGATIVE_INFINITY;
const safePositiveInfinity = Number.POSITIVE_INFINITY;
const safeMaxValue = Number.MAX_VALUE;
exports.maxNonIntegerValue = 4503599627370495.5;
exports.onlyIntegersAfterThisValue = 4503599627370496;
function refineConstraintsForDoubleOnly(constraints) {
return (0, FloatingOnlyHelpers_1.refineConstraintsForFloatingOnly)(constraints, safeMaxValue, exports.maxNonIntegerValue, exports.onlyIntegersAfterThisValue);
}
function doubleOnlyMapper(value) {
return value === exports.onlyIntegersAfterThisValue
? safePositiveInfinity
: value === -exports.onlyIntegersAfterThisValue
? safeNegativeInfinity
: value;
}
function doubleOnlyUnmapper(value) {
if (typeof value !== 'number')
throw new Error('Unsupported type');
return value === safePositiveInfinity
? exports.onlyIntegersAfterThisValue
: value === safeNegativeInfinity
? -exports.onlyIntegersAfterThisValue
: value;
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractEnumerableKeys = extractEnumerableKeys;
const safeObjectKeys = Object.keys;
const safeObjectGetOwnPropertySymbols = Object.getOwnPropertySymbols;
const safeObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
function extractEnumerableKeys(instance) {
const keys = safeObjectKeys(instance);
const symbols = safeObjectGetOwnPropertySymbols(instance);
for (let index = 0; index !== symbols.length; ++index) {
const symbol = symbols[index];
const descriptor = safeObjectGetOwnPropertyDescriptor(instance, symbol);
if (descriptor && descriptor.enumerable) {
keys.push(symbol);
}
}
return keys;
}

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EPSILON_32 = exports.MAX_VALUE_32 = exports.MIN_VALUE_32 = void 0;
exports.decomposeFloat = decomposeFloat;
exports.floatToIndex = floatToIndex;
exports.indexToFloat = indexToFloat;
const safeNegativeInfinity = Number.NEGATIVE_INFINITY;
const safePositiveInfinity = Number.POSITIVE_INFINITY;
exports.MIN_VALUE_32 = 2 ** -126 * 2 ** -23;
exports.MAX_VALUE_32 = 2 ** 127 * (1 + (2 ** 23 - 1) / 2 ** 23);
exports.EPSILON_32 = 2 ** -23;
const INDEX_POSITIVE_INFINITY = 2139095040;
const INDEX_NEGATIVE_INFINITY = -2139095041;
const f32 = new Float32Array(1);
const u32 = new Uint32Array(f32.buffer, f32.byteOffset);
function bitCastFloatToUInt32(f) {
f32[0] = f;
return u32[0];
}
function decomposeFloat(f) {
const bits = bitCastFloatToUInt32(f);
const signBit = bits >>> 31;
const exponentBits = (bits >>> 23) & 0xff;
const significandBits = bits & 0x7fffff;
const exponent = exponentBits === 0 ? -126 : exponentBits - 127;
let significand = exponentBits === 0 ? 0 : 1;
significand += significandBits / 2 ** 23;
significand *= signBit === 0 ? 1 : -1;
return { exponent, significand };
}
function indexInFloatFromDecomp(exponent, significand) {
if (exponent === -126) {
return significand * 0x800000;
}
return (exponent + 127) * 0x800000 + (significand - 1) * 0x800000;
}
function floatToIndex(f) {
if (f === safePositiveInfinity) {
return INDEX_POSITIVE_INFINITY;
}
if (f === safeNegativeInfinity) {
return INDEX_NEGATIVE_INFINITY;
}
const decomp = decomposeFloat(f);
const exponent = decomp.exponent;
const significand = decomp.significand;
if (f > 0 || (f === 0 && 1 / f === safePositiveInfinity)) {
return indexInFloatFromDecomp(exponent, significand);
}
else {
return -indexInFloatFromDecomp(exponent, -significand) - 1;
}
}
function indexToFloat(index) {
if (index < 0) {
return -indexToFloat(-index - 1);
}
if (index === INDEX_POSITIVE_INFINITY) {
return safePositiveInfinity;
}
if (index < 0x1000000) {
return index * 2 ** -149;
}
const postIndex = index - 0x1000000;
const exponent = -125 + (postIndex >> 23);
const significand = 1 + (postIndex & 0x7fffff) / 0x800000;
return significand * 2 ** exponent;
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.onlyIntegersAfterThisValue = exports.maxNonIntegerValue = void 0;
exports.refineConstraintsForFloatOnly = refineConstraintsForFloatOnly;
exports.floatOnlyMapper = floatOnlyMapper;
exports.floatOnlyUnmapper = floatOnlyUnmapper;
const FloatHelpers_1 = require("./FloatHelpers");
const FloatingOnlyHelpers_1 = require("./FloatingOnlyHelpers");
const safeNegativeInfinity = Number.NEGATIVE_INFINITY;
const safePositiveInfinity = Number.POSITIVE_INFINITY;
const safeMaxValue = FloatHelpers_1.MAX_VALUE_32;
exports.maxNonIntegerValue = 8388607.5;
exports.onlyIntegersAfterThisValue = 8388608;
function refineConstraintsForFloatOnly(constraints) {
return (0, FloatingOnlyHelpers_1.refineConstraintsForFloatingOnly)(constraints, safeMaxValue, exports.maxNonIntegerValue, exports.onlyIntegersAfterThisValue);
}
function floatOnlyMapper(value) {
return value === exports.onlyIntegersAfterThisValue
? safePositiveInfinity
: value === -exports.onlyIntegersAfterThisValue
? safeNegativeInfinity
: value;
}
function floatOnlyUnmapper(value) {
if (typeof value !== 'number')
throw new Error('Unsupported type');
return value === safePositiveInfinity
? exports.onlyIntegersAfterThisValue
: value === safeNegativeInfinity
? -exports.onlyIntegersAfterThisValue
: value;
}

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.refineConstraintsForFloatingOnly = refineConstraintsForFloatingOnly;
const safeNumberIsInteger = Number.isInteger;
const safeObjectIs = Object.is;
const safeNegativeInfinity = Number.NEGATIVE_INFINITY;
const safePositiveInfinity = Number.POSITIVE_INFINITY;
function refineConstraintsForFloatingOnly(constraints, maxValue, maxNonIntegerValue, onlyIntegersAfterThisValue) {
const { noDefaultInfinity = false, minExcluded = false, maxExcluded = false, min = noDefaultInfinity ? -maxValue : safeNegativeInfinity, max = noDefaultInfinity ? maxValue : safePositiveInfinity, } = constraints;
const effectiveMin = minExcluded
? min < -maxNonIntegerValue
? -onlyIntegersAfterThisValue
: Math.max(min, -maxNonIntegerValue)
: min === safeNegativeInfinity
? Math.max(min, -onlyIntegersAfterThisValue)
: Math.max(min, -maxNonIntegerValue);
const effectiveMax = maxExcluded
? max > maxNonIntegerValue
? onlyIntegersAfterThisValue
: Math.min(max, maxNonIntegerValue)
: max === safePositiveInfinity
? Math.min(max, onlyIntegersAfterThisValue)
: Math.min(max, maxNonIntegerValue);
const fullConstraints = {
noDefaultInfinity: false,
minExcluded: minExcluded || ((min !== safeNegativeInfinity || minExcluded) && safeNumberIsInteger(effectiveMin)),
maxExcluded: maxExcluded || ((max !== safePositiveInfinity || maxExcluded) && safeNumberIsInteger(effectiveMax)),
min: safeObjectIs(effectiveMin, -0) ? 0 : effectiveMin,
max: safeObjectIs(effectiveMax, 0) ? -0 : effectiveMax,
noNaN: constraints.noNaN || false,
};
return fullConstraints;
}

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertGraphemeRangeToMapToConstantEntry = convertGraphemeRangeToMapToConstantEntry;
exports.intersectGraphemeRanges = intersectGraphemeRanges;
const globals_1 = require("../../../utils/globals");
const safeStringFromCodePoint = String.fromCodePoint;
const safeMathMin = Math.min;
const safeMathMax = Math.max;
function convertGraphemeRangeToMapToConstantEntry(range) {
if (range.length === 1) {
const codePointString = safeStringFromCodePoint(range[0]);
return { num: 1, build: () => codePointString };
}
const rangeStart = range[0];
return { num: range[1] - range[0] + 1, build: (idInGroup) => safeStringFromCodePoint(rangeStart + idInGroup) };
}
function intersectGraphemeRanges(rangesA, rangesB) {
const mergedRanges = [];
let cursorA = 0;
let cursorB = 0;
while (cursorA < rangesA.length && cursorB < rangesB.length) {
const rangeA = rangesA[cursorA];
const rangeAMin = rangeA[0];
const rangeAMax = rangeA.length === 1 ? rangeA[0] : rangeA[1];
const rangeB = rangesB[cursorB];
const rangeBMin = rangeB[0];
const rangeBMax = rangeB.length === 1 ? rangeB[0] : rangeB[1];
if (rangeAMax < rangeBMin) {
cursorA += 1;
}
else if (rangeBMax < rangeAMin) {
cursorB += 1;
}
else {
let min = safeMathMax(rangeAMin, rangeBMin);
const max = safeMathMin(rangeAMax, rangeBMax);
if (mergedRanges.length >= 1) {
const lastMergedRange = mergedRanges[mergedRanges.length - 1];
const lastMergedRangeMax = lastMergedRange.length === 1 ? lastMergedRange[0] : lastMergedRange[1];
if (lastMergedRangeMax + 1 === min) {
min = lastMergedRange[0];
(0, globals_1.safePop)(mergedRanges);
}
}
(0, globals_1.safePush)(mergedRanges, min === max ? [min] : [min, max]);
if (rangeAMax <= max) {
cursorA += 1;
}
if (rangeBMax <= max) {
cursorB += 1;
}
}
}
return mergedRanges;
}

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterInvalidSubdomainLabel = filterInvalidSubdomainLabel;
function filterInvalidSubdomainLabel(subdomainLabel) {
if (subdomainLabel.length > 63) {
return false;
}
return (subdomainLabel.length < 4 ||
subdomainLabel[0] !== 'x' ||
subdomainLabel[1] !== 'n' ||
subdomainLabel[2] !== '-' ||
subdomainLabel[3] !== '-');
}

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSubarrayOf = isSubarrayOf;
const globals_1 = require("../../../utils/globals");
const safeObjectIs = Object.is;
function isSubarrayOf(source, small) {
const countMap = new globals_1.Map();
let countMinusZero = 0;
for (const sourceEntry of source) {
if (safeObjectIs(sourceEntry, -0)) {
++countMinusZero;
}
else {
const oldCount = (0, globals_1.safeMapGet)(countMap, sourceEntry) || 0;
(0, globals_1.safeMapSet)(countMap, sourceEntry, oldCount + 1);
}
}
for (let index = 0; index !== small.length; ++index) {
if (!(index in small)) {
return false;
}
const smallEntry = small[index];
if (safeObjectIs(smallEntry, -0)) {
if (countMinusZero === 0)
return false;
--countMinusZero;
}
else {
const oldCount = (0, globals_1.safeMapGet)(countMap, smallEntry) || 0;
if (oldCount === 0)
return false;
(0, globals_1.safeMapSet)(countMap, smallEntry, oldCount - 1);
}
}
return true;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.jsonConstraintsBuilder = jsonConstraintsBuilder;
const boolean_1 = require("../../boolean");
const constant_1 = require("../../constant");
const double_1 = require("../../double");
function jsonConstraintsBuilder(stringArbitrary, constraints) {
const { depthSize, maxDepth } = constraints;
const key = stringArbitrary;
const values = [
(0, boolean_1.boolean)(),
(0, double_1.double)({ noDefaultInfinity: true, noNaN: true }),
stringArbitrary,
(0, constant_1.constant)(null),
];
return { key, values, depthSize, maxDepth };
}

View File

@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultSize = exports.MaxLengthUpperBound = void 0;
exports.maxLengthFromMinLength = maxLengthFromMinLength;
exports.relativeSizeToSize = relativeSizeToSize;
exports.maxGeneratedLengthFromSizeForArbitrary = maxGeneratedLengthFromSizeForArbitrary;
exports.depthBiasFromSizeForArbitrary = depthBiasFromSizeForArbitrary;
exports.resolveSize = resolveSize;
const GlobalParameters_1 = require("../../../check/runner/configuration/GlobalParameters");
const globals_1 = require("../../../utils/globals");
const safeMathFloor = Math.floor;
const safeMathMin = Math.min;
exports.MaxLengthUpperBound = 0x7fffffff;
const orderedSize = ['xsmall', 'small', 'medium', 'large', 'xlarge'];
const orderedRelativeSize = ['-4', '-3', '-2', '-1', '=', '+1', '+2', '+3', '+4'];
exports.DefaultSize = 'small';
function maxLengthFromMinLength(minLength, size) {
switch (size) {
case 'xsmall':
return safeMathFloor(1.1 * minLength) + 1;
case 'small':
return 2 * minLength + 10;
case 'medium':
return 11 * minLength + 100;
case 'large':
return 101 * minLength + 1000;
case 'xlarge':
return 1001 * minLength + 10000;
default:
throw new Error(`Unable to compute lengths based on received size: ${size}`);
}
}
function relativeSizeToSize(size, defaultSize) {
const sizeInRelative = (0, globals_1.safeIndexOf)(orderedRelativeSize, size);
if (sizeInRelative === -1) {
return size;
}
const defaultSizeInSize = (0, globals_1.safeIndexOf)(orderedSize, defaultSize);
if (defaultSizeInSize === -1) {
throw new Error(`Unable to offset size based on the unknown defaulted one: ${defaultSize}`);
}
const resultingSizeInSize = defaultSizeInSize + sizeInRelative - 4;
return resultingSizeInSize < 0
? orderedSize[0]
: resultingSizeInSize >= orderedSize.length
? orderedSize[orderedSize.length - 1]
: orderedSize[resultingSizeInSize];
}
function maxGeneratedLengthFromSizeForArbitrary(size, minLength, maxLength, specifiedMaxLength) {
const { baseSize: defaultSize = exports.DefaultSize, defaultSizeToMaxWhenMaxSpecified } = (0, GlobalParameters_1.readConfigureGlobal)() || {};
const definedSize = size !== undefined ? size : specifiedMaxLength && defaultSizeToMaxWhenMaxSpecified ? 'max' : defaultSize;
if (definedSize === 'max') {
return maxLength;
}
const finalSize = relativeSizeToSize(definedSize, defaultSize);
return safeMathMin(maxLengthFromMinLength(minLength, finalSize), maxLength);
}
function depthBiasFromSizeForArbitrary(depthSizeOrSize, specifiedMaxDepth) {
if (typeof depthSizeOrSize === 'number') {
return 1 / depthSizeOrSize;
}
const { baseSize: defaultSize = exports.DefaultSize, defaultSizeToMaxWhenMaxSpecified } = (0, GlobalParameters_1.readConfigureGlobal)() || {};
const definedSize = depthSizeOrSize !== undefined
? depthSizeOrSize
: specifiedMaxDepth && defaultSizeToMaxWhenMaxSpecified
? 'max'
: defaultSize;
if (definedSize === 'max') {
return 0;
}
const finalSize = relativeSizeToSize(definedSize, defaultSize);
switch (finalSize) {
case 'xsmall':
return 1;
case 'small':
return 0.5;
case 'medium':
return 0.25;
case 'large':
return 0.125;
case 'xlarge':
return 0.0625;
}
}
function resolveSize(size) {
const { baseSize: defaultSize = exports.DefaultSize } = (0, GlobalParameters_1.readConfigureGlobal)() || {};
if (size === undefined) {
return defaultSize;
}
return relativeSizeToSize(size, defaultSize);
}

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.UndefinedContextPlaceholder = void 0;
exports.noUndefinedAsContext = noUndefinedAsContext;
const Value_1 = require("../../../check/arbitrary/definition/Value");
exports.UndefinedContextPlaceholder = Symbol('UndefinedContextPlaceholder');
function noUndefinedAsContext(value) {
if (value.context !== undefined) {
return value;
}
if (value.hasToBeCloned) {
return new Value_1.Value(value.value_, exports.UndefinedContextPlaceholder, () => value.value);
}
return new Value_1.Value(value.value_, exports.UndefinedContextPlaceholder);
}

View File

@@ -0,0 +1,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toQualifiedObjectConstraints = toQualifiedObjectConstraints;
const boolean_1 = require("../../boolean");
const constant_1 = require("../../constant");
const double_1 = require("../../double");
const fullUnicodeString_1 = require("../../fullUnicodeString");
const maxSafeInteger_1 = require("../../maxSafeInteger");
const oneof_1 = require("../../oneof");
const string_1 = require("../../string");
const BoxedArbitraryBuilder_1 = require("../builders/BoxedArbitraryBuilder");
function defaultValues(constraints, stringArbitrary) {
return [
(0, boolean_1.boolean)(),
(0, maxSafeInteger_1.maxSafeInteger)(),
(0, double_1.double)(),
stringArbitrary(constraints),
(0, oneof_1.oneof)(stringArbitrary(constraints), (0, constant_1.constant)(null), (0, constant_1.constant)(undefined)),
];
}
function boxArbitraries(arbs) {
return arbs.map((arb) => (0, BoxedArbitraryBuilder_1.boxedArbitraryBuilder)(arb));
}
function boxArbitrariesIfNeeded(arbs, boxEnabled) {
return boxEnabled ? boxArbitraries(arbs).concat(arbs) : arbs;
}
function toQualifiedObjectConstraints(settings = {}) {
function orDefault(optionalValue, defaultValue) {
return optionalValue !== undefined ? optionalValue : defaultValue;
}
const stringArbitrary = 'stringUnit' in settings ? string_1.string : settings.withUnicodeString ? fullUnicodeString_1.fullUnicodeString : string_1.string;
const valueConstraints = { size: settings.size, unit: settings.stringUnit };
return {
key: orDefault(settings.key, stringArbitrary(valueConstraints)),
values: boxArbitrariesIfNeeded(orDefault(settings.values, defaultValues(valueConstraints, stringArbitrary)), orDefault(settings.withBoxedValues, false)),
depthSize: settings.depthSize,
maxDepth: settings.maxDepth,
maxKeys: settings.maxKeys,
size: settings.size,
withSet: orDefault(settings.withSet, false),
withMap: orDefault(settings.withMap, false),
withObjectString: orDefault(settings.withObjectString, false),
withNullPrototype: orDefault(settings.withNullPrototype, false),
withBigInt: orDefault(settings.withBigInt, false),
withDate: orDefault(settings.withDate, false),
withTypedArray: orDefault(settings.withTypedArray, false),
withSparseArray: orDefault(settings.withSparseArray, false),
};
}

View File

@@ -0,0 +1,211 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenizerBlockMode = void 0;
exports.readFrom = readFrom;
function charSizeAt(text, pos) {
return text[pos] >= '\uD800' && text[pos] <= '\uDBFF' && text[pos + 1] >= '\uDC00' && text[pos + 1] <= '\uDFFF'
? 2
: 1;
}
function isHexaDigit(char) {
return (char >= '0' && char <= '9') || (char >= 'a' && char <= 'f') || (char >= 'A' && char <= 'F');
}
function isDigit(char) {
return char >= '0' && char <= '9';
}
function squaredBracketBlockContentEndFrom(text, from) {
for (let index = from; index !== text.length; ++index) {
const char = text[index];
if (char === '\\') {
index += 1;
}
else if (char === ']') {
return index;
}
}
throw new Error(`Missing closing ']'`);
}
function parenthesisBlockContentEndFrom(text, from) {
let numExtraOpened = 0;
for (let index = from; index !== text.length; ++index) {
const char = text[index];
if (char === '\\') {
index += 1;
}
else if (char === ')') {
if (numExtraOpened === 0) {
return index;
}
numExtraOpened -= 1;
}
else if (char === '[') {
index = squaredBracketBlockContentEndFrom(text, index);
}
else if (char === '(') {
numExtraOpened += 1;
}
}
throw new Error(`Missing closing ')'`);
}
function curlyBracketBlockContentEndFrom(text, from) {
let foundComma = false;
for (let index = from; index !== text.length; ++index) {
const char = text[index];
if (isDigit(char)) {
}
else if (from === index) {
return -1;
}
else if (char === ',') {
if (foundComma) {
return -1;
}
foundComma = true;
}
else if (char === '}') {
return index;
}
else {
return -1;
}
}
return -1;
}
var TokenizerBlockMode;
(function (TokenizerBlockMode) {
TokenizerBlockMode[TokenizerBlockMode["Full"] = 0] = "Full";
TokenizerBlockMode[TokenizerBlockMode["Character"] = 1] = "Character";
})(TokenizerBlockMode || (exports.TokenizerBlockMode = TokenizerBlockMode = {}));
function blockEndFrom(text, from, unicodeMode, mode) {
switch (text[from]) {
case '[': {
if (mode === TokenizerBlockMode.Character) {
return from + 1;
}
return squaredBracketBlockContentEndFrom(text, from + 1) + 1;
}
case '{': {
if (mode === TokenizerBlockMode.Character) {
return from + 1;
}
const foundEnd = curlyBracketBlockContentEndFrom(text, from + 1);
if (foundEnd === -1) {
return from + 1;
}
return foundEnd + 1;
}
case '(': {
if (mode === TokenizerBlockMode.Character) {
return from + 1;
}
return parenthesisBlockContentEndFrom(text, from + 1) + 1;
}
case ']':
case '}':
case ')':
return from + 1;
case '\\': {
const next1 = text[from + 1];
switch (next1) {
case 'x':
if (isHexaDigit(text[from + 2]) && isHexaDigit(text[from + 3])) {
return from + 4;
}
throw new Error(`Unexpected token '${text.substring(from, from + 4)}' found`);
case 'u':
if (text[from + 2] === '{') {
if (!unicodeMode) {
return from + 2;
}
if (text[from + 4] === '}') {
if (isHexaDigit(text[from + 3])) {
return from + 5;
}
throw new Error(`Unexpected token '${text.substring(from, from + 5)}' found`);
}
if (text[from + 5] === '}') {
if (isHexaDigit(text[from + 3]) && isHexaDigit(text[from + 4])) {
return from + 6;
}
throw new Error(`Unexpected token '${text.substring(from, from + 6)}' found`);
}
if (text[from + 6] === '}') {
if (isHexaDigit(text[from + 3]) && isHexaDigit(text[from + 4]) && isHexaDigit(text[from + 5])) {
return from + 7;
}
throw new Error(`Unexpected token '${text.substring(from, from + 7)}' found`);
}
if (text[from + 7] === '}') {
if (isHexaDigit(text[from + 3]) &&
isHexaDigit(text[from + 4]) &&
isHexaDigit(text[from + 5]) &&
isHexaDigit(text[from + 6])) {
return from + 8;
}
throw new Error(`Unexpected token '${text.substring(from, from + 8)}' found`);
}
if (text[from + 8] === '}' &&
isHexaDigit(text[from + 3]) &&
isHexaDigit(text[from + 4]) &&
isHexaDigit(text[from + 5]) &&
isHexaDigit(text[from + 6]) &&
isHexaDigit(text[from + 7])) {
return from + 9;
}
throw new Error(`Unexpected token '${text.substring(from, from + 9)}' found`);
}
if (isHexaDigit(text[from + 2]) &&
isHexaDigit(text[from + 3]) &&
isHexaDigit(text[from + 4]) &&
isHexaDigit(text[from + 5])) {
return from + 6;
}
throw new Error(`Unexpected token '${text.substring(from, from + 6)}' found`);
case 'p':
case 'P': {
if (!unicodeMode) {
return from + 2;
}
let subIndex = from + 2;
for (; subIndex < text.length && text[subIndex] !== '}'; subIndex += text[subIndex] === '\\' ? 2 : 1) {
}
if (text[subIndex] !== '}') {
throw new Error(`Invalid \\P definition`);
}
return subIndex + 1;
}
case 'k': {
let subIndex = from + 2;
for (; subIndex < text.length && text[subIndex] !== '>'; ++subIndex) {
}
if (text[subIndex] !== '>') {
if (!unicodeMode) {
return from + 2;
}
throw new Error(`Invalid \\k definition`);
}
return subIndex + 1;
}
default: {
if (isDigit(next1)) {
const maxIndex = unicodeMode ? text.length : Math.min(from + 4, text.length);
let subIndex = from + 2;
for (; subIndex < maxIndex && isDigit(text[subIndex]); ++subIndex) {
}
return subIndex;
}
const charSize = unicodeMode ? charSizeAt(text, from + 1) : 1;
return from + charSize + 1;
}
}
}
default: {
const charSize = unicodeMode ? charSizeAt(text, from) : 1;
return from + charSize;
}
}
}
function readFrom(text, from, unicodeMode, mode) {
const to = blockEndFrom(text, from, unicodeMode, mode);
return text.substring(from, to);
}

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SameValueSet = void 0;
const globals_1 = require("../../../utils/globals");
const safeObjectIs = Object.is;
class SameValueSet {
constructor(selector) {
this.selector = selector;
this.selectedItemsExceptMinusZero = new globals_1.Set();
this.data = [];
this.hasMinusZero = false;
}
tryAdd(value) {
const selected = this.selector(value);
if (safeObjectIs(selected, -0)) {
if (this.hasMinusZero) {
return false;
}
(0, globals_1.safePush)(this.data, value);
this.hasMinusZero = true;
return true;
}
const sizeBefore = this.selectedItemsExceptMinusZero.size;
(0, globals_1.safeAdd)(this.selectedItemsExceptMinusZero, selected);
if (sizeBefore !== this.selectedItemsExceptMinusZero.size) {
(0, globals_1.safePush)(this.data, value);
return true;
}
return false;
}
size() {
return this.data.length;
}
getData() {
return this.data;
}
}
exports.SameValueSet = SameValueSet;

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SameValueZeroSet = void 0;
const globals_1 = require("../../../utils/globals");
class SameValueZeroSet {
constructor(selector) {
this.selector = selector;
this.selectedItems = new globals_1.Set();
this.data = [];
}
tryAdd(value) {
const selected = this.selector(value);
const sizeBefore = this.selectedItems.size;
(0, globals_1.safeAdd)(this.selectedItems, selected);
if (sizeBefore !== this.selectedItems.size) {
(0, globals_1.safePush)(this.data, value);
return true;
}
return false;
}
size() {
return this.data.length;
}
getData() {
return this.data;
}
}
exports.SameValueZeroSet = SameValueZeroSet;

View File

@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addMissingDotStar = addMissingDotStar;
const stringify_1 = require("../../../utils/stringify");
function raiseUnsupportedASTNode(astNode) {
return new Error(`Unsupported AST node! Received: ${(0, stringify_1.stringify)(astNode)}`);
}
function addMissingDotStarTraversalAddMissing(astNode, isFirst, isLast) {
if (!isFirst && !isLast) {
return astNode;
}
const traversalResults = { hasStart: false, hasEnd: false };
const revampedNode = addMissingDotStarTraversal(astNode, isFirst, isLast, traversalResults);
const missingStart = isFirst && !traversalResults.hasStart;
const missingEnd = isLast && !traversalResults.hasEnd;
if (!missingStart && !missingEnd) {
return revampedNode;
}
const expressions = [];
if (missingStart) {
expressions.push({ type: 'Assertion', kind: '^' });
expressions.push({
type: 'Repetition',
quantifier: { type: 'Quantifier', kind: '*', greedy: true },
expression: { type: 'Char', kind: 'meta', symbol: '.', value: '.', codePoint: Number.NaN },
});
}
expressions.push(revampedNode);
if (missingEnd) {
expressions.push({
type: 'Repetition',
quantifier: { type: 'Quantifier', kind: '*', greedy: true },
expression: { type: 'Char', kind: 'meta', symbol: '.', value: '.', codePoint: Number.NaN },
});
expressions.push({ type: 'Assertion', kind: '$' });
}
return { type: 'Group', capturing: false, expression: { type: 'Alternative', expressions } };
}
function addMissingDotStarTraversal(astNode, isFirst, isLast, traversalResults) {
switch (astNode.type) {
case 'Char':
return astNode;
case 'Repetition':
return astNode;
case 'Quantifier':
throw new Error(`Wrongly defined AST tree, Quantifier nodes not supposed to be scanned!`);
case 'Alternative':
traversalResults.hasStart = true;
traversalResults.hasEnd = true;
return Object.assign(Object.assign({}, astNode), { expressions: astNode.expressions.map((node, index) => addMissingDotStarTraversalAddMissing(node, isFirst && index === 0, isLast && index === astNode.expressions.length - 1)) });
case 'CharacterClass':
return astNode;
case 'ClassRange':
return astNode;
case 'Group': {
return Object.assign(Object.assign({}, astNode), { expression: addMissingDotStarTraversal(astNode.expression, isFirst, isLast, traversalResults) });
}
case 'Disjunction': {
traversalResults.hasStart = true;
traversalResults.hasEnd = true;
return Object.assign(Object.assign({}, astNode), { left: astNode.left !== null ? addMissingDotStarTraversalAddMissing(astNode.left, isFirst, isLast) : null, right: astNode.right !== null ? addMissingDotStarTraversalAddMissing(astNode.right, isFirst, isLast) : null });
}
case 'Assertion': {
if (astNode.kind === '^' || astNode.kind === 'Lookahead') {
traversalResults.hasStart = true;
return astNode;
}
else if (astNode.kind === '$' || astNode.kind === 'Lookbehind') {
traversalResults.hasEnd = true;
return astNode;
}
else {
throw new Error(`Assertions of kind ${astNode.kind} not implemented yet!`);
}
}
case 'Backreference':
return astNode;
default:
throw raiseUnsupportedASTNode(astNode);
}
}
function addMissingDotStar(astNode) {
return addMissingDotStarTraversalAddMissing(astNode, true, true);
}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.shrinkBigInt = shrinkBigInt;
const Stream_1 = require("../../../stream/Stream");
const Value_1 = require("../../../check/arbitrary/definition/Value");
const globals_1 = require("../../../utils/globals");
function halveBigInt(n) {
return n / (0, globals_1.BigInt)(2);
}
function shrinkBigInt(current, target, tryTargetAsap) {
const realGap = current - target;
function* shrinkDecr() {
let previous = tryTargetAsap ? undefined : target;
const gap = tryTargetAsap ? realGap : halveBigInt(realGap);
for (let toremove = gap; toremove > 0; toremove = halveBigInt(toremove)) {
const next = current - toremove;
yield new Value_1.Value(next, previous);
previous = next;
}
}
function* shrinkIncr() {
let previous = tryTargetAsap ? undefined : target;
const gap = tryTargetAsap ? realGap : halveBigInt(realGap);
for (let toremove = gap; toremove < 0; toremove = halveBigInt(toremove)) {
const next = current - toremove;
yield new Value_1.Value(next, previous);
previous = next;
}
}
return realGap > 0 ? (0, Stream_1.stream)(shrinkDecr()) : (0, Stream_1.stream)(shrinkIncr());
}

View File

@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.shrinkInteger = shrinkInteger;
const Value_1 = require("../../../check/arbitrary/definition/Value");
const Stream_1 = require("../../../stream/Stream");
const safeMathCeil = Math.ceil;
const safeMathFloor = Math.floor;
function halvePosInteger(n) {
return safeMathFloor(n / 2);
}
function halveNegInteger(n) {
return safeMathCeil(n / 2);
}
function shrinkInteger(current, target, tryTargetAsap) {
const realGap = current - target;
function* shrinkDecr() {
let previous = tryTargetAsap ? undefined : target;
const gap = tryTargetAsap ? realGap : halvePosInteger(realGap);
for (let toremove = gap; toremove > 0; toremove = halvePosInteger(toremove)) {
const next = toremove === realGap ? target : current - toremove;
yield new Value_1.Value(next, previous);
previous = next;
}
}
function* shrinkIncr() {
let previous = tryTargetAsap ? undefined : target;
const gap = tryTargetAsap ? realGap : halveNegInteger(realGap);
for (let toremove = gap; toremove < 0; toremove = halveNegInteger(toremove)) {
const next = toremove === realGap ? target : current - toremove;
yield new Value_1.Value(next, previous);
previous = next;
}
}
return realGap > 0 ? (0, Stream_1.stream)(shrinkDecr()) : (0, Stream_1.stream)(shrinkIncr());
}

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSlicesForStringLegacy = createSlicesForStringLegacy;
exports.createSlicesForString = createSlicesForString;
const globals_1 = require("../../../utils/globals");
const PatternsToString_1 = require("../mappers/PatternsToString");
const MaxLengthFromMinLength_1 = require("./MaxLengthFromMinLength");
const TokenizeString_1 = require("./TokenizeString");
const dangerousStrings = [
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
'__proto__',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'toLocaleString',
'toString',
'valueOf',
'apply',
'arguments',
'bind',
'call',
'caller',
'length',
'name',
'prototype',
'key',
'ref',
];
function computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter) {
let candidate;
try {
candidate = stringSplitter(dangerous);
}
catch (err) {
return undefined;
}
for (const entry of candidate) {
if (!charArbitrary.canShrinkWithoutContext(entry)) {
return undefined;
}
}
return candidate;
}
function createSlicesForStringLegacy(charArbitrary, stringSplitter) {
const slicesForString = [];
for (const dangerous of dangerousStrings) {
const candidate = computeCandidateStringLegacy(dangerous, charArbitrary, stringSplitter);
if (candidate !== undefined) {
(0, globals_1.safePush)(slicesForString, candidate);
}
}
return slicesForString;
}
const slicesPerArbitrary = new WeakMap();
function createSlicesForStringNoConstraints(charArbitrary) {
const slicesForString = [];
for (const dangerous of dangerousStrings) {
const candidate = (0, TokenizeString_1.tokenizeString)(charArbitrary, dangerous, 0, MaxLengthFromMinLength_1.MaxLengthUpperBound);
if (candidate !== undefined) {
(0, globals_1.safePush)(slicesForString, candidate);
}
}
return slicesForString;
}
function createSlicesForString(charArbitrary, constraints) {
let slices = (0, globals_1.safeGet)(slicesPerArbitrary, charArbitrary);
if (slices === undefined) {
slices = createSlicesForStringNoConstraints(charArbitrary);
(0, globals_1.safeSet)(slicesPerArbitrary, charArbitrary, slices);
}
const slicesForConstraints = [];
for (const slice of slices) {
if ((0, PatternsToString_1.patternsToStringUnmapperIsValidLength)(slice, constraints)) {
(0, globals_1.safePush)(slicesForConstraints, slice);
}
}
return slicesForConstraints;
}

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StrictlyEqualSet = void 0;
const globals_1 = require("../../../utils/globals");
const safeNumberIsNaN = Number.isNaN;
class StrictlyEqualSet {
constructor(selector) {
this.selector = selector;
this.selectedItemsExceptNaN = new globals_1.Set();
this.data = [];
}
tryAdd(value) {
const selected = this.selector(value);
if (safeNumberIsNaN(selected)) {
(0, globals_1.safePush)(this.data, value);
return true;
}
const sizeBefore = this.selectedItemsExceptNaN.size;
(0, globals_1.safeAdd)(this.selectedItemsExceptNaN, selected);
if (sizeBefore !== this.selectedItemsExceptNaN.size) {
(0, globals_1.safePush)(this.data, value);
return true;
}
return false;
}
size() {
return this.data.length;
}
getData() {
return this.data;
}
}
exports.StrictlyEqualSet = StrictlyEqualSet;

View File

@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeForTemplateString = escapeForTemplateString;
exports.escapeForMultilineComments = escapeForMultilineComments;
function escapeForTemplateString(originalText) {
return originalText.replace(/([$`\\])/g, '\\$1').replace(/\r/g, '\\r');
}
function escapeForMultilineComments(originalText) {
return originalText.replace(/\*\//g, '*\\/');
}

View File

@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.countToggledBits = countToggledBits;
exports.computeNextFlags = computeNextFlags;
exports.computeTogglePositions = computeTogglePositions;
exports.computeFlagsFromChars = computeFlagsFromChars;
exports.applyFlagsOnChars = applyFlagsOnChars;
const globals_1 = require("../../../utils/globals");
function countToggledBits(n) {
let count = 0;
while (n > (0, globals_1.BigInt)(0)) {
if (n & (0, globals_1.BigInt)(1))
++count;
n >>= (0, globals_1.BigInt)(1);
}
return count;
}
function computeNextFlags(flags, nextSize) {
const allowedMask = ((0, globals_1.BigInt)(1) << (0, globals_1.BigInt)(nextSize)) - (0, globals_1.BigInt)(1);
const preservedFlags = flags & allowedMask;
let numMissingFlags = countToggledBits(flags - preservedFlags);
let nFlags = preservedFlags;
for (let mask = (0, globals_1.BigInt)(1); mask <= allowedMask && numMissingFlags !== 0; mask <<= (0, globals_1.BigInt)(1)) {
if (!(nFlags & mask)) {
nFlags |= mask;
--numMissingFlags;
}
}
return nFlags;
}
function computeTogglePositions(chars, toggleCase) {
const positions = [];
for (let idx = chars.length - 1; idx !== -1; --idx) {
if (toggleCase(chars[idx]) !== chars[idx])
(0, globals_1.safePush)(positions, idx);
}
return positions;
}
function computeFlagsFromChars(untoggledChars, toggledChars, togglePositions) {
let flags = (0, globals_1.BigInt)(0);
for (let idx = 0, mask = (0, globals_1.BigInt)(1); idx !== togglePositions.length; ++idx, mask <<= (0, globals_1.BigInt)(1)) {
if (untoggledChars[togglePositions[idx]] !== toggledChars[togglePositions[idx]]) {
flags |= mask;
}
}
return flags;
}
function applyFlagsOnChars(chars, flags, togglePositions, toggleCase) {
for (let idx = 0, mask = (0, globals_1.BigInt)(1); idx !== togglePositions.length; ++idx, mask <<= (0, globals_1.BigInt)(1)) {
if (flags & mask)
chars[togglePositions[idx]] = toggleCase(chars[togglePositions[idx]]);
}
}

View File

@@ -0,0 +1,323 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokenizeRegex = tokenizeRegex;
const globals_1 = require("../../../utils/globals");
const ReadRegex_1 = require("./ReadRegex");
const safeStringFromCodePoint = String.fromCodePoint;
function safePop(tokens) {
const previous = tokens.pop();
if (previous === undefined) {
throw new Error('Unable to extract token preceeding the currently parsed one');
}
return previous;
}
function isDigit(char) {
return char >= '0' && char <= '9';
}
function simpleChar(char, escaped) {
return {
type: 'Char',
kind: 'simple',
symbol: char,
value: char,
codePoint: char.codePointAt(0) || -1,
escaped,
};
}
function metaEscapedChar(block, symbol) {
return {
type: 'Char',
kind: 'meta',
symbol,
value: block,
codePoint: symbol.codePointAt(0) || -1,
};
}
function toSingleToken(tokens, allowEmpty) {
if (tokens.length > 1) {
return {
type: 'Alternative',
expressions: tokens,
};
}
if (!allowEmpty && tokens.length === 0) {
throw new Error(`Unsupported no token`);
}
return tokens[0];
}
function blockToCharToken(block) {
if (block[0] === '\\') {
const next = block[1];
switch (next) {
case 'x': {
const allDigits = block.substring(2);
const codePoint = Number.parseInt(allDigits, 16);
const symbol = safeStringFromCodePoint(codePoint);
return { type: 'Char', kind: 'hex', symbol, value: block, codePoint };
}
case 'u': {
if (block === '\\u') {
return simpleChar('u', true);
}
const allDigits = block[2] === '{' ? block.substring(3, block.length - 1) : block.substring(2);
const codePoint = Number.parseInt(allDigits, 16);
const symbol = safeStringFromCodePoint(codePoint);
return { type: 'Char', kind: 'unicode', symbol, value: block, codePoint };
}
case '0': {
return metaEscapedChar(block, '\0');
}
case 'n': {
return metaEscapedChar(block, '\n');
}
case 'f': {
return metaEscapedChar(block, '\f');
}
case 'r': {
return metaEscapedChar(block, '\r');
}
case 't': {
return metaEscapedChar(block, '\t');
}
case 'v': {
return metaEscapedChar(block, '\v');
}
case 'w':
case 'W':
case 'd':
case 'D':
case 's':
case 'S':
case 'b':
case 'B': {
return { type: 'Char', kind: 'meta', symbol: undefined, value: block, codePoint: Number.NaN };
}
default: {
if (isDigit(next)) {
const allDigits = block.substring(1);
const codePoint = Number(allDigits);
const symbol = safeStringFromCodePoint(codePoint);
return { type: 'Char', kind: 'decimal', symbol, value: block, codePoint };
}
if (block.length > 2 && (next === 'p' || next === 'P')) {
throw new Error(`UnicodeProperty not implemented yet!`);
}
const char = block.substring(1);
return simpleChar(char, true);
}
}
}
return simpleChar(block);
}
function pushTokens(tokens, regexSource, unicodeMode, groups) {
let disjunctions = null;
for (let index = 0, block = (0, ReadRegex_1.readFrom)(regexSource, index, unicodeMode, ReadRegex_1.TokenizerBlockMode.Full); index !== regexSource.length; index += block.length, block = (0, ReadRegex_1.readFrom)(regexSource, index, unicodeMode, ReadRegex_1.TokenizerBlockMode.Full)) {
const firstInBlock = block[0];
switch (firstInBlock) {
case '|': {
if (disjunctions === null) {
disjunctions = [];
}
disjunctions.push(toSingleToken(tokens.splice(0), true) || null);
break;
}
case '.': {
tokens.push({ type: 'Char', kind: 'meta', symbol: block, value: block, codePoint: Number.NaN });
break;
}
case '*':
case '+': {
const previous = safePop(tokens);
tokens.push({
type: 'Repetition',
expression: previous,
quantifier: { type: 'Quantifier', kind: firstInBlock, greedy: true },
});
break;
}
case '?': {
const previous = safePop(tokens);
if (previous.type === 'Repetition') {
previous.quantifier.greedy = false;
tokens.push(previous);
}
else {
tokens.push({
type: 'Repetition',
expression: previous,
quantifier: { type: 'Quantifier', kind: firstInBlock, greedy: true },
});
}
break;
}
case '{': {
if (block === '{') {
tokens.push(simpleChar(block));
break;
}
const previous = safePop(tokens);
const quantifierText = block.substring(1, block.length - 1);
const quantifierTokens = quantifierText.split(',');
const from = Number(quantifierTokens[0]);
const to = quantifierTokens.length === 1
? from
: quantifierTokens[1].length !== 0
? Number(quantifierTokens[1])
: undefined;
tokens.push({
type: 'Repetition',
expression: previous,
quantifier: { type: 'Quantifier', kind: 'Range', greedy: true, from, to },
});
break;
}
case '[': {
const blockContent = block.substring(1, block.length - 1);
const subTokens = [];
let negative = undefined;
let previousWasSimpleDash = false;
for (let subIndex = 0, subBlock = (0, ReadRegex_1.readFrom)(blockContent, subIndex, unicodeMode, ReadRegex_1.TokenizerBlockMode.Character); subIndex !== blockContent.length; subIndex += subBlock.length,
subBlock = (0, ReadRegex_1.readFrom)(blockContent, subIndex, unicodeMode, ReadRegex_1.TokenizerBlockMode.Character)) {
if (subIndex === 0 && subBlock === '^') {
negative = true;
continue;
}
const newToken = blockToCharToken(subBlock);
if (subBlock === '-') {
subTokens.push(newToken);
previousWasSimpleDash = true;
}
else {
const operand1Token = subTokens.length >= 2 ? subTokens[subTokens.length - 2] : undefined;
if (previousWasSimpleDash && operand1Token !== undefined && operand1Token.type === 'Char') {
subTokens.pop();
subTokens.pop();
subTokens.push({ type: 'ClassRange', from: operand1Token, to: newToken });
}
else {
subTokens.push(newToken);
}
previousWasSimpleDash = false;
}
}
tokens.push({ type: 'CharacterClass', expressions: subTokens, negative });
break;
}
case '(': {
const blockContent = block.substring(1, block.length - 1);
const subTokens = [];
if (blockContent[0] === '?') {
if (blockContent[1] === ':') {
pushTokens(subTokens, blockContent.substring(2), unicodeMode, groups);
tokens.push({
type: 'Group',
capturing: false,
expression: toSingleToken(subTokens),
});
}
else if (blockContent[1] === '=' || blockContent[1] === '!') {
pushTokens(subTokens, blockContent.substring(2), unicodeMode, groups);
tokens.push({
type: 'Assertion',
kind: 'Lookahead',
negative: blockContent[1] === '!' ? true : undefined,
assertion: toSingleToken(subTokens),
});
}
else if (blockContent[1] === '<' && (blockContent[2] === '=' || blockContent[2] === '!')) {
pushTokens(subTokens, blockContent.substring(3), unicodeMode, groups);
tokens.push({
type: 'Assertion',
kind: 'Lookbehind',
negative: blockContent[2] === '!' ? true : undefined,
assertion: toSingleToken(subTokens),
});
}
else {
const chunks = blockContent.split('>');
if (chunks.length < 2 || chunks[0][1] !== '<') {
throw new Error(`Unsupported regex content found at ${JSON.stringify(block)}`);
}
const groupIndex = ++groups.lastIndex;
const nameRaw = chunks[0].substring(2);
groups.named.set(nameRaw, groupIndex);
pushTokens(subTokens, chunks.slice(1).join('>'), unicodeMode, groups);
tokens.push({
type: 'Group',
capturing: true,
nameRaw,
name: nameRaw,
number: groupIndex,
expression: toSingleToken(subTokens),
});
}
}
else {
const groupIndex = ++groups.lastIndex;
pushTokens(subTokens, blockContent, unicodeMode, groups);
tokens.push({
type: 'Group',
capturing: true,
number: groupIndex,
expression: toSingleToken(subTokens),
});
}
break;
}
default: {
if (block === '^') {
tokens.push({ type: 'Assertion', kind: block });
}
else if (block === '$') {
tokens.push({ type: 'Assertion', kind: block });
}
else if (block[0] === '\\' && isDigit(block[1])) {
const reference = Number(block.substring(1));
if (unicodeMode || reference <= groups.lastIndex) {
tokens.push({ type: 'Backreference', kind: 'number', number: reference, reference });
}
else {
tokens.push(blockToCharToken(block));
}
}
else if (block[0] === '\\' && block[1] === 'k' && block.length !== 2) {
const referenceRaw = block.substring(3, block.length - 1);
tokens.push({
type: 'Backreference',
kind: 'name',
number: groups.named.get(referenceRaw) || 0,
referenceRaw,
reference: referenceRaw,
});
}
else {
tokens.push(blockToCharToken(block));
}
break;
}
}
}
if (disjunctions !== null) {
disjunctions.push(toSingleToken(tokens.splice(0), true) || null);
let currentDisjunction = {
type: 'Disjunction',
left: disjunctions[0],
right: disjunctions[1],
};
for (let index = 2; index < disjunctions.length; ++index) {
currentDisjunction = {
type: 'Disjunction',
left: currentDisjunction,
right: disjunctions[index],
};
}
tokens.push(currentDisjunction);
}
}
function tokenizeRegex(regex) {
const unicodeMode = (0, globals_1.safeIndexOf)([...regex.flags], 'u') !== -1;
const regexSource = regex.source;
const tokens = [];
pushTokens(tokens, regexSource, unicodeMode, { lastIndex: 0, named: new Map() });
return toSingleToken(tokens);
}

View File

@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tokenizeString = tokenizeString;
const globals_1 = require("../../../utils/globals");
function tokenizeString(patternsArb, value, minLength, maxLength) {
if (value.length === 0) {
if (minLength > 0) {
return undefined;
}
return [];
}
if (maxLength <= 0) {
return undefined;
}
const stack = [{ endIndexChunks: 0, nextStartIndex: 1, chunks: [] }];
while (stack.length > 0) {
const last = (0, globals_1.safePop)(stack);
for (let index = last.nextStartIndex; index <= value.length; ++index) {
const chunk = (0, globals_1.safeSubstring)(value, last.endIndexChunks, index);
if (patternsArb.canShrinkWithoutContext(chunk)) {
const newChunks = [...last.chunks, chunk];
if (index === value.length) {
if (newChunks.length < minLength) {
break;
}
return newChunks;
}
(0, globals_1.safePush)(stack, { endIndexChunks: last.endIndexChunks, nextStartIndex: index + 1, chunks: last.chunks });
if (newChunks.length < maxLength) {
(0, globals_1.safePush)(stack, { endIndexChunks: index, nextStartIndex: index + 1, chunks: newChunks });
}
break;
}
}
}
return undefined;
}

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.zipIterableIterators = zipIterableIterators;
function initZippedValues(its) {
const vs = [];
for (let index = 0; index !== its.length; ++index) {
vs.push(its[index].next());
}
return vs;
}
function nextZippedValues(its, vs) {
for (let index = 0; index !== its.length; ++index) {
vs[index] = its[index].next();
}
}
function isDoneZippedValues(vs) {
for (let index = 0; index !== vs.length; ++index) {
if (vs[index].done) {
return true;
}
}
return false;
}
function* zipIterableIterators(...its) {
const vs = initZippedValues(its);
while (!isDoneZippedValues(vs)) {
yield vs.map((v) => v.value);
nextZippedValues(its, vs);
}
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoopSlicedGenerator = void 0;
class NoopSlicedGenerator {
constructor(arb, mrng, biasFactor) {
this.arb = arb;
this.mrng = mrng;
this.biasFactor = biasFactor;
}
attemptExact() {
return;
}
next() {
return this.arb.generate(this.mrng, this.biasFactor);
}
}
exports.NoopSlicedGenerator = NoopSlicedGenerator;

View File

@@ -0,0 +1,196 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchedulerImplem = void 0;
const TextEscaper_1 = require("../helpers/TextEscaper");
const symbols_1 = require("../../../check/symbols");
const stringify_1 = require("../../../utils/stringify");
const defaultSchedulerAct = (f) => f();
class SchedulerImplem {
constructor(act, taskSelector) {
this.act = act;
this.taskSelector = taskSelector;
this.lastTaskId = 0;
this.sourceTaskSelector = taskSelector.clone();
this.scheduledTasks = [];
this.triggeredTasks = [];
this.scheduledWatchers = [];
}
static buildLog(reportItem) {
return `[task\${${reportItem.taskId}}] ${reportItem.label.length !== 0 ? `${reportItem.schedulingType}::${reportItem.label}` : reportItem.schedulingType} ${reportItem.status}${reportItem.outputValue !== undefined ? ` with value ${(0, TextEscaper_1.escapeForTemplateString)(reportItem.outputValue)}` : ''}`;
}
log(schedulingType, taskId, label, metadata, status, data) {
this.triggeredTasks.push({
status,
schedulingType,
taskId,
label,
metadata,
outputValue: data !== undefined ? (0, stringify_1.stringify)(data) : undefined,
});
}
scheduleInternal(schedulingType, label, task, metadata, customAct, thenTaskToBeAwaited) {
let trigger = null;
const taskId = ++this.lastTaskId;
const scheduledPromise = new Promise((resolve, reject) => {
trigger = () => {
(thenTaskToBeAwaited ? task.then(() => thenTaskToBeAwaited()) : task).then((data) => {
this.log(schedulingType, taskId, label, metadata, 'resolved', data);
return resolve(data);
}, (err) => {
this.log(schedulingType, taskId, label, metadata, 'rejected', err);
return reject(err);
});
};
});
this.scheduledTasks.push({
original: task,
scheduled: scheduledPromise,
trigger: trigger,
schedulingType,
taskId,
label,
metadata,
customAct,
});
if (this.scheduledWatchers.length !== 0) {
this.scheduledWatchers[0]();
}
return scheduledPromise;
}
schedule(task, label, metadata, customAct) {
return this.scheduleInternal('promise', label || '', task, metadata, customAct || defaultSchedulerAct);
}
scheduleFunction(asyncFunction, customAct) {
return (...args) => this.scheduleInternal('function', `${asyncFunction.name}(${args.map(stringify_1.stringify).join(',')})`, asyncFunction(...args), undefined, customAct || defaultSchedulerAct);
}
scheduleSequence(sequenceBuilders, customAct) {
const status = { done: false, faulty: false };
const dummyResolvedPromise = { then: (f) => f() };
let resolveSequenceTask = () => { };
const sequenceTask = new Promise((resolve) => (resolveSequenceTask = resolve));
sequenceBuilders
.reduce((previouslyScheduled, item) => {
const [builder, label, metadata] = typeof item === 'function' ? [item, item.name, undefined] : [item.builder, item.label, item.metadata];
return previouslyScheduled.then(() => {
const scheduled = this.scheduleInternal('sequence', label, dummyResolvedPromise, metadata, customAct || defaultSchedulerAct, () => builder());
scheduled.catch(() => {
status.faulty = true;
resolveSequenceTask();
});
return scheduled;
});
}, dummyResolvedPromise)
.then(() => {
status.done = true;
resolveSequenceTask();
}, () => {
});
return Object.assign(status, {
task: Promise.resolve(sequenceTask).then(() => {
return { done: status.done, faulty: status.faulty };
}),
});
}
count() {
return this.scheduledTasks.length;
}
internalWaitOne() {
if (this.scheduledTasks.length === 0) {
throw new Error('No task scheduled');
}
const taskIndex = this.taskSelector.nextTaskIndex(this.scheduledTasks);
const [scheduledTask] = this.scheduledTasks.splice(taskIndex, 1);
return scheduledTask.customAct(async () => {
scheduledTask.trigger();
try {
await scheduledTask.scheduled;
}
catch (_err) {
}
});
}
async waitOne(customAct) {
const waitAct = customAct || defaultSchedulerAct;
await this.act(() => waitAct(async () => await this.internalWaitOne()));
}
async waitAll(customAct) {
while (this.scheduledTasks.length > 0) {
await this.waitOne(customAct);
}
}
async waitFor(unscheduledTask, customAct) {
let taskResolved = false;
let awaiterPromise = null;
const awaiter = async () => {
while (!taskResolved && this.scheduledTasks.length > 0) {
await this.waitOne(customAct);
}
awaiterPromise = null;
};
const handleNotified = () => {
if (awaiterPromise !== null) {
return;
}
awaiterPromise = Promise.resolve().then(awaiter);
};
const clearAndReplaceWatcher = () => {
const handleNotifiedIndex = this.scheduledWatchers.indexOf(handleNotified);
if (handleNotifiedIndex !== -1) {
this.scheduledWatchers.splice(handleNotifiedIndex, 1);
}
if (handleNotifiedIndex === 0 && this.scheduledWatchers.length !== 0) {
this.scheduledWatchers[0]();
}
};
const rewrappedTask = unscheduledTask.then((ret) => {
taskResolved = true;
if (awaiterPromise === null) {
clearAndReplaceWatcher();
return ret;
}
return awaiterPromise.then(() => {
clearAndReplaceWatcher();
return ret;
});
}, (err) => {
taskResolved = true;
if (awaiterPromise === null) {
clearAndReplaceWatcher();
throw err;
}
return awaiterPromise.then(() => {
clearAndReplaceWatcher();
throw err;
});
});
if (this.scheduledTasks.length > 0 && this.scheduledWatchers.length === 0) {
handleNotified();
}
this.scheduledWatchers.push(handleNotified);
return rewrappedTask;
}
report() {
return [
...this.triggeredTasks,
...this.scheduledTasks.map((t) => ({
status: 'pending',
schedulingType: t.schedulingType,
taskId: t.taskId,
label: t.label,
metadata: t.metadata,
})),
];
}
toString() {
return ('schedulerFor()`\n' +
this.report()
.map(SchedulerImplem.buildLog)
.map((log) => `-> ${log}`)
.join('\n') +
'`');
}
[symbols_1.cloneMethod]() {
return new SchedulerImplem(this.act, this.sourceTaskSelector);
}
}
exports.SchedulerImplem = SchedulerImplem;

View File

@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlicedBasedGenerator = void 0;
const Value_1 = require("../../../check/arbitrary/definition/Value");
const globals_1 = require("../../../utils/globals");
const safeMathMin = Math.min;
const safeMathMax = Math.max;
class SlicedBasedGenerator {
constructor(arb, mrng, slices, biasFactor) {
this.arb = arb;
this.mrng = mrng;
this.slices = slices;
this.biasFactor = biasFactor;
this.activeSliceIndex = 0;
this.nextIndexInSlice = 0;
this.lastIndexInSlice = -1;
}
attemptExact(targetLength) {
if (targetLength !== 0 && this.mrng.nextInt(1, this.biasFactor) === 1) {
const eligibleIndices = [];
for (let index = 0; index !== this.slices.length; ++index) {
const slice = this.slices[index];
if (slice.length === targetLength) {
(0, globals_1.safePush)(eligibleIndices, index);
}
}
if (eligibleIndices.length === 0) {
return;
}
this.activeSliceIndex = eligibleIndices[this.mrng.nextInt(0, eligibleIndices.length - 1)];
this.nextIndexInSlice = 0;
this.lastIndexInSlice = targetLength - 1;
}
}
next() {
if (this.nextIndexInSlice <= this.lastIndexInSlice) {
return new Value_1.Value(this.slices[this.activeSliceIndex][this.nextIndexInSlice++], undefined);
}
if (this.mrng.nextInt(1, this.biasFactor) !== 1) {
return this.arb.generate(this.mrng, this.biasFactor);
}
this.activeSliceIndex = this.mrng.nextInt(0, this.slices.length - 1);
const slice = this.slices[this.activeSliceIndex];
if (this.mrng.nextInt(1, this.biasFactor) !== 1) {
this.nextIndexInSlice = 1;
this.lastIndexInSlice = slice.length - 1;
return new Value_1.Value(slice[0], undefined);
}
const rangeBoundaryA = this.mrng.nextInt(0, slice.length - 1);
const rangeBoundaryB = this.mrng.nextInt(0, slice.length - 1);
this.nextIndexInSlice = safeMathMin(rangeBoundaryA, rangeBoundaryB);
this.lastIndexInSlice = safeMathMax(rangeBoundaryA, rangeBoundaryB);
return new Value_1.Value(slice[this.nextIndexInSlice++], undefined);
}
}
exports.SlicedBasedGenerator = SlicedBasedGenerator;

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayToMapMapper = arrayToMapMapper;
exports.arrayToMapUnmapper = arrayToMapUnmapper;
function arrayToMapMapper(data) {
return new Map(data);
}
function arrayToMapUnmapper(value) {
if (typeof value !== 'object' || value === null) {
throw new Error('Incompatible instance received: should be a non-null object');
}
if (!('constructor' in value) || value.constructor !== Map) {
throw new Error('Incompatible instance received: should be of exact type Map');
}
return Array.from(value);
}

View File

@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.arrayToSetMapper = arrayToSetMapper;
exports.arrayToSetUnmapper = arrayToSetUnmapper;
function arrayToSetMapper(data) {
return new Set(data);
}
function arrayToSetUnmapper(value) {
if (typeof value !== 'object' || value === null) {
throw new Error('Incompatible instance received: should be a non-null object');
}
if (!('constructor' in value) || value.constructor !== Set) {
throw new Error('Incompatible instance received: should be of exact type Set');
}
return Array.from(value);
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.charsToStringMapper = charsToStringMapper;
exports.charsToStringUnmapper = charsToStringUnmapper;
const globals_1 = require("../../../utils/globals");
function charsToStringMapper(tab) {
return (0, globals_1.safeJoin)(tab, '');
}
function charsToStringUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Cannot unmap the passed value');
}
return (0, globals_1.safeSplit)(value, '');
}

View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.codePointsToStringMapper = codePointsToStringMapper;
exports.codePointsToStringUnmapper = codePointsToStringUnmapper;
const globals_1 = require("../../../utils/globals");
function codePointsToStringMapper(tab) {
return (0, globals_1.safeJoin)(tab, '');
}
function codePointsToStringUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Cannot unmap the passed value');
}
return [...value];
}

View File

@@ -0,0 +1,85 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fullySpecifiedMapper = fullySpecifiedMapper;
exports.fullySpecifiedUnmapper = fullySpecifiedUnmapper;
exports.onlyTrailingMapper = onlyTrailingMapper;
exports.onlyTrailingUnmapper = onlyTrailingUnmapper;
exports.multiTrailingMapper = multiTrailingMapper;
exports.multiTrailingUnmapper = multiTrailingUnmapper;
exports.multiTrailingMapperOne = multiTrailingMapperOne;
exports.multiTrailingUnmapperOne = multiTrailingUnmapperOne;
exports.singleTrailingMapper = singleTrailingMapper;
exports.singleTrailingUnmapper = singleTrailingUnmapper;
exports.noTrailingMapper = noTrailingMapper;
exports.noTrailingUnmapper = noTrailingUnmapper;
const globals_1 = require("../../../utils/globals");
function readBh(value) {
if (value.length === 0)
return [];
else
return (0, globals_1.safeSplit)(value, ':');
}
function extractEhAndL(value) {
const valueSplits = (0, globals_1.safeSplit)(value, ':');
if (valueSplits.length >= 2 && valueSplits[valueSplits.length - 1].length <= 4) {
return [
(0, globals_1.safeSlice)(valueSplits, 0, valueSplits.length - 2),
`${valueSplits[valueSplits.length - 2]}:${valueSplits[valueSplits.length - 1]}`,
];
}
return [(0, globals_1.safeSlice)(valueSplits, 0, valueSplits.length - 1), valueSplits[valueSplits.length - 1]];
}
function fullySpecifiedMapper(data) {
return `${(0, globals_1.safeJoin)(data[0], ':')}:${data[1]}`;
}
function fullySpecifiedUnmapper(value) {
if (typeof value !== 'string')
throw new Error('Invalid type');
return extractEhAndL(value);
}
function onlyTrailingMapper(data) {
return `::${(0, globals_1.safeJoin)(data[0], ':')}:${data[1]}`;
}
function onlyTrailingUnmapper(value) {
if (typeof value !== 'string')
throw new Error('Invalid type');
if (!(0, globals_1.safeStartsWith)(value, '::'))
throw new Error('Invalid value');
return extractEhAndL((0, globals_1.safeSubstring)(value, 2));
}
function multiTrailingMapper(data) {
return `${(0, globals_1.safeJoin)(data[0], ':')}::${(0, globals_1.safeJoin)(data[1], ':')}:${data[2]}`;
}
function multiTrailingUnmapper(value) {
if (typeof value !== 'string')
throw new Error('Invalid type');
const [bhString, trailingString] = (0, globals_1.safeSplit)(value, '::', 2);
const [eh, l] = extractEhAndL(trailingString);
return [readBh(bhString), eh, l];
}
function multiTrailingMapperOne(data) {
return multiTrailingMapper([data[0], [data[1]], data[2]]);
}
function multiTrailingUnmapperOne(value) {
const out = multiTrailingUnmapper(value);
return [out[0], (0, globals_1.safeJoin)(out[1], ':'), out[2]];
}
function singleTrailingMapper(data) {
return `${(0, globals_1.safeJoin)(data[0], ':')}::${data[1]}`;
}
function singleTrailingUnmapper(value) {
if (typeof value !== 'string')
throw new Error('Invalid type');
const [bhString, trailing] = (0, globals_1.safeSplit)(value, '::', 2);
return [readBh(bhString), trailing];
}
function noTrailingMapper(data) {
return `${(0, globals_1.safeJoin)(data[0], ':')}::`;
}
function noTrailingUnmapper(value) {
if (typeof value !== 'string')
throw new Error('Invalid type');
if (!(0, globals_1.safeEndsWith)(value, '::'))
throw new Error('Invalid value');
return [readBh((0, globals_1.safeSubstring)(value, 0, value.length - 2))];
}

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.indexToCharStringMapper = void 0;
exports.indexToCharStringUnmapper = indexToCharStringUnmapper;
const globals_1 = require("../../../utils/globals");
exports.indexToCharStringMapper = String.fromCodePoint;
function indexToCharStringUnmapper(c) {
if (typeof c !== 'string') {
throw new Error('Cannot unmap non-string');
}
if (c.length === 0 || c.length > 2) {
throw new Error('Cannot unmap string with more or less than one character');
}
const c1 = (0, globals_1.safeCharCodeAt)(c, 0);
if (c.length === 1) {
return c1;
}
const c2 = (0, globals_1.safeCharCodeAt)(c, 1);
if (c1 < 0xd800 || c1 > 0xdbff || c2 < 0xdc00 || c2 > 0xdfff) {
throw new Error('Cannot unmap invalid surrogate pairs');
}
return c.codePointAt(0);
}

View File

@@ -0,0 +1,71 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.indexToMappedConstantMapperFor = indexToMappedConstantMapperFor;
exports.indexToMappedConstantUnmapperFor = indexToMappedConstantUnmapperFor;
const globals_1 = require("../../../utils/globals");
const safeObjectIs = Object.is;
function buildDichotomyEntries(entries) {
let currentFrom = 0;
const dichotomyEntries = [];
for (const entry of entries) {
const from = currentFrom;
currentFrom = from + entry.num;
const to = currentFrom - 1;
dichotomyEntries.push({ from, to, entry });
}
return dichotomyEntries;
}
function findDichotomyEntry(dichotomyEntries, choiceIndex) {
let min = 0;
let max = dichotomyEntries.length;
while (max - min > 1) {
const mid = ~~((min + max) / 2);
if (choiceIndex < dichotomyEntries[mid].from) {
max = mid;
}
else {
min = mid;
}
}
return dichotomyEntries[min];
}
function indexToMappedConstantMapperFor(entries) {
const dichotomyEntries = buildDichotomyEntries(entries);
return function indexToMappedConstantMapper(choiceIndex) {
const dichotomyEntry = findDichotomyEntry(dichotomyEntries, choiceIndex);
return dichotomyEntry.entry.build(choiceIndex - dichotomyEntry.from);
};
}
function buildReverseMapping(entries) {
const reverseMapping = { mapping: new globals_1.Map(), negativeZeroIndex: undefined };
let choiceIndex = 0;
for (let entryIdx = 0; entryIdx !== entries.length; ++entryIdx) {
const entry = entries[entryIdx];
for (let idxInEntry = 0; idxInEntry !== entry.num; ++idxInEntry) {
const value = entry.build(idxInEntry);
if (value === 0 && 1 / value === globals_1.Number.NEGATIVE_INFINITY) {
reverseMapping.negativeZeroIndex = choiceIndex;
}
else {
(0, globals_1.safeMapSet)(reverseMapping.mapping, value, choiceIndex);
}
++choiceIndex;
}
}
return reverseMapping;
}
function indexToMappedConstantUnmapperFor(entries) {
let reverseMapping = null;
return function indexToMappedConstantUnmapper(value) {
if (reverseMapping === null) {
reverseMapping = buildReverseMapping(entries);
}
const choiceIndex = safeObjectIs(value, -0)
? reverseMapping.negativeZeroIndex
: (0, globals_1.safeMapGet)(reverseMapping.mapping, value);
if (choiceIndex === undefined) {
throw new globals_1.Error('Unknown value encountered cannot be built using this mapToConstant');
}
return choiceIndex;
};
}

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.indexToPrintableIndexMapper = indexToPrintableIndexMapper;
exports.indexToPrintableIndexUnmapper = indexToPrintableIndexUnmapper;
function indexToPrintableIndexMapper(v) {
if (v < 95)
return v + 0x20;
if (v <= 0x7e)
return v - 95;
return v;
}
function indexToPrintableIndexUnmapper(v) {
if (v >= 0x20 && v <= 0x7e)
return v - 0x20;
if (v >= 0 && v <= 0x1f)
return v + 95;
return v;
}

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.keyValuePairsToObjectMapper = keyValuePairsToObjectMapper;
exports.keyValuePairsToObjectUnmapper = keyValuePairsToObjectUnmapper;
const globals_1 = require("../../../utils/globals");
const safeObjectCreate = Object.create;
const safeObjectDefineProperty = Object.defineProperty;
const safeObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
const safeObjectGetPrototypeOf = Object.getPrototypeOf;
const safeObjectGetOwnPropertySymbols = Object.getOwnPropertySymbols;
const safeObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
const safeObjectEntries = Object.entries;
function keyValuePairsToObjectMapper(definition) {
const obj = definition[1] ? safeObjectCreate(null) : {};
for (const keyValue of definition[0]) {
safeObjectDefineProperty(obj, keyValue[0], {
enumerable: true,
configurable: true,
writable: true,
value: keyValue[1],
});
}
return obj;
}
function buildIsValidPropertyNameFilter(obj) {
return function isValidPropertyNameFilter(key) {
const descriptor = safeObjectGetOwnPropertyDescriptor(obj, key);
return (descriptor !== undefined &&
!!descriptor.configurable &&
!!descriptor.enumerable &&
!!descriptor.writable &&
descriptor.get === undefined &&
descriptor.set === undefined);
};
}
function keyValuePairsToObjectUnmapper(value) {
if (typeof value !== 'object' || value === null) {
throw new globals_1.Error('Incompatible instance received: should be a non-null object');
}
const hasNullPrototype = safeObjectGetPrototypeOf(value) === null;
const hasObjectPrototype = 'constructor' in value && value.constructor === Object;
if (!hasNullPrototype && !hasObjectPrototype) {
throw new globals_1.Error('Incompatible instance received: should be of exact type Object');
}
if (safeObjectGetOwnPropertySymbols(value).length > 0) {
throw new globals_1.Error('Incompatible instance received: should contain symbols');
}
if (!(0, globals_1.safeEvery)(safeObjectGetOwnPropertyNames(value), buildIsValidPropertyNameFilter(value))) {
throw new globals_1.Error('Incompatible instance received: should contain only c/e/w properties without get/set');
}
return [safeObjectEntries(value), hasNullPrototype];
}

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.natToStringifiedNatMapper = natToStringifiedNatMapper;
exports.tryParseStringifiedNat = tryParseStringifiedNat;
exports.natToStringifiedNatUnmapper = natToStringifiedNatUnmapper;
const globals_1 = require("../../../utils/globals");
const safeNumberParseInt = Number.parseInt;
function natToStringifiedNatMapper(options) {
const [style, v] = options;
switch (style) {
case 'oct':
return `0${(0, globals_1.safeNumberToString)(v, 8)}`;
case 'hex':
return `0x${(0, globals_1.safeNumberToString)(v, 16)}`;
case 'dec':
default:
return `${v}`;
}
}
function tryParseStringifiedNat(stringValue, radix) {
const parsedNat = safeNumberParseInt(stringValue, radix);
if ((0, globals_1.safeNumberToString)(parsedNat, radix) !== stringValue) {
throw new Error('Invalid value');
}
return parsedNat;
}
function natToStringifiedNatUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Invalid type');
}
if (value.length >= 2 && value[0] === '0') {
if (value[1] === 'x') {
return ['hex', tryParseStringifiedNat((0, globals_1.safeSubstring)(value, 2), 16)];
}
return ['oct', tryParseStringifiedNat((0, globals_1.safeSubstring)(value, 1), 8)];
}
return ['dec', tryParseStringifiedNat(value, 10)];
}

View File

@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.numberToPaddedEightMapper = numberToPaddedEightMapper;
exports.numberToPaddedEightUnmapper = numberToPaddedEightUnmapper;
const globals_1 = require("../../../utils/globals");
function numberToPaddedEightMapper(n) {
return (0, globals_1.safePadStart)((0, globals_1.safeNumberToString)(n, 16), 8, '0');
}
function numberToPaddedEightUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported type');
}
if (value.length !== 8) {
throw new Error('Unsupported value: invalid length');
}
const n = parseInt(value, 16);
if (value !== numberToPaddedEightMapper(n)) {
throw new Error('Unsupported value: invalid content');
}
return n;
}

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.paddedEightsToUuidMapper = paddedEightsToUuidMapper;
exports.paddedEightsToUuidUnmapper = paddedEightsToUuidUnmapper;
const globals_1 = require("../../../utils/globals");
function paddedEightsToUuidMapper(t) {
return `${t[0]}-${(0, globals_1.safeSubstring)(t[1], 4)}-${(0, globals_1.safeSubstring)(t[1], 0, 4)}-${(0, globals_1.safeSubstring)(t[2], 0, 4)}-${(0, globals_1.safeSubstring)(t[2], 4)}${t[3]}`;
}
const UuidRegex = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/;
function paddedEightsToUuidUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported type');
}
const m = UuidRegex.exec(value);
if (m === null) {
throw new Error('Unsupported type');
}
return [m[1], m[3] + m[2], m[4] + (0, globals_1.safeSubstring)(m[5], 0, 4), (0, globals_1.safeSubstring)(m[5], 4)];
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.partsToUrlMapper = partsToUrlMapper;
exports.partsToUrlUnmapper = partsToUrlUnmapper;
function partsToUrlMapper(data) {
const [scheme, authority, path] = data;
const query = data[3] === null ? '' : `?${data[3]}`;
const fragments = data[4] === null ? '' : `#${data[4]}`;
return `${scheme}://${authority}${path}${query}${fragments}`;
}
const UrlSplitRegex = /^([[A-Za-z][A-Za-z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[A-Za-z0-9\-._~!$&'()*+,;=:@/?%]*)?(#[A-Za-z0-9\-._~!$&'()*+,;=:@/?%]*)?$/;
function partsToUrlUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Incompatible value received: type');
}
const m = UrlSplitRegex.exec(value);
if (m === null) {
throw new Error('Incompatible value received');
}
const scheme = m[1];
const authority = m[2];
const path = m[3];
const query = m[4];
const fragments = m[5];
return [
scheme,
authority,
path,
query !== undefined ? query.substring(1) : null,
fragments !== undefined ? fragments.substring(1) : null,
];
}

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.patternsToStringMapper = patternsToStringMapper;
exports.patternsToStringUnmapperIsValidLength = patternsToStringUnmapperIsValidLength;
exports.patternsToStringUnmapperFor = patternsToStringUnmapperFor;
const MaxLengthFromMinLength_1 = require("../helpers/MaxLengthFromMinLength");
const globals_1 = require("../../../utils/globals");
const TokenizeString_1 = require("../helpers/TokenizeString");
function patternsToStringMapper(tab) {
return (0, globals_1.safeJoin)(tab, '');
}
function minLengthFrom(constraints) {
return constraints.minLength !== undefined ? constraints.minLength : 0;
}
function maxLengthFrom(constraints) {
return constraints.maxLength !== undefined ? constraints.maxLength : MaxLengthFromMinLength_1.MaxLengthUpperBound;
}
function patternsToStringUnmapperIsValidLength(tokens, constraints) {
return minLengthFrom(constraints) <= tokens.length && tokens.length <= maxLengthFrom(constraints);
}
function patternsToStringUnmapperFor(patternsArb, constraints) {
return function patternsToStringUnmapper(value) {
if (typeof value !== 'string') {
throw new globals_1.Error('Unsupported value');
}
const tokens = (0, TokenizeString_1.tokenizeString)(patternsArb, value, minLengthFrom(constraints), maxLengthFrom(constraints));
if (tokens === undefined) {
throw new globals_1.Error('Unable to unmap received string');
}
return tokens;
};
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.segmentsToPathMapper = segmentsToPathMapper;
exports.segmentsToPathUnmapper = segmentsToPathUnmapper;
const globals_1 = require("../../../utils/globals");
function segmentsToPathMapper(segments) {
return (0, globals_1.safeJoin)((0, globals_1.safeMap)(segments, (v) => `/${v}`), '');
}
function segmentsToPathUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Incompatible value received: type');
}
if (value.length !== 0 && value[0] !== '/') {
throw new Error('Incompatible value received: start');
}
return (0, globals_1.safeSplice)((0, globals_1.safeSplit)(value, '/'), 1);
}

View File

@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.stringToBase64Mapper = stringToBase64Mapper;
exports.stringToBase64Unmapper = stringToBase64Unmapper;
const globals_1 = require("../../../utils/globals");
function stringToBase64Mapper(s) {
switch (s.length % 4) {
case 0:
return s;
case 3:
return `${s}=`;
case 2:
return `${s}==`;
default:
return (0, globals_1.safeSubstring)(s, 1);
}
}
function stringToBase64Unmapper(value) {
if (typeof value !== 'string' || value.length % 4 !== 0) {
throw new Error('Invalid string received');
}
const lastTrailingIndex = value.indexOf('=');
if (lastTrailingIndex === -1) {
return value;
}
const numTrailings = value.length - lastTrailingIndex;
if (numTrailings > 2) {
throw new Error('Cannot unmap the passed value');
}
return (0, globals_1.safeSubstring)(value, 0, lastTrailingIndex);
}

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.timeToDateMapper = timeToDateMapper;
exports.timeToDateUnmapper = timeToDateUnmapper;
exports.timeToDateMapperWithNaN = timeToDateMapperWithNaN;
exports.timeToDateUnmapperWithNaN = timeToDateUnmapperWithNaN;
const globals_1 = require("../../../utils/globals");
const safeNaN = Number.NaN;
const safeNumberIsNaN = Number.isNaN;
function timeToDateMapper(time) {
return new globals_1.Date(time);
}
function timeToDateUnmapper(value) {
if (!(value instanceof globals_1.Date) || value.constructor !== globals_1.Date) {
throw new globals_1.Error('Not a valid value for date unmapper');
}
return (0, globals_1.safeGetTime)(value);
}
function timeToDateMapperWithNaN(valueForNaN) {
return (time) => {
return time === valueForNaN ? new globals_1.Date(safeNaN) : timeToDateMapper(time);
};
}
function timeToDateUnmapperWithNaN(valueForNaN) {
return (value) => {
const time = timeToDateUnmapper(value);
return safeNumberIsNaN(time) ? valueForNaN : time;
};
}

View File

@@ -0,0 +1,111 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.uintToBase32StringMapper = uintToBase32StringMapper;
exports.paddedUintToBase32StringMapper = paddedUintToBase32StringMapper;
exports.uintToBase32StringUnmapper = uintToBase32StringUnmapper;
const globals_1 = require("../../../utils/globals");
const encodeSymbolLookupTable = {
10: 'A',
11: 'B',
12: 'C',
13: 'D',
14: 'E',
15: 'F',
16: 'G',
17: 'H',
18: 'J',
19: 'K',
20: 'M',
21: 'N',
22: 'P',
23: 'Q',
24: 'R',
25: 'S',
26: 'T',
27: 'V',
28: 'W',
29: 'X',
30: 'Y',
31: 'Z',
};
const decodeSymbolLookupTable = {
'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
A: 10,
B: 11,
C: 12,
D: 13,
E: 14,
F: 15,
G: 16,
H: 17,
J: 18,
K: 19,
M: 20,
N: 21,
P: 22,
Q: 23,
R: 24,
S: 25,
T: 26,
V: 27,
W: 28,
X: 29,
Y: 30,
Z: 31,
};
function encodeSymbol(symbol) {
return symbol < 10 ? (0, globals_1.String)(symbol) : encodeSymbolLookupTable[symbol];
}
function pad(value, paddingLength) {
let extraPadding = '';
while (value.length + extraPadding.length < paddingLength) {
extraPadding += '0';
}
return extraPadding + value;
}
function smallUintToBase32StringMapper(num) {
let base32Str = '';
for (let remaining = num; remaining !== 0;) {
const next = remaining >> 5;
const current = remaining - (next << 5);
base32Str = encodeSymbol(current) + base32Str;
remaining = next;
}
return base32Str;
}
function uintToBase32StringMapper(num, paddingLength) {
const head = ~~(num / 0x40000000);
const tail = num & 0x3fffffff;
return pad(smallUintToBase32StringMapper(head), paddingLength - 6) + pad(smallUintToBase32StringMapper(tail), 6);
}
function paddedUintToBase32StringMapper(paddingLength) {
return function padded(num) {
return uintToBase32StringMapper(num, paddingLength);
};
}
function uintToBase32StringUnmapper(value) {
if (typeof value !== 'string') {
throw new globals_1.Error('Unsupported type');
}
let accumulated = 0;
let power = 1;
for (let index = value.length - 1; index >= 0; --index) {
const char = value[index];
const numericForChar = decodeSymbolLookupTable[char];
if (numericForChar === undefined) {
throw new globals_1.Error('Unsupported type');
}
accumulated += numericForChar * power;
power *= 32;
}
return accumulated;
}

View File

@@ -0,0 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.unboxedToBoxedMapper = unboxedToBoxedMapper;
exports.unboxedToBoxedUnmapper = unboxedToBoxedUnmapper;
const globals_1 = require("../../../utils/globals");
function unboxedToBoxedMapper(value) {
switch (typeof value) {
case 'boolean':
return new globals_1.Boolean(value);
case 'number':
return new globals_1.Number(value);
case 'string':
return new globals_1.String(value);
default:
return value;
}
}
function unboxedToBoxedUnmapper(value) {
if (typeof value !== 'object' || value === null || !('constructor' in value)) {
return value;
}
return value.constructor === globals_1.Boolean || value.constructor === globals_1.Number || value.constructor === globals_1.String
? value.valueOf()
: value;
}

View File

@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildValuesAndSeparateKeysToObjectMapper = buildValuesAndSeparateKeysToObjectMapper;
exports.buildValuesAndSeparateKeysToObjectUnmapper = buildValuesAndSeparateKeysToObjectUnmapper;
const globals_1 = require("../../../utils/globals");
const safeObjectCreate = Object.create;
const safeObjectDefineProperty = Object.defineProperty;
const safeObjectGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
const safeObjectGetOwnPropertyNames = Object.getOwnPropertyNames;
const safeObjectGetOwnPropertySymbols = Object.getOwnPropertySymbols;
function buildValuesAndSeparateKeysToObjectMapper(keys, noKeyValue) {
return function valuesAndSeparateKeysToObjectMapper(definition) {
const obj = definition[1] ? safeObjectCreate(null) : {};
for (let idx = 0; idx !== keys.length; ++idx) {
const valueWrapper = definition[0][idx];
if (valueWrapper !== noKeyValue) {
safeObjectDefineProperty(obj, keys[idx], {
value: valueWrapper,
configurable: true,
enumerable: true,
writable: true,
});
}
}
return obj;
};
}
function buildValuesAndSeparateKeysToObjectUnmapper(keys, noKeyValue) {
return function valuesAndSeparateKeysToObjectUnmapper(value) {
if (typeof value !== 'object' || value === null) {
throw new Error('Incompatible instance received: should be a non-null object');
}
const hasNullPrototype = Object.getPrototypeOf(value) === null;
const hasObjectPrototype = 'constructor' in value && value.constructor === Object;
if (!hasNullPrototype && !hasObjectPrototype) {
throw new Error('Incompatible instance received: should be of exact type Object');
}
let extractedPropertiesCount = 0;
const extractedValues = [];
for (let idx = 0; idx !== keys.length; ++idx) {
const descriptor = safeObjectGetOwnPropertyDescriptor(value, keys[idx]);
if (descriptor !== undefined) {
if (!descriptor.configurable || !descriptor.enumerable || !descriptor.writable) {
throw new Error('Incompatible instance received: should contain only c/e/w properties');
}
if (descriptor.get !== undefined || descriptor.set !== undefined) {
throw new Error('Incompatible instance received: should contain only no get/set properties');
}
++extractedPropertiesCount;
(0, globals_1.safePush)(extractedValues, descriptor.value);
}
else {
(0, globals_1.safePush)(extractedValues, noKeyValue);
}
}
const namePropertiesCount = safeObjectGetOwnPropertyNames(value).length;
const symbolPropertiesCount = safeObjectGetOwnPropertySymbols(value).length;
if (extractedPropertiesCount !== namePropertiesCount + symbolPropertiesCount) {
throw new Error('Incompatible instance received: should not contain extra properties');
}
return [extractedValues, hasNullPrototype];
};
}

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildVersionsAppliersForUuid = buildVersionsAppliersForUuid;
const globals_1 = require("../../../utils/globals");
const quickNumberToHexaString = '0123456789abcdef';
function buildVersionsAppliersForUuid(versions) {
const mapping = {};
const reversedMapping = {};
for (let index = 0; index !== versions.length; ++index) {
const from = quickNumberToHexaString[index];
const to = quickNumberToHexaString[versions[index]];
mapping[from] = to;
reversedMapping[to] = from;
}
function versionsApplierMapper(value) {
return mapping[value[0]] + (0, globals_1.safeSubstring)(value, 1);
}
function versionsApplierUnmapper(value) {
if (typeof value !== 'string') {
throw new globals_1.Error('Cannot produce non-string values');
}
const rev = reversedMapping[value[0]];
if (rev === undefined) {
throw new globals_1.Error('Cannot produce strings not starting by the version in hexa code');
}
return rev + (0, globals_1.safeSubstring)(value, 1);
}
return { versionsApplierMapper, versionsApplierUnmapper };
}

View File

@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.wordsToJoinedStringMapper = wordsToJoinedStringMapper;
exports.wordsToJoinedStringUnmapperFor = wordsToJoinedStringUnmapperFor;
exports.wordsToSentenceMapper = wordsToSentenceMapper;
exports.wordsToSentenceUnmapperFor = wordsToSentenceUnmapperFor;
exports.sentencesToParagraphMapper = sentencesToParagraphMapper;
exports.sentencesToParagraphUnmapper = sentencesToParagraphUnmapper;
const globals_1 = require("../../../utils/globals");
function wordsToJoinedStringMapper(words) {
return (0, globals_1.safeJoin)((0, globals_1.safeMap)(words, (w) => (w[w.length - 1] === ',' ? (0, globals_1.safeSubstring)(w, 0, w.length - 1) : w)), ' ');
}
function wordsToJoinedStringUnmapperFor(wordsArbitrary) {
return function wordsToJoinedStringUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported type');
}
const words = [];
for (const candidate of (0, globals_1.safeSplit)(value, ' ')) {
if (wordsArbitrary.canShrinkWithoutContext(candidate))
(0, globals_1.safePush)(words, candidate);
else if (wordsArbitrary.canShrinkWithoutContext(candidate + ','))
(0, globals_1.safePush)(words, candidate + ',');
else
throw new Error('Unsupported word');
}
return words;
};
}
function wordsToSentenceMapper(words) {
let sentence = (0, globals_1.safeJoin)(words, ' ');
if (sentence[sentence.length - 1] === ',') {
sentence = (0, globals_1.safeSubstring)(sentence, 0, sentence.length - 1);
}
return (0, globals_1.safeToUpperCase)(sentence[0]) + (0, globals_1.safeSubstring)(sentence, 1) + '.';
}
function wordsToSentenceUnmapperFor(wordsArbitrary) {
return function wordsToSentenceUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported type');
}
if (value.length < 2 ||
value[value.length - 1] !== '.' ||
value[value.length - 2] === ',' ||
(0, globals_1.safeToUpperCase)((0, globals_1.safeToLowerCase)(value[0])) !== value[0]) {
throw new Error('Unsupported value');
}
const adaptedValue = (0, globals_1.safeToLowerCase)(value[0]) + (0, globals_1.safeSubstring)(value, 1, value.length - 1);
const words = [];
const candidates = (0, globals_1.safeSplit)(adaptedValue, ' ');
for (let idx = 0; idx !== candidates.length; ++idx) {
const candidate = candidates[idx];
if (wordsArbitrary.canShrinkWithoutContext(candidate))
(0, globals_1.safePush)(words, candidate);
else if (idx === candidates.length - 1 && wordsArbitrary.canShrinkWithoutContext(candidate + ','))
(0, globals_1.safePush)(words, candidate + ',');
else
throw new Error('Unsupported word');
}
return words;
};
}
function sentencesToParagraphMapper(sentences) {
return (0, globals_1.safeJoin)(sentences, ' ');
}
function sentencesToParagraphUnmapper(value) {
if (typeof value !== 'string') {
throw new Error('Unsupported type');
}
const sentences = (0, globals_1.safeSplit)(value, '. ');
for (let idx = 0; idx < sentences.length - 1; ++idx) {
sentences[idx] += '.';
}
return sentences;
}

View File

@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

8
node_modules/fast-check/lib/arbitrary/anything.js generated vendored Normal file
View File

@@ -0,0 +1,8 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.anything = anything;
const AnyArbitraryBuilder_1 = require("./_internals/builders/AnyArbitraryBuilder");
const QualifiedObjectConstraints_1 = require("./_internals/helpers/QualifiedObjectConstraints");
function anything(constraints) {
return (0, AnyArbitraryBuilder_1.anyArbitraryBuilder)((0, QualifiedObjectConstraints_1.toQualifiedObjectConstraints)(constraints));
}

Some files were not shown because too many files have changed in this diff Show More