Skip to content

Commit 84b65ec

Browse files
committed
test suite schema, first suite, suites validation
1 parent 57e2f31 commit 84b65ec

File tree

6 files changed

+239
-0
lines changed

6 files changed

+239
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ node_modules
3131

3232
# Optional REPL history
3333
.node_repl_history
34+
35+
.DS_Store

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# jsonscript-test-suite
2+
Tests for JSONScript interpreter
3+
4+
Work in progress

Diff for: package.json

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "jsonscript-test-suite",
3+
"version": "0.1.0",
4+
"description": "Tests for JSONScript interpreter",
5+
"main": "lib/index.js",
6+
"scripts": {
7+
"test": "mocha spec/*.spec.js -R spec"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/JSONScript/jsonscript-test-suite.git"
12+
},
13+
"keywords": [
14+
"JSONScript",
15+
"tests"
16+
],
17+
"author": "Evgeny Poberezkin",
18+
"license": "MIT",
19+
"bugs": {
20+
"url": "https://github.com/JSONScript/jsonscript-test-suite/issues"
21+
},
22+
"homepage": "https://github.com/JSONScript/jsonscript-test-suite#readme",
23+
"devDependencies": {
24+
"ajv": "^3.7.0",
25+
"glob": "^7.0.0",
26+
"jsonscript": "^0.1.2",
27+
"mocha": "^2.4.5"
28+
}
29+
}

Diff for: spec/suites.spec.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
var glob = require('glob');
4+
var Ajv = require('Ajv');
5+
var assert = require('assert');
6+
var path = require('path');
7+
8+
9+
describe('test suites', function() {
10+
var validate;
11+
12+
before(function() {
13+
var ajv = Ajv({ allErrors: true });
14+
ajv.addSchema(require('jsonscript/schema/schema.json'));
15+
validate = ajv.compile(require('../test_suite_schema.json'));
16+
});
17+
18+
describe('validation according to the test suite schema', function() {
19+
var files = glob.sync('../tests/**/*.json', { cwd: __dirname });
20+
21+
files.forEach(function (f) {
22+
it(path.basename(f), function() {
23+
assert(validate(require(f)));
24+
});
25+
});
26+
});
27+
});

Diff for: test_suite_schema.json

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"id": "https://raw.githubusercontent.com/JSONScript/jsonscript-test/master/test_suite_schema.json",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"description": "schema for the test suite of the JSONScript scripts",
5+
"definitions": {
6+
"nonEmptyString": {
7+
"id": "#nonEmptyString",
8+
"type": "string",
9+
"minLength": 1
10+
}
11+
},
12+
"type": "array",
13+
"minItems": 1,
14+
"items": {
15+
"description": "set of tests for one script or for one data instance",
16+
"type": "object",
17+
"required": [ "description", "tests" ],
18+
"oneOf": [
19+
{
20+
"required": [ "script" ],
21+
"items": { "required": [ "data" ] }
22+
},
23+
{
24+
"required": [ "data" ],
25+
"items": { "required": [ "script" ] }
26+
}
27+
],
28+
"properties": {
29+
"description": { "$ref": "#nonEmptyString" },
30+
"script": {
31+
"description": "JSONScript to test",
32+
"$ref": "http://json-script.com/schema/schema.json#"
33+
},
34+
"data": {
35+
"description": "data instance, can be any type"
36+
},
37+
"tests": {
38+
"type": "array",
39+
"minItems": 1,
40+
"items": {
41+
"description": "one test, should either have 'result' or 'error' property but not both",
42+
"type": "object",
43+
"required": [ "description" ],
44+
"oneOf": [
45+
{ "required": [ "result" ] },
46+
{ "required": [ "error" ] }
47+
],
48+
"properties": {
49+
"description": { "$ref": "#nonEmptyString" },
50+
"script": {
51+
"description": "JSONScript to test",
52+
"$ref": "http://json-script.com/schema/schema.json#"
53+
},
54+
"data": {
55+
"description": "data instance, can be any type"
56+
},
57+
"result": {
58+
"description": "the result of script evaluation with the data instance"
59+
},
60+
"error": {
61+
"description": "expected error message",
62+
"$ref": "#nonEmptyString"
63+
}
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}

Diff for: tests/$data.json

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
[
2+
{
3+
"description": "$data with different JSON pointers",
4+
"data": {
5+
"": "abc",
6+
"foo": 1,
7+
"~bar": {
8+
"/baz": 2,
9+
"%quux": 3
10+
}
11+
},
12+
"tests": [
13+
{
14+
"description": "data",
15+
"script": { "$data": "" },
16+
"result": {
17+
"": "abc",
18+
"foo": 1,
19+
"~bar": {
20+
"/baz": 2,
21+
"%quux": 3
22+
}
23+
}
24+
},
25+
{
26+
"description": "data['']",
27+
"script": { "$data": "/" },
28+
"result": "abc"
29+
},
30+
{
31+
"description": "data.foo",
32+
"script": { "$data": "/foo" },
33+
"result": 1
34+
},
35+
{
36+
"description": "data['~bar']",
37+
"script": { "$data": "/~0bar" },
38+
"result": {
39+
"/baz": 2,
40+
"%quux": 3
41+
}
42+
},
43+
{
44+
"description": "data['~bar']['/baz']",
45+
"script": { "$data": "/~0bar/~1baz" },
46+
"result": 2
47+
},
48+
{
49+
"description": "data['~bar']['%quux']",
50+
"script": { "$data": "/~0bar/%quux" },
51+
"result": 3
52+
}
53+
]
54+
},
55+
{
56+
"description": "$data with different JSON pointers as URL hash fragments",
57+
"data": {
58+
"": "abc",
59+
"foo": 1,
60+
"~bar": {
61+
"/baz": 2,
62+
"%quux": 3
63+
}
64+
},
65+
"tests": [
66+
{
67+
"description": "data",
68+
"script": { "$data": "#" },
69+
"result": {
70+
"": "abc",
71+
"foo": 1,
72+
"~bar": {
73+
"/baz": 2,
74+
"%quux": 3
75+
}
76+
}
77+
},
78+
{
79+
"description": "data['']",
80+
"script": { "$data": "#/" },
81+
"result": "abc"
82+
},
83+
{
84+
"description": "data.foo",
85+
"script": { "$data": "#/foo" },
86+
"result": 1
87+
},
88+
{
89+
"description": "data['~bar']",
90+
"script": { "$data": "#/~0bar" },
91+
"result": {
92+
"/baz": 2,
93+
"%quux": 3
94+
}
95+
},
96+
{
97+
"description": "data['~bar']['/baz']",
98+
"script": { "$data": "#/~0bar/~1baz" },
99+
"result": 2
100+
},
101+
{
102+
"description": "data['~bar']['%quux']",
103+
"script": { "$data": "#/~0bar/%25quux" },
104+
"result": 3
105+
}
106+
]
107+
}
108+
]

0 commit comments

Comments
 (0)