From 109f25cc1f3b8c2a7e7330020e62d59e0af61b89 Mon Sep 17 00:00:00 2001 From: Nicolas DUBIEN Date: Thu, 8 Feb 2018 23:34:41 +0100 Subject: [PATCH] Add property based tests to assess load reverses dump --- package.json | 1 + test/40-properties.js | 16 ++++++++++++++++ test/properties/identity.js | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 test/40-properties.js create mode 100644 test/properties/identity.js diff --git a/package.json b/package.json index 7c736363..617ba33f 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/test/40-properties.js b/test/40-properties.js new file mode 100644 index 00000000..9843a97e --- /dev/null +++ b/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)); + } + }); +}); diff --git a/test/properties/identity.js b/test/properties/identity.js new file mode 100644 index 00000000..39a8e54a --- /dev/null +++ b/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); + })); +});