Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Impractical, took several seconds or even minutes to complete these tests
if (false) {
let unicodeCats = (function() {
let a: string[] = [];
let U = Object.assign({}, UnicodeProperty.canonical) as {[k: string]: Set};
delete U.NonBinary_Property;
for (let k in U) {
for (let cat of U[k]) {
a.push(k + '/' + cat);
}
}
return a;
})();
const genUnicodeCat = C.constantFrom(...unicodeCats);
it('Unicode module', () => {
for (let path of unicodeCats) {
let codePoints = require(DEFAULT_UNICODE_PKG + '/' + path + '/code-points.js');
let charset = K.Charset.fromCodePoints(codePoints);
let [cls, cat] = path.split('/');
assert(charset.equals((Unicode as any)[cls][cat]));
}
});
testProp('Unicode category fromPattern toPattern equal', genUnicodeCat, cat => {
let codePoints = require(DEFAULT_UNICODE_PKG + '/' + cat + '/code-points.js');
let charset = K.Charset.fromCodePoints(codePoints);
assert(K.Charset.fromPattern(charset.toPattern()).equals(charset));
});
runToPromiseExit(io2)
.then((result2) => {
return expect(result1).to.deep.equal(result2);
})
.then(constTrue)
);
}
export function exitType(io1: Wave, tag: Exit["_tag"]): Promise {
return runToPromiseExit(io1)
.then((result) => expect(result._tag).to.equal(tag))
.then(() => undefined);
}
export const arbVariant: Arbitrary =
fc.constantFrom("succeed", "complete", "suspend", "async");
export function arbIO(arb: Arbitrary<a>): Arbitrary> {
return arbVariant
.chain((ioStep) => {
if (ioStep === "succeed") {
return arb.map((a) => pure(a) as Wave); // force downcast
} else if (ioStep === "complete") {
return arb.map((a) => completed(done(a)));
} else if (ioStep === "suspend") {
// We now need to do recursion... wooo
return arbIO(arb)
.map((nestedIO) => suspended(() => nestedIO));
} else { // async with random delay
return fc.tuple(fc.nat(50), arb)
.map(
([delay, val]) =></a>
// - key can be any unicode string (not empty)
// - value must be one of:
// --> any unicode string
// --> null
// --> array containing values defined above (at least two items)
const queryParamsArbitrary = fastCheck.dictionary(
fastCheck.fullUnicodeString(1, 10),
fastCheck.oneof(
fastCheck.fullUnicodeString(),
fastCheck.constant(null),
fastCheck.array(fastCheck.oneof(fastCheck.fullUnicodeString(), fastCheck.constant(null)), 2, 10)
)
);
const optionsArbitrary = fastCheck.record({
arrayFormat: fastCheck.constantFrom('bracket', 'index', 'none'),
strict: fastCheck.boolean(),
encode: fastCheck.constant(true),
sort: fastCheck.constant(false)
}, {withDeletedKeys: true});
test('should read correctly from stringified query params', t => {
t.notThrows(() => {
fastCheck.assert(
fastCheck.property(
queryParamsArbitrary,
optionsArbitrary,
(object, options) => deepEqual(queryString.parse(queryString.stringify(object, options), options), object)
)
);
});
});
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) => {
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import fc from 'fast-check';
// settings for anything arbitrary
export const anythingSettings = {
key: fc.oneof(fc.string(), fc.constantFrom('k1', 'k2', 'k3')),
maxDepth: 2, // Limit object depth (default: 2)
maxKeys: 5, // Limit number of keys per object (default: 5)
withBoxedValues: true,
// Issue #7975 have to be fixed before enabling the generation of Map
withMap: false,
// Issue #7975 have to be fixed before enabling the generation of Set
withSet: false,
};
// assertion settings
export const assertSettings = {}; // eg.: {numRuns: 10000}
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)
})
)
})
})
const lowerCamelCase = () =>
fc
.tuple(
fc.constantFrom(...'abcdefghijklmnopqrstuvwxyz'.split('')),
fc.stringOf(
fc.constantFrom(
...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(
'',
),
),
),
)
.map(([firstLetter, remaining]) => `${firstLetter}${remaining}`);
const lowerCamelCase = () =>
fc
.tuple(
fc.constantFrom(...'abcdefghijklmnopqrstuvwxyz'.split('')),
fc.stringOf(
fc.constantFrom(
...'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'.split(
'',
),
),
),
)
.map(([firstLetter, remaining]) => `${firstLetter}${remaining}`);
export function genInCharset(ch: K.Charset): C.Arbitrary {
return C.constantFrom(...ch.ranges).chain(range =>
C.integer(K.CharRange.begin(range), K.CharRange.end(range)).map(String.fromCodePoint)
);
}