Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('parse stringified object', () => {
const key = fc.fullUnicodeString()
const values = [
key,
fc.lorem(1000, false), // words
fc.lorem(100, true), // sentences
fc.boolean(),
fc.integer(),
fc.double(),
fc.constantFrom(null, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY)
]
const yamlArbitrary = fc.anything({ key: key, values: values })
const optionsArbitrary = fc.record(
{
keepBlobsInJSON: fc.boolean(),
keepCstNodes: fc.boolean(),
keepNodeTypes: fc.boolean(),
mapAsMap: fc.constant(false),
merge: fc.boolean(),
schema: fc.constantFrom('core', 'yaml-1.1') // ignore 'failsafe', 'json'
},
{ withDeletedKeys: true }
)
fc.assert(
fc.property(yamlArbitrary, optionsArbitrary, (obj, opts) => {
expect(YAML.parse(YAML.stringify(obj, opts), opts)).toStrictEqual(obj)
})
async function() {
return fc.assert(
fc.asyncProperty(
fc.anything(),
async (anything: any) => {
let input = anything
const output = await PromiseWorker(
input
)
expect(input).toEqual(
output
)
}
),
{ numRuns: 10000 }
)
},
10 * 1000 // 10s
it("should produce string evaluating to the original value", () => {
fc.assert(
fc.property(fc.anything(), value => {
expect(evalValue(stringify(value))).toEqual(value);
})
);
});
});
export function getArbitrary(codec: T): fc.Arbitrary> {
const type: HasArbitrary = codec as any;
switch (type._tag) {
case 'UnknownType':
return fc.anything();
case 'UndefinedType':
case 'VoidType':
return fc.constant(undefined) as any;
case 'NullType':
return fc.constant(null) as any;
case 'StringType':
return fc.string() as any;
case 'NumberType':
return fc.float() as any;
case 'BooleanType':
return fc.boolean() as any;
case 'KeyofType':
return fc.oneof(...keys(type.keys).map(fc.constant)) as any;
case 'LiteralType':
return fc.constant(type.value);
case 'ArrayType':