Skip to content

Commit

Permalink
Add property based tests to assess load reverses dump
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzzz committed Feb 22, 2018
1 parent c62fd62 commit 109f25c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"browserify": "^14.3.0",
"codemirror": "^5.13.4",
"eslint": "^4.1.1",
"fast-check": "0.0.10",
"istanbul": "^0.4.5",
"mocha": "^3.3.0",
"uglify-js": "^3.0.1"
Expand Down
16 changes: 16 additions & 0 deletions test/40-properties.js
@@ -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));
}
});
});
21 changes: 21 additions & 0 deletions test/properties/identity.js
@@ -0,0 +1,21 @@
'use strict';


var assert = require('assert');
var fc = require('fast-check');
var yaml = require('../../');


test('Load from dumped object should be the original object', function () {
var key = fc.string();
var values = [ fc.boolean(), fc.integer(), fc.double(), fc.string(), fc.constant(null) ];
var yamlArbitrary = fc.object({ key: key, values: values });

fc.assert(fc.property(
yamlArbitrary,
function (obj) {
var yamlContent = yaml.safeDump(obj);
assert.ok(typeof yamlContent === 'string');
assert.deepEqual(yaml.safeLoad(yamlContent), obj);
}));
});

0 comments on commit 109f25c

Please sign in to comment.