-
-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add property based tests to assess load reverses dump
- Loading branch information
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
'use strict'; | ||
|
||
|
||
var path = require('path'); | ||
var fs = require('fs'); | ||
|
||
|
||
suite('Properties', function () { | ||
var directory = path.resolve(__dirname, 'properties'); | ||
|
||
fs.readdirSync(directory).forEach(function (file) { | ||
if (path.extname(file) === '.js') { | ||
require(path.resolve(directory, file)); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict'; | ||
|
||
var fc = require('fast-check'); | ||
|
||
// Generate valid options for yaml.safeDump configuration | ||
|
||
var dumpOptionsArbitrary = 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: 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 }) | ||
}, { with_deleted_keys: true }) | ||
.map(function (instance) { | ||
if (instance.condenseFlow === true && instance.flowLevel !== undefined) { instance.flowLevel = -1; } | ||
return instance; | ||
}); | ||
|
||
module.exports = dumpOptionsArbitrary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
var fc = require('fast-check'); | ||
|
||
// Generate valid YAML instances for yaml.safeDump | ||
|
||
var key = fc.string16bits(); | ||
var values = [ | ||
key, fc.boolean(), fc.integer(), fc.double(), | ||
fc.constantFrom(null, Number.NEGATIVE_INFINITY, Number.POSITIVE_INFINITY) | ||
]; | ||
var yamlArbitrary = fc.object({ key: key, values: values }); | ||
|
||
module.exports = yamlArbitrary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var fc = require('fast-check'); | ||
var yaml = require('../../'); | ||
var yamlArbitrary = require('../properties-arbitraries/yaml'); | ||
var dumpOptionsArbitrary = require('../properties-arbitraries/dump-options'); | ||
|
||
test('Load from dumped should be the original object', function () { | ||
fc.assert(fc.property( | ||
yamlArbitrary, | ||
dumpOptionsArbitrary, | ||
function (obj, dumpOptions) { | ||
var yamlContent = yaml.safeDump(obj, dumpOptions); | ||
assert.ok(typeof yamlContent === 'string'); | ||
assert.deepStrictEqual(yaml.safeLoad(yamlContent), obj); | ||
})); | ||
}); |