question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dubzzzcommented, Sep 11, 2022

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.

1reaction
dubzzzcommented, Sep 11, 2022

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)?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found