From 0023e72c21c664d8612b708dbcb542ba9c6c67f3 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Tue, 4 Aug 2015 23:55:21 -0700 Subject: [PATCH 1/6] initial general schema added --- lib/schema.json | 167 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 lib/schema.json diff --git a/lib/schema.json b/lib/schema.json new file mode 100644 index 0000000..62b75ab --- /dev/null +++ b/lib/schema.json @@ -0,0 +1,167 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "nodes": { + "type": "array", + "items": { + "type": "object", + "properties": { + "opcode": { + "type": "string", + "enum": [ + "if", + "jump", + "region", + "start", + "literal", + "add", + "phi", + "return" + ] + }, + "control": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "inputs": { + "type": "array", + "items": { + "type": "integer", + "minimum": 0 + } + }, + "literals": { + "type": "array", + "items": { + "oneOf": [ + { + "type": "integer", + "minimum": 0 + }, + { + "type": "string", + "enum": [ + "ok", + "not-ok" + ] + }, + { + "type": "boolean", + "enum": [ + true + ] + } + ] + } + } + }, + "additionalProperties": false, + "required": [ + "opcode" + ] + } + }, + "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" + ] + }, + "registers": { + "type": "object", + "properties": { + "nodes": { + "type": "array" + } + } + } + }, + "additionalProperties": false, + "required": [ + "nodes" + ] +} From 9be51041bd6dfbc51baeebd5589ee9b1a73a8e0d Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Wed, 5 Aug 2015 00:18:48 -0700 Subject: [PATCH 2/6] added tv4 for schema validation --- package.json | 3 ++- test/pipeline-test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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..1d53a79 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,22 @@ describe('JSON Pipeline', function() { p = pipeline.create(); }); + it('p0 should comply with the schema', function() { + assert.equal(tv4.validate(fixtures.json.p0, schema), true); + }); + + it('p1 should comply with the schema', function() { + assert.equal(tv4.validate(fixtures.json.p1, schema), true); + }); + + it('p1cfg should comply with the schema', function() { + assert.equal(tv4.validate(fixtures.json.p1cfg, schema), true); + }); + + it('p2dom should comply with the schema', function() { + assert.equal(tv4.validate(fixtures.json.p2dom, schema), true); + }); + it('should render JSON', function() { var start = p.add('start'); var one = p.add('literal').addLiteral(1); From 0f28398b57af0323af07a1257899dcc1a6b82878 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Wed, 5 Aug 2015 00:31:12 -0700 Subject: [PATCH 3/6] minor cleanup --- test/pipeline-test.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/test/pipeline-test.js b/test/pipeline-test.js index 1d53a79..c2e139b 100644 --- a/test/pipeline-test.js +++ b/test/pipeline-test.js @@ -15,20 +15,10 @@ describe('JSON Pipeline', function() { p = pipeline.create(); }); - it('p0 should comply with the schema', function() { - assert.equal(tv4.validate(fixtures.json.p0, schema), true); - }); - - it('p1 should comply with the schema', function() { - assert.equal(tv4.validate(fixtures.json.p1, schema), true); - }); - - it('p1cfg should comply with the schema', function() { - assert.equal(tv4.validate(fixtures.json.p1cfg, schema), true); - }); - - it('p2dom should comply with the schema', function() { - assert.equal(tv4.validate(fixtures.json.p2dom, schema), true); + '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() { From c007f1f03e55b3659148d01acbff2c820acd2723 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Wed, 5 Aug 2015 14:16:23 -0700 Subject: [PATCH 4/6] schema rules simplification for opcode and literals; minor style fix --- lib/schema.json | 34 ++-------------------------------- test/pipeline-test.js | 4 ++-- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/lib/schema.json b/lib/schema.json index 62b75ab..3a406ed 100644 --- a/lib/schema.json +++ b/lib/schema.json @@ -9,16 +9,7 @@ "properties": { "opcode": { "type": "string", - "enum": [ - "if", - "jump", - "region", - "start", - "literal", - "add", - "phi", - "return" - ] + "pattern": "^([a-zA-Z0-9\\_\\-\\.\\:])+$" }, "control": { "type": "array", @@ -35,28 +26,7 @@ } }, "literals": { - "type": "array", - "items": { - "oneOf": [ - { - "type": "integer", - "minimum": 0 - }, - { - "type": "string", - "enum": [ - "ok", - "not-ok" - ] - }, - { - "type": "boolean", - "enum": [ - true - ] - } - ] - } + "type": "array" } }, "additionalProperties": false, diff --git a/test/pipeline-test.js b/test/pipeline-test.js index c2e139b..fa3f3e2 100644 --- a/test/pipeline-test.js +++ b/test/pipeline-test.js @@ -17,8 +17,8 @@ describe('JSON Pipeline', function() { '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); - }); + assert.equal(tv4.validate(fixtures.json[e], schema), true); + }); }); it('should render JSON', function() { From 3e3919b06c05a744a5896f1be2bc22e017898858 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Wed, 5 Aug 2015 16:41:34 -0700 Subject: [PATCH 5/6] require all properties of nodes in the schema --- lib/schema.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/schema.json b/lib/schema.json index 3a406ed..aa84660 100644 --- a/lib/schema.json +++ b/lib/schema.json @@ -31,7 +31,10 @@ }, "additionalProperties": false, "required": [ - "opcode" + "opcode", + "control", + "inputs", + "literals" ] } }, From 2e5cedbe4960452cb824b4793392901a379b8d08 Mon Sep 17 00:00:00 2001 From: Aliaksei Chapyzhenka Date: Sun, 9 Aug 2015 20:49:45 -0700 Subject: [PATCH 6/6] removed registers section from schema --- lib/schema.json | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lib/schema.json b/lib/schema.json index aa84660..cd0b3d7 100644 --- a/lib/schema.json +++ b/lib/schema.json @@ -123,14 +123,6 @@ "required": [ "blocks" ] - }, - "registers": { - "type": "object", - "properties": { - "nodes": { - "type": "array" - } - } } }, "additionalProperties": false,