Multiple properties for js-yaml

node v8.17.0
version: 11.0.0
endpointsharetweet
const assert = require('assert'); const yaml = require('js-yaml'); const fc = require('fast-check');
Definition of arbitraries specific to js-yaml
const key = fc.string16bits(); const values = [ key, fc.boolean(), fc.integer(), fc.double(), fc.constantFrom(null, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY/*, Number.NaN*/) ]; const yamlArbitrary = fc.object({ key: key, values: values }); const styleArbitrary = fc.record({ '!!null': fc.constantFrom('lowercase', 'canonical', 'uppercase', 'camelcase'), '!!int': fc.constantFrom('decimal', 'binary', 'octal', 'hexadecimal'), '!!bool': fc.constantFrom('lowercase', 'uppercase', 'camelcase'), '!!float': fc.constantFrom('lowercase', 'uppercase', 'camelcase'), }, {with_deleted_keys: true}); const optionsArbitrary = fc.record({ skipInvalid: fc.boolean(), sortKeys: fc.boolean(), noRefs: fc.boolean(), noCompatMode: fc.boolean(), condenseFlow: fc.boolean(), indent: fc.integer(1, 80), flowLevel: fc.integer(-1, 10), styles: styleArbitrary, }, {with_deleted_keys: true}) .map(instance => { if (instance.condenseFlow === true && instance.flowLevel !== undefined) instance.flowLevel = -1; return instance; });
Property #1: Produce valid UTF-16 strings
const isValidUtf16 = (text) => { try { encodeURIComponent(text); } catch(err) { return false; } return true; }; fc.assert(fc.property(yamlArbitrary, optionsArbitrary, (obj, opts) => isValidUtf16(yaml.safeDump(obj, opts))));
Property #2: Able to read itself
// Uncomment to run a failing case: //yaml.safeLoad(yaml.safeDump({"":[{"\u0000":""}]},{"condenseFlow":true,"flowLevel":1})); const options = {styles:{'!!int':'binary'}}; console.log(yaml.safeDump({"":[null]})); console.log(yaml.safeLoad(yaml.safeDump({"":[null]}))); console.log(yaml.safeDump({'toto':Number.NaN}, options)); console.log(yaml.safeLoad(yaml.safeDump({'toto':10}, options))); console.log(yaml.safeLoad(yaml.safeDump({'toto':-10}, options))); //assert.deepStrictEqual({"":[Number.NaN]}, {"":[Number.NaN]}); //assert.deepStrictEqual(Number.NaN, Number.NaN);
fc.assert(fc.property(yamlArbitrary, optionsArbitrary, (obj, opts) => assert.deepStrictEqual(yaml.safeLoad(yaml.safeDump(obj, opts)), obj)));
Loading…

no comments

    sign in to comment