diff --git a/lib/schema.json b/lib/schema.json new file mode 100644 index 0000000..cd0b3d7 --- /dev/null +++ b/lib/schema.json @@ -0,0 +1,132 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "nodes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "opcode": { + "type": "string", + "pattern": "^([a-zA-Z0-9\\_\\-\\.\\:])+$" + }, + "control": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "inputs": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "literals": { + "type": "array" + } + }, + "additionalProperties": false, + "required": [ + "opcode", + "control", + "inputs", + "literals" + ] + } + }, + "cfg": { + "type": "object", + "properties": { + "blocks": { + "type": "array", + "items": { + "type": "object", + "properties": { + "node": { + "type": "integer", + "minimum": 0 + }, + "nodes": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "successors": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + "additionalProperties": false, + "required": [ + "node", + "nodes", + "successors" + ] + } + } + }, + "additionalProperties": false, + "required": [ + "blocks" + ] + }, + "dominance": { + "type": "object", + "properties": { + "blocks": { + "type": "array", + "items": { + "type": "object", + "properties": { + "node": { + "type": "integer", + "minimum": 0 + }, + "parent": { + "oneOf": [ + { + "type": "integer", + "minimum": 0 + }, + { + "type": "null" + } + ] + }, + "frontier": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + } + }, + "additionalProperties": false, + "required": [ + "node", + "parent", + "frontier" + ] + } + } + }, + "additionalProperties": false, + "required": [ + "blocks" + ] + } + }, + "additionalProperties": false, + "required": [ + "nodes" + ] +} diff --git a/package.json b/package.json index 813941d..4c1c47f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "assert-text": "^1.1.0", "jscs": "^1.13.1", "jshint": "^2.8.0", - "mocha": "^2.2.5" + "mocha": "^2.2.5", + "tv4": "^1.1.12" }, "dependencies": { "bitfield.js": "^1.1.0" diff --git a/test/pipeline-test.js b/test/pipeline-test.js index b4b8b68..fa3f3e2 100644 --- a/test/pipeline-test.js +++ b/test/pipeline-test.js @@ -1,5 +1,7 @@ var assert = require('assert'); var assertText = require('assert-text'); +var schema = require('../lib/schema.json'); +var tv4 = require('tv4'); assertText.options.trim = true; @@ -13,6 +15,12 @@ describe('JSON Pipeline', function() { p = pipeline.create(); }); + 'p0 p1 p1cfg p2dom'.split(' ').forEach(function (e) { + it(e + ' should comply with the schema', function() { + assert.equal(tv4.validate(fixtures.json[e], schema), true); + }); + }); + it('should render JSON', function() { var start = p.add('start'); var one = p.add('literal').addLiteral(1);