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)
})
)
// Valid query parameters must follow:
// - 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)
)
);
});
// - 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) => {
expect(YAML.parse(YAML.stringify(obj, opts), opts)).toStrictEqual(obj)
})
)
})
})
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)
})
)
})
})
import * as fastCheck from 'fast-check';
import test from 'ava';
import queryString from '..';
// Valid query parameters must follow:
// - 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,
import deepEqual from 'deep-equal';
import * as fastCheck from 'fast-check';
import test from 'ava';
import queryString from '..';
// Valid query parameters must follow:
// - 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(
describe('CharRange', () => {
it('compareFullUnicode', () => {
// String.fromCodePoint(0x1F437) == "🐷" == "\uD83D\uDC37" == "\u{1F437}"
let c1 = '\uD83D\uDC37';
let c2 = '\uFA16';
assert(K.compareFullUnicode(c1, c2) > 0);
});
testProp('subtract join intersect', C.tuple(charRangeGen(), charRangeGen()), a => {
let [r1, r2] = a;
assert(K.CharRange.subtract(r1, r1) === undefined);
assert(K.CharRange.join(r1, r1) === r1);
let inter = K.CharRange.intersect(r1, r2);
if (inter === undefined) {
assert(K.CharRange.subtract(r1, r2) === r1);
assert(K.CharRange.subtract(r2, r1) === r2);
} else {
let join = K.CharRange.join(r1, r2);
if (join === undefined) return assert(join !== undefined);
let j1 = K.CharRange.subtract(join, r1);
if (j1 === undefined) return assert(join === r1 && K.CharRange.isSubsetOf(r2, r1));
let j2 = K.CharRange.subtract(join, r2);
if (j2 === undefined) return assert(join === r2 && K.CharRange.isSubsetOf(r1, r2));
// 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>