diff options
author | isaacs <i@izs.me> | 2020-07-24 22:50:02 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-07-29 21:55:03 +0300 |
commit | bbe4279120c94791b70d97f235c73d972fd67354 (patch) | |
tree | a098e008fc4b906180a4b5ca03a6203ba7a946d5 /node_modules/json-schema-traverse/spec/index.spec.js | |
parent | 764103ceff2ec2e80f396b5a071660fd7425be15 (diff) |
reset and update all deps
Diffstat (limited to 'node_modules/json-schema-traverse/spec/index.spec.js')
-rw-r--r-- | node_modules/json-schema-traverse/spec/index.spec.js | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/node_modules/json-schema-traverse/spec/index.spec.js b/node_modules/json-schema-traverse/spec/index.spec.js index 7e66143d3..c76b64fc8 100644 --- a/node_modules/json-schema-traverse/spec/index.spec.js +++ b/node_modules/json-schema-traverse/spec/index.spec.js @@ -14,10 +14,29 @@ describe('json-schema-traverse', function() { var schema = require('./fixtures/schema').schema; var expectedCalls = require('./fixtures/schema').expectedCalls; - traverse(schema, callback); + traverse(schema, {cb: callback}); assert.deepStrictEqual(calls, expectedCalls); }); + describe('Legacy v0.3.1 API', function() { + it('should traverse all keywords containing schemas recursively', function() { + var schema = require('./fixtures/schema').schema; + var expectedCalls = require('./fixtures/schema').expectedCalls; + + traverse(schema, callback); + assert.deepStrictEqual(calls, expectedCalls); + }); + + it('should work when an options object is provided', function() { + // schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex + var schema = require('./fixtures/schema').schema; + var expectedCalls = require('./fixtures/schema').expectedCalls; + + traverse(schema, {}, callback); + assert.deepStrictEqual(calls, expectedCalls); + }); + }); + describe('allKeys option', function() { var schema = { @@ -34,7 +53,7 @@ describe('json-schema-traverse', function() { [schema.someObject, '/someObject', schema, '', 'someObject', schema, undefined] ]; - traverse(schema, {allKeys: true}, callback); + traverse(schema, {allKeys: true, cb: callback}); assert.deepStrictEqual(calls, expectedCalls); }); @@ -45,7 +64,7 @@ describe('json-schema-traverse', function() { [schema, '', schema, undefined, undefined, undefined, undefined] ]; - traverse(schema, {allKeys: false}, callback); + traverse(schema, {allKeys: false, cb: callback}); assert.deepStrictEqual(calls, expectedCalls); }); @@ -56,7 +75,7 @@ describe('json-schema-traverse', function() { [schema, '', schema, undefined, undefined, undefined, undefined] ]; - traverse(schema, callback); + traverse(schema, {cb: callback}); assert.deepStrictEqual(calls, expectedCalls); }); @@ -90,13 +109,63 @@ describe('json-schema-traverse', function() { [schema2.properties.larger, '/properties/larger', schema2, '', 'properties', schema2, 'larger'], ]; - traverse(schema2, {allKeys: true}, callback); + traverse(schema2, {allKeys: true, cb: callback}); assert.deepStrictEqual(calls, expectedCalls); }); }); + describe('pre and post', function() { + var schema = { + type: 'object', + properties: { + name: {type: 'string'}, + age: {type: 'number'} + } + }; + + it('should traverse schema in pre-order', function() { + traverse(schema, {cb: {pre}}); + var expectedCalls = [ + ['pre', schema, '', schema, undefined, undefined, undefined, undefined], + ['pre', schema.properties.name, '/properties/name', schema, '', 'properties', schema, 'name'], + ['pre', schema.properties.age, '/properties/age', schema, '', 'properties', schema, 'age'], + ]; + assert.deepStrictEqual(calls, expectedCalls); + }); + + it('should traverse schema in post-order', function() { + traverse(schema, {cb: {post}}); + var expectedCalls = [ + ['post', schema.properties.name, '/properties/name', schema, '', 'properties', schema, 'name'], + ['post', schema.properties.age, '/properties/age', schema, '', 'properties', schema, 'age'], + ['post', schema, '', schema, undefined, undefined, undefined, undefined], + ]; + assert.deepStrictEqual(calls, expectedCalls); + }); + + it('should traverse schema in pre- and post-order at the same time', function() { + traverse(schema, {cb: {pre, post}}); + var expectedCalls = [ + ['pre', schema, '', schema, undefined, undefined, undefined, undefined], + ['pre', schema.properties.name, '/properties/name', schema, '', 'properties', schema, 'name'], + ['post', schema.properties.name, '/properties/name', schema, '', 'properties', schema, 'name'], + ['pre', schema.properties.age, '/properties/age', schema, '', 'properties', schema, 'age'], + ['post', schema.properties.age, '/properties/age', schema, '', 'properties', schema, 'age'], + ['post', schema, '', schema, undefined, undefined, undefined, undefined], + ]; + assert.deepStrictEqual(calls, expectedCalls); + }); + }); function callback() { calls.push(Array.prototype.slice.call(arguments)); } + + function pre() { + calls.push(['pre'].concat(Array.prototype.slice.call(arguments))); + } + + function post() { + calls.push(['post'].concat(Array.prototype.slice.call(arguments))); + } }); |