alphanumeric generator generating empty strings
See original GitHub issue💬 Question and Help
I’m working on testing a validator that accepts a string starting with a letter followed by alphanumeric characters with fast-check. I have this code:
it('should return on true on valid generated inputs', () => {
const alphanumericChar = fc.mapToConstant(
{ num: 26, build: (v) => String.fromCharCode(v + 0x61) },
{ num: 10, build: (v) => String.fromCharCode(v + 0x30) }
);
const letterChar = fc.mapToConstant({ num: 26, build: (v) => String.fromCharCode(v + 0x61) });
const letters = fc.stringOf(letterChar);
const alphanumericString = fc.stringOf(alphanumericChar);
const prometheusMetricArbitrary = fc.record({ start: letters, rest: alphanumericString }).map(({ start, rest }) => {
if (!/^[a-z|A-Z]+$/.test(start)) {
throw new Error(`start is messed up: ${start}`);
}
if (!/^[a-z|A-Z|0-9]+$/.test(rest)) {
throw new Error(`rest is messed up: ${rest}`);
}
return `${start}${rest}`;
});
fc.assert(
fc.property(prometheusMetricArbitrary, fc.context(), (input, ctx) => {
ctx.log(`input: ${input}, output: ${validateStatsNamespaceAndSubystem(input)}`);
expect(validateStatsNamespaceAndSubystem(input)).toBe(true);
})
);
});
but the assertions in prometheusMetricArbitrary
are failing w/ empty strings generated…
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
c# - How can I generate random alphanumeric strings?
I heard LINQ is the new black, so here's my attempt using LINQ: private static Random random = new Random(); public static string...
Read more >Random AlphaNumeric Generator Online - Code Beautify
Random AlphaNumeric Generator is easy to use tool to generate unique AlphaNumeric word based on given parameters.
Read more >How to generate a random, unique, alphanumeric string in PHP
There are many ways to generate a random, unique, alphanumeric string in PHP which are given below: Using str_shuffle() Function: The ...
Read more >Generate a random alphanumeric string in Python | bobbyhadz
To generate a random alphanumeric string, use the `string` module to ... method takes a sequence and returns a random element from the...
Read more >Easiest Ways To Generate A Random String In Java - Xperti
A random alphanumeric string of your required length can be easily created by combining this randomly generated number with a few other ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If so, can I ask you to create another issue saying ‘add missing documentation for default values in jsdoc’ (or similar title) and close this one but reference it into the new one? It would make tracking easier.
Aren’t they already documented? If we check
stringOf
in the documentation generated from the jsdoc we have https://dubzzz.github.io/fast-check/functions/stringOf.html, leading us to https://dubzzz.github.io/fast-check/interfaces/StringSharedConstraints.html. Well the options are documented, but I should agree that I barely never document the@-defaultValue
. By not documented do you talk about it (the at default)?