Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider introducing an any generator. #6

Open
sunesimonsen opened this issue Aug 7, 2016 · 5 comments
Open

Consider introducing an any generator. #6

sunesimonsen opened this issue Aug 7, 2016 · 5 comments

Comments

@sunesimonsen
Copy link
Owner

sunesimonsen commented Aug 7, 2016

Something like:

var number = g.pick([
    g.integer({min: -100, max: 100}), g.integer,
    g.floating({min: -100, max: 100}), g.floating
])
var stringNumber = number.map(function (v) { return String(v) })
var anyPrimitive = g.pick([number, g.string, g.pick([
    -0, +0, 0, undefined, null, false, true,
    NaN, Infinity, -Infinity, '', [], stringNumber,
    Number.MAX_SAFE_INTEGER,
    Number.MIN_SAFE_INTEGER,
    Number.MAX_VALUE,
    Number.MIN_VALUE
])])
var any = g.weighted([anyPrimitive, g.array(anyPrimitive)], [10, 1])

It should also be capable of generating random objects and nested arrays.

@papandreou
Copy link
Collaborator

Good idea! Sounds really useful for trying to find errors in input sanitation/validation code.

@papandreou
Copy link
Collaborator

Could also include magic values if available?

@sunesimonsen
Copy link
Owner Author

Yes it should just be based on the number and text generators, then you get that for free.

@sunesimonsen
Copy link
Owner Author

This generator should also produce nested objects and arrays.

I think it would be nice to just say how many leafs you want and generate a random tree structure connecting the leafs with random branches.

@sunesimonsen
Copy link
Owner Author

We might also allow to generate any primitive as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants