dubzzz / fast-check

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

Generate Strings from Nearley grammars. #3053

Closed PWBENNETT closed 1 year ago

PWBENNETT commented 2 years ago

💡 Idea

Generating strings is not just for regexes. The same techniques can be used with any grammar.

Motivation

I came here with a background in using Python's "hypothesis" and Perl's "LectroTest". One of the awesome things in hypothesis is that it can read the same grammar format as the "lark" Earley algorithm parser. Instead of reading text, though, hypothesis runs the rules backwards to generate strings matching any grammar you can think of. Far more than any regex can express, at least.

https://nearley.js.org/ seems to be the "lark" of the JavaScript world, and the good news is that running the rules backwards requires recursive code far less clever than needed fof running them in the usual direction.

Example

I'm not yet familiar enough with the fast-check API to spell out an example word for word, but it looks like the right keywords are "recursive charArb", I think.

dubzzz commented 2 years ago

Hey 👋

I'm wondering if such option should not come as a satellite package based on fast-check. Having it natively would probably brings some unwanted extra development time to the core and increase the complexity to start with fast-check's core.

But it seems it could fit to the idea of an external package adding some extra arbitraries into fast-check.

By the way, strings will be the main target for v3. Current generators around strings have many important things to do better.

Sorry for the late answer.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.